ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/src/MenuRatePlots.cpp
Revision: 1.5
Committed: Tue Jun 4 10:21:10 2013 UTC (11 years, 11 months ago) by grimes
Branch: MAIN
Changes since 1.4: +1 -0 lines
Log Message:
Fixed a stupid bug in the loop indexing, and tidied up the code a little.

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.h"
8 #include "l1menu/ReducedMenuSample.h"
9 #include "l1menu/IReducedEvent.h"
10 #include <TH1F.h>
11
12 l1menu::MenuRatePlots::MenuRatePlots( const l1menu::TriggerMenu& triggerMenu, TDirectory* pDirectory )
13 {
14
15 // Loop over each of the triggers in the menu, book a histogram for it and then create
16 // a l1menu::TriggerRate plot for it.
17 for( size_t triggerNumber=0; triggerNumber<triggerMenu.numberOfTriggers(); ++triggerNumber )
18 {
19 std::unique_ptr<l1menu::ITrigger> pTrigger=triggerMenu.getTriggerCopy(triggerNumber);
20 // Figure out the parameter names of all the possible thresholds.
21 const std::vector<std::string> thresholdNames= l1menu::getThresholdNames(*pTrigger);
22
23 // When a threshold is tested, I want all the other thresholds to be zero. I'll run through
24 // and zero all of them now.
25 for( std::vector<std::string>::const_iterator iName=thresholdNames.begin(); iName!=thresholdNames.end(); ++iName )
26 {
27 pTrigger->parameter(*iName)=0;
28 }
29
30
31 // I want a plot for each of the thresholds, so I'll loop over the threshold names
32 for( std::vector<std::string>::const_iterator iThresholdName=thresholdNames.begin(); iThresholdName!=thresholdNames.end(); ++iThresholdName )
33 {
34 unsigned int numberOfBins=100;
35 float lowerEdge=0;
36 float upperEdge=100;
37 try
38 {
39 const l1menu::TriggerTable& triggerTable=l1menu::TriggerTable::instance();
40 numberOfBins=triggerTable.getSuggestedNumberOfBins( pTrigger->name(), *iThresholdName );
41 lowerEdge=triggerTable.getSuggestedLowerEdge( pTrigger->name(), *iThresholdName );
42 upperEdge=triggerTable.getSuggestedUpperEdge( pTrigger->name(), *iThresholdName );
43 upperEdge*=5; // I'm getting incomplete ReducedSamples, I think because there is the odd overflow event.
44 }
45 catch( std::exception& error) { /* Do nothing. If no binning suggestions have been set for this trigger use the defaults I set above. */ }
46
47 std::unique_ptr<TH1> pHistogram( new TH1F( (pTrigger->name()+"_v_"+(*iThresholdName)).c_str(), "This title gets changed by TriggerRatePlot anyway", numberOfBins, lowerEdge, upperEdge ) );
48 pHistogram->SetDirectory( pDirectory );
49 triggerPlots_.push_back( std::move(l1menu::TriggerRatePlot(*pTrigger,std::move(pHistogram),*iThresholdName)) );
50 }
51
52 } // end of loop over the triggers in the menu
53 }
54
55 void l1menu::MenuRatePlots::addEvent( const l1menu::IEvent& event )
56 {
57 // Loop over each of the TriggerRatePlots and add the event to each of them.
58 for( auto& ratePlot : triggerPlots_ )
59 {
60 ratePlot.addEvent( event );
61 }
62 }
63
64 void l1menu::MenuRatePlots::initiateForReducedSample( const l1menu::ReducedMenuSample& sample )
65 {
66 // Loop over each of the TriggerRatePlots and delegate the call to them.
67 for( auto& ratePlot : triggerPlots_ )
68 {
69 ratePlot.initiateForReducedSample( sample );
70 }
71 }
72
73 void l1menu::MenuRatePlots::addEvent( const l1menu::IReducedEvent& event )
74 {
75 // Loop over each of the TriggerRatePlots and add the event to each of them.
76 for( auto& ratePlot : triggerPlots_ )
77 {
78 ratePlot.addEvent( event );
79 }
80 }
81
82 void l1menu::MenuRatePlots::setDirectory( TDirectory* pDirectory )
83 {
84 // Loop over each of the TriggerRatePlots and individually set the directory.
85 for( auto& ratePlot : triggerPlots_ )
86 {
87 ratePlot.getPlot()->SetDirectory( pDirectory );
88 }
89 }
90
91 std::vector<TH1*> l1menu::MenuRatePlots::getPlots()
92 {
93 std::vector<TH1*> returnValue;
94 for( auto& ratePlot : triggerPlots_ )
95 {
96 returnValue.push_back( ratePlot.getPlot() );
97 }
98 return returnValue;
99 }
100
101 void l1menu::MenuRatePlots::relinquishOwnershipOfPlots()
102 {
103 // Loop over each of the TriggerRatePlots and individually release them.
104 for( std::vector<l1menu::TriggerRatePlot>::iterator iRatePlot=triggerPlots_.begin(); iRatePlot!=triggerPlots_.end(); ++iRatePlot )
105 {
106 iRatePlot->relinquishOwnershipOfPlot();
107 }
108 }