ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
TriggerAnalysisAlgorithms
Root
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
12
#include <
TriggerAnalysisAlgorithms/TrigPrescalesAlg.h
>
13
14
#include <algorithm>
15
#include <
xAODEventInfo/EventInfo.h
>
16
#include <format>
17
//
18
// method implementations
19
//
20
21
namespace
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
45
ANA_CHECK
(
m_pileupReweightingTool
.retrieve());
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
{
58
m_prescaleAccessors
.emplace_back(
m_prescaleDecoration
);
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
{
74
m_trigListAll
=
m_trigList
;
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
{
94
return
invalidTriggerPrescale
();
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 (
const
EventContext&
/*ctx*/
)
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
}
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
TrigPrescalesAlg.h
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
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::m_pileupReweightingTool
ToolHandle< IPileupReweightingTool > m_pileupReweightingTool
the pile-up reweighting tool
Definition
TrigPrescalesAlg.h:39
CP::TrigPrescalesAlg::m_trigListAll
Gaudi::Property< std::vector< std::string > > m_trigListAll
list of all triggers or trigger chains
Definition
TrigPrescalesAlg.h:47
CP::TrigPrescalesAlg::m_trigFormula
Gaudi::Property< std::string > m_trigFormula
list of all triggers or trigger chains
Definition
TrigPrescalesAlg.h:51
CP::TrigPrescalesAlg::m_trigList
Gaudi::Property< std::vector< std::string > > m_trigList
list of prescaled triggers or trigger chains
Definition
TrigPrescalesAlg.h:43
CP::TrigPrescalesAlg::m_prescaleMC
Gaudi::Property< bool > m_prescaleMC
whether to prescale MC instead of unprescale dat
Definition
TrigPrescalesAlg.h:63
CP::TrigPrescalesAlg::m_prescaleDecoration
Gaudi::Property< std::string > m_prescaleDecoration
the decoration for trigger prescales
Definition
TrigPrescalesAlg.h:59
CP::TrigPrescalesAlg::m_prescaleAccessors
std::vector< SG::Decorator< float > > m_prescaleAccessors
the accessors for m_prescaleDecoration and m_trigList combination
Definition
TrigPrescalesAlg.h:67
CP::TrigPrescalesAlg::m_selectionDecoration
Gaudi::Property< std::string > m_selectionDecoration
the decoration for trigger selection
Definition
TrigPrescalesAlg.h:71
CP::TrigPrescalesAlg::m_selectionAccessors
std::unordered_map< std::string, SG::ConstAccessor< bool > > m_selectionAccessors
the accessors for m_selectionDecoration and m_trigList combination
Definition
TrigPrescalesAlg.h:75
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
CP::invalidTriggerPrescale
constexpr float invalidTriggerPrescale()
the decoration value to use if there is no valid trigger prescale information
Definition
TrigPrescalesAlg.h:22
xAOD::EventInfo
EventInfo_v1 EventInfo
Definition of the latest event info version.
Definition
IEventInfoCnvTool.h:16
EventInfo.h
Generated on
for ATLAS Offline Software by
1.17.0