Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
17 namespace {
18  const static SG::ConstAccessor<unsigned int> accRRN("RandomRunNumber");
19 }
20 
21 //
22 // method implementations
23 //
24 
25 namespace CP
26 {
27 
29  initialize ()
30  {
34 
45  return StatusCode::SUCCESS;
46  }
47 
48 
49 
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 
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 }
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_pileupReweightingTool
ToolHandle< IPileupReweightingTool > m_pileupReweightingTool
the smearing tool
Definition: PileupReweightingAlg.h:39
SG::WriteDecorHandle::isAvailable
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
CurrentContext.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
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::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< unsigned int >
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
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
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:49
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
CP::PileupReweightingAlg::m_decHashKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_decHashKey
Definition: PileupReweightingAlg.h:92
CP::PileupReweightingAlg::execute
StatusCode execute() override
Definition: PileupReweightingAlg.cxx:51
CP::SysListHandle::initialize
::StatusCode initialize()
intialize this property
Definition: SysListHandle.cxx:69
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
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:52
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
CP::PileupReweightingAlg::m_weightDecorator
CP::SysWriteDecorHandle< float > m_weightDecorator
the decoration for the pileup weight
Definition: PileupReweightingAlg.h:47
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
WriteDecorHandle.h
Handle class for adding a decoration to an object.
CP::PileupReweightingAlg::m_outOfValidity
OutOfValidityHelper m_outOfValidity
the helper for OutOfValidity results
Definition: PileupReweightingAlg.h:81
CP::OutOfValidityHelper::initialize
::StatusCode initialize()
standard initialize
Definition: OutOfValidityHelper.cxx:25
CP::PileupReweightingAlg::m_correctedActualMuDecorator
SG::WriteDecorHandleKey< xAOD::EventInfo > m_correctedActualMuDecorator
the decoration for the corrected actual interactions per crossing
Definition: PileupReweightingAlg.h:70
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
CP::SysWriteDecorHandle::lock
void lock(const SG::AuxElement &object, const CP::SystematicSet &sys) const
lock the object decoration for the given systematic You should call this after all set() calls for a ...
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
CP::PileupReweightingAlg::m_systematicsList
SysListHandle m_systematicsList
the systematics list we run
Definition: PileupReweightingAlg.h:43
PileupReweightingAlg.h
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
CP::PileupReweightingAlg::m_decRRNKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_decRRNKey
Definition: PileupReweightingAlg.h:84
CP::PileupReweightingAlg::m_decRLBNKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_decRLBNKey
Definition: PileupReweightingAlg.h:88
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
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
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.
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