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