liminfo

CERN ROOT Reference

Free reference guide: CERN ROOT Reference

26 results

About CERN ROOT Reference

The CERN ROOT Reference is a searchable cheat sheet for the ROOT data analysis framework widely used in high-energy physics. It covers 27 key classes and commands organized into six categories: Histograms (TH1F, TH2F, TH1D, TProfile, THStack), TTree (TTree, Draw, TChain, TTreeReader, SetBranchAddress), Fitting (TF1, Fit, RooFit, TMinuit), Graphics (TCanvas, TGraph, TGraphErrors, TLegend, gStyle), File I/O (TFile, TFile::Open, hadd), and Physics Analysis (TLorentzVector, RDataFrame, TCut, TMath).

Each entry includes a description of the class purpose, ready-to-use C++ code examples showing constructor syntax, method calls, and typical usage patterns. Whether you are plotting invariant mass distributions, fitting Gaussian peaks, or processing millions of events with RDataFrame, this reference provides the code patterns you need.

Designed for particle physics graduate students, postdocs, and researchers at CERN and labs worldwide, this tool runs entirely in the browser with Korean/English support, dark mode, and mobile-responsive design.

Key Features

  • 27 ROOT classes and commands covering histograms, trees, fitting, graphics, file I/O, and physics analysis
  • Histogram types explained: TH1F (1D float), TH2F (2D), TH1D (double precision), TProfile (bin-averaged), and THStack (overlay)
  • Complete TTree workflow: creating branches, TTree::Draw for quick plots, TChain for multi-file analysis, TTreeReader for type-safe access, and SetBranchAddress for classic reading
  • Fitting tools from basic TF1 with built-in functions (gaus, pol2) to RooFit extended likelihood fits and TMinuit minimization
  • Graphics essentials: TCanvas (multi-pad layouts, PDF export), TGraph/TGraphErrors (scatter plots with error bars), TLegend, and gStyle settings
  • File I/O including TFile open/create/save, multi-protocol support (local, xrootd, HTTP), and hadd for merging ROOT files
  • Physics analysis classes: TLorentzVector for 4-momentum operations, RDataFrame for declarative analysis, TCut for event selection, and TMath utility functions
  • All code examples use proper C++ syntax matching ROOT 6 conventions with correct constructor arguments and method signatures

Frequently Asked Questions

What ROOT classes does this reference cover?

It covers 27 entries across 6 categories: Histograms (TH1F, TH2F, TH1D, TProfile, THStack), TTree (TTree, TTree::Draw, TChain, TTreeReader, SetBranchAddress), Fitting (TF1, Fit, RooFit, TMinuit), Graphics (TCanvas, TGraph, TGraphErrors, TLegend, gStyle), File I/O (TFile, TFile::Open, hadd), and Physics Analysis (TLorentzVector, RDataFrame, TCut, TMath). Each includes ready-to-use C++ code examples.

How do I create and fill a histogram in ROOT?

Create with TH1F *h = new TH1F("name", "Title;X;Y", nbins, xmin, xmax), fill with h->Fill(value), and draw with h->Draw(). For 2D histograms, use TH2F with two axis ranges and h->Fill(x, y). The reference shows constructor syntax, fill methods, and draw options like "COLZ" for 2D color plots.

What is the difference between TTreeReader and SetBranchAddress?

TTreeReader is the modern, type-safe interface: you declare TTreeReaderValue<Type> variables and iterate with reader.Next(). SetBranchAddress is the classic approach where you manually bind branch pointers and call GetEntry(i) in a loop. TTreeReader is recommended for new code as it catches type mismatches at compile time and is less error-prone.

How do I fit a Gaussian to a histogram?

The simplest way is h->Fit("gaus") which uses a built-in Gaussian function. For more control, create TF1 *f = new TF1("f", "gaus", xmin, xmax), set initial parameters with f->SetParameters(amplitude, mean, sigma), and call h->Fit(f, "R"). For advanced fits, the reference also covers RooFit with RooGaussian and TMinuit for custom chi-square minimization.

What is RDataFrame and when should I use it?

RDataFrame is ROOT's modern declarative analysis framework. Instead of writing explicit event loops, you chain Filter(), Define(), and Histo1D() calls. Example: ROOT::RDataFrame df("Events", "data.root"); auto h = df.Filter("pt > 25").Histo1D(...). It automatically parallelizes on multiple cores and is the recommended approach for new ROOT 6 analyses.

How do I calculate invariant mass with TLorentzVector?

Create two TLorentzVectors, set them with SetPtEtaPhiM(pt, eta, phi, mass), add them (TLorentzVector sum = p1 + p2), and call sum.M() for the invariant mass. This is the standard method for reconstructing particle decays, such as Z boson to dimuon (setting mass to muon mass 0.105 GeV).

How do I merge multiple ROOT files?

Use the hadd command-line tool: "hadd merged.root file1.root file2.root" or "hadd -f output.root input_*.root" with wildcards. For programmatic merging or when processing files across protocols, use TChain to chain TTrees from multiple files: chain->Add("data_*.root"). The reference covers both approaches.

Is this reference suitable for ROOT beginners?

Yes. Each entry shows the essential constructor syntax and most common usage pattern with working code examples. Beginners can start with TH1F for histograms, TTree::Draw for quick plots, and TFile for saving results. The reference progresses to advanced topics like RooFit, RDataFrame, and TMinuit for users who need them. All examples follow ROOT 6 C++ conventions.