ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "AnalyticalIntegrals.h"
19 
20 #include "TROOT.h"
21 #include "TF1.h"
22 #include "TFormula.h"
23 #include "TMath.h"
24 #include "Math/DistFuncMathCore.h" //for cdf
25 
26 #include <stdio.h>
27 
28 using namespace std;
29 
31 {
32 
33  Double_t xmin = a;
34  Double_t xmax = b;
35  Int_t num = f->GetNumber();
36  Double_t *p = f->GetParameters();
37  Double_t result = 0.;
38 
39  TFormula * formula = f->GetFormula();
40  if (!formula) {
41  Error("TF1::AnalyticalIntegral","Invalid formula number - return a NaN");
42  result = TMath::QuietNaN();
43  }
44 
45  if (num == 200)//expo: exp(p0+p1*x)
46  {
47  result = ( exp(p[0]+p[1]*xmax) - exp(p[0]+p[1]*xmin))/p[1];
48  }
49  else if (num == 100)//gaus: [0]*exp(-0.5*((x-[1])/[2])^2))
50  {
51  double amp = p[0];
52  double mean = p[1];
53  double sigma = p[2];
54  if (formula->TestBit(TFormula::kNormalized) )
55  result = amp*( ROOT::Math::gaussian_cdf(xmax, sigma, mean)- ROOT::Math::gaussian_cdf(xmin, sigma, mean) );
56  else
57  result = amp*sqrt(2*M_PI)*sigma*(ROOT::Math::gaussian_cdf(xmax, sigma, mean)- ROOT::Math::gaussian_cdf(xmin, sigma, mean));//
58  }
59  else if (num == 400)//landau: root::math::landau(x,mpv=0,sigma=1,bool norm=false)
60  {
61 
62  double amp = p[0];
63  double mean = p[1];
64  double sigma = p[2];
65  //printf("computing integral for landau in [%f,%f] for m=%f s = %f \n",xmin,xmax,mean,sigma);
66  if (formula->TestBit(TFormula::kNormalized) )
67  result = amp*(ROOT::Math::landau_cdf(xmax,sigma,mean) - ROOT::Math::landau_cdf(xmin,sigma,mean));
68  else
69  result = amp*sigma*(ROOT::Math::landau_cdf(xmax,sigma,mean) - ROOT::Math::landau_cdf(xmin,sigma,mean));
70  }
71  else if (num == 500) //crystal ball
72  {
73  double amp = p[0];
74  double mean = p[1];
75  double sigma = p[2];
76  double alpha = p[3];
77  double n = p[4];
78 
79  //printf("computing integral for CB in [%f,%f] for m=%f s = %f alpha = %f n = %f\n",xmin,xmax,mean,sigma,alpha,n);
80  if (alpha > 0)
81  result = amp*( ROOT::Math::crystalball_integral(xmin,alpha,n,sigma,mean) - ROOT::Math::crystalball_integral(xmax,alpha,n,sigma,mean) );
82  else {
83  result = amp*( ROOT::Math::crystalball_integral(xmax,alpha,n,sigma,mean) - ROOT::Math::crystalball_integral(xmin,alpha,n,sigma,mean) );
84  }
85  }
86 
87  else if (num >= 300 && num < 400)//polN
88  {
89  Int_t n = num - 300;
90  for (int i=0;i<n+1;i++)
91  {
92  result += p[i]/(i+1)*(std::pow(xmax,i+1)-std::pow(xmin,i+1));
93  }
94  }
95  else
96  result = TMath::QuietNaN();
97 
98  return result;
99 }
float xmin
Definition: THbookFile.cxx:93
Double_t QuietNaN()
Definition: TMath.h:635
int Int_t
Definition: RtypesCore.h:41
TArc * a
Definition: textangle.C:12
TFile * f
double sqrt(double)
double pow(double, double)
const Double_t sigma
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
float xmax
Definition: THbookFile.cxx:93
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.
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