ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/src/MenuRatePlots.cpp
Revision: 1.3
Committed: Sun Jun 2 22:40:57 2013 UTC (11 years, 11 months ago) by grimes
Branch: MAIN
Changes since 1.2: +3 -0 lines
Log Message:
A few changes, and added skeleton files for all of the triggers.

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 grimes 1.3 #include <iostream>
73 grimes 1.2 void l1menu::MenuRatePlots::addEvent( const l1menu::IReducedEvent& event )
74     {
75 grimes 1.3 std::cout << "New event" << std::endl;
76 grimes 1.2 // 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.3 std::cout << "Trigger " << ratePlot.getTrigger().name() << std::endl;
80 grimes 1.2 ratePlot.addEvent( event );
81 grimes 1.1 }
82     }
83    
84     void l1menu::MenuRatePlots::setDirectory( TDirectory* pDirectory )
85     {
86     // Loop over each of the TriggerRatePlots and individually set the directory.
87 grimes 1.2 for( auto& ratePlot : triggerPlots_ )
88     {
89     ratePlot.getPlot()->SetDirectory( pDirectory );
90     }
91     }
92    
93     std::vector<TH1*> l1menu::MenuRatePlots::getPlots()
94     {
95     std::vector<TH1*> returnValue;
96     for( auto& ratePlot : triggerPlots_ )
97 grimes 1.1 {
98 grimes 1.2 returnValue.push_back( ratePlot.getPlot() );
99 grimes 1.1 }
100 grimes 1.2 return returnValue;
101 grimes 1.1 }
102    
103     void l1menu::MenuRatePlots::relinquishOwnershipOfPlots()
104     {
105     // Loop over each of the TriggerRatePlots and individually release them.
106     for( std::vector<l1menu::TriggerRatePlot>::iterator iRatePlot=triggerPlots_.begin(); iRatePlot!=triggerPlots_.end(); ++iRatePlot )
107     {
108     iRatePlot->relinquishOwnershipOfPlot();
109     }
110     }