ATLAS Offline Software
Loading...
Searching...
No Matches
ValidityHistogram.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include <math.h>
9
10namespace jet
11{
12
13
15// //
16// Validity information helpers //
17// //
19
21{
22 public:
23 InfoHelper(const ValidityHistogram& validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
24 : m_validHist(validHist), m_energyScale(energyScale), m_massDef(massDef) {}
25 virtual ~InfoHelper() = default;
26 virtual InfoHelper* clone() const = 0;
27
28 virtual bool isValid(const xAOD::Jet& jet) const = 0;
29
30 protected:
32 const float m_energyScale;
34
35 double getAbsMass(const xAOD::Jet& jet) const;
36 double getMassOverPt(const xAOD::Jet& jet) const;
37 double getMassOverE(const xAOD::Jet& jet) const;
38};
39
41{
42 public:
43 InfoHelperPt(const ValidityHistogram& validHist, const float energyScale)
44 : InfoHelper(validHist,energyScale,CompMassDef::UNKNOWN) {}
45 virtual InfoHelperPt* clone() const { return new InfoHelperPt(*this); }
46
47 virtual bool isValid(const xAOD::Jet& jet) const
48 {
49 return m_validHist.getValue(jet.pt()*m_energyScale);
50 }
51};
52
54{
55 public:
56 InfoHelperPtEta(const ValidityHistogram& validHist, const float energyScale)
57 : InfoHelper(validHist,energyScale,CompMassDef::UNKNOWN) {}
58 virtual InfoHelperPtEta* clone() const { return new InfoHelperPtEta(*this); }
59
60 virtual bool isValid(const xAOD::Jet& jet) const
61 {
62 return m_validHist.getValue(jet.pt()*m_energyScale,jet.eta());
63 }
64};
65
67{
68 public:
69 InfoHelperPtAbsEta(const ValidityHistogram& validHist, const float energyScale)
70 : InfoHelper(validHist,energyScale,CompMassDef::UNKNOWN) {}
71 virtual InfoHelperPtAbsEta* clone() const { return new InfoHelperPtAbsEta(*this); }
72
73 virtual bool isValid(const xAOD::Jet& jet) const
74 {
75 return m_validHist.getValue(jet.pt()*m_energyScale,fabs(jet.eta()));
76 }
77};
78
80{
81 public:
82 InfoHelperPtAbsMass(const ValidityHistogram& validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
83 : InfoHelper(validHist,energyScale,massDef) {}
84 virtual InfoHelperPtAbsMass* clone() const { return new InfoHelperPtAbsMass(*this); }
85
86 virtual bool isValid(const xAOD::Jet& jet) const
87 {
88 return m_validHist.getValue(jet.pt()*m_energyScale,getAbsMass(jet));
89 }
90};
91
93{
94 public:
95 InfoHelperPtMass(const ValidityHistogram& validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
96 : InfoHelper(validHist,energyScale,massDef) {}
97 virtual InfoHelperPtMass* clone() const { return new InfoHelperPtMass(*this); }
98
99 virtual bool isValid(const xAOD::Jet& jet) const
100 {
101 return m_validHist.getValue(jet.pt()*m_energyScale,getMassOverPt(jet));
102 }
103};
104
106{
107 public:
108 InfoHelperPtMassEta(const ValidityHistogram& validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
109 : InfoHelper(validHist,energyScale,massDef) {}
110 virtual InfoHelperPtMassEta* clone() const { return new InfoHelperPtMassEta(*this); }
111
112 virtual bool isValid(const xAOD::Jet& jet) const
113 {
114 return m_validHist.getValue(jet.pt()*m_energyScale,getMassOverPt(jet),jet.eta());
115 }
116};
117
119{
120 public:
121 InfoHelperPtMassAbsEta(const ValidityHistogram& validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
122 : InfoHelper(validHist,energyScale,massDef) {}
123 virtual InfoHelperPtMassAbsEta* clone() const { return new InfoHelperPtMassAbsEta(*this); }
124
125 virtual bool isValid(const xAOD::Jet& jet) const
126 {
127 return m_validHist.getValue(jet.pt()*m_energyScale,getMassOverPt(jet),fabs(jet.eta()));
128 }
129};
130
132{
133 public:
134 InfoHelperPtAbsMassEta(const ValidityHistogram& validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
135 : InfoHelper(validHist,energyScale,massDef) {}
136 virtual InfoHelperPtAbsMassEta* clone() const { return new InfoHelperPtAbsMassEta(*this); }
137
138 virtual bool isValid(const xAOD::Jet& jet) const
139 {
140 return m_validHist.getValue(jet.pt()*m_energyScale,getAbsMass(jet)*m_energyScale,jet.eta());
141 }
142};
143
145{
146 public:
147 InfoHelperPtAbsMassAbsEta(const ValidityHistogram& validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
148 : InfoHelper(validHist,energyScale,massDef) {}
149 virtual InfoHelperPtAbsMassAbsEta* clone() const { return new InfoHelperPtAbsMassAbsEta(*this); }
150
151 virtual bool isValid(const xAOD::Jet& jet) const
152 {
153 return m_validHist.getValue(jet.pt()*m_energyScale,getAbsMass(jet)*m_energyScale,fabs(jet.eta()));
154 }
155};
156
158{
159 public:
160 InfoHelpereLOGmOe(const ValidityHistogram& validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
161 : InfoHelper(validHist,energyScale,massDef) {}
162 virtual InfoHelpereLOGmOe* clone() const { return new InfoHelpereLOGmOe(*this); }
163
164 virtual bool isValid(const xAOD::Jet& jet) const
165 {
166 return m_validHist.getValue(jet.e()*m_energyScale,log(getMassOverE(jet)));
167 }
168};
169
171{
172 public:
173 InfoHelpereLOGmOeEta(const ValidityHistogram& validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
174 : InfoHelper(validHist,energyScale,massDef) {}
175 virtual InfoHelpereLOGmOeEta* clone() const { return new InfoHelpereLOGmOeEta(*this); }
176
177 virtual bool isValid(const xAOD::Jet& jet) const
178 {
179 return m_validHist.getValue(jet.e()*m_energyScale,log(getMassOverE(jet)),jet.eta());
180 }
181};
182
184{
185 public:
186 InfoHelpereLOGmOeAbsEta(const ValidityHistogram& validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
187 : InfoHelper(validHist,energyScale,massDef) {}
188 virtual InfoHelpereLOGmOeAbsEta* clone() const { return new InfoHelpereLOGmOeAbsEta(*this); }
189
190 virtual bool isValid(const xAOD::Jet& jet) const
191 {
192 return m_validHist.getValue(jet.e()*m_energyScale,log(getMassOverE(jet)),fabs(jet.eta()));
193 }
194};
195
196
198{
199 // Check for the simple case (where we want the default four-vector itself)
201 return jet.m();
202
203 // Not the simple case, check for the specified four-vector instead and return it if it is available
205 if (scale.isAvailable(jet))
206 return scale(jet).M();
207
208 // Fall-back on the TA moment as a float if applicable (legacy support)
209 SG::AuxElement::ConstAccessor<float> scaleTAMoment("JetTrackAssistedMassCalibrated");
210 if (m_massDef == CompMassDef::TAMass && scaleTAMoment.isAvailable(jet))
211 return scaleTAMoment(jet);
212
213 // Fall-back on the calo mass as the 4-vec if applicable (legacy support)
215 return jet.m();
216
217 // Specified scale is not available, error
218 return JESUNC_ERROR_CODE;
219}
220
222{
223 // Check for the simple case (where we want the default four-vector itself)
225 return jet.m()/jet.pt();
226
227 // Not the simple case, check for the specified four-vector instead and return it if it is available
229 if (scale.isAvailable(jet))
230 return scale(jet).M()/scale(jet).Pt();
231
232 // Fall-back on the TA moment as a float if applicable (legacy support)
233 SG::AuxElement::ConstAccessor<float> scaleTAMoment("JetTrackAssistedMassCalibrated");
234 if (m_massDef == CompMassDef::TAMass && scaleTAMoment.isAvailable(jet))
235 return scaleTAMoment(jet)/jet.pt();
236
237 // Fall-back on the calo mass as the 4-vec if applicable (legacy support)
239 return jet.m()/jet.pt();
240
241 // Specified scale is not available, error
242 return JESUNC_ERROR_CODE;
243
244}
245
247{
248 // Check for the simple case (where we want the default four-vector itself)
250 return jet.m()/jet.e();
251
252 // Not the simple case, check for the specified four-vector instead and return it if it is available
254 if (scale.isAvailable(jet))
255 return scale(jet).M()/scale(jet).E();
256
257 // Fall-back on the TA moment as a float if applicable (legacy support)
258 SG::AuxElement::ConstAccessor<float> scaleTAMoment("JetTrackAssistedMassCalibrated");
259 if (m_massDef == CompMassDef::TAMass && scaleTAMoment.isAvailable(jet))
260 return scaleTAMoment(jet)/jet.e();
261
262 // Fall-back on the calo mass as the 4-vec if applicable (legacy support)
264 return jet.m()/jet.e();
265
266 // Specified scale is not available, error
267 return JESUNC_ERROR_CODE;
268
269}
270
271
272
273
275// //
276// Constructor/destructor/initialization //
277// //
279
280ValidityHistogram::ValidityHistogram(const std::string& histName, const CompParametrization::TypeEnum parametrization, const float energyScale, const CompMassDef::TypeEnum massDef)
282 , m_isInit(false)
283 , m_param(parametrization)
284 , m_energyScale(energyScale)
285 , m_massDef(massDef)
286 , m_helper(nullptr)
287{
288 ATH_MSG_DEBUG(Form("Creating ValidityHistogram named %s",getName().Data()));
289}
290
291ValidityHistogram::ValidityHistogram(const TString& histName, const CompParametrization::TypeEnum parametrization, const float energyScale, const CompMassDef::TypeEnum massDef)
292 : ValidityHistogram(std::string(histName.Data()),parametrization,energyScale,massDef)
293{ }
294
295ValidityHistogram::ValidityHistogram(const char* histName, const CompParametrization::TypeEnum parametrization, const float energyScale, const CompMassDef::TypeEnum massDef)
296 : ValidityHistogram(std::string(histName),parametrization,energyScale,massDef)
297{ }
298
300 : UncertaintyHistogram(toCopy)
301 , m_isInit(toCopy.m_isInit)
302 , m_param(toCopy.m_param)
304 , m_massDef(toCopy.m_massDef)
305 , m_helper(nullptr)
306{
307 ATH_MSG_DEBUG("Creating copy of ValidityHistogram named " << getName().Data());
308 m_helper = toCopy.m_helper->clone();
309}
310
315
316StatusCode ValidityHistogram::initialize(TFile* histFile)
317{
318 // Ensure it wasn't already initialized
319 if (m_isInit)
320 {
321 ATH_MSG_ERROR("ValidityHistogram was already initialized: " << getName().Data());
322 return StatusCode::FAILURE;
323 }
324
325 // Initialize the base class
326 if (UncertaintyHistogram::initialize(histFile).isFailure())
327 return StatusCode::FAILURE;
328
329 // Ensure that the parametrization is sensible
330 switch (m_param)
331 {
333 ATH_MSG_ERROR("ValidityHistogram parametrization is UNKNOWN: " << getName().Data());
334 return StatusCode::FAILURE;
336 //1D
337 if (getNumDim() != 1)
338 {
339 ATH_MSG_ERROR("ValidityHistogram is " << getNumDim() << "D, but parametrization is 1D: " << CompParametrization::enumToString(m_param).Data());
340 return StatusCode::FAILURE;
341 }
342 break;
349 // 2D
350 if (getNumDim() != 2)
351 {
352 ATH_MSG_ERROR("ValidityHistogram is " << getNumDim() << "D, but parametrization is 2D: " << CompParametrization::enumToString(m_param).Data());
353 return StatusCode::FAILURE;
354 }
355 break;
362 // 3D
363 if (getNumDim() != 3)
364 {
365 ATH_MSG_ERROR("ValidityHistogram is " << getNumDim() << "D, but parametrization is 3D: " << CompParametrization::enumToString(m_param).Data());
366 return StatusCode::FAILURE;
367 }
368 break;
369 default:
370 ATH_MSG_ERROR("ValidityHistogram named \"" << getName().Data() << "\" had an unpexted parametrization: " << CompParametrization::enumToString(m_param).Data());
371 return StatusCode::FAILURE;
372 }
373
374 // Figure out which function helper we want once, right now, so we don't need to switch every time
375 switch (m_param)
376 {
379 break;
382 break;
385 break;
388 break;
391 break;
394 break;
397 break;
400 break;
403 break;
406 break;
409 break;
412 break;
413 default:
414 ATH_MSG_ERROR("ValidityHistogram named \"" << getName().Data() << "\" was not prepared to handle the provided parametrization: " << CompParametrization::enumToString(m_param).Data());
415 return StatusCode::FAILURE;
416 }
417
418 // Done
419 m_isInit = true;
420 return StatusCode::SUCCESS;
421}
422
423
425// //
426// Validity information access //
427// //
429
430
432{
433 if (!m_isInit)
434 {
435 ATH_MSG_ERROR("You must initialize the ValidityHistogram before calling getIsValid: " << getName().Data());
436 return false;
437 }
438
439 const double validity = m_helper->isValid(jet);
440 if (validity < 1.e-5 && validity > -1.e-5)
441 return false;
442 if (validity < 1+1.e-5 && validity > 1-1.e-5)
443 return true;
444
445 // Validity is neither 0 nor 1
446 ATH_MSG_ERROR("ValidityHistogram \"" << getName().Data() << "\" out of expected range: " << validity);
447 return false;
448}
449
450
451} // end jet namespace
452
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
@ Data
Definition BaseObject.h:11
@ None
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
virtual bool isValid(const xAOD::Jet &jet) const
virtual InfoHelperPtAbsEta * clone() const
InfoHelperPtAbsEta(const ValidityHistogram &validHist, const float energyScale)
InfoHelperPtAbsMassAbsEta(const ValidityHistogram &validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
virtual bool isValid(const xAOD::Jet &jet) const
virtual InfoHelperPtAbsMassAbsEta * clone() const
virtual bool isValid(const xAOD::Jet &jet) const
virtual InfoHelperPtAbsMassEta * clone() const
InfoHelperPtAbsMassEta(const ValidityHistogram &validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
InfoHelperPtAbsMass(const ValidityHistogram &validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
virtual InfoHelperPtAbsMass * clone() const
virtual bool isValid(const xAOD::Jet &jet) const
virtual bool isValid(const xAOD::Jet &jet) const
virtual InfoHelperPtEta * clone() const
InfoHelperPtEta(const ValidityHistogram &validHist, const float energyScale)
virtual bool isValid(const xAOD::Jet &jet) const
InfoHelperPtMassAbsEta(const ValidityHistogram &validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
virtual InfoHelperPtMassAbsEta * clone() const
virtual bool isValid(const xAOD::Jet &jet) const
InfoHelperPtMassEta(const ValidityHistogram &validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
virtual InfoHelperPtMassEta * clone() const
virtual bool isValid(const xAOD::Jet &jet) const
virtual InfoHelperPtMass * clone() const
InfoHelperPtMass(const ValidityHistogram &validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
virtual InfoHelperPt * clone() const
InfoHelperPt(const ValidityHistogram &validHist, const float energyScale)
virtual bool isValid(const xAOD::Jet &jet) const
virtual ~InfoHelper()=default
const float m_energyScale
virtual bool isValid(const xAOD::Jet &jet) const =0
virtual InfoHelper * clone() const =0
double getAbsMass(const xAOD::Jet &jet) const
double getMassOverPt(const xAOD::Jet &jet) const
const ValidityHistogram & m_validHist
const CompMassDef::TypeEnum m_massDef
InfoHelper(const ValidityHistogram &validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
double getMassOverE(const xAOD::Jet &jet) const
InfoHelpereLOGmOeAbsEta(const ValidityHistogram &validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
virtual bool isValid(const xAOD::Jet &jet) const
virtual InfoHelpereLOGmOeAbsEta * clone() const
InfoHelpereLOGmOeEta(const ValidityHistogram &validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
virtual bool isValid(const xAOD::Jet &jet) const
virtual InfoHelpereLOGmOeEta * clone() const
InfoHelpereLOGmOe(const ValidityHistogram &validHist, const float energyScale, const CompMassDef::TypeEnum massDef)
virtual bool isValid(const xAOD::Jet &jet) const
virtual InfoHelpereLOGmOe * clone() const
JetFourMomAccessor is an extension of JetAttributeAccessor::AccessorWrapper<xAOD::JetFourMom_t> Acces...
virtual StatusCode initialize(TFile *histFile)
const TString & getName() const
UncertaintyHistogram(const std::string &histName, const Interpolate::TypeEnum interpolate)
bool getValidity(const xAOD::Jet &jet) const
const CompMassDef::TypeEnum m_massDef
ValidityHistogram(const std::string &histName, const CompParametrization::TypeEnum parametrization, const float energyScale, const CompMassDef::TypeEnum massDef)
virtual StatusCode initialize(TFile *histFile)
const CompParametrization::TypeEnum m_param
STL class.
TString getJetScaleString(const TypeEnum type)
TString enumToString(const TypeEnum type)
STL namespace.
Jet_v1 Jet
Definition of the current "jet version".