Open a file to read data

Hello,

I dont have a very deep knowlage of root so I would like to know if its possible to read a given .root file so i can see the data inside in the form of columns. I know i can use TBrowser to see the data but that representation gives me an histogram and i would like to see just the raw data i have written inside a given file so i can understand how to perform my analisis.

Thanks for the attention.

Best regards,
André Miranda

How to “see inside” an object depends on what type of object it is (TTree, TGraph, TH1…).
From the terminal (outside ROOT) you can do:

$ rootls -l yourfile.root

to see what’s inside, e.g. (1st col. is the type; name is after the year):

$ rootls -l hsimple.root
TProfile  Apr 12 17:27 2022 hprof;1  "Profile of pz versus px"
TH1F      Apr 12 17:27 2022 hpx;1    "This is the px distribution"
TH2F      Apr 12 17:27 2022 hpxpy;1  "py vs px"
TNtuple   Apr 12 17:27 2022 ntuple;1 "Demo ntuple"

Supposing you have a TTree named “mytree” (like “ntuple” above), you could open the file directly when opening ROOT and then do mytree->Scan() to see all columns and data:

$ root hsimple.root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.26/06                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Jul 28 2022, 18:08:51                 |
  | From tags/v6-26-06@v6-26-06                                      |
  | With c++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0                   |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0]
Attaching file hsimple.root as _file0...
(TFile *) 0x7fffbe06d280
root [1] ntuple->Scan()
************************************************************************
*    Row   *     px.px *     py.py *     pz.pz * random.ra *       i.i *
************************************************************************
*        0 * 0.0194094 * 0.0118254 * 0.0005165 * 0.2826178 *         0 *
*        1 * 0.3271895 * 0.0378782 * 0.1084877 * 0.4849736 *         1 *
*        2 * -0.294611 * -0.010545 * 0.0869072 * 0.5400436 *         2 *
*        3 * -0.774589 * 0.0484584 * 0.6023373 * 0.6586366 *         3 *
*        4 * -1.430795 * 0.5090636 * 2.3063209 * 0.5196720 *         4 *
*        5 * 0.2889872 * -1.864742 * 3.5607798 * 0.3923139 *         5 *

...etc

The first part was very usefull thanks. I can now see the objects inside my file, but i cant use the second code for reading, I think its because I just have directory files.

waves_file_obj

https://root.cern/doc/master/group__tutorial__io.html

rootls -h
rootls -l yourfile.root:*

So can you understand from this information how many columns of data do I have?
I would like to check, if possible the dimension of the data stored on my file, but im having trouble with that.

rootls -t yourfile.root:* # prints also TTree branches

Making that in my file comes with an error:

The first “bold” string in each line is the name of the class of the object that is stored (e.g., “TTime”, “TH1D”, “TH2I”).

Well, the “CalibrationCoefficient” class is not a standard ROOT class. You need to inspect its documentation (or contact its authors).

@Axel / @etejedor Looks like one needs to improve the parser so that it does not die on unknown classes.

Thanks, I have created `rootls` should not show errors when seeing a branch of class without dictionary · Issue #11675 · root-project/root · GitHub

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.