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 47 of file PrescaleWeightProvider.h.

Constructor & Destructor Documentation

◆ PrescaleWeightProvider() [1/3]

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() [2/3]

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

Definition at line 89 of file PrescaleWeightProvider.h.

91  hltPrescaleProvider_.reset(new HLTPrescaleProvider(config, iC, module));
92 }

References hltPrescaleProvider_.

◆ ~PrescaleWeightProvider()

PrescaleWeightProvider::~PrescaleWeightProvider ( )
inline

Definition at line 71 of file PrescaleWeightProvider.h.

71 {}

◆ PrescaleWeightProvider() [3/3]

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

Definition at line 18 of file PrescaleWeightProvider.cc.

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 }

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

Member Function Documentation

◆ initRun()

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

Definition at line 60 of file PrescaleWeightProvider.cc.

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 }

References configured_, HltComparatorCreateWorkflow::hltConfig, hltPrescaleProvider_, init_, edm::HandleBase::isValid(), l1GtTriggerMenuLiteTag_, l1GtTriggerMenuLiteToken_, edm::InputTag::label(), edm::InputTag::process(), writedatasetfile::run, singleTopDQM_cfi::setup, triggerMenuLite_, triggerResultsTag_, and verbosity_.

◆ parseL1Seeds()

void PrescaleWeightProvider::parseL1Seeds ( const std::string &  l1Seeds)
private

Definition at line 200 of file PrescaleWeightProvider.cc.

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 }

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

Referenced by prescaleWeight().

◆ prescaleWeight()

int PrescaleWeightProvider::prescaleWeight ( const edm::Event event,
const edm::EventSetup setup 
)

Definition at line 97 of file PrescaleWeightProvider.cc.

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 }

References L1GtUtils::decision(), edm::InputTag::encode(), L1GtTriggerMenuLite::gtTechTrigName(), HltComparatorCreateWorkflow::hltConfig, zMuMuMuonUserData::hltPath, hltPaths_, hltPrescaleProvider_, init_, l1SeedPaths_, parseL1Seeds(), L1GtUtils::prescaleFactor(), singleTopDQM_cfi::setup, AlCaHLTBitMon_QueryRunRegistry::string, triggerMenuLite_, triggerResults, triggerResultsTag_, triggerResultsToken_, interactiveExample::ui, verbosity_, and mps_merge::weight.

Member Data Documentation

◆ configured_

bool PrescaleWeightProvider::configured_
private

Definition at line 48 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

◆ hltPaths_

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

Definition at line 61 of file PrescaleWeightProvider.h.

Referenced by prescaleWeight(), and PrescaleWeightProvider().

◆ hltPrescaleProvider_

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

Definition at line 50 of file PrescaleWeightProvider.h.

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

◆ init_

bool PrescaleWeightProvider::init_
private

Definition at line 49 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

◆ l1GtTriggerMenuLiteTag_

edm::InputTag PrescaleWeightProvider::l1GtTriggerMenuLiteTag_
private

Definition at line 59 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

◆ l1GtTriggerMenuLiteToken_

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

Definition at line 60 of file PrescaleWeightProvider.h.

Referenced by initRun(), and PrescaleWeightProvider().

◆ l1SeedPaths_

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

Definition at line 53 of file PrescaleWeightProvider.h.

Referenced by parseL1Seeds(), and prescaleWeight().

◆ triggerMenuLite_

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

Definition at line 51 of file PrescaleWeightProvider.h.

Referenced by initRun(), and prescaleWeight().

◆ triggerResultsTag_

edm::InputTag PrescaleWeightProvider::triggerResultsTag_
private

Definition at line 57 of file PrescaleWeightProvider.h.

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

◆ triggerResultsToken_

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

Definition at line 58 of file PrescaleWeightProvider.h.

Referenced by prescaleWeight(), and PrescaleWeightProvider().

◆ verbosity_

unsigned PrescaleWeightProvider::verbosity_
private
interactiveExample.ui
ui
Definition: interactiveExample.py:13
PrescaleWeightProvider::hltPrescaleProvider_
std::unique_ptr< HLTPrescaleProvider > hltPrescaleProvider_
Definition: PrescaleWeightProvider.h:50
mps_merge.weight
weight
Definition: mps_merge.py:88
PrescaleWeightProvider::hltPaths_
std::vector< std::string > hltPaths_
Definition: PrescaleWeightProvider.h:61
triggerResults
static const std::string triggerResults
Definition: EdmProvDump.cc:45
edm::InputTag::process
std::string const & process() const
Definition: InputTag.h:40
L1GtUtils::decision
const bool decision(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, int &errorCode) const
Definition: L1GtUtils.cc:1066
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle< edm::TriggerResults >
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::InRun
Definition: BranchType.h:11
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
L1GtTriggerMenuLite::gtTechTrigName
const std::string * gtTechTrigName(const unsigned int bitNumber, int &errorCode) const
Definition: L1GtTriggerMenuLite.cc:346
PrescaleWeightProvider::triggerResultsToken_
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
Definition: PrescaleWeightProvider.h:58
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
config
Definition: config.py:1
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
PrescaleWeightProvider::configured_
bool configured_
Definition: PrescaleWeightProvider.h:48
L1GtUtils
Definition: L1GtUtils.h:66
PrescaleWeightProvider::l1GtTriggerMenuLiteTag_
edm::InputTag l1GtTriggerMenuLiteTag_
Definition: PrescaleWeightProvider.h:59
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PrescaleWeightProvider::parseL1Seeds
void parseL1Seeds(const std::string &l1Seeds)
Definition: PrescaleWeightProvider.cc:200
PrescaleWeightProvider::verbosity_
unsigned verbosity_
Definition: PrescaleWeightProvider.h:56
edm::ConsumesCollector::mayConsume
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
Definition: ConsumesCollector.h:72
HLTPrescaleProvider
Definition: HLTPrescaleProvider.h:38
edm::InputTag::encode
std::string encode() const
Definition: InputTag.cc:159
PrescaleWeightProvider::triggerMenuLite_
edm::Handle< L1GtTriggerMenuLite > triggerMenuLite_
Definition: PrescaleWeightProvider.h:51
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
L1GtTriggerMenuLite
Definition: L1GtTriggerMenuLite.h:39
HLTConfigProvider
Definition: HLTConfigProvider.h:29
writedatasetfile.run
run
Definition: writedatasetfile.py:27
zMuMuMuonUserData.hltPath
hltPath
Definition: zMuMuMuonUserData.py:20
PrescaleWeightProvider::PrescaleWeightProvider
PrescaleWeightProvider(const edm::ParameterSet &config, edm::ConsumesCollector &&iC, T &module)
Definition: PrescaleWeightProvider.h:85
HltComparatorCreateWorkflow.hltConfig
hltConfig
Definition: HltComparatorCreateWorkflow.py:161
PrescaleWeightProvider::init_
bool init_
Definition: PrescaleWeightProvider.h:49
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
event
Definition: event.py:1
L1GtUtils::prescaleFactor
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
edm::InputTag
Definition: InputTag.h:15
edm::TriggerResults
Definition: TriggerResults.h:35
weight
Definition: weight.py:1
PrescaleWeightProvider::l1SeedPaths_
std::vector< std::string > l1SeedPaths_
Definition: PrescaleWeightProvider.h:53
PrescaleWeightProvider::triggerResultsTag_
edm::InputTag triggerResultsTag_
Definition: PrescaleWeightProvider.h:57
PrescaleWeightProvider::l1GtTriggerMenuLiteToken_
edm::EDGetTokenT< L1GtTriggerMenuLite > l1GtTriggerMenuLiteToken_
Definition: PrescaleWeightProvider.h:60