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
14
17#include <format>
18#include <unordered_set>
19//
20// method implementations
21//
22
23namespace CP
24{
25
26 StatusCode TrigPrescalesAlg ::
27 initialize ()
28 {
29 if (m_prescaleDecoration.empty())
30 {
31 ANA_MSG_ERROR ("The prescale decoration should not be empty");
32 return StatusCode::FAILURE;
33 }
34
35 if (m_trigList.empty() && m_trigFormula.empty())
36 {
37 ANA_MSG_ERROR ("Either a list of triggers or trigger formula need to be provided");
38 return StatusCode::FAILURE;
39 }
40
41 if (!m_trigList.empty() && !m_trigFormula.empty())
42 {
43 ANA_MSG_ERROR ("Provide either only a list of triggers or only a trigger formula");
44 return StatusCode::FAILURE;
45 }
46
48
49 ANA_CHECK (m_eventInfoKey.initialize());
50
51 if (!m_selectionDecoration.empty()) {
52 for (const std::string &chain : m_trigList) {
53 m_selectionAccessors.emplace(chain, std::format("{}_{}", m_selectionDecoration.value(), sanitizeTriggerChainName(chain)));
54 }
55 }
56
57 if (!m_trigFormula.empty())
58 {
60 m_prescaleFunctions.emplace_back([this](const xAOD::EventInfo *evtInfo, const std::string &trigger)
61 {
62 if(m_prescaleMC) return m_pileupReweightingTool->getPrescaleWeight(*evtInfo, trigger, true);
63 return m_pileupReweightingTool->getDataWeight (*evtInfo, trigger, true);
64 });
65 // By putting the formula into` m_trigListAll`
66 // the logic in `execute` does not have to change
67 // depending on if `m_trigFormula` or `m_trigList` is used
68 std::vector<std::string> formulaVector = {m_trigFormula.value()};
69 m_trigListAll = std::move(formulaVector);
70 return StatusCode::SUCCESS;
71 }
72
73 if (m_trigListAll.empty())
74 {
76 }
77 const std::string prefix = m_prescaleDecoration + "_";
78 const std::unordered_set<std::string> trigSet (m_trigList.begin(), m_trigList.end());
79 for (const std::string &chain : m_trigListAll)
80 {
81 m_prescaleAccessors.emplace_back(prefix + sanitizeTriggerChainName(chain));
82
83 // Generate helper functions
84 if (trigSet.contains(chain))
85 {
86 m_prescaleFunctions.emplace_back([this](const xAOD::EventInfo *evtInfo, const std::string &trigger)
87 {
88 auto it = m_selectionAccessors.find(trigger);
89 if (it != m_selectionAccessors.end())
90 {
91 if (!it->second(*evtInfo))
92 {
94 }
95 }
96
97 if(m_prescaleMC) return m_pileupReweightingTool->getPrescaleWeight(*evtInfo, trigger, true);
98 return m_pileupReweightingTool->getDataWeight (*evtInfo, trigger, true);
99 });
100 }
101 else
102 {
103 m_prescaleFunctions.emplace_back([](const xAOD::EventInfo *, const std::string &)
104 {
105 return invalidTriggerPrescale();
106 });
107 }
108 }
109
110
111 return StatusCode::SUCCESS;
112 }
113
114
115
116 StatusCode TrigPrescalesAlg ::
117 execute (const EventContext& ctx)
118 {
120 ANA_CHECK (evtInfoHandle.isValid());
121 const xAOD::EventInfo *evtInfo = evtInfoHandle.cptr();
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}
Handle class for reading from StoreGate.
#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
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
the EventInfo to decorate
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
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Select isolated Photons, Electrons and Muons.
constexpr float invalidTriggerPrescale()
the decoration value to use if there is no valid trigger prescale information
std::string sanitizeTriggerChainName(std::string chain)
convert a trigger chain name into a string usable in decoration/branch names (.
EventInfo_v1 EventInfo
Definition of the latest event info version.