ATLAS Offline Software
Loading...
Searching...
No Matches
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
6namespace CP {
7
9 return mu(etaAcc);
10 }
12 return mu(ptAcc);
13 }
15 return mu(ptAcc) / 1.e3;
16 }
18 return std::abs(mu(etaAcc));
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(ptAcc) > 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(ptAcc)/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(ptAcc) > 200.e3 && (eloss_syst < abs_error || abs_error == 0 || mu(ptAcc) > 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) {
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 //###############################################################
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(ptAcc) <= 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(ptAcc) / 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) :
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(ptAcc) >= 100.e3) {
182 CorrectionCode cc = findAppropiatePolynomial(mu.getXAODObject(), Poly);
183 if (cc != CorrectionCode::Ok) {
184 return cc;
185 }
186 RelHighPtSys = Poly->Eval((this->*m_uncertVar)(mu.getXAODObject()));
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 }
212
214 if (!m_polySelVar) {
215 Error("BadMuonVetoSystHandler()", "Something went wrong with the initialization");
217 }
218 uint8_t nprecisionLayers=0;
219 if (!mu.summaryValue(nprecisionLayers, xAOD::SummaryType::numberOfPrecisionLayers)){
220 Error("BadMuonSysVetoHandler()", "Precisionlayers unkown");
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 */
std::map< Ranges, std::unique_ptr< TF1 > > m_syst2Stations
void fillMap(TDirectory *InDir, std::map< Ranges, std::unique_ptr< TF1 > > &systPolynomials)
bool initialize() override
Initialize method to load the inputs and check that everything will work as expected.
CP::CorrectionCode findAppropiatePolynomial(const xAOD::Muon &mu, TF1 *&Poly) const
BadMuonVetoSystHandler(TDirectory *InDir_3Stations, TDirectory *InDir_2Stations=nullptr)
std::map< Ranges, std::unique_ptr< TF1 > > m_syst3Stations
std::pair< float, float > Ranges
void SetSystematicWeight(float SystWeight) override
Set's the absolute scaling of the systematic.
CorrectionCode GetKineDependent(columnar::MuonId mu, float &Eff) const override
Add an additional uncertainty to the muon depending on its kinematics.
std::string getNextProperty(std::string &sstr) const
Return value from object correction CP tools.
@ Error
Some error happened during the object correction.
@ OutOfValidityRange
Input object is out of validity range.
@ Ok
The correction was done successfully.
float(IKinematicSystHandler::* KinVariable)(columnar::MuonId mu) const
Typedef to prepare function pointers to the muon.
float PtGeV(columnar::MuonId mu) const
float Pt(columnar::MuonId mu) const
columnar::MuonAccessor< float > ptAcc
columnar::MuonAccessor< float > etaAcc
KinVariable GetMuonVariableToUse(const std::string &name)
float AbsEta(columnar::MuonId mu) const
float Eta(columnar::MuonId mu) const
CorrectionCode GetKineDependent(columnar::MuonId mu, float &Eff) const override
Add an additional uncertainty to the muon depending on its kinematics.
std::unique_ptr< HistHandler > m_Handler
void SetSystematicWeight(float SystWeight) override
Set's the absolute scaling of the systematic.
PrimodialPtSystematic(std::unique_ptr< HistHandler > HistHandler)
bool initialize() override
Initialize method to load the inputs and check that everything will work as expected.
PtKinematicSystHandler(std::unique_ptr< HistHandler > pt_flatnesss, std::unique_ptr< HistHandler > energy_loss)
Constructor having two histhandler objects inside. The.
void SetSystematicWeight(float syst_weight) override
Set's the absolute scaling of the systematic.
std::unique_ptr< HistHandler > m_flatness
CorrectionCode GetKineDependent(columnar::MuonId mu, float &eff) const override
Add an additional uncertainty to the muon depending on its kinematics.
std::unique_ptr< HistHandler > m_loss
bool initialize() override
Initialize method to load the inputs and check that everything will work as expected.
TTVAClosureSysHandler(std::unique_ptr< HistHandler > HistHandler)
bool initialize() override
Initialize method to load the inputs and check that everything will work as expected.
CorrectionCode GetKineDependent(columnar::MuonId mu, float &Eff) const override
Add an additional uncertainty to the muon depending on its kinematics.
void SetSystematicWeight(float SystWeight) override
Set's the absolute scaling of the systematic.
std::unique_ptr< HistHandler > m_Handler
Support class for PropertyMgr.
Definition Property.h:23
Select isolated Photons, Electrons and Muons.
AthROOTErrorHandlerSvc: Replaces ROOT's standard error handler in order to detect Problematic ROOT is...
ObjectId< ContainerId::muon > MuonId
Definition MuonDef.h:25
Muon_v1 Muon
Reference the current persistent version:
@ numberOfPrecisionLayers
layers with at least 3 hits [unit8_t].