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