ATLAS Offline Software
Loading...
Searching...
No Matches
TrigPrescalesAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8//
9// includes
10//
11
13
14#include <algorithm>
16#include <format>
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 std::string chainfix = chain;
50 std::replace(chainfix.begin(), chainfix.end(), '.', 'p');
51 std::replace(chainfix.begin(), chainfix.end(), '-', '_');
52 m_selectionAccessors.emplace(chain, std::format("{}_{}", m_selectionDecoration.value(), chainfix));
53 }
54 }
55
56 if (!m_trigFormula.empty())
57 {
59 m_prescaleFunctions.emplace_back([this](const xAOD::EventInfo *evtInfo, const std::string &trigger)
60 {
61 if(m_prescaleMC) return m_pileupReweightingTool->getPrescaleWeight(*evtInfo, trigger, true);
62 return m_pileupReweightingTool->getDataWeight (*evtInfo, trigger, true);
63 });
64 // By putting the formula into` m_trigListAll`
65 // the logic in `execute` does not have to change
66 // depending on if `m_trigFormula` or `m_trigList` is used
67 std::vector<std::string> formulaVector = {m_trigFormula.value()};
68 m_trigListAll = std::move(formulaVector);
69 return StatusCode::SUCCESS;
70 }
71
72 if (m_trigListAll.empty())
73 {
75 }
76 const std::string prefix = m_prescaleDecoration + "_";
77 for (const std::string &chain : m_trigListAll)
78 {
79 std::string chainfix = chain;
80 std::replace(chainfix.begin(), chainfix.end(), '.', 'p');
81 std::replace(chainfix.begin(), chainfix.end(), '-', '_');
82 m_prescaleAccessors.emplace_back(prefix + chainfix);
83
84 // Generate helper functions
85 if (std::find(m_trigList.begin(), m_trigList.end(), chain) != m_trigList.end())
86 {
87 m_prescaleFunctions.emplace_back([this](const xAOD::EventInfo *evtInfo, const std::string &trigger)
88 {
89 auto it = m_selectionAccessors.find(trigger);
90 if (it != m_selectionAccessors.end())
91 {
92 if (!it->second(*evtInfo))
93 {
95 }
96 }
97
98 if(m_prescaleMC) return m_pileupReweightingTool->getPrescaleWeight(*evtInfo, trigger, true);
99 return m_pileupReweightingTool->getDataWeight (*evtInfo, trigger, true);
100 });
101 }
102 else
103 {
104 m_prescaleFunctions.emplace_back([](const xAOD::EventInfo *, const std::string &)
105 {
106 return invalidTriggerPrescale();
107 });
108 }
109 }
110
111
112 return StatusCode::SUCCESS;
113 }
114
115
116
117 StatusCode TrigPrescalesAlg ::
118 execute ()
119 {
120 const xAOD::EventInfo *evtInfo{};
121 ANA_CHECK (evtStore()->retrieve(evtInfo, "EventInfo"));
122
123 for (size_t i = 0; i < m_trigListAll.size(); i++)
124 {
125 (m_prescaleAccessors[i]) (*evtInfo) = (m_prescaleFunctions[i]) (evtInfo, m_trigListAll[i]);
126 }
127
128 return StatusCode::SUCCESS;
129 }
130}
#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
EventInfo_v1 EventInfo
Definition of the latest event info version.