/* #include ; #include #include #include using namespace std; */ void root_debug() { MakeFile(); TFile * file = new TFile("C:/.../root_debug.root","READ"); TTree * tree = (TTree*)file->Get("test_tree"); DrawHistograms(tree); //DrawTree(tree); } void DrawTree(TTree * tree) { const int Nbranch = 10; int i; TCanvas * c[Nbranch-1]; for (i = 1; i < Nbranch; ++i) { c[i] = new TCanvas(); c[i]->cd(); stringstream tmp; tmp << "branch_" << i << ":branch_" << 0; tree->Draw(tmp.str().c_str(),"","LP"); } } void DrawHistograms(TTree * tree) { const int Nbranch = 10; TH1F * h[Nbranch-1]; TCanvas * c[Nbranch-1]; int i1 = 0, i2 = 1; for (int i = i1; i < i2; ++i) { stringstream tmp; tmp << "branch_" << i; h[i-1] = GetHistogram(tree, tmp.str().c_str()); stringstream tmp2; tmp2 << "canvas_" << i; c[i-1] = new TCanvas(tmp2.str().c_str(),tmp2.str().c_str()); c[i-1]->cd(); h[i-1]->Draw(); h[i-1]->SetBit(kCanDelete); } } void MakeFile() { TFile * file = new TFile("C:/.../root_debug.root", "UPDATE"); TTree * tree = new TTree("test_tree", "test_tree"); int Nbranch = 10, Nentries = 100; int i; vector x(Nbranch-1); for (i = 0; i < Nbranch; ++i) { stringstream tmp; tmp << "branch_" << i; if (i) tree->Branch(tmp.str().c_str(), &x[0] + i - 1, (tmp.str() +"/D").c_str()); else tree->Branch(tmp.str().c_str(), &i, (tmp.str() +"/I").c_str()); } for (i = 0; i < Nentries; ++i) { for (int k = 0; k < Nbranch - 1; ++k) x[k] = k*100.+ i; tree->Fill(); } file->Write(); cout << "wrote root file" << endl; } TH1F * GetHistogram(TTree * tree, const char * branch) { double x, xmin = 1.e100, xmax = -1.e100; vector xx; int n = tree->GetEntries(); xx.reserve(n); tree->SetBranchAddress(branch,&x); for (int i=0; iGetEntry(i); xx.push_back(x); if (x>xmax) xmax = x; if (xFillN(n, &xx[0], 0); cout << "returning histogram for " << branch << endl; return h; }