ATLAS Offline Software
CalibrationDataEigenVariations.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // CalibrationDataEigenVariations.h, (c) ATLAS Detector software
8 
9 #ifndef ANALYSISCALIBRATIONDATAINTERFACEEVVARIATIONS_H
10 #define ANALYSISCALIBRATIONDATAINTERFACEEVVARIATIONS_H
11 
12 #include <string>
13 #include <vector>
14 #include <map>
15 #include <set>
16 #include <utility>
17 #include "TMatrixD.h"
18 #include "TMatrixDSym.h"
20 
21 class TH1;
22 
23 namespace Analysis
24 {
25  class CalibrationDataHistogramContainer;
26 
28  public:
29  typedef std::set<size_t> IndexSet;
30  typedef std::set<IndexSet> IndexSuperSet;
31 
33  CalibrationDataEigenVariations(const std::string& cdipath, const std::string& tagger, const std::string& wp, const std::string& jetcollection, CalibrationDataHistogramContainer* cnt, bool excludeRecommendedUncertaintySet = false, bool base = true);
35 
37  void excludeNamedUncertainty(const std::string& name, CalibrationDataContainer* cnt);
40  virtual void initialize(double min_variance = 1.0E-20); // <------ this default value for min_variance can be tuned - some combinations of CDI file and systematic strategy can use a higher threshold
41 
43  void removeVariations(const IndexSet &set);
45  void removeVariations(const IndexSuperSet &set);
46 
48  void mergeVariationsFrom(const size_t& index);
49 
51  void mergeVariations(const IndexSet &set);
53  void mergeVariations(const IndexSuperSet &set);
54 
56  unsigned int getNumberOfNamedVariations() const;
58  std::vector<std::string> listNamedVariations() const;
62  unsigned int getNamedVariationIndex(const std::string& name) const;
63 
65  unsigned int getNumberOfEigenVariations();
66 
69  bool getEigenvectorVariation(unsigned int variation, TH1*& up, TH1*& down);
70 
74  bool getNamedVariation(const std::string& name, TH1*& up, TH1*& down);
79  bool getNamedVariation(unsigned int nameIndex, TH1*& up, TH1*& down);
81  bool isExtrapolationVariation(unsigned int nameIndex) const;
82 
85  virtual TMatrixDSym getEigenCovarianceMatrix();
90  TMatrixD getJacobianReductionMatrix();
91 
93  bool EigenVectorRecomposition(const std::string& label,
94  std::map<std::string, std::map<std::string, float>> &coefficientMap);
95 
96  void setVerbose(bool);
97 
98  private:
101 
102  protected:
103 
106  bool m_validate; // <------ flag that says you want to validate the systematic strategies, and the merging schemes
107 
109  std::map<std::string, unsigned int> m_namedIndices;
110  std::vector<std::pair<TH1*, TH1*> > m_named; // <---- In the CalibrationDataGlobalEigenVariations, this will store regular variations as well
111 
114 
116  std::vector<std::pair<TH1*, TH1*> > m_eigen; // <----- In the CalibrationDataGlobalEigenVariations, this will store the **combined** variations FOR PRUNING ONLY ("reporting" is done differently)
117 
120 
121  // /** @ data members needed for eigenvector method **/
122  // /** the map stores the int which is needed to access the other vector<> objects **/
123  // mutable std::map<std::string, unsigned int> m_eigenvectorMethod_index;
124  // std::vector<TMatrixT<double> > m_eigenvectorMethod_matrix;
125  // std::vector<std::vector<TObject*> > m_eigenvectorMethod_uncUpProvider;
126  // std::vector<std::vector<TObject*> > m_eigenvectorMethod_uncDownProvider;
127  // std::vector<std::vector<TObject*> > m_eigenvectorMethod_uncProvider;
128 
129  std::string m_cdipath;
130  std::string m_taggername;
131  std::string m_wp;
132  std::string m_jetauthor;
133  // The reduction scheme can be said to "capture" X % of the variance by computing m_capturedvariance/m_totalvariance
134  // total variance is the sum of all the eigenvalues found through eigenvector decomposition
135  // the "captured" variance is the sum of the eigenvalue of the retained eigenvectors (after pruning)
138 
139  bool m_verbose;
140 
141  };
142 
143 
144 
146  public:
147  CalibrationDataGlobalEigenVariations(const std::string& cdipath, const std::string& tagger, const std::string& wp, const std::string& jetcollection, const std::vector<std::string>& flavours, CalibrationDataHistogramContainer* cnt, bool excludeRecommendedUncertaintySet = false) ;
149 
151  TMatrixDSym getEigenCovarianceMatrix();
152 
153  void initialize(double min_variance = 1.0E-6) ; // <------ this min_variance threshold value holds generally for the global eigenvariations strategy - but not necessarily set in stone, can depend on CDI file as well
154 
155  TMatrixD getJacobianReductionMatrix(TMatrixDSym& cov);
156 
157  void excludeNamedUncertainty(const std::string& name, const std::string& flavour);
158 
159  std::vector<std::string> listNamedVariations(const std::string& flavour) const;
160  unsigned int getNamedVariationIndex(const std::string& name, const std::string& flavour) const;
161  bool getNamedVariation(const std::string& flavour, const std::string& name, TH1*& up, TH1*& down); // <--- Get the named variation index by flavour and variation name
162  bool getNamedVariation(unsigned int nameIndex, const std::string& flavour, TH1*& up, TH1*& down); // <--- This does the actual retrieval, just also enforces that initialization was done first
163 
164  bool getEigenvectorVariation(const std::string& flavour, unsigned int variation, TH1*& up, TH1*& down);
165  unsigned int getNumberOfEigenVariations(const std::string& flavour);
166  bool isExtrapolationVariation(unsigned int nameIndex, const std::string& flavour) const;
167 
168  void mergeVariationsFrom(const size_t& index, std::string& flav);
169 
170  void mergeVariations(const IndexSet &set, std::string& flav);
171  void mergeVariations(const IndexSuperSet &set, std::string& flav);
172 
173  void removeVariations(const IndexSet &set, std::string& flav);
174  void removeVariations(const IndexSuperSet &set, std::string& flav);
175 
176  private:
177 
178  int m_blockmatrixsize; // store the concatenated length of all binned flavour calibrations, i.e. dim(B) + dim(C) + dim(Light) + dim(T)
179 
180  std::map<std::string, Analysis::CalibrationDataHistogramContainer*> m_histcontainers; // map of flavour to container, useful for when you need to actually quote a variation! (correct binning here per flavour)
181  std::set<std::string> m_all_shared_systematics;
182  std::set<std::string> m_only_shared_systematics;
183  std::map<std::string, std::vector<int>> m_flavour_combinations;
184 
185 
186  std::map<std::string, std::map<std::string, unsigned int>> m_flav_namedIndices; // replace the m_namedIndices, still can use m_named to store? Yes.
187  std::map<std::string, std::vector<std::pair<TH1*,TH1*>>> m_flav_named; // On second second thought, this is needed to keep indices consistent between flavours...
188  std::map<std::string, int> m_flav_namedExtrapolation; // store the index of the flavour container's extrapolation named uncertainty index - replaces m_namedExtrapolation
189  std::map<std::string, std::vector<std::pair<TH1*, TH1*>>> m_flav_eigen; // replace m_eigen when it comes to RETURNING VARIATIONS with proper binning (i.e. the "reporting" of up/down variations per flavour)
190  std::vector<std::string> m_flavours;
191 
192  };
193 
194 }
195 
196 #endif // ANALYSISCALIBRATIONDATAINTERFACEEVVARIATIONS_H
Analysis::CalibrationDataGlobalEigenVariations::getEigenCovarianceMatrix
TMatrixDSym getEigenCovarianceMatrix()
also provide (some) access to the underlying information: covariance matrix corresponding to eigenvec...
Definition: CalibrationDataEigenVariations.cxx:1377
Analysis::CalibrationDataEigenVariations::isExtrapolationVariation
bool isExtrapolationVariation(unsigned int nameIndex) const
flag whether the given index corresponds to an extrapolation variation
Definition: CalibrationDataEigenVariations.cxx:1099
base
std::string base
Definition: hcg.cxx:78
Analysis::CalibrationDataEigenVariations::getNamedVariationIndex
unsigned int getNamedVariationIndex(const std::string &name) const
retrieve the integer index corresponding to the named variation.
Definition: CalibrationDataEigenVariations.cxx:1088
Analysis::CalibrationDataEigenVariations::excludeNamedUncertainty
void excludeNamedUncertainty(const std::string &name, CalibrationDataContainer *cnt)
exclude the source of uncertainty indicated by name from eigenvector calculations
Definition: CalibrationDataEigenVariations.cxx:371
Analysis::CalibrationDataEigenVariations::m_named
std::vector< std::pair< TH1 *, TH1 * > > m_named
Definition: CalibrationDataEigenVariations.h:110
Analysis::CalibrationDataEigenVariations::m_cdipath
std::string m_cdipath
Definition: CalibrationDataEigenVariations.h:129
Analysis::CalibrationDataContainer
Definition: CalibrationDataContainer.h:51
Analysis::CalibrationDataGlobalEigenVariations::m_flav_named
std::map< std::string, std::vector< std::pair< TH1 *, TH1 * > > > m_flav_named
Definition: CalibrationDataEigenVariations.h:187
Analysis::CalibrationDataEigenVariations::m_initialized
bool m_initialized
flag whether the initialization has been carried out
Definition: CalibrationDataEigenVariations.h:105
Analysis::CalibrationDataEigenVariations::getNumberOfEigenVariations
unsigned int getNumberOfEigenVariations()
retrieve the number of eigenvector variations
Definition: CalibrationDataEigenVariations.cxx:1010
index
Definition: index.py:1
Analysis::CalibrationDataEigenVariations::m_statVariations
bool m_statVariations
indicate whether statistical uncertainties are stored as variations
Definition: CalibrationDataEigenVariations.h:119
Analysis::CalibrationDataEigenVariations::EigenVectorRecomposition
bool EigenVectorRecomposition(const std::string &label, std::map< std::string, std::map< std::string, float >> &coefficientMap)
Eigenvector recomposition method.
Definition: CalibrationDataEigenVariations.cxx:1109
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
Analysis::CalibrationDataGlobalEigenVariations::isExtrapolationVariation
bool isExtrapolationVariation(unsigned int nameIndex, const std::string &flavour) const
Definition: CalibrationDataEigenVariations.cxx:2033
Analysis::CalibrationDataEigenVariations::m_totalvariance
double m_totalvariance
Definition: CalibrationDataEigenVariations.h:136
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
Analysis::CalibrationDataGlobalEigenVariations::CalibrationDataGlobalEigenVariations
CalibrationDataGlobalEigenVariations(const std::string &cdipath, const std::string &tagger, const std::string &wp, const std::string &jetcollection, const std::vector< std::string > &flavours, CalibrationDataHistogramContainer *cnt, bool excludeRecommendedUncertaintySet=false)
Definition: CalibrationDataEigenVariations.cxx:1282
Analysis::CalibrationDataEigenVariations::m_taggername
std::string m_taggername
Definition: CalibrationDataEigenVariations.h:130
Analysis::CalibrationDataGlobalEigenVariations::getNamedVariation
bool getNamedVariation(const std::string &flavour, const std::string &name, TH1 *&up, TH1 *&down)
Definition: CalibrationDataEigenVariations.cxx:1977
Analysis::CalibrationDataEigenVariations::initialize
virtual void initialize(double min_variance=1.0E-20)
carry out the eigenvector computations.
Definition: CalibrationDataEigenVariations.cxx:637
Analysis::CalibrationDataEigenVariations::mergeVariationsFrom
void mergeVariationsFrom(const size_t &index)
merge all variations starting from the given index
Definition: CalibrationDataEigenVariations.cxx:863
Analysis::CalibrationDataEigenVariations::getJacobianReductionMatrix
TMatrixD getJacobianReductionMatrix()
matrix to remove unecessary rows and columns from covariance
Definition: CalibrationDataEigenVariations.cxx:500
Analysis::CalibrationDataGlobalEigenVariations::mergeVariationsFrom
void mergeVariationsFrom(const size_t &index, std::string &flav)
Definition: CalibrationDataEigenVariations.cxx:2045
Analysis::CalibrationDataEigenVariations::getEigenCovarianceMatrix
virtual TMatrixDSym getEigenCovarianceMatrix()
also provide (some) access to the underlying information: covariance matrix corresponding to eigenvec...
Definition: CalibrationDataEigenVariations.cxx:416
Analysis::CalibrationDataEigenVariations::IndexSuperSet
std::set< IndexSet > IndexSuperSet
Definition: CalibrationDataEigenVariations.h:30
Analysis::CalibrationDataEigenVariations::IndexSet
std::set< size_t > IndexSet
Definition: CalibrationDataEigenVariations.h:29
Analysis::CalibrationDataEigenVariations::m_eigen
std::vector< std::pair< TH1 *, TH1 * > > m_eigen
eigenvector variations
Definition: CalibrationDataEigenVariations.h:116
Analysis::CalibrationDataGlobalEigenVariations::~CalibrationDataGlobalEigenVariations
~CalibrationDataGlobalEigenVariations()
Definition: CalibrationDataEigenVariations.cxx:1359
Analysis::CalibrationDataGlobalEigenVariations::mergeVariations
void mergeVariations(const IndexSet &set, std::string &flav)
Definition: CalibrationDataEigenVariations.cxx:2060
Analysis::CalibrationDataEigenVariations::m_wp
std::string m_wp
Definition: CalibrationDataEigenVariations.h:131
Analysis::CalibrationDataGlobalEigenVariations::m_all_shared_systematics
std::set< std::string > m_all_shared_systematics
Definition: CalibrationDataEigenVariations.h:181
Analysis::CalibrationDataEigenVariations::m_capturedvariance
double m_capturedvariance
Definition: CalibrationDataEigenVariations.h:137
Analysis::CalibrationDataGlobalEigenVariations::m_flavours
std::vector< std::string > m_flavours
Definition: CalibrationDataEigenVariations.h:190
Analysis::CalibrationDataEigenVariations::m_namedIndices
std::map< std::string, unsigned int > m_namedIndices
named variations
Definition: CalibrationDataEigenVariations.h:109
Analysis::CalibrationDataEigenVariations
Definition: CalibrationDataEigenVariations.h:27
Analysis::CalibrationDataEigenVariations::getEigenvectorVariation
bool getEigenvectorVariation(unsigned int variation, TH1 *&up, TH1 *&down)
obtain the "up" and "down" variations for the given eigenvector number.
Definition: CalibrationDataEigenVariations.cxx:1018
Analysis::CalibrationDataGlobalEigenVariations::m_histcontainers
std::map< std::string, Analysis::CalibrationDataHistogramContainer * > m_histcontainers
Definition: CalibrationDataEigenVariations.h:180
Analysis::CalibrationDataGlobalEigenVariations
Definition: CalibrationDataEigenVariations.h:145
CalibCoolCompareRT.up
up
Definition: CalibCoolCompareRT.py:109
PlotSFuncertainty.wp
wp
Definition: PlotSFuncertainty.py:112
Analysis::CalibrationDataGlobalEigenVariations::excludeNamedUncertainty
void excludeNamedUncertainty(const std::string &name, const std::string &flavour)
Definition: CalibrationDataEigenVariations.cxx:1515
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
Analysis::CalibrationDataGlobalEigenVariations::m_blockmatrixsize
int m_blockmatrixsize
Definition: CalibrationDataEigenVariations.h:178
Analysis::CalibrationDataGlobalEigenVariations::getNamedVariationIndex
unsigned int getNamedVariationIndex(const std::string &name, const std::string &flavour) const
Definition: CalibrationDataEigenVariations.cxx:2022
Analysis::CalibrationDataEigenVariations::listNamedVariations
std::vector< std::string > listNamedVariations() const
list the named variations
Definition: CalibrationDataEigenVariations.cxx:997
Analysis
The namespace of all packages in PhysicsAnalysis/JetTagging.
Definition: BTaggingCnvAlg.h:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
Analysis::CalibrationDataEigenVariations::removeVariations
void removeVariations(const IndexSet &set)
remove all variations in the given set
Definition: CalibrationDataEigenVariations.cxx:835
Analysis::CalibrationDataGlobalEigenVariations::initialize
void initialize(double min_variance=1.0E-6)
carry out the eigenvector computations.
Definition: CalibrationDataEigenVariations.cxx:1558
Analysis::CalibrationDataHistogramContainer
Definition: CalibrationDataContainer.h:247
Analysis::CalibrationDataGlobalEigenVariations::m_flavour_combinations
std::map< std::string, std::vector< int > > m_flavour_combinations
Definition: CalibrationDataEigenVariations.h:183
Analysis::CalibrationDataEigenVariations::~CalibrationDataEigenVariations
virtual ~CalibrationDataEigenVariations()
Definition: CalibrationDataEigenVariations.cxx:355
Analysis::CalibrationDataEigenVariations::m_jetauthor
std::string m_jetauthor
Definition: CalibrationDataEigenVariations.h:132
Analysis::CalibrationDataEigenVariations::m_verbose
bool m_verbose
Definition: CalibrationDataEigenVariations.h:139
Analysis::CalibrationDataEigenVariations::CalibrationDataEigenVariations
CalibrationDataEigenVariations(const std::string &cdipath, const std::string &tagger, const std::string &wp, const std::string &jetcollection, CalibrationDataHistogramContainer *cnt, bool excludeRecommendedUncertaintySet=false, bool base=true)
normal constructor.
Analysis::CalibrationDataEigenVariations::m_validate
bool m_validate
Definition: CalibrationDataEigenVariations.h:106
Analysis::CalibrationDataEigenVariations::getEigenCovarianceMatrixFromVariations
TMatrixDSym getEigenCovarianceMatrixFromVariations()
covariance matrix corresponding to eigenvector variations constructed from the eigen-variation
Definition: CalibrationDataEigenVariations.cxx:473
trigbs_pickEvents.cnt
cnt
Definition: trigbs_pickEvents.py:71
Analysis::CalibrationDataEigenVariations::setVerbose
void setVerbose(bool)
Definition: CalibrationDataEigenVariations.cxx:1247
Analysis::CalibrationDataEigenVariations::m_namedExtrapolation
int m_namedExtrapolation
named variation index for the special case of extrapolation uncertainties
Definition: CalibrationDataEigenVariations.h:113
Analysis::CalibrationDataGlobalEigenVariations::removeVariations
void removeVariations(const IndexSet &set, std::string &flav)
Definition: CalibrationDataEigenVariations.cxx:2179
Analysis::CalibrationDataGlobalEigenVariations::getEigenvectorVariation
bool getEigenvectorVariation(const std::string &flavour, unsigned int variation, TH1 *&up, TH1 *&down)
Definition: CalibrationDataEigenVariations.cxx:1953
Analysis::CalibrationDataGlobalEigenVariations::m_flav_eigen
std::map< std::string, std::vector< std::pair< TH1 *, TH1 * > > > m_flav_eigen
Definition: CalibrationDataEigenVariations.h:189
Analysis::CalibrationDataEigenVariations::getNumberOfNamedVariations
unsigned int getNumberOfNamedVariations() const
retrieve the number of named variations
Definition: CalibrationDataEigenVariations.cxx:988
Analysis::CalibrationDataEigenVariations::getNamedVariation
bool getNamedVariation(const std::string &name, TH1 *&up, TH1 *&down)
obtain the "up" and "down" variations for the named uncertainty.
Definition: CalibrationDataEigenVariations.cxx:1043
Analysis::CalibrationDataEigenVariations::m_cnt
CalibrationDataHistogramContainer * m_cnt
container object containing the basic information
Definition: CalibrationDataEigenVariations.h:100
Analysis::CalibrationDataEigenVariations::mergeVariations
void mergeVariations(const IndexSet &set)
merge all variations in the given set
Definition: CalibrationDataEigenVariations.cxx:877
Analysis::CalibrationDataGlobalEigenVariations::m_flav_namedIndices
std::map< std::string, std::map< std::string, unsigned int > > m_flav_namedIndices
Definition: CalibrationDataEigenVariations.h:186
checker_macros.h
Define macros for attributes used to control the static checker.
Analysis::CalibrationDataGlobalEigenVariations::m_only_shared_systematics
std::set< std::string > m_only_shared_systematics
Definition: CalibrationDataEigenVariations.h:182
Analysis::CalibrationDataGlobalEigenVariations::m_flav_namedExtrapolation
std::map< std::string, int > m_flav_namedExtrapolation
Definition: CalibrationDataEigenVariations.h:188