4 |
|
#include "l1menu/ICachedTrigger.h" |
5 |
|
#include "l1menu/L1TriggerDPGEvent.h" |
6 |
|
#include "l1menu/IEvent.h" |
7 |
+ |
#include "l1menu/ISample.h" |
8 |
|
#include "l1menu/TriggerTable.h" |
8 |
– |
#include "l1menu/ReducedMenuSample.h" |
9 |
– |
#include "l1menu/ReducedEvent.h" |
9 |
|
#include <TH1F.h> |
10 |
|
#include <sstream> |
11 |
|
#include <algorithm> |
108 |
|
float weightPerEvent=sample.eventRate()/sample.sumOfWeights(); |
109 |
|
|
110 |
|
// For some implementations of ISample, it is significantly faster to |
111 |
< |
// create ICachedTriggers and then loop over those. |
111 |
> |
// create ICachedTriggers and then loop over those. The addEvent overload |
112 |
> |
// I'm about to delegate to loops over the histogram bins, so even for |
113 |
> |
// one event this trigger can be called multiple times. |
114 |
|
std::unique_ptr<l1menu::ICachedTrigger> pCachedTrigger=sample.createCachedTrigger( *pTrigger_ ); |
115 |
|
|
116 |
< |
for( int binNumber=1; binNumber<pHistogram_->GetNbinsX(); ++binNumber ) |
116 |
< |
{ |
117 |
< |
(*pParameter_)=pHistogram_->GetBinCenter(binNumber); |
118 |
< |
|
119 |
< |
// Scale accordingly any other parameters that should be scaled. |
120 |
< |
for( const auto& parameterScalingPair : otherParameterScalings_ ) *(parameterScalingPair.first)=parameterScalingPair.second*(*pParameter_); |
121 |
< |
|
122 |
< |
if( pCachedTrigger->apply(event) ) |
123 |
< |
{ |
124 |
< |
pHistogram_->Fill( (*pParameter_), event.weight()*weightPerEvent ); |
125 |
< |
} |
126 |
< |
else break; |
127 |
< |
// Not sure if this "else break" is a good idea. I don't know if triggers |
128 |
< |
// will run their thresholds the other way. E.g. a trigger could require |
129 |
< |
// a minimum amount of energy in the event, in which case the higher |
130 |
< |
// bins will pass. |
131 |
< |
} |
116 |
> |
addEvent( event, pCachedTrigger, weightPerEvent ); |
117 |
|
} |
118 |
|
|
119 |
|
void l1menu::TriggerRatePlot::addSample( const l1menu::ISample& sample ) |
126 |
|
|
127 |
|
for( size_t eventNumber=0; eventNumber<sample.numberOfEvents(); ++eventNumber ) |
128 |
|
{ |
129 |
< |
const l1menu::IEvent& event=sample.getEvent( eventNumber ); |
129 |
> |
addEvent( sample.getEvent(eventNumber), pCachedTrigger, weightPerEvent ); |
130 |
> |
} // end of loop over events |
131 |
|
|
132 |
< |
for( int binNumber=1; binNumber<pHistogram_->GetNbinsX(); ++binNumber ) |
147 |
< |
{ |
148 |
< |
(*pParameter_)=pHistogram_->GetBinCenter(binNumber); |
132 |
> |
} |
133 |
|
|
134 |
< |
// Scale accordingly any other parameters that should be scaled. |
135 |
< |
for( const auto& parameterScalingPair : otherParameterScalings_ ) *(parameterScalingPair.first)=parameterScalingPair.second*(*pParameter_); |
134 |
> |
void l1menu::TriggerRatePlot::addEvent( const l1menu::IEvent& event, const std::unique_ptr<l1menu::ICachedTrigger>& pCachedTrigger, float weightPerEvent ) |
135 |
> |
{ |
136 |
> |
// |
137 |
> |
// Loop over all of the bins and fill it if that threshold would |
138 |
> |
// have passed the trigger. |
139 |
> |
// |
140 |
> |
for( int binNumber=1; binNumber<pHistogram_->GetNbinsX(); ++binNumber ) |
141 |
> |
{ |
142 |
> |
(*pParameter_)=pHistogram_->GetBinLowEdge(binNumber); |
143 |
|
|
144 |
< |
if( pCachedTrigger->apply(event) ) // If the event passes the trigger |
145 |
< |
{ |
146 |
< |
pHistogram_->Fill( (*pParameter_), event.weight()*weightPerEvent ); |
147 |
< |
} |
148 |
< |
else break; |
149 |
< |
// Not sure if this "else break" is a good idea. I don't know if triggers |
150 |
< |
// will run their thresholds the other way. E.g. a trigger could require |
151 |
< |
// a minimum amount of energy in the event, in which case the higher |
152 |
< |
// bins will pass. |
153 |
< |
} // end of loop over histogram bins |
154 |
< |
} // end of loop over events |
144 |
> |
// Scale accordingly any other parameters that should be scaled. Remember that |
145 |
> |
// in parameterScalingPair, 'first' is a pointer to the threshold to be changed |
146 |
> |
// and 'second' is the ratio of the first threshold it should be. |
147 |
> |
for( const auto& parameterScalingPair : otherParameterScalings_ ) *(parameterScalingPair.first)=parameterScalingPair.second*(*pParameter_); |
148 |
> |
|
149 |
> |
if( pCachedTrigger->apply(event) ) // If the event passes the trigger |
150 |
> |
{ |
151 |
> |
pHistogram_->Fill( pHistogram_->GetBinCenter(binNumber), event.weight()*weightPerEvent ); |
152 |
> |
} |
153 |
> |
else break; |
154 |
> |
// Not sure if this "else break" is a good idea. I don't know if triggers |
155 |
> |
// will run their thresholds the other way. E.g. a trigger could require |
156 |
> |
// a minimum amount of energy in the event, in which case the higher |
157 |
> |
// bins will pass. |
158 |
> |
} // end of loop over histogram bins |
159 |
|
|
160 |
|
} |
161 |
|
|