ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/src/TriggerRatePlot.cpp
(Generate patch)

Comparing UserCode/grimes/L1Menu/src/TriggerRatePlot.cpp (file contents):
Revision 1.1 by grimes, Tue May 28 23:14:03 2013 UTC vs.
Revision 1.6 by grimes, Sat Jun 29 16:14:45 2013 UTC

# Line 1 | Line 1
1   #include "l1menu/TriggerRatePlot.h"
2  
3   #include "l1menu/ITrigger.h"
4 + #include "l1menu/ICachedTrigger.h"
5 + #include "l1menu/L1TriggerDPGEvent.h"
6   #include "l1menu/IEvent.h"
7   #include "l1menu/TriggerTable.h"
8 + #include "l1menu/ReducedMenuSample.h"
9 + #include "l1menu/ReducedEvent.h"
10   #include <TH1F.h>
7 #include <iostream>
11   #include <sstream>
12 + #include <algorithm>
13 +
14 + #include <iostream>
15  
16 < l1menu::TriggerRatePlot::TriggerRatePlot( const l1menu::ITrigger& trigger, std::unique_ptr<TH1> pHistogram, const std::string versusParameter )
16 > l1menu::TriggerRatePlot::TriggerRatePlot( const l1menu::ITrigger& trigger, std::unique_ptr<TH1> pHistogram, const std::string& versusParameter, const std::vector<std::string> scaledParameters )
17          : pHistogram_( std::move(pHistogram) ), versusParameter_(versusParameter), histogramOwnedByMe_(true)
18   {
19          // Take a copy of the trigger
# Line 15 | Line 21 | l1menu::TriggerRatePlot::TriggerRatePlot
21          pTrigger_=table.copyTrigger( trigger );
22  
23          // Make sure the versusParameter_ supplied is valid. If it's not then this call will
24 <        // throw an exception.
25 <        pTrigger_->parameter(versusParameter_);
26 <
24 >        // throw an exception. Take a pointer to the parameter so I don't need to keep performing
25 >        // expensive string comparisons.
26 >        pParameter_=&pTrigger_->parameter(versusParameter_);
27 >
28 >        // If any parameters have been requested to be scaled along with the versusParameter, figure
29 >        // out what the scaling should be and take a note of pointers.
30 >        for( const auto& parameterToScale : scaledParameters )
31 >        {
32 >                if( parameterToScale!=versusParameter_ )
33 >                {
34 >                        otherParameterScalings_.push_back( std::make_pair( &pTrigger_->parameter(parameterToScale), pTrigger_->parameter(parameterToScale)/(*pParameter_) ) );
35 >                }
36 >        }
37          // I want to make a note of the other parameters set for the trigger. As far as I know TH1
38          // has no way of adding annotations so I'll tag it on the end of the title.
39          std::stringstream description;
# Line 30 | Line 46 | l1menu::TriggerRatePlot::TriggerRatePlot
46          for( std::vector<std::string>::const_iterator iName=parameterNames.begin(); iName!=parameterNames.end(); ++iName )
47          {
48                  if( *iName==versusParameter ) continue; // Don't bother adding the parameter I'm plotting against
49 <                description << *iName << "=" << pTrigger_->parameter(*iName);
49 >
50 >                // First check to see if this is one of the parameters that are being scaled
51 >                if( std::find(scaledParameters.begin(),scaledParameters.end(),*iName)==scaledParameters.end() )
52 >                {
53 >                        // This parameter isn't being scaled, so write the absoulte value in the description
54 >                        description << *iName << "=" << pTrigger_->parameter(*iName);
55 >                }
56 >                else
57 >                {
58 >                        // This parameter is being scaled, so write what the scaling is in the description
59 >                        description << *iName << "=x*" << pTrigger_->parameter(*iName)/(*pParameter_);
60 >                }
61 >
62                  if( iName+1!=parameterNames.end() ) description << ","; // Add delimeter between parameter names
63          }
64          description << "]";
# Line 41 | Line 69 | l1menu::TriggerRatePlot::TriggerRatePlot
69  
70   l1menu::TriggerRatePlot::TriggerRatePlot( l1menu::TriggerRatePlot&& otherTriggerRatePlot ) noexcept
71          : pTrigger_( std::move(otherTriggerRatePlot.pTrigger_) ), pHistogram_( std::move(otherTriggerRatePlot.pHistogram_) ),
72 <          versusParameter_( std::move(otherTriggerRatePlot.versusParameter_) ), histogramOwnedByMe_(histogramOwnedByMe_)
72 >          versusParameter_( std::move(otherTriggerRatePlot.versusParameter_) ), pParameter_(&pTrigger_->parameter(versusParameter_)),
73 >          otherParameterScalings_( std::move(otherTriggerRatePlot.otherParameterScalings_) ), histogramOwnedByMe_(histogramOwnedByMe_)
74   {
75          // No operation besides the initaliser list
76   }
# Line 57 | Line 86 | l1menu::TriggerRatePlot& l1menu::Trigger
86          pTrigger_=std::move(otherTriggerRatePlot.pTrigger_);
87          pHistogram_=std::move(otherTriggerRatePlot.pHistogram_);
88          versusParameter_=std::move(otherTriggerRatePlot.versusParameter_);
89 <        histogramOwnedByMe_=histogramOwnedByMe_;
89 >        pParameter_=&pTrigger_->parameter(versusParameter_);
90 >        otherParameterScalings_=std::move(otherTriggerRatePlot.otherParameterScalings_);
91 >        histogramOwnedByMe_=otherTriggerRatePlot.histogramOwnedByMe_;
92  
93          return *this;
94   }
# Line 72 | Line 103 | l1menu::TriggerRatePlot::~TriggerRatePlo
103          }
104   }
105  
106 < void l1menu::TriggerRatePlot::addEvent( const l1menu::IEvent& event ) const
106 > void l1menu::TriggerRatePlot::addEvent( const l1menu::L1TriggerDPGEvent& event )
107   {
77        float& threshold1=pTrigger_->parameter(versusParameter_);
78
108          // loop over all of the bins in the histogram, and see if the trigger passes
109          // for the value at the center of the bin.
110          for( int binNumber=1; binNumber<pHistogram_->GetNbinsX(); ++binNumber )
111          {
112 <                threshold1=pHistogram_->GetBinCenter(binNumber);
112 >                (*pParameter_)=pHistogram_->GetBinCenter(binNumber);
113 >
114 >                // Scale accordingly any other parameters that should be scaled.
115 >                for( const auto& parameterScalingPair : otherParameterScalings_ ) *(parameterScalingPair.first)=parameterScalingPair.second*(*pParameter_);
116 >
117                  if( pTrigger_->apply( event ) )
118                  {
119 <                        pHistogram_->Fill( threshold1, event.weight() );
119 >                        pHistogram_->Fill( (*pParameter_), event.weight() );
120                  }
121                  // could put an "else break" in here, but I don't know if triggers
122                  // will run their thresholds the other way. E.g. a trigger could require
# Line 92 | Line 125 | void l1menu::TriggerRatePlot::addEvent(
125          }
126   }
127  
128 + void l1menu::TriggerRatePlot::addSample( const l1menu::ISample& sample )
129 + {
130 +        float weightPerEvent=sample.eventRate()/sample.sumOfWeights();
131 +
132 +        // Create a cached trigger, which depending on the concrete type of the ISample
133 +        // may or may not significantly increase the speed at which this next loop happens.
134 +        std::unique_ptr<l1menu::ICachedTrigger> pCachedTrigger=sample.createCachedTrigger( *pTrigger_ );
135 +
136 +        for( size_t eventNumber=0; eventNumber<sample.numberOfEvents(); ++eventNumber )
137 +        {
138 +                const l1menu::IEvent& event=sample.getEvent( eventNumber );
139 +
140 +                for( int binNumber=1; binNumber<pHistogram_->GetNbinsX(); ++binNumber )
141 +                {
142 +                        (*pParameter_)=pHistogram_->GetBinCenter(binNumber);
143 +
144 +                        // Scale accordingly any other parameters that should be scaled.
145 +                        for( const auto& parameterScalingPair : otherParameterScalings_ ) *(parameterScalingPair.first)=parameterScalingPair.second*(*pParameter_);
146 +
147 +                        if( pCachedTrigger->apply(event) ) // If the event passes the trigger
148 +                        {
149 +                                pHistogram_->Fill( (*pParameter_), event.weight()*weightPerEvent );
150 +                        }
151 +                        // could put an "else break" in here, but I don't know if triggers will
152 +                        // run their thresholds the other way. E.g. a trigger could require
153 +                        // a minimum amount of energy in the event, in which case the higher
154 +                        // bins will pass.
155 +                } // end of loop over histogram bins
156 +        } // end of loop over events
157 +
158 + }
159 +
160 + const l1menu::ITrigger& l1menu::TriggerRatePlot::getTrigger() const
161 + {
162 +        return *pTrigger_;
163 + }
164 +
165 + void l1menu::TriggerRatePlot::initiateForReducedSample( const l1menu::ReducedMenuSample& sample )
166 + {
167 +        pTrigger_->initiateForReducedSample( sample );
168 + }
169 +
170 + void l1menu::TriggerRatePlot::addEvent( const l1menu::ReducedEvent& event )
171 + {
172 +        // Basically exactly the same as for the l1menu::L1TriggerDPGEvent version. I
173 +        // should probably template this.
174 +        for( int binNumber=1; binNumber<pHistogram_->GetNbinsX(); ++binNumber )
175 +        {
176 +                (*pParameter_)=pHistogram_->GetBinCenter(binNumber);
177 +
178 +                // Scale accordingly any other parameters that should be scaled.
179 +                for( const auto& parameterScalingPair : otherParameterScalings_ ) *(parameterScalingPair.first)=parameterScalingPair.second*(*pParameter_);
180 +
181 +                if( pTrigger_->apply( event ) )
182 +                {
183 +                        pHistogram_->Fill( (*pParameter_), event.weight() );
184 +                }
185 +        }
186 +
187 + }
188 +
189   TH1* l1menu::TriggerRatePlot::getPlot()
190   {
191          return pHistogram_.get();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines