46double exactIntegral(
double a,
double b) {
50double func(
double x){
56double func2(
const double *
x,
const double * =
nullptr){
64void testIntegPerf(
double x1,
double x2,
int n = 100000){
67 std::cout <<
"\n\n***************************************************************\n";
68 std::cout <<
"Test integration performances in interval [ " << x1 <<
" , " << x2 <<
" ]\n\n";
72 double dx = (x2-x1)/
double(
n);
81 for (
int i = 0; i <
n; ++i) {
83 s1+= ig.Integral(x1,
x);
86 std::cout <<
"Time using ROOT::Math::Integrator :\t" << timer.
RealTime() << std::endl;
87 std::cout <<
"Number of function calls = " << nc/
n << std::endl;
88 int pr = std::cout.precision(18); std::cout <<
s1 << std::endl; std::cout.precision(pr);
93 TF1 *fBW =
new TF1(
"fBW",func2,x1, x2,0);
98 for (
int i = 0; i <
n; ++i) {
103 std::cout <<
"Time using TF1::Integral :\t\t\t" << timer.
RealTime() << std::endl;
104 std::cout <<
"Number of function calls = " << nc/
n << std::endl;
105 pr = std::cout.precision(18); std::cout <<
s1 << std::endl; std::cout.precision(pr);
110void DrawCumulative(
double x1,
double x2,
int n = 100){
112 std::cout <<
"\n\n***************************************************************\n";
113 std::cout <<
"Drawing cumulatives of BreitWigner in interval [ " << x1 <<
" , " << x2 <<
" ]\n\n";
116 double dx = (x2-x1)/
double(
n);
118 TH1D *cum0 =
new TH1D(
"cum0",
"",
n, x1, x2);
119 for (
int i = 1; i <=
n; ++i) {
120 double x = x1 + dx*i;
131 TH1D *cum1 =
new TH1D(
"cum1",
"",
n, x1, x2);
132 for (
int i = 1; i <=
n; ++i) {
133 double x = x1 + dx*i;
138 TF1 *fBW =
new TF1(
"fBW",
"TMath::BreitWigner(x, 0, 1)",x1, x2);
141 TH1D *cum2 =
new TH1D(
"cum2",
"",
n, x1, x2);
142 for (
int i = 1; i <=
n; ++i) {
143 double x = x1 + dx*i;
147 TH1D *cum10 =
new TH1D(
"cum10",
"",
n, x1, x2);
148 TH1D *cum20 =
new TH1D(
"cum23",
"",
n, x1, x2);
149 for (
int i = 1; i <=
n; ++i) {
164 cum0->
SetTitle(
"BreitWigner - the cumulative");
182 cum20->
Draw(
"hsame");
185 l->AddEntry(cum10,
"GSL integration - analytical ");
186 l->AddEntry(cum20,
"TF1::Integral - analytical ");
191 std::cout <<
"\n***************************************************************\n";
198void mathmoreIntegration(
double a = -2,
double b = 2)
200 DrawCumulative(
a,
b);
Functor1D class for one-dimensional functions.
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)
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.
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
IntegratorOneDim Integrator
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.