Convert root file to txt, csv file

Hi all, I would like to convert the root file to a more intuitive way of storing data, such as txt, csv file format, can anyone solve this problem, thank you very much (Linux, Ubuntu 16.04, ROOT 6.10/02)


Welcome to the ROOT community!

I do not think ROOT provides something out of the box to achieve that, but it should be enough to read your binary ROOT files in Python or C++ to then create the ASCII file in the format you see fit.
I just feel compelled to write that, while you can easily achieve human readable files, you will unavoidably end up with an I/O system which is far less efficient than the one natively provided by ROOT.


You can easily get a readable text version of some ROOT objects using dedicated methods like Print() (for histograms and graph) or Scan() for trees. This is useful to visually check the data but, as Danilo said, not recommended for storage (specially histograms and tress).

some (loosely related) ideas:

there’s a simple root2csv command in the groot package (a Go-based set of libraries and commands).


See also

import ROOT

df = ROOT.RDataFrame("mytree", "myfile.root")
npy_arrays = df.AsNumpy()

You can then easily output any type of trivial data format from the numpy arrays.


(Linux, Ubuntu 16.04, ROOT 6.10/02)

This is an ancient system and ROOT version, I highly suggest you update.


1 Like