ATLAS Offline Software
KinematicSystHandler.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 namespace CP {
7 
8  float IKinematicSystHandler::Eta(const xAOD::Muon &mu) const {
9  return mu.eta();
10  }
11  float IKinematicSystHandler::Pt(const xAOD::Muon &mu) const {
12  return mu.pt();
13  }
15  return mu.pt() / 1.e3;
16  }
18  return std::abs(mu.eta());
19  }
20 
22  if (name == "pt") return &IKinematicSystHandler::Pt;
23  if (name == "ptGeV") return &IKinematicSystHandler::PtGeV;
24  if (name == "eta") return &IKinematicSystHandler::Eta;
25  if (name == "AbsEta") return &IKinematicSystHandler::AbsEta;
26  return nullptr;
27  }
28 
29  //###############################################################
30  // PtKinematicSystHandler
31  //###############################################################
32  PtKinematicSystHandler::PtKinematicSystHandler(std::unique_ptr<HistHandler> pt_flatnesss, std::unique_ptr<HistHandler> energy_loss):
33  m_flatness(),
34  m_loss(),
35  m_SystWeight(0){
36  m_flatness.swap(pt_flatnesss);
37  m_loss.swap(energy_loss);
38  }
39 
41  int bin_flat(-1), bin_loss(-1);
42  float syst = 0;
43  CorrectionCode cc_flat = m_flatness->FindBin(mu, bin_flat);
44  CorrectionCode cc_eloss = mu.pt() > 200.e3 ? m_loss->FindBin(mu, bin_loss) : cc_flat;
45 
46  float eloss_syst = bin_loss < 1 ? 1.e6 : std::abs( m_loss->GetBinContent(bin_loss) * mu.pt()/1.0e6);
48  if (cc_flat != CorrectionCode::Ok){
50  if (cc_eloss == CorrectionCode::Ok){
51  syst = eloss_syst;
52  eff *= 1 + m_SystWeight * std::abs(syst);
53  return cc_eloss;
54  } else return cc_flat;
55  } else {
56  // The eloss -systematic is valid and smaller than the error from the flatness
57  float abs_error = std::abs( m_flatness->GetBinError(bin_flat));
58  if (cc_eloss == CorrectionCode::Ok && mu.pt() > 200.e3 && (eloss_syst < abs_error || abs_error == 0 || mu.pt() > 500.e3)){
59  syst = eloss_syst;
60  // The flatness of the scale-factor is still more precise than the eloss. Assign this as an extra syst
61  } else {
62  syst = m_flatness->GetBinContent(bin_flat);
63  }
64  }
65  eff *= 1 + m_SystWeight * std::abs(syst);
66  return cc_flat;
67  }
68 
70  m_SystWeight = syst_weight;
71  }
72 
74  return m_flatness.get() != nullptr && m_loss.get() != nullptr;
75  }
76  //###############################################################
77  // TTVAClosureSysHandler
78  //###############################################################
80  m_Handler(),
81  m_SystWeight(0) {
82  m_Handler.swap(HistHandler);
83  }
84  void TTVAClosureSysHandler::SetSystematicWeight( float SystWeight){m_SystWeight = SystWeight;}
85  bool TTVAClosureSysHandler::initialize() { return m_Handler.get() != nullptr; }
87  int binsys = -1;
88  CorrectionCode cc = m_Handler->FindBin(mu, binsys);
89  if (cc != CorrectionCode::Ok) {
90  return cc;
91  }
92  Eff *= (1. + m_SystWeight * std::abs(m_Handler->GetBinContent(binsys)));
93  return CorrectionCode::Ok;
94  }
95  //###############################################################
96  // PrimodialPtSystematic
97  //###############################################################
98  PrimodialPtSystematic::PrimodialPtSystematic(std::unique_ptr<HistHandler> Handler) :
99  m_Handler(),
100  m_SystWeight(0) {
101  m_Handler.swap(Handler);
102  }
104  // Account for catastrophic energy loss for very high
105  // pt's
106  if (mu.pt() <= 200.e3) return CorrectionCode::Ok;
107 
108  int binsys = -1;
109  CorrectionCode cc = m_Handler->FindBin(mu, binsys);
110  if (cc != CorrectionCode::Ok) {
111  return cc;
112  }
113  Eff *= (1. + m_SystWeight * std::abs(m_Handler->GetBinContent(binsys)) * mu.pt() / 1.0e6);
114  return CorrectionCode::Ok;
115  }
117  m_SystWeight = SystWeight;
118  }
120  return m_Handler.get() != nullptr;
121  }
122  //###############################################################
123  // BadMuonVetoSystHandler
124  //###############################################################
125  BadMuonVetoSystHandler::BadMuonVetoSystHandler(TDirectory* InDir_3Stations, TDirectory* InDir_2Stations) :
126  m_syst3Stations(),
127  m_syst2Stations(),
128  m_uncertVar(nullptr),
129  m_polySelVar(nullptr),
130  m_SystWeight(0.) {
131  fillMap(InDir_3Stations, m_syst3Stations);
132  if (InDir_2Stations && InDir_2Stations!= InDir_3Stations) {
133  fillMap(InDir_2Stations,m_syst2Stations);
134  }
135 
136  }
137  void BadMuonVetoSystHandler::fillMap(TDirectory* InDir, std::map<Ranges, std::unique_ptr<TF1>>& systPolynomials){
138  if (!InDir) {
139  Error("BadMuonSysVetoHandler()", "No TDirectory is given");
140  return;
141  }
142  TIter next(InDir->GetListOfKeys());
143  while (TObject* obj = next()) {
144  std::string ObjName = obj->GetName();
145  float lowRange(-1.e20), highRange(1.e20);
146  if (ObjName.find("TF1") == std::string::npos) {
147  continue;
148  }
149  TF1* TF = nullptr;
150  InDir->GetObject(ObjName.c_str(), TF);
151  if (!TF) {
152  continue;
153  }
154  //Elimnate the TF1_
155  getNextProperty(ObjName);
158  else {getNextProperty(ObjName);}
160  else {getNextProperty(ObjName);}
161 
162  std::string LowRange_str = getNextProperty(ObjName);
163  std::string HighRange_str = getNextProperty(ObjName);
164  if (!LowRange_str.empty()) {
165  lowRange = atof(LowRange_str.c_str()) / std::pow(10, LowRange_str.size() -1);
166  }
167  if (!HighRange_str.empty()) {
168  highRange = atof(HighRange_str.c_str()) / std::pow(10, LowRange_str.size() -1);
169  }
170  systPolynomials.insert(std::pair<Ranges, std::unique_ptr<TF1>>(Ranges(lowRange, highRange), std::unique_ptr<TF1>(TF)));
171  }
172 
173  }
175  if (m_SystWeight == 0.) {
176  return CorrectionCode::Ok;
177  }
178  TF1* Poly = nullptr;
179  // we know that Eff=(1+relative sys error), since SF==1
180  float RelHighPtSys = 0.;
181  if (mu.pt() >= 100.e3) {
183  if (cc != CorrectionCode::Ok) {
184  return cc;
185  }
186  RelHighPtSys = Poly->Eval((this->*m_uncertVar)(mu));
187 
188  } else {
189  //Apply flat 0.5% systematic
190  RelHighPtSys = 0.005;
191  }
192  Eff = 1 + m_SystWeight * std::sqrt(std::pow(Eff - 1,2) + RelHighPtSys * RelHighPtSys);
193 
194  return CorrectionCode::Ok;
195  }
197  m_SystWeight = SystWeight;
198  }
199 
201  if (m_syst3Stations.empty()) {
202  Error("BadMuonVetoSystHandler::initialize()", "No polynomials");
203  return false;
204  }
205  if (!m_uncertVar || !m_polySelVar) {
206  return false;
207  }
208  return true;
209  }
211  }
212 
214  if (!m_polySelVar) {
215  Error("BadMuonVetoSystHandler()", "Something went wrong with the initialization");
216  return CorrectionCode::Error;
217  }
218  uint8_t nprecisionLayers=0;
219  if (!mu.summaryValue(nprecisionLayers, xAOD::SummaryType::numberOfPrecisionLayers)){
220  Error("BadMuonSysVetoHandler()", "Precisionlayers unkown");
221  return CorrectionCode::Error;
222  } else if (nprecisionLayers >= 3) {
223  for (const auto& BinnedPoly : m_syst3Stations) {
224  if (BinnedPoly.first.first <= (this->*m_polySelVar)(mu) && (this->*m_polySelVar)(mu) < BinnedPoly.first.second) {
225  Poly = BinnedPoly.second.get();
226  return CorrectionCode::Ok;
227  }
228  }
229  } else if (nprecisionLayers == 2) {
230  for (const auto& BinnedPoly : m_syst2Stations) {
231  if (BinnedPoly.first.first <= (this->*m_polySelVar)(mu) && (this->*m_polySelVar)(mu) < BinnedPoly.first.second) {
232  Poly = BinnedPoly.second.get();
233  return CorrectionCode::Ok;
234  }
235  }
236  }
238  }
239  std::string BadMuonVetoSystHandler::getNextProperty(std::string &sstr) const {
240  //Eliminate the beginning underscores
241  while (!sstr.empty() && sstr[0] == '_') {
242  sstr.erase(0, 1);
243  }
244  size_t pos = sstr.find("_");
245  std::string Property = pos != std::string::npos ? sstr.substr(0, pos) : sstr;
246  if (pos != std::string::npos) {
247  sstr = sstr.substr(Property.size() + 1, sstr.size());
248  }
249  return Property;
250  }
251 
252 } /* namespace CP */
Handler
AthROOTErrorHandlerSvc: Replaces ROOT's standard error handler in order to detect Problematic ROOT is...
Definition: AthROOTErrorHandlerSvc.cxx:9
CP::IKinematicSystHandler::GetMuonVariableToUse
KinVariable GetMuonVariableToUse(const std::string &name)
Definition: KinematicSystHandler.cxx:21
CP::BadMuonVetoSystHandler::fillMap
void fillMap(TDirectory *InDir, std::map< Ranges, std::unique_ptr< TF1 >> &systPolynomials)
Definition: KinematicSystHandler.cxx:137
CP::BadMuonVetoSystHandler::Ranges
std::pair< float, float > Ranges
Definition: KinematicSystHandler.h:121
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
CP::PrimodialPtSystematic::GetKineDependent
CorrectionCode GetKineDependent(const xAOD::Muon &mu, float &Eff) const override
Add an additional uncertainty to the muon depending on its kinematics.
Definition: KinematicSystHandler.cxx:103
CP::PrimodialPtSystematic::PrimodialPtSystematic
PrimodialPtSystematic(std::unique_ptr< HistHandler > HistHandler)
Definition: KinematicSystHandler.cxx:98
CP::IKinematicSystHandler::KinVariable
float(IKinematicSystHandler::* KinVariable)(const xAOD::Muon &mu) const
Typedef to prepare function pointers to the muon.
Definition: KinematicSystHandler.h:45
CP::BadMuonVetoSystHandler::m_syst2Stations
std::map< Ranges, std::unique_ptr< TF1 > > m_syst2Stations
Definition: KinematicSystHandler.h:129
CP::BadMuonVetoSystHandler::getNextProperty
std::string getNextProperty(std::string &sstr) const
Definition: KinematicSystHandler.cxx:239
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
CP::BadMuonVetoSystHandler::~BadMuonVetoSystHandler
virtual ~BadMuonVetoSystHandler()
Definition: KinematicSystHandler.cxx:210
CP::TTVAClosureSysHandler::m_SystWeight
float m_SystWeight
Definition: KinematicSystHandler.h:108
CP::IKinematicSystHandler::Pt
float Pt(const xAOD::Muon &mu) const
Definition: KinematicSystHandler.cxx:11
CP::PrimodialPtSystematic::initialize
bool initialize() override
Initialize method to load the inputs and check that everything will work as expected.
Definition: KinematicSystHandler.cxx:119
Property
Support class for PropertyMgr.
Definition: Property.h:23
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::PtKinematicSystHandler::SetSystematicWeight
void SetSystematicWeight(float syst_weight) override
Set's the absolute scaling of the systematic.
Definition: KinematicSystHandler.cxx:69
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
CP::BadMuonVetoSystHandler::findAppropiatePolynomial
CP::CorrectionCode findAppropiatePolynomial(const xAOD::Muon &mu, TF1 *&Poly) const
Definition: KinematicSystHandler.cxx:213
CP::CorrectionCode::OutOfValidityRange
@ OutOfValidityRange
Input object is out of validity range.
Definition: CorrectionCode.h:37
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
CP::PrimodialPtSystematic::m_SystWeight
float m_SystWeight
Definition: KinematicSystHandler.h:94
CP::TTVAClosureSysHandler::GetKineDependent
CorrectionCode GetKineDependent(const xAOD::Muon &mu, float &Eff) const override
Add an additional uncertainty to the muon depending on its kinematics.
Definition: KinematicSystHandler.cxx:86
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
CP::TTVAClosureSysHandler::m_Handler
std::unique_ptr< HistHandler > m_Handler
Definition: KinematicSystHandler.h:107
CP::HistHandler
Definition: HistHandler.h:37
CP::BadMuonVetoSystHandler::m_uncertVar
KinVariable m_uncertVar
Definition: KinematicSystHandler.h:131
CP::PtKinematicSystHandler::m_SystWeight
float m_SystWeight
Definition: KinematicSystHandler.h:78
CP::IKinematicSystHandler::AbsEta
float AbsEta(const xAOD::Muon &mu) const
Definition: KinematicSystHandler.cxx:17
CP::BadMuonVetoSystHandler::BadMuonVetoSystHandler
BadMuonVetoSystHandler(TDirectory *InDir_3Stations, TDirectory *InDir_2Stations=nullptr)
Definition: KinematicSystHandler.cxx:125
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
CP::PrimodialPtSystematic::m_Handler
std::unique_ptr< HistHandler > m_Handler
Definition: KinematicSystHandler.h:93
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CP::BadMuonVetoSystHandler::m_SystWeight
float m_SystWeight
Definition: KinematicSystHandler.h:133
KinematicSystHandler.h
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
CP::PtKinematicSystHandler::initialize
bool initialize() override
Initialize method to load the inputs and check that everything will work as expected.
Definition: KinematicSystHandler.cxx:73
CP::PtKinematicSystHandler::GetKineDependent
CorrectionCode GetKineDependent(const xAOD::Muon &mu, float &eff) const override
Add an additional uncertainty to the muon depending on its kinematics.
Definition: KinematicSystHandler.cxx:40
CP::IKinematicSystHandler::PtGeV
float PtGeV(const xAOD::Muon &mu) const
Definition: KinematicSystHandler.cxx:14
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
CP::PtKinematicSystHandler::m_flatness
std::unique_ptr< HistHandler > m_flatness
Definition: KinematicSystHandler.h:76
CP::PtKinematicSystHandler::PtKinematicSystHandler
PtKinematicSystHandler(std::unique_ptr< HistHandler > pt_flatnesss, std::unique_ptr< HistHandler > energy_loss)
Constructor having two histhandler objects inside. The.
Definition: KinematicSystHandler.cxx:32
CP::BadMuonVetoSystHandler::GetKineDependent
CorrectionCode GetKineDependent(const xAOD::Muon &mu, float &Eff) const override
Add an additional uncertainty to the muon depending on its kinematics.
Definition: KinematicSystHandler.cxx:174
CP::BadMuonVetoSystHandler::initialize
bool initialize() override
Initialize method to load the inputs and check that everything will work as expected.
Definition: KinematicSystHandler.cxx:200
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
CP::IKinematicSystHandler::Eta
float Eta(const xAOD::Muon &mu) const
Definition: KinematicSystHandler.cxx:8
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
CP::BadMuonVetoSystHandler::m_polySelVar
KinVariable m_polySelVar
Definition: KinematicSystHandler.h:132
CP::PrimodialPtSystematic::SetSystematicWeight
void SetSystematicWeight(float SystWeight) override
Set's the absolute scaling of the systematic.
Definition: KinematicSystHandler.cxx:116
CP::BadMuonVetoSystHandler::m_syst3Stations
std::map< Ranges, std::unique_ptr< TF1 > > m_syst3Stations
Definition: KinematicSystHandler.h:128
python.PyAthena.obj
obj
Definition: PyAthena.py:135
CP::TTVAClosureSysHandler::initialize
bool initialize() override
Initialize method to load the inputs and check that everything will work as expected.
Definition: KinematicSystHandler.cxx:85
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
CP::TTVAClosureSysHandler::TTVAClosureSysHandler
TTVAClosureSysHandler(std::unique_ptr< HistHandler > HistHandler)
Definition: KinematicSystHandler.cxx:79
CP::PtKinematicSystHandler::m_loss
std::unique_ptr< HistHandler > m_loss
Definition: KinematicSystHandler.h:77
CP::TTVAClosureSysHandler::SetSystematicWeight
void SetSystematicWeight(float SystWeight) override
Set's the absolute scaling of the systematic.
Definition: KinematicSystHandler.cxx:84
python.handimod.cc
int cc
Definition: handimod.py:523
CP::BadMuonVetoSystHandler::SetSystematicWeight
void SetSystematicWeight(float SystWeight) override
Set's the absolute scaling of the systematic.
Definition: KinematicSystHandler.cxx:196
xAOD::numberOfPrecisionLayers
@ numberOfPrecisionLayers
layers with at least 3 hits [unit8_t].
Definition: TrackingPrimitives.h:288