Logo ROOT   6.16/01
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 "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
28using 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 * TMath::Pi()) * sigma *
59 }
60 else if (num == 400)//landau: root::math::landau(x,mpv=0,sigma=1,bool norm=false)
61 {
62
63 double amp = p[0];
64 double mean = p[1];
65 double sigma = p[2];
66 //printf("computing integral for landau in [%f,%f] for m=%f s = %f \n",xmin,xmax,mean,sigma);
67 if (formula->TestBit(TFormula::kNormalized) )
69 else
71 }
72 else if (num == 500) //crystal ball
73 {
74 double amp = p[0];
75 double mean = p[1];
76 double sigma = p[2];
77 double alpha = p[3];
78 double n = p[4];
79
80 //printf("computing integral for CB in [%f,%f] for m=%f s = %f alpha = %f n = %f\n",xmin,xmax,mean,sigma,alpha,n);
81 if (alpha > 0)
83 else {
85 }
86 }
87
88 else if (num >= 300 && num < 400)//polN
89 {
90 Int_t n = num - 300;
91 for (int i=0;i<n+1;i++)
92 {
93 result += p[i]/(i+1)*(std::pow(xmax,i+1)-std::pow(xmin,i+1));
94 }
95 }
96 else
97 result = TMath::QuietNaN();
98
99 return result;
100}
Double_t AnalyticalIntegral(TF1 *f, Double_t a, Double_t b)
#define b(i)
Definition: RSha256.hxx:100
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
void Error(const char *location, const char *msgfmt,...)
float xmin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
double pow(double, double)
double sqrt(double)
double exp(double)
1-Dim function class
Definition: TF1.h:211
The Formula class.
Definition: TFormula.h:84
@ kNormalized
Definition: TFormula.h:170
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
double crystalball_integral(double x, double alpha, double n, double sigma, double x0=0)
Integral of the not-normalized Crystal Ball function.
double landau_cdf(double x, double xi=1, double x0=0)
Cumulative distribution function of the Landau distribution (lower tail).
const Double_t sigma
const Int_t n
Definition: legend1.C:16
double gaussian_cdf(double x, double sigma=1, double x0=0)
Alternative name for same function.
Double_t QuietNaN()
Returns a quiet NaN as defined by IEEE 754
Definition: TMath.h:889
constexpr Double_t Pi()
Definition: TMath.h:38
STL namespace.
auto * a
Definition: textangle.C:12