SLAC PEP-II
BABAR
SLAC<->RAL
Babar logo
HEPIC E,S & H Databases PDG HEP preprints
Organization Detector Computing Physics Documentation
Personnel Glossary Sitemap Search Hypernews
Unwrap page!
Comp. Search
Who's who?
Meetings
FAQ Homepage
Archive
Environment
Administration
New User Info.
Web Info/Tools
Monitoring
Training
Tools & Utils
Programming
C++ Standard
SRT, AFS, CVS
QA and QC
Remedy
Histogramming
Operations
PromptReco
Simulation Production
Online SW
Dataflow
Detector Control
Evt Processing
Run Control
Calibration
Databases
Offline
Workbook
Coding Standards
Simulation
Reconstruction
Prompt Reco.
BaBar Grid
Data Distribution
Beta & BetaTools
Kanga & Root
Analysis Tools
RooFit Toolkit
Data Management
Data Quality
Event display
Event Browser
Code releases
Databases
Check this page for HTML 4.01 Transitional compliance with the
W3C Validator
(More checks...)

Stuff that might be useful when working with ROOT

Some of the following got posted to roottalk in the past. Some was lying around in the old tutorials. Some was provided by users. Some was taken from user support mails. Some might be wrong, please complain if you find examples that don't work in your preferred version of ROOT.

Some of the macros given below need input, most often hsimple.root (which you get by executing the 'hsimple' demo -- try .x hsimple.C).

Histograms

Plot TH1 in directory

Draw a TH1 that is in a subdirectory of a ROOT file

Two Stats boxes

Draw a second statistics box (when overlaying histograms)

No Histogram Title

Get rid of the histogram title box

Rotated Histogram

A function to draw a TH1 rotated by 90 degrees. (needs hsimple.root) picture

Rotated Histograms II

Draw a 2-d plot and the projections on top and side (needs hsimple.root) picture

Merge rootfiles with histograms

Small executable to merge histograms in different rootfiles (needs Makefile)

Fill histogram into arrays

Works for both 1-d and 2-d histograms

h/get_vect/cont

Plot two 1-d histograms against each other picture

Trees

Copy trees

Copy a tree from one file to another

Merge rootfiles with trees

Small executable to merge trees in different root files (needs Makefile)

Scan trees

Print Variables of a tree (and select events in that tree)

Write subset of tree into file

Uses TEventList to copy tree entries

Fit two ntuple columns

Do you know how to do this in PAW? (needs hsimple.root)

2d arrays in trees

With 'optimal' packing

Display of 2 trees

How to make a scatter plot of variables from different trees

Reduce number of variables

Copy part of the variables of a tree into another file

Enhanced subset of tree

Take a tree, dump a few of its variables and new variables into a new tree

Draw all branches

Loop over all branches of a tree and draw their variable

Graphics

Custom Colors

Define your own colors

LEP-style plots

How to create world-average, checks, ... plots picture

No red box

Remove the red box around your pad/canvas

PAW-like style

Get a better style than the default

Overlay two graphs

Overlay two graphs with a different scale picture

Axis labelling

Rotate long bin labels picture

Fitting

Goodness of fit

Get chi2 and ndof

Constant + double Gaussian

How to define a non-trivial function and fit interactively

Minuit: error matrix

How to display the error matrix plot and txt

Minuit: Error and correlation matrix

How to access internal parameters of Minuit

Fit a TH1+TF1 to a TH1

Using a combination of function and histogram in a fit to a histogram picture

Fit a TH2D in slices

Slice a 2-d histogram and fit a function to all slices

Fit with 'discontinuous' function

Fit histogram with function having gaps picture

Functions

Splines

Use splines to interpolate a graph picture

Draw Integral

Given f(t,S), draw the integral F(S) = I_t1^t2 f(t,S) dt as a function of S

Piece-wise function

Define a function with f(x) for x < x1 and g(x) for x > x1 picture

Improve function drawing

Use more points for the interpolation during function drawing

Predefined function definition

Define functions with built-in functions

User function definition

Define functions in a separate file

Function drawing

Some options useful for function drawing

Miscellaneous

Invoke one macro from another

How to execute '.x' a macro from another macro

Loop over all histograms

Loop over all histograms in a file and draw them

Decouple histogram from file

Read a histogram from a file and close the file afterwards

Reading data files

Read in many files in a directory (C++ style)

Opening all rootfiles in a directory

Read in many files in a directory (C-Style)

Write TH1 to file

Save a TH1 from one ROOT file into another ROOT file

Wait between plots

GUI and keyboard-driven examples how to wait between plots

Macro for interactive and compiled use

Skeleton for a macro with necessary #ifdef's for CINT

If you have a macro or function that you find very useful, please consider contributing it to this page.


Page Author: Urs Langenegger
Last significant update: 03/04/2004