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//
15
17namespace {
18 const static SG::ConstAccessor<unsigned int> accRRN("RandomRunNumber");
19}
20
21//
22// method implementations
23//
24
25namespace CP
26{
27
28 StatusCode PileupReweightingAlg ::
29 initialize ()
30 {
34
39 ANA_CHECK (m_systematicsList.initialize());
40 ANA_CHECK (m_outOfValidity.initialize());
41 ANA_CHECK (m_baseEventInfoName.initialize());
42 ANA_CHECK (m_decRRNKey.initialize());
43 ANA_CHECK (m_decRLBNKey.initialize());
44 ANA_CHECK (m_decHashKey.initialize());
45 return StatusCode::SUCCESS;
46 }
47
48
49
50 StatusCode PileupReweightingAlg ::
51 execute ()
52 {
53
54 const EventContext& ctx = Gaudi::Hive::currentContext();
56
57 // Add additional decorations - these apply to data (and on MC just redecorate the same value as
58 // before)
60 {
62 dec (*evtInfo)
63 = m_pileupReweightingTool->getCorrectedAverageInteractionsPerCrossing (*evtInfo, true);
64 }
65
67 {
69 dec (*evtInfo)
70 = m_pileupReweightingTool->getCorrectedActualInteractionsPerCrossing (*evtInfo);
71 }
72
74 {
76 dec (*evtInfo)
77 = m_pileupReweightingTool->getCorrectedActualInteractionsPerCrossing (*evtInfo, true);
78 }
79
80 if (!evtInfo->eventType(xAOD::EventInfo::IS_SIMULATION))
81 // The rest of the PRW tool only applies to MC
82 return StatusCode::SUCCESS;
83
84 // Deal with the parts that aren't related to systematics
85 // Get random run and lumi block numbers
87 unsigned int rrn = 0;
88 if(decRRN.isAvailable())
89 rrn = accRRN(*evtInfo);
90 else{
91 rrn = m_pileupReweightingTool->getRandomRunNumber(*evtInfo, true);
92 // If it returns 0, try again without the mu dependence
93 if(rrn == 0)
94 rrn = m_pileupReweightingTool->getRandomRunNumber(*evtInfo, false);
95 decRRN(*evtInfo) = rrn;
96 }
97
99 if(!decRLBN.isAvailable())
100 decRLBN(*evtInfo) = (rrn == 0) ? 0 : m_pileupReweightingTool->GetRandomLumiBlockNumber(rrn);
101
102 // Also decorate with the hash, this can be used for rerunning PRW (but usually isn't)
104 if(!decHash.isAvailable())
105 decHash(*evtInfo) = m_pileupReweightingTool->getPRWHash(*evtInfo);
106
107 // Take care of the weight (which is the only thing depending on systematics)
108 for (const auto& sys : m_systematicsList.systematicsVector())
109 {
110 const xAOD::EventInfo* systEvtInfo = nullptr;
111 ANA_CHECK( m_eventInfoHandle.retrieve(systEvtInfo, sys));
112 ANA_CHECK (m_pileupReweightingTool->applySystematicVariation (sys));
113 if (m_weightDecorator) {
114 // calculate and set the weight. The 'true' argument makes the tool treat unrepresented data
115 // correctly if the corresponding property is set
116 m_weightDecorator.set(*systEvtInfo, m_pileupReweightingTool->getCombinedWeight(*evtInfo, true), sys);
117 m_weightDecorator.lock(*systEvtInfo, sys);
118 }
119
120 };
121 return StatusCode::SUCCESS;
122 }
123}
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.