ATLAS Offline Software
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 //
12 
14 namespace {
15  const static SG::ConstAuxElement::ConstAccessor<unsigned int> accRRN("RandomRunNumber");
16  const static SG::ConstAuxElement::Decorator<unsigned int> decRRN("RandomRunNumber");
17  const static SG::ConstAuxElement::Decorator<unsigned int> decRLBN("RandomLumiBlockNumber");
18  const static SG::ConstAuxElement::Decorator<uint64_t> decHash("PRWHash");
19 }
20 
21 //
22 // method implementations
23 //
24 
25 namespace CP
26 {
27 
29  initialize ()
30  {
32  {
33  m_correctedScaledAverageMuDecorator = std::make_unique<SG::AuxElement::Decorator<float> > (m_correctedScaledAverageMuDecoration);
34  }
35  if (!m_correctedActualMuDecoration.empty())
36  {
37  m_correctedActualMuDecorator = std::make_unique<SG::AuxElement::Decorator<float> > (m_correctedActualMuDecoration);
38  }
40  {
41  m_correctedScaledActualMuDecorator = std::make_unique<SG::AuxElement::Decorator<float> > (m_correctedScaledActualMuDecoration);
42  }
43 
51  return StatusCode::SUCCESS;
52  }
53 
54 
55 
57  execute ()
58  {
59 
61 
62  // Add additional decorations - these apply to data (and on MC just redecorate the same value as
63  // before)
65  {
66  (*m_correctedScaledAverageMuDecorator) (*evtInfo)
67  = m_pileupReweightingTool->getCorrectedAverageInteractionsPerCrossing (*evtInfo, true);
68  }
69 
71  {
72  (*m_correctedActualMuDecorator) (*evtInfo)
73  = m_pileupReweightingTool->getCorrectedActualInteractionsPerCrossing (*evtInfo);
74  }
75 
77  {
78  (*m_correctedScaledActualMuDecorator) (*evtInfo)
79  = m_pileupReweightingTool->getCorrectedActualInteractionsPerCrossing (*evtInfo, true);
80  }
81 
83  // The rest of the PRW tool only applies to MC
84  return StatusCode::SUCCESS;
85 
86  // Deal with the parts that aren't related to systematics
87  // Get random run and lumi block numbers
88  unsigned int rrn = 0;
89  if(decRRN.isAvailable(*evtInfo))
90  rrn = 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  if(!decRLBN.isAvailable(*evtInfo))
99  decRLBN(*evtInfo) = (rrn == 0) ? 0 : m_pileupReweightingTool->GetRandomLumiBlockNumber(rrn);
100  // Also decorate with the hash, this can be used for rerunning PRW (but usually isn't)
101  if(!decHash.isAvailable(*evtInfo))
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));
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 
115  };
116  return StatusCode::SUCCESS;
117  }
118 }
CP::SysWriteDecorHandle::set
void set(const SG::AuxElement &object, const T &value, const CP::SystematicSet &sys) const
set the object decoration for the given systematic
CP::PileupReweightingAlg::m_correctedActualMuDecorator
std::unique_ptr< const SG::AuxElement::Decorator< float > > m_correctedActualMuDecorator
the accessor for m_correctedActualMuDecoration
Definition: PileupReweightingAlg.h:78
CP::PileupReweightingAlg::m_pileupReweightingTool
ToolHandle< IPileupReweightingTool > m_pileupReweightingTool
the smearing tool
Definition: PileupReweightingAlg.h:38
CP::PileupReweightingAlg::m_correctedScaledActualMuDecoration
Gaudi::Property< std::string > m_correctedScaledActualMuDecoration
the decoration for the corrected and scaled actual interactions per crossing
Definition: PileupReweightingAlg.h:70
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
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:56
CP::SysListHandle::addSystematics
StatusCode addSystematics(const CP::SystematicSet &recommended, const CP::SystematicSet &affecting)
register a set of affecting variables for the current algorithm (usually obtained from an CP::ISystem...
Definition: SysListHandle.cxx:48
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
CP::SysListHandle::systematicsVector
const std::vector< CP::SystematicSet > & systematicsVector() const
the list of systematics to loop over
Definition: SysListHandle.cxx:96
PURW_create_mc_default_profile.rrn
rrn
Definition: PURW_create_mc_default_profile.py:85
CP::PileupReweightingAlg::initialize
StatusCode initialize() override
Definition: PileupReweightingAlg.cxx:29
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:48
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
CP::PileupReweightingAlg::m_correctedScaledActualMuDecorator
std::unique_ptr< const SG::AuxElement::Decorator< float > > m_correctedScaledActualMuDecorator
the accessor for m_correctedScaledAverageMuDecoration
Definition: PileupReweightingAlg.h:82
CP::PileupReweightingAlg::m_correctedScaledAverageMuDecorator
std::unique_ptr< const SG::AuxElement::Decorator< float > > m_correctedScaledAverageMuDecorator
the accessor for m_correctedScaledAverageMuDecoration
Definition: PileupReweightingAlg.h:74
CP::PileupReweightingAlg::m_correctedScaledAverageMuDecoration
Gaudi::Property< std::string > m_correctedScaledAverageMuDecoration
the decoration for the corrected and scaled average interactions per crossing
Definition: PileupReweightingAlg.h:62
CP::PileupReweightingAlg::execute
StatusCode execute() override
Definition: PileupReweightingAlg.cxx:57
CP::SysListHandle::initialize
::StatusCode initialize()
intialize this property
Definition: SysListHandle.cxx:69
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::PileupReweightingAlg::m_correctedActualMuDecoration
Gaudi::Property< std::string > m_correctedActualMuDecoration
the decoration for the corrected actual interactions per crossing
Definition: PileupReweightingAlg.h:66
CP::SysWriteDecorHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle, const ISysHandleBase &objectHandle)
initialize this handle
CP::PileupReweightingAlg::m_eventInfoHandle
CP::SysReadHandle< xAOD::EventInfo > m_eventInfoHandle
the name of the event info object
Definition: PileupReweightingAlg.h:51
CP::PileupReweightingAlg::m_weightDecorator
CP::SysWriteDecorHandle< float > m_weightDecorator
the decoration for the pileup weight
Definition: PileupReweightingAlg.h:46
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
CP::PileupReweightingAlg::m_outOfValidity
OutOfValidityHelper m_outOfValidity
the helper for OutOfValidity results
Definition: PileupReweightingAlg.h:86
CP::OutOfValidityHelper::initialize
::StatusCode initialize()
standard initialize
Definition: OutOfValidityHelper.cxx:25
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
CP::PileupReweightingAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition: PileupReweightingAlg.h:42
PileupReweightingAlg.h
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.