ATLAS Offline Software
TrigPrescalesAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 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_trigFormula.empty())
48  {
50  m_prescaleFunctions.emplace_back([this](const xAOD::EventInfo *evtInfo, const std::string &trigger)
51  {
52  if(m_prescaleMC) return m_pileupReweightingTool->getPrescaleWeight(*evtInfo, trigger, true);
53  return m_pileupReweightingTool->getDataWeight (*evtInfo, trigger, true);
54  });
55  // By putting the formula into` m_trigListAll`
56  // the logic in `execute` does not have to change
57  // depending on if `m_trigFormula` or `m_trigList` is used
58  std::vector<std::string> formulaVector = {m_trigFormula.value()};
59  m_trigListAll = formulaVector;
60  return StatusCode::SUCCESS;
61  }
62 
63  if (m_trigListAll.empty())
64  {
66  }
67 
68  for (const std::string &chain : m_trigListAll)
69  {
70  m_prescaleAccessors.emplace_back(m_prescaleDecoration + "_" + RCU::substitute (chain, "-", "_"));
71 
72  // Generate helper functions
73  if (std::find(m_trigList.begin(), m_trigList.end(), chain) != m_trigList.end())
74  {
75  m_prescaleFunctions.emplace_back([this](const xAOD::EventInfo *evtInfo, const std::string &trigger)
76  {
77  if(m_prescaleMC) return m_pileupReweightingTool->getPrescaleWeight(*evtInfo, trigger, true);
78  return m_pileupReweightingTool->getDataWeight (*evtInfo, trigger, true);
79  });
80  }
81  else
82  {
83  m_prescaleFunctions.emplace_back([](const xAOD::EventInfo *, const std::string &)
84  {
85  return invalidTriggerPrescale();
86  });
87  }
88  }
89 
90 
91  return StatusCode::SUCCESS;
92  }
93 
94 
95 
97  execute ()
98  {
99  const xAOD::EventInfo *evtInfo{};
100  ANA_CHECK (evtStore()->retrieve(evtInfo, "EventInfo"));
101 
102  for (size_t i = 0; i < m_trigListAll.size(); i++)
103  {
104  (m_prescaleAccessors[i]) (*evtInfo) = (m_prescaleFunctions[i]) (evtInfo, m_trigListAll[i]);
105  }
106 
107  return StatusCode::SUCCESS;
108  }
109 }
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:21
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:58
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:66
CP::TrigPrescalesAlg::m_trigListAll
Gaudi::Property< std::vector< std::string > > m_trigListAll
list of all triggers or trigger chains
Definition: TrigPrescalesAlg.h:46
CP::TrigPrescalesAlg::m_prescaleMC
Gaudi::Property< bool > m_prescaleMC
whether to prescale MC instead of unprescale dat
Definition: TrigPrescalesAlg.h:62
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:48
StringUtil.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
lumiFormat.i
int i
Definition: lumiFormat.py:92
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:38
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:54
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:42
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::execute
StatusCode execute() override
Definition: TrigPrescalesAlg.cxx:97
CP::TrigPrescalesAlg::m_trigFormula
Gaudi::Property< std::string > m_trigFormula
list of all triggers or trigger chains
Definition: TrigPrescalesAlg.h:50
PhysDESDM_Quirks.trigger
trigger
Definition: PhysDESDM_Quirks.py:27