ROOT  6.06/09
Reference Guide
AnalyticalIntegrals.cxx
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Authors: L. Moneta, A. Flandi 2015
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2015 ROOT Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 //
11 // AnalyticalIntegrals.cxx
12 //
13 //
14 // Created by AurĂ©lie Flandi on 09.09.14.
15 //
16 //
17 
18 #include <stdio.h>
19 #include "TROOT.h"
20 #include "TF1.h"
21 #include "TFormula.h"
22 #include "TMath.h"
23 #include "AnalyticalIntegrals.h"
24 #include "Math/DistFuncMathCore.h" //for cdf
25 
26 
27 using namespace std;
28 
30 {
31 
32  Double_t xmin = a;
33  Double_t xmax = b;
34  Int_t num = f->GetNumber();
35  Double_t *p = f->GetParameters();
36  Double_t result = 0.;
37 
38  TFormula * formula = f->GetFormula();
39  if (!formula) {
40  Error("TF1::AnalyticalIntegral","Invalid formula number - return a NaN");
41  result = TMath::QuietNaN();
42  }
43 
44  if (num == 200)//expo: exp(p0+p1*x)
45  {
46  result = ( exp(p[0]+p[1]*xmax) - exp(p[0]+p[1]*xmin))/p[1];
47  }
48  else if (num == 100)//gaus: [0]*exp(-0.5*((x-[1])/[2])^2))
49  {
50  double amp = p[0];
51  double mean = p[1];
52  double sigma = p[2];
53  if (formula->TestBit(TFormula::kNormalized) )
54  result = amp*( ROOT::Math::gaussian_cdf(xmax, sigma, mean)- ROOT::Math::gaussian_cdf(xmin, sigma, mean) );
55  else
56  result = amp*sqrt(2*M_PI)*sigma*(ROOT::Math::gaussian_cdf(xmax, sigma, mean)- ROOT::Math::gaussian_cdf(xmin, sigma, mean));//
57  }
58  else if (num == 400)//landau: root::math::landau(x,mpv=0,sigma=1,bool norm=false)
59  {
60 
61  double amp = p[0];
62  double mean = p[1];
63  double sigma = p[2];
64  //printf("computing integral for landau in [%f,%f] for m=%f s = %f \n",xmin,xmax,mean,sigma);
65  if (formula->TestBit(TFormula::kNormalized) )
66  result = amp*(ROOT::Math::landau_cdf(xmax,sigma,mean) - ROOT::Math::landau_cdf(xmin,sigma,mean));
67  else
68  result = amp*sigma*(ROOT::Math::landau_cdf(xmax,sigma,mean) - ROOT::Math::landau_cdf(xmin,sigma,mean));
69  }
70  else if (num == 500) //crystal ball
71  {
72  double amp = p[0];
73  double mean = p[1];
74  double sigma = p[2];
75  double alpha = p[3];
76  double n = p[4];
77 
78  //printf("computing integral for CB in [%f,%f] for m=%f s = %f alpha = %f n = %f\n",xmin,xmax,mean,sigma,alpha,n);
79  if (alpha > 0)
80  result = amp*( ROOT::Math::crystalball_integral(xmin,alpha,n,sigma,mean) - ROOT::Math::crystalball_integral(xmax,alpha,n,sigma,mean) );
81  else {
82  result = amp*( ROOT::Math::crystalball_integral(xmax,alpha,n,sigma,mean) - ROOT::Math::crystalball_integral(xmin,alpha,n,sigma,mean) );
83  }
84  }
85 
86  else if (num >= 300 && num < 400)//polN
87  {
88  Int_t n = num - 300;
89  for (int i=0;i<n+1;i++)
90  {
91  result += p[i]/(i+1)*(std::pow(xmax,i+1)-std::pow(xmin,i+1));
92  }
93  }
94  else
95  result = TMath::QuietNaN();
96 
97  return result;
98 }
float xmin
Definition: THbookFile.cxx:93
virtual TFormula * GetFormula()
Definition: TF1.h:339
Double_t QuietNaN()
Definition: TMath.h:635
int Int_t
Definition: RtypesCore.h:41
TArc * a
Definition: textangle.C:12
STL namespace.
double sqrt(double)
double pow(double, double)
void Error(const char *location, const char *msgfmt,...)
double landau_cdf(double x, double xi=1, double x0=0)
Cumulative distribution function of the Landau distribution (lower tail).
#define M_PI
Definition: Rotated.cxx:105
The F O R M U L A class.
Definition: TFormula.h:89
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
float xmax
Definition: THbookFile.cxx:93
double f(double x)
double Double_t
Definition: RtypesCore.h:55
Double_t AnalyticalIntegral(TF1 *f, Double_t a, Double_t b)
double gaussian_cdf(double x, double sigma=1, double x0=0)
Alternative name for same function.
virtual Int_t GetNumber() const
Definition: TF1.h:354
virtual Double_t * GetParameters() const
Definition: TF1.h:365
1-Dim function class
Definition: TF1.h:149
double crystalball_integral(double x, double alpha, double n, double sigma, double x0=0)
Integral of the not-normalized Crystal Ball function.
double result[121]
double exp(double)
const Int_t n
Definition: legend1.C:16