TVector in a TTree

Hi all,

So the only thing I would like to have is to create my own TTree fill it with TVector3 objects and save it in a file. The code I am using is:

[code]
int main(int argc, char* argv[]){

TVector3* p = new TVector3();
TFile* file = TFile::Open(“myfile.root”, “RECREATE”);

TTree *mytree = new TTree(“mytree”,“mytree”);
mytree->Branch(“p”, “TVector3”, &p, 32000, 1);

while (1){
p->SetXYZ(fst[t1]->GetMomentum().X(), fst[t1]->GetMomentum().Y(), fst[t1]->GetMomentum().Z() ); // fills p with Double_t-s
mytree->Fill();
}

mytree->Write(); //Produces error message: Error in TTree::Write: No file open
file->Write();
file->Close();
return 0;
}[/code]

At the end I have as an output:

  1. The error message: Error in No file open
  2. the root file with the tree, in which the vector x,y and z are values around 0 (which should not be the case)

What do I do wrong?
Thank you in advance,
Ivan

Your Tree creation is correct. However your loop uses arrays/variables not known
to the program.
Please provide a concrete & running script showing your problem.

Rene