ATLAS Offline Software
Loading...
Searching...
No Matches
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//
13
14//
15// method implementations
16//
17
18namespace CP
19{
20
21 StatusCode PileupReweightingAlg ::
22 initialize ()
23 {
28
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 {
50
51 // Add additional decorations - these apply to data (and on MC just redecorate the same value as
52 // before)
54 {
56 dec (*evtInfo)
57 = m_pileupReweightingTool->getCorrectedAverageInteractionsPerCrossing (*evtInfo);
58 }
59
61 {
63 dec (*evtInfo)
64 = m_pileupReweightingTool->getCorrectedAverageInteractionsPerCrossing (*evtInfo, true);
65 }
66
68 {
70 dec (*evtInfo)
71 = m_pileupReweightingTool->getCorrectedActualInteractionsPerCrossing (*evtInfo);
72 }
73
75 {
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
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
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)
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}
Handle class for adding a decoration to an object.
#define ANA_CHECK(EXP)
check whether the given expression was successful
SG::WriteDecorHandleKey< xAOD::EventInfo > m_decRRNKey
std::optional< SG::ConstAccessor< unsigned int > > m_accRRN
the accessor for reading back the RandomRunNumber decoration
SG::WriteDecorHandleKey< xAOD::EventInfo > m_correctedScaledAverageMuDecorator
the decoration for the corrected and scaled average interactions per crossing
CP::SysWriteDecorHandle< float > m_weightDecorator
the decoration for the pileup weight
SG::WriteDecorHandleKey< xAOD::EventInfo > m_correctedScaledActualMuDecorator
the decoration for the corrected and scaled actual interactions per crossing
OutOfValidityHelper m_outOfValidity
the helper for OutOfValidity results
SG::ReadHandleKey< xAOD::EventInfo > m_baseEventInfoKey
the name of the original event info (this should usually be the same as eventiNfoHandle and EventInfo...
CP::SysReadHandle< xAOD::EventInfo > m_eventInfoHandle
the name of the event info object
SysListHandle m_systematicsList
the systematics list we run
SG::WriteDecorHandleKey< xAOD::EventInfo > m_decHashKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_correctedActualMuDecorator
the decoration for the corrected actual interactions per crossing
SG::WriteDecorHandleKey< xAOD::EventInfo > m_decRLBNKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_correctedAverageMuDecorator
the decoration for the corrected average interactions per crossing
ToolHandle< IPileupReweightingTool > m_pileupReweightingTool
the smearing tool
Handle class for adding a decoration to an object.
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
@ IS_SIMULATION
true: simulation, false: data
Select isolated Photons, Electrons and Muons.
EventInfo_v1 EventInfo
Definition of the latest event info version.