struct Hit { double x; double y; double t; int meth; }; void testWrite() { //create an array of hits// const int MaxHits = 32; Hit hit[MaxHits]; int nbrOfCurrentHits = 0; //create a file to write the tree to// TFile f ("TestTree.root","RECREATE"); //create the tree// TTree * tt = new TTree("TestTree","A test with variable lenght array of structs"); //create the branches// tt->Branch("NbrHits",&nbrOfCurrentHits,"nbrHits/I"); tt->Branch("Hit",&hit,"x/D:y:t:Meth/I"); //?is this correct? //try to fill the tree with 10000 events// for (int i=0; i< 10000;++i) { //first get the number of Hits from a random generator// nbrOfCurrentHits = (int) (31 * gRandom->Rndm()); //clear all entries first// for (int j=0; jRannor(x,y); hit[j].x = x; hit[j].y = y; hit[j].t = 10000*gRandom->Rndm(); hit[j].meth = (int) (24*gRandom->Rndm()); } //now fill the tree with these hits// tt->Fill(); } tt->Write(); } void testRead() { //open file and load tree// TFile *f = new TFile("TestTree.root"); TTree * tt = (TTree*) f->Get("TestTree"); //create an array of hits// const int MaxHits = 32; Hit hit[MaxHits]; int nbrOfHits = 0; //create Histos for testing// TH1D * ty = new TH1D("Y","test y", 80,-4,4); TH2D * det = new TH2D("det","Det",80,-4,4,80,-4,4); det->SetOption("colz"); TH2D * wig = new TH2D("wig","Wiggles",100,0,10100,20,0,4); wig->SetOption("colz"); //set the branches// tt->SetBranchAddress("NbrHits",&nbrOfHits); tt->SetBranchAddress("Hit",&hit); //?Is this correct? //loop over all entries and get the info from it// int nbrEntriesInTree = tt->GetEntries(); for(int i=0;iGetEntry(i); for (int j=0;jFill(hit[j].y); if (hit[j].meth < 15) { det->Fill(hit[j].x,hit[j].y); wig->Fill(hit[j].t,TMath::Sqrt(hit[j].x*hit[j].x + hit[j].y*hit[j].y)); } } } }