CMS 3D CMS Logo

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)
 
template<typename T >
 PrescaleWeightProvider (const edm::ParameterSet &config, edm::ConsumesCollector &&iC, T &module)
 
template<typename T >
 PrescaleWeightProvider (const edm::ParameterSet &config, edm::ConsumesCollector &iC, T &module)
 
 ~PrescaleWeightProvider ()
 

Private Member Functions

void parseL1Seeds (const std::string &l1Seeds)
 
 PrescaleWeightProvider (const edm::ParameterSet &config, edm::ConsumesCollector &iC)
 

Private Attributes

bool configured_
 
std::vector< std::string > hltPaths_
 
std::unique_ptr< HLTPrescaleProviderhltPrescaleProvider_
 
bool init_
 
edm::InputTag l1GtTriggerMenuLiteTag_
 
edm::EDGetTokenT< L1GtTriggerMenuLitel1GtTriggerMenuLiteToken_
 
std::vector< std::string > l1SeedPaths_
 
edm::Handle< L1GtTriggerMenuLitetriggerMenuLite_
 
edm::InputTag triggerResultsTag_
 
edm::EDGetTokenT< edm::TriggerResultstriggerResultsToken_
 
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

Definition at line 50 of file PrescaleWeightProvider.h.

Constructor & Destructor Documentation

template<typename T >
PrescaleWeightProvider::PrescaleWeightProvider ( const edm::ParameterSet config,
edm::ConsumesCollector &&  iC,
T module 
)

Definition at line 90 of file PrescaleWeightProvider.h.

90  :
91  PrescaleWeightProvider( config, iC, module ) {
92 }
PrescaleWeightProvider(const edm::ParameterSet &config, edm::ConsumesCollector &&iC, T &module)
Definition: vlib.h:208
template<typename T >
PrescaleWeightProvider::PrescaleWeightProvider ( const edm::ParameterSet config,
edm::ConsumesCollector iC,
T module 
)

Definition at line 95 of file PrescaleWeightProvider.h.

References hltPrescaleProvider_.

95  :
96  PrescaleWeightProvider( config, iC ) {
97  hltPrescaleProvider_.reset(new HLTPrescaleProvider(config, iC, module));
98 }
PrescaleWeightProvider(const edm::ParameterSet &config, edm::ConsumesCollector &&iC, T &module)
std::unique_ptr< HLTPrescaleProvider > hltPrescaleProvider_
Definition: vlib.h:208
PrescaleWeightProvider::~PrescaleWeightProvider ( )
inline
PrescaleWeightProvider::PrescaleWeightProvider ( const edm::ParameterSet config,
edm::ConsumesCollector iC 
)
private

Definition at line 19 of file PrescaleWeightProvider.cc.

References configured_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), hltPaths_, edm::InRun, l1GtTriggerMenuLiteTag_, l1GtTriggerMenuLiteToken_, edm::InputTag::label(), edm::ConsumesCollector::mayConsume(), edm::InputTag::process(), triggerResultsTag_, triggerResultsToken_, and verbosity_.

21 : init_(false)
22 , verbosity_( 0 )
23 , triggerResultsTag_( "TriggerResults::HLT" )
25 , l1GtTriggerMenuLiteTag_( "l1GtTriggerMenuLite" )
27 {
28 
29  hltPaths_.clear();
30  if ( config.exists( "prescaleWeightVerbosityLevel" ) ) verbosity_ = config.getParameter< unsigned >( "prescaleWeightVerbosityLevel" );
31  if ( config.exists( "prescaleWeightTriggerResults" ) ) triggerResultsTag_ = config.getParameter< edm::InputTag >( "prescaleWeightTriggerResults" );
32  if ( config.exists( "prescaleWeightL1GtTriggerMenuLite" ) ) l1GtTriggerMenuLiteTag_ = config.getParameter< edm::InputTag >( "prescaleWeightL1GtTriggerMenuLite" );
33  if ( config.exists( "prescaleWeightHltPaths" ) ) hltPaths_ = config.getParameter< std::vector< std::string > >( "prescaleWeightHltPaths" );
34 
35  configured_ = true;
36  if ( triggerResultsTag_.process().empty() ) {
37  configured_ = false;
38  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "Process name not configured via TriggerResults InputTag";
39  } else if ( triggerResultsTag_.label().empty() ) {
40  configured_ = false;
41  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "TriggerResults label not configured";
42  } else if ( l1GtTriggerMenuLiteTag_.label().empty() ) {
43  configured_ = false;
44  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "L1GtTriggerMenuLite label not configured";
45  } else if ( hltPaths_.empty() ) {
46  configured_ = false;
47  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "HLT paths of interest not configured";
48  }
49  if ( configured_ ) {
52  }
53 
54 }
edm::EDGetTokenT< L1GtTriggerMenuLite > l1GtTriggerMenuLiteToken_
T getParameter(std::string const &) const
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< std::string > hltPaths_
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
std::string const & label() const
Definition: InputTag.h:36
std::string const & process() const
Definition: InputTag.h:40

Member Function Documentation

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

Definition at line 56 of file PrescaleWeightProvider.cc.

References configured_, edm::Run::getByToken(), hltPrescaleProvider_, init_, edm::HandleBase::isValid(), l1GtTriggerMenuLiteTag_, l1GtTriggerMenuLiteToken_, edm::InputTag::label(), edm::InputTag::process(), HLTConfigProvider::size(), triggerMenuLite_, triggerResultsTag_, and verbosity_.

Referenced by BPHMonitor::bookHistograms().

57 {
58 
59  init_ = true;
60 
61  if ( ! configured_ ) {
62  init_ = false;
63  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "Run initialisation failed due to failing configuration";
64  return;
65  }
66 
67  HLTConfigProvider const& hltConfig = hltPrescaleProvider_->hltConfigProvider();
68  bool hltChanged( false );
69  if ( ! hltPrescaleProvider_->init( run, setup, triggerResultsTag_.process(), hltChanged ) ) {
70  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "HLT config initialization error with process name \"" << triggerResultsTag_.process() << "\"";
71  init_ = false;
72  } else if ( hltConfig.size() <= 0 ) {
73  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "HLT config size error";
74  init_ = false;
75  } else if ( hltChanged ) {
76  if ( verbosity_ > 0 ) edm::LogInfo( "PrescaleWeightProvider" ) << "HLT configuration changed";
77  }
78  if ( ! init_ ) return;
79 
81  if ( ! triggerMenuLite_.isValid() ) {
82  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "L1GtTriggerMenuLite with label \"" << l1GtTriggerMenuLiteTag_.label() << "\" not found";
83  init_ = false;
84  }
85 
86 }
unsigned int size() const
number of trigger paths in trigger table
edm::EDGetTokenT< L1GtTriggerMenuLite > l1GtTriggerMenuLiteToken_
edm::Handle< L1GtTriggerMenuLite > triggerMenuLite_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Run.h:287
std::unique_ptr< HLTPrescaleProvider > hltPrescaleProvider_
bool isValid() const
Definition: HandleBase.h:74
std::string const & label() const
Definition: InputTag.h:36
std::string const & process() const
Definition: InputTag.h:40
void PrescaleWeightProvider::parseL1Seeds ( const std::string &  l1Seeds)
private

Definition at line 175 of file PrescaleWeightProvider.cc.

References l1SeedPaths_, AlCaHLTBitMon_QueryRunRegistry::string, and verbosity_.

Referenced by prescaleWeight().

176 {
177  l1SeedPaths_.clear();
178  std::stringstream ss( l1Seeds );
179  std::string buf;
180 
181  while ( ss.good() && ! ss.eof() ){
182  ss >> buf;
183  if ( buf[0] == '(' || buf[ buf.size() - 1 ] == ')' || buf == "AND" || buf == "NOT" ){
184  l1SeedPaths_.clear();
185  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider::parseL1Seeds" ) << "Only supported logical expression is OR";
186  return;
187  }
188  else if (buf == "OR") continue;
189  else l1SeedPaths_.push_back( buf );
190  }
191 
192 }
std::vector< std::string > l1SeedPaths_
int PrescaleWeightProvider::prescaleWeight ( const edm::Event event,
const edm::EventSetup setup 
)

Definition at line 89 of file PrescaleWeightProvider.cc.

References edm::HLTGlobalStatus::accept(), L1GtUtils::decision(), edm::InputTag::encode(), L1GtTriggerMenuLite::gtTechTrigName(), HLTConfigProvider::hltL1GTSeeds(), TriggerAnalyzer::hltPath, hltPaths_, hltPrescaleProvider_, init_, edm::HandleBase::isValid(), l1SeedPaths_, parseL1Seeds(), L1GtUtils::prescaleFactor(), HLTConfigProvider::size(), AlCaHLTBitMon_QueryRunRegistry::string, HLTConfigProvider::triggerIndex(), triggerMenuLite_, triggerResults, triggerResultsTag_, triggerResultsToken_, interactiveExample::ui, verbosity_, and mps_merge::weight.

Referenced by BPHMonitor::analyze().

90 {
91  if ( ! init_ ) return 1;
92 
93  // L1
94  L1GtUtils const& l1GtUtils = hltPrescaleProvider_->l1GtUtils();
95 
96  // HLT
97  HLTConfigProvider const& hltConfig = hltPrescaleProvider_->hltConfigProvider();
98 
100  event.getByToken( triggerResultsToken_, triggerResults);
101  if( ! triggerResults.isValid() ) {
102  if ( verbosity_ > 0 ) edm::LogError("PrescaleWeightProvider::prescaleWeight") << "TriggerResults product not found for InputTag \"" << triggerResultsTag_.encode() << "\"";
103  return 1;
104  }
105 
106  const int SENTINEL( -1 );
107  int weight( SENTINEL );
108 
109  for ( unsigned ui = 0; ui < hltPaths_.size(); ui++ ) {
110  const std::string hltPath( hltPaths_.at( ui ) );
111  unsigned hltIndex( hltConfig.triggerIndex( hltPath ) );
112  if ( hltIndex == hltConfig.size() ) {
113  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider::prescaleWeight" ) << "HLT path \"" << hltPath << "\" does not exist";
114  continue;
115  }
116  if ( ! triggerResults->accept( hltIndex ) ) continue;
117 
118  const std::vector< std::pair < bool, std::string > >& level1Seeds = hltConfig.hltL1GTSeeds( hltPath );
119  if ( level1Seeds.size() != 1 ) {
120  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider::prescaleWeight" ) << "HLT path \"" << hltPath << "\" provides too many L1 seeds";
121  return 1;
122  }
123  parseL1Seeds( level1Seeds.at( 0 ).second );
124  if ( l1SeedPaths_.empty() ){
125  if ( verbosity_ > 0 ) edm::LogWarning("PrescaleWeightProvider::prescaleWeight") << "Failed to parse L1 seeds for HLT path \"" << hltPath << "\"";
126  continue;
127  }
128 
129  int l1Prescale( SENTINEL );
130  for ( unsigned uj = 0; uj < l1SeedPaths_.size(); uj++ ) {
131  int l1TempPrescale( SENTINEL );
132  int errorCode( 0 );
133  if ( level1Seeds.at( 0 ).first ) { // technical triggers
134  unsigned techBit( atoi( l1SeedPaths_.at( uj ).c_str() ) );
135  const std::string techName( *( triggerMenuLite_->gtTechTrigName( techBit, errorCode ) ) );
136  if ( errorCode != 0 ) continue;
137  if ( ! l1GtUtils.decision( event, techName, errorCode ) ) continue;
138  if ( errorCode != 0 ) continue;
139  l1TempPrescale = l1GtUtils.prescaleFactor( event, techName, errorCode );
140  if ( errorCode != 0 ) continue;
141  }
142  else { // algorithmic triggers
143  if ( ! l1GtUtils.decision( event, l1SeedPaths_.at( uj ), errorCode ) ) continue;
144  if ( errorCode != 0 ) continue;
145  l1TempPrescale = l1GtUtils.prescaleFactor( event, l1SeedPaths_.at( uj ), errorCode );
146  if ( errorCode != 0 ) continue;
147  }
148  if ( l1TempPrescale > 0 ){
149  if ( l1Prescale == SENTINEL || l1Prescale > l1TempPrescale ) l1Prescale = l1TempPrescale;
150  }
151  }
152  if ( l1Prescale == SENTINEL ){
153  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider::prescaleWeight" ) << "Unable to find the L1 prescale for HLT path \"" << hltPath << "\"";
154  continue;
155  }
156 
157  int hltPrescale( hltPrescaleProvider_->prescaleValue( event, setup, hltPath ) );
158 
159  if ( hltPrescale * l1Prescale > 0 ) {
160  if ( weight == SENTINEL || weight > hltPrescale * l1Prescale ) {
161  weight = hltPrescale * l1Prescale;
162  }
163  }
164  }
165 
166  if ( weight == SENTINEL ){
167  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider::prescaleWeight" ) << "No valid weight for any requested HLT path, returning default weight of 1";
168  return 1;
169  }
170  return weight;
171 
172 }
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
bool accept() const
Has at least one path accepted the event?
const bool decision(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
Definition: L1GtUtils.cc:1208
Definition: weight.py:1
std::string encode() const
Definition: InputTag.cc:166
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_
const std::string * gtTechTrigName(const unsigned int bitNumber, int &errorCode) const
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
std::unique_ptr< HLTPrescaleProvider > hltPrescaleProvider_
static std::string const triggerResults
Definition: EdmProvDump.cc:41
bool isValid() const
Definition: HandleBase.h:74
void parseL1Seeds(const std::string &l1Seeds)
const int prescaleFactor(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
return prescale factor for a given algorithm or technical trigger
Definition: L1GtUtils.cc:1223

Member Data Documentation

bool PrescaleWeightProvider::configured_
private

Definition at line 52 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

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

Definition at line 65 of file PrescaleWeightProvider.h.

Referenced by prescaleWeight(), and PrescaleWeightProvider().

std::unique_ptr<HLTPrescaleProvider> PrescaleWeightProvider::hltPrescaleProvider_
private

Definition at line 54 of file PrescaleWeightProvider.h.

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

bool PrescaleWeightProvider::init_
private

Definition at line 53 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

edm::InputTag PrescaleWeightProvider::l1GtTriggerMenuLiteTag_
private

Definition at line 63 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

edm::EDGetTokenT< L1GtTriggerMenuLite > PrescaleWeightProvider::l1GtTriggerMenuLiteToken_
private

Definition at line 64 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

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

Definition at line 57 of file PrescaleWeightProvider.h.

Referenced by parseL1Seeds(), and prescaleWeight().

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

Definition at line 55 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

edm::InputTag PrescaleWeightProvider::triggerResultsTag_
private

Definition at line 61 of file PrescaleWeightProvider.h.

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

edm::EDGetTokenT< edm::TriggerResults > PrescaleWeightProvider::triggerResultsToken_
private

Definition at line 62 of file PrescaleWeightProvider.h.

Referenced by prescaleWeight(), and PrescaleWeightProvider().

unsigned PrescaleWeightProvider::verbosity_
private