KAHIBARO
Discord Login Register

10.2. Built-in Functions

Gaussian

ROOT provides several built‑in Gaussian function types that you can use directly with TF1, without writing any C++ code. The most common one is "gaus". When you create a TF1 like

cpp
TF1 *f = new TF1("f", "gaus", xmin, xmax);

ROOT interprets "gaus" as the standard Gaussian function

$$
f(x) = A \exp\left( -\frac{1}{2} \left( \frac{x - \mu}{\sigma} \right)^2 \right)
$$

with three parameters:

Parameter indexMeaning
0$A$ (normalization)
1$\mu$ (mean)
2$\sigma$ (width)

You can set or read these parameters through the usual TF1 parameter methods that are introduced in the chapter on TF1. For example,

cpp
f->SetParameters(1.0, 0.0, 1.0);  // A, mu, sigma

sets a Gaussian with unit amplitude, centered at zero, with $\sigma = 1$. ROOT will later adjust these parameters automatically if you use the function as a fit model.

ROOT also provides variants that allow you to specify the parameters in the expression itself, but "gaus" is the basic building block that is most often used for fits to peaks in histograms, especially in particle and nuclear physics. When you fit, ROOT automatically prints the mean and sigma from the Gaussian parameters, which you can convert to physical quantities such as energy resolution or detector timing resolution.

In ROOT, the built‑in Gaussian "gaus" always has three parameters in the order: amplitude, mean, sigma. The mathematical formula is
$$
f(x) = p_0 \exp\left( -\frac{1}{2}\left( \frac{x - p_1}{p_2} \right)^2 \right).
$$

Polynomial

Polynomials are another important family of built‑in functions. ROOT uses the name "polN" for a polynomial of degree $N$. For example

cpp
TF1 *p1 = new TF1("p1", "pol1", xmin, xmax);  // linear
TF1 *p2 = new TF1("p2", "pol2", xmin, xmax);  // quadratic
TF1 *p5 = new TF1("p5", "pol5", xmin, xmax);  // 5th degree

A polynomial of degree $N$ is defined as

$$
f(x) = \sum_{i=0}^{N} p_i x^i
$$

where $p_i$ are the TF1 parameters. For example, "pol1" corresponds to

$$
f(x) = p_0 + p_1 x
$$

and "pol2" corresponds to

$$
f(x) = p_0 + p_1 x + p_2 x^2.
$$

You control the coefficients through the TF1 parameter interface. For instance

cpp
p2->SetParameters(1.0, -0.5, 0.1);  // p0, p1, p2

creates the polynomial

$$
f(x) = 1.0 - 0.5 x + 0.1 x^2.
$$

Polynomials are widely used as simple background models. In many physics analyses a narrow signal peak modeled by a Gaussian sits on top of a slowly varying background modeled by a low order polynomial. In ROOT, you can combine a polynomial and a Gaussian by writing an expression like

cpp
TF1 *f = new TF1("f", "gaus(0) + pol1(3)", xmin, xmax);

which uses the first three parameters for the Gaussian, and the next two for the linear background. The exact syntax for parameter indexing is explained in more detail when custom function expressions are discussed, but the key point here is that "polN" gives you a ready made polynomial that you can include in such expressions.

The built‑in polynomial "polN" uses parameters as coefficients:
$$
f(x) = \sum_{i=0}^{N} p_i x^i.
$$
For "pol1" this is
$$
f(x) = p_0 + p_1 x.
$$

Exponential functions

ROOT also includes exponential functions as built‑in models. The most commonly used is "expo" which represents an exponential of a linear function in $x$:

cpp
TF1 *e = new TF1("e", "expo", xmin, xmax);

By definition in ROOT, "expo" corresponds to

$$
f(x) = \exp(p_0 + p_1 x)
$$

where $p_0$ and $p_1$ are the first two TF1 parameters. Very often, this is interpreted as

$$
f(x) = \exp(\ln A - \lambda x) = A e^{-\lambda x}
$$

so that $p_0 = \ln A$ and $p_1 = -\lambda$. In that case, $A$ is a normalization constant and $\lambda$ controls the slope or decay constant.

You can set starting values, for instance

cpp
e->SetParameters(std::log(100.0), -0.5);  // p0 = ln(A), p1 = -lambda

which creates approximately

$$
f(x) = 100.0\, e^{-0.5 x}.
$$

In many experimental situations, especially when modeling decays or attenuations, an exponential can appear on its own, or as part of a more complex model combined with other built‑in functions. For example, you might model a falling background under a peak with an exponential and the peak itself with a Gaussian. In ROOT, this can be written as

cpp
TF1 *f = new TF1("f", "gaus(0) + expo(3)", xmin, xmax);

which uses parameters 0 to 2 for the Gaussian and 3 to 4 for the exponential.

The built‑in exponential "expo" in ROOT is defined as
$$
f(x) = \exp(p_0 + p_1 x).
$$
To obtain a form $A e^{-\lambda x}$, use $p_0 = \ln A$ and $p_1 = -\lambda$.

These built‑in Gaussian, polynomial, and exponential functions are designed to be combined and reused with TF1. They provide standard building blocks that you can quickly plug into your analyses and fits without having to reimplement common mathematical expressions.

Views: 10

Comments

Please login to add a comment.

Don't have an account? Register now!