00001
00002
00004
00005 #ifndef ANALYSISCALIBRATIONDATACONTAINER_H
00006 #define ANALYSISCALIBRATIONDATACONTAINER_H
00007
00008 #include <vector>
00009 #include <map>
00010 #include <string>
00011
00012 #include "TMap.h"
00013 #include "THashList.h"
00014
00015 class TH1;
00016
00017 #include "CalibrationDataInterface/CalibrationDataVariables.h"
00018
00019 namespace Analysis {
00020
00029 typedef std::pair<double, double> UncertaintyResult;
00030
00036 const unsigned int MaxCalibrationVars = 10;
00037
00047 class CalibrationDataContainer: public TMap {
00048 public:
00049 CalibrationDataContainer(const char* name = "default");
00050 virtual ~CalibrationDataContainer();
00051
00059 enum CalibrationParametrization {
00060 kPt = 0,
00061 kEta = 1,
00062 kAbsEta = 2,
00063 kTagWeight = 3
00064 };
00065
00070 std::vector<std::string> listUncertainties() const;
00071
00077 CalibrationStatus getUncertainties(const CalibrationDataVariables& x,
00078 std::map<std::string, Analysis::UncertaintyResult>& all) const;
00079
00081 std::string getComment() const;
00082
00084 std::string getHadronisation() const;
00085
00094 virtual CalibrationStatus getResult(const CalibrationDataVariables& x,
00095 double& result,
00096 TObject* obj = 0, bool extrapolate = false) const = 0;
00097
00107 virtual CalibrationStatus getStatUncertainty(const CalibrationDataVariables& x,
00108 double& result) const = 0;
00109
00114 CalibrationStatus getSystUncertainty(const CalibrationDataVariables& x,
00115 UncertaintyResult& result,
00116 TObject* obj = 0) const;
00117
00126 virtual CalibrationStatus getUncertainty(const std::string& unc,
00127 const CalibrationDataVariables& x,
00128 UncertaintyResult& result, TObject* obj = 0) const = 0;
00129
00131 void setResult(TObject* obj);
00132
00134 void setComment(const std::string& text);
00135
00137 void setHadronisation(const std::string& text);
00138
00140 void setUncertainty(const std::string& unc, TObject* obj);
00141
00147 void restrictToRange(bool restrict) { m_restrict = restrict; }
00148
00150 bool isRangeRestricted() const { return m_restrict; }
00151
00156 double getLowerBound(unsigned int vartype, bool extrapolate = false) const;
00157
00162 double getUpperBound(unsigned int vartype, bool extrapolate = false) const;
00163
00165 std::vector<std::pair<double, double> > getBounds() const;
00166
00168 std::vector<unsigned int> getVariableTypes() const;
00169
00171 static bool isNearlyEqual (double a, double b);
00172
00173 protected:
00174
00178 int typeFromString(const std::string& key) const;
00179
00180
00181
00182
00183
00184
00185
00186
00187
00193 CalibrationStatus computeVariables(const CalibrationDataVariables& x, bool extrapolate = false) const;
00194
00196 virtual void computeVariableTypes() const = 0;
00197
00198 mutable std::vector<double> m_lowerBounds;
00199 mutable std::vector<double> m_upperBounds;
00200
00201 mutable std::vector<double> m_lowerBoundsExtrapolated;
00202 mutable std::vector<double> m_upperBoundsExtrapolated;
00203
00205 mutable TObject* m_objResult;
00206 mutable TObject* m_objSystematics;
00207
00208 mutable double m_vars[MaxCalibrationVars];
00209
00211 mutable std::vector<unsigned int> m_variables;
00212
00213
00214
00215 private:
00216
00218 bool m_restrict;
00219
00220 ClassDef(CalibrationDataContainer, 1);
00221
00222 };
00223
00224
00225
00226
00233
00234
00235 class CalibrationDataHistogramContainer: public CalibrationDataContainer {
00236 public:
00237 CalibrationDataHistogramContainer(const char* name = "default");
00238 virtual ~CalibrationDataHistogramContainer();
00239 virtual CalibrationStatus getResult(const CalibrationDataVariables& x, double& result,
00240 TObject* obj = 0, bool extrapolate = false) const;
00241 virtual CalibrationStatus getStatUncertainty(const CalibrationDataVariables& x, double& result) const;
00242 virtual CalibrationStatus getUncertainty(const std::string& unc, const CalibrationDataVariables& x,
00243 UncertaintyResult& result, TObject* obj = 0) const;
00244
00247 bool isBinCorrelated(const std::string& unc) const;
00248
00251 void setUncorrelated(const std::string& unc);
00252
00255 void setInterpolated(bool doInterpolate);
00256
00258 virtual bool isInterpolated() const;
00259
00264 virtual int getTagWeightAxis() const;
00265
00268 virtual std::vector<double> getBinBoundaries(unsigned int vartype) const;
00269
00274 virtual int getEigenvectorReduction(unsigned int choice) const;
00275
00276 protected:
00277
00279 mutable std::map<unsigned int, std::vector<double> > m_binBoundaries;
00280
00281 private:
00282
00284 THashList m_uncorrelatedSyst;
00285
00287 bool m_interpolate;
00288
00290 double getInterpolatedResult(TH1* hist) const;
00291
00293 double getInterpolatedUncertainty(TH1* hist) const;
00294
00296 void checkBounds();
00297
00298
00299
00300
00301
00302
00303
00305 virtual void computeVariableTypes() const;
00306
00307 ClassDef(CalibrationDataHistogramContainer, 2);
00308 };
00309
00321
00322
00323 class CalibrationDataMappedHistogramContainer: public CalibrationDataHistogramContainer {
00324 public:
00325 CalibrationDataMappedHistogramContainer(const char* name = "default");
00326 virtual ~CalibrationDataMappedHistogramContainer();
00327 virtual CalibrationStatus getResult(const CalibrationDataVariables& x, double& result,
00328 TObject* obj = 0, bool extrapolate = false) const;
00329 virtual CalibrationStatus getStatUncertainty(const CalibrationDataVariables& x, double& result) const;
00330 virtual CalibrationStatus getUncertainty(const std::string& unc, const CalibrationDataVariables& x,
00331 UncertaintyResult& result, TObject* obj = 0) const;
00332
00334 virtual bool isInterpolated() const { return false; }
00335
00340 virtual int getTagWeightAxis() const;
00341
00343 void setMappedVariables(const std::vector<std::string>& variables);
00344
00346 std::vector<std::string> getMappedVariables() const;
00347
00350 virtual std::vector<double> getBinBoundaries(unsigned int vartype) const;
00351
00355 class Bin {
00356 public:
00357 Bin();
00358 Bin(unsigned int dimension, double* low, double* up);
00359 Bin(const Bin& other);
00360 ~Bin();
00361
00362 unsigned int getDimension() const { return m_dimension; }
00363 bool contains(double* x) const;
00364 double getUpperBound(unsigned int dim) const;
00365 double getLowerBound(unsigned int dim) const;
00366 private:
00367 unsigned int m_dimension;
00368 double* m_low;
00369 double* m_up;
00370 };
00371
00374 unsigned int addBin(const Bin& bin);
00375
00377 unsigned int getNMappedBins() const;
00378
00379 private:
00380
00383 std::vector<std::string> m_mapped;
00384
00386 mutable unsigned int m_beginMapped;
00387
00389 std::vector<Bin> m_bins;
00390
00391 mutable unsigned int m_lastBin;
00392
00394 Int_t findBin() const;
00395 Int_t findMappedBin(double* x) const;
00396
00398 void checkBounds();
00399
00401 virtual void computeVariableTypes() const;
00402
00403 ClassDef(CalibrationDataMappedHistogramContainer, 1);
00404 };
00405
00406
00412
00413
00414 class CalibrationDataFunctionContainer: public CalibrationDataContainer {
00415 public:
00416 CalibrationDataFunctionContainer(const char* name = "default");
00417 virtual ~CalibrationDataFunctionContainer();
00418 virtual CalibrationStatus getResult(const CalibrationDataVariables& x, double& result,
00419 TObject* obj = 0, bool = false) const;
00420 virtual CalibrationStatus getStatUncertainty(const CalibrationDataVariables& x, double& result) const;
00421 virtual CalibrationStatus getUncertainty(const std::string& unc, const CalibrationDataVariables& x,
00422 UncertaintyResult& result, TObject* obj = 0) const;
00423
00425 inline void setLowerBound(int vartype, double bound) {m_lowerBounds[vartype] = bound; }
00426
00428 inline void setUpperBound(int vartype, double bound) {m_upperBounds[vartype] = bound; }
00429
00430 private:
00431
00432 mutable TObject* m_objStatistics;
00433
00435 virtual void computeVariableTypes() const;
00436
00437 ClassDef(CalibrationDataFunctionContainer, 1);
00438 };
00439
00440 }
00441
00442 #endif