ROOT Version: 6.36.04
Platform: macosxarm64
Compiler: Not Provided
Hi ROOTers!
I have a relatively basic question about reading a branch from a TTree
, which might be a bit of a rehash of some older questions about reading multi-dimensional arrays [1, 2] (but perhaps worth rehashing, since those threads are from some time ago…)
In this case, I have a tree produced by Delphes [3] (I’ve attached the file as an example), and I’m trying to read it without the Delphes library loaded – so I’m trying to read the leaves of the collections of objects it has saved to a tree using TTreeReaderValue
and TTreeReaderArray
.
For the most part this works. However, some objects have a fixed-length array as one of their leaves – so I’m effectively looking at a multi-dimensional array, where one dimension is variable (how many objects are in this event) and the other fixed (the length of the object’s member variable array). For example, here’s the relevant snippet from TTree::Print()
for one of these branches:
*............................................................................*
*Br 15 :EFlowPhoton.Edges[4] : Float_t Edges[EFlowPhoton_] *
*Entries : 10 : Total Size= 9662 bytes File Size = 4171 *
*Baskets : 1 : Basket Size= 64000 bytes Compression= 2.17 *
*............................................................................*
It’s not clear to me if/how I can properly read this within the TTreeReader
paradigm. I’ve found that I can create a TTreeReaderArray
if I pass the name of the leaf including the size in brackets, i.e.
TFile* f = new TFile("events.delphes.root","READ");
TTree* t = (TTree*)f->Get("Delphes");
TTreeReader reader(t);
TTreeReaderArray<Float_t> etArray(reader,"EFlowPhoton.ET"); // a float branch, one value per EFlowPhoton
TTreeReaderArray<Float_t> edgesArray(reader,"EFlowPhoton.Edges[4]"); // using just "EFlowPhoton.Edges" won't work, get a warning that such a branch/sub-branch doesn't exist when calling TTreeReader::SetEntry()
reader.SetEntry(0);
ULong64_t nObjects = etArray.GetSize();
cout << (edgesArray.GetSize() == nObjects) << endl; // prints "1" (True)
In the above example, it looks like edgesArray
lets me access EFlowPhoton::fEdges[0]
for each EFlowPhoton
object, but I don’t see how I can get the other entries in the array.
In practice, I can fully read this branch by doing the reading the “old-fashioned” way with TTree::SetBranchAddress()
but it’d be great to be able to somehow handle this with TTreeReader
otherwise one is forced to, at best, mix the two tree reading paradigms for cases like this. The posts I ref’d below suggest that some kind of support for multi-dim arrays may have been planned at some point – is this still the case?
– Jan
[1] How to read second rank array using TTreeReader
[2] TTreeReader for 2d array
[3] https://delphes.github.io / GitHub - delphes/delphes: A framework for fast simulation of a generic collider experiment
events.delphes.root (881.1 KB)