ROOT as calculator

Now that you have installed ROOT, what's this interactive shell thing you're running ? It's like this: ROOT leads a double life. It has an interpreter for macros (Cling [@Cling]) that you can run from the command line or run like applications. But it is also an interactive shell that can evaluate arbitrary statements and expressions. This is extremely useful for debugging, quick hacking and testing. Let us first have a look at some very simple examples.

ROOT as calculator

You can even use the ROOT interactive shell in lieu of a calculator! Launch the ROOT interactive shell with the command

> root

on your Linux box. The prompt should appear shortly:

root 

and let's dive in with the steps shown here:

root  1+1
(int)2
root  2*(4+2)/12.
(double) 1.000000e+00
root  sqrt(3.)
(double) 1.732051e+00
root  1 > 2
(bool) false
root  TMath::Pi()
(Double_t) 3.141593e+00
root  TMath::Erf(.2)
(Double_t) 2.227026e-01

Not bad. You can see that ROOT offers you the possibility not only to type in C++ statements, but also advanced mathematical functions, which live in the TMath namespace.

Now let's do something more elaborated. A numerical example with the well known geometrical series:

root  double x=.5
(double) 5.000000e-01
root  int N=30
(int) 30
root  double geom_series=0
(double) 0.000000e+00
root  for (int i=0;i<N;++i)geom_series+=TMath::Power(x,i)
root  TMath::Abs(geom_series - (1-TMath::Power(x,N-1))/(1-x))
(Double_t) 1.862645e-09

Here we made a step forward. We even declared variables and used a for control structure. Note that there are some subtle differences between Cling and the standard C++ language. You do not need the ";" at the end of line in interactive mode -- try the difference e.g. using the command at line root .