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

# 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 }
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 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 #include <iostream>
73 void l1menu::MenuRatePlots::addEvent( const l1menu::IReducedEvent& event )
74 {
75 std::cout << "New event" << std::endl;
76 // Loop over each of the TriggerRatePlots and add the event to each of them.
77 for( auto& ratePlot : triggerPlots_ )
78 {
79 std::cout << "Trigger " << ratePlot.getTrigger().name() << std::endl;
80 ratePlot.addEvent( event );
81 }
82 }
83
84 void l1menu::MenuRatePlots::setDirectory( TDirectory* pDirectory )
85 {
86 // Loop over each of the TriggerRatePlots and individually set the directory.
87 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 {
98 returnValue.push_back( ratePlot.getPlot() );
99 }
100 return returnValue;
101 }
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 }