TRefArray apears empty (reading via makeClass)

Last week this forum gave me some assistance in reading my TTree, you kindly pointed out that MakeClass was the place to start.
Following these instruction I generated a class from my tree, there where some errors in the auto-generated code (from MakeClass) but once they were fixed it ran.
I can now reliably read all values from the TTree apart from the ones that are TRefArrays.

The TRefArrays appear empty, although to have strong reason to suspect they are not.

Attached are the tree, the class and it’s header. example.zip (892.7 KB)

If you put them all in a folder and do;

$ root
root [0] TFile f("tag_1_delphes_events.root")
root [1] TTree  * t = (TTree *) f.Get("Delphes")
root [2] .L $ROOTSYS/test/libEvent.so  // need to have run make in $ROOTSYS/test/ for this library to exist
root [3] // Bunch of errors but ignore for now
root [4] .L madgraphDefaults.C
root [5] madgraphDefaults reader
root [6] reader.GetEntry(2)
root [7] reader.Jet_Pt                         // its an array of Float_t
root [8] // works beautifully, list of floats.
root [9] reader.Jet_Constituents               // its a TRefArray
root [10] // appears empty... but I am relatively certain that it isn't

My confidence that there should be entries in Jet_Constituents comes from playing with another tool,
ExRootAnalysis, which was able to pick the momentum vectors of tracks in the jets.
If ExRootAnalysis could do this then information about which track is in which jet
must be found somewhere in the TTree.

How can I get the values of Jet_Constituents?

Thanks, H

P.S. I think my problem is the same as Reading TRefArray from PyROOT but if I try that I get AttributeError: 'TObject' object has no attribute 'Constituents'

It may also be the same as Wanted: Event structure example but I’m having trouble following that one.

You may have better luck using MakeSelector instead (MakeClass is not very good at reading objects).

Cheers,
Philippe.

I will give MakeSelector a shot. Thanks for the tip.

The link to get sample data ftp://root.cern.ch/root/h1analysis/ given at the top of https://root.cern.ch/root/htmldoc/guides/users-guide/ExampleAnalysis.html doesn’t appear to go anywhere. Is that my browser?

Ok, so again the auto generated code had some issues with identifying the right types for the variables, but after fixing that it runs.
Again I can use it to read out all variables but the TRefArrays.
The issue this time isn’t that they look empty, it’s that calling the methods of the TRefArray seems to cause a seg fault.

Here is a cut down example of my selector class;

#define Delph_selector_cxx

#include "Delph_selector.h"
#include <TH2.h>
#include <TStyle.h>


void Delph_selector::Begin(TTree * tree)
{
    ~ blah blah ~
}

void Delph_selector::SlaveBegin(TTree * /*tree*/)
{
    ~ blah blah ~
}

Bool_t Delph_selector::Process(Long64_t entry)
{
   printf("In the process function\n");
   printf("entry number %d \n", int(entry));

   fReader.SetEntry(entry);

   if (true) {
       Int_t  bucket = * Jet_size.Get();
       Float_t fork[bucket];
       TRefArray gravel[bucket];
       for(int i = 0; i < bucket; i++)
       {
           fork[i] = Jet_PT.At(i);
           cout << fork[i] << " "; // works fine
           Jet_Constituents.At(i);  // runs
           Jet_Constituents.At(i).IsEmpty();  //seg fault. I expected a bool.
           
       }

       cout << bucket << endl;
   }

   return kTRUE;
}

void Delph_selector::SlaveTerminate()
{
}

void Delph_selector::Terminate()
{
}

Full files here; files.zip (885.6 KB)

It can be launched with;

$ root
root [0] TChain chain("Delphes");
root [1] chain.Add("tag_1_delphes_events.root");
root [2] chain.Process("Delph_selector.C")

Am I handling the Jet_Constituents wrong?

Edit;
So the TTree created by $ROOTSYS/tutorial/jets.C also has a TRefArray in it, and it’s reasonable to assume this tree is well formed.
I have the same problems (seg fault) trying to read the TRefArray in that TTree using code generated by MakeSelector. I can read the other branches just not the TRefArray branches (e.g. fJets_fPt works fine but fJets_fTracks causes seg faults).

Any pointers?

Hi,

This case was not support in TTreeReader. You will need to use the commit (soon to be merged) in https://github.com/root-project/root/pull/3761

And also use (update the .h file)

   TTreeReaderArray<TRefArray> Jet_Constituents = {fReader, "Jet.Constituents"};

Cheers,
Philippe.