ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/src/MenuRatePlots.cpp
Revision: 1.9
Committed: Fri Jun 28 14:30:08 2013 UTC (11 years, 10 months ago) by grimes
Branch: MAIN
Changes since 1.8: +12 -3 lines
Log Message:
Added ICachedTrigger to speed up processing

File Contents

# User Rev Content
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     // 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 grimes 1.8 const std::vector<std::string> thresholdNames=l1menu::tools::getThresholdNames(*pTrigger);
24 grimes 1.1
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 grimes 1.9 void l1menu::MenuRatePlots::addEvent( const l1menu::L1TriggerDPGEvent& event )
57 grimes 1.1 {
58     // Loop over each of the TriggerRatePlots and add the event to each of them.
59 grimes 1.2 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 grimes 1.9 void l1menu::MenuRatePlots::addEvent( const l1menu::ReducedEvent& event )
75 grimes 1.2 {
76     // Loop over each of the TriggerRatePlots and add the event to each of them.
77     for( auto& ratePlot : triggerPlots_ )
78 grimes 1.1 {
79 grimes 1.2 ratePlot.addEvent( event );
80 grimes 1.1 }
81     }
82    
83 grimes 1.9 void l1menu::MenuRatePlots::addSample( const l1menu::ISample& sample )
84     {
85     // Loop over each of the TriggerRatePlots and add the sample to each of them.
86     for( auto& ratePlot : triggerPlots_ )
87     {
88     ratePlot.addSample( sample );
89     }
90     }
91    
92 grimes 1.1 void l1menu::MenuRatePlots::setDirectory( TDirectory* pDirectory )
93     {
94     // Loop over each of the TriggerRatePlots and individually set the directory.
95 grimes 1.2 for( auto& ratePlot : triggerPlots_ )
96     {
97     ratePlot.getPlot()->SetDirectory( pDirectory );
98     }
99     }
100    
101     std::vector<TH1*> l1menu::MenuRatePlots::getPlots()
102     {
103     std::vector<TH1*> returnValue;
104     for( auto& ratePlot : triggerPlots_ )
105 grimes 1.1 {
106 grimes 1.2 returnValue.push_back( ratePlot.getPlot() );
107 grimes 1.1 }
108 grimes 1.2 return returnValue;
109 grimes 1.1 }
110    
111     void l1menu::MenuRatePlots::relinquishOwnershipOfPlots()
112     {
113     // Loop over each of the TriggerRatePlots and individually release them.
114     for( std::vector<l1menu::TriggerRatePlot>::iterator iRatePlot=triggerPlots_.begin(); iRatePlot!=triggerPlots_.end(); ++iRatePlot )
115     {
116     iRatePlot->relinquishOwnershipOfPlot();
117     }
118     }