CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CompMethods.h
Go to the documentation of this file.
1 #ifndef CompMethods_h
2 #define CompMethods_h
3 
4 #include <memory>
5 #include <string>
6 #include <fstream>
7 #include <iostream>
8 #include <cmath>
9 
12 
13 
14 class MaximalValue {
15 
16  public:
17 
18  MaximalValue(double val, double err):val_(val), err_(err){};
20  double value(TH1F& hist){ return hist.GetBinCenter(hist.GetMaximumBin()); };
21  double valueError(TH1F& hist) { return spread(hist, val_); };
22  double spread(TH1F& hist) { return spread(hist, 0.5); };
23  double spreadError(TH1F& hist){ return std::fabs(spread(hist, 0.5-err_)-spread(hist, 0.5+err_))/2; };
24 
25  private:
26 
27  std::pair<int,int> contour(TH1F&, double&);
28  double spread(TH1F& hist, double frac){ return std::fabs(hist.GetBinCenter(contour(hist, frac).second)-hist.GetBinCenter(contour(hist, frac).first)); };
29 
30  private:
31 
32  double val_;
33  double err_;
34 };
35 
36 // ------------------------------------------------------------------------------------------------------------------
37 
38 class Quantile {
39 
40  public:
41 
42  Quantile(double central, double err):central_(central), err_(err){};
43  ~Quantile(){};
44  double value(TH1F& hist){ quantiles(hist, err_); return qnt_[1]; };
45  double valueError(TH1F& hist) { quantiles(hist, err_); return distance(hist); };
46  double spread(TH1F& hist) { quantiles(hist, 0.25); return distance(hist); };
47  double spreadError(TH1F& hist);
48 
49  private:
50 
51  void evaluate(double& err){val_[0]=central_-err; val_[1]=central_; val_[2]=central_+err;};
52  void quantiles(TH1F& hist, double err){ evaluate(err); hist.GetQuantiles(3, qnt_, val_); };
53  double distance(TH1F& hist){ return std::fabs(qnt_[2]-qnt_[0]); };
54 
55  private:
56 
57  double central_;
58  double err_;
59  double val_[3];
60  double qnt_[3];
61 };
62 
63 // ------------------------------------------------------------------------------------------------------------------
64 
66 
67  public:
68 
71  double value(TH1F& hist){ return hist.GetMean(); };
72  double valueError(TH1F& hist) { return hist.GetMeanError(); };
73  double spread(TH1F& hist) { return TMath::Sqrt(hist.GetRMS()); };
74  double spreadError(TH1F& hist){ return hist.GetRMSError()/TMath::Sqrt(hist.GetRMS()); };
75 };
76 
77 // ------------------------------------------------------------------------------------------------------------------
78 
80 
81  public:
82 
83  StabilizedGauss(){ func_=new TF1(); };
84  StabilizedGauss(const char* name):funcName_(name){ func_=new TF1(); };
85  StabilizedGauss(const char*, int, double, double);
86  ~StabilizedGauss(){ delete func_;};
87  void fit(TH1F&);
88  double value(TH1F& hist){ return value(hist, 1); };
89  double valueError(TH1F& hist){ return error(hist, 1); };
90  double spread(TH1F& hist){ return value(hist, 2); };
91  double spreadError(TH1F& hist){ return error(hist, 2); };
92 
93  private:
94 
95  double value(TH1F& hist, int target){ return (hist.GetFunction( funcName_) ? hist.GetFunction( funcName_)->GetParameter(target) : 0.); }
96  double error(TH1F& hist, int target){ return (hist.GetFunction( funcName_) ? hist.GetFunction( funcName_)->GetParError (target) : 0.); }
97 
98  private:
99 
100  TF1* func_;
101  double mean_;
102  double sigma_;
104  const char* funcName_;
105  double lowerBound_;
106  double upperBound_;
107 };
108 
109 #endif
double spreadError(TH1F &hist)
Definition: CompMethods.h:23
double value(TH1F &hist)
Definition: CompMethods.h:44
StabilizedGauss(const char *name)
Definition: CompMethods.h:84
std::pair< int, int > contour(TH1F &, double &)
Definition: CompMethods.cc:79
void evaluate(double &err)
Definition: CompMethods.h:51
double valueError(TH1F &hist)
Definition: CompMethods.h:21
double valueError(TH1F &hist)
Definition: CompMethods.h:72
double valueError(TH1F &hist)
Definition: CompMethods.h:45
double value(TH1F &hist, int target)
Definition: CompMethods.h:95
double spreadError(TH1F &hist)
Definition: CompMethods.h:74
double err_
Definition: CompMethods.h:58
double distance(TH1F &hist)
Definition: CompMethods.h:53
double value(TH1F &hist)
Definition: CompMethods.h:71
double valueError(TH1F &hist)
Definition: CompMethods.h:89
U second(std::pair< T, U > const &p)
Quantile(double central, double err)
Definition: CompMethods.h:42
double spread(TH1F &hist)
Definition: CompMethods.h:22
double value(TH1F &hist)
Definition: CompMethods.h:20
bool first
Definition: L1TdeRCT.cc:79
const char * funcName_
Definition: CompMethods.h:104
double val_
Definition: CompMethods.h:28
MaximalValue(double val, double err)
Definition: CompMethods.h:18
double value(TH1F &hist)
Definition: CompMethods.h:88
double central_
Definition: CompMethods.h:53
double err_
Definition: CompMethods.h:33
double spread(TH1F &hist)
Definition: CompMethods.h:90
double upperBound_
Definition: CompMethods.h:106
double val_[3]
Definition: CompMethods.h:59
double error(TH1F &hist, int target)
Definition: CompMethods.h:96
double qnt_[3]
Definition: CompMethods.h:60
void fit(TH1F &)
Definition: CompMethods.cc:39
double spreadError(TH1F &hist)
Definition: CompMethods.h:91
double lowerBound_
Definition: CompMethods.h:105
double spreadError(TH1F &hist)
Definition: CompMethods.cc:92
double spread(TH1F &hist)
Definition: CompMethods.h:73
double spread(TH1F &hist)
Definition: CompMethods.h:46
void quantiles(TH1F &hist, double err)
Definition: CompMethods.h:52