# First steps with ROOT

Note

Before you can use ROOT, it must be successfully installed and all environment variables must be set. → See Installation Guide.

In particular, it is recommended to add the following command to the .profile or .login file so that the environment variables are properly defined at each login.

source /path/to/install-or-build/dir/bin/thisroot.sh


## Starting and quitting a ROOT session

### Starting ROOT

You start ROOT at the system prompt.

Type at the system prompt:

$root  The ROOT prompt is displayed.  ------------------------------------------------------------------ | Welcome to ROOT 6.22/02 https://root.cern | | (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers | | Built for macosx64 on Aug 17 2020, 12:46:52 | | From tags/v6-22-02@v6-22-02 | | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' | ------------------------------------------------------------------ root [0]  To display a list of ROOT commands, type: .help  A list of ROOT commands is displayed.  Cling (C/C++ interpreter) meta commands usage All commands must be preceded by a '.', except for the evaluation statement { } ============================================================================== Syntax: .Command [arg0 arg1 ... argN] .L <filename> - Load the given file or library .(x|X) <filename>[args] - Same as .L and runs a function with signature: ret_type filename(args) .> <filename> - Redirect command to a given file '>' or '1>' - Redirects the stdout stream only '2>' - Redirects the stderr stream only '&>' (or '2>&1') - Redirects both stdout and stderr '>>' - Appends to the given file .undo [n] - Unloads the last 'n' inputs lines .U <filename> - Unloads the given file .I [path] - Shows the include path. If a path is given - adds the path to the include paths .O <level> - Sets the optimization level (0-3) (not yet implemented) .class <name> - Prints out class <name> in a CINT-like style .files - Prints out some CINT-like file statistics .fileEx - Prints out some file statistics .g - Prints out information about global variable 'name' - if no name is given, print them all .@ - Cancels and ignores the multiline input .rawInput [0|1] - Toggle wrapping and printing the execution results of the input .dynamicExtensions [0|1] - Toggles the use of the dynamic scopes and the late binding .printDebug [0|1] - Toggles the printing of input's corresponding state changes .storeState <filename> - Store the interpreter's state to a given file .compareState <filename> - Compare the interpreter's state with the one saved in a given file .stats [name] - Show stats for internal data structures 'ast' abstract syntax tree stats 'asttree [filter]' abstract syntax tree layout 'decl' dump ast declarations 'undo' show undo stack .help - Shows this information .q - Exit the program ROOT special commands. ========================================================================== .pwd : show current directory, pad and style .ls : list contents of current directory .which [file] : shows path of macro file .help Class : opens the reference guide for that class .help Class::Member : opens the reference guide for function/member  ### Starting ROOT with command line options ROOT command line tools ROOT also provides many command line tools at the system prompt for simple file operations or automating common operations performed on ROOT classes. → See ROOT command line tools You can start ROOT with the following command line options: -b: ROOT session runs in batch mode, without graphics display. This mode is useful in case you do not want to set the DISPLAY. -n: Does not execute the logon script and logoff script as specified in .rootrc. -q: Exits after processing the command line macro files. -l: Does not show the ROOT banner. -a: Displays the ROOT splash screen. -x: Exits on exception. dir: If dir is a valid directory, change to it (cd) before executing ROOT. -?, -h, --help: Prints usage. -config: Prints the ./configure options. -memstat: Runs ROOT with memory usage monitoring. ### Quitting ROOT Type at the ROOT prompt: .q  ## Using the interactive C++ interpreter Cling ROOT uses the interactive C++ interpreter Cling that is built on top of the Low Level Virtual Machine (LLVM) and the Clang libraries. Cling provides a command line prompt and a just-in-time (JIT) compiler for compilation. For more information on Cling, → see Cling. Note When using the interactive interpreter Cling, unlike to pure C++ language, no semicolon (;) is required at the end of the line. ### Simple commands You can use ROOT to execute simple commands at the ROOT prompt. Every command typed at the ROOT prompt is stored in the .root_hist file in your home directory. Examples Simple operations: Relational operators: Calling a function from a ROOT class like TMath::Pi: ### Multi-line commands You can use ROOT to execute multi-line commands at the ROOT prompt. 1. To start a multi-line command, type at the ROOT prompt:{ 2. Type one command per line. 3. To end the multi-line command, type:} Example You can also write the commands to a file, called a ROOT macro, and then execute and compile it. For more information on ROOT macros, → see ROOT macros and shared libraries. ## Regular expressions You can use the following meta-characters in regular expressions: ˆ: Start-of-line anchor. $: End-of-line anchor.

.: Matches any character.

[: Start a character class.

]: End a character class.

ˆ: Negates character class if first character.

*: Kleene closure (matches 0 or more).

+: Positive closure (1 or more).

?: Optional closure (0 or 1).