CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
PrescaleWeightProvider Class Reference

This class takes a vector of HLT paths and returns a weight based on their HLT and L1 prescales. The weight is equal to the lowest combined (L1*HLT) prescale of the selected paths. More...

#include "CommonTools/TriggerUtils/interface/PrescaleWeightProvider.h"

Public Member Functions

void initRun (const edm::Run &run, const edm::EventSetup &setup)
 
int prescaleWeight (const edm::Event &event, const edm::EventSetup &setup)
 
 PrescaleWeightProvider (const edm::ParameterSet &config)
 
 ~PrescaleWeightProvider ()
 

Private Member Functions

void parseL1Seeds (const std::string &l1Seeds)
 

Private Attributes

bool configured_
 
HLTConfigProvider hltConfig_
 
std::vector< std::string > hltPaths_
 
bool init_
 
edm::InputTag l1GtTriggerMenuLite_
 
std::vector< std::string > l1SeedPaths_
 
edm::Handle< L1GtTriggerMenuLitetriggerMenuLite_
 
edm::InputTag triggerResults_
 
unsigned verbosity_
 

Detailed Description

This class takes a vector of HLT paths and returns a weight based on their HLT and L1 prescales. The weight is equal to the lowest combined (L1*HLT) prescale of the selected paths.

Author
Aram Avetisyan
Version
Id:
PrescaleWeightProvider.h,v 1.1 2010/08/17 17:15:26 vadler Exp

Definition at line 37 of file PrescaleWeightProvider.h.

Constructor & Destructor Documentation

PrescaleWeightProvider::PrescaleWeightProvider ( const edm::ParameterSet config)

Definition at line 17 of file PrescaleWeightProvider.cc.

References configured_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), hltPaths_, l1GtTriggerMenuLite_, edm::InputTag::label(), edm::InputTag::process(), triggerResults_, and verbosity_.

19 : verbosity_( 0 )
20 , triggerResults_( "TriggerResults::HLT" )
21 , l1GtTriggerMenuLite_( "l1GtTriggerMenuLite" )
22 {
23 
24  hltPaths_.clear();
25  if ( config.exists( "prescaleWeightVerbosityLevel" ) ) verbosity_ = config.getParameter< unsigned >( "prescaleWeightVerbosityLevel" );
26  if ( config.exists( "prescaleWeightTriggerResults" ) ) triggerResults_ = config.getParameter< edm::InputTag >( "prescaleWeightTriggerResults" );
27  if ( config.exists( "prescaleWeightL1GtTriggerMenuLite" ) ) l1GtTriggerMenuLite_ = config.getParameter< edm::InputTag >( "prescaleWeightL1GtTriggerMenuLite" );
28  if ( config.exists( "prescaleWeightHltPaths" ) ) hltPaths_ = config.getParameter< std::vector< std::string > >( "prescaleWeightHltPaths" );
29 
30  configured_ = true;
31  if ( triggerResults_.process().empty() ) {
32  configured_ = false;
33  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "Process name not configured via TriggerResults InputTag";
34  } else if ( triggerResults_.label().empty() ) {
35  configured_ = false;
36  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "TriggerResults label not configured";
37  } else if ( l1GtTriggerMenuLite_.label().empty() ) {
38  configured_ = false;
39  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "L1GtTriggerMenuLite label not configured";
40  } else if ( hltPaths_.empty() ) {
41  configured_ = false;
42  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "HLT paths of interest not configured";
43  }
44 
45 }
T getParameter(std::string const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< std::string > hltPaths_
std::string const & label() const
Definition: InputTag.h:25
std::string const & process() const
Definition: InputTag.h:29
PrescaleWeightProvider::~PrescaleWeightProvider ( )
inline

Definition at line 55 of file PrescaleWeightProvider.h.

55 {}

Member Function Documentation

void PrescaleWeightProvider::initRun ( const edm::Run run,
const edm::EventSetup setup 
)

Definition at line 47 of file PrescaleWeightProvider.cc.

References configured_, edm::Run::getByLabel(), hltConfig_, HLTConfigProvider::init(), init_, edm::HandleBase::isValid(), l1GtTriggerMenuLite_, edm::InputTag::label(), edm::InputTag::process(), HLTConfigProvider::size(), triggerMenuLite_, triggerResults_, and verbosity_.

48 {
49 
50  init_ = true;
51 
52  if ( ! configured_ ) {
53  init_ = false;
54  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "Run initialisation failed due to failing configuration";
55  return;
56  }
57 
58  bool hltChanged( false );
59  if ( ! hltConfig_.init( run, setup, triggerResults_.process(), hltChanged ) ) {
60  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "HLT config initialization error with process name \"" << triggerResults_.process() << "\"";
61  init_ = false;
62  } else if ( hltConfig_.size() <= 0 ) {
63  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "HLT config size error";
64  init_ = false;
65  } else if ( hltChanged ) {
66  if ( verbosity_ > 0 ) edm::LogInfo( "PrescaleWeightProvider" ) << "HLT configuration changed";
67  }
68  if ( ! init_ ) return;
69 
71  if ( ! triggerMenuLite_.isValid() ) {
72  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "L1GtTriggerMenuLite with label \"" << l1GtTriggerMenuLite_.label() << "\" not found";
73  init_ = false;
74  }
75 
76 }
unsigned int size() const
number of trigger paths in trigger table
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:174
edm::Handle< L1GtTriggerMenuLite > triggerMenuLite_
bool isValid() const
Definition: HandleBase.h:76
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
std::string const & label() const
Definition: InputTag.h:25
std::string const & process() const
Definition: InputTag.h:29
void PrescaleWeightProvider::parseL1Seeds ( const std::string &  l1Seeds)
private

Definition at line 164 of file PrescaleWeightProvider.cc.

References l1SeedPaths_, and verbosity_.

Referenced by prescaleWeight().

165 {
166  l1SeedPaths_.clear();
167  std::stringstream ss( l1Seeds );
168  std::string buf;
169 
170  while ( ss.good() && ! ss.eof() ){
171  ss >> buf;
172  if ( buf[0] == '(' || buf[ buf.size() - 1 ] == ')' || buf == "AND" || buf == "NOT" ){
173  l1SeedPaths_.clear();
174  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider::parseL1Seeds" ) << "Only supported logical expression is OR";
175  return;
176  }
177  else if (buf == "OR") continue;
178  else l1SeedPaths_.push_back( buf );
179  }
180 
181 }
std::vector< std::string > l1SeedPaths_
int PrescaleWeightProvider::prescaleWeight ( const edm::Event event,
const edm::EventSetup setup 
)

Definition at line 79 of file PrescaleWeightProvider.cc.

References L1GtUtils::decision(), edm::InputTag::encode(), hltConfig_, HLTConfigProvider::hltL1GTSeeds(), hltPaths_, init_, edm::HandleBase::isValid(), l1SeedPaths_, parseL1Seeds(), L1GtUtils::prescaleFactor(), HLTConfigProvider::prescaleValue(), L1GtUtils::retrieveL1EventSetup(), HLTConfigProvider::size(), HLTConfigProvider::triggerIndex(), triggerMenuLite_, triggerResults_, interactiveExample::ui, verbosity_, and CommonMethods::weight().

80 {
81  if ( ! init_ ) return 1;
82 
83  // L1
84  L1GtUtils l1GtUtils;
85  l1GtUtils.retrieveL1EventSetup( setup );
86 
87  // HLT
89  event.getByLabel( triggerResults_, triggerResults);
90  if( ! triggerResults.isValid() ) {
91  if ( verbosity_ > 0 ) edm::LogError("PrescaleWeightProvider::prescaleWeight") << "TriggerResults product not found for InputTag \"" << triggerResults_.encode() << "\"";
92  return 1;
93  }
94 
95  const int SENTINEL( -1 );
96  int weight( SENTINEL );
97 
98  for ( unsigned ui = 0; ui < hltPaths_.size(); ui++ ) {
99  const std::string hltPath( hltPaths_.at( ui ) );
100  unsigned hltIndex( hltConfig_.triggerIndex( hltPath ) );
101  if ( hltIndex == hltConfig_.size() ) {
102  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider::prescaleWeight" ) << "HLT path \"" << hltPath << "\" does not exist";
103  continue;
104  }
105  if ( ! triggerResults->accept( hltIndex ) ) continue;
106 
107  const std::vector< std::pair < bool, std::string > > level1Seeds = hltConfig_.hltL1GTSeeds( hltPath );
108  if ( level1Seeds.size() != 1 ) {
109  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider::prescaleWeight" ) << "HLT path \"" << hltPath << "\" provides too many L1 seeds";
110  return 1;
111  }
112  parseL1Seeds( level1Seeds.at( 0 ).second );
113  if ( l1SeedPaths_.empty() ){
114  if ( verbosity_ > 0 ) edm::LogWarning("PrescaleWeightProvider::prescaleWeight") << "Failed to parse L1 seeds for HLT path \"" << hltPath << "\"";
115  continue;
116  }
117 
118  int l1Prescale( SENTINEL );
119  for ( unsigned uj = 0; uj < l1SeedPaths_.size(); uj++ ) {
120  int l1TempPrescale( SENTINEL );
121  int errorCode( 0 );
122  if ( level1Seeds.at( 0 ).first ) { // technical triggers
123  unsigned techBit( atoi( l1SeedPaths_.at( uj ).c_str() ) );
124  const std::string techName( *( triggerMenuLite_->gtTechTrigName( techBit, errorCode ) ) );
125  if ( errorCode != 0 ) continue;
126  if ( ! l1GtUtils.decision( event, techName, errorCode ) ) continue;
127  if ( errorCode != 0 ) continue;
128  l1TempPrescale = l1GtUtils.prescaleFactor( event, techName, errorCode );
129  if ( errorCode != 0 ) continue;
130  }
131  else { // algorithmic triggers
132  if ( ! l1GtUtils.decision( event, l1SeedPaths_.at( uj ), errorCode ) ) continue;
133  if ( errorCode != 0 ) continue;
134  l1TempPrescale = l1GtUtils.prescaleFactor( event, l1SeedPaths_.at( uj ), errorCode );
135  if ( errorCode != 0 ) continue;
136  }
137  if ( l1TempPrescale > 0 ){
138  if ( l1Prescale == SENTINEL || l1Prescale > l1TempPrescale ) l1Prescale = l1TempPrescale;
139  }
140  }
141  if ( l1Prescale == SENTINEL ){
142  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider::prescaleWeight" ) << "Unable to find the L1 prescale for HLT path \"" << hltPath << "\"";
143  continue;
144  }
145 
146  int hltPrescale( hltConfig_.prescaleValue( event, setup, hltPath ) );
147 
148  if ( hltPrescale * l1Prescale > 0 ) {
149  if ( weight == SENTINEL || weight > hltPrescale * l1Prescale ) {
150  weight = hltPrescale * l1Prescale;
151  }
152  }
153  }
154 
155  if ( weight == SENTINEL ){
156  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider::prescaleWeight" ) << "No valid weight for any requested HLT path, returning default weight of 1";
157  return 1;
158  }
159  return weight;
160 
161 }
unsigned int size() const
number of trigger paths in trigger table
edm::Handle< L1GtTriggerMenuLite > triggerMenuLite_
std::vector< std::string > l1SeedPaths_
const std::vector< std::vector< std::pair< bool, std::string > > > & hltL1GTSeeds() const
std::string encode() const
Definition: InputTag.cc:72
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
std::vector< std::string > hltPaths_
unsigned int prescaleValue(unsigned int set, const std::string &trigger) const
HLT prescale value in specific prescale set for a specific trigger path.
const bool decision(const edm::Event &iEvent, const edm::InputTag &l1GtRecordInputTag, const edm::InputTag &l1GtReadoutRecordInputTag, const std::string &nameAlgoTechTrig, int &errorCode) const
Definition: L1GtUtils.cc:1184
void retrieveL1EventSetup(const edm::EventSetup &)
retrieve all the relevant L1 trigger event setup records and cache them to improve the speed ...
Definition: L1GtUtils.cc:107
bool isValid() const
Definition: HandleBase.h:76
const int prescaleFactor(const edm::Event &iEvent, const edm::InputTag &l1GtRecordInputTag, const edm::InputTag &l1GtReadoutRecordInputTag, const std::string &nameAlgoTechTrig, int &errorCode) const
return prescale factor for a given algorithm or technical trigger
Definition: L1GtUtils.cc:1221
void parseL1Seeds(const std::string &l1Seeds)

Member Data Documentation

bool PrescaleWeightProvider::configured_
private

Definition at line 39 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

HLTConfigProvider PrescaleWeightProvider::hltConfig_
private

Definition at line 41 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

std::vector< std::string > PrescaleWeightProvider::hltPaths_
private

Definition at line 50 of file PrescaleWeightProvider.h.

Referenced by prescaleWeight(), and PrescaleWeightProvider().

bool PrescaleWeightProvider::init_
private

Definition at line 40 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

edm::InputTag PrescaleWeightProvider::l1GtTriggerMenuLite_
private

Definition at line 49 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

std::vector< std::string > PrescaleWeightProvider::l1SeedPaths_
private

Definition at line 44 of file PrescaleWeightProvider.h.

Referenced by parseL1Seeds(), and prescaleWeight().

edm::Handle< L1GtTriggerMenuLite > PrescaleWeightProvider::triggerMenuLite_
private

Definition at line 42 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

edm::InputTag PrescaleWeightProvider::triggerResults_
private

Definition at line 48 of file PrescaleWeightProvider.h.

Referenced by initRun(), prescaleWeight(), and PrescaleWeightProvider().

unsigned PrescaleWeightProvider::verbosity_
private