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.5 by grimes, Fri Jun 28 14:30:09 2013 UTC vs.
Revision 1.8 by grimes, Thu Jul 4 13:02:22 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>
12  
13 < l1menu::TriggerRatePlot::TriggerRatePlot( const l1menu::ITrigger& trigger, std::unique_ptr<TH1> pHistogram, const std::string versusParameter )
13 > #include <iostream>
14 >
15 > l1menu::TriggerRatePlot::TriggerRatePlot( const l1menu::ITrigger& trigger, std::unique_ptr<TH1> pHistogram, const std::string& versusParameter, const std::vector<std::string> scaledParameters )
16          : pHistogram_( std::move(pHistogram) ), versusParameter_(versusParameter), histogramOwnedByMe_(true)
17   {
18          // Take a copy of the trigger
# Line 18 | Line 20 | l1menu::TriggerRatePlot::TriggerRatePlot
20          pTrigger_=table.copyTrigger( trigger );
21  
22          // Make sure the versusParameter_ supplied is valid. If it's not then this call will
23 <        // throw an exception.
23 >        // throw an exception. Take a pointer to the parameter so I don't need to keep performing
24 >        // expensive string comparisons.
25          pParameter_=&pTrigger_->parameter(versusParameter_);
26  
27 +        // If any parameters have been requested to be scaled along with the versusParameter, figure
28 +        // out what the scaling should be and take a note of pointers.
29 +        for( const auto& parameterToScale : scaledParameters )
30 +        {
31 +                if( parameterToScale!=versusParameter_ )
32 +                {
33 +                        otherParameterScalings_.push_back( std::make_pair( &pTrigger_->parameter(parameterToScale), pTrigger_->parameter(parameterToScale)/(*pParameter_) ) );
34 +                }
35 +        }
36          // I want to make a note of the other parameters set for the trigger. As far as I know TH1
37          // has no way of adding annotations so I'll tag it on the end of the title.
38          std::stringstream description;
# Line 33 | Line 45 | l1menu::TriggerRatePlot::TriggerRatePlot
45          for( std::vector<std::string>::const_iterator iName=parameterNames.begin(); iName!=parameterNames.end(); ++iName )
46          {
47                  if( *iName==versusParameter ) continue; // Don't bother adding the parameter I'm plotting against
48 <                description << *iName << "=" << pTrigger_->parameter(*iName);
48 >
49 >                // First check to see if this is one of the parameters that are being scaled
50 >                if( std::find(scaledParameters.begin(),scaledParameters.end(),*iName)==scaledParameters.end() )
51 >                {
52 >                        // This parameter isn't being scaled, so write the absoulte value in the description
53 >                        description << *iName << "=" << pTrigger_->parameter(*iName);
54 >                }
55 >                else
56 >                {
57 >                        // This parameter is being scaled, so write what the scaling is in the description
58 >                        description << *iName << "=x*" << pTrigger_->parameter(*iName)/(*pParameter_);
59 >                }
60 >
61                  if( iName+1!=parameterNames.end() ) description << ","; // Add delimeter between parameter names
62          }
63          description << "]";
# Line 44 | Line 68 | l1menu::TriggerRatePlot::TriggerRatePlot
68  
69   l1menu::TriggerRatePlot::TriggerRatePlot( l1menu::TriggerRatePlot&& otherTriggerRatePlot ) noexcept
70          : pTrigger_( std::move(otherTriggerRatePlot.pTrigger_) ), pHistogram_( std::move(otherTriggerRatePlot.pHistogram_) ),
71 <          versusParameter_( std::move(otherTriggerRatePlot.versusParameter_) ), pParameter_(otherTriggerRatePlot.pParameter_),
72 <          histogramOwnedByMe_(histogramOwnedByMe_)
71 >          versusParameter_( std::move(otherTriggerRatePlot.versusParameter_) ), pParameter_(&pTrigger_->parameter(versusParameter_)),
72 >          otherParameterScalings_( std::move(otherTriggerRatePlot.otherParameterScalings_) ), histogramOwnedByMe_(histogramOwnedByMe_)
73   {
74          // No operation besides the initaliser list
75   }
# Line 61 | Line 85 | l1menu::TriggerRatePlot& l1menu::Trigger
85          pTrigger_=std::move(otherTriggerRatePlot.pTrigger_);
86          pHistogram_=std::move(otherTriggerRatePlot.pHistogram_);
87          versusParameter_=std::move(otherTriggerRatePlot.versusParameter_);
88 <        pParameter_=otherTriggerRatePlot.pParameter_;
88 >        pParameter_=&pTrigger_->parameter(versusParameter_);
89 >        otherParameterScalings_=std::move(otherTriggerRatePlot.otherParameterScalings_);
90          histogramOwnedByMe_=otherTriggerRatePlot.histogramOwnedByMe_;
91  
92          return *this;
# Line 77 | 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.
107 >        const l1menu::ISample& sample=event.sample();
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.
112 >        std::unique_ptr<l1menu::ICachedTrigger> pCachedTrigger=sample.createCachedTrigger( *pTrigger_ );
113 >
114          for( int binNumber=1; binNumber<pHistogram_->GetNbinsX(); ++binNumber )
115          {
116                  (*pParameter_)=pHistogram_->GetBinCenter(binNumber);
117 <                if( pTrigger_->apply( event ) )
117 >
118 >                // Scale accordingly any other parameters that should be scaled.
119 >                for( const auto& parameterScalingPair : otherParameterScalings_ ) *(parameterScalingPair.first)=parameterScalingPair.second*(*pParameter_);
120 >
121 >                if( pCachedTrigger->apply(event) )
122                  {
123 <                        pHistogram_->Fill( (*pParameter_), event.weight() );
123 >                        pHistogram_->Fill( (*pParameter_), event.weight()*weightPerEvent );
124                  }
125 <                // could put an "else break" in here, but I don't know if triggers
125 >                else break;
126 >                // Not sure if this "else break" is a good idea. I don't know if triggers
127                  // will run their thresholds the other way. E.g. a trigger could require
128                  // a minimum amount of energy in the event, in which case the higher
129                  // bins will pass.
# Line 110 | Line 145 | void l1menu::TriggerRatePlot::addSample(
145                  for( int binNumber=1; binNumber<pHistogram_->GetNbinsX(); ++binNumber )
146                  {
147                          (*pParameter_)=pHistogram_->GetBinCenter(binNumber);
148 +
149 +                        // Scale accordingly any other parameters that should be scaled.
150 +                        for( const auto& parameterScalingPair : otherParameterScalings_ ) *(parameterScalingPair.first)=parameterScalingPair.second*(*pParameter_);
151 +
152                          if( pCachedTrigger->apply(event) ) // If the event passes the trigger
153                          {
154                                  pHistogram_->Fill( (*pParameter_), event.weight()*weightPerEvent );
155                          }
156 <                        // could put an "else break" in here, but I don't know if triggers will
157 <                        // run their thresholds the other way. E.g. a trigger could require
156 >                        else break;
157 >                        // Not sure if this "else break" is a good idea. I don't know if triggers
158 >                        // will run their thresholds the other way. E.g. a trigger could require
159                          // a minimum amount of energy in the event, in which case the higher
160                          // bins will pass.
161                  } // end of loop over histogram bins
162          } // end of loop over events
163 +
164   }
165  
166   const l1menu::ITrigger& l1menu::TriggerRatePlot::getTrigger() const
# Line 127 | Line 168 | const l1menu::ITrigger& l1menu::TriggerR
168          return *pTrigger_;
169   }
170  
130 void l1menu::TriggerRatePlot::initiateForReducedSample( const l1menu::ReducedMenuSample& sample )
131 {
132        pTrigger_->initiateForReducedSample( sample );
133 }
134
135 void l1menu::TriggerRatePlot::addEvent( const l1menu::ReducedEvent& event )
136 {
137        // Basically exactly the same as for the l1menu::L1TriggerDPGEvent version. I
138        // should probably template this.
139        for( int binNumber=1; binNumber<pHistogram_->GetNbinsX(); ++binNumber )
140        {
141                (*pParameter_)=pHistogram_->GetBinCenter(binNumber);
142                if( pTrigger_->apply( event ) )
143                {
144                        pHistogram_->Fill( (*pParameter_), event.weight() );
145                }
146        }
147
148 }
149
171   TH1* l1menu::TriggerRatePlot::getPlot()
172   {
173          return pHistogram_.get();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines