ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/src/TriggerRatePlot.cpp
Revision: 1.1
Committed: Tue May 28 23:14:03 2013 UTC (11 years, 11 months ago) by grimes
Branch: MAIN
Log Message:
Numerous changes

File Contents

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