ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
AsgAnalysisAlgorithms
Root
PileupReweightingAlg.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
#include "
AsgAnalysisAlgorithms/PileupReweightingAlg.h
"
12
#include "
AsgDataHandles/WriteDecorHandle.h
"
13
14
//
15
// method implementations
16
//
17
18
namespace
CP
19
{
20
21
StatusCode PileupReweightingAlg ::
22
initialize ()
23
{
24
ANA_CHECK
(
m_correctedAverageMuDecorator
.initialize(
SG::AllowEmpty
) );
25
ANA_CHECK
(
m_correctedScaledAverageMuDecorator
.initialize(
SG::AllowEmpty
) );
26
ANA_CHECK
(
m_correctedActualMuDecorator
.initialize(
SG::AllowEmpty
) );
27
ANA_CHECK
(
m_correctedScaledActualMuDecorator
.initialize(
SG::AllowEmpty
) );
28
29
ANA_CHECK
(
m_eventInfoHandle
.initialize(
m_systematicsList
));
30
ANA_CHECK
(
m_weightDecorator
.initialize(
m_systematicsList
,
m_eventInfoHandle
,
SG::AllowEmpty
));
31
ANA_CHECK
(
m_pileupReweightingTool
.retrieve());
32
ANA_CHECK
(
m_systematicsList
.addSystematics (*
m_pileupReweightingTool
));
33
ANA_CHECK
(
m_systematicsList
.initialize());
34
ANA_CHECK
(
m_outOfValidity
.initialize());
35
ANA_CHECK
(
m_baseEventInfoKey
.initialize());
36
ANA_CHECK
(
m_decRRNKey
.initialize());
37
const
std::string& rrnKey =
m_decRRNKey
.key();
38
m_accRRN
.emplace (rrnKey.substr (rrnKey.rfind (
'.'
) + 1));
39
ANA_CHECK
(
m_decRLBNKey
.initialize());
40
ANA_CHECK
(
m_decHashKey
.initialize());
41
return
StatusCode::SUCCESS;
42
}
43
44
45
46
StatusCode PileupReweightingAlg ::
47
execute (
const
EventContext& ctx)
48
{
49
SG::ReadHandle<xAOD::EventInfo>
evtInfo(
m_baseEventInfoKey
, ctx);
50
51
// Add additional decorations - these apply to data (and on MC just redecorate the same value as
52
// before)
53
if
(!
m_correctedAverageMuDecorator
.empty())
54
{
55
SG::WriteDecorHandle<xAOD::EventInfo, float>
dec (
m_correctedAverageMuDecorator
, ctx);
56
dec (*evtInfo)
57
=
m_pileupReweightingTool
->getCorrectedAverageInteractionsPerCrossing (*evtInfo);
58
}
59
60
if
(!
m_correctedScaledAverageMuDecorator
.empty())
61
{
62
SG::WriteDecorHandle<xAOD::EventInfo, float>
dec (
m_correctedScaledAverageMuDecorator
, ctx);
63
dec (*evtInfo)
64
=
m_pileupReweightingTool
->getCorrectedAverageInteractionsPerCrossing (*evtInfo,
true
);
65
}
66
67
if
(!
m_correctedActualMuDecorator
.empty())
68
{
69
SG::WriteDecorHandle<xAOD::EventInfo, float>
dec (
m_correctedActualMuDecorator
, ctx);
70
dec (*evtInfo)
71
=
m_pileupReweightingTool
->getCorrectedActualInteractionsPerCrossing (*evtInfo);
72
}
73
74
if
(!
m_correctedScaledActualMuDecorator
.empty())
75
{
76
SG::WriteDecorHandle<xAOD::EventInfo, float>
dec (
m_correctedScaledActualMuDecorator
, ctx);
77
dec (*evtInfo)
78
=
m_pileupReweightingTool
->getCorrectedActualInteractionsPerCrossing (*evtInfo,
true
);
79
}
80
81
if
(!evtInfo->eventType(
xAOD::EventInfo::IS_SIMULATION
))
82
// The rest of the PRW tool only applies to MC
83
return
StatusCode::SUCCESS;
84
85
// Deal with the parts that aren't related to systematics
86
// Get random run and lumi block numbers
87
SG::WriteDecorHandle<xAOD::EventInfo, unsigned int>
decRRN (
m_decRRNKey
, ctx);
88
unsigned
int
rrn = 0;
89
if
(decRRN.
isAvailable
())
90
rrn = (*m_accRRN)(*evtInfo);
91
else
{
92
rrn =
m_pileupReweightingTool
->getRandomRunNumber(*evtInfo,
true
);
93
// If it returns 0, try again without the mu dependence
94
if
(rrn == 0)
95
rrn =
m_pileupReweightingTool
->getRandomRunNumber(*evtInfo,
false
);
96
decRRN(*evtInfo) = rrn;
97
}
98
99
SG::WriteDecorHandle<xAOD::EventInfo, unsigned int>
decRLBN (
m_decRLBNKey
, ctx);
100
if
(!decRLBN.
isAvailable
())
101
decRLBN(*evtInfo) = (rrn == 0) ? 0 :
m_pileupReweightingTool
->GetRandomLumiBlockNumber(rrn);
102
103
// Also decorate with the hash, this can be used for rerunning PRW (but usually isn't)
104
SG::WriteDecorHandle<xAOD::EventInfo, uint64_t>
decHash (
m_decHashKey
, ctx);
105
if
(!decHash.
isAvailable
())
106
decHash(*evtInfo) =
m_pileupReweightingTool
->getPRWHash(*evtInfo);
107
108
// Take care of the weight (which is the only thing depending on systematics)
109
if
(
m_weightDecorator
) {
110
for
(
const
auto
& sys :
m_systematicsList
.systematicsVector())
111
{
112
const
xAOD::EventInfo
* systEvtInfo =
nullptr
;
113
ANA_CHECK
(
m_eventInfoHandle
.retrieve(systEvtInfo, sys, ctx));
114
ANA_CHECK
(
m_pileupReweightingTool
->applySystematicVariation (sys));
115
// calculate and set the weight. The 'true' argument makes the tool treat unrepresented data
116
// correctly if the corresponding property is set
117
m_weightDecorator
.set(*systEvtInfo,
m_pileupReweightingTool
->getCombinedWeight(*evtInfo,
true
), sys);
118
m_weightDecorator
.lock(*systEvtInfo, sys);
119
}
120
}
121
return
StatusCode::SUCCESS;
122
}
123
}
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:325
PileupReweightingAlg.h
CP::PileupReweightingAlg::m_decRRNKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_decRRNKey
Definition
PileupReweightingAlg.h:94
CP::PileupReweightingAlg::m_accRRN
std::optional< SG::ConstAccessor< unsigned int > > m_accRRN
the accessor for reading back the RandomRunNumber decoration
Definition
PileupReweightingAlg.h:98
CP::PileupReweightingAlg::m_correctedScaledAverageMuDecorator
SG::WriteDecorHandleKey< xAOD::EventInfo > m_correctedScaledAverageMuDecorator
the decoration for the corrected and scaled average interactions per crossing
Definition
PileupReweightingAlg.h:74
CP::PileupReweightingAlg::m_weightDecorator
CP::SysWriteDecorHandle< float > m_weightDecorator
the decoration for the pileup weight
Definition
PileupReweightingAlg.h:50
CP::PileupReweightingAlg::m_correctedScaledActualMuDecorator
SG::WriteDecorHandleKey< xAOD::EventInfo > m_correctedScaledActualMuDecorator
the decoration for the corrected and scaled actual interactions per crossing
Definition
PileupReweightingAlg.h:86
CP::PileupReweightingAlg::m_outOfValidity
OutOfValidityHelper m_outOfValidity
the helper for OutOfValidity results
Definition
PileupReweightingAlg.h:91
CP::PileupReweightingAlg::m_baseEventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_baseEventInfoKey
the name of the original event info (this should usually be the same as eventiNfoHandle and EventInfo...
Definition
PileupReweightingAlg.h:60
CP::PileupReweightingAlg::m_eventInfoHandle
CP::SysReadHandle< xAOD::EventInfo > m_eventInfoHandle
the name of the event info object
Definition
PileupReweightingAlg.h:55
CP::PileupReweightingAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition
PileupReweightingAlg.h:46
CP::PileupReweightingAlg::m_decHashKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_decHashKey
Definition
PileupReweightingAlg.h:105
CP::PileupReweightingAlg::m_correctedActualMuDecorator
SG::WriteDecorHandleKey< xAOD::EventInfo > m_correctedActualMuDecorator
the decoration for the corrected actual interactions per crossing
Definition
PileupReweightingAlg.h:80
CP::PileupReweightingAlg::m_decRLBNKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_decRLBNKey
Definition
PileupReweightingAlg.h:101
CP::PileupReweightingAlg::m_correctedAverageMuDecorator
SG::WriteDecorHandleKey< xAOD::EventInfo > m_correctedAverageMuDecorator
the decoration for the corrected average interactions per crossing
Definition
PileupReweightingAlg.h:68
CP::PileupReweightingAlg::m_pileupReweightingTool
ToolHandle< IPileupReweightingTool > m_pileupReweightingTool
the smearing tool
Definition
PileupReweightingAlg.h:42
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:66
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
SG::WriteDecorHandle::isAvailable
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition
EventInfo_v1.h:151
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
SG::AllowEmpty
@ AllowEmpty
Definition
StoreGate/StoreGate/VarHandleKey.h:29
xAOD::EventInfo
EventInfo_v1 EventInfo
Definition of the latest event info version.
Definition
IEventInfoCnvTool.h:16
Generated on
for ATLAS Offline Software by
1.17.0