1 |
#include "l1menu/MenuRatePlots.h"
|
2 |
|
3 |
#include <sstream>
|
4 |
#include "l1menu/ITrigger.h"
|
5 |
#include "l1menu/TriggerMenu.h"
|
6 |
#include "l1menu/TriggerRatePlot.h"
|
7 |
#include "l1menu/tools/tools.h"
|
8 |
#include <TH1F.h>
|
9 |
|
10 |
l1menu::MenuRatePlots::MenuRatePlots( const l1menu::TriggerMenu& triggerMenu, TDirectory* pDirectory )
|
11 |
{
|
12 |
// Before making any histograms make sure errors are done properly
|
13 |
TH1::SetDefaultSumw2();
|
14 |
|
15 |
// This is always useful
|
16 |
const l1menu::TriggerTable& triggerTable=l1menu::TriggerTable::instance();
|
17 |
|
18 |
// Loop over each of the triggers in the menu, book a histogram for it and then create
|
19 |
// a l1menu::TriggerRate plot for it.
|
20 |
for( size_t triggerNumber=0; triggerNumber<triggerMenu.numberOfTriggers(); ++triggerNumber )
|
21 |
{
|
22 |
std::unique_ptr<l1menu::ITrigger> pTrigger=triggerMenu.getTriggerCopy(triggerNumber);
|
23 |
// Figure out the parameter names of all the possible thresholds.
|
24 |
const std::vector<std::string> thresholdNames=l1menu::tools::getThresholdNames(*pTrigger);
|
25 |
|
26 |
//
|
27 |
// If there is more than one threshold add a plot where all of the thresholds are scaled together.
|
28 |
//
|
29 |
if( thresholdNames.size()>1 )
|
30 |
{
|
31 |
const std::string& mainThreshold=thresholdNames.front();
|
32 |
unsigned int numberOfBins=100;
|
33 |
float lowerEdge=0;
|
34 |
float upperEdge=100;
|
35 |
try
|
36 |
{
|
37 |
numberOfBins=triggerTable.getSuggestedNumberOfBins( pTrigger->name(), mainThreshold );
|
38 |
lowerEdge=triggerTable.getSuggestedLowerEdge( pTrigger->name(), mainThreshold );
|
39 |
upperEdge=triggerTable.getSuggestedUpperEdge( pTrigger->name(), mainThreshold );
|
40 |
}
|
41 |
catch( std::exception& error) { /* Do nothing. If no binning suggestions have been set for this trigger use the defaults I set above. */ }
|
42 |
|
43 |
std::unique_ptr<TH1> pHistogram( new TH1F( (pTrigger->name()+"_v_allThresholdsScaled").c_str(), "This title gets changed by TriggerRatePlot anyway", numberOfBins, lowerEdge, upperEdge ) );
|
44 |
pHistogram->SetDirectory( pDirectory );
|
45 |
// Passing thresholdNames tells the TriggerRatePlot to scale all parameters named in that
|
46 |
// vector along with mainThreshold.
|
47 |
triggerPlots_.push_back( std::move(l1menu::TriggerRatePlot(*pTrigger,std::move(pHistogram),mainThreshold,thresholdNames)) );
|
48 |
|
49 |
}
|
50 |
|
51 |
// When a threshold is tested, I want all the other thresholds to be zero. I'll run through
|
52 |
// and zero all of them now.
|
53 |
for( std::vector<std::string>::const_iterator iName=thresholdNames.begin(); iName!=thresholdNames.end(); ++iName )
|
54 |
{
|
55 |
pTrigger->parameter(*iName)=0;
|
56 |
}
|
57 |
|
58 |
|
59 |
// I want a plot for each of the thresholds, so I'll loop over the threshold names
|
60 |
for( std::vector<std::string>::const_iterator iThresholdName=thresholdNames.begin(); iThresholdName!=thresholdNames.end(); ++iThresholdName )
|
61 |
{
|
62 |
unsigned int numberOfBins=100;
|
63 |
float lowerEdge=0;
|
64 |
float upperEdge=100;
|
65 |
try
|
66 |
{
|
67 |
numberOfBins=triggerTable.getSuggestedNumberOfBins( pTrigger->name(), *iThresholdName );
|
68 |
lowerEdge=triggerTable.getSuggestedLowerEdge( pTrigger->name(), *iThresholdName );
|
69 |
upperEdge=triggerTable.getSuggestedUpperEdge( pTrigger->name(), *iThresholdName );
|
70 |
}
|
71 |
catch( std::exception& error) { /* Do nothing. If no binning suggestions have been set for this trigger use the defaults I set above. */ }
|
72 |
|
73 |
std::unique_ptr<TH1> pHistogram( new TH1F( (pTrigger->name()+"_v_"+(*iThresholdName)).c_str(), "This title gets changed by TriggerRatePlot anyway", numberOfBins, lowerEdge, upperEdge ) );
|
74 |
pHistogram->SetDirectory( pDirectory );
|
75 |
triggerPlots_.push_back( std::move(l1menu::TriggerRatePlot(*pTrigger,std::move(pHistogram),*iThresholdName)) );
|
76 |
}
|
77 |
|
78 |
} // end of loop over the triggers in the menu
|
79 |
}
|
80 |
|
81 |
void l1menu::MenuRatePlots::addEvent( const l1menu::IEvent& event )
|
82 |
{
|
83 |
// Loop over each of the TriggerRatePlots and add the event to each of them.
|
84 |
for( auto& ratePlot : triggerPlots_ )
|
85 |
{
|
86 |
ratePlot.addEvent( event );
|
87 |
}
|
88 |
}
|
89 |
|
90 |
void l1menu::MenuRatePlots::addSample( const l1menu::ISample& sample )
|
91 |
{
|
92 |
// Loop over each of the TriggerRatePlots and add the sample to each of them.
|
93 |
for( auto& ratePlot : triggerPlots_ )
|
94 |
{
|
95 |
ratePlot.addSample( sample );
|
96 |
}
|
97 |
}
|
98 |
|
99 |
void l1menu::MenuRatePlots::setDirectory( TDirectory* pDirectory )
|
100 |
{
|
101 |
// Loop over each of the TriggerRatePlots and individually set the directory.
|
102 |
for( auto& ratePlot : triggerPlots_ )
|
103 |
{
|
104 |
ratePlot.getPlot()->SetDirectory( pDirectory );
|
105 |
}
|
106 |
}
|
107 |
|
108 |
std::vector<TH1*> l1menu::MenuRatePlots::getPlots()
|
109 |
{
|
110 |
std::vector<TH1*> returnValue;
|
111 |
for( auto& ratePlot : triggerPlots_ )
|
112 |
{
|
113 |
returnValue.push_back( ratePlot.getPlot() );
|
114 |
}
|
115 |
return returnValue;
|
116 |
}
|
117 |
|
118 |
void l1menu::MenuRatePlots::relinquishOwnershipOfPlots()
|
119 |
{
|
120 |
// Loop over each of the TriggerRatePlots and individually release them.
|
121 |
for( std::vector<l1menu::TriggerRatePlot>::iterator iRatePlot=triggerPlots_.begin(); iRatePlot!=triggerPlots_.end(); ++iRatePlot )
|
122 |
{
|
123 |
iRatePlot->relinquishOwnershipOfPlot();
|
124 |
}
|
125 |
}
|