void JEC_fit_Uncertainty(int N) { TF1 *func[1000]; TFile *inf = new TFile("L3Graphs_test_Icone5.root"); TGraphErrors *g = (TGraphErrors*)inf->Get("Correction_vs_CaloPt"); TGraphErrors *vg[1000]; int i,k; double x[20],y[20],ex[20],ey[20]; double vx[20],vy[20],vex[20],vey[20]; for(i=0;i<g->GetN();i++) { g->GetPoint(i,x[i],y[i]); ex[i]=g->GetErrorX(i); ey[i]=g->GetErrorY(i); } TRandom *rnd = new TRandom(); rnd->SetSeed(0); for(k=0;k<N;k++) { for(i=0;i<g->GetN();i++) { vx[i] = rnd->Gaus(x[i],ex[i]); //vx[i] = x[i]; vy[i] = rnd->Gaus(y[i],ey[i]); vex[i] = ex[i]; vey[i] = ey[i]; } vg[k] = new TGraphErrors(g->GetN(),vx,vy,vex,vey); func[k] = new TF1("func","[0]+[1]/(pow(log10(x),[2])+[3])",1,2000); func[k]->SetParameters(1,3,6,5); vg[k]->Fit(func[k],"RQ"); } TCanvas *c = new TCanvas("c","c"); gPad->SetLogx(); g->SetMarkerStyle(20); g->SetMaximum(3.5); g->Draw("AP"); for(k=0;k<N;k++) { func[k]->SetLineColor(5); func[k]->SetLineWidth(1); cout<<func[k]->GetChisquare()<<endl; vg[k]->SetMarkerColor(2); vg[k]->SetLineColor(2); vg[k]->SetMarkerStyle(21); //if (func[k]->GetChisquare()<0.1) //vg[k]->Draw("sameP"); func[k]->Draw("same"); } }
void profileDistributions(TString dist) { gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetPalette(1); TFile *inF=TFile::Open("~/work/top_539/plotter.root"); TFile *inSystF=TFile::Open("~/work/top_539/plotter_syst.root"); bool isPhi(dist.Contains("phi")); TString profs[]={dist, dist+"toward", dist+"transverse", dist+"away"}; const size_t nprofs= isPhi ? 1 : sizeof(profs)/sizeof(TString); Int_t colors[]={1,kBlue,kRed,kGreen-3}; TString cats[]={"inclusive","away","transverse","toward"}; /* TFile *inNomF=inF; TString nomTTbar="t#bar{t}"; TString nomTTbarTitle="MG+PY"; //TString systList[]={"t#bar{t}systmcatnlo"}; //TString systLabels[]={"MC@NLO+HW"}; //TString systList[]={"t#bar{t}systq2down","t#bar{t}systq2up"}; //TString systLabels[]={"-Q^{2}","+Q^{2}"}; //TString systList[]={"t#bar{t}systmepsdown","t#bar{t}systmepsup"}; // TString systLabels[]={"-ME-PS","+ME-PS"}; */ TFile *inNomF=inSystF; TString nomTTbar="t#bar{t}systtunep11"; TString nomTTbarTitle="P11"; TString systList[]={"t#bar{t}systtunep11nocr","t#bar{t}systtunep11tev"}; TString systLabels[]={"P11-noCR","P11TeV"}; Int_t systColors[]={1,kAzure,kRed-6,kGreen+3}; const size_t nSysts=sizeof(systList)/sizeof(TString); TString ch[]={"emu"}; const size_t nch=sizeof(ch)/sizeof(TString); for(size_t ich=0; ich<nch; ich++) { TCanvas *c=new TCanvas("c"+ch[ich]+dist,"c"+ch[ich]+dist,800,800); c->SetTopMargin(0); c->SetBottomMargin(0); c->Divide(1,nprofs); TCanvas *cratios=new TCanvas("cratios"+ch[ich]+dist,"cratios"+ch[ich]+dist,800,800); cratios->SetTopMargin(0); cratios->SetBottomMargin(0); cratios->Divide(1,nprofs); TCanvas *cproj=new TCanvas("cproj"+ch[ich]+dist,"cproj"+ch[ich]+dist,600,600); TLegend *dataprojLeg=new TLegend(0.5,0.9,0.6,0.7,"Data","brNDC"); TLegend *mcprojLeg=new TLegend(0.7,0.9,0.92,0.7,"MC","brNDC"); for(size_t i=0; i<nprofs; i++) { TH2 *bckgMC = (TH2 *) inF->Get("Z#rightarrow ll/"+ch[ich]+"_"+profs[i]); bckgMC->Add( (TH2 *) inF->Get("VV/"+ch[ich]+"_"+profs[i]) ); bckgMC->Add( (TH2 *) inF->Get("Single top/"+ch[ich]+"_"+profs[i]) ); bckgMC->Add( (TH2 *) inF->Get("W+jets-multijets/"+ch[ich]+"_"+profs[i]) ); //build the total MC with signal alternatives TH2 *MC = (TH2 *) inNomF->Get(nomTTbar+"/"+ch[ich]+"_"+profs[i]) ; Double_t totalTTbar(MC->Integral()); MC->Add(bckgMC); MC->SetDirectory(0); MC->Sumw2(); std::vector<TH2 *> systMC; for(size_t isyst=0; isyst<nSysts; isyst++) { TH2F *h=(TH2F *)inSystF->Get(systList[isyst]+"/"+ch[ich]+"_"+profs[i]) ; h->Scale(totalTTbar/h->Integral()); h->Add(bckgMC); h->Sumw2(); h->SetDirectory(0); systMC.push_back(h); } //get the data TH2 *Data = (TH2 *) inF->Get("data/"+ch[ich]+"_"+profs[i]); Data->SetDirectory(0); Data->Sumw2(); TGraphErrors *MCProf = new TGraphErrors(MC->ProfileX()); MCProf->SetMarkerStyle(24); MCProf->SetFillStyle(0); MCProf->SetName(ch[ich]+profs[i]+"mc"); TGraphErrors *DataProf = new TGraphErrors(Data->ProfileX()); DataProf->SetMarkerStyle(20); DataProf->SetFillStyle(0); DataProf->SetName(ch[ich]+profs[i]+"data"); //build data/MC scale factors std::vector<TGraphErrors *> data2mcProfs; for(size_t isyst=0; isyst<=systMC.size(); isyst++) { TGraphErrors *prof= (isyst==0 ? MCProf : new TGraphErrors(systMC[isyst-1]->ProfileX())); TString baseName(ch[ich]+profs[i]); if(isyst) baseName += systList[isyst]; prof = (TGraphErrors *) prof->Clone(baseName+"data2mc"); for(int ip=0; ip<DataProf->GetN(); ip++) { Double_t x,y,ydata,y_err,ydata_err; prof->GetPoint(ip,x,y); y_err=prof->GetErrorY(ip); DataProf->GetPoint(ip,x,ydata); ydata_err=DataProf->GetErrorY(ip); if(y<=0) continue; prof->SetPoint(ip,x,ydata/y); prof->SetPointError(ip,0,sqrt(pow(ydata*y_err,2)+pow(ydata_err*y,2))/pow(y,2)); } prof->SetFillColor(systColors[isyst]); prof->SetFillStyle(3001+isyst%2); prof->SetTitle( isyst==0 ? nomTTbarTitle : systLabels[isyst-1] ); //prof->SetMarkerStyle(24); prof->SetFillStyle(3001); prof->SetMarkerColor(1+isyst); prof->SetMarkerColor(1+isyst); prof->SetLineColor(1+isyst); data2mcProfs.push_back(prof); } TH1D *MCProjY=MC->ProjectionY(); MCProjY->Scale(1./MCProjY->Integral()); TGraphErrors *MCProj = new TGraphErrors(MCProjY); MCProj->SetMarkerStyle(24); MCProj->SetFillStyle(0); MCProj->SetName(ch[ich]+profs[i]+"projmc"); TH1D *DataProjY=Data->ProjectionY(); DataProjY->Scale(1./DataProjY->Integral()); TGraphErrors *DataProj = new TGraphErrors(DataProjY); DataProj->SetMarkerStyle(20); DataProj->SetFillStyle(0); DataProj->SetName(ch[ich]+profs[i]+"projdata"); MCProj->SetLineColor(colors[i]); MCProj->SetMarkerColor(colors[i]); MCProj->SetFillColor(colors[i]); MCProj->SetFillStyle(1001); DataProj->SetLineColor(colors[i]); DataProj->SetMarkerColor(colors[i]); DataProj->SetFillColor(colors[i]); TPad *p=(TPad *)cproj->cd(); p->SetLeftMargin(0.15); p->SetRightMargin(0.02); p->SetTopMargin(0.05); p->SetLogy(); MCProj->SetFillStyle(0); MCProj->Draw(i==0 ? "al3" : "l3"); MCProj->GetYaxis()->SetRangeUser(1e-5,1.0); MCProj->GetXaxis()->SetTitle( MC->GetYaxis()->GetTitle() ); MCProj->GetYaxis()->SetTitle( "1/N dN/dx" ); MCProj->GetYaxis()->SetTitleOffset(1.8); DataProj->Draw("p"); std::pair<float,int> chi2=computeChiSquareFor(DataProj,MCProj); char buf[200]; sprintf(buf,"#scale[0.7]{#chi^{2}/ndof=%3.1f}", chi2.first/chi2.second ); dataprojLeg->AddEntry(DataProj,buf,"p"); mcprojLeg->AddEntry(MCProj,cats[i],"l"); if(i==0) drawCMSHeader(ch[ich]); p=(TPad *)c->cd(i+1); if(i<nprofs-1) p->SetBottomMargin(0.01); if(i>0) p->SetTopMargin(0); if(i==0)p->SetTopMargin(0.1); if(i==nprofs-1) p->SetBottomMargin(0.15); TGraphErrors *frame=DataProf; frame->Draw("ap"); //frame->GetYaxis()->SetRangeUser(0.54,1.46); frame->GetXaxis()->SetTitle(MC->GetXaxis()->GetTitle()); //frame->GetXaxis()->SetRangeUser(0,4.75); TString yTit("<"); yTit+=MC->GetYaxis()->GetTitle(); yTit +=">"; frame->GetYaxis()->SetTitle(yTit); frame->GetYaxis()->SetLabelSize(0.07); frame->GetYaxis()->SetTitleSize(0.09); frame->GetYaxis()->SetTitleOffset(0.5); frame->GetXaxis()->SetLabelSize(0.07); frame->GetXaxis()->SetTitleSize(0.09); frame->GetXaxis()->SetTitleOffset(0.7); //p->SetGridy(); //DataProf->Draw("p"); MCProf->Draw("p"); if(i==0) { drawCMSHeader(ch[ich],0.08); TLegend *leg=new TLegend(0.6,0.95,1.0,0.99); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->SetTextFont(42); leg->SetTextSize(0.09); leg->AddEntry(DataProf,"data","p"); leg->AddEntry(MCProf,"simulation","p"); leg->SetNColumns(2); leg->Draw(); } TPaveText *pt=new TPaveText(0.15,0.5,0.8,0.85,"brNDC"); pt->SetBorderSize(0); pt->SetFillStyle(0); pt->SetTextAlign(13); pt->SetTextFont(42); pt->SetTextColor(kBlue); pt->SetTextSize(0.08); pt->AddText("[ "+cats[i]+" ]"); if(i==0) { pt->AddText("p_{T}>0.5 GeV"); pt->AddText("|#eta|<2.1"); } pt->Draw(); p=(TPad *) cratios->cd(i+1); if(i<nprofs-1) p->SetBottomMargin(0.01); if(i>0) p->SetTopMargin(0); if(i==0)p->SetTopMargin(0.1); if(i==nprofs-1) p->SetBottomMargin(0.15); frame=data2mcProfs[0]; frame->Draw("a3"); TLine *l=new TLine(frame->GetXaxis()->GetXmin(),1,frame->GetXaxis()->GetXmax(),1); l->Draw(); frame->GetYaxis()->SetRangeUser(0.54,1.46); frame->GetXaxis()->SetTitle(MC->GetXaxis()->GetTitle()); frame->GetYaxis()->SetTitle("Data/Simulation"); frame->GetYaxis()->SetLabelSize(0.07); frame->GetYaxis()->SetTitleSize(0.09); frame->GetYaxis()->SetTitleOffset(0.5); frame->GetXaxis()->SetLabelSize(0.07); frame->GetXaxis()->SetTitleSize(0.09); frame->GetXaxis()->SetTitleOffset(0.7); //p->SetGridy(); for(size_t ip=1; ip<data2mcProfs.size(); ip++) data2mcProfs[ip]->Draw("3"); if(i==0) { drawCMSHeader(ch[ich],0.08); TLegend *leg=new TLegend(0.6,0.94,1.0,0.98); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->SetTextFont(42); leg->SetTextSize(0.09); leg->SetNColumns(data2mcProfs.size()); for(size_t ip=0; ip<data2mcProfs.size(); ip++) leg->AddEntry(data2mcProfs[ip],data2mcProfs[ip]->GetTitle(),"f"); leg->Draw(); } pt=new TPaveText(0.12,0.65,0.8,0.9,"brNDC"); pt->SetBorderSize(0); pt->SetFillStyle(0); pt->SetTextAlign(13); pt->SetTextFont(42); pt->SetTextColor(kBlue); pt->SetTextSize(0.08); pt->AddText("[ "+cats[i]+" ]"); if(i==0) { pt->AddText("p_{T}>0.5 GeV"); pt->AddText("|#eta|<2.1"); } pt->Draw(); } cproj->cd(); dataprojLeg->SetFillStyle(0); dataprojLeg->SetBorderSize(0); dataprojLeg->SetTextFont(42); dataprojLeg->SetTextSize(0.03); dataprojLeg->Draw(); mcprojLeg->SetFillStyle(0); mcprojLeg->SetBorderSize(0); mcprojLeg->SetTextFont(42); mcprojLeg->SetTextSize(0.03); mcprojLeg->Draw(); TString pf(".png"); c->SaveAs(outDir+c->GetName()+pf); cproj->SaveAs(outDir+cproj->GetName()+pf); cratios->SaveAs(outDir+cratios->GetName()+pf); } inF->Close(); inSystF->Close(); }
TGraphErrors *ReadMWGraph(const char *name, Int_t flag) { Double_t xreject = 0.49; TGraphErrors *g = new TGraphErrors(name); if (g->IsZombie()) return 0; while (g->GetX()[0] < xreject) g->RemovePoint(0); TGraphErrors *g2 = new TGraphErrors(name); if (g2->IsZombie()) return 0; while (g2->GetX()[0] < xreject) g2->RemovePoint(0); g2->SetMarkerStyle(4); g2->SetMarkerSize(1.00); g2->SetMarkerColor(kBlack); g2->SetLineColor(kBlack); TGraphErrors *gsys = new TGraphErrors(name, "%lg %lg %lg %*lg %lg"); if (gsys->IsZombie()) return 0; while (gsys->GetX()[0] < xreject) gsys->RemovePoint(0); for (Int_t i = 0; i < gsys->GetN(); i++) gsys->SetPointError(i, gsys->GetErrorX(i)*0.75, gsys->GetErrorY(i)); gsys->SetFillColor(kGray+2); gsys->SetLineColor(kGray+2); gsys->SetFillStyle(3000); if (flag == 1 || flag == 3) { TGraphErrors *gt = new TGraphErrors(Form("%s_%s", name, "trues")); if (gt->IsZombie()) return 0; while (gt->GetX()[0] < xreject) gt->RemovePoint(0); gt->SetMarkerStyle(20); gt->SetMarkerSize(0.75); gt->SetMarkerColor(kGreen+1); gt->SetLineColor(kGreen+1); TGraphErrors *gbw = new TGraphErrors(Form("%s_%s", name, "gen")); if (gbw->IsZombie()) return 0; while (gbw->GetX()[0] < xreject) gbw->RemovePoint(0); gbw->SetMarkerStyle(20); gbw->SetMarkerSize(0.75); gbw->SetMarkerColor(kBlue+1); gbw->SetLineColor(kBlue+1); for (Int_t i = 0; i < g->GetN(); i++) { g->SetPointError(i, g->GetEX()[i], 0.); gt->SetPointError(i, gt->GetEX()[i], 0.); gbw->SetPointError(i, gbw->GetEX()[i], 0.); } for (Int_t i = 0; i < g2->GetN(); i++) { g2->SetPoint(i, g2->GetX()[i], g2->GetY()[i] - gt->GetY()[i] + gbw->GetY()[i]); g2->SetPointError(i, g2->GetEX()[i], TMath::Sqrt(g2->GetEY()[i]*g2->GetEY()[i] + gt->GetEY()[i]*gt->GetEY()[i] + gbw->GetEY()[i]*gbw->GetEY()[i])); // g2->SetPoint(i, g2->GetX()[i], g2->GetY()[i] - gt->GetY()[i] + 1.01947); // g2->SetPointError(i, g2->GetEX()[i], TMath::Sqrt(g2->GetEY()[i]*g2->GetEY()[i] + gt->GetEY()[i]*gt->GetEY()[i] + // 7.78680e-06*7.78680e-06)); gsys->SetPoint(i, gsys->GetX()[i], g2->GetY()[i]); } } g->SetTitle(); g->SetName(name); g->GetXaxis()->SetTitle("p_{T}, GeV/c"); g->SetMarkerStyle(20); g->SetMarkerSize(0.95); g->SetMarkerColor(kRed+1); g->SetLineColor(kRed+1); const Double_t mass = 1.019455; const Double_t mass_delta = 0.000020; const Double_t width = 0.00426; const Double_t width_delta = 0.00004; if (flag == 1) { // mass g->GetYaxis()->SetTitleOffset(1.50); g->GetYaxis()->SetTitle("mass, GeV/c^{2}"); g->SetMaximum(mass+0.0015); g->SetMinimum(mass-0.0015); TBox *box = new TBox(g->GetXaxis()->GetXmin(), mass - mass_delta, g->GetXaxis()->GetXmax(), mass + mass_delta); box->SetFillColor(kGray+1); box->SetFillStyle(3001); g->GetListOfFunctions()->Add(box); g->GetListOfFunctions()->Add(g2, "CP"); g->GetListOfFunctions()->Add(gt, "CP"); g->GetListOfFunctions()->Add(gbw, "CP"); } else if (flag == 3) { // mass simple g2->SetTitle(); g2->SetName(Form("%s_only", name)); g2->GetXaxis()->SetTitle("p_{T}, GeV/c"); g2->SetMarkerStyle(20); g2->SetMarkerSize(0.75); g2->SetMarkerColor(kBlack); g2->SetLineColor(kBlack); g2->GetYaxis()->SetTitleOffset(1.50); g2->GetYaxis()->SetTitle("mass, GeV/c^{2}"); g2->SetMaximum(mass+0.0015); g2->SetMinimum(mass-0.0015); TBox *box = new TBox(g->GetXaxis()->GetXmin(), mass - mass_delta, g2->GetXaxis()->GetXmax(), mass + mass_delta); box->SetFillColor(kGray+1); box->SetFillStyle(3001); g2->GetListOfFunctions()->Add(box); g2->GetListOfFunctions()->Add(gsys, "E5"); return g2; } else if (flag == 2) { // width g->SetTitle(); g->SetName(name); g->GetXaxis()->SetTitle("p_{T}, GeV/c"); g->SetMarkerStyle(20); g->SetMarkerSize(0.75); g->SetMarkerColor(kBlack); g->SetLineColor(kBlack); g->GetYaxis()->SetTitleOffset(1.50); g->GetYaxis()->SetTitle("width, GeV/c^{2}"); g->SetMaximum(0.01); g->SetMinimum(0.0); TBox *box = new TBox(g->GetXaxis()->GetXmin(), width - width_delta, g->GetXaxis()->GetXmax(), width + width_delta); box->SetFillColor(kGray+1); box->SetFillStyle(3001); g->GetListOfFunctions()->Add(box); g->GetListOfFunctions()->Add(gsys, "E5"); } return g; }
void plot(int mass) { double myQCDRelUncert = 0.038; double myEWKRelUncert = 0.131; double myFakesRelUncert = 0.238; double delta = 1.4; double br = 0.05; bool debug = false; bool log = false; double ymin = 0.001; double ymax = 48; static bool bMessage = false; if (!bMessage) { cout << "Values used as relative uncertainty (please check):" << endl; cout << " QCD: " << myQCDRelUncert << endl; cout << " EWK genuine tau: " << myEWKRelUncert << endl; cout << " EWK fake tau: " << myFakesRelUncert << endl << endl; bMessage = true; } cout << "Processing mass point: " << mass << " GeV/c2" << endl; gStyle->SetOptFit(1); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetTitleFont(43, "xyz"); gStyle->SetTitleSize(33, "xyz"); gStyle->SetLabelFont(43, "xyz"); gStyle->SetLabelSize(27, "xyz"); //std::string infile = "EPS_data_nodeltaphi/hplus_100.root"; //std::string infile = "EPS_data_deltaphi160/hplus_100.root"; std::stringstream s; s << "lands_histograms_hplushadronic_m" << mass << ".root"; std::string infile = s.str(); // Canvas TCanvas *myCanvas = new TCanvas("myCanvas", "",0,0,600,600); myCanvas->SetHighLightColor(2); myCanvas->Range(0,0,1,1); myCanvas->SetFillColor(0); myCanvas->SetBorderMode(0); myCanvas->SetBorderSize(2); if (log) myCanvas->SetLogy(); myCanvas->SetTickx(1); myCanvas->SetTicky(1); myCanvas->SetLeftMargin(0.16); myCanvas->SetRightMargin(0.05); myCanvas->SetTopMargin(0.05); myCanvas->SetBottomMargin(0.08); myCanvas->SetFrameFillStyle(0); myCanvas->SetFrameBorderMode(0); myCanvas->SetFrameFillStyle(0); myCanvas->SetFrameBorderMode(0); myCanvas->cd(); Int_t ci; TFile* f = TFile::Open(infile.c_str()); s.str(""); s << "HW" << mass << "_1"; TH1* hw = (TH1*)f->Get(s.str().c_str()); s.str(""); s << "HH" << mass << "_1"; TH1* hh = (TH1*)f->Get(s.str().c_str()); TH1* data = (TH1*)f->Get("data_obs"); data->SetLineWidth(2); data->SetMarkerStyle(20); data->SetMarkerSize(1.2); TH1* ewktau = (TH1*)f->Get("EWK_Tau"); ci = TColor::GetColor("#993399"); ewktau->SetFillColor(ci); ewktau->SetLineWidth(0); TH1* ewkDY = (TH1*)f->Get("EWK_DYx"); TH1* ewkVV = (TH1*)f->Get("EWK_VVx"); ewktau->Add(ewkDY); ewktau->Add(ewkVV); //TH1* qcd = (TH1*)f->Get("QCDInv"); TH1* qcd = (TH1*)f->Get("QCD"); ci = TColor::GetColor("#ffcc33"); qcd->SetFillColor(ci); qcd->SetLineWidth(0); TH1* fakett = (TH1*)f->Get("fake_tt"); ci = TColor::GetColor("#669900"); fakett->SetFillColor(ci); fakett->SetLineWidth(0); TH1* fakeW = (TH1*)f->Get("fake_W"); ci = TColor::GetColor("#cc3300"); fakeW->SetFillColor(ci); fakeW->SetLineWidth(0); TH1* faket = (TH1*)f->Get("fake_t"); TH1F *hFrame = new TH1F("hFrame","",20,0,400); hFrame->SetMinimum(ymin); if (log) hFrame->SetMaximum(ymax*1.5); else hFrame->SetMaximum(ymax); hFrame->SetDirectory(0); hFrame->SetStats(0); hFrame->SetLineStyle(0); hFrame->SetMarkerStyle(20); hFrame->SetXTitle("Transverse mass (#tau jet, E_{T}^{miss}), (GeV/c^{2})"); if (paperStatus) hFrame->SetXTitle("Transverse mass (#tau_{h}, E_{T}^{miss}), (GeV/c^{2})"); hFrame->SetYTitle("Events / 20 GeV/c^{2}"); hFrame->GetXaxis()->SetTitleSize(0); hFrame->GetXaxis()->SetLabelSize(0); hFrame->GetYaxis()->SetTitleFont(43); hFrame->GetYaxis()->SetTitleSize(27); hFrame->GetYaxis()->SetTitleOffset(1.3); // signal hh->Scale(br*br); hw->Scale(2*br*(1.0-br)); TH1* signal = (TH1*)hh->Clone(); signal->Add(hw); ci = TColor::GetColor("#ff3399"); signal->SetLineColor(ci); signal->SetLineStyle(2); signal->SetLineWidth(2); // Fakes TH1* fakes = (TH1*)(fakett->Clone()); fakes->Add(fakeW); fakes->Add(faket); // stacked backgrounds THStack *exp = new THStack(); exp->SetName("exp"); exp->SetTitle("exp"); exp->Add(fakes); exp->Add(ewktau); exp->Add(qcd); exp->Add(signal); TH1* hExpBkg = (TH1*)fakes->Clone(); hExpBkg->Add(ewktau); hExpBkg->Add(qcd); // uncertainty TH1* uncert = (TH1*)fakeW->Clone(); uncert->Add(fakett); uncert->Add(ewktau); uncert->Add(qcd); uncert->SetFillColor(1); uncert->SetFillStyle(3344); uncert->SetLineColor(0); uncert->SetLineStyle(0); uncert->SetLineWidth(0); TH1* hExpBkgTotalUncert = (TH1*)uncert->Clone(); hExpBkgTotalUncert->SetFillStyle(3354); TH1* hAgreement = (TH1*)data->Clone(); hAgreement->Divide(hExpBkg); TGraphErrors* hAgreementRelUncert = new TGraphErrors(hAgreement->GetNbinsX()); hAgreementRelUncert->SetLineWidth(2); hAgreementRelUncert->SetLineColor(kBlack); for (int i = 1; i <= hFrame->GetNbinsX(); ++i) { double myQCDTotalUncert = TMath::Power(qcd->GetBinError(i), 2) + TMath::Power(qcd->GetBinContent(i)*myQCDRelUncert, 2); double myEWKTotalUncert = TMath::Power(ewktau->GetBinError(i), 2) + TMath::Power(ewktau->GetBinContent(i)*myEWKRelUncert, 2); double myFakesTotalUncert = TMath::Power(fakes->GetBinError(i), 2) + TMath::Power(fakes->GetBinContent(i)*myFakesRelUncert, 2); hExpBkgTotalUncert->SetBinError(i, TMath::Sqrt(myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert)); if (hExpBkg->GetBinContent(i) > 0) { hAgreementRelUncert->SetPoint(i-1, hExpBkg->GetBinCenter(i), data->GetBinContent(i) / hExpBkg->GetBinContent(i)); double myUncertData = 0; if (data->GetBinContent(i) > 0) myUncertData = TMath::Power(data->GetBinError(i) / data->GetBinContent(i), 2); double myUncertBkg = (myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert) / TMath::Power(hExpBkg->GetBinContent(i), 2); hAgreementRelUncert->SetPointError(i-1, 0, data->GetBinContent(i) / hExpBkg->GetBinContent(i) * TMath::Sqrt(myUncertData + myUncertBkg)); } else { hAgreementRelUncert->SetPoint(i-1, hExpBkg->GetBinCenter(i), 0); hAgreementRelUncert->SetPointError(i-1, 0, 0); } if (debug) { cout << "Point: " << hAgreementRelUncert->GetX()[i-1]-10 << "-" << hAgreementRelUncert->GetX()[i-1]+10 << " GeV/c2, agreement: " << hAgreementRelUncert->GetY()[i-1] << ", uncert: " << hAgreement->GetBinError(i) << ", " << hAgreementRelUncert->GetErrorY(i-1) << endl; cout << " bkg. stat. uncert. " << hExpBkg->GetBinError(i) << " (i.e. " << hExpBkg->GetBinError(i) / hExpBkg->GetBinContent(i) * 100.0 << " %)" << ", stat+syst uncert. " << TMath::Sqrt(myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert) << " (i.e. " << TMath::Sqrt(myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert) / hExpBkg->GetBinContent(i) * 100.0 << " %)" << endl; } } // Agreement pad TPad* pad = new TPad("ratiopad","ratiopad",0.,0.,1.,.3); pad->Draw(); pad->cd(); pad->Range(0,0,1,1); pad->SetFillColor(0); pad->SetFillStyle(4000); pad->SetBorderMode(0); pad->SetBorderSize(2); pad->SetTickx(1); pad->SetTicky(1); pad->SetLeftMargin(0.16); pad->SetRightMargin(0.05); pad->SetTopMargin(0); pad->SetBottomMargin(0.34); pad->SetFrameFillStyle(0); pad->SetFrameBorderMode(0); // Plot here ratio if (1.0-delta > 0) hAgreement->SetMinimum(1.0-delta); else hAgreement->SetMinimum(0.); hAgreement->SetMaximum(1.0+delta); hAgreement->GetXaxis()->SetLabelOffset(0.007); hAgreement->GetXaxis()->SetLabelFont(43); hAgreement->GetXaxis()->SetLabelSize(27); hAgreement->GetYaxis()->SetLabelFont(43); hAgreement->GetYaxis()->SetLabelSize(27); hAgreement->GetYaxis()->SetLabelOffset(0.007); hAgreement->GetYaxis()->SetNdivisions(505); hAgreement->GetXaxis()->SetTitleFont(43); hAgreement->GetYaxis()->SetTitleFont(43); hAgreement->GetXaxis()->SetTitleSize(33); hAgreement->GetYaxis()->SetTitleSize(33); hAgreement->SetTitleSize(27, "xyz"); hAgreement->GetXaxis()->SetTitleOffset(3.2); hAgreement->GetYaxis()->SetTitleOffset(1.3); hAgreement->SetXTitle(hFrame->GetXaxis()->GetTitle()); hAgreement->SetYTitle("Data/#Sigmabkg"); hAgreement->Draw("e2"); // Plot line at zero TH1* hAgreementLine = dynamic_cast<TH1*>(hAgreement->Clone()); for (int i = 1; i <= hAgreementLine->GetNbinsX(); ++i) { hAgreementLine->SetBinContent(i,1.0); hAgreementLine->SetBinError(i,0.0); } hAgreementLine->SetLineColor(kRed); hAgreementLine->SetLineWidth(2); hAgreementLine->SetLineStyle(3); hAgreementLine->Draw("hist same"); hAgreement->Draw("same"); hAgreementRelUncert->Draw("[]"); pad->RedrawAxis(); myCanvas->cd(); TPad* plotpad = new TPad("plotpad", "plotpad",0,0.3,1.,1.); plotpad->Draw(); plotpad->cd(); plotpad->Range(0,0,1,1); plotpad->SetFillColor(0); plotpad->SetFillStyle(4000); plotpad->SetBorderMode(0); plotpad->SetBorderSize(2); //if (logy) // plotpad->SetLogy(); plotpad->SetTickx(1); plotpad->SetTicky(1); plotpad->SetLeftMargin(0.16); plotpad->SetRightMargin(0.05); plotpad->SetTopMargin(0.065); plotpad->SetBottomMargin(0.0); plotpad->SetFrameFillStyle(0); plotpad->SetFrameBorderMode(0); hFrame->GetXaxis()->SetTitleSize(0); hFrame->GetXaxis()->SetLabelSize(0); hFrame->GetYaxis()->SetTitleFont(43); hFrame->GetYaxis()->SetTitleSize(33); hFrame->GetYaxis()->SetTitleOffset(1.3); // Draw objects hFrame->Draw(); exp->Draw("hist same"); uncert->Draw("E2 same"); hExpBkgTotalUncert->Draw("E2 same"); // Data data->Draw("same"); //signal->Draw("same"); TLegend *leg = new TLegend(0.53,0.6,0.87,0.91,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextFont(63); leg->SetTextSize(18); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(kWhite); //leg->SetFillStyle(4000); // enabling this will cause the plot to be erased from the pad TLegendEntry* entry = leg->AddEntry(data, "Data", "P"); s.str(""); s << "with H^{#pm}#rightarrow#tau^{#pm}#nu"; entry = leg->AddEntry(signal, s.str().c_str(), "L"); entry = leg->AddEntry(qcd, "QCD (meas.)", "F"); entry = leg->AddEntry(ewktau, "EWK genuine #tau (meas.)", "F"); entry = leg->AddEntry(fakes, "EWK fake #tau (MC)", "F"); entry = leg->AddEntry(uncert, "stat. uncert.", "F"); entry = leg->AddEntry(hExpBkgTotalUncert, "stat. #oplus syst. uncert.", "F"); leg->Draw(); string myTitle = "CMS Preliminary"; if (paperStatus) myTitle = "CMS"; TLatex *tex = new TLatex(0.62,0.945,myTitle.c_str()); tex->SetNDC(); tex->SetTextFont(43); tex->SetTextSize(27); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.2,0.945,"#sqrt{s} = 7 TeV"); tex->SetNDC(); tex->SetTextFont(43); tex->SetTextSize(27); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.43,0.945,"2.2 fb^{-1}"); tex->SetNDC(); tex->SetTextFont(43); tex->SetTextSize(27); tex->SetLineWidth(2); tex->Draw(); s.str(""); s << "m_{H^{#pm}} = " << mass << " GeV/c^{2}"; tex = new TLatex(0.28,0.865,s.str().c_str()); tex->SetNDC(); tex->SetTextFont(63); tex->SetTextSize(20); tex->SetLineWidth(2); tex->Draw(); s.str(""); s << "BR(t#rightarrowbH^{#pm})=" << setprecision(2) << br; tex = new TLatex(0.28,0.805,s.str().c_str()); tex->SetNDC(); tex->SetTextFont(63); tex->SetTextSize(20); tex->SetLineWidth(2); tex->Draw(); plotpad->RedrawAxis(); plotpad->Modified(); s.str(""); s << "mT_datadriven_m" << mass << ".png"; myCanvas->Print(s.str().c_str()); s.str(""); s << "mT_datadriven_m" << mass << ".C"; myCanvas->Print(s.str().c_str()); s.str(""); s << "mT_datadriven_m" << mass << ".eps"; myCanvas->Print(s.str().c_str()); }