ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/src/MenuRatePlots.cpp
Revision: 1.10
Committed: Sat Jun 29 16:14:45 2013 UTC (11 years, 10 months ago) by grimes
Branch: MAIN
Changes since 1.9: +28 -1 lines
Log Message:
Added an option to the TriggerRatePlot to scale all thresholds at once for the plot

File Contents

# Content
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 "l1menu/ReducedMenuSample.h"
9 #include "l1menu/ReducedEvent.h"
10 #include <TH1F.h>
11
12 l1menu::MenuRatePlots::MenuRatePlots( const l1menu::TriggerMenu& triggerMenu, TDirectory* pDirectory )
13 {
14 // Before making any histograms make sure errors are done properly
15 TH1::SetDefaultSumw2();
16
17 // This is always useful
18 const l1menu::TriggerTable& triggerTable=l1menu::TriggerTable::instance();
19
20 // 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 const std::vector<std::string> thresholdNames=l1menu::tools::getThresholdNames(*pTrigger);
27
28 //
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 // 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 void l1menu::MenuRatePlots::addEvent( const l1menu::L1TriggerDPGEvent& event )
84 {
85 // Loop over each of the TriggerRatePlots and add the event to each of them.
86 for( auto& ratePlot : triggerPlots_ )
87 {
88 ratePlot.addEvent( event );
89 }
90 }
91
92 void l1menu::MenuRatePlots::initiateForReducedSample( const l1menu::ReducedMenuSample& sample )
93 {
94 // Loop over each of the TriggerRatePlots and delegate the call to them.
95 for( auto& ratePlot : triggerPlots_ )
96 {
97 ratePlot.initiateForReducedSample( sample );
98 }
99 }
100
101 void l1menu::MenuRatePlots::addEvent( const l1menu::ReducedEvent& event )
102 {
103 // Loop over each of the TriggerRatePlots and add the event to each of them.
104 for( auto& ratePlot : triggerPlots_ )
105 {
106 ratePlot.addEvent( event );
107 }
108 }
109
110 void l1menu::MenuRatePlots::addSample( const l1menu::ISample& sample )
111 {
112 // Loop over each of the TriggerRatePlots and add the sample to each of them.
113 for( auto& ratePlot : triggerPlots_ )
114 {
115 ratePlot.addSample( sample );
116 }
117 }
118
119 void l1menu::MenuRatePlots::setDirectory( TDirectory* pDirectory )
120 {
121 // Loop over each of the TriggerRatePlots and individually set the directory.
122 for( auto& ratePlot : triggerPlots_ )
123 {
124 ratePlot.getPlot()->SetDirectory( pDirectory );
125 }
126 }
127
128 std::vector<TH1*> l1menu::MenuRatePlots::getPlots()
129 {
130 std::vector<TH1*> returnValue;
131 for( auto& ratePlot : triggerPlots_ )
132 {
133 returnValue.push_back( ratePlot.getPlot() );
134 }
135 return returnValue;
136 }
137
138 void l1menu::MenuRatePlots::relinquishOwnershipOfPlots()
139 {
140 // Loop over each of the TriggerRatePlots and individually release them.
141 for( std::vector<l1menu::TriggerRatePlot>::iterator iRatePlot=triggerPlots_.begin(); iRatePlot!=triggerPlots_.end(); ++iRatePlot )
142 {
143 iRatePlot->relinquishOwnershipOfPlot();
144 }
145 }