Filling a tree with an object array

Hi,
I am trying to fill a branch of a root tree with an array of TLorentzVectors, but I do not know how to do this correctly. I have tried the following code, wich seemed like the obvious way to do it to me:

TFile hfile = (TFile)gROOT->FindObject(“MCdata.root”);
if (hfile)
hfile->Close();
hfile = new TFile(“MCData.root”,“RECREATE”);
Int_t split = 0;
Int_t bsize = 64000;
TTree *MCTree = new TTree(“MCTree”,"");

TLorentzVector *bhiggs[2];

MCTree->Branch(“bhiggs”,“TLorentzVector”,&bhiggs,bsize,split);

but i get a segmentation violation. I would like to use a TClonesArray, but I dont think they work with TLorentzVectors. Is this the case, and do you have any other ideas for how to do this?
Thanks,
Clare

You must correctly preset the pointer before calling TTree::Branch. eg:

[code]{
TFile *hfile = new TFile(“MCData.root”,“RECREATE”);
Int_t split = 0;
Int_t bsize = 64000;
TTree *MCTree = new TTree(“MCTree”,"");

TLorentzVector *bhiggs[2] ={0,0};

MCTree->Branch(“bhiggs0”,“TLorentzVector”,&bhiggs[0],bsize,split);
MCTree->Branch(“bhiggs1”,“TLorentzVector”,&bhiggs[1],bsize,split);
MCTree->Print();
}
[/code]

Rene

Thanks for replying so quickly.

That stops the segmentation violation when the branch is declared. However, if I then try and access the elements of the array like this:

TLorentzVector *bhiggs[2] ={0,0};

MCTree->Branch(“bhiggs0”,“TLorentzVector”,&bhiggs[0],bsize,split);
MCTree->Branch(“bhiggs1”,“TLorentzVector”,&bhiggs[1],bsize,split);
bhiggs[0]->SetPxPyPzE(0,0,0,0)

I get the error:

Error: illegal pointer to class object bhiggs[0] 0x0 987

Do I need to access the elements in a different way?

Thanks,
Clare

You get this error because you call SetPxPyPzE with a null pointer.
You must create the TLorentzVector objects first.

Rene