CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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)
 
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
< HLTPrescaleProvider
hltPrescaleProvider_
 
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 47 of file PrescaleWeightProvider.h.

Constructor & Destructor Documentation

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

Definition at line 85 of file PrescaleWeightProvider.h.

86  : PrescaleWeightProvider(config, iC, module) {}
PrescaleWeightProvider(const edm::ParameterSet &config, edm::ConsumesCollector &&iC, T &module)
tuple module
Definition: callgraph.py:69
template<typename T >
PrescaleWeightProvider::PrescaleWeightProvider ( const edm::ParameterSet config,
edm::ConsumesCollector iC,
T module 
)

Definition at line 89 of file PrescaleWeightProvider.h.

References submitPVResolutionJobs::config, hltPrescaleProvider_, and callgraph::module.

90  : PrescaleWeightProvider(config, iC) {
91  hltPrescaleProvider_ = std::make_unique<HLTPrescaleProvider>(config, iC, module);
92 }
PrescaleWeightProvider(const edm::ParameterSet &config, edm::ConsumesCollector &&iC, T &module)
std::unique_ptr< HLTPrescaleProvider > hltPrescaleProvider_
tuple config
parse the configuration file
tuple module
Definition: callgraph.py:69
PrescaleWeightProvider::~PrescaleWeightProvider ( )
inline

Definition at line 71 of file PrescaleWeightProvider.h.

71 {}
PrescaleWeightProvider::PrescaleWeightProvider ( const edm::ParameterSet config,
edm::ConsumesCollector iC 
)
private

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

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

Member Function Documentation

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

Definition at line 60 of file PrescaleWeightProvider.cc.

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

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

Definition at line 200 of file PrescaleWeightProvider.cc.

References visDQMUpload::buf, l1SeedPaths_, contentValuesCheck::ss, AlCaHLTBitMon_QueryRunRegistry::string, and verbosity_.

Referenced by prescaleWeight().

200  {
201  l1SeedPaths_.clear();
202  std::stringstream ss(l1Seeds);
204 
205  while (ss.good() && !ss.eof()) {
206  ss >> buf;
207  if (buf[0] == '(' || buf[buf.size() - 1] == ')' || buf == "AND" || buf == "NOT") {
208  l1SeedPaths_.clear();
209  if (verbosity_ > 0)
210  edm::LogWarning("PrescaleWeightProvider::parseL1Seeds") << "Only supported logical expression is OR";
211  return;
212  } else if (buf == "OR")
213  continue;
214  else
215  l1SeedPaths_.push_back(buf);
216  }
217 }
std::vector< std::string > l1SeedPaths_
Log< level::Warning, false > LogWarning
int PrescaleWeightProvider::prescaleWeight ( const edm::Event event,
const edm::EventSetup setup 
)

Definition at line 97 of file PrescaleWeightProvider.cc.

References L1GtUtils::decision(), edm::InputTag::encode(), HltComparatorCreateWorkflow::hltConfig, HLTConfigProvider::hltL1GTSeeds(), 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 histoStyle::weight.

97  {
98  if (!init_)
99  return 1;
100 
101  // L1
102  L1GtUtils const& l1GtUtils = hltPrescaleProvider_->l1GtUtils();
103 
104  // HLT
105  HLTConfigProvider const& hltConfig = hltPrescaleProvider_->hltConfigProvider();
106 
108  event.getByToken(triggerResultsToken_, triggerResults);
109  if (!triggerResults.isValid()) {
110  if (verbosity_ > 0)
111  edm::LogError("PrescaleWeightProvider::prescaleWeight")
112  << "TriggerResults product not found for InputTag \"" << triggerResultsTag_.encode() << "\"";
113  return 1;
114  }
115 
116  const int SENTINEL(-1);
117  int weight(SENTINEL);
118 
119  for (unsigned ui = 0; ui < hltPaths_.size(); ui++) {
120  const std::string hltPath(hltPaths_.at(ui));
121  unsigned hltIndex(hltConfig.triggerIndex(hltPath));
122  if (hltIndex == hltConfig.size()) {
123  if (verbosity_ > 0)
124  edm::LogError("PrescaleWeightProvider::prescaleWeight") << "HLT path \"" << hltPath << "\" does not exist";
125  continue;
126  }
127  if (!triggerResults->accept(hltIndex))
128  continue;
129 
130  const std::vector<std::pair<bool, std::string> >& level1Seeds = hltConfig.hltL1GTSeeds(hltPath);
131  if (level1Seeds.size() != 1) {
132  if (verbosity_ > 0)
133  edm::LogError("PrescaleWeightProvider::prescaleWeight")
134  << "HLT path \"" << hltPath << "\" provides too many L1 seeds";
135  return 1;
136  }
137  parseL1Seeds(level1Seeds.at(0).second);
138  if (l1SeedPaths_.empty()) {
139  if (verbosity_ > 0)
140  edm::LogWarning("PrescaleWeightProvider::prescaleWeight")
141  << "Failed to parse L1 seeds for HLT path \"" << hltPath << "\"";
142  continue;
143  }
144 
145  int l1Prescale(SENTINEL);
146  for (unsigned uj = 0; uj < l1SeedPaths_.size(); uj++) {
147  int l1TempPrescale(SENTINEL);
148  int errorCode(0);
149  if (level1Seeds.at(0).first) { // technical triggers
150  unsigned techBit(atoi(l1SeedPaths_.at(uj).c_str()));
151  const std::string techName(*(triggerMenuLite_->gtTechTrigName(techBit, errorCode)));
152  if (errorCode != 0)
153  continue;
154  if (!l1GtUtils.decision(event, techName, errorCode))
155  continue;
156  if (errorCode != 0)
157  continue;
158  l1TempPrescale = l1GtUtils.prescaleFactor(event, techName, errorCode);
159  if (errorCode != 0)
160  continue;
161  } else { // algorithmic triggers
162  if (!l1GtUtils.decision(event, l1SeedPaths_.at(uj), errorCode))
163  continue;
164  if (errorCode != 0)
165  continue;
166  l1TempPrescale = l1GtUtils.prescaleFactor(event, l1SeedPaths_.at(uj), errorCode);
167  if (errorCode != 0)
168  continue;
169  }
170  if (l1TempPrescale > 0) {
171  if (l1Prescale == SENTINEL || l1Prescale > l1TempPrescale)
172  l1Prescale = l1TempPrescale;
173  }
174  }
175  if (l1Prescale == SENTINEL) {
176  if (verbosity_ > 0)
177  edm::LogError("PrescaleWeightProvider::prescaleWeight")
178  << "Unable to find the L1 prescale for HLT path \"" << hltPath << "\"";
179  continue;
180  }
181 
182  int hltPrescale(hltPrescaleProvider_->prescaleValue(event, setup, hltPath));
183 
184  if (hltPrescale * l1Prescale > 0) {
185  if (weight == SENTINEL || weight > hltPrescale * l1Prescale) {
186  weight = hltPrescale * l1Prescale;
187  }
188  }
189  }
190 
191  if (weight == SENTINEL) {
192  if (verbosity_ > 0)
193  edm::LogWarning("PrescaleWeightProvider::prescaleWeight")
194  << "No valid weight for any requested HLT path, returning default weight of 1";
195  return 1;
196  }
197  return weight;
198 }
unsigned int size() const
number of trigger paths in trigger table
edm::Handle< L1GtTriggerMenuLite > triggerMenuLite_
const bool decision(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
Definition: L1GtUtils.cc:1066
Log< level::Error, false > LogError
std::string encode() const
Definition: InputTag.cc:159
std::vector< std::string > l1SeedPaths_
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_
std::unique_ptr< HLTPrescaleProvider > hltPrescaleProvider_
static std::string const triggerResults
Definition: EdmProvDump.cc:44
bool isValid() const
Definition: HandleBase.h:70
const std::vector< std::vector< std::pair< bool, std::string > > > & hltL1GTSeeds() const
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
Log< level::Warning, false > LogWarning
int weight
Definition: histoStyle.py:51
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:1078

Member Data Documentation

bool PrescaleWeightProvider::configured_
private

Definition at line 48 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

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

Definition at line 61 of file PrescaleWeightProvider.h.

Referenced by prescaleWeight(), and PrescaleWeightProvider().

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

Definition at line 50 of file PrescaleWeightProvider.h.

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

bool PrescaleWeightProvider::init_
private

Definition at line 49 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

edm::InputTag PrescaleWeightProvider::l1GtTriggerMenuLiteTag_
private

Definition at line 59 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

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

Definition at line 60 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

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

Definition at line 53 of file PrescaleWeightProvider.h.

Referenced by parseL1Seeds(), and prescaleWeight().

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

Definition at line 51 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

edm::InputTag PrescaleWeightProvider::triggerResultsTag_
private

Definition at line 57 of file PrescaleWeightProvider.h.

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

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

Definition at line 58 of file PrescaleWeightProvider.h.

Referenced by prescaleWeight(), and PrescaleWeightProvider().

unsigned PrescaleWeightProvider::verbosity_
private