ATLAS Offline Software
Loading...
Searching...
No Matches
CalibrationDataContainer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// CalibrationDataContainer.h, (c) ATLAS Detector software
8
9#ifndef ANALYSISCALIBRATIONDATACONTAINER_H
10#define ANALYSISCALIBRATIONDATACONTAINER_H
11
12#include <vector>
13#include <map>
14#include <string>
15
16#include "TMap.h"
17#include "THashList.h"
18
19class TH1;
20
22
23namespace Analysis {
24
32
33 typedef std::pair<double, double> UncertaintyResult;
34
39
40 const unsigned int MaxCalibrationVars = 10;
41
49
50
51 class CalibrationDataContainer: public TMap {
52 public:
53 CalibrationDataContainer(const char* name = "default"); // default ctor needed for persistence
54 virtual ~CalibrationDataContainer(); // virtual dtor needed for persistence
55
62
64 kPt = 0, // calibrated jet pt
65 kEta = 1, // jet eta
66 kAbsEta = 2, // jet |eta|
67 kTagWeight = 3 // tagging output (relevant for "continuous" calibration)
68 };
69
74 std::vector<std::string> listUncertainties() const;
75
82 std::map<std::string, Analysis::UncertaintyResult>& all);
83
85 std::string getComment() const;
86
88 std::string getHadronisation() const;
89
91 std::string getExcludedUncertainties() const;
92
102 double& result,
103 TObject* obj = 0, bool extrapolate = false) = 0;
104
115 double& result) = 0;
116
123 TObject* obj = 0);
124
133 virtual CalibrationStatus getUncertainty(const std::string& unc,
135 UncertaintyResult& result, TObject* obj = 0) = 0;
136
138 void setResult(TObject* obj);
139
141 void setComment(const std::string& text);
142
144 void setHadronisation(const std::string& text);
145
149 void setExcludedUncertainties(const std::string& text);
150
152 void setUncertainty(const std::string& unc, TObject* obj);
153
159 void restrictToRange(bool restrict) { m_restrict = restrict; }
160
162 bool isRangeRestricted() const { return m_restrict; }
163
168 double getLowerBound(unsigned int vartype, bool extrapolate = false) const;
169
174 double getUpperBound(unsigned int vartype, bool extrapolate = false) const;
175
177 std::vector<std::pair<double, double> > getBounds();
178
180 std::vector<unsigned int> getVariableTypes();
181
183 static bool isNearlyEqual (double a, double b);
184
185 protected:
186
190 int typeFromString(const std::string& key) const;
191
192 // /** compute the variables to be used for the given 'uncertainty'
193 // @param x user-supplied (kinematic or other) variables
194 // @param unc given source of uncertainty (can also be the central value)
195 // @return false if the given variables are outside the parametrisation's validity range
196 // */
197 // bool computeVariables(const std::string& unc,
198 // const CalibrationDataVariables& x) const;
199
205 CalibrationStatus computeVariables(const CalibrationDataVariables& x, bool extrapolate = false);
206
208 virtual void computeVariableTypes() = 0;
209
210 std::vector<double> m_lowerBounds; // lower validity bounds
211 std::vector<double> m_upperBounds; // upper validity bounds
212 // persistency not needed for the following (relevant for histogram uncertainties only and computed automatically)
213 std::vector<double> m_lowerBoundsExtrapolated;
214 std::vector<double> m_upperBoundsExtrapolated;
215
217 TObject* m_objResult;
219
221
223 std::vector<unsigned int> m_variables;
224 // mutable std::map<std::string, std::vector<unsigned int> > m_variables; //! persistency not needed for this variable
225 // mutable std::vector<unsigned int>* m_variablesResult; //! persistency not needed for this variable
226
227 private:
228
231
232 ClassDef(CalibrationDataContainer, 1); // base class for calibration data objects
233
234 };
235
236
237
238
244
245//__________________________________________________________________________________________
246
248 public:
249 CalibrationDataHistogramContainer(const char* name = "default"); // default ctor needed for persistence
250 virtual ~CalibrationDataHistogramContainer(); // virtual dtor needed for persistence
252 TObject* obj = 0, bool extrapolate = false);
254 virtual CalibrationStatus getUncertainty(const std::string& unc, const CalibrationDataVariables& x,
255 UncertaintyResult& result, TObject* obj = 0);
256
259 bool isBinCorrelated(const std::string& unc) const;
260
263 void setUncorrelated(const std::string& unc);
264
267 void setInterpolated(bool doInterpolate);
268
270 virtual bool isInterpolated() const;
271
276 virtual int getTagWeightAxis();
277
280 virtual std::vector<double> getBinBoundaries(unsigned int vartype);
281
286 virtual int getEigenvectorReduction(unsigned int choice) const;
287
288 protected:
289
291 std::map<unsigned int, std::vector<double> > m_binBoundaries;
292
293 private:
294
297
300
302 double getInterpolatedResult(TH1* hist) const;
303
305 double getInterpolatedUncertainty(TH1* hist) const;
306
308 void checkBounds();
309
310 // /** utility for determining global bin number, subject to extrapolation constraints.
311 // @param hist pointer to histogram containing actual bin boundary information
312 // @param doExtrapolate specifies whether or not an extrapolation uncertainty is being requested
313 // */
314 // Int_t findBin(const TH1* hist, bool doExtrapolate) const;
315
317 virtual void computeVariableTypes();
318
319 ClassDef(CalibrationDataHistogramContainer, 2); // histogram based calibration data object
320 };
321
332
333//__________________________________________________________________________________________
334
336 public:
337 CalibrationDataMappedHistogramContainer(const char* name = "default"); // default ctor needed for persistence
338 virtual ~CalibrationDataMappedHistogramContainer(); // virtual dtor needed for persistence
340 TObject* obj = 0, bool extrapolate = false);
342 virtual CalibrationStatus getUncertainty(const std::string& unc, const CalibrationDataVariables& x,
343 UncertaintyResult& result, TObject* obj = 0);
344
346 virtual bool isInterpolated() const { return false; }
347
352 virtual int getTagWeightAxis();
353
355 void setMappedVariables(const std::vector<std::string>& variables);
356
358 const std::vector<std::string>& getMappedVariables() const;
359
362 virtual std::vector<double> getBinBoundaries(unsigned int vartype);
363
367 class Bin {
368 public:
369 Bin(); // default constructor (for persistency)
370 Bin(unsigned int dimension, const double* low, const double* up);
371 Bin(const Bin& other);
372 Bin& operator=(const Bin& other);
373 ~Bin();
374 // return the number of dimensions
375 unsigned int getDimension() const { return m_dimension; }
376 bool contains(const double* x) const;
377 double getUpperBound(unsigned int dim) const;
378 double getLowerBound(unsigned int dim) const;
379 private:
380 unsigned int m_dimension;
381 double* m_low; //[m_dimension]
382 double* m_up; //[m_dimension]
383 };
384
387 unsigned int addBin(const Bin& bin);
388
390 unsigned int getNMappedBins() const;
391
392 private:
393
396 std::vector<std::string> m_mapped;
397
399 unsigned int m_beginMapped;
400
402 std::vector<Bin> m_bins;
403 // cache index to the last used bin
404 unsigned int m_lastBin;
405
407 Int_t findBin();
408 Int_t findMappedBin(const double* x);
409
411 void checkBounds();
412
414 virtual void computeVariableTypes();
415
416 ClassDef(CalibrationDataMappedHistogramContainer, 1); // 'mapped' histogram based calibration data object
417 };
418
419
424
425//__________________________________________________________________________________________
426
428 public:
429 CalibrationDataFunctionContainer(const char* name = "default"); // default ctor needed for persistence
430 virtual ~CalibrationDataFunctionContainer(); // virtual dtor needed for persistence
432 TObject* obj = 0, bool /* extrapolate */ = false);
434 virtual CalibrationStatus getUncertainty(const std::string& unc, const CalibrationDataVariables& x,
435 UncertaintyResult& result, TObject* obj = 0);
436
438 inline void setLowerBound(int vartype, double bound) {m_lowerBounds[vartype] = bound; }
439
441 inline void setUpperBound(int vartype, double bound) {m_upperBounds[vartype] = bound; }
442
443 private:
444
446
448 virtual void computeVariableTypes();
449
450 ClassDef(CalibrationDataFunctionContainer, 1); // function based calibration data object
451 };
452
453} // end of namespace
454
455#endif
static Double_t a
#define x
void setResult(TObject *obj)
insert the main object for this calibration
double getLowerBound(unsigned int vartype, bool extrapolate=false) const
retrieve the lower bound of validity for the requested variable type
std::vector< double > m_upperBoundsExtrapolated
(possibly looser) lower validity bounds for extrapolation
ClassDef(CalibrationDataContainer, 1)
virtual CalibrationStatus getUncertainty(const std::string &unc, const CalibrationDataVariables &x, UncertaintyResult &result, TObject *obj=0)=0
retrieve the calibration uncertainty due to the given source.
void setExcludedUncertainties(const std::string &text)
insert the set of uncertainties that are recommended for removal from the eigenvector decomposition.
virtual CalibrationStatus getStatUncertainty(const CalibrationDataVariables &x, double &result)=0
retrieve the calibration statistical uncertainty.
CalibrationDataContainer(const char *name="default")
void restrictToRange(bool restrict)
If true, this will restrict the variables used to be within the (specified) range of validity.
bool isRangeRestricted() const
allow the user to inspect the above information
double getUpperBound(unsigned int vartype, bool extrapolate=false) const
retrieve the upper bound of validity for the requested variable type
int typeFromString(const std::string &key) const
Connection between variable names (on histogram axes etc.) and variable 'types' as used in actual eva...
CalibrationStatus getUncertainties(const CalibrationDataVariables &x, std::map< std::string, Analysis::UncertaintyResult > &all)
retrieve the list of "uncertainties" accessible to this object.
void setUncertainty(const std::string &unc, TObject *obj)
insert the relevant object for the requested source of 'uncertainty'
virtual void computeVariableTypes()=0
decode the 'uncertainty' objects' names to determine the relevant variable types
std::vector< std::pair< double, double > > getBounds()
allow the user to inspect the bounds of validity
CalibrationParametrization
The following enums are intended to contain the list of (kinematic or other) variables in terms of wh...
CalibrationStatus getSystUncertainty(const CalibrationDataVariables &x, UncertaintyResult &result, TObject *obj=0)
retrieve the calibration total systematic uncertainty
CalibrationStatus computeVariables(const CalibrationDataVariables &x, bool extrapolate=false)
compute the variables to be used for the given 'uncertainty'
void setHadronisation(const std::string &text)
insert the given text as the 'hadronisation reference' for this calibration
std::string getHadronisation() const
retrieve the 'hadronisation reference' entered for this calibration, if any
std::string getExcludedUncertainties() const
retrieve the (semicolon-separated) set of uncertainties that are recommended for removal from the eig...
static bool isNearlyEqual(double a, double b)
utility for comparison of doubles
void setComment(const std::string &text)
insert the given text as comment for this calibration
double m_vars[MaxCalibrationVars]
don't persistify
bool m_restrict
persistency not needed for this variable
std::vector< unsigned int > getVariableTypes()
utility to retrieve variable types
std::vector< std::string > listUncertainties() const
retrieve the list of "uncertainties" accessible to this object.
virtual CalibrationStatus getResult(const CalibrationDataVariables &x, double &result, TObject *obj=0, bool extrapolate=false)=0
retrieve the calibration result.
TObject * m_objResult
(possibly looser) upper validity bounds for extrapolation
std::string getComment() const
retrieve the comments entered for this calibration, if any
std::vector< unsigned int > m_variables
don't persistify
virtual CalibrationStatus getUncertainty(const std::string &unc, const CalibrationDataVariables &x, UncertaintyResult &result, TObject *obj=0)
retrieve the calibration uncertainty due to the given source.
CalibrationDataFunctionContainer(const char *name="default")
void setUpperBound(int vartype, double bound)
Set the lower bound of validity for the given variable.
void setLowerBound(int vartype, double bound)
Set the lower bound of validity for the given variable.
virtual CalibrationStatus getStatUncertainty(const CalibrationDataVariables &x, double &result)
retrieve the calibration statistical uncertainty.
ClassDef(CalibrationDataFunctionContainer, 1)
virtual CalibrationStatus getResult(const CalibrationDataVariables &x, double &result, TObject *obj=0, bool=false)
retrieve the calibration result.
virtual int getEigenvectorReduction(unsigned int choice) const
Retrieve the number of eigenvectors to be retained for the purpose of eigenvector variation reduction...
std::map< unsigned int, std::vector< double > > m_binBoundaries
Cache for bin boundary information.
double getInterpolatedUncertainty(TH1 *hist) const
Retrieve interpolated result (utility function)
virtual CalibrationStatus getUncertainty(const std::string &unc, const CalibrationDataVariables &x, UncertaintyResult &result, TObject *obj=0)
retrieve the calibration uncertainty due to the given source.
void setUncorrelated(const std::string &unc)
Indicate that the given uncertainty is to be treated uncorrelated from bin to bin (note that the defa...
ClassDef(CalibrationDataHistogramContainer, 2)
void setInterpolated(bool doInterpolate)
Indicate whether results are to be interpolated between bins or not (this feature is thought to be us...
virtual std::vector< double > getBinBoundaries(unsigned int vartype)
Retrieve the bin boundaries for the specified variable type (which should be a CalibrationParametriza...
virtual int getTagWeightAxis()
Test whether this calibration object is one for "continuous" calibration (this has some subtle conseq...
bool m_interpolate
If true, interpolate between bins rather than doing a straight bin-wise evaluation.
void checkBounds()
check the bounds of validity for this calibration object
double getInterpolatedResult(TH1 *hist) const
Retrieve interpolated result (utility function)
virtual CalibrationStatus getStatUncertainty(const CalibrationDataVariables &x, double &result)
retrieve the calibration statistical uncertainty.
virtual CalibrationStatus getResult(const CalibrationDataVariables &x, double &result, TObject *obj=0, bool extrapolate=false)
retrieve the calibration result.
virtual void computeVariableTypes()
utility for determining global bin number, subject to extrapolation constraints.
CalibrationDataHistogramContainer(const char *name="default")
bool isBinCorrelated(const std::string &unc) const
Indicate whether the given uncertainty is correlated from bin to bin or not (note that this function ...
virtual bool isInterpolated() const
Indicate whether histogram interpolation is used or not.
Helper class for the specification of custom binning.
virtual int getTagWeightAxis()
Test whether this calibration object is one for "continuous" calibration (this has some subtle conseq...
unsigned int getNMappedBins() const
return the number of mapped bins
virtual void computeVariableTypes()
decode the 'uncertainty' objects' names to determine the relevant variable types
ClassDef(CalibrationDataMappedHistogramContainer, 1)
unsigned int m_beginMapped
starting position of mapped variables
std::vector< std::string > m_mapped
mapped variables.
virtual bool isInterpolated() const
Indicate whether histogram interpolation is used or not.
virtual CalibrationStatus getResult(const CalibrationDataVariables &x, double &result, TObject *obj=0, bool extrapolate=false)
retrieve the calibration result.
void setMappedVariables(const std::vector< std::string > &variables)
Set (by hand) the variables that will be mapped onto a single histogram axis.
virtual CalibrationStatus getUncertainty(const std::string &unc, const CalibrationDataVariables &x, UncertaintyResult &result, TObject *obj=0)
retrieve the calibration uncertainty due to the given source.
virtual CalibrationStatus getStatUncertainty(const CalibrationDataVariables &x, double &result)
retrieve the calibration statistical uncertainty.
CalibrationDataMappedHistogramContainer(const char *name="default")
const std::vector< std::string > & getMappedVariables() const
List which variables get mapped onto a single histogram axis.
virtual std::vector< double > getBinBoundaries(unsigned int vartype)
Retrieve the bin boundaries for the specified variable type (which should be a CalibrationParametriza...
unsigned int addBin(const Bin &bin)
Add mapping bin.
void checkBounds()
check the bounds of validity for this calibration object
This class (struct, actually) is nothing but a light-weight container of (kinematic or other) variabl...
The namespace of all packages in PhysicsAnalysis/JetTagging.
const unsigned int MaxCalibrationVars
Maximum dimensionality of the calibration parametrisation.
std::pair< double, double > UncertaintyResult
The following typedef is for convenience: most uncertainties can be asymmetric.