Walkthrough: Starting ROOT
(5 minutes)
ROOT is a robust, complex environment for performing physics analysis, and you can spend a lifetime learning it.1
To actually run ROOT, just type this if you’ve not already done so:
> root
Command window
The Terminal window in which you type this command will become your ROOT command window.2 You’ll see some “Welcome to ROOT” text in the window.
You can type .help to see a list of ROOT commands. You’ll probably
get more information than you can use right now. Try it and see.
For the moment, the most important ROOT line command is the one to quit
ROOT. To exit ROOT, type .q. Do this now and then start ROOT again,
just to make sure you can do it.
Dealing with crashes
Sometimes ROOT will crash. If it does, it can get into a state for which
.q won’t work. Try typing .qqq (three q) if .q doesn’t work;
if that still doesn’t work, try five q, then seven q. Unfortunately, if
you type ten q, ROOT won’t respond, “You’re welcome.”
OK, that’s a dumb joke; I should leave the humor to xkcd. But the tip
about .qqq, .qqqqq, and .qqqqqqq is legitimate. Sometimes I
find just typing q or using Ctrl-C also works.
ROOT as a calculator
One of the defining features of Python is that if you just type in a
equation or a variable, it will simply print it out. ROOT can do the same
thing, but you have to use
For example:
[] int x = 5
(int) 5
[] x
(int) 5
[] 2+3
(int) 5
[] sqrt(2)
(double) 1.4142136
C++ types
If you’re familiar with Python, one difference you’ll notice
immediately: int x=5 instead of just x=5 for
ROOT to accept the statement without an error message. x=5 will
still work (give it a try) but ROOT will complain.
You can ask C++ to deduce the type for you by using the keyword auto:
[] auto x = 5
(int) 5
[] auto z = 5.0
(double) 5.0000000
As a matter of programming style, I specify explicit types for base
C++ types like numbers and strings, but use auto for complicated
derived types like std::map<int,double>::const_iterator.
I’m not going to dwell on this aspect of ROOT, but it’s good to know it’s there.4
Figure 6: https://xkcd.com/217/ by Randall Munroe.
If you want to try this in ROOT, it’s exp(TMath::Pi()) - TMath::Pi()
- 1
That’s three lifetimes so far.
In case you missed it, lifetime #2 was spent learning emacs.
- 2
In case you skipped over the Getting started section, or you don’t like clicking on links in the middle of Notes: You will need two terminal windows open during this section of the tutorial: a UNIX window and a ROOT window.
- 3
ROOT’s command line uses a full-fledged
C++ interpreter, cling. If you want to experiment withC++ without compiling anything, ROOT makes it easy to do.Honesty compels me to add that there are other C++ command-line interpreters other than ROOT; for example, Clang-Repl.
- 4
If it matters, ROOT’s trig functions use radians by default. If you want to take the sine of 30 degrees you have to use
sin(30.*TMath::Pi()/180.)