SetBranchAddress with and without splitting of TBranchElements

Hi rooters,

I have a root file with many different trees and I want to access all of its variables. I am creating properly the friendship of the trees and I am able to get successfully the variables of almost all the trees by using for example:

vector < float > GenP_Pt;
TBranch *b_GenP_Pt;
fChain -> SetBranchAddress(“partPt”, &GenP_Pt, &b_GenP_Pt)

But, the tree which is under l1TracksTree (and it is named eventTree) has different structure (as you can see from the rootfile attached) and the same way of addressing the branches is returning me empty vectors with enormous sizes.

If I try to use vectors of pointers (which is what MakeClass() is telling me to do) I get a segmentation fault on fChain->GetEntry(iEntry).

Does anyone know what is the proper way to get the variables of the last tree?


L1Ntuple_EBTP_HGCalTP_L1_L1TTracklet_onMC_L1_FEVTHLTDEBUG_TRACK_GEN_TT_nevt_10.root (825.8 KB)

I tried your tree with a MakeClass generated analysis skeleton and it seems fine to me:

root [0] .L eventTree.C
root [1] eventTree t; // some warnings about unavailable dictionaries appear
root [2] t.GetEntry(0);
root [3] t.trk_pt->size()
(const unsigned long)149
root [4] t.trk_pt->at(0)
(vector<float,allocator<float> >::reference)2.22559070587158203e+00
root [5] t.trk_pt->at(1)
(vector<float,allocator<float> >::reference)2.06306195259094238e+00
root [7] t.GetEntry(1);
root [8] t.trk_pt->size()
(const unsigned long)153
root [9] t.trk_pt->at(0)
(vector<float,allocator<float> >::reference)2.16367387771606445e+00
root [10] t.trk_pt->at(1)
(vector<float,allocator<float> >::reference)2.09600806236267090e+00

eventTree.C (1.4 KB)
eventTree.h (9.7 KB)

Hi Wile,

Thank you very much, but the same way does not work for me unfortunately using the whole tree.
I believe that the problem arises because of creating a friendship between trees with different structures and when I do SetMakeClass(1) to both the trees maybe it cannot synchronize them or something similar!
But I am not sure, I am just guessing! Did you happen to know anything about how exactly the friendship is done?

I think you need to give more precise details (e.g. a minimal “reproducer” would be helpful) and then @pcanal may be able to help.

If I just remove the pointers from the .C file (and remove the part that is making all the vector pointers zero) and follow what you did in the previous message I get:

root [4]
(float) 0.00000f
root [5] t.trk_pt.size()
(unsigned long) 18446744073695880084

Why is this happening in the first place? Why do we need pointer vectors instead of just vectors?

eventTree.h (9.7 KB)
eventTree.C (1.4 KB)

Hi again,

I created a minimal reproducer of the problem and actually the problem seems to arise when I am not using pointers to get the branches of the eventTree.

So, in the files attached I am creating a friendship between the two trees (these trees have different structure) and I am able to get variables from both trees successfully.

The thing is that I am working in a framework that seems to have problem when using a pointer! It gives me a segmentation fault when it is getting the entry.

Is there a way that I can make it work without using pointer vectors for the eventTree?
(all you need to do to reproduce my problem is to make the trk_pt a simple vector and comment out the trk_pt = 0;)

Thank you in advance,

eventTree.h (4.9 KB)
eventTree.C (1.4 KB)

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

Not at the moment. (i.e. SetBranchAddress could be upgraded to support passing the address of an object rather than the address of a pointer but we have not had the effort needed to do this improvement).