ATLAS Offline Software
PileupScaleFactorCalculator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3  */
4 
7 #include "TopEvent/EventTools.h"
8 
10 
11 namespace top {
13  asg::AsgTool(name),
14  m_config(nullptr),
15  m_pileupReweightingTool("PileupReweightingTool"),
16  m_systNominal(CP::SystematicSet()),
17  m_systDataSFUp(CP::SystematicSet()),
18  m_systDataSFDown(CP::SystematicSet()) {
19  declareProperty("config", m_config);
20  }
21 
23  ATH_MSG_INFO(" top::PileupScaleFactorCalculator initialize");
24 
25  top::check(m_pileupReweightingTool.retrieve(), "Failed to retireve pileup reweighting tool");
26 
29 
30  m_mu_dependent_PRW = m_config->PileupMuDependent();
31 
32  return StatusCode::SUCCESS;
33  }
34 
36  // get the event info
37  const xAOD::EventInfo* eventInfo(nullptr);
38 
39  top::check(evtStore()->retrieve(eventInfo, m_config->sgKeyEventInfo()),
40  "Failed to retrieve EventInfo");
41 
42  top::check(m_pileupReweightingTool->applySystematicVariation(m_systNominal),
43  "Failed to set pileup reweighting to nominal value");
44 
46  "Failed to apply pileup weight");
47 
48  // Apply correction to actual mu for data
49  if (!m_config->isMC()) {
50  float actualMu = m_pileupReweightingTool->getCorrectedActualInteractionsPerCrossing(*eventInfo);
51  eventInfo->auxdecor<float>("corrected_actualInteractionsPerCrossing") = actualMu;
52  }
53 
54  // Get hash value which can be used later for reweighting
55  if (m_config->isMC()) {
56  unsigned long long prw_hash = m_pileupReweightingTool->getPRWHash(*eventInfo);
57  eventInfo->auxdecor<unsigned long long>("PileupWeight_Hash") = prw_hash;
58  }
59 
60  // Now get the up and down pileup variations
61  // We want the SF for MC and the mu value for data
62 
63  // Switch tool to DataSFUp
64  top::check(m_pileupReweightingTool->applySystematicVariation(m_systDataSFUp),
65  "Failed to switch pileup reweighting tool to data SF up");
66 
67  if (m_config->isMC()) {
68  // The apply method above has pileupWeight as
69  // a double (although the function returns a float)
70  // so here we do the same for consistency
71  float pileupWeight = m_pileupReweightingTool->getCombinedWeight(*eventInfo);
72  eventInfo->auxdecor<float>("PileupWeight_UP") = pileupWeight;
73  } else {
74  float lumiBlockMu {
75  1
76  };
77  if (m_config->isAFII() && m_config->PileupActualMu_AF().size() > 0) {
78  lumiBlockMu = m_pileupReweightingTool->getCorrectedActualInteractionsPerCrossing(*eventInfo);
79  } else if (!m_config->isAFII() && m_config->PileupActualMu_FS().size() > 0) {
80  lumiBlockMu = m_pileupReweightingTool->getCorrectedActualInteractionsPerCrossing(*eventInfo);
81  } else {
82  lumiBlockMu = m_pileupReweightingTool->getCorrectedAverageInteractionsPerCrossing(*eventInfo);
83  }
84  eventInfo->auxdecor<float>("corrected_averageInteractionsPerCrossing_UP") = lumiBlockMu;
85  }
86 
87  // Switch tool to DataSFDown
88  top::check(m_pileupReweightingTool->applySystematicVariation(m_systDataSFDown),
89  "Failed to switch pileup reweighting tool to data SF down");
90 
91  if (m_config->isMC()) {
92  float pileupWeight = m_pileupReweightingTool->getCombinedWeight(*eventInfo);
93  eventInfo->auxdecor<float>("PileupWeight_DOWN") = pileupWeight;
94  } else {
95  float lumiBlockMu {
96  1
97  };
98  if (m_config->isAFII() && m_config->PileupActualMu_AF().size() > 0) {
99  lumiBlockMu = m_pileupReweightingTool->getCorrectedActualInteractionsPerCrossing(*eventInfo);
100  } else if (!m_config->isAFII() && m_config->PileupActualMu_FS().size() > 0) {
101  lumiBlockMu = m_pileupReweightingTool->getCorrectedActualInteractionsPerCrossing(*eventInfo);
102  } else {
103  lumiBlockMu = m_pileupReweightingTool->getCorrectedAverageInteractionsPerCrossing(*eventInfo);
104  }
105  eventInfo->auxdecor<float>("corrected_averageInteractionsPerCrossing_DOWN") = lumiBlockMu;
106  }
107 
108  // Switch tool to back to nominal to be extra careful...
109  top::check(m_pileupReweightingTool->applySystematicVariation(m_systNominal),
110  "Failed to switch pileup reweighting tool back to nominal");
111 
112  return StatusCode::SUCCESS;
113  }
114 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
top::PileupScaleFactorCalculator::m_systDataSFUp
CP::SystematicSet m_systDataSFUp
Definition: PileupScaleFactorCalculator.h:43
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
top::PileupScaleFactorCalculator::execute
StatusCode execute()
Definition: PileupScaleFactorCalculator.cxx:35
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
top::PileupScaleFactorCalculator::m_mu_dependent_PRW
bool m_mu_dependent_PRW
Definition: PileupScaleFactorCalculator.h:46
asg
Definition: DataHandleTestTool.h:28
CP::SystematicVariation
Definition: SystematicVariation.h:47
PileupScaleFactorCalculator.h
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
SG::AuxElement::auxdecor
Decorator< T, ALLOC >::reference_type auxdecor(const std::string &name) const
Fetch an aux decoration, as a non-const reference.
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
top::PileupScaleFactorCalculator::m_systNominal
CP::SystematicSet m_systNominal
Definition: PileupScaleFactorCalculator.h:42
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
CP::SystematicSet::insert
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
Definition: SystematicSet.cxx:88
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
top::PileupScaleFactorCalculator::m_pileupReweightingTool
ToolHandle< CP::IPileupReweightingTool > m_pileupReweightingTool
Pileup Reweighting Tool.
Definition: PileupScaleFactorCalculator.h:39
TopConfig.h
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
top::PileupScaleFactorCalculator::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: PileupScaleFactorCalculator.cxx:22
top::PileupScaleFactorCalculator::m_config
std::shared_ptr< top::TopConfig > m_config
Definition: PileupScaleFactorCalculator.h:36
top::PileupScaleFactorCalculator::PileupScaleFactorCalculator
PileupScaleFactorCalculator(const std::string &name)
Definition: PileupScaleFactorCalculator.cxx:12
top::PileupScaleFactorCalculator::m_systDataSFDown
CP::SystematicSet m_systDataSFDown
Definition: PileupScaleFactorCalculator.h:44