45 double exactIntegral(
double a,
double b) {
49 double func(
double x){
55 double func2(
const double *
x,
const double * = 0){
63 void testIntegPerf(
double x1,
double x2,
int n = 100000){
66 std::cout <<
"\n\n***************************************************************\n";
67 std::cout <<
"Test integration performances in interval [ " << x1 <<
" , " << x2 <<
" ]\n\n";
71 double dx = (x2-
x1)/
double(
n);
80 for (
int i = 0; i <
n; ++i) {
82 s1+= ig.Integral(x1,x);
85 std::cout <<
"Time using ROOT::Math::Integrator :\t" << timer.
RealTime() << std::endl;
86 std::cout <<
"Number of function calls = " << nc/n << std::endl;
87 int pr = std::cout.precision(18); std::cout << s1 << std::endl; std::cout.precision(pr);
92 TF1 *fBW =
new TF1(
"fBW",func2,x1, x2,0);
97 for (
int i = 0; i <
n; ++i) {
102 std::cout <<
"Time using TF1::Integral :\t\t\t" << timer.
RealTime() << std::endl;
103 std::cout <<
"Number of function calls = " << nc/n << std::endl;
104 pr = std::cout.precision(18); std::cout << s1 << std::endl; std::cout.precision(pr);
109 void DrawCumulative(
double x1,
double x2,
int n = 100){
111 std::cout <<
"\n\n***************************************************************\n";
112 std::cout <<
"Drawing cumulatives of BreitWigner in interval [ " << x1 <<
" , " << x2 <<
" ]\n\n";
115 double dx = (x2-
x1)/
double(n);
117 TH1D *cum0 =
new TH1D(
"cum0",
"", n, x1, x2);
118 for (
int i = 1; i <=
n; ++i) {
119 double x = x1 + dx*i;
130 TH1D *cum1 =
new TH1D(
"cum1",
"", n, x1, x2);
131 for (
int i = 1; i <=
n; ++i) {
132 double x = x1 + dx*i;
137 TF1 *fBW =
new TF1(
"fBW",
"TMath::BreitWigner(x, 0, 1)",x1, x2);
140 TH1D *cum2 =
new TH1D(
"cum2",
"", n, x1, x2);
141 for (
int i = 1; i <=
n; ++i) {
142 double x = x1 + dx*i;
146 TH1D *cum10 =
new TH1D(
"cum10",
"", n, x1, x2);
147 TH1D *cum20 =
new TH1D(
"cum23",
"", n, x1, x2);
148 for (
int i = 1; i <=
n; ++i) {
163 cum0->
SetTitle(
"BreitWigner - the cumulative");
181 cum20->
Draw(
"hsame");
184 l->
AddEntry(cum10,
"GSL integration - analytical ");
185 l->
AddEntry(cum20,
"TF1::Integral - analytical ");
190 std::cout <<
"\n***************************************************************\n";
197 void mathmoreIntegration(
double a = -2,
double b = 2)
199 DrawCumulative(a, b);
Double_t BreitWigner(Double_t x, Double_t mean=0, Double_t gamma=1)
Calculate a Breit Wigner function with mean and gamma.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
This class displays a legend box (TPaveText) containing several legend entries.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
Template class to wrap any C++ callable object which takes one argument i.e.
static const double x2[5]
void Stop()
Stop the stopwatch.
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...
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void Draw(Option_t *option="")
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...
User Class for performing numerical integration of a function in one dimension.
1-D histogram with a double per channel (see TH1 documentation)}
constexpr Double_t E()
Base of natural log: .
static const double x1[5]
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
virtual void Draw(Option_t *option="")
Draw a canvas.
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Functor1D class for one-dimensional functions.
virtual void Update()
Update canvas pad buffers.
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.