CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CompMethods.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <string>
3 #include <fstream>
4 #include <iostream>
5 #include <cmath>
6 
8 
9 using std::cerr;
10 using std::cout;
11 using std::endl;
12 
13 double Gauss(double *x, double *par){
14  double arg=0;
15  if(par[2]!=0){
16  arg = (x[0]-par[1])/par[2];
17  }
18  return par[0]*TMath::Exp(-0.5*arg*arg);
19 }
20 
21 // ------------------------------------------------------------------------------------------------------------------
22 
23 StabilizedGauss::StabilizedGauss(const char* funcName, int funcType, double lowerBound, double upperBound):
24  funcType_ (funcType ),
25  funcName_ (funcName ),
26  lowerBound_(lowerBound),
27  upperBound_(upperBound)
28 {
29  if(funcType_==0){
30  func_ = new TF1(funcName_, Gauss, lowerBound_, upperBound_, 3);
31  func_->SetParNames( "Const", "Mean", "Sigma" );
32  }
33  else{
34  std::cout << "Sorry: not yet implemented" << std::endl;
35  }
36 }
37 
38 void
40 {
41  //set start values for first iteration
42  if(funcType_==0){
43  double maxValue=hist.GetBinCenter(hist.GetMaximumBin());
44  func_->SetParameter(1, maxValue);
45  func_->SetParameter(2, hist.GetRMS());
46  }
47 
48  //set parameter limits
49  if(funcType_==0){
50  func_->SetParLimits(1, lowerBound_, upperBound_);
51  func_->SetParLimits(2, 0., 5.*hist.GetRMS());
52  }
53 
54  //do the fit
55  mean_ = func_->GetParameter(1);
56  sigma_= func_->GetParameter(2);
57 
58  hist.Fit( "func", "RE0", "", (mean_-2.*sigma_), (mean_+2.*sigma_) );
59  if(hist.GetFunction("func")){
60  //get mean and sigma
61  //from first iteration
62  mean_ = hist.GetFunction("func")->GetParameter(1);
63  sigma_= hist.GetFunction("func")->GetParameter(2);
64 
65  //set start values for
66  //second iteration
67  func_->SetParameter(1, mean_ );
68  func_->SetParameter(2, sigma_);
69  hist.Fit( func_, "MEL", "", (mean_-1.5*sigma_), (mean_+1.5*sigma_) );
70  }
71  else{
72  std::cout << "sorry... no fit function found..." << std::endl;
73  }
74 }
75 
76 // ------------------------------------------------------------------------------------------------------------------
77 
78 std::pair<int,int>
80 {
81  int idx=hist.GetMaximumBin(), jdx=hist.GetMaximumBin();
82  if(0<=frac && frac<=1){
83  while( hist.GetBinContent(idx)/hist.GetMaximum()>frac) --idx;
84  while( hist.GetBinContent(jdx)/hist.GetMaximum()>frac) ++jdx;
85  }
86  return std::pair<int, int>(idx, jdx);
87 }
88 
89 // ------------------------------------------------------------------------------------------------------------------
90 
91 double
93 {
94  quantiles(hist, 0.25+err_); double outer=distance(hist);
95  quantiles(hist, 0.25-err_); double inner=distance(hist);
96  return std::fabs(outer-inner)/2;
97 }
std::pair< int, int > contour(TH1F &, double &)
Definition: CompMethods.cc:79
double err_
Definition: CompMethods.h:58
A arg
Definition: Factorize.h:36
double distance(TH1F &hist)
Definition: CompMethods.h:53
double Gauss(double *x, double *par)
Definition: fitUtilities.h:225
const char * funcName_
Definition: CompMethods.h:104
double upperBound_
Definition: CompMethods.h:106
tuple cout
Definition: gather_cfg.py:41
void fit(TH1F &)
Definition: CompMethods.cc:39
Definition: DDAxes.h:10
double lowerBound_
Definition: CompMethods.h:105
double spreadError(TH1F &hist)
Definition: CompMethods.cc:92
const double par[8 *NPar][4]
void quantiles(TH1F &hist, double err)
Definition: CompMethods.h:52