25.6. F. Common Fit Functions
Table of Contents
Overview
This appendix lists common fit functions that you will use frequently with ROOT. It focuses on their standard mathematical form, typical ROOT usage, and common parameter conventions. You can use this as a quick reference when choosing and configuring a model for your fit.
Whenever you see a function written as a textual expression in ROOT, it is usually passed as a string to a TF1 or to a fitting method, for example:
TF1 *f = new TF1("f", "gaus", xmin, xmax);
hist->Fit("f");
In the tables below, “par[0]”, “par[1]”, and so on refer to the internal parameter array of a TF1 object.
Important rule: The meaning of parameters in ROOT’s built‑in function codes (for example "gaus") follows ROOT conventions and is not always the same as textbook amplitude or normalization. Always check the parameter definition before interpreting fit results.
Gaussian and Related Peak Functions
Standard Gaussian
ROOT built‑in code: "gaus" (or "gausn" for normalized form).
Mathematical form for "gaus":
$$
f(x) = p_0 \exp\!\left( -\frac{1}{2} \left( \frac{x - p_1}{p_2} \right)^2 \right)
$$
Parameter mapping:
| Parameter | Name (common) | Meaning |
|---|---|---|
| par[0] | amplitude | Peak height at $x = \mu$ |
| par[1] | mean | $\mu$, central value of the peak |
| par[2] | sigma | $\sigma$, standard deviation of peak |
The integral of this form is:
$$
\int_{-\infty}^{\infty} f(x)\,dx = p_0 \, p_2 \sqrt{2\pi}.
$$
ROOT also provides "gausn", which is normalized such that:
$$
\int_{-\infty}^{\infty} f(x)\,dx = p_0,
$$
so in that case par[0] represents the total area under the Gaussian.
Gaussian parameters: In "gaus", par[0] is the height of the peak, not the area. In "gausn", par[0] is the area (integral). Always choose the variant that matches how you want to interpret the result.
Typical usage:
TF1 *g = new TF1("g", "gaus", xlow, xhigh);
hist->Fit("g");Multiple Gaussians
You can sum multiple Gaussians to model more complex structures or overlapping peaks. ROOT does not have a special keyword for this, you combine them in an expression, for example:
TF1 *g2 = new TF1("g2",
"gaus(0) + gaus(3)", // first gaus uses par[0..2], second gaus uses par[3..5]
xlow, xhigh);Here:
| Sub‑function | Parameters |
|---|---|
gaus(0) | par[0], par[1], par[2] |
gaus(3) | par[3], par[4], par[5] |
The parameter meaning is the same as for "gaus".
Crystal Ball Function
The Crystal Ball function is often used in particle physics to model a Gaussian core with a power‑law tail, usually on the low side.
A common definition is:
$$
f(x;\alpha,n,\bar{x},\sigma) =
N \times
\begin{cases}
\exp\!\left( -\frac{(x-\bar{x})^2}{2\sigma^2} \right), & \text{for } \frac{x-\bar{x}}{\sigma} > -\alpha, \\
A \left( B - \frac{x-\bar{x}}{\sigma} \right)^{-n}, & \text{for } \frac{x-\bar{x}}{\sigma} \le -\alpha,
\end{cases}
$$
with
$$
A = \left( \frac{n}{|\alpha|} \right)^n \exp\!\left( -\frac{|\alpha|^2}{2} \right),
\quad
B = \frac{n}{|\alpha|} - |\alpha|.
$$
ROOT provides several variants such as crystalball in ROOT::Math. In many analyses, users implement their own C++ function or a TF1 with an expression. A typical parameter order is:
| par index | Meaning |
|---|---|
| par[0] | Overall normalization $N$ |
| par[1] | Mean $\bar{x}$ |
| par[2] | Width $\sigma$ |
| par[3] | Tail parameter $\alpha$ |
| par[4] | Tail exponent $n$ |
Crystal Ball conventions: There are several sign conventions and parameter orders in use. Always document your chosen definition and check that your code and interpretation agree.
Polynomial Functions
General Polynomial
ROOT built‑in code: "polN" where N is the order, for example "pol0", "pol1", "pol2", and so on.
General form for "polN":
$$
f(x) = \sum_{k=0}^{N} p_k\,x^k.
$$
Examples:
- Constant (offset)
"pol0":
$$
f(x) = p_0
$$ - Linear
"pol1":
$$
f(x) = p_0 + p_1 x
$$ - Quadratic
"pol2":
$$
f(x) = p_0 + p_1 x + p_2 x^2
$$
Parameter mapping:
"polN" | Parameter | Meaning |
|---|---|---|
| any | par[k] | coefficient of $x^k$ |
Usage example:
TF1 *lin = new TF1("lin", "pol1", xlow, xhigh);
hist->Fit("lin"); // linear fitPolynomials are often used to describe smooth backgrounds under peaks.
Polynomial order: Use the lowest polynomial order that adequately describes the background. High‑order polynomials can absorb features that should belong to your signal and can lead to unstable fits.
Exponential and Power Law Functions
Exponential Functions
ROOT built‑in code: "expo" for a simple exponential.
Standard "expo" form:
$$
f(x) = \exp\left(p_0 + p_1 x\right).
$$
This can also be written as:
$$
f(x) = A \exp(\lambda x),
\quad
A = e^{p_0},
\quad
\lambda = p_1.
$$
Parameter mapping:
| Parameter | Meaning |
|---|---|
| par[0] | log amplitude, $\ln A$ |
| par[1] | exponential slope, $\lambda$ |
Usage example:
TF1 *ex = new TF1("ex", "expo", xlow, xhigh);
hist->Fit("ex");If you want a non‑standard exponential form, such as $A \exp(-x/\tau)$, you can define it explicitly:
TF1 *ex2 = new TF1("ex2", "[0]*exp(-x/[1])", xlow, xhigh);
// par[0] = A, par[1] = tauPower Laws
ROOT does not have a dedicated keyword for simple power laws, but they are easy to define with an expression:
General power law:
$$
f(x) = A x^{n}.
$$
You can write this in ROOT as:
TF1 *powlaw = new TF1("powlaw", "[0]*pow(x, [1])", xlow, xhigh);
// par[0] = A, par[1] = n
Or, to avoid issues near $x = 0$, you may shift the variable:
$$
f(x) = A (x - x_0)^n,
$$
using, for example,
TF1 *powlawShift = new TF1("powlawShift", "[0]*pow(x-[2],[1])", xlow, xhigh);
// par[0] = A, par[1] = n, par[2] = x0Exponential vs power law: Exponentials behave as straight lines in a semi‑log plot, while power laws are straight lines in a log‑log plot. Choose the function that matches the physical expectation and the scaling behavior of your data.
Breit–Wigner and Resonance Shapes
Resonances in particle physics are often modeled with Breit–Wigner functions or variants that include detector resolution.
Nonrelativistic Breit–Wigner
A simple Breit–Wigner line shape (also known as a Lorentzian) is:
$$
f(E) = \frac{A}{(E - E_0)^2 + (\Gamma / 2)^2},
$$
where:
| Symbol | Meaning |
|---|---|
| $A$ | amplitude or scale factor |
| $E_0$ | resonance energy (position) |
| $\Gamma$ | full width at half maximum (FWHM) |
A common ROOT definition:
TF1 *bw = new TF1("bw",
"[0]/((x-[1])*(x-[1]) + 0.25*[2]*[2])",
xlow, xhigh);
// par[0] = A, par[1] = E0, par[2] = GammaRelativistic Breit–Wigner
A relativistic version is used when the energy dependence is important, for example:
$$
f(m) = \frac{A\,m_0\Gamma}{(m^2 - m_0^2)^2 + m_0^2\Gamma^2},
$$
where $m$ is the invariant mass, $m_0$ is the resonance mass, and $\Gamma$ is the width.
You can implement this with:
TF1 *rbw = new TF1("rbw",
"[0]*[1]*[2] / ((x*x - [1]*[1])*(x*x - [1]*[1]) + [1]*[1]*[2]*[2])",
xlow, xhigh);
// par[0] = amplitude, par[1] = m0, par[2] = GammaDetector resolution is often modeled by convolving a Breit–Wigner with a Gaussian. In practice, this is often approximated with specialized functions (for example, Voigt profile) or with numerical convolutions.
Resonance fits: The choice between nonrelativistic and relativistic Breit–Wigner, and the inclusion of detector resolution, can significantly affect extracted masses and widths. The function form must match the physics model you want to test.
Step, Error, and Sigmoid Functions
Error Function and Integrated Gaussian
The error function is related to the integral of a Gaussian and is useful for modeling turn‑on curves and cumulative distributions.
Standard definition:
$$
\operatorname{erf}(z) = \frac{2}{\sqrt{\pi}} \int_0^z e^{-t^2}\,dt.
$$
ROOT provides TMath::Erf for use in expressions:
TF1 *turnOn = new TF1("turnOn",
"[0] * 0.5 * (1 + TMath::Erf((x-[1]) / (sqrt(2)*[2])))",
xlow, xhigh);
// par[0] = plateau height, par[1] = threshold, par[2] = sigma of turn-onThis function represents a smoothed step, similar to the integral of a Gaussian.
Logistic (Sigmoid) Function
A logistic function is another common model for efficiency curves and smooth steps:
$$
f(x) = \frac{A}{1 + \exp\left( -\frac{x - x_0}{k} \right)},
$$
where $A$ is the plateau value, $x_0$ is the midpoint, and $k$ controls the slope.
In ROOT:
TF1 *sigm = new TF1("sigm",
"[0] / (1 + exp(-(x-[1])/[2]))",
xlow, xhigh);
// par[0] = A, par[1] = x0, par[2] = kTurn‑on functions: For trigger or detector efficiency curves, a smoothed step such as an error function or logistic function is usually more realistic than a sharp step. Using a discontinuous function can cause unstable fits and unphysical parameter errors.
Combinations of Signal and Background
Most realistic fits involve both a signal component and a background component. ROOT lets you combine any of the previously defined functions into a composite model.
Typical Signal plus Background Model
A common example is a Gaussian signal plus a polynomial background:
TF1 *model = new TF1("model",
"gaus(0) + pol1(3)", // Gaussian uses par[0..2], linear background uses par[3..4]
xlow, xhigh);Parameter mapping:
| Index range | Sub‑function | Typical meaning |
|---|---|---|
| 0,1,2 | gaus(0) | signal amplitude, mean, sigma |
| 3,4 | pol1(3) | background offset and slope |
Another example is a Breit–Wigner plus exponential background:
TF1 *model2 = new TF1("model2",
"[0]/((x-[1])*(x-[1]) + 0.25*[2]*[2]) + exp([3] + [4]*x)",
xlow, xhigh);
// par[0..2] = resonance parameters, par[3..4] = log amplitude and slope of backgroundYou can also build more complex combinations, for example multiple peaks over a curved background.
Composite model parameters: When combining sub‑functions like gaus(0) and pol1(3), keep a clear record of which parameter index corresponds to which physical quantity. Mislabeling parameters is a common source of confusion and incorrect physics conclusions.
Discrete Distributions for Counting
Although histograms are typically fitted with continuous functions, you may occasionally need to fit discrete distributions, especially for low‑count data.
Poisson Distribution
The Poisson probability mass function is:
$$
P(k; \mu) = \frac{\mu^k e^{-\mu}}{k!}, \quad k = 0,1,2,\dots
$$
In ROOT, you can use TMath::Poisson or TMath::PoissonI in an expression:
TF1 *pois = new TF1("pois", "[1]*TMath::PoissonI(x, [0])", -0.5, 19.5);
// par[0] = mean mu, par[1] = overall scale (for counts)
Here TMath::PoissonI(k, mu) gives the probability for integer k. You often scale by a normalization factor to compare to histogram counts.
Binomial Distribution
The binomial probability mass function is:
$$
P(k; n, p) = \binom{n}{k} p^k (1-p)^{n-k}.
$$
ROOT provides TMath::Binomial:
TF1 *bino = new TF1("bino",
"[2]*TMath::Binomial([0], x)*pow([1], x)*pow(1-[1], [0]-x)",
-0.5, n + 0.5);
// par[0] = n, par[1] = p, par[2] = scaleFor most practical histogram fits, especially for larger counts, Poisson or binomial models are more often used via likelihood fits rather than direct function fitting.
Discrete data: For very low statistics, chi‑square fits with continuous functions can give biased results. In that case, use binned or unbinned likelihood methods that treat the counts as Poisson or binomial variables.
Using Built‑In Math Functions in Expressions
ROOT’s fit functions can use many functions from TMath and the C standard library directly in the function string. Some commonly used ones in fit definitions are:
| Function | Description |
|---|---|
exp(x) | exponential |
log(x) | natural logarithm |
sqrt(x) | square root |
sin(x), cos(x) | trigonometric functions |
TMath::Erf(x) | error function |
TMath::BreitWigner(x, m0, gamma) | Breit–Wigner function |
TMath::Voigt(x, sigma, gamma) | Voigt profile (Gaussian convoluted with Lorentzian) |
Example with TMath::BreitWigner:
TF1 *rbw2 = new TF1("rbw2",
"[0]*TMath::BreitWigner(x, [1], [2])",
xlow, xhigh);
// par[0] = amplitude, par[1] = m0, par[2] = Gamma
Expression functions: When using TMath functions in expressions, ensure the correct namespace and argument order. Mistakes in the function call often lead to subtle mis‑modeling rather than obvious errors.
This appendix is intended as a starting point. For precise and up‑to‑date details, always consult the ROOT reference for TF1, TMath, and the specific classes or functions you use in your fits.
Views: 0
Where to Move
Move chapter:
- ☰ 1. Introduction to ROOT
- ☰ 1.1. What Is ROOT?
- ☰ 1.2. Installing ROOT
- ☰ 1.3. Starting ROOT
- ☰ 1.4. Your First ROOT Session
-
- ☰ 2. C++ Basics for ROOT
- ☰ 2.1. Why ROOT Uses C++
- ☰ 2.2. Variables and Data Types
- ☰ 2.3. Operators
- ☰ 2.4. Conditional Statements
- ☰ 2.5. Loops
- ☰ 2.6. Functions
- ☰ 2.7. Arrays and Vectors
-
- ☰ 3. ROOT Macros
- ☰ 3.1. What Is a ROOT Macro?
- ☰ 3.2. Running ROOT Macros
- ☰ 3.3. Functions Inside ROOT Macros
- ☰ 3.4. Compiling ROOT Macros
- ☰ 3.5. Organizing a ROOT Project
-
- ☰ 4. ROOT Objects and the ROOT Object Model
- ☰ 4.1. Introduction to ROOT Classes
- ☰ 4.2. Object Names and Titles
- ☰ 4.3. ROOT Collections
- ☰ 4.4. Inspecting ROOT Objects
-
- ☰ 5. Histograms
- ☰ 5.1. Introduction to Histograms
- ☰ 5.2. Creating a 1D Histogram
- ☰ 5.3. Filling Histograms
- ☰ 5.4. Drawing Histograms
- ☰ 5.5. Histogram Properties
- ☰ 5.6. Accessing Histogram Bins
- ☰ 5.7. Histogram Errors
- ☰ 5.8. Normalizing Histograms
- ☰ 5.9. Combining Histograms
-
- ☰ 6. Two-Dimensional Histograms
- ☰ 6.1. Creating 2D Histograms
- ☰ 6.2. Filling 2D Histograms
- ☰ 6.3. Drawing 2D Histograms
- ☰ 6.4. Projections
- ☰ 6.5. Profiles
-
- ☰ 7. Graphs
- ☰ 7.1. Introduction to TGraph
- ☰ 7.2. Creating a TGraph
- ☰ 7.3. Graph Styling
- ☰ 7.4. TGraphErrors
- ☰ 7.5. TGraphAsymmErrors
- ☰ 7.6. MultiGraph
-
- ☰ 8. Canvases and Plotting
- ☰ 8.1. TCanvas
- ☰ 8.2. Dividing a Canvas
- ☰ 8.3. Drawing Multiple Objects
- ☰ 8.4. Legends
- ☰ 8.5. Text and Annotations
- ☰ 8.6. Logarithmic Axes
- ☰ 8.7. Saving Plots
-
- ☰ 9. Styling ROOT Plots
- ☰ 9.1. ROOT Plot Styles
- ☰ 9.2. Axis Configuration
- ☰ 9.3. Line Styles
- ☰ 9.4. Marker Styles
- ☰ 9.5. Publication-Quality Figures
-
- ☰ 10. Mathematical Functions
- ☰ 10.1. Introduction to TF1
- ☰ 10.2. Built-in Functions
- ☰ 10.3. Custom Functions
- ☰ 10.4. Evaluating Functions
- ☰ 10.5. Function Integrals
-
- ☰ 11. Curve Fitting
- ☰ 11.1. Introduction to Fitting
- ☰ 11.2. Gaussian Fits
- ☰ 11.3. Polynomial Fits
- ☰ 11.4. Custom Fit Functions
- ☰ 11.5. Fit Parameters
- ☰ 11.6. Goodness of Fit
- ☰ 11.7. Fit Residuals
- ☰ 11.8. Fitting Graphs
-
- ☰ 12. ROOT Files
- ☰ 12.1. Introduction to ROOT Files
- ☰ 12.2. Creating ROOT Files
- ☰ 12.3. Writing Objects
- ☰ 12.4. Reading ROOT Files
- ☰ 12.5. Exploring ROOT Files
- ☰ 12.6. Directories Inside ROOT Files
-
- ☰ 13. TTrees
- ☰ 13.1. Introduction to TTrees
- ☰ 13.2. Creating a TTree
- ☰ 13.3. Filling a TTree
- ☰ 13.4. Writing a TTree to a File
- ☰ 13.5. Reading a TTree
- ☰ 13.6. Inspecting TTrees
- ☰ 13.7. Drawing Data from TTrees
- ☰ 13.8. Applying Selection Cuts
- ☰ 13.9. Branch Addresses
-
- ☰ 14. Event-Based Data Analysis
- ☰ 14.1. Understanding Event Data
- ☰ 14.2. Event Loops
- ☰ 14.3. Event Selection
- ☰ 14.4. Derived Quantities
- ☰ 14.5. Analysis Workflow
-
- ☰ 15. Working with Real Experimental Data
- ☰ 15.1. Importing Text Data
- ☰ 15.2. Converting Data to ROOT
- ☰ 15.3. Data Cleaning
- ☰ 15.4. Data Calibration
- ☰ 15.5. Signal and Background
-
- ☰ 16. Random Numbers and Simulations
- ☰ 16.1. Random Number Generation
- ☰ 16.2. Common Distributions
- ☰ 16.3. Simple Monte Carlo Simulation
- ☰ 16.4. Detector Resolution Simulation
- ☰ 16.5. Efficiency Simulation
-
- ☰ 17. Statistical Analysis with ROOT
- ☰ 17.1. Basic Statistics
- ☰ 17.2. Probability Distributions
- ☰ 17.3. Statistical Uncertainties
- ☰ 17.4. Chi-Square Tests
- ☰ 17.5. Confidence Intervals
-
- ☰ 18. Modern ROOT with RDataFrame
- ☰ 18.1. Introduction to RDataFrame
- ☰ 18.2. Loading Data
- ☰ 18.3. Filtering Data
- ☰ 18.4. Defining New Columns
- ☰ 18.5. Creating Histograms
- ☰ 18.6. Statistical Operations
- ☰ 18.7. Saving Results
- ☰ 18.8. Multithreading
-
- ☰ 19. ROOT and Python
- ☰ 19.1. Introduction to PyROOT
- ☰ 19.2. ROOT Objects in Python
- ☰ 19.3. Reading ROOT Files with Python
- ☰ 19.4. PyROOT and NumPy
- ☰ 19.5. PyROOT and Matplotlib
- ☰ 19.6. Choosing Between C++ and Python
-
- ☰ 20. Advanced TTree Techniques
- ☰ 20.1. Trees with Multiple Branches
- ☰ 20.2. Storing std::vector Objects
- ☰ 20.3. TChain
- ☰ 20.4. Friends
- ☰ 20.5. Efficient TTree Analysis
-
- ☰ 21. ROOT for Particle and Nuclear Physics
- ☰ 21.1. Four-Vectors
- ☰ 21.2. Particle Kinematics
- ☰ 21.3. Invariant Mass
- ☰ 21.4. Angular Distributions
- ☰ 21.5. Detector Spectra
-
- ☰ 22. Debugging and Common ROOT Problems
- ☰ 22.1. ROOT Object Ownership
- ☰ 22.2. Null Pointers
- ☰ 22.3. Segmentation Faults
- ☰ 22.4. Missing Histograms
- ☰ 22.5. ROOT File Problems
- ☰ 22.6. TTree Branch Problems
- ☰ 22.7. Histogram Range Problems
- ☰ 22.8. Fit Failures
- ☰ 22.9. Debugging ROOT Macros
-
- ☰ 23. Writing Better ROOT Analysis Code
- ☰ 23.1. Separating Analysis and Plotting
- ☰ 23.2. Using Functions
- ☰ 23.3. Using Header Files
- ☰ 23.4. Naming Conventions
- ☰ 23.5. Avoiding Hard-Coded Values
- ☰ 23.6. Configuration Parameters
- ☰ 23.7. Reproducible Analysis
- ☰ 23.8. Version Control with Git
-
- ☰ 24. Final Project
- ☰ 24.1. Project Overview
- ☰ 24.2. Analyze a complete scientific dataset using ROOT.
- ☰ 24.3. Import the Data
- ☰ 24.4. Explore the Dataset
- ☰ 24.5. Apply Data Selection
- ☰ 24.6. Create Histograms
- ☰ 24.7. Fit the Data
- ☰ 24.8. Calculate Physical Quantities
- ☰ 24.9. Estimate Statistical Uncertainties
- ☰ 24.10. Create Publication-Quality Figures
- ☰ 24.11. Save the Analysis Results
- ☰ 24.12. Write a Short Analysis Report
-
- ☰ 25. Appendices
- ☰ 25.1. A. ROOT Command Cheat Sheet
- ☰ 25.2. B. ROOT Histogram Classes
- ☰ 25.3. C. ROOT Graph Classes
- ☰ 25.4. D. Common TTree Commands
- ☰ 25.5. E. Common Drawing Options
- ☰ 25.6. F. Common Fit Functions
- ☰ 25.7. G. ROOT C++ Cheat Sheet
- ☰ 25.8. H. PyROOT Cheat Sheet
- ☰ 25.9. I. Common ROOT Errors and Solutions
- ☰ 25.10. J. Recommended ROOT Analysis Workflow
-
Comments
Please login to add a comment.
Don't have an account? Register now!