Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
RatesAnalysisAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // RatesAnalysis includes
7 
9 
11 #include "TrigConfData/HLTMenu.h"
12 #include "TrigConfData/L1Menu.h"
15 //uncomment the line below to use the HistSvc for outputting trees and histograms
16 #include "GaudiKernel/ITHistSvc.h"
17 #include "TH1.h"
19 #include <sstream>
20 
21 
22 RatesAnalysisAlg::RatesAnalysisAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
23  AthAnalysisAlgorithm( name, pSvcLocator ),
24  m_linearLumiFactor(0),
25  m_weightingValues(),
26  m_ratesDenominator(0),
27  m_targetMu(0.),
28  m_targetBunches(0.),
29  m_targetLumi(0.),
30  m_runNumber(0.),
31  m_eventCounter(0),
32  m_weightedEventCounter(0),
33  m_scalingHist(nullptr),
34  m_bcidHist(nullptr),
35  m_metadataTree(nullptr)
36 {}
37 
39 
41  const double thresholdMin,
42  const double thresholdMax,
43  const uint32_t thresholdBins,
45  const double prescale,
46  const std::string& seedName,
47  const double seedPrecale,
48  const Method_t method,
49  const ExtrapStrat_t extrapolation) {
50 
51  if (method != kMANUAL) {
52  ATH_MSG_ERROR("Sorry - ScanTriggers have to be implemented with the kMANUAL method for now.");
53  return StatusCode::FAILURE;
54  }
55 
57  m_scanTriggers.emplace(name, std::make_unique<RatesScanTrigger>(name, msgSvc(), thresholdMin, thresholdMax, thresholdBins, behaviour, prescale, seedName, seedPrecale, e));
59  if (isRandomSeed(name, seedName)) newScanTrigger->setSeedsFromRandom(true);
60  ATH_MSG_DEBUG("newScanTrigger " << name << " added");
61  return StatusCode::SUCCESS;
62 }
63 
64 
66  const std::vector<double>& thresholdBinEdges,
68  const double prescale,
69  const std::string& seedName,
70  const double seedPrecale,
71  const Method_t method,
72  const ExtrapStrat_t extrapolation) {
73 
74  if (method != kMANUAL) {
75  ATH_MSG_ERROR("Sorry - ScanTriggers have to be implemented with the kMANUAL method for now.");
76  return StatusCode::FAILURE;
77  }
78 
80 
81  m_scanTriggers.emplace(name, std::make_unique<RatesScanTrigger>(name, msgSvc(), thresholdBinEdges, behaviour, prescale, seedName, seedPrecale, e));
83  if (isRandomSeed(name, seedName)) newScanTrigger->setSeedsFromRandom(true);
84  ATH_MSG_DEBUG("newScanTrigger " << name << " added");
85  return StatusCode::SUCCESS;
86 }
87 
88 
90  const double prescale,
91  const double expressPrescale,
92  const std::string& seedName,
93  const double seedPrecale,
94  const std::string& groups,
95  const Method_t method,
96  const ExtrapStrat_t extrapolation) {
97 
98  std::set<std::string> groupSet;
99  std::istringstream ss(groups);
100  while (ss) {
101  std::string group;
102  if (!std::getline(ss, group, ',')) break;
103  groupSet.insert(group);
104  }
105 
106  return newTrigger(name, prescale, expressPrescale, seedName, seedPrecale, groupSet, method, extrapolation);
107 }
108 
110  const double prescale,
111  const double expressPrescale,
112  const std::string& seedName,
113  const double seedPrecale,
114  const std::set<std::string>& groups,
115  const Method_t method,
116  const ExtrapStrat_t extrapolation) {
117 
118  if (m_eventCounter > 1) { // All triggers must be defined before we start looping over the sample
119  ATH_MSG_FATAL("Too late to call newTrigger. All emulated triggers must be registered during ratesInitialize().");
120  return StatusCode::FAILURE;
121  }
122  if (method == kEXISTING) ATH_CHECK( checkExistingTrigger(name, seedName) ); // Check this agrees with what is in the AOD
123 
124  // Check if it already exists
125  if (m_triggers.count(name) == 1) {
126  ATH_MSG_WARNING("Trigger " << name << " is already registered.");
127  return StatusCode::SUCCESS;
128  }
129 
130  const ExtrapStrat_t e = (m_enableLumiExtrapolation ? extrapolation : ExtrapStrat_t::kNONE);
131  m_triggers.emplace(name, std::make_unique<RatesTrigger>(name, msgSvc(), prescale, expressPrescale, seedName, seedPrecale, m_doHistograms, e));
132  RatesTrigger* newTriggerPtr = m_triggers.at(name).get();
133 
134  if (isRandomSeed(name, seedName)) newTriggerPtr->setSeedsFromRandom(true);
135 
136  // Only worthwhile doing the remainder if the trigger is not disabled. Otherwise will slow everything down
137  if (newTriggerPtr->getDisabled()) {
138  ATH_MSG_DEBUG("newTrigger " << name << " added (disabled)");
139  return StatusCode::SUCCESS;
140  }
141 
142  if (method == kAUTO) {
143  m_autoTriggers.push_back(name);
144  } else if (method == kEXISTING) {
145  m_existingTriggers[name] = m_tdt->getChainGroup(name);
147  }
148 
149  // Add this trigger to its groups
150  if (m_doTriggerGroups) {
151  for (const std::string& group : groups) {
152  // Ignore BW and PS groups
153  if (group.starts_with("BW") || group.starts_with("PS") || group.starts_with("STREAM:express")) continue;
154 
155  const auto [it, inserted] = m_groups.try_emplace(group, std::make_unique<RatesGroup>(group, msgSvc(), m_doHistograms, m_enableLumiExtrapolation));
156  if (inserted) {
157  // As the group is formed from at least one active trigger - it must be active itself (counter example - CPS group of a PS=-1 trigger)
158  m_activeGroups.insert( it->second.get() );
159  }
160  it->second->addToGroup( newTriggerPtr );
161  // For CPS, we let the trigger know that it is special
162  if (isCPS(group)) {
163  if (newTriggerPtr->getCPSID() != 0) ATH_MSG_WARNING("Trigger " << name << " can only be in one coherent prescale group.");
164  newTriggerPtr->setCPS(group); // This changes the CPSID
165  const size_t CPSID = newTriggerPtr->getCPSID();
166  // Find the lowest prescale of any member in this CPS group
167  m_lowestPrescale.try_emplace(CPSID, FLT_MAX);
168  if (prescale < m_lowestPrescale[CPSID]) m_lowestPrescale[CPSID] = prescale;
169  }
170  }
171  }
172 
173  // Add to total rates
174  const uint32_t level = getLevel(name);
175  if (m_doGlobalGroups) {
176  if (level == 2) m_globalGroups.at(m_l2GroupName)->addToGroup( newTriggerPtr );
177  else if (level == 1) m_globalGroups.at(m_l1GroupName)->addToGroup( newTriggerPtr );
178  }
179  // Add to express group - if express prescale is enabled
180  if (level == 2 && expressPrescale >= 1) {
181  if (m_doGlobalGroups) m_globalGroups.at(m_expressGroupName)->addToGroup( newTriggerPtr );
182  if (m_doExpressRates) m_expressTriggers.insert( newTriggerPtr );
183  }
184 
185  ATH_MSG_DEBUG("newTrigger " << name << " added");
186  return StatusCode::SUCCESS;
187 }
188 
191  return addExisting(".*");
192 }
193 
195  // Check we have the TDT
197 
198  const auto& triggers = m_tdt->getListOfTriggers(pattern);
199  ATH_MSG_INFO("Read " << triggers.size() << " triggers from AOD.");
200 
201  // Check if chain was disabled in athena job
202  const bool runWithPrescaleJSON = !m_prescalesJSON.value().empty();
203  const TrigConf::HLTPrescalesSet& hltPrescalesSet = m_configSvc->hltPrescalesSet(Gaudi::Hive::currentContext());
204  for( auto & p : hltPrescalesSet.data().get_child("prescales") ) {
205  if ((!m_prescalesJSON.value().count(p.first) && !runWithPrescaleJSON) || hltPrescalesSet.prescale(p.first).prescale < 0){
206  m_prescalesJSON[p.first]["prescale"] = (hltPrescalesSet.prescale(p.first).enabled ? hltPrescalesSet.prescale(p.first).prescale : -1);
207  m_prescalesJSON[p.first]["prescale_express"] = (hltPrescalesSet.prescale_express(p.first).enabled ? hltPrescalesSet.prescale_express(p.first).prescale : -1);
208  if (hltPrescalesSet.prescale(p.first).prescale < 0){
209  ATH_MSG_WARNING("Trigger " << p.first << " disabled in supplied AOD file. DISABLING");
210  }
211  }
212  }
213 
214  const TrigConf::L1PrescalesSet& l1PrescalesSet = m_configSvc->l1PrescalesSet(Gaudi::Hive::currentContext());
215  for( auto & p : l1PrescalesSet.prescales() ) {
216  if ((!m_prescalesJSON.value().count(p.first) && !runWithPrescaleJSON) || p.second.prescale < 0){
217  m_prescalesJSON[p.first]["prescale"] = p.second.prescale;
218 
219  if (p.second.prescale < 0){
220  ATH_MSG_WARNING("Trigger " << p.first << " disabled in supplied AOD file. DISABLING");
221  }
222  }
223  }
224 
225  // Iterate over the triggers and add them
226  for (const auto& trigger : triggers) {
227  ATH_MSG_DEBUG("Considering " << trigger );
228  const bool isHLT = (getLevel(trigger) == 2);
229  const auto trigConf = (isHLT ? m_tdt->ExperimentalAndExpertMethods().getChainConfigurationDetails(trigger) : nullptr);
230  if (isHLT && !trigConf) {
231  ATH_MSG_ERROR("Problem with TDT trig conf - cannot get details for " << trigger << ", will be ignored.");
232  continue;
233  }
234  const std::string lowerName = (isHLT ? trigConf->lower_chain_name() : "");
235  std::set<std::string> groups = std::set<std::string>(); // To be filled later from the HLTMenu
236 
237  if (isHLT) {
238  // If this is a HLT item, we require it to be seeded by at most one item. This allows us to use a factorising rates algorithm
239  if (lowerName.find(",") != std::string::npos) {
240  ATH_MSG_WARNING("Can not add " << trigger << " due to multiple L1 seeds." );
241  continue;
242  }
243 
244  if (lowerName.empty()) {
245  ATH_MSG_WARNING("Can not add " << trigger << " due to multiple L1 seeds: L1All" );
246  continue;
247  }
248 
249  // Check it also wasn't disabled in the reprocessing (e.g. auto prescaled out in a perf or tightperf menu)
250  if (trigConf->prescale() < 1.) { // Note this prescale is from ATHENA
251  ATH_MSG_DEBUG("Will not add " << trigger << ", it was disabled in the reprocessing.");
252  continue;
253  }
254 
255  ATH_CHECK(m_configSvc.isValid());
256  const TrigConf::HLTMenu& hltMenu = m_configSvc->hltMenu(Gaudi::Hive::currentContext());
257 
258  TrigConf::HLTMenu::const_iterator chain = std::find_if(hltMenu.begin(), hltMenu.end(), [&] (const TrigConf::Chain& c) {return c.name() == trigger;});
259  if (chain == hltMenu.end()){
260  ATH_MSG_WARNING("Chain " << trigger << " not found in the menu!");
261  continue;
262  }
263 
264  std::vector<std::string> chainGroups = (*chain).groups();
265  std::vector<std::string> chainStreams = (*chain).streams();
266 
267  ATH_MSG_DEBUG(" chain " << trigger << " has " << chainGroups.size() << " groups and " << chainStreams.size() << " streams");
268 
269  groups.insert(chainGroups.begin(), chainGroups.end());
270  for (const std::string& stream : chainStreams){
271  groups.insert("STREAM:" + stream );
272  }
273  }
274 
275  // Get the prescale, express prescale and lower prescale. Note these prescales are from SUPPLIED JSON.
276  double prescale = 1., expressPrescale = -1., lowerPrescale = 1.;
277  if (m_prescalesJSON.size() != 0) {
278  if (m_prescalesJSON.value().count(trigger) == 0) {
279  ATH_MSG_WARNING("Unable to find " << trigger << " in supplied JSON. DISABLING." );
280  prescale = 0.;
281  } else {
282  prescale = m_prescalesJSON[trigger]["prescale"];
283  expressPrescale = m_prescalesJSON[trigger]["prescale_express"];
284  }
285  if (isHLT) {
286  if (m_prescalesJSON.value().count(lowerName) == 0) {
287  ATH_MSG_WARNING("Unable to find " << trigger << "'s seed, " << lowerName << ", in supplied JSON. DISABLING." );
288  lowerPrescale = 0.;
289  } else {
290  lowerPrescale = m_prescalesJSON[lowerName]["prescale"];
291  }
292  }
293  }
294 
295 
296  // We now have all the info needed to add this trigger
297  ATH_MSG_DEBUG("Registering existing trigger " << trigger << " for automatic TDT based rates prediction." );
298  ATH_CHECK( newTrigger(trigger, prescale, expressPrescale, lowerName, lowerPrescale, groups, kEXISTING) );
299  }
300 
301  for (const auto& trigger : m_prescalesJSON) {
302  if (trigger.second.at("prescale") > 0 && std::find(triggers.begin(), triggers.end(), trigger.first) == triggers.end()) {
303  ATH_MSG_WARNING( "Trigger " << trigger.first << " in supplied JSON is NOT AVAILABLE in the supplied AOD file.");
304  }
305  }
306 
307  return StatusCode::SUCCESS;
308 }
309 
311  if (m_tdt.empty()){
312  ATH_MSG_ERROR("TriggerDecisionTool is not available!");
313  return StatusCode::FAILURE;
314  }
315  [[maybe_unused]] static std::atomic<bool> printed = [&]() {
316  ATH_MSG_INFO("TDT contains: " << m_tdt->getListOfTriggers().size() << " triggers, "
317  << m_tdt->getListOfStreams().size() << " streams and "
318  << m_tdt->getListOfGroups().size() << " groups.");
319  return true;
320  }();
321  return StatusCode::SUCCESS;
322 }
323 
324 
325 StatusCode RatesAnalysisAlg::checkExistingTrigger(const std::string& name, const std::string& seedName) {
327  const auto& triggers = m_tdt->getListOfTriggers(name);
328  if (triggers.size() != 1) {
329  ATH_MSG_FATAL("Unable to find existing trigger " << name << " in this AOD.");
330  return StatusCode::FAILURE;
331  }
332  if (getLevel(name) == 1) return StatusCode::SUCCESS;
333  // L1 items will crash if we call this on them.
334  const auto trigConf = m_tdt->ExperimentalAndExpertMethods().getChainConfigurationDetails(triggers.at(0));
335  if (trigConf->lower_chain_name() != seedName) {
336  ATH_MSG_FATAL("Tried to register an existing trigger '" << name << "' seeding from '" << seedName << "' but in this AOD it seeds from '" << trigConf->lower_chain_name() << "'");
337  return StatusCode::FAILURE;
338  }
339  return StatusCode::SUCCESS;
340 }
341 
342 StatusCode RatesAnalysisAlg::setTriggerDesicison(const std::string& name, const bool triggerIsPassed, const bool triggerIsActive) {
343  // Currently - we call execute on setPassed, so the user would be unable to overwrite a decision set e.g. by the TDT.
344  // so for now we only accept positive decisions here.
345  if (triggerIsPassed || triggerIsActive) {
346  const auto iterator = m_triggers.find(name);
347  if (iterator == m_triggers.end()) {
348  ATH_MSG_ERROR("Cannot find trigger " << name << " did you call newTrigger for this in initialize?");
349  return StatusCode::FAILURE;
350  }
351  iterator->second->setPassedAndExecute(triggerIsPassed, triggerIsActive, m_weightingValues); // There is logic in the RatesTrigger to prevent multiple calls per event by accident.
352  m_activatedTriggers.insert( iterator->second.get() );
353  }
354  return StatusCode::SUCCESS;
355 }
356 
357 
359  const auto iterator = m_scanTriggers.find(name);
360  if (iterator == m_scanTriggers.end()) {
361  ATH_MSG_ERROR("Cannot find scan-trigger " << name << " did you call newScanTrigger for this in initialize?");
362  return StatusCode::FAILURE;
363  }
364  iterator->second->setPassedAndExecute(threshold, m_weightingValues); // There is logic in the RatesScanTrigger to prevent multiple calls per event by accident.
365  m_activatedTriggers.insert( static_cast<RatesTrigger*>(iterator->second.get()));
366  return StatusCode::SUCCESS;
367 }
368 
370  ATH_MSG_INFO ("Initializing " << name() << "...");
371 
372  if (!m_tdt.empty()){
373  ATH_CHECK( m_tdt.retrieve() );
374  }
375 
376  if(!m_configSvc.empty()) {
377  ATH_CHECK( m_configSvc.retrieve() );
378  }
379 
380  ATH_CHECK( m_enhancedBiasRatesTool.retrieve() );
381 
383  ATH_MSG_ERROR("DoUniqueRates=True requires DoGlobalGroups=True");
384  return StatusCode::FAILURE;
385  }
386 
387  return StatusCode::SUCCESS;
388 }
389 
391  // Let user add their triggers
392  ATH_MSG_INFO("Initializing User's Triggers (note: we are actually now in the event loop)");
393 
394  if (m_doGlobalGroups) {
395  m_globalGroups.emplace(m_l1GroupName, std::make_unique<RatesGroup>(m_l1GroupName, msgSvc(), m_doHistograms, m_enableLumiExtrapolation));
396  m_globalGroups.emplace(m_l2GroupName, std::make_unique<RatesGroup>(m_l2GroupName, msgSvc(), m_doHistograms, m_enableLumiExtrapolation));
397  m_globalGroups.at(m_l2GroupName)->setDoCachedWeights( m_doUniqueRates ); // This extra sub-weight caching is only utilised by unique-rate groups
398  if (m_doExpressRates) {
400  m_globalGroups.at(m_expressGroupName)->setExpressGroup( true );
401  }
402  }
403 
404  // This runs the derived class's code to add whatever triggers are desired.
405  // Should be calling newTrigger(...), newScanTrigger(...) or addExisting(...), addAllExisting().
407 
408  ATH_MSG_INFO("Computing coherent factors for coherent prescale groups.");
409  // Now we are not going to get any more chains - we can fill in the coherent prescale factors
410  for (const auto& trigger : m_triggers) {
411  const size_t CPSID = trigger.second->getCPSID();
412  if (CPSID != 0) trigger.second->setCoherentFactor( m_lowestPrescale.at(CPSID) );
413  }
414 
416  ATH_MSG_INFO("Creating extra groups to calculate unique rates.");
417  const RatesGroup* l2GroupPtr = m_globalGroups.at(m_l2GroupName).get(); // The finalised list of all HLT chains
418  const RatesGroup* l1GroupPtr = m_globalGroups.at(m_l1GroupName).get(); // The finalised list of all L1 chains
419  for (const auto& trigger : m_triggers) {
420  const uint32_t level = getLevel(trigger.first);
421  m_uniqueGroups.emplace(trigger.first, std::make_unique<RatesGroup>(trigger.first, msgSvc(), false, m_enableLumiExtrapolation)); // Each trigger gets its own unique group. No hist needed
422  RatesTrigger* triggerPtr = m_triggers.at(trigger.first).get();
423  RatesGroup* uniqueGroupPtr = m_uniqueGroups.at(trigger.first).get();
424  triggerPtr->setUniqueGroup( uniqueGroupPtr ); // Create two-way links
425  uniqueGroupPtr->setUniqueTrigger( triggerPtr ); // Create two-way links
426  // Copy in the global rates topology and make note of the unique rates master group
427  if (level == 2) uniqueGroupPtr->duplicateChildren( l2GroupPtr );
428  else if (level == 1) uniqueGroupPtr->duplicateChildren( l1GroupPtr );
429  else continue;
430  // Remove this one chain from the group (a unique rate is the rate of the entire menu minus one chain)
431  uniqueGroupPtr->removeFromGroup( triggerPtr );
432  if (getLevel(trigger.first) == 2) {
433  // For HLT, we can be more computationally efficient by utilising cached info from the hlt group
434  // We remove from the group all other L1 seeds except for the one seeding our chain.
435  // This sub-weight is the only one which can change. The combined weight of all other L1 seeds
436  // can be cached by the master group and fetched from there.
437  uniqueGroupPtr->removeOtherL1( triggerPtr );
438  uniqueGroupPtr->setUseCachedWeights(true);
439  }
440  // Efficiency - if the trigger is disabled, no need to actually calculate anything for it.
441  if (trigger.second->getDisabled() == false) {
442  m_activeGroups.insert( uniqueGroupPtr ); // Add this to the event loop
443  }
444  }
445  }
446 
447  ATH_MSG_INFO("Retrieving HLT chain's ID and Group from HLT menu.");
448 
449  if(!m_configSvc.empty() && m_configSvc.isValid()) {
450  const TrigConf::HLTMenu& hltmenu = m_configSvc->hltMenu( Gaudi::Hive::currentContext() );
451 
452  TrigConf::HLTMenu::const_iterator chain_itr = hltmenu.begin();
453  TrigConf::HLTMenu::const_iterator chain_end = hltmenu.end();
454 
455  m_hltChainIDGroup.resize(hltmenu.size());
456  for (size_t i = 0; i < hltmenu.size(); i++) m_hltChainIDGroup.at(i).resize(3);
457 
458  size_t c = 0;
459  for( ; chain_itr != chain_end; ++chain_itr ) {
460  std::string chainName = ( *chain_itr ).name() ;
461  unsigned int chainID = ( *chain_itr ).counter();
462  std::vector<std::string> chainGroups = ( *chain_itr ).groups();
463  for (std::string& stream : (*chain_itr).streams()){
464  chainGroups.push_back("STREAM:" + stream);
465  }
466  std::string singlechainGroups = "";
467  for (unsigned int j=0; j < chainGroups.size(); ++j){
468  if (j==0) singlechainGroups += chainGroups[j];
469  else singlechainGroups += ", "+chainGroups[j];
470  }
471 
472  m_hltChainIDGroup.at(c).at(0) = chainName;
473  m_hltChainIDGroup.at(c).at(1) = std::to_string(chainID);
474  m_hltChainIDGroup.at(c).at(2) = singlechainGroups;
475  ++c;
476  }
477  }
478 
479  ATH_MSG_INFO("Retrieving L1 item's ID from L1 menu.");
480 
481  if(!m_configSvc.empty() && m_configSvc.isValid()) {
482  const TrigConf::L1Menu& l1menu = m_configSvc->l1Menu( Gaudi::Hive::currentContext() );
483 
484  m_l1ItemID.resize(l1menu.size());
485  for (size_t i = 0; i < l1menu.size(); i++) {
486  // No groups for items
487  m_l1ItemID.at(i).resize(2);
488  }
489 
490  TrigConf::L1Menu::const_iterator item_itr = l1menu.begin();
491  TrigConf::L1Menu::const_iterator item_end = l1menu.end();
492 
493  size_t c = 0;
494  for( ; item_itr != item_end; ++item_itr ) {
495  m_l1ItemID.at(c).at(0) = (*item_itr).name();
496  m_l1ItemID.at(c).at(1) = std::to_string((*item_itr).ctpId());
497  ++c;
498  }
499  }
500 
501  // Print all triggers
502  if (msgLevel(MSG::DEBUG)) {
503  if (m_triggers.size()) {
504  ATH_MSG_DEBUG("################## Configured to estimate rates for the following triggers:");
505  for (const auto& trigger : m_triggers) ATH_MSG_DEBUG(trigger.second->printConfig());
506  }
507  if (m_scanTriggers.size()) {
508  ATH_MSG_DEBUG("################## Configured to estimate rates for the following scan triggers:");
509  for (const auto& trigger : m_scanTriggers) ATH_MSG_DEBUG(trigger.second->printConfig());
510  }
511  if (m_groups.size()) {
512  ATH_MSG_DEBUG("################## Configured to estimate rates for the following groups of triggers:");
513  for (const auto& group : m_groups) ATH_MSG_DEBUG(group.second->printConfig());
514  }
515  if (m_globalGroups.size()) {
516  ATH_MSG_DEBUG("################## Configured to estimate rates for the following global groups of triggers:");
517  for (const auto& group : m_globalGroups) ATH_MSG_DEBUG(group.second->printConfig());
518  }
519  }
520  if (m_doHistograms) {
521  ATH_MSG_DEBUG("################## Registering normalisation histogram:");
522  m_scalingHist = new TH1D("normalisation",";;",3,0.,3.);
523  ATH_CHECK( histSvc()->regHist("/RATESTREAM/normalisation", m_scalingHist) );
524  m_bcidHist = new TH1D("bcid",";BCID;Events",3565,-.5,3564.5);
525  ATH_CHECK( histSvc()->regHist("/RATESTREAM/bcid", m_bcidHist) );
526  ATH_MSG_DEBUG("################## Registering metadata tree histogram:");
527  ATH_CHECK( histSvc()->regTree("/RATESTREAM/metadata", std::make_unique<TTree>("metadata", "metadata")) );
528  ATH_CHECK( histSvc()->getTree("/RATESTREAM/metadata", m_metadataTree) );
529  if (m_triggers.size()) {
530  ATH_MSG_DEBUG("################## Registering trigger histograms:");
531  for (const auto& trigger : m_triggers) {
532  if (!trigger.second->doHistograms()) continue; // Not all may be doing histograming
533  std::string lvlSubdir = "";
534  if (trigger.second->getName().find("L1") == 0){
535  lvlSubdir = "Rate_ChainL1_HLT/";
536  } else if (trigger.second->getName().find("HLT") == 0) {
537  lvlSubdir = "Rate_ChainHLT_HLT/";
538  }
539  ATH_CHECK( trigger.second->giveDataHist(histSvc(), std::string("/RATESTREAM/All/" + lvlSubdir + trigger.first + "/data")) );
540  ATH_CHECK( trigger.second->giveMuHist(histSvc(), std::string("/RATESTREAM/All/" + lvlSubdir + trigger.first + "/rateVsMu")) );
541  if (m_useBunchCrossingData) ATH_CHECK( trigger.second->giveTrainHist(histSvc(), std::string("/RATESTREAM/All/" + lvlSubdir + trigger.first + "/rateVsTrain")) );
542  else trigger.second->clearTrainHist();
543  }
544  }
545  if (m_scanTriggers.size()) {
546  ATH_MSG_DEBUG("################## Registering scan trigger histograms:");
547  for (const auto& trigger : m_scanTriggers) {
548  ATH_CHECK( trigger.second->giveThresholdHist(histSvc(), std::string("/RATESTREAM/ScanTriggers/" + trigger.first + "/rateVsThreshold")) );
549  }
550  }
551  if (m_groups.size()) {
552  ATH_MSG_DEBUG("################## Registering group histograms:");
553  for (const auto& group : m_groups) {
554  if (!group.second->doHistograms()) continue;
555  std::string groupName = group.first;
556  std::replace( groupName.begin(), groupName.end(), ':', '_');
557  ATH_CHECK( group.second->giveDataHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/" + groupName + "/data")) );
558  ATH_CHECK( group.second->giveMuHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/" + groupName + "/rateVsMu")) );
559  if (m_useBunchCrossingData) ATH_CHECK( group.second->giveTrainHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/" + groupName + "/rateVsTrain")) );
560  else group.second->clearTrainHist();
561  }
562  }
563  if (m_globalGroups.size()) {
564  ATH_MSG_DEBUG("################## Registering global group histograms:");
565  for (const auto& group : m_globalGroups) {
566  if (!group.second->doHistograms()) continue;
567  ATH_CHECK( group.second->giveDataHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" + group.first + "/data")) );
568  ATH_CHECK( group.second->giveMuHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" + group.first + "/rateVsMu")) );
569  if (m_useBunchCrossingData) ATH_CHECK( group.second->giveTrainHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" + group.first + "/rateVsTrain")) );
570  else group.second->clearTrainHist();
571  }
572  }
573  }
574 
575  // Has the user set a lumi extrapolation? If not - set a default
577 
578  // We now know the final lumi scaling so we can set the bunch scaling
579  const uint32_t ebPairedBunches = m_enhancedBiasRatesTool->getPairedBunches();
580  ATH_MSG_INFO("Number of paired bunches in input file:" << m_enhancedBiasRatesTool->getPairedBunches());
582 
583  return StatusCode::SUCCESS;
584 }
585 
587  ATH_MSG_DEBUG("Executing " << name() << " on event " << m_eventCounter << "...");
588  if (m_eventCounter++ == 0) { // First time in execute loop - cannot access TDT before this.
590  }
591 
592  // Get event characteristics
593  const xAOD::EventInfo* eventInfo(nullptr);
594  uint32_t distance = 0;
595  ATH_CHECK( evtStore()->retrieve(eventInfo, "EventInfo") );
596  ATH_CHECK( m_enhancedBiasRatesTool->getDistanceIntoTrain(eventInfo, distance) );
597 
598  // Get the weighting & scaling characteristics
600  m_weightingValues.m_eventMu = std::ceil(eventInfo->actualInteractionsPerCrossing()); // This always seems to be a half integer
601  m_weightingValues.m_eventLumi = m_enhancedBiasRatesTool->getLBLumi(eventInfo);
602  m_weightingValues.m_isUnbiased = m_enhancedBiasRatesTool->isUnbiasedEvent(eventInfo);
604  m_weightingValues.m_eventLiveTime = m_enhancedBiasRatesTool->getEBLiveTime(eventInfo);
605 
607 
608  // Bunch factor doesn't change as a fn. of the run. Reminder: m_bunchFactor = m_targetBunches / (double)ebPairedBunches;
612 
613  // Ignore zero weighted events. Typically these come from bad LB
614  if (RatesHistoBase::isZero(m_weightingValues.m_enhancedBiasWeight)) return StatusCode::SUCCESS;
615 
616  // Do automated triggers
618 
619  // Do TDT-controlled triggers
621 
622  // Run user's code. Do manual triggers
623  ATH_CHECK( ratesExecute() );
624 
625  // Execute groups
626  for (const auto& group : m_globalGroups) group.second->execute(m_weightingValues); // Physics, L1, express: Must execute before m_uniqueGroups (which are in active groups). Map.
627  for (const auto& group : m_activeGroups) group->execute(m_weightingValues); // Individual groups, CPS groups and active unique groups. Set.
628 
629  // Reset triggers
630  for (const auto& trigger : m_activatedTriggers) trigger->reset();
631  m_activatedTriggers.clear();
632 
633  // Keep track of elapsed walltime
636 
637  if (m_doHistograms) {
638  m_bcidHist->Fill(eventInfo->bcid(), m_weightingValues.m_enhancedBiasWeight);
639  m_scalingHist->Fill(0.5, m_weightingValues.m_eventLiveTime); // Walltime
640  m_scalingHist->Fill(1.5, 1.); // Total events
641  m_scalingHist->Fill(2.5, m_weightingValues.m_enhancedBiasWeight); // Total events weighted
642  }
643 
644  // Some debug info
645  if (m_eventCounter % 1000 == 0) {
646  ATH_MSG_INFO( "Event " << m_eventCounter << " " << m_weightingValues.print() << " currentWallTime:" << m_ratesDenominator );
647  }
648 
649  setFilterPassed(true); //if got here, assume that means algorithm passed
650  return StatusCode::SUCCESS;
651 }
652 
654  for (const auto& trigger : m_existingTriggers) {
655  const bool passed = trigger.second->isPassed();
656  // L1 chains are always active, HLT chains are active if their L1 passed.
657  const std::string& lower = m_lowerTrigger[trigger.first];
658  // Expect this find operation to fail for L1 chains (lower = "")
659  const std::unordered_map<std::string, const Trig::ChainGroup*>::const_iterator it = m_existingTriggers.find(lower);
660  const bool active = (it == m_existingTriggers.end() ? true : it->second->isPassed());
661  ATH_CHECK( setTriggerDesicison(trigger.first, passed, active) );
662  }
663  return StatusCode::SUCCESS;
664 }
665 
667  // TODO emulation code here
668  for (const auto& trigger : m_autoTriggers) {
669  ATH_MSG_WARNING("Cannot do rates for " << trigger << ". Automatic trigger emulation is not yet included, sorry :(");
670  }
671  return StatusCode::SUCCESS;
672 }
673 
675  ATH_MSG_INFO ("Finalizing " << name() << "...");
676 
678  if (m_scanTriggers.size()) {
679  ATH_MSG_INFO("################## Computed Rate Scans for Threshold-Scan Items:");
680  for (const auto& trigger : m_scanTriggers) ATH_MSG_INFO(trigger.second->printRate(m_ratesDenominator));
681  }
682  if (m_triggers.size()) {
683  ATH_MSG_INFO("################## Computed Rate Estimations for Single Items:");
684  std::set<std::string> keys; // Used an unordered map for speed, but now we'd like the items in order
685  for (const auto& trigger : m_triggers) keys.insert(trigger.first);
686  for (const std::string& key : keys) ATH_MSG_INFO(m_triggers.at(key)->printRate(m_ratesDenominator));
687  }
688  if (m_expressTriggers.size()) {
689  ATH_MSG_INFO("################## Computed Express Rate Estimations for Single Items:");
690  for (const auto& trigger : m_expressTriggers) ATH_MSG_INFO(trigger->printExpressRate(m_ratesDenominator));
691  }
692  if (m_groups.size()) {
693  ATH_MSG_INFO("################## Computed Rate Estimations for Groups:");
694  for (const auto& group : m_groups) ATH_MSG_INFO(group.second->printRate(m_ratesDenominator));
695  }
696  if (m_globalGroups.size()) {
697  ATH_MSG_INFO("################## Computed Rate Estimations for Global Groups:");
698  for (const auto& group : m_globalGroups) ATH_MSG_INFO(group.second->printRate(m_ratesDenominator));
699  }
700  ATH_MSG_INFO("################## LHC Conditions and weighting information:");
702  printTarget();
703  printStatistics();
704  ATH_MSG_INFO("##################");
705  writeMetadata();
706 
707  return StatusCode::SUCCESS;
708 }
709 
710 void RatesAnalysisAlg::setTargetLumiMu(const double lumi, const double mu) {
711  if (m_eventCounter > 1) { // All settings must be defined before we start looping over the sample
712  ATH_MSG_WARNING("Too late to call setTargetLumiMu. Do this during ratesInitialize().");
713  return;
714  }
715  m_targetLumi = lumi;
716  if (isZero(mu)) {
717  ATH_MSG_WARNING("Cannot have <mu> = 0. Setting to 1.");
718  m_targetMu = 1;
719  } else {
720  m_targetMu = mu;
721  }
724  ATH_MSG_WARNING("Un-physical number of bunches " << m_targetBunches << ", should be within 1 < N < " << EnhancedBiasWeighter::FULL_RING+1);
725  if (m_targetBunches == 0) ++m_targetBunches;
726  }
727  printTarget();
728 }
729 
730 void RatesAnalysisAlg::setTargetLumiBunches(const double lumi, const int32_t bunches) {
731  if (m_eventCounter > 1) { // All settings must be defined before we start looping over the sample
732  ATH_MSG_WARNING("Too late to call setTargetLumiBunches. Do this during ratesInitialize().");
733  return;
734  }
735  m_targetLumi = lumi;
736  if (bunches == 0) {
737  ATH_MSG_WARNING("Cannot have bunches = 0. Setting to 1.");
738  m_targetBunches = 1;
739  } else {
740  m_targetBunches = bunches;
741  }
743  printTarget();
744 }
745 
746 
747 void RatesAnalysisAlg::setTargetMuBunches(const double mu, const int32_t bunches) {
748  if (m_eventCounter > 1) { // All settings must be defined before we start looping over the sample
749  ATH_MSG_WARNING("Too late to call setTargetMuBunches. Do this during ratesInitialize().");
750  return;
751  }
752  if (bunches == 0) {
753  ATH_MSG_WARNING("Cannot have paired bunches = 0. Setting to 1.");
754  m_targetBunches = 1;
755  } else {
756  m_targetBunches = bunches;
757  }
758  if (isZero(mu)) {
759  ATH_MSG_WARNING("Cannot have mu = 0. Setting to 1.");
760  m_targetMu = 1;
761  } else {
762  m_targetMu = mu;
763  }
765  printTarget();
766 }
767 
770  ATH_MSG_INFO("Calculating rates for a target L_inst. = " << m_targetLumi << " cm-2s-1, mu = " << m_targetMu << ", paired bunches = " << m_targetBunches);
771  } else {
772  ATH_MSG_INFO("Luminosity extrapolation is switched off. Input files will determin the paired bunches, L_inst. and mu profile.");
773  }
774 }
775 
777  ATH_MSG_INFO("Processed " << m_eventCounter << " raw events, " << m_weightedEventCounter << " weighted. Total LHC wall-time of " << m_ratesDenominator << " s.");
778 }
779 
781  ATH_MSG_INFO("Input " << (m_enhancedBiasRatesTool->isMC() ? "MC" : "EB Data")
782  << " with <L_inst.> = "
783  << m_enhancedBiasRatesTool->getAverageLumi()
784  << " cm-2s-1, <mu> = "
785  << m_enhancedBiasRatesTool->getAverageMu()
786  << ", paired bunches = "
787  << m_enhancedBiasRatesTool->getPairedBunches());
788 }
789 
790 bool RatesAnalysisAlg::isCPS(const std::string& group) const {
791  return (group.find("CPS") != std::string::npos);
792 }
793 
794 bool RatesAnalysisAlg::isRandomSeed(const std::string& me, const std::string& seed) const {
795  if (me.find("L1_RD") != std::string::npos) return true;
796  if (me.find("L1RD") != std::string::npos) return true;
797  if (seed.find("L1_RD") != std::string::npos) return true;
798  return false;
799 }
800 
801 uint32_t RatesAnalysisAlg::getLevel(const std::string& name) const {
802  if (name.find("HLT_") != std::string::npos) return 2;
803  if (name.find("L1_") != std::string::npos) return 1;
804  return 2;
805 }
806 
808  if (!m_metadataTree) {
809  return;
810  }
811  m_runNumber = m_enhancedBiasRatesTool->getRunNumber();
812  m_metadataTree->Branch("runNumber", &m_runNumber);
813 
814  m_metadataTree->Branch("targetMu", &m_targetMu);
815  m_metadataTree->Branch("targetBunches", &m_targetBunches);
816  m_metadataTree->Branch("targetLumi", &m_targetLumi);
817  std::vector<std::string> triggers;
818  std::vector<std::string> lowers;
819  std::vector<double> prescales;
820  std::vector<double> express;
821  triggers.reserve(m_triggers.size());
822  lowers.reserve(m_triggers.size());
823  prescales.reserve(m_triggers.size());
824  express.reserve(m_triggers.size());
825  for (const auto& trigger : m_triggers) {
826  triggers.push_back(trigger.first);
827  lowers.push_back(trigger.second->getSeedName());
828  prescales.push_back(trigger.second->getPrescale() );
829  express.push_back(trigger.second->getPrescale(true /*includeExpress*/) );
830  }
831  for (const auto& group : m_groups) {
832  triggers.push_back(group.first);
833  lowers.push_back("-");
834  prescales.push_back(-1);
835  express.push_back(-1);
836  }
837  for (const auto& group : m_globalGroups) {
838  triggers.push_back("RATE_GLOBAL_" + group.first);
839  lowers.push_back("-");
840  prescales.push_back(-1);
841  express.push_back(-1);
842  }
843  m_metadataTree->Branch("triggers", &triggers);
844  m_metadataTree->Branch("lowers", &lowers);
845  m_metadataTree->Branch("prescales", &prescales);
846  m_metadataTree->Branch("express", &express);
847  std::vector<int32_t> bunchGroups;
848  bunchGroups.reserve(16);
849 
850  uint32_t masterKey = 0;
851  uint32_t hltPrescaleKey = 0;
852  uint32_t lvl1PrescaleKey = 0;
853 
854  if(!m_enhancedBiasRatesTool->isMC()){
855  bunchGroups = m_enhancedBiasRatesTool->getBunchGroups();
856  }
857  if(!m_configSvc.empty() && m_configSvc.isValid() && ( bunchGroups.size() == 0 || std::all_of(bunchGroups.begin(), bunchGroups.end(), [](int i) { return i==0; }) ) && (!m_enhancedBiasRatesTool->isMC())) {
858  const TrigConf::L1BunchGroupSet& bgs = m_configSvc->l1BunchGroupSet(Gaudi::Hive::currentContext());
859  for (size_t i = 0; i < bgs.maxNBunchGroups(); ++i ) {
860  bunchGroups.push_back(bgs.getBunchGroup(i)->size());
861  }
862  masterKey = m_configSvc->masterKey();
863  hltPrescaleKey = m_configSvc->hltPrescaleKey();
864  lvl1PrescaleKey = m_configSvc->lvl1PrescaleKey();
865  }
866  m_metadataTree->Branch("bunchGroups", &bunchGroups);
867 
868  m_metadataTree->Branch("hltChainIDGroup", &m_hltChainIDGroup);
869  m_metadataTree->Branch("l1ItemID", &m_l1ItemID);
870 
871  m_metadataTree->Branch("masterKey", &masterKey);
872  m_metadataTree->Branch("lvl1PrescaleKey", &lvl1PrescaleKey);
873  m_metadataTree->Branch("hltPrescaleKey", &hltPrescaleKey);
874  std::string atlasProject = std::getenv("AtlasProject");
875  std::string atlasVersion = std::getenv("AtlasVersion");
876  m_metadataTree->Branch("AtlasProject", &atlasProject);
877  m_metadataTree->Branch("AtlasVersion", &atlasVersion);
878  m_metadataTree->Fill();
879 }
RunTileTBRec.method
method
Definition: RunTileTBRec.py:73
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TrigConf::DataStructure::data
const ptree & data() const
Access to the underlying data, if needed.
Definition: DataStructure.h:83
TrigConf::HLTPrescalesSet::HLTPrescale::prescale
double prescale
Definition: HLTPrescalesSet.h:24
RatesAnalysisAlg::printStatistics
void printStatistics() const
Print some extra statistics on events processed.
Definition: RatesAnalysisAlg.cxx:776
AthHistogramAlgorithm::histSvc
const ServiceHandle< ITHistSvc > & histSvc() const
The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a...
Definition: AthHistogramAlgorithm.h:113
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
RatesAnalysisAlg::m_expressGroupName
const std::string m_expressGroupName
Definition: RatesAnalysisAlg.h:265
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
ChainDefInMenu.groups
groups
Definition: ChainDefInMenu.py:43
HLTPrescalesSet.h
RatesAnalysisAlg::populateTriggers
StatusCode populateTriggers()
Register all triggers to emulate.
Definition: RatesAnalysisAlg.cxx:390
RatesAnalysisFullMenu.e34
e34
Definition: RatesAnalysisFullMenu.py:25
RatesAnalysisAlg::m_runNumber
uint32_t m_runNumber
What is the RunNumber.
Definition: RatesAnalysisAlg.h:287
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
WeightingValuesSummary_t::m_eventLiveTime
double m_eventLiveTime
How much wall-time at P1 did this event represent.
Definition: RatesHistoBase.h:62
AthAnalysisAlgorithm
Definition: AthAnalysisAlgorithm.h:34
RatesScanTrigger
Used to calculate a rate scan as a function of some threshold value.
Definition: RatesScanTrigger.h:14
RatesAnalysisAlg::m_tdt
ToolHandle< Trig::TrigDecisionTool > m_tdt
Definition: RatesAnalysisAlg.h:268
RatesAnalysisAlg::newTrigger
StatusCode newTrigger(const std::string &name, const double prescale=1., const double expressPrescale=-1., const std::string &seedName="", const double seedPrecale=1., const std::string &groups="", const Method_t method=kMANUAL, const ExtrapStrat_t extrapolation=kLINEAR)
Version of newTrigger which accepts a set of group names rather than a comma separated string.
Definition: RatesAnalysisAlg.cxx:89
RatesGroup::removeFromGroup
void removeFromGroup(const RatesTrigger *toRemove)
Remove a trigger from this group.
Definition: RatesGroup.cxx:67
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
RatesAnalysisAlg::m_enableLumiExtrapolation
Gaudi::Property< bool > m_enableLumiExtrapolation
Definition: RatesAnalysisAlg.h:279
RatesAnalysisAlg::m_lowerTrigger
std::unordered_map< std::string, std::string > m_lowerTrigger
Map of triggers lower chain, to tell if a HLT trigger ran or not.
Definition: RatesAnalysisAlg.h:258
RatesAnalysisAlg::ratesExecute
virtual StatusCode ratesExecute()=0
To be implemented by the user.
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
TrigCompositeUtils::passed
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
Definition: TrigCompositeUtilsRoot.cxx:117
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
TrigConf::HLTMenu
HLT menu configuration.
Definition: HLTMenu.h:21
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
RatesAnalysisAlg::m_scanTriggers
std::unordered_map< std::string, std::unique_ptr< RatesScanTrigger > > m_scanTriggers
All individual rates-scan triggers (L1 or HLT)
Definition: RatesAnalysisAlg.h:246
RatesAnalysisAlg::~RatesAnalysisAlg
virtual ~RatesAnalysisAlg()
Definition: RatesAnalysisAlg.cxx:38
RatesAnalysisAlg::checkGotTDT
StatusCode checkGotTDT()
Internal check that the TDT is fetched.
Definition: RatesAnalysisAlg.cxx:310
RatesAnalysisAlg::newScanTrigger
StatusCode newScanTrigger(const std::string &name, const double thresholdMin, const double thresholdMax, const uint32_t thresholdBins=100, const RatesScanTrigger::TriggerBehaviour_t behaviour=RatesScanTrigger::TriggerBehaviour_t::kTriggerBelowThreshold, const double prescale=1., const std::string &seedName="", const double seedPrecale=1., const Method_t method=kMANUAL, const ExtrapStrat_t extrapolation=kLINEAR)
Register a new threshold scan trigger which plots rate as a function of some dependent variable.
Definition: RatesAnalysisAlg.cxx:40
WeightingValuesSummary_t::m_isUnbiased
bool m_isUnbiased
If the event was taken online with a RD trigger.
Definition: RatesHistoBase.h:60
RatesAnalysisAlg::m_l2GroupName
const std::string m_l2GroupName
Definition: RatesAnalysisAlg.h:264
RatesGroup::setUseCachedWeights
void setUseCachedWeights(const bool i)
Set to use cached weights from the Master group (need ptr to m_masterGroup)
Definition: RatesGroup.cxx:188
RatesAnalysisAlg.h
RunTileMonitoring.groupName
groupName
Definition: RunTileMonitoring.py:158
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
RatesAnalysisAlg::m_bcidHist
TH1D * m_bcidHist
Histogram of the BCIDs distribution of the processing.
Definition: RatesAnalysisAlg.h:292
WeightingValuesSummary_t::m_eventLumi
double m_eventLumi
The instantaneous lumi in cm-2s-1.
Definition: RatesHistoBase.h:59
skel.it
it
Definition: skel.GENtoEVGEN.py:407
RatesAnalysisAlg::m_enhancedBiasRatesTool
ToolHandle< IEnhancedBiasWeighter > m_enhancedBiasRatesTool
Definition: RatesAnalysisAlg.h:267
RatesAnalysisAlg::ratesInitialize
virtual StatusCode ratesInitialize()=0
To be implemented by the user.
WeightingValuesSummary_t::print
const std::string print()
Definition: RatesHistoBase.h:69
RatesAnalysisAlg::m_expoScalingFactor
Gaudi::Property< double > m_expoScalingFactor
Definition: RatesAnalysisAlg.h:271
TrigConf::HLTPrescalesSet::prescale_express
const HLTPrescale & prescale_express(const std::string &chainName) const
HLT prescales by chain names.
Definition: HLTPrescalesSet.cxx:96
RatesAnalysisAlg::m_groups
std::unordered_map< std::string, std::unique_ptr< RatesGroup > > m_groups
All regular and CPS groups.
Definition: RatesAnalysisAlg.h:247
RatesAnalysisAlg::m_ratesDenominator
double m_ratesDenominator
How much walltime is seen by the algorithm.
Definition: RatesAnalysisAlg.h:190
WeightingValuesSummary_t::m_linearLumiFactor
double m_linearLumiFactor
What weight needs to be applied to extrapolate rates linear in mu and bunches.
Definition: RatesHistoBase.h:66
WeightingValuesSummary_t::m_distanceInTrain
uint32_t m_distanceInTrain
How far into the bunch train the event was, in bunch crossings.
Definition: RatesHistoBase.h:61
RatesAnalysisAlg::m_doUniqueRates
Gaudi::Property< bool > m_doUniqueRates
Definition: RatesAnalysisAlg.h:273
RatesAnalysisAlg::m_globalGroups
std::unordered_map< std::string, std::unique_ptr< RatesGroup > > m_globalGroups
Big (master) groups which do the OR of the whole menu.
Definition: RatesAnalysisAlg.h:248
RatesAnalysisAlg::m_targetMu
double m_targetMu
What pileup level the prediction is targeting.
Definition: RatesAnalysisAlg.h:284
TrigConf::L1Menu
L1 menu configuration.
Definition: L1Menu.h:28
L1PrescalesSet.h
python.TrigTLAMonitorAlgorithm.triggers
triggers
Definition: TrigTLAMonitorAlgorithm.py:196
RatesAnalysisAlg::m_autoTriggers
std::vector< std::string > m_autoTriggers
List of triggers which it is up to us to the algorithm to work out the pass/fail for.
Definition: RatesAnalysisAlg.h:255
TrigConf::L1BunchGroupSet::getBunchGroup
const std::shared_ptr< L1BunchGroup > & getBunchGroup(const std::string &name) const
Accessor to the bunchgroup by name.
Definition: L1BunchGroupSet.cxx:118
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
RatesScanTrigger::TriggerBehaviour_t
TriggerBehaviour_t
enum to describe if a trigger should activate for values >= or <= than the thresold
Definition: RatesScanTrigger.h:20
RatesAnalysisAlg::kEXISTING
@ kEXISTING
The pass/fail decision is taken from the Trigger Decision Tool for an existing trigger.
Definition: RatesAnalysisAlg.h:46
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
H5Utils::getTree
std::string getTree(const std::string &file_name)
Definition: getTree.cxx:36
RatesTrigger::setUniqueGroup
void setUniqueGroup(const RatesGroup *unique)
If I have a group which is calculating my unique rate.
Definition: RatesTrigger.cxx:163
ExtrapStrat_t
ExtrapStrat_t
Extrapolation strategy to apply to each emulated trigger.
Definition: RatesHistoBase.h:30
RatesAnalysisFullMenu.prescales
prescales
Definition: RatesAnalysisFullMenu.py:118
RatesAnalysisAlg::setTargetMuBunches
void setTargetMuBunches(const double mu, const int32_t bunches)
Set the target mu and number of bunches.
Definition: RatesAnalysisAlg.cxx:747
RatesAnalysisAlg::m_prescalesJSON
Gaudi::Property< std::map< std::string, std::map< std::string, double > > > m_prescalesJSON
Definition: RatesAnalysisAlg.h:281
RatesAnalysisAlg::setTargetLumiMu
void setTargetLumiMu(const double lumi, const double mu)
Set the target instantaneous luminosity and mu.
Definition: RatesAnalysisAlg.cxx:710
RatesAnalysisAlg::kAUTO
@ kAUTO
The pass/fail decision is automatically emulated per event based on decoding the trigger name.
Definition: RatesAnalysisAlg.h:45
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
RatesAnalysisAlg::m_weightedEventCounter
double m_weightedEventCounter
Count how many weighted events were processed.
Definition: RatesAnalysisAlg.h:289
RatesTrigger
Used to calculate the rate for a single trigger at L1 or the HLT.
Definition: RatesTrigger.h:15
RatesAnalysisAlg::initialize
virtual StatusCode initialize()
Get the trigger decision tool and set up global groups.
Definition: RatesAnalysisAlg.cxx:369
RatesGroup
Used to calculate the rate for a group of RatesTrigger objects at L1 or the HLT.
Definition: RatesGroup.h:29
RatesAnalysisAlg::Method_t
Method_t
Method by which the trigger pass/fail decision is calculated.
Definition: RatesAnalysisAlg.h:43
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
WeightingValuesSummary_t::m_enhancedBiasWeight
double m_enhancedBiasWeight
A property of the event derived from online enhanced bias prescales.
Definition: RatesHistoBase.h:57
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
RatesAnalysisAlg::executeTriggerEmulation
StatusCode executeTriggerEmulation()
Internal call to get the pass/fail for all automatically emulated triggers.
Definition: RatesAnalysisAlg.cxx:666
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
RatesTrigger::setSeedsFromRandom
void setSeedsFromRandom(const bool i)
Set if this trigger is to behave as if it seeds from a random L1 item.
Definition: RatesTrigger.cxx:145
Trk::active
@ active
Definition: Layer.h:48
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigConf::HLTPrescalesSet::prescale
const HLTPrescale & prescale(const std::string &chainName) const
HLT prescales by chain names.
Definition: HLTPrescalesSet.cxx:85
RatesTrigger::setCPS
void setCPS(const std::string &group)
If I'm in a CPS group, set the group name (I'll keep a copy of the hash)
Definition: RatesTrigger.cxx:167
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
RatesAnalysisAlg::m_metadataTree
TTree * m_metadataTree
Used to write out some metadata needed by post-processing (e.g.
Definition: RatesAnalysisAlg.h:294
RatesAnalysisAlg::m_targetBunches
double m_targetBunches
How many bunches the prediction is targeting.
Definition: RatesAnalysisAlg.h:285
RatesAnalysisAlg::setTargetLumiBunches
void setTargetLumiBunches(const double lumi, const int32_t bunches)
Set the target instantaneous luminosity and number of bunches.
Definition: RatesAnalysisAlg.cxx:730
RatesAnalysisAlg::RatesAnalysisAlg
RatesAnalysisAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: RatesAnalysisAlg.cxx:22
RatesAnalysisAlg::isCPS
bool isCPS(const std::string &group) const
String match coherent prescale groups.
Definition: RatesAnalysisAlg.cxx:790
RatesAnalysisAlg::m_uniqueGroups
std::unordered_map< std::string, std::unique_ptr< RatesGroup > > m_uniqueGroups
Groups used to obtain unique rates for chains.
Definition: RatesAnalysisAlg.h:249
RatesAnalysisAlg::m_weightingValues
WeightingValuesSummary_t m_weightingValues
Possible weighting & lumi extrapolation values for the current event.
Definition: RatesAnalysisAlg.h:189
RatesAnalysisAlg::addExisting
StatusCode addExisting(const std::string &pattern)
Register some existing triggers based on wild-card match, e.g.
Definition: RatesAnalysisAlg.cxx:194
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
WeightingValuesSummary_t::m_expoMuFactor
double m_expoMuFactor
What weight needs to be applied to extrapolate rates linear in bunches and exponential in mu.
Definition: RatesHistoBase.h:67
TrigConf::L1BunchGroupSet::maxNBunchGroups
constexpr std::size_t maxNBunchGroups() const
Maximum number of bunchgroups.
Definition: L1BunchGroupSet.h:107
RatesTrigger::getCPSID
size_t getCPSID() const
Get the hash of my CPS group name.
Definition: RatesTrigger.cxx:169
RatesAnalysisAlg::kMANUAL
@ kMANUAL
The pass/fail decision is evaluated by the user and supplied per event using setTriggerDesicison.
Definition: RatesAnalysisAlg.h:44
RatesAnalysisAlg::m_doHistograms
Gaudi::Property< bool > m_doHistograms
Definition: RatesAnalysisAlg.h:191
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
RatesAnalysisAlg::execute
virtual StatusCode execute()
In first call - register all triggers.
Definition: RatesAnalysisAlg.cxx:586
TrigConf::L1BunchGroupSet
L1 board configuration.
Definition: L1BunchGroupSet.h:71
RatesGroup::removeOtherL1
void removeOtherL1(const RatesTrigger *toKeep)
Remove from the groups mapping all triggers which have a dissimilar seed to the supplied trigger.
Definition: RatesGroup.cxx:72
RatesAnalysisAlg::m_activeGroups
std::unordered_set< RatesGroup * > m_activeGroups
All groups which are enabled (PS >= 1)
Definition: RatesAnalysisAlg.h:253
RatesAnalysisAlg::printTarget
void printTarget() const
Print the target instantaneous luminosity, mu and number of bunches.
Definition: RatesAnalysisAlg.cxx:768
TrigConf::HLTMenu::begin
const_iterator begin() const
Begin of the HLT chains list.
Definition: HLTMenu.cxx:51
RatesAnalysisAlg::isRandomSeed
bool isRandomSeed(const std::string &me, const std::string &seed) const
String match random L1 items.
Definition: RatesAnalysisAlg.cxx:794
EnhancedBiasWeighter::FULL_RING
constexpr static uint32_t FULL_RING
Number of bunches in a full ring.
Definition: EnhancedBiasWeighter.h:56
RatesTrigger::getDisabled
bool getDisabled() const
If I or my seed were prescaled out.
Definition: RatesTrigger.cxx:161
TrigConf::L1PrescalesSet
L1 menu configuration.
Definition: L1PrescalesSet.h:19
WeightingValuesSummary_t::m_bunchFactor
double m_bunchFactor
What weight needs to be applied to extrapolate rates linear in number of bunches.
Definition: RatesHistoBase.h:64
TrigConf::HLTMenu::size
std::size_t size() const
Accessor to the number of HLT chains.
Definition: HLTMenu.cxx:35
TrigConf::ConstIter
Forward iterator over an iterable of type V returning an object of type T.
Definition: ConstIter.h:32
BunchGroupSet.h
RatesAnalysisAlg::m_activatedTriggers
std::unordered_set< RatesTrigger * > m_activatedTriggers
Triggers which were changed & hence need to be reset at the event end.
Definition: RatesAnalysisAlg.h:251
L1BunchGroupSet.h
RatesAnalysisAlg::m_doExpressRates
Gaudi::Property< bool > m_doExpressRates
Definition: RatesAnalysisAlg.h:276
RatesHistoBase::isZero
static bool isZero(double v)
Definition: RatesHistoBase.h:103
EnhancedBiasWeighter::LHC_FREQUENCY
constexpr static double LHC_FREQUENCY
Definition: EnhancedBiasWeighter.h:55
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
threshold
Definition: chainparser.cxx:74
RatesAnalysisAlg::m_scalingHist
TH1D * m_scalingHist
One-bin histogram to store the normalisation of the sample, for use in later combinations.
Definition: RatesAnalysisAlg.h:291
RatesAnalysisAlg::setTargetLumi
void setTargetLumi(const double lumi)
Set the target instantaneous luminosity.
Definition: RatesAnalysisAlg.h:172
RatesAnalysisAlg::executeTrigDecisionToolTriggers
StatusCode executeTrigDecisionToolTriggers()
Internal call to get the pass/fail for all TDT triggers.
Definition: RatesAnalysisAlg.cxx:653
RatesGroup::setUniqueTrigger
void setUniqueTrigger(RatesTrigger *trigger)
Set trigger I am doing unique rates for.
Definition: RatesGroup.cxx:196
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
RatesAnalysisAlg::checkExistingTrigger
StatusCode checkExistingTrigger(const std::string &name, const std::string &seedName)
Internal function to check if a supplied HLT trigger and L1 seed match what is stored in the AOD conf...
Definition: RatesAnalysisAlg.cxx:325
RatesAnalysisAlg::writeMetadata
void writeMetadata()
Write to outpute tree (if any) the metadata needed downstream.
Definition: RatesAnalysisAlg.cxx:807
RatesAnalysisAlg::m_triggers
std::unordered_map< std::string, std::unique_ptr< RatesTrigger > > m_triggers
All individual triggers (L1 or HLT)
Definition: RatesAnalysisAlg.h:245
RatesAnalysisAlg::getLevel
uint32_t getLevel(const std::string &name) const
String match to a trigger level.
Definition: RatesAnalysisAlg.cxx:801
RatesAnalysisAlg::m_configSvc
ServiceHandle< TrigConf::ITrigConfigSvc > m_configSvc
Definition: RatesAnalysisAlg.h:269
lumiFormat.lumi
lumi
Definition: lumiFormat.py:106
RatesAnalysisAlg::printInputSummary
void printInputSummary() const
Print the input data instantaneous luminosity, mu and number of bunches.
Definition: RatesAnalysisAlg.cxx:780
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
RatesAnalysisAlg::m_l1GroupName
const std::string m_l1GroupName
Definition: RatesAnalysisAlg.h:263
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
RatesAnalysisAlg::m_lowestPrescale
std::unordered_map< size_t, double > m_lowestPrescale
Lowest prescale within a CPS group, key is the hash of the CPS group name.
Definition: RatesAnalysisAlg.h:254
DEBUG
#define DEBUG
Definition: page_access.h:11
RatesAnalysisAlg::m_l1ItemID
std::vector< std::vector< std::string > > m_l1ItemID
Definition: RatesAnalysisAlg.h:261
python.TriggerAPI.TriggerAPISession.chainName
chainName
Definition: TriggerAPISession.py:426
TrigConf::L1PrescalesSet::prescales
const std::map< std::string, L1Prescale > & prescales() const
Definition: L1PrescalesSet.cxx:58
python.XMLReader.l1menu
l1menu
Definition: XMLReader.py:73
RatesAnalysisAlg::ratesFinalize
virtual StatusCode ratesFinalize()=0
To be implemented by the user.
TrigConf::HLTPrescalesSet::HLTPrescale::enabled
bool enabled
Definition: HLTPrescalesSet.h:23
RatesAnalysisAlg::m_existingTriggers
std::unordered_map< std::string, const Trig::ChainGroup * > m_existingTriggers
Map of triggers which we ask the TDT ChainGroup for the pass/fail.
Definition: RatesAnalysisAlg.h:257
HLTMenu.h
ValidateEBMenu.seedName
seedName
Definition: ValidateEBMenu.py:100
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
RatesAnalysisAlg::m_vetoStartOfTrain
Gaudi::Property< uint32_t > m_vetoStartOfTrain
Definition: RatesAnalysisAlg.h:280
WeightingValuesSummary_t::m_muFactor
double m_muFactor
What weight needs to be applied to extrapolate rates linear in mu.
Definition: RatesHistoBase.h:65
RatesAnalysisAlg::addAllExisting
StatusCode addAllExisting()
Register all existing triggers in the AOD into the rates algorithm.
Definition: RatesAnalysisAlg.cxx:189
RatesAnalysisAlg::finalize
virtual StatusCode finalize()
Print rates.
Definition: RatesAnalysisAlg.cxx:674
L1Menu.h
RatesAnalysisAlg::m_doTriggerGroups
Gaudi::Property< bool > m_doTriggerGroups
Definition: RatesAnalysisAlg.h:275
TrigConf::Chain
HLT chain configuration.
Definition: TrigConfData/TrigConfData/HLTChain.h:18
RatesAnalysisAlg::m_useBunchCrossingData
Gaudi::Property< bool > m_useBunchCrossingData
Definition: RatesAnalysisAlg.h:277
RatesAnalysisAlg::m_targetLumi
double m_targetLumi
What instantaneous luminosity the prediction is targeting.
Definition: RatesAnalysisAlg.h:286
TrigConf::HLTPrescalesSet
HLT menu configuration.
Definition: HLTPrescalesSet.h:19
RatesAnalysisAlg::m_eventCounter
uint32_t m_eventCounter
Count how many events processed.
Definition: RatesAnalysisAlg.h:288
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
python.compressB64.c
def c
Definition: compressB64.py:93
RatesAnalysisAlg::setTriggerDesicison
StatusCode setTriggerDesicison(const std::string &name, const bool triggerIsPassed=true, const bool triggerIsActive=true)
Set the pass/fail decision for an item.
Definition: RatesAnalysisAlg.cxx:342
TrigConf::HLTMenu::end
const_iterator end() const
End of the HLT chains list.
Definition: HLTMenu.cxx:57
RatesAnalysisAlg::m_inelasticCrossSection
Gaudi::Property< double > m_inelasticCrossSection
Definition: RatesAnalysisAlg.h:272
RatesAnalysisAlg::m_doGlobalGroups
Gaudi::Property< bool > m_doGlobalGroups
Definition: RatesAnalysisAlg.h:274
RatesAnalysisAlg::m_hltChainIDGroup
std::vector< std::vector< std::string > > m_hltChainIDGroup
Definition: RatesAnalysisAlg.h:260
RatesAnalysisAlg::isZero
bool isZero(double v) const
Helper function for floating point subtraction.
Definition: RatesAnalysisAlg.h:243
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
RatesGroup::duplicateChildren
void duplicateChildren(const RatesGroup *toDuplicate)
Copy in triggers from another group.
Definition: RatesGroup.cxx:190
kNONE
@ kNONE
Do not scale this trigger for changes in luminosity.
Definition: RatesHistoBase.h:35
RatesAnalysisAlg::m_expressTriggers
std::unordered_set< RatesTrigger * > m_expressTriggers
Triggers with non-zero express PS, used to print them at the end.
Definition: RatesAnalysisAlg.h:252
WeightingValuesSummary_t::m_eventMu
double m_eventMu
The actual number of interactions in the event.
Definition: RatesHistoBase.h:58