- The names x, y, and z: These denote the 3 dimensions.
- The terms [0], [1], ... These are elements of a parameter array. Initially, when a TFormula object is instantiated they are all set to zero but can subsequently be set, individually or collectively.
- Standard operators such as + - * / && || == != < <= > >= ...
- Standard functions such as sin, asin, sinh, exp, log ...
- Gausians, exponentials and power series that use both the dimensions and the parameter array.
- Previously defined TFormula objects.

Polynomials are denoted by:-

dpoln(i) where:- d = dimension = x(default if omitted), y or z n = dimension of the power series i = index of first parameter element so:- pol3(5) or xpol3(5) is equivalent to [5]+[6]*x+[7]*x**2+[8]*x**3In a similar way:-

xgaus(i) is equivalent to [i]*exp(-0.5*((x-[i+1])/[i+2])**2) xexpo(i) is equivalent to exp([i]+[i+1]*x)Try this in ROOT as a simple example:-

- They can be 1, 2 or 3 dimensional: TF1, TF2 and TF3 respectively.
- They are bounded in all dimensions.
- The underlying formula can either be a TFormula object or a user written C function.
- They can draw, integrate and differentiate themselves.
- They can be passed to histogram objects for fitting.

As we shall see shortly the TF1, TF2, TF3 classes are used in histogram fitting. They inherit from TFormula and the parameters of the TFormula object are used as the fit parameters. Flexible though TFormula is, it can only describe a simple analytic form and there are times when the form of a fitted function needs to be more complex. To allow for this, TF1, TF2 and TF3 can take a user C defined function. The function definition is of the form:-

- Array x - array containing x, (and possibly y and z - for 2D and 3D functions).
- Array parm - array of fit parameters.

Now the parameters are loaded and finally the TF1 draws itself for the line 2 + 3x:-

- Create a file called tf1.cxx containing the above.
- Run ROOT.
- Load the code:
.L tf1.cxx - Call the test function:
test_c_func();

The next line is were all the action takes place:-

- Its not a pointer to TF1 object that is passed, but its
*name.*ROOT's ability to access objects by name was a subject dealt with in the Inheritance lesson. It so happens that in this case the name of the TF1 object (the first arg in its constructor) is the same as the name of its pointer. That's a common convention, but nothing more, its the object name that the Fit() message requires. - This is a miniature example of a typical OO program, passing one object to another and then letting them interact to achieve a task. The TF1 object "knows all about" functions, including how to draw them. The TH1F object "knows all about histograms" including how to fit them using the abstraction of a function which TF1 implements.

- TFormula are objects that encapsulate the concept of an expression
in x, y and z. The expression can involve user assignable parameters,
standard maths functions and operators. For example:-
TFormula *my_formula = new TFormula("my_formula","[0] + [1]*sin(x)"); my_formula->SetParameter(0, 2.); my_formula->SetParameter(1, 3.); my_formula->Eval(20.); evaluates 2 + 3*sin(20.) The full list of supported expressions can be found in TFormula - TF1, TF2 and TF3 represent 1, 2 and 3 dimensional functions that can
be based on TFormula objects or user written C functions. Functions can
draw, differentiate and integrate themselves and are used as the basis for
histogram fitting. For example:-
TF1 *fun1 = new TF1("fun1","abs(sin(x)/x)",0,10); fun1->Draw() - TF1, TF2 and TF3 objects whose Tformula, or user C function,
involves parameters can be passed to histogram's Fit() message:-
my_hist->Fit(my_tf1) After fitting the TF1, TF2 and TF3 object's parameters hold the fit result.

Go Back to the The First Steps Top Page

If you have any comments about this page please send them to Nick West