/* 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(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 *c1 = new TCanvas("c1","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]->GetYaxis()->SetTitleOffset(1.4); 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]->Draw(); else th[i]->Draw("sames"); 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); if(n==6) { //TH1F* h1_1 = new TH1F("h1_1","Ratio",80,42,100); TH1F* hh1 = th[0]->Clone(); TH1F* hh2 = th[4]->Clone(); // th[4]->DrawCopy(); c1->cd(); TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3); pad2->SetTopMargin(0); pad2->Draw(); pad2->cd(); //hh1->Sumw2(); hh1->SetStats(0); hh1->SetMinimum(0.0); hh1->SetMaximum(1.8); hh1->Divide(th[5]); hh1->SetMarkerStyle(21); hh1->Draw(); hh2->Divide(th[5]); hh2->Draw("same"); TLine *line = new TLine(0,0.2,1,0.2); line->SetLineWidth(2); line->SetLineColor(kGreen); line->Draw(); c1->cd(); } }