ATLAS Offline Software
Loading...
Searching...
No Matches
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//
14
16namespace {
17 const static SG::ConstAccessor<unsigned int> accRRN("RandomRunNumber");
18}
19
20//
21// method implementations
22//
23
24namespace CP
25{
26
27 StatusCode PileupReweightingAlg ::
28 initialize ()
29 {
33
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 {
53
54 // Add additional decorations - these apply to data (and on MC just redecorate the same value as
55 // before)
57 {
59 dec (*evtInfo)
60 = m_pileupReweightingTool->getCorrectedAverageInteractionsPerCrossing (*evtInfo, true);
61 }
62
64 {
66 dec (*evtInfo)
67 = m_pileupReweightingTool->getCorrectedActualInteractionsPerCrossing (*evtInfo);
68 }
69
71 {
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
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
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)
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}
Handle class for adding a decoration to an object.
Helper class to provide constant type-safe access to aux data.
#define ANA_CHECK(EXP)
check whether the given expression was successful
SG::WriteDecorHandleKey< xAOD::EventInfo > m_decRRNKey
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
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::ReadHandleKey< xAOD::EventInfo > m_baseEventInfoName
the name of the original event info (this should usually be the same as eventiNfoHandle and EventInfo...
ToolHandle< IPileupReweightingTool > m_pileupReweightingTool
the smearing tool
Helper class to provide constant type-safe access to aux data.
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.