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, edm::ConsumesCollector &&iC)
 
 PrescaleWeightProvider (const edm::ParameterSet &config, edm::ConsumesCollector &iC)
 
 ~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 l1GtTriggerMenuLiteTag_
 
edm::EDGetTokenT
< L1GtTriggerMenuLite
l1GtTriggerMenuLiteToken_
 
std::vector< std::string > l1SeedPaths_
 
edm::Handle< L1GtTriggerMenuLitetriggerMenuLite_
 
edm::InputTag triggerResultsTag_
 
edm::EDGetTokenT
< edm::TriggerResults
triggerResultsToken_
 
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 35 of file PrescaleWeightProvider.h.

Constructor & Destructor Documentation

PrescaleWeightProvider::PrescaleWeightProvider ( const edm::ParameterSet config,
edm::ConsumesCollector &&  iC 
)
inline

Definition at line 54 of file PrescaleWeightProvider.h.

54 : PrescaleWeightProvider( config, iC ) {}; // to be called from the ED module's c'tor
PrescaleWeightProvider(const edm::ParameterSet &config, edm::ConsumesCollector &&iC)
PrescaleWeightProvider::PrescaleWeightProvider ( const edm::ParameterSet config,
edm::ConsumesCollector iC 
)

Definition at line 16 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_.

18 : verbosity_( 0 )
19 , triggerResultsTag_( "TriggerResults::HLT" )
21 , l1GtTriggerMenuLiteTag_( "l1GtTriggerMenuLite" )
23 {
24 
25  hltPaths_.clear();
26  if ( config.exists( "prescaleWeightVerbosityLevel" ) ) verbosity_ = config.getParameter< unsigned >( "prescaleWeightVerbosityLevel" );
27  if ( config.exists( "prescaleWeightTriggerResults" ) ) triggerResultsTag_ = config.getParameter< edm::InputTag >( "prescaleWeightTriggerResults" );
28  if ( config.exists( "prescaleWeightL1GtTriggerMenuLite" ) ) l1GtTriggerMenuLiteTag_ = config.getParameter< edm::InputTag >( "prescaleWeightL1GtTriggerMenuLite" );
29  if ( config.exists( "prescaleWeightHltPaths" ) ) hltPaths_ = config.getParameter< std::vector< std::string > >( "prescaleWeightHltPaths" );
30 
31  configured_ = true;
32  if ( triggerResultsTag_.process().empty() ) {
33  configured_ = false;
34  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "Process name not configured via TriggerResults InputTag";
35  } else if ( triggerResultsTag_.label().empty() ) {
36  configured_ = false;
37  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "TriggerResults label not configured";
38  } else if ( l1GtTriggerMenuLiteTag_.label().empty() ) {
39  configured_ = false;
40  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "L1GtTriggerMenuLite label not configured";
41  } else if ( hltPaths_.empty() ) {
42  configured_ = false;
43  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "HLT paths of interest not configured";
44  }
45  if ( configured_ ) {
48  }
49 
50 }
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:42
std::string const & process() const
Definition: InputTag.h:46
PrescaleWeightProvider::~PrescaleWeightProvider ( )
inline

Definition at line 56 of file PrescaleWeightProvider.h.

56 {}

Member Function Documentation

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

Definition at line 52 of file PrescaleWeightProvider.cc.

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

Referenced by AnotherPrimaryVertexAnalyzer::beginRun().

53 {
54 
55  init_ = true;
56 
57  if ( ! configured_ ) {
58  init_ = false;
59  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "Run initialisation failed due to failing configuration";
60  return;
61  }
62 
63  bool hltChanged( false );
64  if ( ! hltConfig_.init( run, setup, triggerResultsTag_.process(), hltChanged ) ) {
65  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "HLT config initialization error with process name \"" << triggerResultsTag_.process() << "\"";
66  init_ = false;
67  } else if ( hltConfig_.size() <= 0 ) {
68  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "HLT config size error";
69  init_ = false;
70  } else if ( hltChanged ) {
71  if ( verbosity_ > 0 ) edm::LogInfo( "PrescaleWeightProvider" ) << "HLT configuration changed";
72  }
73  if ( ! init_ ) return;
74 
76  if ( ! triggerMenuLite_.isValid() ) {
77  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "L1GtTriggerMenuLite with label \"" << l1GtTriggerMenuLiteTag_.label() << "\" not found";
78  init_ = false;
79  }
80 
81 }
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:239
bool isValid() const
Definition: HandleBase.h:76
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
std::string const & label() const
Definition: InputTag.h:42
std::string const & process() const
Definition: InputTag.h:46
void PrescaleWeightProvider::parseL1Seeds ( const std::string &  l1Seeds)
private

Definition at line 169 of file PrescaleWeightProvider.cc.

References l1SeedPaths_, AlCaHLTBitMon_QueryRunRegistry::string, and verbosity_.

Referenced by prescaleWeight().

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

Definition at line 84 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(), AlCaHLTBitMon_QueryRunRegistry::string, HLTConfigProvider::triggerIndex(), triggerMenuLite_, triggerResults, triggerResultsTag_, triggerResultsToken_, interactiveExample::ui, verbosity_, and histoStyle::weight.

Referenced by AnotherPrimaryVertexAnalyzer::analyze().

85 {
86  if ( ! init_ ) return 1;
87 
88  // L1
89  L1GtUtils l1GtUtils;
90  l1GtUtils.retrieveL1EventSetup( setup );
91 
92  // HLT
94  event.getByToken( triggerResultsToken_, triggerResults);
95  if( ! triggerResults.isValid() ) {
96  if ( verbosity_ > 0 ) edm::LogError("PrescaleWeightProvider::prescaleWeight") << "TriggerResults product not found for InputTag \"" << triggerResultsTag_.encode() << "\"";
97  return 1;
98  }
99 
100  const int SENTINEL( -1 );
101  int weight( SENTINEL );
102 
103  for ( unsigned ui = 0; ui < hltPaths_.size(); ui++ ) {
104  const std::string hltPath( hltPaths_.at( ui ) );
105  unsigned hltIndex( hltConfig_.triggerIndex( hltPath ) );
106  if ( hltIndex == hltConfig_.size() ) {
107  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider::prescaleWeight" ) << "HLT path \"" << hltPath << "\" does not exist";
108  continue;
109  }
110  if ( ! triggerResults->accept( hltIndex ) ) continue;
111 
112  const std::vector< std::pair < bool, std::string > > level1Seeds = hltConfig_.hltL1GTSeeds( hltPath );
113  if ( level1Seeds.size() != 1 ) {
114  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider::prescaleWeight" ) << "HLT path \"" << hltPath << "\" provides too many L1 seeds";
115  return 1;
116  }
117  parseL1Seeds( level1Seeds.at( 0 ).second );
118  if ( l1SeedPaths_.empty() ){
119  if ( verbosity_ > 0 ) edm::LogWarning("PrescaleWeightProvider::prescaleWeight") << "Failed to parse L1 seeds for HLT path \"" << hltPath << "\"";
120  continue;
121  }
122 
123  int l1Prescale( SENTINEL );
124  for ( unsigned uj = 0; uj < l1SeedPaths_.size(); uj++ ) {
125  int l1TempPrescale( SENTINEL );
126  int errorCode( 0 );
127  if ( level1Seeds.at( 0 ).first ) { // technical triggers
128  unsigned techBit( atoi( l1SeedPaths_.at( uj ).c_str() ) );
129  const std::string techName( *( triggerMenuLite_->gtTechTrigName( techBit, errorCode ) ) );
130  if ( errorCode != 0 ) continue;
131  if ( ! l1GtUtils.decision( event, techName, errorCode ) ) continue;
132  if ( errorCode != 0 ) continue;
133  l1TempPrescale = l1GtUtils.prescaleFactor( event, techName, errorCode );
134  if ( errorCode != 0 ) continue;
135  }
136  else { // algorithmic triggers
137  if ( ! l1GtUtils.decision( event, l1SeedPaths_.at( uj ), errorCode ) ) continue;
138  if ( errorCode != 0 ) continue;
139  l1TempPrescale = l1GtUtils.prescaleFactor( event, l1SeedPaths_.at( uj ), errorCode );
140  if ( errorCode != 0 ) continue;
141  }
142  if ( l1TempPrescale > 0 ){
143  if ( l1Prescale == SENTINEL || l1Prescale > l1TempPrescale ) l1Prescale = l1TempPrescale;
144  }
145  }
146  if ( l1Prescale == SENTINEL ){
147  if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider::prescaleWeight" ) << "Unable to find the L1 prescale for HLT path \"" << hltPath << "\"";
148  continue;
149  }
150 
151  int hltPrescale( hltConfig_.prescaleValue( event, setup, hltPath ) );
152 
153  if ( hltPrescale * l1Prescale > 0 ) {
154  if ( weight == SENTINEL || weight > hltPrescale * l1Prescale ) {
155  weight = hltPrescale * l1Prescale;
156  }
157  }
158  }
159 
160  if ( weight == SENTINEL ){
161  if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider::prescaleWeight" ) << "No valid weight for any requested HLT path, returning default weight of 1";
162  return 1;
163  }
164  return weight;
165 
166 }
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:164
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:1448
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
void retrieveL1EventSetup(const edm::EventSetup &)
retrieve all the relevant L1 trigger event setup records and cache them to improve the speed ...
Definition: L1GtUtils.cc:111
static std::string const triggerResults
Definition: EdmProvDump.cc:41
bool isValid() const
Definition: HandleBase.h:76
int weight
Definition: histoStyle.py:50
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:1485
void parseL1Seeds(const std::string &l1Seeds)

Member Data Documentation

bool PrescaleWeightProvider::configured_
private

Definition at line 37 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

HLTConfigProvider PrescaleWeightProvider::hltConfig_
private

Definition at line 39 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 38 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

edm::InputTag PrescaleWeightProvider::l1GtTriggerMenuLiteTag_
private

Definition at line 48 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

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

Definition at line 49 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

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

Definition at line 42 of file PrescaleWeightProvider.h.

Referenced by parseL1Seeds(), and prescaleWeight().

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

Definition at line 40 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

edm::InputTag PrescaleWeightProvider::triggerResultsTag_
private

Definition at line 46 of file PrescaleWeightProvider.h.

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

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

Definition at line 47 of file PrescaleWeightProvider.h.

Referenced by prescaleWeight(), and PrescaleWeightProvider().

unsigned PrescaleWeightProvider::verbosity_
private