ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/src/MenuRatePlots.cpp
Revision: 1.4
Committed: Tue Jun 4 08:17:37 2013 UTC (11 years, 11 months ago) by grimes
Branch: MAIN
Changes since 1.3: +0 -3 lines
Log Message:
Multiple changes. Implemented all required triggers, removed the ones not needed and changed some names.

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     #include "l1menu/tools.h"
8 grimes 1.2 #include "l1menu/ReducedMenuSample.h"
9     #include "l1menu/IReducedEvent.h"
10 grimes 1.1 #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     }
44     catch( std::exception& error) { /* Do nothing. If no binning suggestions have been set for this trigger use the defaults I set above. */ }
45    
46     std::unique_ptr<TH1> pHistogram( new TH1F( (pTrigger->name()+"_v_"+(*iThresholdName)).c_str(), "This title gets changed by TriggerRatePlot anyway", numberOfBins, lowerEdge, upperEdge ) );
47     pHistogram->SetDirectory( pDirectory );
48     triggerPlots_.push_back( std::move(l1menu::TriggerRatePlot(*pTrigger,std::move(pHistogram),*iThresholdName)) );
49     }
50    
51     } // end of loop over the triggers in the menu
52     }
53    
54     void l1menu::MenuRatePlots::addEvent( const l1menu::IEvent& event )
55     {
56     // Loop over each of the TriggerRatePlots and add the event to each of them.
57 grimes 1.2 for( auto& ratePlot : triggerPlots_ )
58     {
59     ratePlot.addEvent( event );
60     }
61     }
62    
63     void l1menu::MenuRatePlots::initiateForReducedSample( const l1menu::ReducedMenuSample& sample )
64     {
65     // Loop over each of the TriggerRatePlots and delegate the call to them.
66     for( auto& ratePlot : triggerPlots_ )
67     {
68     ratePlot.initiateForReducedSample( sample );
69     }
70     }
71    
72     void l1menu::MenuRatePlots::addEvent( const l1menu::IReducedEvent& event )
73     {
74     // Loop over each of the TriggerRatePlots and add the event to each of them.
75     for( auto& ratePlot : triggerPlots_ )
76 grimes 1.1 {
77 grimes 1.2 ratePlot.addEvent( event );
78 grimes 1.1 }
79     }
80    
81     void l1menu::MenuRatePlots::setDirectory( TDirectory* pDirectory )
82     {
83     // Loop over each of the TriggerRatePlots and individually set the directory.
84 grimes 1.2 for( auto& ratePlot : triggerPlots_ )
85     {
86     ratePlot.getPlot()->SetDirectory( pDirectory );
87     }
88     }
89    
90     std::vector<TH1*> l1menu::MenuRatePlots::getPlots()
91     {
92     std::vector<TH1*> returnValue;
93     for( auto& ratePlot : triggerPlots_ )
94 grimes 1.1 {
95 grimes 1.2 returnValue.push_back( ratePlot.getPlot() );
96 grimes 1.1 }
97 grimes 1.2 return returnValue;
98 grimes 1.1 }
99    
100     void l1menu::MenuRatePlots::relinquishOwnershipOfPlots()
101     {
102     // Loop over each of the TriggerRatePlots and individually release them.
103     for( std::vector<l1menu::TriggerRatePlot>::iterator iRatePlot=triggerPlots_.begin(); iRatePlot!=triggerPlots_.end(); ++iRatePlot )
104     {
105     iRatePlot->relinquishOwnershipOfPlot();
106     }
107     }