ATLAS Offline Software
Loading...
Searching...
No Matches
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
21namespace CP
22{
23
24 StatusCode TrigPrescalesAlg ::
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) {
49 m_selectionAccessors.emplace(chain, m_selectionDecoration + "_" + RCU::substitute(RCU::substitute(chain, ".", "p"), "-", "_"));
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 {
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
111 StatusCode TrigPrescalesAlg ::
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}
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
std::vector< std::function< float(const xAOD::EventInfo *, const std::string &)> > m_prescaleFunctions
list of helper functions to compute the prescales
ToolHandle< IPileupReweightingTool > m_pileupReweightingTool
the pile-up reweighting tool
Gaudi::Property< std::vector< std::string > > m_trigListAll
list of all triggers or trigger chains
Gaudi::Property< std::string > m_trigFormula
list of all triggers or trigger chains
Gaudi::Property< std::vector< std::string > > m_trigList
list of prescaled triggers or trigger chains
Gaudi::Property< bool > m_prescaleMC
whether to prescale MC instead of unprescale dat
Gaudi::Property< std::string > m_prescaleDecoration
the decoration for trigger prescales
std::vector< SG::Decorator< float > > m_prescaleAccessors
the accessors for m_prescaleDecoration and m_trigList combination
Gaudi::Property< std::string > m_selectionDecoration
the decoration for trigger selection
std::unordered_map< std::string, SG::ConstAccessor< bool > > m_selectionAccessors
the accessors for m_selectionDecoration and m_trigList combination
Select isolated Photons, Electrons and Muons.
constexpr float invalidTriggerPrescale()
the decoration value to use if there is no valid trigger prescale information
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...
EventInfo_v1 EventInfo
Definition of the latest event info version.