ATLAS Offline Software
RatesAnalysisAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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 {}
36 
38 
40  const double thresholdMin,
41  const double thresholdMax,
42  const uint32_t thresholdBins,
44  const double prescale,
45  const std::string& seedName,
46  const double seedPrecale,
47  const Method_t method,
48  const ExtrapStrat_t extrapolation) {
49 
50  if (method != kMANUAL) {
51  ATH_MSG_ERROR("Sorry - ScanTriggers have to be implemented with the kMANUAL method for now.");
52  return StatusCode::FAILURE;
53  }
54 
56  m_scanTriggers.emplace(name, std::make_unique<RatesScanTrigger>(name, msgSvc(), thresholdMin, thresholdMax, thresholdBins, behaviour, prescale, seedName, seedPrecale, e));
58  if (isRandomSeed(name, seedName)) newScanTrigger->setSeedsFromRandom(true);
59  ATH_MSG_DEBUG("newScanTrigger " << name << " added");
60  return StatusCode::SUCCESS;
61 }
62 
63 
65  const std::vector<double>& thresholdBinEdges,
67  const double prescale,
68  const std::string& seedName,
69  const double seedPrecale,
70  const Method_t method,
71  const ExtrapStrat_t extrapolation) {
72 
73  if (method != kMANUAL) {
74  ATH_MSG_ERROR("Sorry - ScanTriggers have to be implemented with the kMANUAL method for now.");
75  return StatusCode::FAILURE;
76  }
77 
79 
80  m_scanTriggers.emplace(name, std::make_unique<RatesScanTrigger>(name, msgSvc(), thresholdBinEdges, behaviour, prescale, seedName, seedPrecale, e));
82  if (isRandomSeed(name, seedName)) newScanTrigger->setSeedsFromRandom(true);
83  ATH_MSG_DEBUG("newScanTrigger " << name << " added");
84  return StatusCode::SUCCESS;
85 }
86 
87 
89  const double prescale,
90  const double expressPrescale,
91  const std::string& seedName,
92  const double seedPrecale,
93  const std::string& groups,
94  const Method_t method,
95  const ExtrapStrat_t extrapolation) {
96 
97  std::set<std::string> groupSet;
98  std::istringstream ss(groups);
99  while (ss) {
100  std::string group;
101  if (!std::getline(ss, group, ',')) break;
102  groupSet.insert(group);
103  }
104 
105  return newTrigger(name, prescale, expressPrescale, seedName, seedPrecale, groupSet, method, extrapolation);
106 }
107 
109  const double prescale,
110  const double expressPrescale,
111  const std::string& seedName,
112  const double seedPrecale,
113  const std::set<std::string>& groups,
114  const Method_t method,
115  const ExtrapStrat_t extrapolation) {
116 
117  if (m_eventCounter > 1) { // All triggers must be defined before we start looping over the sample
118  ATH_MSG_FATAL("Too late to call newTrigger. All emulated triggers must be registered during ratesInitialize().");
119  return StatusCode::FAILURE;
120  }
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 
132  m_triggers.emplace(name, std::make_unique<RatesTrigger>(name, msgSvc(), prescale, expressPrescale, seedName, seedPrecale, m_doHistograms, e));
133  RatesTrigger* newTriggerPtr = m_triggers.at(name).get();
134 
135  if (isRandomSeed(name, seedName)) newTriggerPtr->setSeedsFromRandom(true);
136 
137  // Only worthwhile doing the remainder if the trigger is not disabled. Otherwise will slow everything down
138  if (newTriggerPtr->getDisabled()) {
139  ATH_MSG_DEBUG("newTrigger " << name << " added (disabled)");
140  return StatusCode::SUCCESS;
141  }
142 
143  if (method == kAUTO) {
144  m_autoTriggers.push_back(name);
145  } else if (method == kEXISTING) {
146  m_existingTriggers[name] = m_tdt->getChainGroup(name);
148  }
149 
150  // Add this trigger to its groups
151  if (m_doTriggerGroups) {
152  for (const std::string& group : groups) {
153  // Ignore BW and PS groups
154  if (group.find("BW") == 0 || group.find("PS") == 0 || group.find("STREAM:express") == 0) continue;
155  if (m_groups.count(group) == 0) {
156  m_groups.emplace(group, std::make_unique<RatesGroup>(group, msgSvc(), m_doHistograms, m_enableLumiExtrapolation));
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( m_groups.at(group).get() );
159  }
160  m_groups.at(group)->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  if (m_lowestPrescale.count(CPSID) == 0) m_lowestPrescale[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 
521  if (m_doHistograms) {
522  ATH_MSG_DEBUG("################## Registering normalisation histogram:");
523  m_scalingHist = new TH1D("normalisation",";;",3,0.,3.);
524  ATH_CHECK( histSvc()->regHist("/RATESTREAM/normalisation", m_scalingHist) );
525  m_bcidHist = new TH1D("bcid",";BCID;Events",3565,-.5,3564.5);
526  ATH_CHECK( histSvc()->regHist("/RATESTREAM/bcid", m_bcidHist) );
527  ATH_MSG_DEBUG("################## Registering metadata tree histogram:");
528  ATH_CHECK( histSvc()->regTree("/RATESTREAM/metadata", std::make_unique<TTree>("metadata", "metadata")) );
529  ATH_CHECK( histSvc()->getTree("/RATESTREAM/metadata", m_metadataTree) );
530  if (m_triggers.size()) {
531  ATH_MSG_DEBUG("################## Registering trigger histograms:");
532  for (const auto& trigger : m_triggers) {
533  if (!trigger.second->doHistograms()) continue; // Not all may be doing histograming
534  std::string lvlSubdir = "";
535  if (trigger.second->getName().find("L1") == 0){
536  lvlSubdir = "Rate_ChainL1_HLT/";
537  } else if (trigger.second->getName().find("HLT") == 0) {
538  lvlSubdir = "Rate_ChainHLT_HLT/";
539  }
540  ATH_CHECK( trigger.second->giveDataHist(histSvc(), std::string("/RATESTREAM/All/" + lvlSubdir + trigger.first + "/data")) );
541  ATH_CHECK( trigger.second->giveMuHist(histSvc(), std::string("/RATESTREAM/All/" + lvlSubdir + trigger.first + "/rateVsMu")) );
542  if (m_useBunchCrossingData) ATH_CHECK( trigger.second->giveTrainHist(histSvc(), std::string("/RATESTREAM/All/" + lvlSubdir + trigger.first + "/rateVsTrain")) );
543  else trigger.second->clearTrainHist();
544  }
545  }
546  if (m_scanTriggers.size()) {
547  ATH_MSG_DEBUG("################## Registering scan trigger histograms:");
548  for (const auto& trigger : m_scanTriggers) {
549  ATH_CHECK( trigger.second->giveThresholdHist(histSvc(), std::string("/RATESTREAM/ScanTriggers/" + trigger.first + "/rateVsThreshold")) );
550  }
551  }
552  if (m_groups.size()) {
553  ATH_MSG_DEBUG("################## Registering group histograms:");
554  for (const auto& group : m_groups) {
555  if (!group.second->doHistograms()) continue;
556  std::string groupName = group.first;
557  std::replace( groupName.begin(), groupName.end(), ':', '_');
558  ATH_CHECK( group.second->giveDataHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/" + groupName + "/data")) );
559  ATH_CHECK( group.second->giveMuHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/" + groupName + "/rateVsMu")) );
560  if (m_useBunchCrossingData) ATH_CHECK( group.second->giveTrainHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/" + groupName + "/rateVsTrain")) );
561  else group.second->clearTrainHist();
562  }
563  }
564  if (m_globalGroups.size()) {
565  ATH_MSG_DEBUG("################## Registering global group histograms:");
566  for (const auto& group : m_globalGroups) {
567  if (!group.second->doHistograms()) continue;
568  ATH_CHECK( group.second->giveDataHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" + group.first + "/data")) );
569  ATH_CHECK( group.second->giveMuHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" + group.first + "/rateVsMu")) );
570  if (m_useBunchCrossingData) ATH_CHECK( group.second->giveTrainHist(histSvc(), std::string("/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" + group.first + "/rateVsTrain")) );
571  else group.second->clearTrainHist();
572  }
573  }
574  }
575 
576  // Has the user set a lumi extrapolation? If not - set a default
578 
579  // We now know the final lumi scaling so we can set the bunch scaling
580  const uint32_t ebPairedBunches = m_enhancedBiasRatesTool->getPairedBunches();
581  ATH_MSG_INFO("Number of paired bunches in input file:" << m_enhancedBiasRatesTool->getPairedBunches());
583 
584  return StatusCode::SUCCESS;
585 }
586 
588  ATH_MSG_DEBUG("Executing " << name() << " on event " << m_eventCounter << "...");
589  if (m_eventCounter++ == 0) { // First time in execute loop - cannot access TDT before this.
591  }
592 
593  // Get event characteristics
594  const xAOD::EventInfo* eventInfo(nullptr);
595  uint32_t distance = 0;
596  ATH_CHECK( evtStore()->retrieve(eventInfo, "EventInfo") );
597  ATH_CHECK( m_enhancedBiasRatesTool->getDistanceIntoTrain(eventInfo, distance) );
598 
599  // Get the weighting & scaling characteristics
601  m_weightingValues.m_eventMu = std::ceil(eventInfo->actualInteractionsPerCrossing()); // This always seems to be a half integer
602  m_weightingValues.m_eventLumi = m_enhancedBiasRatesTool->getLBLumi(eventInfo);
603  m_weightingValues.m_isUnbiased = m_enhancedBiasRatesTool->isUnbiasedEvent(eventInfo);
605  m_weightingValues.m_eventLiveTime = m_enhancedBiasRatesTool->getEBLiveTime(eventInfo);
606 
608 
609  // Bunch factor doesn't change as a fn. of the run. Reminder: m_bunchFactor = m_targetBunches / (double)ebPairedBunches;
613 
614  // Ignore zero weighted events. Typically these come from bad LB
615  if (RatesHistoBase::isZero(m_weightingValues.m_enhancedBiasWeight)) return StatusCode::SUCCESS;
616 
617  // Do automated triggers
619 
620  // Do TDT-controlled triggers
622 
623  // Run user's code. Do manual triggers
624  ATH_CHECK( ratesExecute() );
625 
626  // Execute groups
627  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.
628  for (const auto& group : m_activeGroups) group->execute(m_weightingValues); // Individual groups, CPS groups and active unique groups. Set.
629 
630  // Reset triggers
631  for (const auto& trigger : m_activatedTriggers) trigger->reset();
632  m_activatedTriggers.clear();
633 
634  // Keep track of elapsed walltime
637 
638  if (m_doHistograms) {
640  m_scalingHist->Fill(0.5, m_weightingValues.m_eventLiveTime); // Walltime
641  m_scalingHist->Fill(1.5, 1.); // Total events
642  m_scalingHist->Fill(2.5, m_weightingValues.m_enhancedBiasWeight); // Total events weighted
643  }
644 
645  // Some debug info
646  if (m_eventCounter % 1000 == 0) {
647  ATH_MSG_INFO( "Event " << m_eventCounter << " " << m_weightingValues.print() << " currentWallTime:" << m_ratesDenominator );
648  }
649 
650  setFilterPassed(true); //if got here, assume that means algorithm passed
651  return StatusCode::SUCCESS;
652 }
653 
655  for (const auto& trigger : m_existingTriggers) {
656  const bool passed = trigger.second->isPassed();
657  // L1 chains are always active, HLT chains are active if their L1 passed.
658  const std::string& lower = m_lowerTrigger[trigger.first];
659  // Expect this find operation to fail for L1 chains (lower = "")
660  const std::unordered_map<std::string, const Trig::ChainGroup*>::const_iterator it = m_existingTriggers.find(lower);
661  const bool active = (it == m_existingTriggers.end() ? true : it->second->isPassed());
663  }
664  return StatusCode::SUCCESS;
665 }
666 
668  // TODO emulation code here
669  for (const auto& trigger : m_autoTriggers) {
670  ATH_MSG_WARNING("Cannot do rates for " << trigger << ". Automatic trigger emulation is not yet included, sorry :(");
671  }
672  return StatusCode::SUCCESS;
673 }
674 
676  ATH_MSG_INFO ("Finalizing " << name() << "...");
677 
679  if (m_scanTriggers.size()) {
680  ATH_MSG_INFO("################## Computed Rate Scans for Threshold-Scan Items:");
681  for (const auto& trigger : m_scanTriggers) ATH_MSG_INFO(trigger.second->printRate(m_ratesDenominator));
682  }
683  if (m_triggers.size()) {
684  ATH_MSG_INFO("################## Computed Rate Estimations for Single Items:");
685  std::set<std::string> keys; // Used an unordered map for speed, but now we'd like the items in order
686  for (const auto& trigger : m_triggers) keys.insert(trigger.first);
687  for (const std::string& key : keys) ATH_MSG_INFO(m_triggers.at(key)->printRate(m_ratesDenominator));
688  }
689  if (m_expressTriggers.size()) {
690  ATH_MSG_INFO("################## Computed Express Rate Estimations for Single Items:");
691  for (const auto& trigger : m_expressTriggers) ATH_MSG_INFO(trigger->printExpressRate(m_ratesDenominator));
692  }
693  if (m_groups.size()) {
694  ATH_MSG_INFO("################## Computed Rate Estimations for Groups:");
695  for (const auto& group : m_groups) ATH_MSG_INFO(group.second->printRate(m_ratesDenominator));
696  }
697  if (m_globalGroups.size()) {
698  ATH_MSG_INFO("################## Computed Rate Estimations for Global Groups:");
699  for (const auto& group : m_globalGroups) ATH_MSG_INFO(group.second->printRate(m_ratesDenominator));
700  }
701  ATH_MSG_INFO("################## LHC Conditions and weighting information:");
703  printTarget();
704  printStatistics();
705  ATH_MSG_INFO("##################");
706 
707  writeMetadata();
708 
709  return StatusCode::SUCCESS;
710 }
711 
712 void RatesAnalysisAlg::setTargetLumiMu(const double lumi, const double mu) {
713  if (m_eventCounter > 1) { // All settings must be defined before we start looping over the sample
714  ATH_MSG_WARNING("Too late to call setTargetLumiMu. Do this during ratesInitialize().");
715  return;
716  }
717  m_targetLumi = lumi;
718  if (isZero(mu)) {
719  ATH_MSG_WARNING("Cannot have <mu> = 0. Setting to 1.");
720  m_targetMu = 1;
721  } else {
722  m_targetMu = mu;
723  }
726  ATH_MSG_WARNING("Un-physical number of bunches " << m_targetBunches << ", should be within 1 < N < " << EnhancedBiasWeighter::FULL_RING+1);
727  if (m_targetBunches == 0) ++m_targetBunches;
728  }
729  printTarget();
730 }
731 
732 void RatesAnalysisAlg::setTargetLumiBunches(const double lumi, const int32_t bunches) {
733  if (m_eventCounter > 1) { // All settings must be defined before we start looping over the sample
734  ATH_MSG_WARNING("Too late to call setTargetLumiBunches. Do this during ratesInitialize().");
735  return;
736  }
737  m_targetLumi = lumi;
738  if (bunches == 0) {
739  ATH_MSG_WARNING("Cannot have bunches = 0. Setting to 1.");
740  m_targetBunches = 1;
741  } else {
742  m_targetBunches = bunches;
743  }
745  printTarget();
746 }
747 
748 
749 void RatesAnalysisAlg::setTargetMuBunches(const double mu, const int32_t bunches) {
750  if (m_eventCounter > 1) { // All settings must be defined before we start looping over the sample
751  ATH_MSG_WARNING("Too late to call setTargetMuBunches. Do this during ratesInitialize().");
752  return;
753  }
754  if (bunches == 0) {
755  ATH_MSG_WARNING("Cannot have paired bunches = 0. Setting to 1.");
756  m_targetBunches = 1;
757  } else {
758  m_targetBunches = bunches;
759  }
760  if (isZero(mu)) {
761  ATH_MSG_WARNING("Cannot have mu = 0. Setting to 1.");
762  m_targetMu = 1;
763  } else {
764  m_targetMu = mu;
765  }
767  printTarget();
768 }
769 
772  ATH_MSG_INFO("Calculating rates for a target L_inst. = " << m_targetLumi << " cm-2s-1, mu = " << m_targetMu << ", paired bunches = " << m_targetBunches);
773  } else {
774  ATH_MSG_INFO("Luminosity extrapolation is switched off. Input files will determin the paired bunches, L_inst. and mu profile.");
775  }
776 }
777 
779  ATH_MSG_INFO("Processed " << m_eventCounter << " raw events, " << m_weightedEventCounter << " weighted. Total LHC wall-time of " << m_ratesDenominator << " s.");
780 }
781 
783  ATH_MSG_INFO("Input " << (m_enhancedBiasRatesTool->isMC() ? "MC" : "EB Data")
784  << " with <L_inst.> = "
785  << m_enhancedBiasRatesTool->getAverageLumi()
786  << " cm-2s-1, <mu> = "
787  << m_enhancedBiasRatesTool->getAverageMu()
788  << ", paired bunches = "
789  << m_enhancedBiasRatesTool->getPairedBunches());
790 }
791 
792 bool RatesAnalysisAlg::isCPS(const std::string& group) const {
793  return (group.find("CPS") != std::string::npos);
794 }
795 
796 bool RatesAnalysisAlg::isRandomSeed(const std::string& me, const std::string& seed) const {
797  if (me.find("L1_RD") != std::string::npos) return true;
798  if (me.find("L1RD") != std::string::npos) return true;
799  if (seed.find("L1_RD") != std::string::npos) return true;
800  return false;
801 }
802 
803 uint32_t RatesAnalysisAlg::getLevel(const std::string& name) const {
804  if (name.find("HLT_") != std::string::npos) return 2;
805  if (name.find("L1_") != std::string::npos) return 1;
806  return 2;
807 }
808 
810  if (!m_metadataTree) {
811  return;
812  }
813 
814  m_runNumber = m_enhancedBiasRatesTool->getRunNumber();
815  m_metadataTree->Branch("runNumber", &m_runNumber);
816 
817  m_metadataTree->Branch("targetMu", &m_targetMu);
818  m_metadataTree->Branch("targetBunches", &m_targetBunches);
819  m_metadataTree->Branch("targetLumi", &m_targetLumi);
820 
821  std::vector<std::string> triggers;
822  std::vector<std::string> lowers;
823  std::vector<double> prescales;
824  std::vector<double> express;
825  triggers.reserve(m_triggers.size());
826  lowers.reserve(m_triggers.size());
827  prescales.reserve(m_triggers.size());
828  express.reserve(m_triggers.size());
829  for (const auto& trigger : m_triggers) {
830  triggers.push_back(trigger.first);
831  lowers.push_back(trigger.second->getSeedName());
832  prescales.push_back(trigger.second->getPrescale() );
833  express.push_back(trigger.second->getPrescale(true /*includeExpress*/) );
834  }
835 
836  for (const auto& group : m_groups) {
837  triggers.push_back(group.first);
838  lowers.push_back("-");
839  prescales.push_back(-1);
840  express.push_back(-1);
841  }
842 
843  for (const auto& group : m_globalGroups) {
844  triggers.push_back("RATE_GLOBAL_" + group.first);
845  lowers.push_back("-");
846  prescales.push_back(-1);
847  express.push_back(-1);
848  }
849 
850  m_metadataTree->Branch("triggers", &triggers);
851  m_metadataTree->Branch("lowers", &lowers);
852  m_metadataTree->Branch("prescales", &prescales);
853  m_metadataTree->Branch("express", &express);
854 
855  std::vector<int32_t> bunchGroups;
856  bunchGroups.reserve(16);
857 
858  uint32_t masterKey = 0;
859  uint32_t hltPrescaleKey = 0;
860  uint32_t lvl1PrescaleKey = 0;
861 
862  if(!m_configSvc.empty() && m_configSvc.isValid()) {
863  const TrigConf::BunchGroupSet* bgs = m_configSvc->bunchGroupSet();
864  for (const TrigConf::BunchGroup& bg : bgs->bunchGroups()) {
865  bunchGroups.push_back(bg.bunches().size());
866  }
867  masterKey = m_configSvc->masterKey();
868  hltPrescaleKey = m_configSvc->hltPrescaleKey();
869  lvl1PrescaleKey = m_configSvc->lvl1PrescaleKey();
870  }
871 
872  if (bunchGroups.size() == 0 || std::all_of(bunchGroups.begin(), bunchGroups.end(), [](int i) { return i==0; })) {
873  bunchGroups = m_enhancedBiasRatesTool->getBunchGroups();
874  }
875 
876  m_metadataTree->Branch("bunchGroups", &bunchGroups);
877 
878  m_metadataTree->Branch("hltChainIDGroup", &m_hltChainIDGroup);
879  m_metadataTree->Branch("l1ItemID", &m_l1ItemID);
880 
881  m_metadataTree->Branch("masterKey", &masterKey);
882  m_metadataTree->Branch("lvl1PrescaleKey", &lvl1PrescaleKey);
883  m_metadataTree->Branch("hltPrescaleKey", &hltPrescaleKey);
884 
885  std::string atlasProject = std::getenv("AtlasProject");
886  std::string atlasVersion = std::getenv("AtlasVersion");
887  m_metadataTree->Branch("AtlasProject", &atlasProject);
888  m_metadataTree->Branch("AtlasVersion", &atlasVersion);
889 
890  m_metadataTree->Fill();
891 
892 }
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:778
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
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:44
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: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
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
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:88
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:37
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:39
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:423
RatesAnalysisAlg::m_enhancedBiasRatesTool
ToolHandle< IEnhancedBiasWeighter > m_enhancedBiasRatesTool
Definition: RatesAnalysisAlg.h:263
RatesAnalysisAlg::ratesInitialize
virtual StatusCode ratesInitialize()=0
To be implemented by the user.
TH1D
Definition: rootspy.cxx:342
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:161
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:749
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:712
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: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: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
RatesAnalysisAlg::executeTriggerEmulation
StatusCode executeTriggerEmulation()
Internal call to get the pass/fail for all automatically emulated triggers.
Definition: RatesAnalysisAlg.cxx:667
RatesAnalysisAlg::addExisting
StatusCode addExisting(const std::string pattern)
Register some existing triggers based on wild-card match, e.g.
Definition: RatesAnalysisAlg.cxx:194
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:143
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:92
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:165
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:732
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:792
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
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:167
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:587
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:770
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:796
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:159
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:195
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:654
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:809
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:803
RatesAnalysisAlg::m_configSvc
ServiceHandle< TrigConf::ITrigConfigSvc > m_configSvc
Definition: RatesAnalysisAlg.h:265
lumiFormat.lumi
lumi
Definition: lumiFormat.py:113
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
RatesAnalysisAlg::printInputSummary
void printInputSummary() const
Print the input data instantaneous luminosity, mu and number of bunches.
Definition: RatesAnalysisAlg.cxx:782
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:353
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:790
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:189
RatesAnalysisAlg::finalize
virtual StatusCode finalize()
Print rates.
Definition: RatesAnalysisAlg.cxx:675
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: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: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
PhysDESDM_Quirks.trigger
trigger
Definition: PhysDESDM_Quirks.py:27
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