Hi,
I posted this to the bug fixes page, but realized that I probably should have posted it here. I apologize if you are seeing this twice.
I am trying to fill a TTree with TLorentzVectors and save to a file. When I open the file and loop over the entries, I find all the TLorentzVector elements are zero. This is also true if I open the tree in a TBrowser or TTreeViewer. I can write the individual elements in a separate branch and they are non-zero.
I’ve pasted a simple script below to illustrate my problem. When I run in 3.05/07, the behavior is as above. If I try to run in 4.00/03, I get a seg fault when I try to create a branch for the TLorentzVector object.
I searched ROOTTalk and it looks like people have done this before – I don’t understand why it doesn’t work for me.
Can anyone help with this? Would it be better to use a TClonesArray to store the TLorentzVector objects?
I’ve attached the .root file output of this script.
Thanks,
Brian
#include “TLorentzVector.h”
#include “TRandom.h”
TLorentzTreeTest() {
double px,py,pz,e;
TLorentzVector* vect = new TLorentzVector();
TTree* tree = new TTree(“tree”,“TLorentzVector test tree”);
TTree::SetBranchStyle(1);
// this branch filled with zeros in all TLorentzVector components
TBranch* branch = tree->Branch(“vect.”,“TLorentzVector”,vect,16000,2);
// seg fault here in 4.00/03
//TBranch* branch = tree->Branch(“vect.”,“TLorentzVector”,vect);
branch->SetAutoDelete(kFALSE);
// this branch has non-zero entries
tree->Branch(“px”,&px,“px/D”);
for(int i=0;i<100;++i) {
px = 100*( gRandom->Rndm(1) - 0.5 );
py = 100*( gRandom->Rndm(1) - 0.5 );
pz = 100*( gRandom->Rndm(1) - 0.5 );
e = sqrt( pow(px,2) + pow(py,2) + pow(pz,2) );
vect->SetPxPyPzE(px,py,pz,e);
tree->Fill();
}
file = new TFile(“TLVTest.root”,“recreate”);
tree->Write();
tree->Print();
file->Close();
}
TLVTest.root (6.76 KB)