Loading [MathJax]/jax/input/TeX/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TrigPrescalesAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 //
9 // includes
10 //
11 
13 
16 
17 //
18 // method implementations
19 //
20 
21 namespace CP
22 {
23 
25  initialize ()
26  {
27  if (m_prescaleDecoration.empty())
28  {
29  ANA_MSG_ERROR ("The prescale decoration should not be empty");
30  return StatusCode::FAILURE;
31  }
32 
33  if (m_trigList.empty() && m_trigFormula.empty())
34  {
35  ANA_MSG_ERROR ("Either a list of triggers or trigger formula need to be provided");
36  return StatusCode::FAILURE;
37  }
38 
39  if (!m_trigList.empty() && !m_trigFormula.empty())
40  {
41  ANA_MSG_ERROR ("Provide either only a list of triggers or only a trigger formula");
42  return StatusCode::FAILURE;
43  }
44 
46 
47  if (!m_selectionDecoration.empty()) {
48  for (const std::string &chain : m_trigList) {
50  }
51  }
52 
53  if (!m_trigFormula.empty())
54  {
56  m_prescaleFunctions.emplace_back([this](const xAOD::EventInfo *evtInfo, const std::string &trigger)
57  {
58  if(m_prescaleMC) return m_pileupReweightingTool->getPrescaleWeight(*evtInfo, trigger, true);
59  return m_pileupReweightingTool->getDataWeight (*evtInfo, trigger, true);
60  });
61  // By putting the formula into` m_trigListAll`
62  // the logic in `execute` does not have to change
63  // depending on if `m_trigFormula` or `m_trigList` is used
64  std::vector<std::string> formulaVector = {m_trigFormula.value()};
65  m_trigListAll = formulaVector;
66  return StatusCode::SUCCESS;
67  }
68 
69  if (m_trigListAll.empty())
70  {
72  }
73 
74  for (const std::string &chain : m_trigListAll)
75  {
76  m_prescaleAccessors.emplace_back(m_prescaleDecoration + "_" + RCU::substitute(RCU::substitute(chain, ".", "p"), "-", "_"));
77 
78  // Generate helper functions
79  if (std::find(m_trigList.begin(), m_trigList.end(), chain) != m_trigList.end())
80  {
81  m_prescaleFunctions.emplace_back([this](const xAOD::EventInfo *evtInfo, const std::string &trigger)
82  {
83  auto it = m_selectionAccessors.find(trigger);
84  if (it != m_selectionAccessors.end())
85  {
86  if (!it->second(*evtInfo))
87  {
88  return invalidTriggerPrescale();
89  }
90  }
91 
92  if(m_prescaleMC) return m_pileupReweightingTool->getPrescaleWeight(*evtInfo, trigger, true);
93  return m_pileupReweightingTool->getDataWeight (*evtInfo, trigger, true);
94  });
95  }
96  else
97  {
98  m_prescaleFunctions.emplace_back([](const xAOD::EventInfo *, const std::string &)
99  {
100  return invalidTriggerPrescale();
101  });
102  }
103  }
104 
105 
106  return StatusCode::SUCCESS;
107  }
108 
109 
110 
112  execute ()
113  {
114  const xAOD::EventInfo *evtInfo{};
115  ANA_CHECK (evtStore()->retrieve(evtInfo, "EventInfo"));
116 
117  for (size_t i = 0; i < m_trigListAll.size(); i++)
118  {
119  (m_prescaleAccessors[i]) (*evtInfo) = (m_prescaleFunctions[i]) (evtInfo, m_trigListAll[i]);
120  }
121 
122  return StatusCode::SUCCESS;
123  }
124 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CP::invalidTriggerPrescale
constexpr float invalidTriggerPrescale()
the decoration value to use if there is no valid trigger prescale information
Definition: TrigPrescalesAlg.h:22
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
CP::TrigPrescalesAlg::m_prescaleDecoration
Gaudi::Property< std::string > m_prescaleDecoration
the decoration for trigger prescales
Definition: TrigPrescalesAlg.h:59
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
CP::TrigPrescalesAlg::m_prescaleAccessors
std::vector< SG::AuxElement::Decorator< float > > m_prescaleAccessors
the accessors for m_prescaleDecoration and m_trigList combination
Definition: TrigPrescalesAlg.h:67
CP::TrigPrescalesAlg::m_trigListAll
Gaudi::Property< std::vector< std::string > > m_trigListAll
list of all triggers or trigger chains
Definition: TrigPrescalesAlg.h:47
skel.it
it
Definition: skel.GENtoEVGEN.py:407
CP::TrigPrescalesAlg::m_prescaleMC
Gaudi::Property< bool > m_prescaleMC
whether to prescale MC instead of unprescale dat
Definition: TrigPrescalesAlg.h:63
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:49
StringUtil.h
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
CP::TrigPrescalesAlg::m_selectionDecoration
Gaudi::Property< std::string > m_selectionDecoration
the decoration for trigger selection
Definition: TrigPrescalesAlg.h:71
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigPrescalesAlg.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::TrigPrescalesAlg::m_pileupReweightingTool
ToolHandle< IPileupReweightingTool > m_pileupReweightingTool
the pile-up reweighting tool
Definition: TrigPrescalesAlg.h:39
CP::TrigPrescalesAlg::m_prescaleFunctions
std::vector< std::function< float(const xAOD::EventInfo *, const std::string &)> > m_prescaleFunctions
list of helper functions to compute the prescales
Definition: TrigPrescalesAlg.h:55
CP::TrigPrescalesAlg::initialize
StatusCode initialize() override
Definition: TrigPrescalesAlg.cxx:25
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
CP::TrigPrescalesAlg::m_trigList
Gaudi::Property< std::vector< std::string > > m_trigList
list of prescaled triggers or trigger chains
Definition: TrigPrescalesAlg.h:43
RCU::substitute
std::string substitute(const std::string &str, const std::string &pattern, const std::string &with)
effects: substitute all occurences of "pattern" with "with" in the string "str" returns: the substitu...
Definition: StringUtil.cxx:24
CP::TrigPrescalesAlg::m_selectionAccessors
std::unordered_map< std::string, SG::AuxElement::ConstAccessor< bool > > m_selectionAccessors
the accessors for m_selectionDecoration and m_trigList combination
Definition: TrigPrescalesAlg.h:75
CP::TrigPrescalesAlg::m_trigFormula
Gaudi::Property< std::string > m_trigFormula
list of all triggers or trigger chains
Definition: TrigPrescalesAlg.h:51