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:

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->Write(); //Produces error message: Error in TTree::Write: No file open
return 0;

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,

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.