Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <cstdio>
27
29{
30
31 Double_t xmin = a;
32 Double_t xmax = b;
33 Int_t num = f->GetNumber();
34 Double_t *p = f->GetParameters();
35 Double_t result = 0.;
36
37 TFormula * formula = f->GetFormula();
38 if (!formula) {
39 Error("TF1::AnalyticalIntegral","Invalid formula number - return a NaN");
40 return TMath::QuietNaN();
41 }
42
43 else if (num == 200) { // expo: exp(p0 + p1*x)
44 const double p0 = p[0];
45 const double p1 = p[1];
46
47 if (p1 == 0) {
48 // Limit p1 -> 0: integral of constant exp(p0)
49 result = std::exp(p0) * (xmax - xmin);
50 } else {
51 const double ea = p0 + p1 * xmin;
52 const double eb = p0 + p1 * xmax;
53
54 // Use expm1 for improved numerical stability when eb ~ ea
55 result = std::exp(ea) * std::expm1(eb - ea) / p1;
56 }
57 }
58
59 else if (num == 100) // gaus: [0]*exp(-0.5*((x-[1])/[2])^2))
60 {
61 double amp = p[0];
62 double mean = p[1];
63 double sigma = p[2];
64 if (sigma <= 0)
65 return TMath::QuietNaN();
66 if (formula->TestBit(TFormula::kNormalized))
68 else
69 result = amp * sqrt(2 * TMath::Pi()) * sigma *
71 } else if (num == 400) // landau: root::math::landau(x,mpv=0,sigma=1,bool norm=false)
72 {
73
74 double amp = p[0];
75 double mean = p[1];
76 double sigma = p[2];
77 if (sigma <= 0)
78 return TMath::QuietNaN();
79 //printf("computing integral for landau in [%f,%f] for m=%f s = %f \n",xmin,xmax,mean,sigma);
80 if (formula->TestBit(TFormula::kNormalized) )
82 else
84 } else if (num == 500) // crystal ball
85 {
86 double amp = p[0];
87 double mean = p[1];
88 double sigma = p[2];
89 double alpha = p[3];
90 double n = p[4];
91 if (sigma <= 0 || n <= 0)
92 return TMath::QuietNaN();
93 //printf("computing integral for CB in [%f,%f] for m=%f s = %f alpha = %f n = %f\n",xmin,xmax,mean,sigma,alpha,n);
94 if (alpha > 0)
96 else {
98 }
99 }
100
101 else if (num >= 300 && num < 400) // polN
102 {
103 Int_t n = num - 300;
104 for (int i=0;i<n+1;i++)
105 {
106 result += p[i]/(i+1)*(std::pow(xmax,i+1)-std::pow(xmin,i+1));
107 }
108 } else
110
111 return result;
112}
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
#define a(i)
Definition RSha256.hxx:99
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
float xmin
float xmax
1-Dim function class
Definition TF1.h:182
The Formula class.
Definition TFormula.h:89
@ kNormalized
Set to true if the TFormula (ex gausn) is normalized.
Definition TFormula.h:178
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:204
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:913
constexpr Double_t Pi()
Definition TMath.h:40