ATLAS Offline Software
PhotonScaleFactorCalculator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 // $Id: PhotonScaleFactorCalculator.cxx 802226 2017-04-04 16:13:10Z grancagn $
7 
8 #include <string>
9 
11 #include "TopEvent/EventTools.h"
12 
14 
15 namespace top {
17  asg::AsgTool(name),
18  m_config(nullptr),
19  m_systNominal(CP::SystematicSet()),
20  m_systEffIDUp("PH_EFF_ID_Uncertainty__1up"),
21  m_systEffIDDown("PH_EFF_ID_Uncertainty__1down"),
22  m_systEffIsoUp("PH_EFF_ISO_Uncertainty__1up"),
23  m_systEffIsoDown("PH_EFF_ISO_Uncertainty__1down"),
24  m_photonEffSF("AsgPhotonEfficiencyCorrectionTool"),
25  m_photonIsoSF(),
26  m_photonLooseIsoSF(),
27  m_photonIsoSF_exists(false),
28  m_photonLooseIsoSF_exists(false),
29  m_decor_isoSF("SetMe"),
30  m_decor_isoSF_loose("SetMe") {
31  declareProperty("config", m_config);
32  }
33 
35  ATH_MSG_INFO(" top::PhotonScaleFactorCalculator initialize");
36  top::check(m_photonEffSF.retrieve(),
37  "Failed to retrieve photon efficiency SF calculator");
38  MsgStream& msgInfo = msg(MSG::Level::INFO);
39  msgInfo << "------>Systematics:\n";
40  for (auto sys:m_photonEffSF->recommendedSystematics())
41  msgInfo << "---> " << sys << "\n";
42  msgInfo.doOutput();
43 
44  // remove "FixedCut" if present
45  std::string s = "FixedCut";
46  std::string isoName = m_config->photonIsolation();
47  m_decor_isoSF = "PH_SF_Iso_" + isoName;
48  std::string::size_type i = isoName.find(s);
49  if (i != std::string::npos) isoName.erase(i, s.length());
50  std::string photonIsoSFName = "AsgPhotonEfficiencyCorrectionTool_IsoSF" + isoName;
51  m_photonIsoSF.setName(photonIsoSFName);
52  if (asg::ToolStore::contains<IAsgPhotonEfficiencyCorrectionTool>(photonIsoSFName)) {
53  m_photonIsoSF_exists = true;
54  top::check(m_photonIsoSF.retrieve(),
55  "Failed to retrieve photon isolation efficiency SF calculator");
56  msgInfo << "------>Systematics:\n";
57  for (auto sys:m_photonIsoSF->recommendedSystematics())
58  msgInfo << "---> " << sys << "\n";
59  }
60 
61  std::string isoNameLoose = m_config->photonIsolationLoose();
62  m_decor_isoSF_loose = "PH_LOOSE_SF_Iso_" + isoNameLoose;
63  i = isoNameLoose.find(s);
64  if (i != std::string::npos) isoNameLoose.erase(i, s.length());
65  std::string photonLooseIsoSFName = "AsgPhotonEfficiencyCorrectionTool_IsoSF" + isoNameLoose;
66  m_photonLooseIsoSF.setName(photonLooseIsoSFName);
67  if (asg::ToolStore::contains<IAsgPhotonEfficiencyCorrectionTool>(photonLooseIsoSFName)) {
69  top::check(m_photonLooseIsoSF.retrieve(),
70  "Failed to retrieve loose photon isolation efficiency SF calculator");
71  }
72  return StatusCode::SUCCESS;
73  }
74 
76  // Loop over all photon collections
77  for (auto currentSystematic : *m_config->systSgKeyMapPhotons()) {
78  const xAOD::PhotonContainer* photons(nullptr);
79 
80  top::check(evtStore()->retrieve(photons, currentSystematic.second),
81  "Failed to retrieve photons");
82 
83  // Loop over all photons in each collection
84  for (auto photonPtr : *photons) {
85  // Does the photon pass object selection?
86  bool passSelection(false);
87  if (photonPtr->isAvailable<char>("passPreORSelection")) {
88  if (photonPtr->auxdataConst<char>("passPreORSelection") == 1) {
89  passSelection = true;
90  }
91  }
92  if (photonPtr->isAvailable<char>("passPreORSelectionLoose")) {
93  if (photonPtr->auxdataConst<char>("passPreORSelectionLoose") == 1) {
94  passSelection = true;
95  }
96  }
97 
98  if (!passSelection) continue;
99 
100  top::check(m_photonEffSF->applySystematicVariation(m_systNominal),
101  "Failed to set photon efficiency SF tool to nominal");
102 
103  double effSF(1.);
104  top::check(m_photonEffSF->getEfficiencyScaleFactor(*photonPtr, effSF),
105  "Failed to get nominal photon SF");
106 
107  static SG::AuxElement::Decorator<float> ph_effID_dec("EFF_ID_SF");
108  ph_effID_dec(*photonPtr) = effSF;
109 
110  double isoSF(1.), isoLooseSF(1.);
111  if (m_photonIsoSF_exists) {
112  top::check(m_photonIsoSF->applySystematicVariation(m_systNominal),
113  "Failed to set photon efficiency SF tool to nominal");
114  top::check(m_photonIsoSF->getEfficiencyScaleFactor(*photonPtr, isoSF),
115  "Failed to get nominal photon SF");
116  static SG::AuxElement::Decorator<float> ph_isoID_dec(m_decor_isoSF);
117  ph_isoID_dec(*photonPtr) = isoSF;
118  }
120  top::check(m_photonLooseIsoSF->applySystematicVariation(m_systNominal),
121  "Failed to set photon efficiency SF tool to nominal");
122  top::check(m_photonLooseIsoSF->getEfficiencyScaleFactor(*photonPtr, isoLooseSF),
123  "Failed to get nominal photon SF");
125  ph_isoID_dec(*photonPtr) = isoLooseSF;
126  }
127 
128  // For nominal calibration, vary the SF systematics
129  if (currentSystematic.first != m_config->nominalHashValue()) continue;
130 
131  double effSF_up(1.), effSF_down(1.);
132  top::check(m_photonEffSF->applySystematicVariation(m_systEffIDUp),
133  "Failed to set photon efficiency SF tool to"
134  " ID up systematic");
135  top::check(m_photonEffSF->getEfficiencyScaleFactor(*photonPtr, effSF_up),
136  "Failed to get photon efficiency SF:"
137  " systematic up ID SF");
138 
139  top::check(m_photonEffSF->applySystematicVariation(m_systEffIDDown),
140  "Failed to set photon efficiency SF tool to"
141  " ID up systematic");
142  top::check(m_photonEffSF->getEfficiencyScaleFactor(*photonPtr, effSF_down),
143  "Failed to get photon efficiency SF:"
144  " systematic down ID SF");
145 
146  static SG::AuxElement::Decorator<float> ph_effIDUp_dec("EFF_ID_SF_UP");
147  static SG::AuxElement::Decorator<float> ph_effIDDown_dec("EFF_ID_SF_DOWN");
148  ph_effIDUp_dec(*photonPtr) = effSF_up;
149  ph_effIDDown_dec(*photonPtr) = effSF_down;
150 
151  // isolation systematic uncertainties
152  double effIsoSF_up(1.), effIsoSF_down(1.);
153  double effLooseIsoSF_up(1.), effLooseIsoSF_down(1.);
154  if (m_photonIsoSF_exists) {
155  top::check(m_photonIsoSF->applySystematicVariation(m_systEffIsoUp),
156  "Failed to set photon efficiency SF tool to"
157  " isolation up systematic");
158  top::check(m_photonIsoSF->getEfficiencyScaleFactor(*photonPtr, effIsoSF_up),
159  "Failed to get photon efficiency SF:"
160  " up systematic isolation");
161  top::check(m_photonIsoSF->applySystematicVariation(m_systEffIsoDown),
162  "Failed to set photon efficiency SF tool to"
163  " isolation down systematic");
164  top::check(m_photonIsoSF->getEfficiencyScaleFactor(*photonPtr, effIsoSF_down),
165  "Failed to get photon efficiency SF:"
166  " down systematic isolation");
167  }
169  top::check(m_photonLooseIsoSF->applySystematicVariation(m_systEffIsoUp),
170  "Failed to set photon efficiency SF tool to"
171  " isolation up systematic");
172  top::check(m_photonLooseIsoSF->getEfficiencyScaleFactor(*photonPtr, effLooseIsoSF_up),
173  "Failed to get photon efficiency SF:"
174  " up systematic isolation");
175  top::check(m_photonLooseIsoSF->applySystematicVariation(m_systEffIsoDown),
176  "Failed to set photon efficiency SF tool to"
177  " isolation down systematic");
178  top::check(m_photonLooseIsoSF->getEfficiencyScaleFactor(*photonPtr, effLooseIsoSF_down),
179  "Failed to get photon efficiency SF:"
180  " down systematic isolation");
181  }
182 
183  static SG::AuxElement::Decorator<float> ph_effIsoUp_dec(m_decor_isoSF + "_UP");
184  static SG::AuxElement::Decorator<float> ph_effIsoDown_dec(m_decor_isoSF + "_DOWN");
185  static SG::AuxElement::Decorator<float> ph_effLooseIsoUp_dec(m_decor_isoSF_loose + "_UP");
186  static SG::AuxElement::Decorator<float> ph_effLooseIsoDown_dec(m_decor_isoSF_loose + "_DOWN");
187 
188  ph_effIsoUp_dec(*photonPtr) = effIsoSF_up;
189  ph_effIsoDown_dec(*photonPtr) = effIsoSF_down;
190  ph_effLooseIsoUp_dec(*photonPtr) = effLooseIsoSF_up;
191  ph_effLooseIsoDown_dec(*photonPtr) = effLooseIsoSF_down;
192  }
193  }
194  return StatusCode::SUCCESS;
195  }
196 } // namespace top
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
top::PhotonScaleFactorCalculator::m_photonEffSF
ToolHandle< IAsgPhotonEfficiencyCorrectionTool > m_photonEffSF
Definition: PhotonScaleFactorCalculator.h:59
top::PhotonScaleFactorCalculator::m_photonIsoSF
ToolHandle< IAsgPhotonEfficiencyCorrectionTool > m_photonIsoSF
Definition: PhotonScaleFactorCalculator.h:60
top::PhotonScaleFactorCalculator::execute
StatusCode execute()
Definition: PhotonScaleFactorCalculator.cxx:75
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
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::PhotonScaleFactorCalculator::m_systEffIDDown
CP::SystematicSet m_systEffIDDown
Definition: PhotonScaleFactorCalculator.h:55
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
top::PhotonScaleFactorCalculator::m_systEffIsoUp
CP::SystematicSet m_systEffIsoUp
Definition: PhotonScaleFactorCalculator.h:56
asg
Definition: DataHandleTestTool.h:28
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
top::PhotonScaleFactorCalculator::m_photonLooseIsoSF_exists
bool m_photonLooseIsoSF_exists
Definition: PhotonScaleFactorCalculator.h:64
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
top::PhotonScaleFactorCalculator::m_decor_isoSF_loose
std::string m_decor_isoSF_loose
Definition: PhotonScaleFactorCalculator.h:67
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
top::PhotonScaleFactorCalculator::PhotonScaleFactorCalculator
PhotonScaleFactorCalculator(const std::string &name)
Definition: PhotonScaleFactorCalculator.cxx:16
lumiFormat.i
int i
Definition: lumiFormat.py:92
top::PhotonScaleFactorCalculator::m_systEffIsoDown
CP::SystematicSet m_systEffIsoDown
Definition: PhotonScaleFactorCalculator.h:57
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
top::PhotonScaleFactorCalculator::m_photonIsoSF_exists
bool m_photonIsoSF_exists
Definition: PhotonScaleFactorCalculator.h:63
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
top::PhotonScaleFactorCalculator::m_systNominal
CP::SystematicSet m_systNominal
Definition: PhotonScaleFactorCalculator.h:53
TopConfig.h
PhotonScaleFactorCalculator.h
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:16
top::PhotonScaleFactorCalculator::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: PhotonScaleFactorCalculator.cxx:34
top::PhotonScaleFactorCalculator::m_decor_isoSF
std::string m_decor_isoSF
Definition: PhotonScaleFactorCalculator.h:66
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
top::PhotonScaleFactorCalculator::m_config
std::shared_ptr< top::TopConfig > m_config
Definition: PhotonScaleFactorCalculator.h:51
PhotonContainer.h
top::PhotonScaleFactorCalculator::m_photonLooseIsoSF
ToolHandle< IAsgPhotonEfficiencyCorrectionTool > m_photonLooseIsoSF
Definition: PhotonScaleFactorCalculator.h:61
top::PhotonScaleFactorCalculator::m_systEffIDUp
CP::SystematicSet m_systEffIDUp
Definition: PhotonScaleFactorCalculator.h:54