KAHIBARO
Discord Login Register

Starting ROOT

Starting the ROOT interactive shell

To begin using ROOT you usually start its interactive shell. This shell is called root and lets you type commands, run macros, and inspect objects interactively.

On most systems, you start ROOT from a terminal by typing:

bash
root

and pressing Enter. If ROOT is installed correctly and your environment is set up, you will see a welcome banner and then a prompt similar to:

text
root [0]

This root [0] prompt means that ROOT is ready to accept C++ commands. The number in brackets counts the commands you enter during the current session.

If your system has multiple versions of ROOT, you might need to load a specific environment first, for example:

bash
source /path/to/thisroot.sh
root

or use a module system provided by your lab or cluster:

bash
module load root
root

Exactly how you do this depends on how ROOT was installed. The important point is that once you can type root and see the interactive prompt, you are ready for the rest of this course.

Interactive ROOT can also start in “quiet” mode with fewer messages:

bash
root -q

or without the splash banner:

bash
root -l

Exiting ROOT

To stop an interactive ROOT session and return to the regular shell, you can use several equivalent commands at the ROOT prompt:

cpp
.q

or

cpp
.q;

You can also call:

cpp
gApplication->Terminate(0);

but for normal use, .q is standard and simplest.

On many systems you can also press Ctrl+D in the terminal while at the ROOT prompt to exit. However, .q is the most reliable and portable way.

Always exit ROOT cleanly with .q before closing your terminal, especially if you are writing output files. This helps ensure that files are properly closed and data is written completely.

Basic ROOT commands

The ROOT prompt accepts C++ code and also a small set of special commands that begin with a dot. These dot commands control ROOT itself. You will use both types.

A few basic examples at the ROOT prompt:

Simple arithmetic:

cpp
root [0] 1 + 2
(int) 3

Using standard C++ output:

cpp
root [1] std::cout << "Hello ROOT" << std::endl;
Hello ROOT

Defining a variable:

cpp
root [2] int n = 42;
root [3] n
(int) 42

ROOT dot commands:

Load and execute a macro file (you will learn about macros later):

cpp
root [4] .x mymacro.C

Change the current working directory:

cpp
root [5] .cd /path/to/dir

Print the current working directory:

cpp
root [6] .pwd

List objects currently in memory or in the current directory:

cpp
root [7] .ls

Show the current ROOT session’s include paths:

cpp
root [8] .include

You can also call ROOT C++ functions directly. For example, to open the ROOT object browser (a graphical window for exploring objects):

cpp
root [9] new TBrowser;

Dot commands like .q, .x, .ls, .cd, and .pwd are not C++ statements. They are interpreted directly by ROOT. They always start with a dot and never end with a semicolon.

Command history

ROOT keeps a history of the commands you type, which makes interactive work much more efficient.

You can navigate through previous commands using the arrow keys directly at the ROOT prompt:

Up arrow: move backward through past commands.
Down arrow: move forward again toward more recent commands.
Left and right arrows: edit the current line.

This behaves much like a typical shell such as bash.

You can also use partial search. Start typing a command, then press the up arrow. ROOT will search backward in the history for commands that begin with what you have typed.

ROOT stores the command history in a file, typically named .root_hist in your home directory. This means that when you start a new ROOT session, your old commands are still available via the arrow keys.

If you want to see the history from within ROOT, one simple way is to use a shell escape:

cpp
root [0] .! cat ~/.root_hist

The .! prefix runs a system command. This is not needed for everyday use, but it shows that your history is saved.

To reuse a long command, press the up arrow until you find it, then edit just the part you need instead of retyping everything.

Getting help

ROOT provides several ways to get help and learn about available classes and functions while you work.

Inside the interactive shell you can inspect classes with the ClassDef information and built in introspection tools. One simple and very commonly used function is:

cpp
root [0] gROOT->GetListOfClasses()->Print();

which prints the list of known classes, although this is quite long. More practical is to focus on a specific class.

To learn about a particular class, for example TH1F, you can call:

cpp
root [1] TH1F h("h", "Example", 10, 0, 1);
root [2] h.Print();

which prints information about that object. To see the class name of any object:

cpp
root [3] h.ClassName()
(const char *) "TH1F"

The ROOT object browser is another source of help. Start it with:

cpp
root [4] new TBrowser;

A graphical window will appear. You can explore classes, files, and objects, and double click on items to see how ROOT interacts with them.

ROOT also has many online resources. The most important is the ROOT reference guide, which you should keep in mind from the very beginning:

The official ROOT reference guide with full class documentation is at:
https://root.cern/doc/master/

From that site you can search for any class, such as TH1, TFile, or TTree, and see lists of member functions, usage examples, and inheritance diagrams.

If you forget a function name or want to explore available methods for an object during an interactive session, you can use C++ tab completion at the ROOT prompt. For example:

cpp
root [5] h.

then press the Tab key. ROOT will show possible completions like h.Draw, h.Fill, and many others. You can select one and continue typing. This tab completion is one of the most convenient “help” tools when you are experimenting.

You can also use:

cpp
root [6] .help

in some ROOT builds, which will print a short summary of dot commands or redirect you to documentation. If .help is not enabled in your version, rely on the reference guide and tab completion.

As you progress through the course, combining tab completion, object inspection with Print(), and the online reference guide will be your main way to find out how to use new ROOT features without leaving the interactive environment.

Views: 10

Comments

Please login to add a comment.

Don't have an account? Register now!