Reading a tree containing vector<TLorentzVector>

Dear all,

I was given a tree filled with vector’s and tried to read it with TSelector, but failed because of the following name clashes (C-style comments added by me, C++ comments by MakeSelector):

/* (…) */
//TLorentzVector lep_l;
/
UInt_t fUniqueID; /
/
UInt_t fBits; /
/
UInt_t fP_fUniqueID; /
/
UInt_t fP_fBits; /
/
Double_t fP_fX; /
/
Double_t fP_fY; /
/
Double_t fP_fZ; /
/
Double_t fE; /
/
(…) */
//TLorentzVector lep_nl;
/
UInt_t fUniqueID; /
/
UInt_t fBits; /
/
UInt_t fP_fUniqueID; /
/
UInt_t fP_fBits; /
/
Double_t fP_fX; /
/
Double_t fP_fY; /
/
Double_t fP_fZ; /
/
Double_t fE; /
/
(…) */

Now, one of the branches is supposed to contain TLorentzVector’s representing jets. I tried to change the .h file this way (commenting away everything written by MakeSelector):

std::vector* jetVec;
TBranch* b_jetVec;

and later

fChain->SetBranchAddress(“jet”, &jetVec, &b_jetVec);

Then, inside Process(), I wrote few simple lines:

b_RunNumber->GetEntry(entry);
b_EventNumber->GetEntry(entry);
cerr << "event " << EventNumber << " from run " << RunNumber << “:” << endl;

b_jetVec->GetEntry(entry);
cerr << " b_jetVec " << b_jetVec << endl;

cerr << " jetVec " << jetVec << endl;

unsigned nJets = jetVec->size();
cerr << " nJets " << nJets << endl;

The jetVec->size() statement makes a crash, as it is shown by this output:

event 27702 from run 116830:
b_jetVec 0x7fbc4a53def0
jetVec 0x7fbc00000002

*** Break *** segmentation violation

Thread 3 (process 45022):
#0 0x00007fff8d854192 in __workq_kernreturn ()
#1 0x00007fff8d678594 in _pthread_wqthread ()
#2 0x00007fff8d679b85 in start_wqthread ()

Thread 2 (process 45022):
#0 0x00007fff8d8547e6 in kevent ()
#1 0x00007fff8b3315be in _dispatch_mgr_invoke ()
#2 0x00007fff8b33014e in _dispatch_mgr_thread ()

Thread 1 (process 45022):
#0 0x00007fff8d854168 in wait4 ()
#1 0x00007fff8d62c5f5 in system ()
#2 0x000000010bf8a98a in TUnixSystem::StackTrace ()
#3 0x0000004100000111 in ?? ()

It seems that jetVec is a valid pointer (at least, it’s not null), but cannot use it.

Do you have any suggestion?

Thanks a lot,
Diego

See [url]Event class containing variable length array and https://root.cern.ch/root/html534/TTree.html#TTree:Branch@2

Thanks for checking. The problem is in my first statement “I was given a tree”, which means that I cannot change the way the tree was created. The tree is there and cannot change it :frowning:

I’d like to know if I can read it via TSelector (well, also MakeClass had troubles, just for information).

Thanks,
Diego

Return that tree to the one who sold it to you. It’s broken. If they don’t honor the warranty, find a good lawyer. :mrgreen:

Hi,

The constructions of the TTree makes it difficult/impossible to use the automatic tools. You would need to replace the calls to SetBranchAddress to introduce the fully specified branch name … and if this does not work you would need to do a recursive search for the correct branch and call SetAddress on it. (And of course you need to manually update the name of the data member generated by MakeSelector).

Cheers,
Philippe.

Hi,

I am the one who made and sold the tree. Since I cannot give warranty I would like to know how (and if) it would be possible to go around this problem (that is giving warranty, in a way :slight_smile: ).
I need to have some “list” of TLorentzVector in my tree, and I used a std::vector since I use an hand-made code to read it.
But how can I make it more “universal” ? Replace the std::vector with a TClonesArray would help ? Is it the only correction I have to apply or do I need something else ?

Thanks,
Francesco

See the links that I posted in my previous post(s) and search for “dot” inside (in short … when you define / create your TTree, append a “dot” to the name of your branches which contain class objects that create duplicate names afterwards).

Hi Francesco,

One important question is whether those vector are semantically independent or are they part of a collection (for example whether they represent the values for a series of particles or whether they represent values for things that would never be mixed together (one for the dectector, one for a particle, for something else).

If it comes from a collection, they I would stored them together as part of either a TClonesArray or a std::vector but in a single (possibly split) branch. Otherwise, it does not matter much what container you use, the important thing is that you name the individual branches distinctly (and with a trailing dot a the end of the name for the name to be carryed into the sub-branches). [This might mean that you need to carry in the collection both the TLorentzVector and its ‘name’].

Cheers,
Philippe.