Questions on ROOT syntax

// Kindly bear my ignorance and help me learn the syntax.
// Please correct me with my comments and questions in the following ROOT code:

//=======
#include “TF1.h”
// to ensure that a 1-dimensional formula can be defined

#include “Math/WrappedTF1.h”
// to wrap the defined formula
// why and for what reasons is the “wrapping”?

#include “Math/GaussIntegrator.h”
// is this the choice of integrator with a “Gaussian measure”?

int GaussIntegratorOneDim()
// should this be the same name at the filename?
{
TF1 f(“f”, “exp(x)”, 0, TMath::Pi());
// f - is the name of the formula
// exp(x) - is the defined formula
// 0, TMath::Pi() - is the range of the variable x
// -> is it really necessary to set the range?
// -> what happens when you integrate beyond the set range?

ROOT::Math::WrappedTF1 wf1(f);
// why does the function have to be wrapped?

ROOT::Math::GaussIntegrator ig;
// defining the integrator

ig.SetFunction(wf1);
// setting of the function
// “ig.SetFunction(wf1, false);” - i do not know why this does not work
// but why does it work without the “false” parameter?

ig.SetRelTolerance(0.001);
// what is this function?
// can it be set arbitrarily?

cout << ig.Integral(0, TMath::PiOver2()) << endl;
cout << ig.Integral(1, 0) << endl;

return 0;
// what does this mean?
// what happens when I put “return 1;” instead?
}
//=======
// Thanks always for your help - Jaybee

If you use the macro execution .x FileName.C then the function matching the filename FileName is executed. If you instead load the macro using .L FileName.C then there does not need to be a function with a name matching the filename. https://root.cern.ch/working-macros

It is commonly accepted that a return value of zero for a program means success. There is no explicit need for it here and can be removed if the function signature is changed from int to void.

I am learning today… thanks ksmith :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.