void electrons(char* newFile="DQM_new.root",char* refFile="DQM_old.root") { gROOT ->Reset(); gROOT ->SetBatch(); //========= settings ==================== gROOT->SetStyle("Plain"); gStyle->SetPadGridX(kTRUE); gStyle->SetPadGridY(kTRUE); gStyle->SetPadRightMargin(0.07); gStyle->SetPadLeftMargin(0.13); //gStyle->SetTitleXSize(0.07); //gStyle->SetTitleXOffset(0.6); //tyle->SetTitleYSize(0.3); //gStyle->SetLabelSize(0.6) //gStyle->SetTextSize(0.5); char* refLabel("reference histogram"); char* newLabel("new histogram"); delete gROOT->GetListOfFiles()->FindObject(refFile); delete gROOT->GetListOfFiles()->FindObject(newFile); TText* te = new TText(); TFile * sfile = new TFile(newFile); TDirectory * sdir=gDirectory; TFile * rfile = new TFile(refFile); TDirectory * rdir=gDirectory; if(sfile->GetDirectory("DQMData/EgammaV")) sfile->cd("DQMData/EgammaV/ElectronMcSignalValidator/"); sdir=gDirectory; TList *sl= sdir->GetListOfKeys(); // sdir->ls(); if(rfile->GetDirectory("DQMData/EgammaV")) rfile->cd("DQMData/EgammaV/ElectronMcSignalValidator/"); rdir=gDirectory; TList *rl= rdir->GetListOfKeys(); // rdir->ls(); TCanvas *canvas; TH1F *sh1,*rh1; TH1F *sh2,*rh2; rdir->GetObject("h_ele_ecalRecHitSumEt_dr04_barrel",rh1); sdir->GetObject("h_ele_ecalRecHitSumEt_dr04_barrel",sh1); rdir->GetObject("h_ele_ecalRecHitSumEt_dr04_endcaps",rh2); sdir->GetObject("h_ele_ecalRecHitSumEt_dr04_endcaps",sh2); canvas = new TCanvas("Electrons","Electrons",1000,1400); TH1F * r[2]={rh1,rh2}; TH1F * s[2]={sh1,sh2}; plotBuilding(canvas,s, r,2, te,"UU",-1, 1, false, 0xC); canvas->cd(); /* l = new TLegend(0.10,0.14,0.90,0.19); l->SetTextSize(0.016); l->SetLineColor(1); l->SetLineWidth(1); l->SetLineStyle(1); l->SetFillColor(0); l->SetBorderSize(3); l->AddEntry(rh1,refLabel,"LPF"); l->AddEntry(sh1,newLabel,"LPF"); l->Draw(); */ TString namepdf = "ecalIso04.pdf"; canvas->Print(namepdf); // delete l; delete canvas; } void plotBuilding(TCanvas *canvas, TH1F **s, TH1F **r, int n,TText* te, char * option, double startingY, double startingX = .1,bool fit = false, unsigned int logx=0){ canvas->Divide(2,(n+1)/2); //this should work also for odd n for(int i=0; iSetMarkerStyle(20); r[i]->SetMarkerStyle(21); s[i]->SetMarkerColor(2); r[i]->SetMarkerColor(4); s[i]->SetMarkerSize(0.7); r[i]->SetMarkerSize(0.7); s[i]->SetLineColor(1); r[i]->SetLineColor(1); s[i]->SetLineWidth(1); r[i]->SetLineWidth(1); // normalize r[i]->Scale(1./r[i]->Integral()); s[i]->Scale(1./s[i]->Integral()); TPad *pad=canvas->cd(i+1); setStats(s[i],r[i], -1, 0, false); if((logx>>i)&1)pad->SetLogx(); r[i]->Draw(); s[i]->Draw("sames"); } } void setStats(TH1* s,TH1* r, double startingY, double startingX = .1,bool fit){ if (startingY<0){ s->SetStats(0); r->SetStats(0); } else { //gStyle->SetOptStat(1001); s->SetStats(1); r->SetStats(1); if (fit){ s->Fit("gaus"); TF1* f1 = (TF1*) s->GetListOfFunctions()->FindObject("gaus"); f1->SetLineColor(2); f1->SetLineWidth(1); } s->Draw(); gPad->Update(); TPaveStats* st1 = (TPaveStats*) s->GetListOfFunctions()->FindObject("stats"); if (fit) {st1->SetOptFit(0010); st1->SetOptStat(1001);} st1->SetX1NDC(startingX); st1->SetX2NDC(startingX+0.30); st1->SetY1NDC(startingY+0.20); st1->SetY2NDC(startingY+0.35); st1->SetTextColor(2); if (fit) { r->Fit("gaus"); TF1* f2 = (TF1*) r->GetListOfFunctions()->FindObject("gaus"); f2->SetLineColor(4); f2->SetLineWidth(1); } r->Draw(); gPad->Update(); TPaveStats* st2 = (TPaveStats*) r->GetListOfFunctions()->FindObject("stats"); if (fit) {st2->SetOptFit(0010); st2->SetOptStat(1001);} st2->SetX1NDC(startingX); st2->SetX2NDC(startingX+0.30); st2->SetY1NDC(startingY); st2->SetY2NDC(startingY+0.15); st2->SetTextColor(4); } }