#include "TFile.h" #include "TTree.h" typedef struct { float mesh_time; } data_tree_new; void run() { int nrunr=0; int nsegm=0; int nstream=2; TFile*f = new TFile(Form("XYMG_run%d_%d_s%d.root",nrunr,nsegm,nstream),"recreate"); TTree*t= new TTree("t","XYMG DATA"); t->Refresh(); // I used Refresh(), but by replacing it by whatever action (i.e. t->Print() for example), it still works float mesh_time; data_tree_new data_tree; //t->SetBranchAddress("mesh_time",&data_tree.mesh_time); t->Branch("mesh_time",&data_tree.mesh_time,"mesh_time/F"); float time=9; for (int i =1; i<=10; i++) { data_tree.mesh_time=time; t->Fill(); t->Write("", TObject::kOverwrite); exit(0); } f->Close(); }