TFile *top = new TFile("top.root","recreate"); TDirectory *cdtof = top->mkdir("tof"); cdtof->cd(); // make the "tof" directory the current directory const Int_t nplanes = 10; const Int_t ncounters = 100; char dirname[50]; char hname[20]; char htitle[80]; Int_t i,j,k; TDirectory *cdplane[nplanes]; TH1F *hn[nplanes][ncounters]; TH1F *hs[nplanes][ncounters]; for (i=0;imkdir(dirname); cdplane[i]->cd(); // create counter histograms for (j=0;jcd(); // change current directory to top } TRandom r; for (i=0;icd(); for (j=0;jFill(100*r.Rndm(),i+j); hs[i][j]->Fill(100*r.Rndm(),i+j+k); } } } top->Write(); delete top;