ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/src/MenuRatePlots.cpp
Revision: 1.7
Committed: Tue Jun 18 10:18:23 2013 UTC (11 years, 10 months ago) by grimes
Branch: MAIN
Changes since 1.6: +2 -0 lines
Log Message:
Fixed some bugs, and started adding functionality to calculate rates.

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