Problem accessing root variables in array form

Please read this, particularly point 5, to format code here:
https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292

As for your code, these lines were missing an ‘*’ :

TTree *tree = new TTree("tree","A Root tree");
t = (TTree*)f->Get("tree");

and also, you need to do tree->Write(), not file->Write(). This should work:

void loop() {
  ...
  TTree *tree = new TTree("tree","A Root tree");
  ...
  for (int run=run_0; run<run_total; run++) {
    ...
    t = (TTree*)f->Get("tree");
    ...
  } // end file loop
  //tree->Print();
  file->cd();  // so that 'tree' is written to 'file', not to 'f'
  tree->Write();
  file->Close();
  delete file;
}