ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/src/TriggerRatePlot.cpp
Revision: 1.4
Committed: Wed Jun 5 11:02:36 2013 UTC (11 years, 11 months ago) by grimes
Branch: MAIN
Changes since 1.3: +0 -1 lines
Log Message:
Fixes to the number of muons (so muon triggers now work); error when loading ReducedMenuSamples from disk; made L1_SingleIsoMu an alias for L1_SingleMu since there's no isolation on muons and they're the same

File Contents

# User Rev Content
1 grimes 1.1 #include "l1menu/TriggerRatePlot.h"
2    
3     #include "l1menu/ITrigger.h"
4     #include "l1menu/IEvent.h"
5     #include "l1menu/TriggerTable.h"
6 grimes 1.2 #include "l1menu/ReducedMenuSample.h"
7     #include "l1menu/IReducedEvent.h"
8 grimes 1.1 #include <TH1F.h>
9     #include <sstream>
10    
11     l1menu::TriggerRatePlot::TriggerRatePlot( const l1menu::ITrigger& trigger, std::unique_ptr<TH1> pHistogram, const std::string versusParameter )
12     : pHistogram_( std::move(pHistogram) ), versusParameter_(versusParameter), histogramOwnedByMe_(true)
13     {
14     // Take a copy of the trigger
15     l1menu::TriggerTable& table=l1menu::TriggerTable::instance();
16     pTrigger_=table.copyTrigger( trigger );
17    
18     // Make sure the versusParameter_ supplied is valid. If it's not then this call will
19     // throw an exception.
20 grimes 1.2 pParameter_=&pTrigger_->parameter(versusParameter_);
21 grimes 1.1
22     // I want to make a note of the other parameters set for the trigger. As far as I know TH1
23     // has no way of adding annotations so I'll tag it on the end of the title.
24     std::stringstream description;
25     description << pTrigger_->name() << " rate versus " << versusParameter;
26    
27     // Loop over all of the parameters and add their values to the description
28     std::vector<std::string> parameterNames=pTrigger_->parameterNames();
29     description << " [v" << pTrigger_->version();
30     if( parameterNames.size()>1 ) description << ",";
31     for( std::vector<std::string>::const_iterator iName=parameterNames.begin(); iName!=parameterNames.end(); ++iName )
32     {
33     if( *iName==versusParameter ) continue; // Don't bother adding the parameter I'm plotting against
34     description << *iName << "=" << pTrigger_->parameter(*iName);
35     if( iName+1!=parameterNames.end() ) description << ","; // Add delimeter between parameter names
36     }
37     description << "]";
38    
39     pHistogram_->SetTitle( description.str().c_str() );
40    
41     }
42    
43     l1menu::TriggerRatePlot::TriggerRatePlot( l1menu::TriggerRatePlot&& otherTriggerRatePlot ) noexcept
44     : pTrigger_( std::move(otherTriggerRatePlot.pTrigger_) ), pHistogram_( std::move(otherTriggerRatePlot.pHistogram_) ),
45 grimes 1.2 versusParameter_( std::move(otherTriggerRatePlot.versusParameter_) ), pParameter_(otherTriggerRatePlot.pParameter_),
46     histogramOwnedByMe_(histogramOwnedByMe_)
47 grimes 1.1 {
48     // No operation besides the initaliser list
49     }
50    
51     l1menu::TriggerRatePlot& l1menu::TriggerRatePlot::operator=( l1menu::TriggerRatePlot&& otherTriggerRatePlot ) noexcept
52     {
53     // Free up whatever was there before
54     pTrigger_.reset();
55     if( histogramOwnedByMe_ ) pHistogram_.reset();
56     else pHistogram_.release();
57    
58     // Then copy from the other object
59     pTrigger_=std::move(otherTriggerRatePlot.pTrigger_);
60     pHistogram_=std::move(otherTriggerRatePlot.pHistogram_);
61     versusParameter_=std::move(otherTriggerRatePlot.versusParameter_);
62 grimes 1.2 pParameter_=otherTriggerRatePlot.pParameter_;
63     histogramOwnedByMe_=otherTriggerRatePlot.histogramOwnedByMe_;
64 grimes 1.1
65     return *this;
66     }
67    
68     l1menu::TriggerRatePlot::~TriggerRatePlot()
69     {
70     // If the flag has been set telling me that this instance doesn't own the histogram,
71     // then I need to tell the unique_ptr not to delete it.
72     if( !histogramOwnedByMe_ )
73     {
74     pHistogram_.release();
75     }
76     }
77    
78 grimes 1.2 void l1menu::TriggerRatePlot::addEvent( const l1menu::IEvent& event )
79 grimes 1.1 {
80     // loop over all of the bins in the histogram, and see if the trigger passes
81     // for the value at the center of the bin.
82     for( int binNumber=1; binNumber<pHistogram_->GetNbinsX(); ++binNumber )
83     {
84 grimes 1.2 (*pParameter_)=pHistogram_->GetBinCenter(binNumber);
85 grimes 1.1 if( pTrigger_->apply( event ) )
86     {
87 grimes 1.2 pHistogram_->Fill( (*pParameter_), event.weight() );
88 grimes 1.1 }
89     // could put an "else break" in here, but I don't know if triggers
90     // will run their thresholds the other way. E.g. a trigger could require
91     // a minimum amount of energy in the event, in which case the higher
92     // bins will pass.
93     }
94     }
95    
96 grimes 1.3 const l1menu::ITrigger& l1menu::TriggerRatePlot::getTrigger() const
97     {
98     return *pTrigger_;
99     }
100    
101 grimes 1.2 void l1menu::TriggerRatePlot::initiateForReducedSample( const l1menu::ReducedMenuSample& sample )
102     {
103     pTrigger_->initiateForReducedSample( sample );
104     }
105    
106     void l1menu::TriggerRatePlot::addEvent( const l1menu::IReducedEvent& event )
107     {
108     // Basically exactly the same as for the l1menu::IEvent version. I
109     // should probably template this.
110     for( int binNumber=1; binNumber<pHistogram_->GetNbinsX(); ++binNumber )
111     {
112     (*pParameter_)=pHistogram_->GetBinCenter(binNumber);
113     if( pTrigger_->apply( event ) )
114     {
115     pHistogram_->Fill( (*pParameter_), event.weight() );
116     }
117     }
118    
119     }
120    
121 grimes 1.1 TH1* l1menu::TriggerRatePlot::getPlot()
122     {
123     return pHistogram_.get();
124     }
125    
126     TH1* l1menu::TriggerRatePlot::relinquishOwnershipOfPlot()
127     {
128     // Rather than call release() on the unique_ptr, I'll set a flag so that I know
129     // to release() in the destructor instead. This way it's possible to relinquish
130     // ownership but still perform operations on the histograms.
131     histogramOwnedByMe_=false;
132     return pHistogram_.get();
133     }