// This is an example base on tree2.C tutorial code #include "TFile.h" #include "TTree.h" #include "TH2.h" #include "TRandom.h" #include "TCanvas.h" #include "TMath.h" // this needs to be constant (for writting or reading) // the value is already set to the maximum of this tree_example.root file npoints variable // my problem is: suppose I have a second root file in which npoints goes up to 35, how can I change this easily? const Int_t MAXMEC = 30; class DATA{ public: Int_t npoints; Float_t val[MAXMEC]; Float_t x[MAXMEC]; }; void tree2w() { //create a Tree file tree_example.root TFile f("tree_example.root","recreate"); TTree t2("t2","t2"); DATA data; t2.Branch("npoints",&data.npoints); t2.Branch("myval",data.val,"myval[npoints]/F"); t2.Branch("x",data.x,"x[npoints]/F"); // creating a first event data.npoints = MAXMEC; // this works if changed to 20; for (Int_t i=0;iGet("t2"); DATA data; t2->SetBranchAddress("npoints",&data.npoints); t2->SetBranchAddress("myval",&data.val); t2->SetBranchAddress("x",&data.x); Long64_t nentries = t2->GetEntries(); vector g(nentries); for (Long64_t i=0;iGetEntry(i); g[i] = new TGraph(data.npoints,data.x,data.val); } TCanvas *c1 = new TCanvas("c1","c1",600,800); c1->cd(1); g[0]->Draw("ALP"); g[1]->Draw("SAME LP"); } void tree_example() { tree2w(); tree2r(); }