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.6 by grimes, Sat Jun 29 16:14:45 2013 UTC vs.
Revision 1.9 by grimes, Fri Jul 5 13:54:44 2013 UTC

# Line 4 | Line 4
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>
# Line 103 | Line 102 | l1menu::TriggerRatePlot::~TriggerRatePlo
102          }
103   }
104  
105 < void l1menu::TriggerRatePlot::addEvent( const l1menu::L1TriggerDPGEvent& event )
105 > void l1menu::TriggerRatePlot::addEvent( const l1menu::IEvent& event )
106   {
107 <        // loop over all of the bins in the histogram, and see if the trigger passes
108 <        // for the value at the center of the bin.
110 <        for( int binNumber=1; binNumber<pHistogram_->GetNbinsX(); ++binNumber )
111 <        {
112 <                (*pParameter_)=pHistogram_->GetBinCenter(binNumber);
107 >        const l1menu::ISample& sample=event.sample();
108 >        float weightPerEvent=sample.eventRate()/sample.sumOfWeights();
109  
110 <                // Scale accordingly any other parameters that should be scaled.
111 <                for( const auto& parameterScalingPair : otherParameterScalings_ ) *(parameterScalingPair.first)=parameterScalingPair.second*(*pParameter_);
110 >        // For some implementations of ISample, it is significantly faster to
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 <                if( pTrigger_->apply( event ) )
118 <                {
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
123 <                // a minimum amount of energy in the event, in which case the higher
124 <                // bins will pass.
125 <        }
116 >        addEvent( event, pCachedTrigger, weightPerEvent );
117   }
118  
119   void l1menu::TriggerRatePlot::addSample( const l1menu::ISample& sample )
# Line 135 | Line 126 | void l1menu::TriggerRatePlot::addSample(
126  
127          for( size_t eventNumber=0; eventNumber<sample.numberOfEvents(); ++eventNumber )
128          {
129 <                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
129 >                addEvent( sample.getEvent(eventNumber), pCachedTrigger, weightPerEvent );
130          } // end of loop over events
131  
132   }
133  
134 < 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 )
134 > void l1menu::TriggerRatePlot::addEvent( const l1menu::IEvent& event, const std::unique_ptr<l1menu::ICachedTrigger>& pCachedTrigger, float weightPerEvent )
135   {
136 <        // Basically exactly the same as for the l1menu::L1TriggerDPGEvent version. I
137 <        // should probably template this.
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_->GetBinCenter(binNumber);
142 >                (*pParameter_)=pHistogram_->GetBinLowEdge(binNumber);
143  
144 <                // Scale accordingly any other parameters that should be scaled.
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( pTrigger_->apply( event ) )
149 >                if( pCachedTrigger->apply(event) ) // If the event passes the trigger
150                  {
151 <                        pHistogram_->Fill( (*pParameter_), event.weight() );
151 >                        pHistogram_->Fill( pHistogram_->GetBinCenter(binNumber), event.weight()*weightPerEvent );
152                  }
153 <        }
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  
162 + const l1menu::ITrigger& l1menu::TriggerRatePlot::getTrigger() const
163 + {
164 +        return *pTrigger_;
165   }
166  
167   TH1* l1menu::TriggerRatePlot::getPlot()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines