How to open root files (ROOT Framework)

Sagar Maher picture Sagar Maher · Jan 14, 2016 · Viewed 19.9k times · Source

How to open .root file in C++ code ? and read and print parameter from .root file using C++ code on terminal ?

Answer

Asen Christov picture Asen Christov · Jan 18, 2016

you need to install ROOT (https://root.cern.ch/)

then you have couple of options, the simplest is opening it in the interpreter by simply typing in the console:

root your_file.root

and you can look at it in the Browser, type in :

TBrowser b

to open it from a script/C++ code and get the tree stored in it:

#include "TFile.h"
#include "TTree.h"

TFile *f=new TFile("your_file.root");
TTree *tr=(TTree*)f->Get("the_tree_name");