ATLAS Offline Software
RatesAnalysisAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // RatesAnalysis includes
8 
10 
12 #include "TrigConfData/HLTMenu.h"
13 #include "TrigConfData/L1Menu.h"
16 //uncomment the line below to use the HistSvc for outputting trees and histograms
17 #include "GaudiKernel/ITHistSvc.h"
18 #include "TH1.h"
19 
20 #include <sstream>
21 
22 
23 RatesAnalysisAlg::RatesAnalysisAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
24  AthAnalysisAlgorithm( name, pSvcLocator ),
25  m_targetMu(0.),
26  m_targetBunches(0.),
27  m_targetLumi(0.),
28  m_runNumber(0.),
29  m_ratesDenominator(0),
30  m_eventCounter(0),
31  m_weightedEventCounter(0),
32  m_scalingHist(nullptr),
33  m_bcidHist(nullptr),
34  m_metadataTree(nullptr),
35  m_weightingValues()
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 
123  if (method == kEXISTING) ATH_CHECK( checkExistingTrigger(name, seedName) ); // Check this agrees with what is in the AOD
124 
125  // Check if it already exists
126  if (m_triggers.count(name) == 1) {
127  ATH_MSG_WARNING("Trigger " << name << " is already registered.");
128  return StatusCode::SUCCESS;
129  }
130 
131  const ExtrapStrat_t e = (m_enableLumiExtrapolation ? extrapolation : ExtrapStrat_t::kNONE);
132 
133  m_triggers.emplace(name, std::make_unique<RatesTrigger>(name, msgSvc(), prescale, expressPrescale, seedName, seedPrecale, m_doHistograms, e));
134  RatesTrigger* newTriggerPtr = m_triggers.at(name).get();
135 
136  if (isRandomSeed(name, seedName)) newTriggerPtr->setSeedsFromRandom(true);
137 
138  // Only worthwhile doing the remainder if the trigger is not disabled. Otherwise will slow everything down
139  if (newTriggerPtr->getDisabled()) {
140  ATH_MSG_DEBUG("newTrigger " << name << " added (disabled)");
141  return StatusCode::SUCCESS;
142  }
143 
144  if (method == kAUTO) {
145  m_autoTriggers.push_back(name);
146  } else if (method == kEXISTING) {
147  m_existingTriggers[name] = m_tdt->getChainGroup(name);
149  }
150 
151  // Add this trigger to its groups
152  if (m_doTriggerGroups) {
153  for (const std::string& group : groups) {
154  // Ignore BW and PS groups
155  if (group.starts_with("BW") || group.starts_with("PS") || group.starts_with("STREAM:express")) continue;
156 
157  const auto [it, inserted] = m_groups.try_emplace(group, std::make_unique<RatesGroup>(group, msgSvc(), m_doHistograms, m_enableLumiExtrapolation));
158  if (inserted) {
159  // 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)
160  m_activeGroups.insert( it->second.get() );
161  }
162  it->second->addToGroup( newTriggerPtr );
163  // For CPS, we let the trigger know that it is special
164  if (isCPS(group)) {
165  if (newTriggerPtr->getCPSID() != 0) ATH_MSG_WARNING("Trigger " << name << " can only be in one coherent prescale group.");
166  newTriggerPtr->setCPS(group); // This changes the CPSID
167  const size_t CPSID = newTriggerPtr->getCPSID();
168  // Find the lowest prescale of any member in this CPS group
169  m_lowestPrescale.try_emplace(CPSID, FLT_MAX);
170  if (prescale < m_lowestPrescale[CPSID]) m_lowestPrescale[CPSID] = prescale;
171  }
172  }
173  }
174 
175  // Add to total rates
176  const uint32_t level = getLevel(name);
177  if (m_doGlobalGroups) {
178  if (level == 2) m_globalGroups.at(m_l2GroupName)->addToGroup( newTriggerPtr );
179  else if (level == 1) m_globalGroups.at(m_l1GroupName)->addToGroup( newTriggerPtr );
180  }
181  // Add to express group - if express prescale is enabled
182  if (level == 2 && expressPrescale >= 1) {
183  if (m_doGlobalGroups) m_globalGroups.at(m_expressGroupName)->addToGroup( newTriggerPtr );
184  if (m_doExpressRates) m_expressTriggers.insert( newTriggerPtr );
185  }
186 
187  ATH_MSG_DEBUG("newTrigger " << name << " added");
188  return StatusCode::SUCCESS;
189 }
190 
193  return addExisting(".*");
194 }
195 
197  // Check we have the TDT
199 
200  const auto& triggers = m_tdt->getListOfTriggers(pattern);
201  ATH_MSG_INFO("Read " << triggers.size() << " triggers from AOD.");
202 
203  // Check if chain was disabled in athena job
204  const bool runWithPrescaleJSON = !m_prescalesJSON.value().empty();
205  const TrigConf::HLTPrescalesSet& hltPrescalesSet = m_configSvc->hltPrescalesSet(Gaudi::Hive::currentContext());
206  for( auto & p : hltPrescalesSet.data().get_child("prescales") ) {
207  if ((!m_prescalesJSON.value().count(p.first) && !runWithPrescaleJSON) || hltPrescalesSet.prescale(p.first).prescale < 0){
208  m_prescalesJSON[p.first]["prescale"] = (hltPrescalesSet.prescale(p.first).enabled ? hltPrescalesSet.prescale(p.first).prescale : -1);
209  m_prescalesJSON[p.first]["prescale_express"] = (hltPrescalesSet.prescale_express(p.first).enabled ? hltPrescalesSet.prescale_express(p.first).prescale : -1);
210  if (hltPrescalesSet.prescale(p.first).prescale < 0){
211  ATH_MSG_WARNING("Trigger " << p.first << " disabled in supplied AOD file. DISABLING");
212  }
213  }
214  }
215 
216  const TrigConf::L1PrescalesSet& l1PrescalesSet = m_configSvc->l1PrescalesSet(Gaudi::Hive::currentContext());
217  for( auto & p : l1PrescalesSet.prescales() ) {
218  if ((!m_prescalesJSON.value().count(p.first) && !runWithPrescaleJSON) || p.second.prescale < 0){
219  m_prescalesJSON[p.first]["prescale"] = p.second.prescale;
220 
221  if (p.second.prescale < 0){
222  ATH_MSG_WARNING("Trigger " << p.first << " disabled in supplied AOD file. DISABLING");
223  }
224  }
225  }
226 
227  // Iterate over the triggers and add them
228  for (const auto& trigger : triggers) {
229  ATH_MSG_DEBUG("Considering " << trigger );
230  const bool isHLT = (getLevel(trigger) == 2);
231  const auto trigConf = (isHLT ? m_tdt->ExperimentalAndExpertMethods().getChainConfigurationDetails(trigger) : nullptr);
232  if (isHLT && !trigConf) {
233  ATH_MSG_ERROR("Problem with TDT trig conf - cannot get details for " << trigger << ", will be ignored.");
234  continue;
235  }
236  const std::string lowerName = (isHLT ? trigConf->lower_chain_name() : "");
237  std::set<std::string> groups = std::set<std::string>(); // To be filled later from the HLTMenu
238 
239  if (isHLT) {
240  // 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
241  if (lowerName.find(",") != std::string::npos) {
242  ATH_MSG_WARNING("Can not add " << trigger << " due to multiple L1 seeds." );
243  continue;
244  }
245 
246  if (lowerName.empty()) {
247  ATH_MSG_WARNING("Can not add " << trigger << " due to multiple L1 seeds: L1All" );
248  continue;
249  }
250 
251  // Check it also wasn't disabled in the reprocessing (e.g. auto prescaled out in a perf or tightperf menu)
252  if (trigConf->prescale() < 1.) { // Note this prescale is from ATHENA
253  ATH_MSG_DEBUG("Will not add " << trigger << ", it was disabled in the reprocessing.");
254  continue;
255  }
256 
257  ATH_CHECK(m_configSvc.isValid());
258  const TrigConf::HLTMenu& hltMenu = m_configSvc->hltMenu(Gaudi::Hive::currentContext());
259 
260  TrigConf::HLTMenu::const_iterator chain = std::find_if(hltMenu.begin(), hltMenu.end(), [&] (const TrigConf::Chain& c) {return c.name() == trigger;});
261  if (chain == hltMenu.end()){
262  ATH_MSG_WARNING("Chain " << trigger << " not found in the menu!");
263  continue;
264  }
265 
266  std::vector<std::string> chainGroups = (*chain).groups();
267  std::vector<std::string> chainStreams = (*chain).streams();
268 
269  ATH_MSG_DEBUG(" chain " << trigger << " has " << chainGroups.size() << " groups and " << chainStreams.size() << " streams");
270 
271  groups.insert(chainGroups.begin(), chainGroups.end());
272  for (const std::string& stream : chainStreams){
273  groups.insert("STREAM:" + stream );
274  }
275  }
276 
277  // Get the prescale, express prescale and lower prescale. Note these prescales are from SUPPLIED JSON.
278  double prescale = 1., expressPrescale = -1., lowerPrescale = 1.;
279  if (m_prescalesJSON.size() != 0) {
280  if (m_prescalesJSON.value().count(trigger) == 0) {
281  ATH_MSG_WARNING("Unable to find " << trigger << " in supplied JSON. DISABLING." );
282  prescale = 0.;
283  } else {
284  prescale = m_prescalesJSON[trigger]["prescale"];
285  expressPrescale = m_prescalesJSON[trigger]["prescale_express"];
286  }
287  if (isHLT) {
288  if (m_prescalesJSON.value().count(lowerName) == 0) {
289  ATH_MSG_WARNING("Unable to find " << trigger << "'s seed, " << lowerName << ", in supplied JSON. DISABLING." );
290  lowerPrescale = 0.;
291  } else {
292  lowerPrescale = m_prescalesJSON[lowerName]["prescale"];
293  }
294  }
295  }
296 
297 
298  // We now have all the info needed to add this trigger
299  ATH_MSG_DEBUG("Registering existing trigger " << trigger << " for automatic TDT based rates prediction." );
300  ATH_CHECK( newTrigger(trigger, prescale, expressPrescale, lowerName, lowerPrescale, groups, kEXISTING) );
301  }
302 
303  for (const auto& trigger : m_prescalesJSON) {
304  if (trigger.second.at("prescale") > 0 && std::find(triggers.begin(), triggers.end(), trigger.first) == triggers.end()) {
305  ATH_MSG_WARNING( "Trigger " << trigger.first << " in supplied JSON is NOT AVAILABLE in the supplied AOD file.");
306  }
307  }
308 
309  return StatusCode::SUCCESS;
310 }
311 
313  if (m_tdt.empty()){
314  ATH_MSG_ERROR("TriggerDecisionTool is not available!");
315  return StatusCode::FAILURE;
316  }
317  [[maybe_unused]] static std::atomic<bool> printed = [&]() {
318  ATH_MSG_INFO("TDT contains: " << m_tdt->getListOfTriggers().size() << " triggers, "
319  << m_tdt->getListOfStreams().size() << " streams and "
320  << m_tdt->getListOfGroups().size() << " groups.");
321  return true;
322  }();
323  return StatusCode::SUCCESS;
324 }
325 
326 
327 StatusCode RatesAnalysisAlg::checkExistingTrigger(const std::string& name, const std::string& seedName) {
329  const auto& triggers = m_tdt->getListOfTriggers(name);
330  if (triggers.size() != 1) {
331  ATH_MSG_FATAL("Unable to find existing trigger " << name << " in this AOD.");
332  return StatusCode::FAILURE;
333  }
334  if (getLevel(name) == 1) return StatusCode::SUCCESS;
335  // L1 items will crash if we call this on them.
336  const auto trigConf = m_tdt->ExperimentalAndExpertMethods().getChainConfigurationDetails(triggers.at(0));
337  if (trigConf->lower_chain_name() != seedName) {
338  ATH_MSG_FATAL("Tried to register an existing trigger '" << name << "' seeding from '" << seedName << "' but in this AOD it seeds from '" << trigConf->lower_chain_name() << "'");
339  return StatusCode::FAILURE;
340  }
341  return StatusCode::SUCCESS;
342 }
343 
344 StatusCode RatesAnalysisAlg::setTriggerDesicison(const std::string& name, const bool triggerIsPassed, const bool triggerIsActive) {
345  // Currently - we call execute on setPassed, so the user would be unable to overwrite a decision set e.g. by the TDT.
346  // so for now we only accept positive decisions here.
347  if (triggerIsPassed || triggerIsActive) {
348  const auto iterator = m_triggers.find(name);
349  if (iterator == m_triggers.end()) {
350  ATH_MSG_ERROR("Cannot find trigger " << name << " did you call newTrigger for this in initialize?");
351  return StatusCode::FAILURE;
352  }
353  iterator->second->setPassedAndExecute(triggerIsPassed, triggerIsActive, m_weightingValues); // There is logic in the RatesTrigger to prevent multiple calls per event by accident.
354  m_activatedTriggers.insert( iterator->second.get() );
355  }
356  return StatusCode::SUCCESS;
357 }
358 
359 
361  const auto iterator = m_scanTriggers.find(name);
362  if (iterator == m_scanTriggers.end()) {
363  ATH_MSG_ERROR("Cannot find scan-trigger " << name << " did you call newScanTrigger for this in initialize?");
364  return StatusCode::FAILURE;
365  }
366  iterator->second->setPassedAndExecute(threshold, m_weightingValues); // There is logic in the RatesScanTrigger to prevent multiple calls per event by accident.
367  m_activatedTriggers.insert( static_cast<RatesTrigger*>(iterator->second.get()));
368  return StatusCode::SUCCESS;
369 }
370 
372  ATH_MSG_INFO ("Initializing " << name() << "...");
373 
374  if (!m_tdt.empty()){
375  ATH_CHECK( m_tdt.retrieve() );
376  }
377 
378  if(!m_configSvc.empty()) {
379  ATH_CHECK( m_configSvc.retrieve() );
380  }
381 
382  ATH_CHECK( m_enhancedBiasRatesTool.retrieve() );
383 
385  ATH_MSG_ERROR("DoUniqueRates=True requires DoGlobalGroups=True");
386  return StatusCode::FAILURE;
387  }
388 
389  return StatusCode::SUCCESS;
390 }
391 
393  // Let user add their triggers
394  ATH_MSG_INFO("Initializing User's Triggers (note: we are actually now in the event loop)");
395 
396  if (m_doGlobalGroups) {
397  m_globalGroups.emplace(m_l1GroupName, std::make_unique<RatesGroup>(m_l1GroupName, msgSvc(), m_doHistograms, m_enableLumiExtrapolation));
398  m_globalGroups.emplace(m_l2GroupName, std::make_unique<RatesGroup>(m_l2GroupName, msgSvc(), m_doHistograms, m_enableLumiExtrapolation));
399  m_globalGroups.at(m_l2GroupName)->setDoCachedWeights( m_doUniqueRates ); // This extra sub-weight caching is only utilised by unique-rate groups
400  if (m_doExpressRates) {
402  m_globalGroups.at(m_expressGroupName)->setExpressGroup( true );
403  }
404  }
405 
406  // This runs the derived class's code to add whatever triggers are desired.
407  // Should be calling newTrigger(...), newScanTrigger(...) or addExisting(...), addAllExisting().
409 
410  ATH_MSG_INFO("Computing coherent factors for coherent prescale groups.");
411  // Now we are not going to get any more chains - we can fill in the coherent prescale factors
412  for (const auto& trigger : m_triggers) {
413  const size_t CPSID = trigger.second->getCPSID();
414  if (CPSID != 0) trigger.second->setCoherentFactor( m_lowestPrescale.at(CPSID) );
415  }
416 
418  ATH_MSG_INFO("Creating extra groups to calculate unique rates.");
419  const RatesGroup* l2GroupPtr = m_globalGroups.at(m_l2GroupName).get(); // The finalised list of all HLT chains
420  const RatesGroup* l1GroupPtr = m_globalGroups.at(m_l1GroupName).get(); // The finalised list of all L1 chains
421  for (const auto& trigger : m_triggers) {
422  const uint32_t level = getLevel(trigger.first);
423  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
424  RatesTrigger* triggerPtr = m_triggers.at(trigger.first).get();
425  RatesGroup* uniqueGroupPtr = m_uniqueGroups.at(trigger.first).get();
426  triggerPtr->setUniqueGroup( uniqueGroupPtr ); // Create two-way links
427  uniqueGroupPtr->setUniqueTrigger( triggerPtr ); // Create two-way links
428  // Copy in the global rates topology and make note of the unique rates master group
429  if (level == 2) uniqueGroupPtr->duplicateChildren( l2GroupPtr );
430  else if (level == 1) uniqueGroupPtr->duplicateChildren( l1GroupPtr );
431  else continue;
432  // Remove this one chain from the group (a unique rate is the rate of the entire menu minus one chain)
433  uniqueGroupPtr->removeFromGroup( triggerPtr );
434  if (getLevel(trigger.first) == 2) {
435  // For HLT, we can be more computationally efficient by utilising cached info from the hlt group
436  // We remove from the group all other L1 seeds except for the one seeding our chain.
437  // This sub-weight is the only one which can change. The combined weight of all other L1 seeds
438  // can be cached by the master group and fetched from there.
439  uniqueGroupPtr->removeOtherL1( triggerPtr );
440  uniqueGroupPtr->setUseCachedWeights(true);
441  }
442  // Efficiency - if the trigger is disabled, no need to actually calculate anything for it.
443  if (trigger.second->getDisabled() == false) {
444  m_activeGroups.insert( uniqueGroupPtr ); // Add this to the event loop
445  }
446  }
447  }
448 
449  ATH_MSG_INFO("Retrieving HLT chain's ID and Group from HLT menu.");
450 
451  if(!m_configSvc.empty() && m_configSvc.isValid()) {
452  const TrigConf::HLTMenu& hltmenu = m_configSvc->hltMenu( Gaudi::Hive::currentContext() );
453 
454  TrigConf::HLTMenu::const_iterator chain_itr = hltmenu.begin();
455  TrigConf::HLTMenu::const_iterator chain_end = hltmenu.end();
456 
457  m_hltChainIDGroup.resize(hltmenu.size());
458  for (size_t i = 0; i < hltmenu.size(); i++) m_hltChainIDGroup.at(i).resize(3);
459 
460  size_t c = 0;
461  for( ; chain_itr != chain_end; ++chain_itr ) {
462  std::string chainName = ( *chain_itr ).name() ;
463  unsigned int chainID = ( *chain_itr ).counter();
464  std::vector<std::string> chainGroups = ( *chain_itr ).groups();
465  for (std::string& stream : (*chain_itr).streams()){
466  chainGroups.push_back("STREAM:" + stream);
467  }
468  std::string singlechainGroups = "";
469  for (unsigned int j=0; j < chainGroups.size(); ++j){
470  if (j==0) singlechainGroups += chainGroups[j];
471  else singlechainGroups += ", "+chainGroups[j];
472  }
473 
474  m_hltChainIDGroup.at(c).at(0) = chainName;
475  m_hltChainIDGroup.at(c).at(1) = std::to_string(chainID);
476  m_hltChainIDGroup.at(c).at(2) = singlechainGroups;
477  ++c;
478  }
479  }
480 
481  ATH_MSG_INFO("Retrieving L1 item's ID from L1 menu.");
482 
483  if(!m_configSvc.empty() && m_configSvc.isValid()) {
484  const TrigConf::L1Menu& l1menu = m_configSvc->l1Menu( Gaudi::Hive::currentContext() );
485 
486  m_l1ItemID.resize(l1menu.size());
487  for (size_t i = 0; i < l1menu.size(); i++) {
488  // No groups for items
489  m_l1ItemID.at(i).resize(2);
490  }
491 
492  TrigConf::L1Menu::const_iterator item_itr = l1menu.begin();
493  TrigConf::L1Menu::const_iterator item_end = l1menu.end();
494 
495  size_t c = 0;
496  for( ; item_itr != item_end; ++item_itr ) {
497  m_l1ItemID.at(c).at(0) = (*item_itr).name();
498  m_l1ItemID.at(c).at(1) = std::to_string((*item_itr).ctpId());
499  ++c;
500  }
501  }
502 
503  // Print all triggers
504  if (msgLevel(MSG::DEBUG)) {
505  if (m_triggers.size()) {
506  ATH_MSG_DEBUG("################## Configured to estimate rates for the following triggers:");
507  for (const auto& trigger : m_triggers) ATH_MSG_DEBUG(trigger.second->printConfig());
508  }
509  if (m_scanTriggers.size()) {
510  ATH_MSG_DEBUG("################## Configured to estimate rates for the following scan triggers:");
511  for (const auto& trigger : m_scanTriggers) ATH_MSG_DEBUG(trigger.second->printConfig());
512  }
513  if (m_groups.size()) {
514  ATH_MSG_DEBUG("################## Configured to estimate rates for the following groups of triggers:");
515  for (const auto& group : m_groups) ATH_MSG_DEBUG(group.second->printConfig());
516  }
517  if (m_globalGroups.size()) {
518  ATH_MSG_DEBUG("################## Configured to estimate rates for the following global groups of triggers:");
519  for (const auto& group : m_globalGroups) ATH_MSG_DEBUG(group.second->printConfig());
520  }
521  }
522 
523  if (m_doHistograms) {
524  ATH_MSG_DEBUG("################## Registering normalisation histogram:");
525  m_scalingHist = new TH1D("normalisation",";;",3,0.,3.);
526  ATH_CHECK( histSvc()->regHist("/RATESTREAM/normalisation", m_scalingHist) );
527  m_bcidHist = new TH1D("bcid",";BCID;Events",3565,-.5,3564.5);
528  ATH_CHECK( histSvc()->regHist("/RATESTREAM/bcid", m_bcidHist) );
529  ATH_MSG_DEBUG("################## Registering metadata tree histogram:");
530  ATH_CHECK( histSvc()->regTree("/RATESTREAM/metadata", std::make_unique<TTree>("metadata", "metadata")) );
531  ATH_CHECK( histSvc()->getTree("/RATESTREAM/metadata", m_metadataTree) );
532  if (m_triggers.size()) {
533  ATH_MSG_DEBUG("################## Registering trigger histograms:");
534  for (const auto& trigger : m_triggers) {
535  if (!trigger.second->doHistograms()) continue; // Not all may be doing histograming
536  std::string lvlSubdir = "";
537  if (trigger.second->getName().find("L1") == 0){
538  lvlSubdir = "Rate_ChainL1_HLT/";
539  } else if (trigger.second->getName().find("HLT") == 0) {
540  lvlSubdir = "Rate_ChainHLT_HLT/";
541  }
542  ATH_CHECK( trigger.second->giveDataHist(histSvc(), std::string("/RATESTREAM/All/" + lvlSubdir + trigger.first + "/data")) );
543  ATH_CHECK( trigger.second->giveMuHist(histSvc(), std::string("/RATESTREAM/All/" + lvlSubdir + trigger.first + "/rateVsMu")) );
544  if (m_useBunchCrossingData) ATH_CHECK( trigger.second->giveTrainHist(histSvc(), std::string("/RATESTREAM/All/" + lvlSubdir + trigger.first + "/rateVsTrain")) );
545  else trigger.second->clearTrainHist();
546  }
547  }
548  if (m_scanTriggers.size()) {
549  ATH_MSG_DEBUG("################## Registering scan trigger histograms:");
550  for (const auto& trigger : m_scanTriggers) {
551  ATH_CHECK( trigger.second->giveThresholdHist(histSvc(), std::string("/RATESTREAM/ScanTriggers/" + trigger.first + "/rateVsThreshold")) );
552  }
553  }
554  if (m_groups.size()) {
555  ATH_MSG_DEBUG("################## Registering group histograms:");
556  for (const auto& group : m_groups) {
557  if (!group.second->doHistograms()) continue;
558  std::string groupName = group.first;
559  std::replace( groupName.begin(), groupName.end(), ':', '_');
560  ATH_CHECK( group.second->giveDataHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/" + groupName + "/data")) );
561  ATH_CHECK( group.second->giveMuHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/" + groupName + "/rateVsMu")) );
562  if (m_useBunchCrossingData) ATH_CHECK( group.second->giveTrainHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/" + groupName + "/rateVsTrain")) );
563  else group.second->clearTrainHist();
564  }
565  }
566  if (m_globalGroups.size()) {
567  ATH_MSG_DEBUG("################## Registering global group histograms:");
568  for (const auto& group : m_globalGroups) {
569  if (!group.second->doHistograms()) continue;
570  ATH_CHECK( group.second->giveDataHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" + group.first + "/data")) );
571  ATH_CHECK( group.second->giveMuHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" + group.first + "/rateVsMu")) );
572  if (m_useBunchCrossingData) ATH_CHECK( group.second->giveTrainHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" + group.first + "/rateVsTrain")) );
573  else group.second->clearTrainHist();
574  }
575  }
576  }
577 
578  // Has the user set a lumi extrapolation? If not - set a default
580 
581  // We now know the final lumi scaling so we can set the bunch scaling
582  const uint32_t ebPairedBunches = m_enhancedBiasRatesTool->getPairedBunches();
583  ATH_MSG_INFO("Number of paired bunches in input file:" << m_enhancedBiasRatesTool->getPairedBunches());
585 
586  return StatusCode::SUCCESS;
587 }
588 
590  ATH_MSG_DEBUG("Executing " << name() << " on event " << m_eventCounter << "...");
591  if (m_eventCounter++ == 0) { // First time in execute loop - cannot access TDT before this.
593  }
594 
595  // Get event characteristics
596  const xAOD::EventInfo* eventInfo(nullptr);
597  uint32_t distance = 0;
598  ATH_CHECK( evtStore()->retrieve(eventInfo, "EventInfo") );
599  ATH_CHECK( m_enhancedBiasRatesTool->getDistanceIntoTrain(eventInfo, distance) );
600 
601  // Get the weighting & scaling characteristics
603  m_weightingValues.m_eventMu = std::ceil(eventInfo->actualInteractionsPerCrossing()); // This always seems to be a half integer
604  m_weightingValues.m_eventLumi = m_enhancedBiasRatesTool->getLBLumi(eventInfo);
605  m_weightingValues.m_isUnbiased = m_enhancedBiasRatesTool->isUnbiasedEvent(eventInfo);
607  m_weightingValues.m_eventLiveTime = m_enhancedBiasRatesTool->getEBLiveTime(eventInfo);
608 
610 
611  // Bunch factor doesn't change as a fn. of the run. Reminder: m_bunchFactor = m_targetBunches / (double)ebPairedBunches;
615 
616  // Ignore zero weighted events. Typically these come from bad LB
617  if (RatesHistoBase::isZero(m_weightingValues.m_enhancedBiasWeight)) return StatusCode::SUCCESS;
618 
619  // Do automated triggers
621 
622  // Do TDT-controlled triggers
624 
625  // Run user's code. Do manual triggers
626  ATH_CHECK( ratesExecute() );
627 
628  // Execute groups
629  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.
630  for (const auto& group : m_activeGroups) group->execute(m_weightingValues); // Individual groups, CPS groups and active unique groups. Set.
631 
632  // Reset triggers
633  for (const auto& trigger : m_activatedTriggers) trigger->reset();
634  m_activatedTriggers.clear();
635 
636  // Keep track of elapsed walltime
639 
640  if (m_doHistograms) {
642  m_scalingHist->Fill(0.5, m_weightingValues.m_eventLiveTime); // Walltime
643  m_scalingHist->Fill(1.5, 1.); // Total events
644  m_scalingHist->Fill(2.5, m_weightingValues.m_enhancedBiasWeight); // Total events weighted
645  }
646 
647  // Some debug info
648  if (m_eventCounter % 1000 == 0) {
649  ATH_MSG_INFO( "Event " << m_eventCounter << " " << m_weightingValues.print() << " currentWallTime:" << m_ratesDenominator );
650  }
651 
652  setFilterPassed(true); //if got here, assume that means algorithm passed
653  return StatusCode::SUCCESS;
654 }
655 
657  for (const auto& trigger : m_existingTriggers) {
658  const bool passed = trigger.second->isPassed();
659  // L1 chains are always active, HLT chains are active if their L1 passed.
660  const std::string& lower = m_lowerTrigger[trigger.first];
661  // Expect this find operation to fail for L1 chains (lower = "")
662  const std::unordered_map<std::string, const Trig::ChainGroup*>::const_iterator it = m_existingTriggers.find(lower);
663  const bool active = (it == m_existingTriggers.end() ? true : it->second->isPassed());
664  ATH_CHECK( setTriggerDesicison(trigger.first, passed, active) );
665  }
666  return StatusCode::SUCCESS;
667 }
668 
670  // TODO emulation code here
671  for (const auto& trigger : m_autoTriggers) {
672  ATH_MSG_WARNING("Cannot do rates for " << trigger << ". Automatic trigger emulation is not yet included, sorry :(");
673  }
674  return StatusCode::SUCCESS;
675 }
676 
678  ATH_MSG_INFO ("Finalizing " << name() << "...");
679 
681  if (m_scanTriggers.size()) {
682  ATH_MSG_INFO("################## Computed Rate Scans for Threshold-Scan Items:");
683  for (const auto& trigger : m_scanTriggers) ATH_MSG_INFO(trigger.second->printRate(m_ratesDenominator));
684  }
685  if (m_triggers.size()) {
686  ATH_MSG_INFO("################## Computed Rate Estimations for Single Items:");
687  std::set<std::string> keys; // Used an unordered map for speed, but now we'd like the items in order
688  for (const auto& trigger : m_triggers) keys.insert(trigger.first);
689  for (const std::string& key : keys) ATH_MSG_INFO(m_triggers.at(key)->printRate(m_ratesDenominator));
690  }
691  if (m_expressTriggers.size()) {
692  ATH_MSG_INFO("################## Computed Express Rate Estimations for Single Items:");
693  for (const auto& trigger : m_expressTriggers) ATH_MSG_INFO(trigger->printExpressRate(m_ratesDenominator));
694  }
695  if (m_groups.size()) {
696  ATH_MSG_INFO("################## Computed Rate Estimations for Groups:");
697  for (const auto& group : m_groups) ATH_MSG_INFO(group.second->printRate(m_ratesDenominator));
698  }
699  if (m_globalGroups.size()) {
700  ATH_MSG_INFO("################## Computed Rate Estimations for Global Groups:");
701  for (const auto& group : m_globalGroups) ATH_MSG_INFO(group.second->printRate(m_ratesDenominator));
702  }
703  ATH_MSG_INFO("################## LHC Conditions and weighting information:");
705  printTarget();
706  printStatistics();
707  ATH_MSG_INFO("##################");
708 
709  writeMetadata();
710 
711  return StatusCode::SUCCESS;
712 }
713 
714 void RatesAnalysisAlg::setTargetLumiMu(const double lumi, const double mu) {
715  if (m_eventCounter > 1) { // All settings must be defined before we start looping over the sample
716  ATH_MSG_WARNING("Too late to call setTargetLumiMu. Do this during ratesInitialize().");
717  return;
718  }
719  m_targetLumi = lumi;
720  if (isZero(mu)) {
721  ATH_MSG_WARNING("Cannot have <mu> = 0. Setting to 1.");
722  m_targetMu = 1;
723  } else {
724  m_targetMu = mu;
725  }
728  ATH_MSG_WARNING("Un-physical number of bunches " << m_targetBunches << ", should be within 1 < N < " << EnhancedBiasWeighter::FULL_RING+1);
729  if (m_targetBunches == 0) ++m_targetBunches;
730  }
731  printTarget();
732 }
733 
734 void RatesAnalysisAlg::setTargetLumiBunches(const double lumi, const int32_t bunches) {
735  if (m_eventCounter > 1) { // All settings must be defined before we start looping over the sample
736  ATH_MSG_WARNING("Too late to call setTargetLumiBunches. Do this during ratesInitialize().");
737  return;
738  }
739  m_targetLumi = lumi;
740  if (bunches == 0) {
741  ATH_MSG_WARNING("Cannot have bunches = 0. Setting to 1.");
742  m_targetBunches = 1;
743  } else {
744  m_targetBunches = bunches;
745  }
747  printTarget();
748 }
749 
750 
751 void RatesAnalysisAlg::setTargetMuBunches(const double mu, const int32_t bunches) {
752  if (m_eventCounter > 1) { // All settings must be defined before we start looping over the sample
753  ATH_MSG_WARNING("Too late to call setTargetMuBunches. Do this during ratesInitialize().");
754  return;
755  }
756  if (bunches == 0) {
757  ATH_MSG_WARNING("Cannot have paired bunches = 0. Setting to 1.");
758  m_targetBunches = 1;
759  } else {
760  m_targetBunches = bunches;
761  }
762  if (isZero(mu)) {
763  ATH_MSG_WARNING("Cannot have mu = 0. Setting to 1.");
764  m_targetMu = 1;
765  } else {
766  m_targetMu = mu;
767  }
769  printTarget();
770 }
771 
774  ATH_MSG_INFO("Calculating rates for a target L_inst. = " << m_targetLumi << " cm-2s-1, mu = " << m_targetMu << ", paired bunches = " << m_targetBunches);
775  } else {
776  ATH_MSG_INFO("Luminosity extrapolation is switched off. Input files will determin the paired bunches, L_inst. and mu profile.");
777  }
778 }
779 
781  ATH_MSG_INFO("Processed " << m_eventCounter << " raw events, " << m_weightedEventCounter << " weighted. Total LHC wall-time of " << m_ratesDenominator << " s.");
782 }
783 
785  ATH_MSG_INFO("Input " << (m_enhancedBiasRatesTool->isMC() ? "MC" : "EB Data")
786  << " with <L_inst.> = "
787  << m_enhancedBiasRatesTool->getAverageLumi()
788  << " cm-2s-1, <mu> = "
789  << m_enhancedBiasRatesTool->getAverageMu()
790  << ", paired bunches = "
791  << m_enhancedBiasRatesTool->getPairedBunches());
792 }
793 
794 bool RatesAnalysisAlg::isCPS(const std::string& group) const {
795  return (group.find("CPS") != std::string::npos);
796 }
797 
798 bool RatesAnalysisAlg::isRandomSeed(const std::string& me, const std::string& seed) const {
799  if (me.find("L1_RD") != std::string::npos) return true;
800  if (me.find("L1RD") != std::string::npos) return true;
801  if (seed.find("L1_RD") != std::string::npos) return true;
802  return false;
803 }
804 
805 uint32_t RatesAnalysisAlg::getLevel(const std::string& name) const {
806  if (name.find("HLT_") != std::string::npos) return 2;
807  if (name.find("L1_") != std::string::npos) return 1;
808  return 2;
809 }
810 
812  if (!m_metadataTree) {
813  return;
814  }
815 
816  m_runNumber = m_enhancedBiasRatesTool->getRunNumber();
817  m_metadataTree->Branch("runNumber", &m_runNumber);
818 
819  m_metadataTree->Branch("targetMu", &m_targetMu);
820  m_metadataTree->Branch("targetBunches", &m_targetBunches);
821  m_metadataTree->Branch("targetLumi", &m_targetLumi);
822 
823  std::vector<std::string> triggers;
824  std::vector<std::string> lowers;
825  std::vector<double> prescales;
826  std::vector<double> express;
827  triggers.reserve(m_triggers.size());
828  lowers.reserve(m_triggers.size());
829  prescales.reserve(m_triggers.size());
830  express.reserve(m_triggers.size());
831  for (const auto& trigger : m_triggers) {
832  triggers.push_back(trigger.first);
833  lowers.push_back(trigger.second->getSeedName());
834  prescales.push_back(trigger.second->getPrescale() );
835  express.push_back(trigger.second->getPrescale(true /*includeExpress*/) );
836  }
837 
838  for (const auto& group : m_groups) {
839  triggers.push_back(group.first);
840  lowers.push_back("-");
841  prescales.push_back(-1);
842  express.push_back(-1);
843  }
844 
845  for (const auto& group : m_globalGroups) {
846  triggers.push_back("RATE_GLOBAL_" + group.first);
847  lowers.push_back("-");
848  prescales.push_back(-1);
849  express.push_back(-1);
850  }
851 
852  m_metadataTree->Branch("triggers", &triggers);
853  m_metadataTree->Branch("lowers", &lowers);
854  m_metadataTree->Branch("prescales", &prescales);
855  m_metadataTree->Branch("express", &express);
856 
857  std::vector<int32_t> bunchGroups;
858  bunchGroups.reserve(16);
859 
860  uint32_t masterKey = 0;
861  uint32_t hltPrescaleKey = 0;
862  uint32_t lvl1PrescaleKey = 0;
863 
864  if(!m_configSvc.empty() && m_configSvc.isValid()) {
865  const TrigConf::BunchGroupSet* bgs = m_configSvc->bunchGroupSet();
866  for (const TrigConf::BunchGroup& bg : bgs->bunchGroups()) {
867  bunchGroups.push_back(bg.bunches().size());
868  }
869  masterKey = m_configSvc->masterKey();
870  hltPrescaleKey = m_configSvc->hltPrescaleKey();
871  lvl1PrescaleKey = m_configSvc->lvl1PrescaleKey();
872  }
873 
874  if (bunchGroups.size() == 0 || std::all_of(bunchGroups.begin(), bunchGroups.end(), [](int i) { return i==0; })) {
875  bunchGroups = m_enhancedBiasRatesTool->getBunchGroups();
876  }
877 
878  m_metadataTree->Branch("bunchGroups", &bunchGroups);
879 
880  m_metadataTree->Branch("hltChainIDGroup", &m_hltChainIDGroup);
881  m_metadataTree->Branch("l1ItemID", &m_l1ItemID);
882 
883  m_metadataTree->Branch("masterKey", &masterKey);
884  m_metadataTree->Branch("lvl1PrescaleKey", &lvl1PrescaleKey);
885  m_metadataTree->Branch("hltPrescaleKey", &hltPrescaleKey);
886 
887  std::string atlasProject = std::getenv("AtlasProject");
888  std::string atlasVersion = std::getenv("AtlasVersion");
889  m_metadataTree->Branch("AtlasProject", &atlasProject);
890  m_metadataTree->Branch("AtlasVersion", &atlasVersion);
891 
892  m_metadataTree->Fill();
893 
894 }
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:780
TrigConf::BunchGroup
Definition: BunchGroup.h:17
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
TrigConf::BunchGroupSet
Definition: BunchGroupSet.h:19
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
RatesAnalysisAlg::m_expressGroupName
const std::string m_expressGroupName
Definition: RatesAnalysisAlg.h:261
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:392
RatesAnalysisFullMenu.e34
e34
Definition: RatesAnalysisFullMenu.py:25
RatesAnalysisAlg::m_runNumber
uint32_t m_runNumber
What is the RunNumber.
Definition: RatesAnalysisAlg.h:285
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:264
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:276
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:254
RatesAnalysisAlg::ratesExecute
virtual StatusCode ratesExecute()=0
To be implemented by the user.
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
StandaloneBunchgroupHandler.bg
bg
Definition: StandaloneBunchgroupHandler.py:243
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:242
RatesAnalysisAlg::~RatesAnalysisAlg
virtual ~RatesAnalysisAlg()
Definition: RatesAnalysisAlg.cxx:38
RatesAnalysisAlg::checkGotTDT
StatusCode checkGotTDT()
Internal check that the TDT is fetched.
Definition: RatesAnalysisAlg.cxx:312
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:260
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:291
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:396
RatesAnalysisAlg::m_enhancedBiasRatesTool
ToolHandle< IEnhancedBiasWeighter > m_enhancedBiasRatesTool
Definition: RatesAnalysisAlg.h:263
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:267
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:243
RatesAnalysisAlg::m_ratesDenominator
double m_ratesDenominator
How much walltime is seen by the algorithm.
Definition: RatesAnalysisAlg.h:286
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:269
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:244
RatesAnalysisAlg::m_targetMu
double m_targetMu
What pileup level the prediction is targeting.
Definition: RatesAnalysisAlg.h:282
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:251
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:47
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:119
RatesAnalysisAlg::setTargetMuBunches
void setTargetMuBunches(const double mu, const int32_t bunches)
Set the target mu and number of bunches.
Definition: RatesAnalysisAlg.cxx:751
EventStreamInfo.h
This file contains the class definition for the EventStreamInfo class.
RatesAnalysisAlg::m_prescalesJSON
Gaudi::Property< std::map< std::string, std::map< std::string, double > > > m_prescalesJSON
Definition: RatesAnalysisAlg.h:279
RatesAnalysisAlg::setTargetLumiMu
void setTargetLumiMu(const double lumi, const double mu)
Set the target instantaneous luminosity and mu.
Definition: RatesAnalysisAlg.cxx:714
RatesAnalysisAlg::kAUTO
@ kAUTO
The pass/fail decision is automatically emulated per event based on decoding the trigger name.
Definition: RatesAnalysisAlg.h:46
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:288
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:371
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:44
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:669
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:293
RatesAnalysisAlg::m_targetBunches
double m_targetBunches
How many bunches the prediction is targeting.
Definition: RatesAnalysisAlg.h:283
RatesAnalysisAlg::setTargetLumiBunches
void setTargetLumiBunches(const double lumi, const int32_t bunches)
Set the target instantaneous luminosity and number of bunches.
Definition: RatesAnalysisAlg.cxx:734
RatesAnalysisAlg::RatesAnalysisAlg
RatesAnalysisAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: RatesAnalysisAlg.cxx:23
RatesAnalysisAlg::isCPS
bool isCPS(const std::string &group) const
String match coherent prescale groups.
Definition: RatesAnalysisAlg.cxx:794
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:245
RatesAnalysisAlg::m_weightingValues
WeightingValuesSummary_t m_weightingValues
Possible weighting & lumi extrapolation values for the current event.
Definition: RatesAnalysisAlg.h:295
RatesAnalysisAlg::addExisting
StatusCode addExisting(const std::string &pattern)
Register some existing triggers based on wild-card match, e.g.
Definition: RatesAnalysisAlg.cxx:196
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
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:45
RatesAnalysisAlg::m_doHistograms
Gaudi::Property< bool > m_doHistograms
Definition: RatesAnalysisAlg.h:275
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
RatesAnalysisAlg::execute
virtual StatusCode execute()
In first call - register all triggers.
Definition: RatesAnalysisAlg.cxx:589
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:249
RatesAnalysisAlg::printTarget
void printTarget() const
Print the target instantaneous luminosity, mu and number of bunches.
Definition: RatesAnalysisAlg.cxx:772
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:798
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
TrigConf::BunchGroupSet::bunchGroups
const std::vector< BunchGroup > & bunchGroups() const
Definition: BunchGroupSet.h:27
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:247
RatesAnalysisAlg::m_doExpressRates
Gaudi::Property< bool > m_doExpressRates
Definition: RatesAnalysisAlg.h:272
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:228
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:290
RatesAnalysisAlg::setTargetLumi
void setTargetLumi(const double lumi)
Set the target instantaneous luminosity.
Definition: RatesAnalysisAlg.h:174
RatesAnalysisAlg::executeTrigDecisionToolTriggers
StatusCode executeTrigDecisionToolTriggers()
Internal call to get the pass/fail for all TDT triggers.
Definition: RatesAnalysisAlg.cxx:656
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:327
RatesAnalysisAlg::writeMetadata
void writeMetadata()
Write to outpute tree (if any) the metadata needed downstream.
Definition: RatesAnalysisAlg.cxx:811
RatesAnalysisAlg::m_triggers
std::unordered_map< std::string, std::unique_ptr< RatesTrigger > > m_triggers
All individual triggers (L1 or HLT)
Definition: RatesAnalysisAlg.h:241
RatesAnalysisAlg::getLevel
uint32_t getLevel(const std::string &name) const
String match to a trigger level.
Definition: RatesAnalysisAlg.cxx:805
RatesAnalysisAlg::m_configSvc
ServiceHandle< TrigConf::ITrigConfigSvc > m_configSvc
Definition: RatesAnalysisAlg.h:265
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:784
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:259
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:250
DEBUG
#define DEBUG
Definition: page_access.h:11
RatesAnalysisAlg::m_l1ItemID
std::vector< std::vector< std::string > > m_l1ItemID
Definition: RatesAnalysisAlg.h:257
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:253
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:277
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:191
RatesAnalysisAlg::finalize
virtual StatusCode finalize()
Print rates.
Definition: RatesAnalysisAlg.cxx:677
L1Menu.h
RatesAnalysisAlg::m_doTriggerGroups
Gaudi::Property< bool > m_doTriggerGroups
Definition: RatesAnalysisAlg.h:271
TrigConf::Chain
HLT chain configuration.
Definition: TrigConfData/TrigConfData/HLTChain.h:18
RatesAnalysisAlg::m_useBunchCrossingData
Gaudi::Property< bool > m_useBunchCrossingData
Definition: RatesAnalysisAlg.h:273
xAOD::EventInfo_v1::bcid
uint32_t bcid() const
The bunch crossing ID of the event.
RatesAnalysisAlg::m_targetLumi
double m_targetLumi
What instantaneous luminosity the prediction is targeting.
Definition: RatesAnalysisAlg.h:284
TrigConf::HLTPrescalesSet
HLT menu configuration.
Definition: HLTPrescalesSet.h:19
RatesAnalysisAlg::m_eventCounter
uint32_t m_eventCounter
Count how many events processed.
Definition: RatesAnalysisAlg.h:287
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:344
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:268
RatesAnalysisAlg::m_doGlobalGroups
Gaudi::Property< bool > m_doGlobalGroups
Definition: RatesAnalysisAlg.h:270
RatesAnalysisAlg::m_hltChainIDGroup
std::vector< std::vector< std::string > > m_hltChainIDGroup
Definition: RatesAnalysisAlg.h:256
RatesAnalysisAlg::isZero
bool isZero(double v) const
Helper function for floating point subtraction.
Definition: RatesAnalysisAlg.h:239
xAOD::EventInfo_v1::actualInteractionsPerCrossing
float actualInteractionsPerCrossing() const
Average interactions per crossing for the current BCID - for in-time pile-up.
Definition: EventInfo_v1.cxx:380
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:248
WeightingValuesSummary_t::m_eventMu
double m_eventMu
The actual number of interactions in the event.
Definition: RatesHistoBase.h:58