Example on the usage of the adaptive 1D integration algorithm of MathMore it calculates the numerically cumulative integral of a distribution (like in this case the BreitWigner) to execute the macro type it (you need to compile with AClic)
root[0] .x mathmoreIntegration.C+
This tutorials require having libMathMore built with ROOT.
To build mathmore you need to have a version of GSL >= 1.8 installed in your system The ROOT configure will automatically find GSL if the script gsl-config (from GSL) is in your PATH,. otherwise you need to configure root with the options –gsl-incdir and –gsl-libdir.
***************************************************************
Drawing cumulatives of BreitWigner in interval [ -2 , 2 ]
***************************************************************
***************************************************************
Test integration performances in interval [ -2 , 2 ]
Time using ROOT::Math::Integrator : 0.119319
Number of function calls = 69
42201.6649413923442
Time using TF1::Integral : 0.38583
Number of function calls = 91
42201.6649413923442
#include <iostream>
#include <limits>
int nc = 0;
double exactIntegral(
double a,
double b) {
}
nc++;
}
double func2(
const double *
x,
const double * =
nullptr){
nc++;
}
void testIntegPerf(
double x1,
double x2,
int n = 100000){
std::cout << "\n\n***************************************************************\n";
std::cout <<
"Test integration performances in interval [ " <<
x1 <<
" , " <<
x2 <<
" ]\n\n";
double dx = (
x2-
x1)/
double(
n);
nc = 0;
for (
int i = 0; i <
n; ++i) {
}
std::cout <<
"Time using ROOT::Math::Integrator :\t" << timer.
RealTime() << std::endl;
std::cout <<
"Number of function calls = " << nc/
n << std::endl;
int pr = std::cout.precision(18); std::cout <<
s1 << std::endl; std::cout.precision(pr);
nc = 0;
double s2 = 0;
for (
int i = 0; i <
n; ++i) {
}
std::cout <<
"Time using TF1::Integral :\t\t\t" << timer.
RealTime() << std::endl;
std::cout <<
"Number of function calls = " << nc/
n << std::endl;
pr = std::cout.precision(18); std::cout <<
s1 << std::endl; std::cout.precision(pr);
}
void DrawCumulative(
double x1,
double x2,
int n = 100){
std::cout << "\n\n***************************************************************\n";
std::cout <<
"Drawing cumulatives of BreitWigner in interval [ " <<
x1 <<
" , " <<
x2 <<
" ]\n\n";
double dx = (
x2-
x1)/
double(
n);
for (
int i = 1; i <=
n; ++i) {
}
for (
int i = 1; i <=
n; ++i) {
}
TF1 *fBW =
new TF1(
"fBW",
"TMath::BreitWigner(x, 0, 1)",
x1,
x2);
for (
int i = 1; i <=
n; ++i) {
}
for (
int i = 1; i <=
n; ++i) {
}
cum0->
SetTitle(
"BreitWigner - the cumulative");
l->AddEntry(cum10,
"GSL integration - analytical ");
l->AddEntry(cum20,
"TF1::Integral - analytical ");
std::cout << "\n***************************************************************\n";
}
void mathmoreIntegration(
double a = -2,
double b = 2)
{
}
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Functor1D class for one-dimensional functions.
User Class for performing numerical integration of a function in one dimension.
Template class to wrap any C++ callable object which takes one argument i.e.
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
1-D histogram with a double per channel (see TH1 documentation)}
void SetTitle(const char *title) override
Change/set the title.
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
void Draw(Option_t *option="") override
Draw this histogram with options.
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
This class displays a legend box (TPaveText) containing several legend entries.
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Stop()
Stop the stopwatch.
@ kADAPTIVE
to be used for general functions without singularities
Double_t ATan(Double_t)
Returns the principal value of the arc tangent of x, expressed in radians.
Double_t BreitWigner(Double_t x, Double_t mean=0, Double_t gamma=1)
Calculates a Breit Wigner function with mean and gamma.
- Authors
- M. Slawinska, L. Moneta
Definition in file mathmoreIntegration.C.