ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Integration.C
Go to the documentation of this file.
1 //Numerical integration using R
2 //passing the function from ROOT
3 #include<TMath.h>
4 #include<TRInterface.h>
5 #include<Math/Integrator.h>
6 #include<TF1.h>
7 
8 //To integrate using R the function must be vectorized
9 //The idea is just to receive a vector like an argument,to evaluate
10 //every element saving the result in another vector
11 //and return the resultant vector.
12 std::vector<Double_t> BreitWignerVectorized(std::vector<Double_t> xx)
13 {
14  std::vector<Double_t> result(xx.size());
15  for(Int_t i=0;i<xx.size();i++)
16  {
17  result[i]=TMath::BreitWigner(xx[i]);
18  }
19  return result;
20 }
21 
22 double BreitWignerWrap( double x){
23  return TMath::BreitWigner(x);
24 }
25 
26 
28 {
29 
31 
33 
34  Double_t value=r.Eval("integrate(BreitWigner, lower = -2, upper = 2)$value");
35 
36  std::cout.precision(18);
37  std::cout<<"Integral of the BreitWigner Function in the interval [-2, 2] R = "<<value<<std::endl;
38 
39 
42  value=i.Integral(-2,2);
43  std::cout<<"Integral of the BreitWigner Function in the interval [-2, 2] MathMore = "<<value<<std::endl;
44 
45 
46  TF1 f1("BreitWigner","BreitWignerWrap(x)");
47  value=f1.Integral(-2,2);
48  std::cout<<"Integral of the BreitWigner Function in the interval [-2, 2] TF1 = "<<value<<std::endl;
49 
50  //infinte limits
51  value=r.Eval("integrate(BreitWigner, lower = -Inf, upper = Inf)$value");
52  std::cout<<"Integral of BreitWigner Function in the interval [-Inf, Inf] R = "<<value<<std::endl;
53 
54 }
Double_t BreitWigner(Double_t x, Double_t mean=0, Double_t gamma=1)
Calculate a Breit Wigner function with mean and gamma.
Definition: TMath.cxx:442
std::vector< Double_t > BreitWignerVectorized(std::vector< Double_t > xx)
Definition: Integration.C:12
double BreitWignerWrap(double x)
Definition: Integration.C:22
int Int_t
Definition: RtypesCore.h:41
virtual Double_t Integral(Double_t a, Double_t b, Double_t epsrel=1.e-12)
IntegralOneDim or analytical integral.
Definition: TF1.cxx:2241
Template class to wrap any C++ callable object which takes one argument i.e.
Double_t x[n]
Definition: legend1.C:17
double Integral(Function &f, double a, double b)
evaluate the Integral of a function f over the defined interval (a,b)
Definition: Integrator.h:506
ROOT::R::TRInterface & r
Definition: Object.C:4
User Class for performing numerical integration of a function in one dimension.
Definition: Integrator.h:102
void Integration()
Definition: Integration.C:27
double Double_t
Definition: RtypesCore.h:55
static TRInterface & Instance()
static method to get an TRInterface instance reference
1-Dim function class
Definition: TF1.h:149
TF1 * f1
Definition: legend1.C:11
double result[121]
float value
Definition: math.cpp:443
Int_t Eval(const TString &code, TRObject &ans)
Method to eval R code and you get the result in a reference to TRObject.
Definition: TRInterface.cxx:58
This is a class to pass functions from ROOT to R