/* this program plots histogram form different root file on the same canvas tree = 0 if we need to read histogram tree = 1 if we need to read branch of tree NOTE: CHANGE THE NAME OF TREE var1 is the variable that we want to plot var2 is the xtitle n is the number of input rootfiles format to enter $root -l root[].L CompareAdvanced.C root[]compareQuantities(0/1,"branch_name","x-axis Title",10,0,200,Cut,2,"abc.root","abc","xyz.root","xyz"); abc.root is the name of root file --->>> abc is the legend of abc.root; similarly others. 19 August: Trying to add ratio plot at bottom of each plot. */ void compareQuantities(string can,int tree, string var1, string var2, int nbins, float min, float max, string cut="",int n,...){ float a1=0.04; float a2=0.20; int color[9] = {2,3,6,4,1,9,7,8,9}; int style[9] = {1,4,3,1,1,4}; float yMax = 0.1; TCanvas *Canvas1 = new TCanvas(TString(can),"example",600,700); TPad *pad1 = new TPad("pad1","pad1",0,0.3,1,1); pad1->SetBottomMargin(0); pad1->Draw(); pad1->cd(); if (var2 == "") var2 = var1; cout<SetOptStat(0); gROOT->ForceStyle(kTRUE); va_list list; va_start(list, n); cout<<"n = "<SetLogy(1); for (int i=0;iGet(Form("%s",var1.c_str())); th[i]->SetTitle(""); th[i]->Rebin(nbins); th[i]->GetXaxis()->SetRangeUser(min,max); } if (tree == 1){ //tt[i] = (TTree*) tf[i]->Get("demo/tree"); tt[i] = (TTree*) tf[i]->Get("tree"); th[i] = new TH1F(Form("th%i",i),"",nbins,min,max); tt[i]->Draw(Form("%s>>th%i",var1.c_str(),i), cut.c_str(), "goff"); } th[i]->SetStats(0); th[i]->SetLineWidth(2); th[i]->SetLineStyle(style[i]); th[i]->SetLineColor(color[i]); th[i]->GetYaxis()->SetTitle("Fraction of Events"); th[i]->GetYaxis()->CenterTitle(); th[i]->GetXaxis()->SetTitle(var2.c_str()); th[i]->GetXaxis()->SetTitle(var2.c_str()); th[i]->GetXaxis()->CenterTitle(); th[i]->Scale(1/th[i]->Integral()); th[0]->SetMaximum(TMath::Max(th[i]->GetMaximum()*1.10,yMax)); yMax = TMath::Max(th[i]->GetMaximum()*1.10,yMax); if (i==0) th[i]->DrawCopy(); else th[i]->Draw("sames"); leg[i] = new TLegend(a1,0.85,a2,0.99); leg[i]->AddEntry(th[i],va_arg(list, char*),"l"); int entries = th[i]->GetEntries(); char c[20]; sprintf(c,"%d",entries); leg[i]->AddEntry(th[i],TString(c),"l"); leg[i]->Draw("sames"); a1 = a2; a2 = a2+0.16; } va_end(list); TH1F* hh0 = th[0]->Clone(); TH1F* hh1 = th[1]->Clone(); TH1F* hh2 = th[2]->Clone(); TH1F* hh3 = th[3]->Clone(); Canvas1->cd(); TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3); pad2->SetTopMargin(0); pad2->Draw(); pad2->cd(); hh0->SetStats(0); hh0->SetMinimum(0.0); hh0->SetMaximum(1.8); hh0->GetYaxis()->SetTitle("Ratio"); hh0->Divide(th[5]); hh0->SetMarkerStyle(21); hh0->Draw(); hh1->Divide(th[5]); hh1->Draw("same"); hh2->Divide(th[5]); hh2->Draw("same"); hh3->Divide(th[5]); hh3->Draw("same"); TLine *line = new TLine(100, 1, 800, 1); line->SetLineWidth(2); line->SetLineColor(kGreen); line->Draw(); }