#include "TFile.h" #include "TH1.h" #include "TKey.h" #include "TDirectory.h" #include #include #include "TROOT.h" #include "TStyle.h" #include "TCanvas.h" #include "TTree.h" #include "TLegend.h" void plotBranches() { //Setting up the plot style gStyle->SetOptStat(kFALSE); Int_t icol=0; // WHITE gStyle->SetFrameBorderMode(icol); gStyle->SetFrameFillColor(icol); gStyle->SetCanvasBorderMode(icol); gStyle->SetCanvasColor(icol); gStyle->SetPadBorderMode(icol); gStyle->SetPadColor(icol); gStyle->SetStatColor(icol); gStyle->SetPadRightMargin(0.06); gStyle->SetLineWidth(2); gStyle->SetPalette(1); TFile *f = new TFile("myInDetTrackD3PD.root"); TTree *t = (TTree*)f->Get("InDetTrackTree"); TFile *f1 = new TFile("myInDetTrackD3PD_fatras.root"); TTree *t1 = (TTree*)f1->Get("InDetTrackTree"); std::cout << t->GetEntries() << std::endl; // -- Get list of branches for the tree TObjArray *o = t->GetListOfBranches(); TObjArray *o1 = t1->GetListOfBranches(); int m = o->GetEntries(); std::cout << "Number of branches: " << m << std::endl; for (int i = 0; i < m; ++i) { TCanvas *c1 = new TCanvas("c1"); const char* branchname = ((TBranch*)(*o)[i])->GetName(); TString branchnamecomp = ((TBranch*)(*o)[i])->GetName(); const char* append = "hist_"; const char* append1 = "hist1_"; std::stringstream tstream; std::stringstream tstream1; tstream << append << i; tstream1 << append1 << i; std::stringstream hs; std::stringstream hs1; hs << ">>" << (tstream.str()).c_str(); hs1 << ">>" << (tstream1.str()).c_str(); const char* branchappend = (hs.str()).c_str(); std::stringstream ss; std::stringstream ss1; ss << branchname << branchappend ; std::cout<<(ss.str()).c_str()<Draw((ss.str()).c_str(),"","goff"); TH1* hist = (TH1*)gDirectory->Get((tstream.str()).c_str()); const char* branchappend1 = (hs1.str()).c_str(); ss1 << branchname << branchappend1 <<"("<GetNbinsX() <<","<GetXaxis()->GetXmin()<<"," <GetXaxis()->GetXmax()<<")"; std::cout<<(ss1.str()).c_str()<Draw((ss1.str()).c_str(),"","goff"); TH1* hist1 = (TH1*)gDirectory->Get((tstream1.str()).c_str()); Double_t max1 = hist->GetBinContent(hist->GetMaximumBin()); Double_t max2 = hist1->GetBinContent(hist1->GetMaximumBin()); Double_t maxbin; if(max1>max2) maxbin = max1*1.5; else maxbin = max2*1.5; Double_t min1 = hist->GetBinContent(hist->GetMinimumBin()); Double_t min2 = hist1->GetBinContent(hist1->GetMinimumBin()); Double_t minbin; if(min1GetYaxis()->SetRangeUser(minbin,maxbin); hist->SetLineColor(2); hist1->SetLineColor(4); hist->SetLineWidth(2); hist1->SetLineWidth(2); hist->Draw(""); hist1->Draw("same"); TLegend *legend = new TLegend(0.70,0.75,0.80,0.85); legend->SetTextSize(0.05); legend->AddEntry(hist,"Full Sim", "F"); legend->AddEntry(hist1,"Fatras", "F"); legend->SetFillColor(kWhite); legend->SetLineColor(kWhite); legend->SetShadowColor(kWhite); legend->SetBorderSize(0); legend->Draw(); c1->Update(); c1->SaveAs("plots/G4FatrasComparison_"+branchnamecomp+".eps"); c1->Flush(); hist1->Reset(); delete hist1; hist->Reset(); delete hist; } }