Loop over leaves from root file

I am trying to loop over leaves from a root file such as most of those leaves are declared as vectors
T->GetEntry(i) // show some errors

Note that the objective of this script is to calculate the number of hits by an event.
Please find attached a script describing this issue and the root file.

output.root (42.8 KB)
reader.cc (476 Bytes)


You need to load dictionaries (shared libraries) for classes that are used in your ROOT file.

Hi @eddymaoui ,
to elaborate @Wile_E_Coyote 's comment further, when opening the file with root output.root you should see:

~/Downloads root -l output.root
root [0]
Attaching file output.root as _file0...
Warning in <TClass::Init>: no dictionary for class Event is available
Warning in <TClass::Init>: no dictionary for class Neutrino is available
Warning in <TClass::Init>: no dictionary for class BaseTrack is available
Warning in <TClass::Init>: no dictionary for class Vec3D is available
Warning in <TClass::Init>: no dictionary for class Primary is available
Warning in <TClass::Init>: no dictionary for class McTrack is available
Warning in <TClass::Init>: no dictionary for class Hit is available
Warning in <TClass::Init>: no dictionary for class RawHit is available
Warning in <TClass::Init>: no dictionary for class Header is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::XSecFile is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::String is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::AsciiIO is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::detector is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::muon_desc_file is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::node is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::target is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::drawing is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::physics is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::generator is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::simul is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::cut_primary is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::cut is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::cut_seamuon is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::cut_in is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::cut_nu is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::start_run is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::spectrum is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::PM1_type_area is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::PDF is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::model is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::can is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::genvol is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::merge is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::coord_origin is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::genhencut is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::k40 is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::norma is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::Vector<MONTE_CARLO::seed> is available
Warning in <TClass::Init>: no dictionary for class MONTE_CARLO::livetime is available
(TFile *) 0x5570321f4350

These warnings mean that ROOT won’t know how to read branches of those types from the file, because the corresponding “I/O information” (stored in ROOT dictionaries) is missing. See also I/O of custom classes - ROOT for documentation on generating dictionaries for your classes, and GitHub - eguiraud/root_dictionaries_tutorial: A tutorial on creating ROOT dictionaries to perform I/O of custom C++ classes for some practical examples.

Cheers,
Enrico

These warnings mean that ROOT won’t know how to read branches of those types from the file, because the corresponding “I/O information”

More exactly, those warnings means that ROOT does not know about object of this type and thus you will not be able to read the data into those kind of objects.

However, the ROOT files are ‘self describing’ and there is many ways to still be able to read the data without the original data (The easiest is to use RDataFrame but there is other alternatives).