void Plot_nPV_dataMC(TChain *dataChain, TChain *mcChain, TString outputFilename, TString puWeightBranch="puWeight"){ TCanvas c("c",""); c.cd(); dataChain->Draw("nPV>>data_nPV_hist(60,0,60)"); mcChain->Draw("nPV>>mc_nPV_hist(60,0,60)",puWeightBranch); // mcChain->Draw("nPV>>mc_nPV_hist"); TH1F *data_hist = (TH1F *) gROOT->FindObject("data_nPV_hist"); TH1F *mc_hist = (TH1F *) gROOT->FindObject("mc_nPV_hist"); data_hist->Sumw2(); // to plot the errors mc_hist->GetXaxis()->SetTitle("Number of reconstructed vertexes"); mc_hist->GetYaxis()->SetTitle("[a.u.]"); data_hist->GetXaxis()->SetTitle("Number of reconstructed vertexes"); data_hist->GetYaxis()->SetTitle("[a.u.]"); mc_hist->GetXaxis()->SetRangeUser(0,30); data_hist->GetXaxis()->SetRangeUser(0,30); mc_hist->SetLineWidth(2); data_hist->SetMarkerStyle(20); data_hist->SetMarkerSize(1.2); mc_hist->DrawNormalized(); data_hist->DrawNormalized("same"); TLegend legend(0.7,0.85,1,1); std::cout << "[INFO] Setting entries in legend using chain titles" << std::endl; legend.AddEntry(data_hist, dataChain->GetTitle(),"p"); legend.AddEntry(mc_hist, mcChain->GetTitle(),"l"); SetLegendStyle(&legend); legend.SetBorderSize(1); legend.Draw(); TPaveText pv(0.3,0.93,0.6,1,"ndc"); pv.AddText("CMS Preliminary, 8TeV"); pv.SetBorderSize(0); pv.SetFillStyle(0); pv.SetTextSize(0.045); pv.Draw(); c.SaveAs(outputFilename); c.SaveAs(outputFilename.ReplaceAll(".eps",".C")); return; }
void crossXmass(int k=4){ gSystem->Load("libFWCoreFWLite.so"); gROOT->LoadMacro("tdrstyle.C"); setTDRStyle(); //gStyle->SetOptStat(0000); gStyle->SetOptFit(0011); TFile * file = new TFile("preUnfolding.root"); TFile * file_unfolded = new TFile("unfolded.root"); TFile * file_acceptance = new TFile("acceptance.root"); TFile * file_truthFinal = new TFile("truthFinal.root"); TFile * file_zprimeM1000W1 = new TFile("zprime/ZPrimeM1000W1.root"); TFile * file_zprimeM2000W1 = new TFile("zprime/ZPrimeM2000W1.root"); //truth level after reconstruction level selection TH1F * hGenDistMADGRAPH = (TH1F*) file->Get("hTruth_MadGraph"); TH1F * hGenDistPOWHEG = (TH1F*) file->Get("hTruth_Powheg"); //unfolded plot TH1F * h_unfold = (TH1F*) file_unfolded->Get("unfolded"); //acceptance TH1F * hAcceptDist = (TH1F*) file_acceptance->Get("hAccept_vsum"); TH1F * hAcceptDistFull = (TH1F*) file_acceptance->Get("hAccept_vsum_Full"); //truth level for final TH1D * hGenMADGRAPH = (TH1D*) file_truthFinal->Get("hTruthFinalMADGRAPH"); TH1D * hGenPOWHEG = (TH1D*) file_truthFinal->Get("hTruthFinalPOWHEG"); TH1D * hGenMADGRAPH_Full = (TH1D*) file_truthFinal->Get("hTruthFinalMADGRAPH_Full"); TH1D * hGenPOWHEG_Full = (TH1D*) file_truthFinal->Get("hTruthFinalPOWHEG_Full"); double lumi = 1143.22; bool printX = true; //print cross section bool norm = false; TH1F* hSigmaData = getMeasuredCrossSection(h_unfold, hAcceptDistFull,lumi,norm, true, "unfolded",false); TH1F* hSigmaTruthHisto = getTruthCrossSection(hGenDistMADGRAPH, hGenMADGRAPH_Full, lumi, norm, false, 1, printX); TH1F* hSigmazprimeM1000W1 = getTruthCrossSection(file_zprimeM1000W1, ZXsectionW1[7], "M1000W1"); TH1F* hSigmazprimeM2000W1 = getTruthCrossSection(file_zprimeM2000W1, ZXsectionW1[18], "M2000W1"); TH1F* hSigmazprime = hSigmazprimeM1000W1; TCanvas * c_Xmass = new TCanvas("c_Xmass","c_Xmass",1); c_Xmass->SetLogy(); TH1F* h_Xmass = (TH1F*)h_unfold->Clone("hSigmaData"); TH1F* h_Xmass_ttbar = (TH1F*)h_unfold->Clone("hSigmaData"); TH1F* h_Xmass_zprime = (TH1F*) h_unfold->Clone("hSigmaData"); h_Xmass->Reset(); h_Xmass_ttbar->Reset(); h_Xmass_zprime->Reset(); int nbins = h_unfold->GetNbinsX(); double total = 0; double total_ttbar = 0; double total_zprime = 0; for(int i=nbins; i >= 1 ;i--){ double sigma = hSigmaData->GetBinContent(i)*hSigmaData->GetBinWidth(i); double sigma_ttbar = hSigmaTruthHisto->GetBinContent(i)*hSigmaTruthHisto->GetBinWidth(i); double sigma_zprime = hSigmazprime->GetBinContent(i)*hSigmazprime->GetBinWidth(i); total += sigma; total_ttbar += sigma_ttbar; total_zprime += sigma_zprime; cout << hSigmazprime->GetBinContent(i)*hSigmazprime->GetBinWidth(i) << endl; h_Xmass->SetBinContent(i, total); h_Xmass_ttbar->SetBinContent(i, total_ttbar); h_Xmass_zprime->SetBinContent(i, total_zprime); } THStack *hs = new THStack("hs","zprime plus ttbar"); h_Xmass_ttbar->SetFillColor(2); h_Xmass_zprime->SetLineColor(4); h_Xmass_zprime->SetLineWidth(2); hs->Add(h_Xmass_ttbar); hs->Add(h_Xmass_zprime); hs->Draw(); hs->GetYaxis()->SetTitle("#int_{x}^{#infty} d#sigma/dm_{t#bar{t}} dm_{t#bar{t}}"); hs->GetXaxis()->SetTitle(" m_{t#bar{t}}"); h_Xmass->Draw("p same"); TLegend *l= new TLegend(); l->AddEntry(h_Xmass, "Data" ,"p"); l->AddEntry(h_Xmass_ttbar, "t#bar{t}" ,"F"); l->AddEntry(h_Xmass_zprime, "zprime" ,"L"); SetLegendStyle(l,true); l->Draw("same"); }
void HTT_TT_X(bool scaled=true, bool log=false, float min=0., float max=-1., const char* inputfile="root/$HISTFILE", const char* directory="$CATEGORY") { // define common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category_extra = ""; if(std::string(directory) == std::string("emu_0jet_low" )){ category_extra = "0 jet, low p_{T}"; } if(std::string(directory) == std::string("emu_0jet_high" )){ category_extra = "0 jet, high p_{T}"; } if(std::string(directory) == std::string("emu_boost_low" )){ category_extra = "1 jet, low p_{T}"; } if(std::string(directory) == std::string("emu_boost_high")){ category_extra = "1 jet, high p_{T}"; } if(std::string(directory) == std::string("emu_vbf" )){ category_extra = "2 jet (VBF)"; } if(std::string(directory) == std::string("emu_nobtag" )){ category_extra = "No B-Tag"; } if(std::string(directory) == std::string("emu_btag" )){ category_extra = "B-Tag"; } const char* dataset; if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS Preliminary, ZH#rightarrow#lltau#tau, 4.9 fb^{-1} at 7 TeV";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, ZH#rightarrowll#tau#tau, 19.4 fb^{-1} at 8 TeV";} #ifdef MSSM if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 19.4 fb^{-1} at 8 TeV";} #endif TFile* input = new TFile(inputfile); TH1F* ZZ = refill((TH1F*)input->Get(TString::Format("%s/ZZ" , directory)), "ZZ"); InitHist(ZZ, "", "", kMagenta-10, 1001); TH1F* GGToZZ2L2L = refill((TH1F*)input->Get(TString::Format("%s/GGToZZ2L2L" , directory)), "GGToZZ2L2L"); InitHist(GGToZZ2L2L, "", "", kMagenta-10, 1001); TH1F* Zjets = refill((TH1F*)input->Get(TString::Format("%s/Zjets" , directory)), "Zjets" ); InitHist(Zjets , "", "", kRed + 2, 1001); #ifndef DROP_SIGNAL TH1F* ZH_htt = refill((TH1F*)input->Get(TString::Format("%s/ZH_htt" , directory)+"125"), "ZH_htt" ); InitSignal(ZH_htt); ZH_htt->Scale(SIGNAL_SCALE); TH1F* ZH_hww = refill((TH1F*)input->Get(TString::Format("%s/ZH_hww" , directory)+"125"), "ZH_hww" ); InitSignal(ZH_hww); ZH_hww->Scale(SIGNAL_SCALE); #endif TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); InitHist(data, "#bf{m_{#tau#tau} [GeV]}", "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)ZZ->Clone("ref"); ref->Add(GGToZZ2L2L); ref->Add(Zjets ); double unscaled[5]; unscaled[0] = ZZ->Integral(); unscaled[1] = GGToZZ2L2L->Integral(); unscaled[2] = Zjets ->Integral(); #ifndef DROP_SIGNAL unscaled[3] = ZH_htt ->Integral(); unscaled[4] = ZH_hww ->Integral(); #endif if(scaled){ rescale(ZZ, 1); rescale(GGToZZ2L2L, 2); rescale(Zjets, 3); #ifndef DROP_SIGNAL rescale(ZH_htt, 4); rescale(ZH_hww, 5); #endif } TH1F* scales[5]; scales[0] = new TH1F("scales-ZZ", "", 5, 0, 5); scales[0]->SetBinContent(1, unscaled[0]>0 ? (ZZ->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-GGToZZ2L2L", "", 5, 0, 5); scales[1]->SetBinContent(2, unscaled[1]>0 ? (GGToZZ2L2L->Integral()/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-Zjets" , "", 5, 0, 5); scales[2]->SetBinContent(3, unscaled[2]>0 ? (Zjets ->Integral()/unscaled[2]-1.) : 0.); #ifndef DROP_SIGNAL scales[3] = new TH1F("scales-ZH_htt" , "", 5, 0, 5); scales[3]->SetBinContent(4, unscaled[3]>0 ? (ZH_htt ->Integral()/unscaled[3]-1.) : 0.); scales[4] = new TH1F("scales-ZH_hww" , "", 5, 0, 5); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ZH_hww ->Integral()/unscaled[4]-1.) : 0.); #endif GGToZZ2L2L->Add(Zjets); ZZ ->Add(GGToZZ2L2L); if(log){ #ifndef DROP_SIGNAL ZH_htt ->Add(ZH_hww ); #endif } else{ #ifndef DROP_SIGNAL ZH_htt ->Add(ZH_hww); #endif } /* mass plot before and after fit */ TCanvas* canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(1000)); }; #else data->GetXaxis()->SetRange(0, data->FindBin(350)); #endif data->SetNdivisions(505); data->SetMinimum(min); float maxZZ=ZZ->GetBinContent(ZZ->GetMaximumBin()); float maxdata=data->GetBinContent(data->GetMaximumBin()); if (maxdata>maxZZ) data->SetMaximum(1.8*maxdata); else data->SetMaximum(1.8*maxZZ); data->Draw("e"); // TH1F* errorBand = (TH1F*)ZZ ->Clone(); TH1F* errorBand = (TH1F*)Zjets ->Clone(); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(1); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); errorBand ->Scale(0.15); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } //if(log){ ZZ ->Draw("histsame"); Zjets->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL ZH_htt ->Draw("histsame"); #endif //} //else{ //#ifndef DROP_SIGNAL // ggH ->Draw("histsame"); //#endif // Ztt ->Draw("histsame"); // ttbar->Draw("histsame"); // EWK ->Draw("histsame"); // Fakes->Draw("histsame"); // $DRAW_ERROR // } data->Draw("esame"); canv->RedrawAxis(); // //CMSPrelim(dataset, "#tau_{e}#tau_{#mu}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); if (directory=="eett_zh") chan->AddText("#tau#tau"); else chan->AddText("#mu#mu#tau#tau"); chan->Draw(); // // TPaveText* cat = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC"); // cat->SetBorderSize( 0 ); // cat->SetFillStyle( 0 ); // cat->SetTextAlign( 12 ); // cat->SetTextSize ( 0.05 ); // cat->SetTextColor( 1 ); // cat->SetTextFont ( 62 ); // cat->AddText(category_extra); // cat->Draw(); // //#ifdef MSSM // TPaveText* massA = new TPaveText(0.75, 0.48+0.061, 0.85, 0.48+0.161, "NDC"); // massA->SetBorderSize( 0 ); // massA->SetFillStyle( 0 ); // massA->SetTextAlign( 12 ); // massA->SetTextSize ( 0.03 ); // massA->SetTextColor( 1 ); // massA->SetTextFont ( 62 ); // massA->AddText("m_{A}=$MAGeV"); // massA->Draw(); // // TPaveText* tanb = new TPaveText(0.75, 0.44+0.061, 0.85, 0.44+0.161, "NDC"); // tanb->SetBorderSize( 0 ); // tanb->SetFillStyle( 0 ); // tanb->SetTextAlign( 12 ); // tanb->SetTextSize ( 0.03 ); // tanb->SetTextColor( 1 ); // tanb->SetTextFont ( 62 ); // tanb->AddText("tan#beta=$TANB"); // tanb->Draw(); // // TPaveText* scen = new TPaveText(0.75, 0.40+0.061, 0.85, 0.40+0.161, "NDC"); // scen->SetBorderSize( 0 ); // scen->SetFillStyle( 0 ); // scen->SetTextAlign( 12 ); // scen->SetTextSize ( 0.03 ); // scen->SetTextColor( 1 ); // scen->SetTextFont ( 62 ); // scen->AddText("mhmax"); // scen->Draw(); //#endif // //#ifdef MSSM // TLegend* leg = new TLegend(0.45, 0.65, 0.95, 0.90); // SetLegendStyle(leg); // leg->AddEntry(ggH , "#phi#rightarrow#tau#tau" , "L" ); //#else TLegend* leg = new TLegend(0.50, 0.65, 0.95, 0.90); SetLegendStyle(leg); //#ifndef DROP_SIGNAL // if(SIGNAL_SCALE!=1){ leg->AddEntry(ZH_htt , TString::Format("%.0f#timesZH(125 GeV)#rightarrowll#tau#tau", SIGNAL_SCALE) , "L" ); // } // else{ // leg->AddEntry(ggH , "H(125 GeV)#rightarrow#tau#tau" , "L" ); // } //#endif //#endif leg->AddEntry(data , "observed" , "LP"); leg->AddEntry(ZZ , "ZZ" , "F" ); leg->AddEntry(Zjets, "Reducible" , "F" ); // leg->AddEntry(EWK , "electroweak" , "F" ); // leg->AddEntry(Fakes, "QCD" , "F" ); $ERROR_LEGEND leg->Draw(); // ////#ifdef MSSM //// TPaveText* mssm = new TPaveText(0.69, 0.85, 0.90, 0.90, "NDC"); //// mssm->SetBorderSize( 0 ); //// mssm->SetFillStyle( 0 ); //// mssm->SetTextAlign( 12 ); //// mssm->SetTextSize ( 0.03 ); //// mssm->SetTextColor( 1 ); //// mssm->SetTextFont ( 62 ); //// mssm->AddText("(m_{A}=250, tan#beta=5)"); //// mssm->Draw(); ////#else //// TPaveText* mssm = new TPaveText(0.83, 0.85, 0.95, 0.90, "NDC"); //// mssm->SetBorderSize( 0 ); //// mssm->SetFillStyle( 0 ); //// mssm->SetTextAlign( 12 ); //// mssm->SetTextSize ( 0.03 ); //// mssm->SetTextColor( 1 ); //// mssm->SetTextFont ( 62 ); //// mssm->AddText("m_{H}=125"); //// mssm->Draw(); ////#endif // // /* // Ratio Data over MC // */ // TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); // canv0->SetGridx(); // canv0->SetGridy(); // canv0->cd(); // // TH1F* zero = (TH1F*)ref ->Clone("zero"); zero->Clear(); // TH1F* rat1 = (TH1F*)data->Clone("rat"); // rat1->Divide(Ztt); // for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ // if(rat1->GetBinContent(ibin+1)>0){ // // catch cases of 0 bins, which would lead to 0-alpha*0-1 // rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); // } // zero->SetBinContent(ibin+1, 0.); // } // rat1->SetLineColor(kBlack); // rat1->SetFillColor(kGray ); // rat1->SetMaximum(+0.5); // rat1->SetMinimum(-0.5); // rat1->GetYaxis()->CenterTitle(); // rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); // rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); // rat1->Draw(); // zero->SetLineColor(kBlack); // zero->Draw("same"); // canv0->RedrawAxis(); // // /* // Ratio After fit over Prefit // */ // TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); // canv1->SetGridx(); // canv1->SetGridy(); // canv1->cd(); // // TH1F* rat2 = (TH1F*) Ztt->Clone("rat2"); // rat2->Divide(ref); // for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ // if(rat2->GetBinContent(ibin+1)>0){ // // catch cases of 0 bins, which would lead to 0-alpha*0-1 // rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); // } // } // rat2->SetLineColor(kRed+ 3); // rat2->SetFillColor(kRed-10); // rat2->SetMaximum(+0.3); // rat2->SetMinimum(-0.3); // rat2->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); // rat2->GetYaxis()->CenterTitle(); // rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); // rat2->GetXaxis()->SetRange(0, 28); // rat2->Draw(); // zero->SetLineColor(kBlack); // zero->Draw("same"); // canv1->RedrawAxis(); // // /* // Relative shift per sample // */ // TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); // canv2->SetGridx(); // canv2->SetGridy(); // canv2->cd(); // // InitHist (scales[0], "", "", kMagenta-10, 1001); // InitHist (scales[1], "", "", kRed + 2, 1001); // InitHist (scales[2], "", "", kBlue - 8, 1001); // InitHist (scales[3], "", "", kOrange - 4, 1001); //#ifndef DROP_SIGNAL // InitSignal(scales[4]); // InitSignal(scales[5]); // InitSignal(scales[6]); //#endif // scales[0]->Draw(); // scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}"); // scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}" ); // scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}"); // scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}" ); //#ifdef MSSM // scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); // scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}" ); // scales[0]->GetXaxis()->SetBinLabel(7, "#bf{NONE}" ); //#else // scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); // scales[0]->GetXaxis()->SetBinLabel(6, "#bf{qqH}" ); // scales[0]->GetXaxis()->SetBinLabel(7, "#bf{VH}" ); //#endif // scales[0]->SetMaximum(+1.0); // scales[0]->SetMinimum(-1.0); // scales[0]->GetYaxis()->CenterTitle(); // scales[0]->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); // scales[1]->Draw("same"); // scales[2]->Draw("same"); // scales[3]->Draw("same"); //#ifndef DROP_SIGNAL // scales[4]->Draw("same"); // scales[5]->Draw("same"); // scales[6]->Draw("same"); //#endif // zero->Draw("same"); // canv2->RedrawAxis(); // // /* // prepare output // */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sscaled_%s_%s.png" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sscaled_%s_%s.pdf" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sscaled_%s_%s.eps" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); TFile* output = new TFile(TString::Format("%s_%sscaled_%s_%s.root", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""), "update"); output->cd(); data ->Write("data_obs"); ZZ->Write("ZZ" ); Zjets ->Write("Zjets" ); ZH_htt->Write("ZH_htt" ); ZH_hww ->Write("ZH_hww" ); //#ifdef MSSM // ggH ->Write("ggH" ); // bbH ->Write("bbH" ); //#else //#ifndef DROP_SIGNAL // ggH ->Write("ggH" ); // qqH ->Write("qqH" ); // VH ->Write("VH" ); //#endif //#endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); }
//// runCode // 0=merged, 1=1stRun, 2=2ndRun void draw_1D_RFB_rap(char* dirName = "8rap9pt2gev", int runCode=0, bool isPrompt = true) { //gROOT->Macro("./JpsiStyleForFinalResult.C"); gROOT->Macro("./tdrstyle_kyo.C"); gStyle->SetTitleSize(0.046, "XYZ"); gStyle->SetEndErrorSize(0); // Margins: /* // gStyle->SetPadTopMargin(0.05); gStyle->SetPadBottomMargin(0.132); //KYO gStyle->SetPadLeftMargin(0.132); //KYO //gStyle->SetPadRightMargin(0.04); */ gStyle->SetOptTitle(0); gStyle->SetPadTopMargin(0.075); gStyle->SetPadBottomMargin(0.13); //KYO gStyle->SetPadLeftMargin(0.13); //KYO gStyle->SetPadRightMargin(0.075); gStyle->SetTitleXOffset(1.15); gStyle->SetTitleYOffset(1.22); writeExtraText = true; extraText = "Preliminary"; lumi_502TeV = "34.6 nb^{-1}"; int iPeriod = 0; int iPos=0; double pxshift = 0.06; // set info. const Double_t br = 0.0593 ; const Double_t brErr = 0.0006; Double_t lumi_nb; Double_t lumi_nb_err; Double_t lumi_mub; Double_t lumi_mub_err; string runstring; string lumistring; string cmsstring = "CMS preliminary"; string beamstring = "pPb #sqrt{s_{NN}} = 5.02 TeV"; if (runCode ==0) { runstring = "All"; lumi_nb =34.622; lumi_nb_err=1.2; } else if (runCode == 1) { runstring = "Pbp"; lumi_nb =20.7; lumi_nb_err=0.7; }//1stRun else if (runCode == 2) { runstring = "pPb"; lumi_nb = 14.0; lumi_nb_err=0.5; }//2ndRun else { cout << " *** Error!!! choose runCode 0, 1, or 2 " << endl; return ; } lumistring = Form("L_{int} = %.1f nb^{ -1}", lumi_nb); lumi_mub = lumi_nb * 1000; // (nb)^{-1} -> {#mub}^{-1} lumi_mub_err = lumi_nb_err * 1000; // (nb)^{-1} -> {#mub}^{-1} ///////////////////////////////////////////////////////////////////////// /// systematic uncertainties by hand KYO const int nRap = 8; const int nPt = 9; const int nRapTmp = nRap + 1; const int nPtTmp = nPt + 1; const int nRapRFB=3; Double_t pxtmp_lowpt[nRapRFB]; // x point to fill tmp Double_t pxtmp_highpt[nRapRFB]; // x point to fill tmp Double_t pytmp_lowpt[nRapRFB]; // y point to fill tmp Double_t pytmp_highpt[nRapRFB]; // y point to fill tmp Double_t eytmp[nRapRFB]; // y point error to fill tmp Double_t ex[nRapRFB] = {0.0, 0.0, 0.0}; //x stat error Double_t exsys[nRapRFB] = {0.03, 0.03, 0.03}; //sys x error Double_t eysys_lowpt[nRapRFB]; //absolute y sys error Double_t eysys_highpt[nRapRFB]; //absolute y sys error Double_t eysysrelPR_lowpt[nRapRFB] = { //relative y sys error 0.04694, //0-0.9 0.04245, //0.9-1.5 0.04795}; //1.5-1.93; Double_t eysysrelNP_lowpt[nRapRFB] = { 0.07412, 0.06288, 0.10487}; Double_t eysysrelPR_highpt[nRapRFB] = { //relative y sys error 0.03705, 0.03360, 0.06486}; Double_t eysysrelNP_highpt[nRapRFB] = { //relative y sys error 0.04483, 0.05592, 0.09280}; Double_t eysysrel_lowpt[nRapRFB]; Double_t eysysrel_highpt[nRapRFB]; for (int iy=0; iy<nRapRFB; iy++){ if (isPrompt) { eysysrel_lowpt[iy] = eysysrelPR_lowpt[iy]; eysysrel_highpt[iy] = eysysrelPR_highpt[iy]; } else { eysysrel_lowpt[iy] = eysysrelNP_lowpt[iy]; eysysrel_highpt[iy] = eysysrelNP_highpt[iy]; } } //y_CM array (from forward to backward) //Double_t rapArrNumFB[] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87};// for pt dist. Double_t rapArrNumBF[nRapTmp] = {-2.87, -2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist. // const Int_t nRap = sizeof(rapArrNumBF)/sizeof(Double_t)-1; // cout << "nRap = " << nRap << endl; Double_t rapBinW[nRap]; for (Int_t iy=0; iy<nRap; iy++) { //rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1]; rapBinW[iy] = rapArrNumBF[iy+1]-rapArrNumBF[iy]; cout << iy <<"th rapBinW = " << rapBinW[iy] <<endl; } //pt array Double_t ptArrNum[nPtTmp] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10., 14., 30.}; Double_t ptBinW[nPt]; for (Int_t ipt=0; ipt<nPt; ipt++) { ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt]; cout << ipt <<"th ptBinW = " << ptBinW[ipt] <<endl; } // array string string rapArr[nRap]; for (Int_t iy=0; iy<nRap; iy++) { formRapArr(rapArrNumBF[iy], rapArrNumBF[iy+1], &rapArr[iy]); cout << iy <<"th rapArr = " << rapArr[iy] << endl; } string ptArr[nPt]; for (Int_t ipt=0; ipt<nPt; ipt++) { formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]); cout << ipt <<"th ptArr = " << ptArr[ipt] << endl; } // --- read-in file TFile * f2D = new TFile(Form("../fittingResult/total2Dhist_%s.root",dirName)); cout << "dirName = " << dirName << endl; cout << "runCode = " << runCode << ", runstring = " << runstring.c_str() << endl; // --- read-in 2D hist for corrected yield TH2D* h2D_corrY_Pbp; TH2D* h2D_corrY_pPb; if (isPrompt) h2D_corrY_Pbp = (TH2D*)f2D->Get("h2D_corrY_PR_Pbp"); else h2D_corrY_Pbp = (TH2D*)f2D->Get("h2D_corrY_NP_Pbp"); if (isPrompt) h2D_corrY_pPb = (TH2D*)f2D->Get("h2D_corrY_PR_pPb"); else h2D_corrY_pPb = (TH2D*)f2D->Get("h2D_corrY_NP_pPb"); cout << "h2D_corrY_Pbp = " << h2D_corrY_Pbp << endl; cout << "h2D_corrY_pPb = " << h2D_corrY_pPb << endl; const int nbinsX = h2D_corrY_Pbp->GetNbinsX(); const int nbinsY = h2D_corrY_Pbp->GetNbinsY(); cout << "nbinsX = " << nbinsX << endl; cout << "nbinsY = " << nbinsY << endl; if (nbinsX != nRap) { cout << " *** Error!!! nbinsX != nRap"; return; }; if (nbinsY != nPt) { cout << " *** Error!!! nbinsY != nPt"; return; }; // --- projection to 1D hist TH1D* h1D_corrY_Pbp_tmp[nPt]; // in y_lab(1st) TH1D* h1D_corrY_Pbp[nPt]; TH1D* h1D_corrY_pPb_tmp[nPt]; // in y_lab(2nd) TH1D* h1D_corrY_pPb[nPt]; //in y_CM // iy=0 refers to forwards !!! (ordering here && in CM) int tmpbin; double tmpval=0; double tmperr=0; for (Int_t ipt = 0; ipt < nPt; ipt++) { h1D_corrY_Pbp_tmp[ipt] = h2D_corrY_Pbp->ProjectionX(Form("h1D_corrY_Pbp_tmp_%d",ipt),ipt+1,ipt+1); h1D_corrY_pPb_tmp[ipt] = h2D_corrY_pPb->ProjectionX(Form("h1D_corrY_pPb_tmp_%d",ipt),ipt+1,ipt+1); h1D_corrY_Pbp[ipt] = new TH1D(Form("h1D_corrY_Pbp_%d",ipt),Form("h1D_corrY_Pbp_%d",ipt),nRap,rapArrNumBF); h1D_corrY_pPb[ipt] = new TH1D(Form("h1D_corrY_pPb_%d",ipt),Form("h1D_corrY_pPb_%d",ipt),nRap,rapArrNumBF); h1D_corrY_Pbp[ipt]->Sumw2(); h1D_corrY_pPb[ipt]->Sumw2(); for (Int_t iy=0; iy<nRap; iy++){ //1st run tmpval = h1D_corrY_Pbp_tmp[ipt]->GetBinContent(iy+1); tmperr = h1D_corrY_Pbp_tmp[ipt]->GetBinError(iy+1); h1D_corrY_Pbp[ipt]->SetBinContent(nRap-iy,tmpval); h1D_corrY_Pbp[ipt]->SetBinError(nRap-iy,tmperr); //2nd run tmpval = h1D_corrY_pPb_tmp[ipt]->GetBinContent(iy+1); tmperr = h1D_corrY_pPb_tmp[ipt]->GetBinError(iy+1); h1D_corrY_pPb[ipt]->SetBinContent(iy+1,tmpval); h1D_corrY_pPb[ipt]->SetBinError(iy+1,tmperr); } } ////////////////////////////////////////////////////////////////////////////////////// // 1) merge Pbp+pPb corrected yield TH1D* h1D_corrY_tot[nPt]; for (Int_t ipt = 0; ipt < nPt; ipt++) { // --- merging if (runCode ==0) { h1D_corrY_tot[ipt] = (TH1D*)h1D_corrY_Pbp[ipt]->Clone(Form("h1D_corrY_tot_%d",ipt)); h1D_corrY_tot[ipt]->Add(h1D_corrY_pPb[ipt]); } else if (runCode ==1) { h1D_corrY_tot[ipt] = (TH1D*)h1D_corrY_Pbp[ipt]->Clone(Form("h1D_corrY_tot_%d",ipt)); } else if (runCode ==2) { h1D_corrY_tot[ipt] = (TH1D*)h1D_corrY_pPb[ipt]->Clone(Form("h1D_corrY_tot_%d",ipt)); } cout <<" "<<endl; cout <<ipt<<"th pt !!!"<<endl; for (int iy=0; iy <nRap; iy ++ ){ cout << iy <<"th rap" << endl; cout << "h1D_corrY_tot = " << h1D_corrY_tot[ipt]->GetBinContent(iy+1)<<endl; } } ////////////////////////////////////////////////////////////////// /////////// calculate RFB const int lowpt_init=4; const int highpt_init=7; // *** pt bin merging cout << "*** low pT bin starts from : " << ptArr[lowpt_init].c_str() << endl; for (Int_t ipt = lowpt_init+1; ipt < highpt_init; ipt++) { h1D_corrY_tot[lowpt_init]->Add(h1D_corrY_tot[ipt]); cout << " *** and to low pT, merging : " << ptArr[ipt].c_str() << endl; } cout << "*** high pT bin starts from : " << ptArr[highpt_init].c_str() << endl; for (Int_t ipt = highpt_init+1; ipt < nPt; ipt++) { h1D_corrY_tot[highpt_init]->Add(h1D_corrY_tot[ipt]); cout << " *** and to high pT, merging : " << ptArr[ipt].c_str() << endl; } // |yCM| for drawing (actual binning) Double_t rapArrRFBNum[nRapRFB+1] = {0., 0.9, 1.5, 1.93};// for rap dist. //const Int_t nRapRFB = sizeof(rapArrRFBNum)/sizeof(Double_t)-1; //cout << "nRapRFB = " << nRapRFB << endl; TH1D* h1D_RFB[nPt]; //byHand int rap_init = 2; // actual RFB calculation double tmpFWval[nRapRFB], tmpBWval[nRapRFB]; double tmpFWerr[nRapRFB], tmpBWerr[nRapRFB]; double actval[nRapRFB], acterr[nRapRFB]; for (Int_t ipt = 0; ipt < nPt; ipt++) { if (ipt != lowpt_init && ipt != highpt_init) continue; cout << ipt <<"th pt -- actual RFB *** " << endl; h1D_RFB[ipt] = new TH1D(Form("h1D_RFB_%d",ipt),Form("h1D_RFB_%d",ipt),nRapRFB,rapArrRFBNum); h1D_RFB[ipt]->Sumw2(); for (int iy=0; iy <nRapRFB; iy ++ ){ cout << iy<< "th RFB calcul" <<endl; tmpFWval[iy] = h1D_corrY_tot[ipt]->GetBinContent(nRap-iy); tmpFWerr[iy] = h1D_corrY_tot[ipt]->GetBinError(nRap-iy); tmpBWval[iy] = h1D_corrY_tot[ipt]->GetBinContent(rap_init+iy+1); tmpBWerr[iy] = h1D_corrY_tot[ipt]->GetBinError(rap_init+iy+1); DivideValue(tmpFWval[iy],tmpFWerr[iy],tmpBWval[iy],tmpBWerr[iy],&actval[iy],&acterr[iy]); h1D_RFB[ipt]->SetBinContent(nRapRFB-iy,actval[iy]); h1D_RFB[ipt]->SetBinError(nRapRFB-iy,acterr[iy]); } } ////////////////////////////////////////////////////////////////// TLegend *legUR = new TLegend(0.52, 0.75, 0.86, 0.92); //upper left TLegend *legUL = new TLegend(0.16, 0.75, 0.45, 0.94, NULL, "brNDC"); //TLegend *legBL = new TLegend(0.17,0.17,0.42,0.38,NULL,"brNDC"); TLegend *legBL = new TLegend(0.16,0.17,0.42,0.38,NULL,"brNDC"); // TLegend *legBR = new TLegend(0.54, 0.17, 0.87, 0.39); //upper left TLegend *legBR = new TLegend(0.51, 0.17, 0.85, 0.37); //upper left SetLegendStyle(legUR); SetLegendStyle(legUL); SetLegendStyle(legBL); SetLegendStyle(legBR); legBR->SetTextSize(0.037); //globtex box for beam, rapidity, pT info TLatex* globtex = new TLatex(); globtex->SetNDC(); //globtex->SetTextAlign(12); //1:left, 2:vertical center globtex->SetTextAlign(32); //3:right 2:vertical center globtex->SetTextFont(42); globtex->SetTextSize(0.04); // --- Draw histograms // ---- prompt TCanvas* c1 = new TCanvas("c1","c1",200,10,600,600); c1->cd(); // --- scaling for drawing norm. // h1D_RFB[lowpt_init]->Scale(scalePR_lowpt); // h1D_RFB[highpt_init]->Scale(scalePR_highpt); string ptArr_lowpt; string ptArr_highpt; formPtArr(ptArrNum[lowpt_init], ptArrNum[highpt_init], &ptArr_lowpt); formPtArr(ptArrNum[highpt_init], ptArrNum[nPt], &ptArr_highpt); ////////////////////////////////////////////// /// convert to TGraphErrors //lowpt TGraphAsymmErrors* gRFB_lowpt = new TGraphAsymmErrors(h1D_RFB[lowpt_init]); gRFB_lowpt->SetName("gRFB_lowpt"); for (int iy=0; iy <nRapRFB; iy ++ ){ gRFB_lowpt-> SetPointEXlow(iy, ex[iy]); gRFB_lowpt-> SetPointEXhigh(iy, ex[iy]); gRFB_lowpt->GetPoint(iy, pxtmp_lowpt[iy], pytmp_lowpt[iy]); eytmp[iy] = gRFB_lowpt-> GetErrorY(iy); } //sys_lowpt TGraphAsymmErrors* gRFB_sys_lowpt = new TGraphAsymmErrors(h1D_RFB[lowpt_init]); gRFB_sys_lowpt->SetName("gRFB_sys_lowpt"); for (int iy=0; iy <nRapRFB; iy ++ ){ //abs err calcul. eysys_lowpt[iy]=eysysrel_lowpt[iy]*pytmp_lowpt[iy]; gRFB_sys_lowpt->SetPointError(iy, exsys[iy], exsys[iy], eysys_lowpt[iy], eysys_lowpt[iy]); cout << "pytmp_lowpt["<<iy<<"] = " << pytmp_lowpt[iy]<<endl; cout << "eytmp_lowpt["<<iy<<"] = " << eytmp[iy]<<endl; cout << "eysys_lowpt["<<iy<<"] = " << eysys_lowpt[iy]<<endl; } //highpt TGraphAsymmErrors* gRFB_highpt = new TGraphAsymmErrors(h1D_RFB[highpt_init]); gRFB_highpt->SetName("gRFB_highpt"); for (int iy=0; iy <nRapRFB; iy ++ ){ gRFB_highpt-> SetPointEXlow(iy, ex[iy]); gRFB_highpt-> SetPointEXhigh(iy, ex[iy]); gRFB_highpt->GetPoint(iy, pxtmp_highpt[iy], pytmp_highpt[iy]); gRFB_highpt->SetPoint(iy, pxtmp_highpt[iy]+pxshift, pytmp_highpt[iy]); eytmp[iy] = gRFB_highpt-> GetErrorY(iy); } //sys_highpt TGraphAsymmErrors* gRFB_sys_highpt = new TGraphAsymmErrors(h1D_RFB[highpt_init]); gRFB_sys_highpt->SetName("gRFB_sys_highpt"); for (int iy=0; iy <nRapRFB; iy ++ ){ //abs err calcul. eysys_highpt[iy]=eysysrel_highpt[iy]*pytmp_highpt[iy]; gRFB_sys_highpt->GetPoint(iy, pxtmp_highpt[iy], pytmp_highpt[iy]); gRFB_sys_highpt->SetPoint(iy, pxtmp_highpt[iy]+pxshift, pytmp_highpt[iy]); gRFB_sys_highpt->SetPointError(iy, exsys[iy], exsys[iy], eysys_highpt[iy], eysys_highpt[iy]); cout << "pytmp_highpt["<<iy<<"] = " << pytmp_highpt[iy]<<endl; cout << "eytmp_highpt["<<iy<<"] = " << eytmp[iy]<<endl; cout << "eysys_highpt["<<iy<<"] = " << eysys_highpt[iy]<<endl; } gRFB_sys_lowpt->GetXaxis()->SetTitle("|y_{CM}|"); gRFB_sys_lowpt->GetXaxis()->CenterTitle(); gRFB_sys_lowpt->GetYaxis()->SetTitle("R_{FB}"); // gRFB_sys_lowpt->GetXaxis()->SetLimits(0.,1.93); gRFB_sys_lowpt->GetXaxis()->SetLimits(0.,2.2); //gRFB_sys_lowpt->SetMinimum(0.0); //gRFB_sys_lowpt->SetMaximum(1.4); gRFB_sys_lowpt->SetMinimum(0.5); gRFB_sys_lowpt->SetMaximum(1.15); gRFB_sys_lowpt->SetFillColor(kRed-9); //gRFB_sys_lowpt->SetFillStyle(3001); gRFB_sys_lowpt->Draw("A2"); gRFB_sys_highpt->SetFillColor(kTeal-9); //gRFB_sys_highpt->SetFillStyle(3001); gRFB_sys_highpt->Draw("2"); SetGraphStyle(gRFB_lowpt, 1, 3); gRFB_lowpt->SetMarkerSize(1.2); gRFB_lowpt->Draw("P"); SetGraphStyle(gRFB_highpt, 0, 5); gRFB_highpt->SetMarkerSize(1.9); gRFB_highpt->Draw("P"); // dashedLine(0.,1.,1.93,1.,1,1); dashedLine(0.,1.,2.2,1.,1,1); //if (isPrompt) legBR -> SetHeader("Prompt J/#psi"); //else legBR -> SetHeader("Non-prompt J/#psi"); legBR -> AddEntry(gRFB_lowpt,Form("%s",ptArr_lowpt.c_str())); legBR -> AddEntry(gRFB_highpt,Form("%s",ptArr_highpt.c_str())); legBR->Draw(); // latex->SetTextSize(0.05); // latex->DrawLatex(0.54, 0.35, cmsstring.c_str()); // latex->SetTextSize(0.04); // latex->DrawLatex(0.56, 0.27, beamstring.c_str()); // latex->SetTextSize(0.04); // latex->DrawLatex(0.56, 0.20, lumistring.c_str()); globtex->SetTextSize(0.045); globtex->SetTextFont(62); if (isPrompt) globtex->DrawLatex(0.88, 0.86, "Prompt J/#psi"); else globtex->DrawLatex(0.88, 0.86, "Non-prompt J/#psi"); CMS_lumi( c1, iPeriod, iPos ); c1->Update(); c1->SaveAs(Form("RFB_%s/RFB_rap_isPrompt%d_%s.pdf",dirName,(int)isPrompt,runstring.c_str())); c1->SaveAs(Form("RFB_%s/RFB_rap_isPrompt%d_%s.png",dirName,(int)isPrompt,runstring.c_str())); /////////////////////////////////////////////////////////////////// // save as a root file TFile *outFile = new TFile(Form("RFB_%s/RFB_rap_isPrompt%d.root",dirName,(int)isPrompt),"RECREATE"); outFile->cd(); gRFB_sys_lowpt->Write(); gRFB_lowpt->Write(); gRFB_sys_highpt->Write(); gRFB_highpt->Write(); outFile->Close(); return; } // end of main func.
void draw_cross_pt(bool sysByHand=false, bool noPtWeight=false, bool isScale=true, bool isLog=true, int isPA = 1, bool isPrompt=true) { gROOT->Macro("./tdrstyle_kyo.C"); gStyle->SetTitleYOffset(1.38); //KYO //int iPos=0.;//outOfFrame int iPos=33;//right corner //int iPos=11;//left corner //// pileup rejection!! Double_t pileReg; if (isPA==0) pileReg = 1; else pileReg = 128234./123240.; //const Double_t pileRegRelErr = 0.23; //// zvtx correction!! //const Double_t zvtxCor = 1.064; // not used anymore!! //// BR and lumi info. const Double_t br = 0.0593 ; const Double_t brErr = 0.0006; const Double_t pp_lumi_pb =27.972; // 28.0/pb const Double_t pp_lumi_pb_err = 0.643; // 2.3 % const Double_t pPb_lumi_nb = 34.622; // 34.6/nb const Double_t pPb_lumi_nb_err = 1.211; // 3.5 % Double_t lumi_mub; Double_t lumi_mub_err; if (isPA==0) { lumi_mub = pp_lumi_pb *1000*1000; lumi_mub_err = pp_lumi_pb_err *1000*1000; } else if (isPA==1) { lumi_mub = pPb_lumi_nb * 1000; lumi_mub_err = pPb_lumi_nb_err * 1000; } else { cout << "select among isPA = 0 or 1"<< endl; return ; } cout << "isPA = " << isPA << ", and lumi_mub = " << lumi_mub <<"+-" <<lumi_mub_err << endl; cout << " *** pileReg = " << pileReg << endl; ///////////////////////////////////////////////////////////////////////// //// bin center & systematic uncertainties by hand const int nRap = 8; const int nPt = 9; const int nRapTmp = nRap + 1; const int nPtTmp = nPt + 1; const int nRapRFB = 3; const int nPtRFB = 3; Double_t pxtmp[nRap][nPt]; //x point to fill remporarily Double_t pytmp[nRap][nPt]; //y point to fill remporarily Double_t eytmp[nRap][nPt]; //y point error to fill remporarily Double_t px[nRap][nPt]; /* Double_t px_pp[nRap][nPt] = { //x point (mean pT) by JB -- from FW to BW {2.54567, 3.50886, 4.48508, 5.69331, 6.97532, 7.97107, 9.17601, 11.5322, 17.4867}, {0, 0, 4.54938, 5.75633, 6.9727, 7.97359, 9.17558, 11.4729, 17.4391}, {0, 0, 0, 0, 7.0061, 7.97991, 9.19355, 11.5729, 17.6818}, {0, 0, 0, 0, 7.08557, 8.01392, 9.2137, 11.6042, 17.9741}, {0, 0, 0, 0, 7.08944, 8.01343, 9.21616, 11.6091, 17.7608}, {0, 0, 0, 0, 7.00408, 7.98632, 9.19122, 11.5535, 17.7004}, {0, 0, 4.54198, 5.76465, 6.97492, 7.96787, 9.18318, 11.5223, 17.4279}, {2.54164, 3.5085, 4.48298, 5.69705, 6.97263, 7.97372, 9.17313, 11.5032, 17.3023} }; Double_t px_pA[nRap][nPt] = { //x point (mean pT) by JB -- from FW to BW {2.525, 3.51255, 4.4772, 5.70327, 6.96635, 7.96061, 9.17243, 11.5938, 18.0681}, {0, 0, 4.52793, 5.74033, 6.97622, 7.98335, 9.19458, 11.4927, 17.6693}, {0, 0, 0, 0, 7.018, 8.00224, 9.19714, 11.5483, 17.6577}, {0, 0, 0, 0, 7.11111, 8.02103, 9.24485, 11.6204, 17.8454}, {0, 0, 0, 0, 7.05329, 8.00998, 9.20583, 11.5222, 17.4633}, {0, 0, 0, 5.84477, 6.98466, 7.97917, 9.17551, 11.5322, 17.34}, {0, 0, 4.52204, 5.72881, 6.97074, 7.95284, 9.14157, 11.4976, 17.3058}, {2.51699, 3.4959, 4.47636, 5.68624, 6.97338, 7.97824, 9.1805, 11.4841, 16.8762} }; */ //// for middle Double_t px_pp[nRap][nPt] = { {2.5, 3.5, 4.5, 5.75, 7, 8, 9.25, 12., 22}, {0., 0., 4.5, 5.75, 7, 8, 9.25, 12., 22}, {0., 0., 0., 0., 7, 8, 9.25, 12., 22}, {0., 0., 0., 0., 7, 8, 9.25, 12., 22}, {0., 0., 0., 0., 7, 8, 9.25, 12., 22}, {0., 0., 0., 0., 7, 8, 9.25, 12., 22}, {0., 0., 4.5, 5.75, 7, 8, 9.25, 12., 22}, {2.5, 3.5, 4.5, 5.75, 7, 8, 9.25, 12., 22} }; Double_t px_pA[nRap][nPt] = { {2.5, 3.5, 4.5, 5.75, 7, 8, 9.25, 12., 22}, {0., 0., 4.5, 5.75, 7, 8, 9.25, 12., 22}, {0., 0., 0., 0., 7, 8, 9.25, 12., 22}, {0., 0., 0., 0., 7, 8, 9.25, 12., 22}, {0., 0., 0., 0., 7, 8, 9.25, 12., 22}, {0., 0., 0., 5.75, 7, 8, 9.25, 12., 22}, {0., 0., 4.5, 5.75, 7, 8, 9.25, 12., 22}, {2.5, 3.5, 4.5, 5.75, 7, 8, 9.25, 12., 22} }; Double_t ex[nPt] = {0,0,0,0,0,0,0,0,0}; // x stat error Double_t exlow[nRap][nPt]; // x binWidth Double_t exhigh[nRap][nPt]; // x binWidth Double_t exsys[nPt] = {0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4}; // x sys error Double_t eysysrel[nRap][nPt]; //relative y sys error Double_t eysys[nRap][nPt]; //absolute y sys error for (Int_t iy=0; iy<nRap; iy++) { for (Int_t ipt=0; ipt<nPt; ipt++) { if (isPA==0) { px[iy][ipt] = px_pp[iy][ipt]; } else { px[iy][ipt] = px_pA[iy][ipt]; } } } //// scaling for drawing double scaleF[nRap]; double scaleF_pp[nRap] = {1000., 100., 10., 1., 1., 10., 100., 1000.}; double scaleF_pA[nRap] = {100., 10., 1., 1., 10., 100., 1000., 10000.}; for (int iy=0; iy<nRap; iy++){ if (isPA==0) {scaleF[iy] = scaleF_pp[iy]; } else {scaleF[iy] = scaleF_pA[iy]; } if (!isScale) { scaleF[iy] = 1.; }; cout << "scaleF["<<iy<<"] = " << scaleF[iy] << endl; } //// 1) y_CM array (from forward to backward) Double_t rapArrNumFB_pA[nRapTmp] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87};// for pt dist. //Double_t rapArrNumBF_pA[nRapTmp] = {-2.87, -2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist. Double_t rapArrNumFB_pp[nRapTmp] = {2.4, 1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4};// for pt dist. //Double_t rapArrNumBF_pp[nRapTmp] = {-2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93, 2.4};// for rap dist. Double_t rapArrNumFB[nRapTmp]; for (Int_t iy=0; iy<nRapTmp; iy++) { if (isPA==0) { rapArrNumFB[iy] = rapArrNumFB_pp[iy]; } else { rapArrNumFB[iy] = rapArrNumFB_pA[iy]; } } Double_t rapBinW[nRap]; for (Int_t iy=0; iy<nRap; iy++) { rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1]; //rapBinW[iy] = rapArrNumBF[iy+1]-rapArrNumBF[iy]; } //// 2) pt array Double_t ptArrNum[nPtTmp] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10., 14., 30.}; Double_t ptBinW[nPt]; for (Int_t ipt=0; ipt<nPt; ipt++) { ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt]; } //// array string TString rapArr[nRap]; for (Int_t iy=0; iy<nRap; iy++) { formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]); cout << iy <<"th rapArr = " << rapArr[iy] << endl; } TString ptArr[nPt]; for (Int_t ipt=0; ipt<nPt; ipt++) { formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]); cout << ipt <<"th ptArr = " << ptArr[ipt] << endl; } //// ex calculation for (Int_t iy=0; iy<nRap; iy++) { for (Int_t ipt=0; ipt<nPt; ipt++) { exlow[iy][ipt] = px[iy][ipt]-ptArrNum[ipt]; exhigh[iy][ipt] = ptArrNum[ipt+1]-px[iy][ipt]; } } ////////////////////////////////////////////////////////////// //// read-in sys. file TFile * fSys; if (isPA==0) fSys = new TFile("../TotalSys/TotSys_8rap9pt_pp_etOpt0.root"); else fSys = new TFile("../TotalSys/TotSys_8rap9pt_pA_etOpt0.root"); TH2D* h2D_SysErr; if (isPrompt) h2D_SysErr = (TH2D*)fSys->Get("hTotalPR"); else h2D_SysErr = (TH2D*)fSys->Get("hTotalNP"); ////////////////////////////////////////////////////////////// //// read-in corr-yield file TFile * f2D; if (isPA==0) { if (noPtWeight) f2D = new TFile("../FittingResult/totalHist_pp_8rap9pt_newcut_nominal_Zvtx0_SF1_etOpt0_noPtWeight.root"); else f2D = new TFile("../FittingResult/totalHist_pp_8rap9pt_newcut_nominal_Zvtx0_SF1_etOpt0.root"); } else { if (noPtWeight) f2D = new TFile("../FittingResult/totalHist_pA_8rap9pt_newcut_nominal_Zvtx1_SF1_etOpt0_noPtWeight.root"); else f2D = new TFile("../FittingResult/totalHist_pA_8rap9pt_newcut_nominal_Zvtx1_SF1_etOpt0.root"); } //// read-in 2D hist for corrected yield TH2D* h2D_CorrY; if (isPA==0) { if (isPrompt) h2D_CorrY = (TH2D*)f2D->Get("h2D_CorrY_PR_pp"); else h2D_CorrY = (TH2D*)f2D->Get("h2D_CorrY_NP_pp"); } else { if (isPrompt) h2D_CorrY = (TH2D*)f2D->Get("h2D_CorrY_PR_pA"); else h2D_CorrY = (TH2D*)f2D->Get("h2D_CorrY_NP_pA"); } const int nbinsX = h2D_CorrY->GetNbinsX(); const int nbinsY = h2D_CorrY->GetNbinsY(); if (nbinsX != nRap) { cout << " *** Error!!! nbinsX != nRap"; return; }; if (nbinsY != nPt) { cout << " *** Error!!! nbinsY != nPt"; return; }; //// projection to 1D hist : iy=0 refers to forwards !!! (ordering here) TH1D* h1D_CorrY[nRap]; TH1D* h1D_SysErr[nRap]; for (Int_t iy = 0; iy < nRap; iy++) { if ( isPA==0) { h1D_CorrY[iy] = h2D_CorrY->ProjectionY(Form("h1D_CorrY_%d",iy),nRap-iy,nRap-iy); h1D_SysErr[iy] = h2D_SysErr->ProjectionY(Form("h1D_SysErr_%d",iy),nRap-iy,nRap-iy); } else { h1D_CorrY[iy] = h2D_CorrY->ProjectionY(Form("h1D_CorrY_%d",iy),iy+1,iy+1); h1D_SysErr[iy] = h2D_SysErr->ProjectionY(Form("h1D_SysErr_%d",iy),iy+1,iy+1); } } //// read sys values from hist for (Int_t iy = 0; iy < nRap; iy++) { for (int ipt=0; ipt <nPt; ipt ++ ){ eysysrel[iy][ipt] = h1D_SysErr[iy]->GetBinContent(ipt+1); } } ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// //// calcualte cross-section = corrY/(dPt*dY*lumi) TH1D* h1D_cross[nRap]; for (Int_t iy = 0; iy < nRap; iy++) { h1D_cross[iy] = (TH1D*)h1D_CorrY[iy]->Clone(Form("h1D_cross_%d",iy)); //// normalization h1D_cross[iy]->Scale(1,"width"); //pT bin h1D_cross[iy]->Scale(1./rapBinW[iy]); //rap bin h1D_cross[iy]->Scale(1./lumi_mub); // lumi // h1D_cross[iy]->Scale(1./br); //br h1D_cross[iy]->Scale(pileReg); // pileup correction h1D_cross[iy]->Scale(scaleF[iy]); // scaling for drawing } //// set values as zero for unused bins for (Int_t iy = 0; iy < nRap; iy++) { if (iy>=1 && iy<=6) { h1D_cross[iy]->SetBinContent(1,-532); h1D_cross[iy]->SetBinError(1,0); h1D_cross[iy]->SetBinContent(2,-532); h1D_cross[iy]->SetBinError(2,0); exlow[iy][0]=0; exhigh[iy][0]=0; exlow[iy][1]=0; exhigh[iy][1]=0; } if (iy>=2 && iy<=5) { h1D_cross[iy]->SetBinContent(3,-532); h1D_cross[iy]->SetBinError(3,0); exlow[iy][2]=0; exhigh[iy][2]=0; } if (isPA==0) { if (iy>=2 && iy<=5) { h1D_cross[iy]->SetBinContent(4,-532); h1D_cross[iy]->SetBinError(4,0); exlow[iy][3]=0; exhigh[iy][3]=0; } } else { if (iy>=2 && iy<=4) { h1D_cross[iy]->SetBinContent(4,-532); h1D_cross[iy]->SetBinError(4,0); exlow[iy][3]=0; exhigh[iy][3]=0; } } } ////////////////////////////////////////////////////////////////// TLegend *legBLFW; TLegend *legBLBW; if (isPA==0) { //legBLFW = new TLegend(0.19, 0.160, 0.46, 0.320); //legBLBW = new TLegend(0.19, 0.160, 0.46, 0.320); legBLFW = new TLegend(0.19, 0.160, 0.46, 0.160+0.035*4+0.035*1.2); legBLBW = new TLegend(0.19, 0.160, 0.46, 0.160+0.035*4+0.035*1.2); } else { legBLFW = new TLegend(0.19, 0.160, 0.46, 0.160+0.035*3+0.035*1.2); legBLBW = new TLegend(0.19, 0.160, 0.46, 0.160+0.035*5+0.035*1.2); } SetLegendStyle(legBLFW); SetLegendStyle(legBLBW); //legBLFW->SetTextSize(0.034); //legBLBW->SetTextSize(0.034); TLatex* globtex = new TLatex(); globtex->SetNDC(); //globtex->SetTextAlign(12); //1:left, 2:vertical center globtex->SetTextAlign(32); //3:right 2:vertical center globtex->SetTextFont(42); globtex->SetTextSize(0.04); ////////////////////////////////////////////////////////////////////////////////////// //// convert to TGraphAsymErrors TGraphAsymmErrors* g_cross_sys[nRap]; TGraphAsymmErrors* g_cross[nRap]; for (Int_t iy = 0; iy < nRap; iy++) { g_cross_sys[iy] = new TGraphAsymmErrors(h1D_cross[iy]); g_cross[iy] = new TGraphAsymmErrors(h1D_cross[iy]); g_cross_sys[iy]->SetName(Form("g_cross_sys_%d",iy)); g_cross[iy]->SetName(Form("g_cross_%d",iy)); cout << "::: for excel ::: iy= " << iy << endl; for (Int_t ipt=0; ipt<nPt; ipt++ ){ g_cross_sys[iy]->GetPoint(ipt, pxtmp[iy][ipt], pytmp[iy][ipt]); g_cross_sys[iy]->SetPoint(ipt, px[iy][ipt], pytmp[iy][ipt]); //// absolute error calculation eysys[iy][ipt]=eysysrel[iy][ipt]*pytmp[iy][ipt]; //g_cross_sys[iy]->SetPointError(ipt, exsys[ipt], exsys[ipt], eysys[iy][ipt], eysys[iy][ipt]); g_cross_sys[iy]->SetPointError(ipt, exlow[iy][ipt], exhigh[iy][ipt], eysys[iy][ipt], eysys[iy][ipt]); g_cross[iy]->GetPoint(ipt, pxtmp[iy][ipt], pytmp[iy][ipt]); eytmp[iy][ipt] = g_cross[iy]-> GetErrorY(ipt); g_cross[iy]->SetPoint(ipt, px[iy][ipt], pytmp[iy][ipt]); g_cross[iy]->SetPointEXlow(ipt, ex[ipt]); g_cross[iy]->SetPointEXhigh(ipt, ex[ipt]); //cout << "" << endl; //cout << "cross["<<iy<<"]["<<ipt<<"] = " << pytmp[iy][ipt]<<endl; //cout << "stat.["<<iy<<"]["<<ipt<<"] = " << eytmp[iy][ipt]<<endl; //cout << "sys.["<<iy<<"]["<<ipt<<"] = " << eysys[iy][ipt]<<endl; cout << pytmp[iy][ipt] <<"\t"<<eytmp[iy][ipt] << "\t "<<eysys[iy][ipt]<<endl; } } ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// //// Draw ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// int fw_init_pp = 0, fw_init_pA = 0; int bw_init_pp = 4, bw_init_pA = 3; int fw_init, bw_init; if (isPA==0) { fw_init=fw_init_pp; bw_init=bw_init_pp; } else { fw_init=fw_init_pA; bw_init=bw_init_pA; } for (Int_t iy = 0; iy < nRap; iy++) { g_cross_sys[iy]->GetXaxis()->SetTitle("p_{T} (GeV/c)"); g_cross_sys[iy]->GetXaxis()->CenterTitle(""); g_cross_sys[iy]->GetYaxis()->SetTitle("B d^{2}#sigma/dp_{T}dy (#mub/ GeV/c)"); g_cross_sys[iy]->GetYaxis()->CenterTitle(""); if (isLog) { if (isPA==0) { g_cross_sys[iy]->SetMinimum(0.0000001); g_cross_sys[iy]->SetMaximum(1000.); } else { g_cross_sys[iy]->SetMinimum(0.00001); //g_cross_sys[iy]->SetMaximum(1000000.); g_cross_sys[iy]->SetMaximum(500000.); } } else { g_cross_sys[iy]->SetMinimum(0.0); if (isPA==0) { if (isPrompt) g_cross_sys[iy]->SetMaximum(0.16); else g_cross_sys[iy]->SetMaximum(0.016); } else { if (isPrompt) g_cross_sys[iy]->SetMaximum(20); else g_cross_sys[iy]->SetMaximum(2); } } //g_cross_sys[iy]->GetXaxis()->SetLimits(0.0, 20.); g_cross_sys[iy]->GetXaxis()->SetLimits(0.0, 32.); } //// different color scheme for pp and pA if (isPA==0) { g_cross_sys[0]->SetFillColorAlpha(kMagenta-10,0.5); g_cross_sys[1]->SetFillColorAlpha(kGreen-10,0.5); g_cross_sys[2]->SetFillColorAlpha(kBlue-10,0.5); g_cross_sys[3]->SetFillColorAlpha(kRed-10,0.5); g_cross_sys[4]->SetFillColorAlpha(kRed-10,0.5); g_cross_sys[5]->SetFillColorAlpha(kBlue-10,0.5); g_cross_sys[6]->SetFillColorAlpha(kGreen-10,0.5); g_cross_sys[7]->SetFillColorAlpha(kMagenta-10,0.5); g_cross_sys[0]->SetLineColor(kViolet-6); g_cross_sys[1]->SetLineColor(kGreen+3); g_cross_sys[2]->SetLineColor(kBlue-2); g_cross_sys[3]->SetLineColor(kPink-6); g_cross_sys[4]->SetLineColor(kPink-6); g_cross_sys[5]->SetLineColor(kBlue-2); g_cross_sys[6]->SetLineColor(kGreen+3); g_cross_sys[7]->SetLineColor(kViolet-6); SetGraphStyleFinal(g_cross[0], 8,6); g_cross[0]->SetMarkerSize(1.4); SetGraphStyleFinal(g_cross[1], 0,5); g_cross[1]->SetMarkerSize(2.1); SetGraphStyleFinal(g_cross[2], 2,3); g_cross[2]->SetMarkerSize(1.4); SetGraphStyleFinal(g_cross[3], 1,0); g_cross[3]->SetMarkerSize(1.4); SetGraphStyleFinal(g_cross[4], 1,0); g_cross[4]->SetMarkerSize(1.4); SetGraphStyleFinal(g_cross[5], 2,3); g_cross[5]->SetMarkerSize(1.4); SetGraphStyleFinal(g_cross[6], 0,5); g_cross[6]->SetMarkerSize(2.1); SetGraphStyleFinal(g_cross[7], 8,6); g_cross[7]->SetMarkerSize(1.4); } else { g_cross_sys[0]->SetFillColorAlpha(kGreen-10,0.5); g_cross_sys[1]->SetFillColorAlpha(kBlue-10,0.5); g_cross_sys[2]->SetFillColorAlpha(kRed-10,0.5); g_cross_sys[3]->SetFillColorAlpha(kRed-10,0.5); g_cross_sys[4]->SetFillColorAlpha(kBlue-10,0.5); g_cross_sys[5]->SetFillColorAlpha(kGreen-10,0.5); g_cross_sys[6]->SetFillColorAlpha(kMagenta-10,0.5); g_cross_sys[7]->SetFillColorAlpha(kGray+1,0.5); g_cross_sys[0]->SetLineColor(kGreen+3); g_cross_sys[1]->SetLineColor(kBlue-2); g_cross_sys[2]->SetLineColor(kPink-6); g_cross_sys[3]->SetLineColor(kPink-6); g_cross_sys[4]->SetLineColor(kBlue-2); g_cross_sys[5]->SetLineColor(kGreen+3); g_cross_sys[6]->SetLineColor(kViolet-6); g_cross_sys[7]->SetLineColor(kBlack); SetGraphStyleFinal(g_cross[0], 0,5); g_cross[0]->SetMarkerSize(2.1); SetGraphStyleFinal(g_cross[1], 2,3); g_cross[1]->SetMarkerSize(1.4); SetGraphStyleFinal(g_cross[2], 1,0); g_cross[2]->SetMarkerSize(1.4); SetGraphStyleFinal(g_cross[3], 1,0); g_cross[3]->SetMarkerSize(1.4); SetGraphStyleFinal(g_cross[4], 2,3); g_cross[4]->SetMarkerSize(1.4); SetGraphStyleFinal(g_cross[5], 0,5); g_cross[5]->SetMarkerSize(2.1); SetGraphStyleFinal(g_cross[6], 8,6); g_cross[6]->SetMarkerSize(1.4); SetGraphStyleFinal(g_cross[7], 9,4); g_cross[7]->SetMarkerSize(2.1); } //////// Forward TCanvas* c_fw = new TCanvas("c_fw","c_fw",200,10,600,600); c_fw->cd(); if (isLog) gPad->SetLogy(1); else gPad->SetLogy(0); //// 1) cross_sys for (Int_t iy = fw_init; iy < bw_init; iy++) { if (iy==fw_init) g_cross_sys[iy]->Draw("A5"); else g_cross_sys[iy]->Draw("5"); } //// 2) cross for (Int_t iy = fw_init; iy < bw_init; iy++) { g_cross[iy]->Draw("P"); } //// leg legBLFW->SetTextSize(0.032*1.2); legBLFW -> SetHeader("Forward rapidity"); legBLFW->SetTextSize(0.032); for (Int_t iy = fw_init; iy < bw_init; iy++) { if (isScale && scaleF[bw_init-iy-1]!=1.) legBLFW -> AddEntry(g_cross[bw_init-iy-1],Form("%s (x%.0f)",rapArr[bw_init-iy-1].Data(),scaleF[bw_init-iy-1]),"lp"); else legBLFW -> AddEntry(g_cross[bw_init-iy-1],Form("%s",rapArr[bw_init-iy-1].Data()),"lp"); //if (isScale && scaleF[iy]!=1.) legBLFW -> AddEntry(g_cross[iy],Form("%s (x%.0f)",rapArr[iy].Data(),scaleF[iy]),"lp"); //else legBLFW -> AddEntry(g_cross[iy],Form("%s",rapArr[iy].Data()),"lp"); } if (isLog) legBLFW->Draw(); globtex->SetTextSize(0.048); globtex->SetTextFont(42); if (isPrompt) globtex->DrawLatex(0.92, 0.77, "Prompt J/#psi"); else globtex->DrawLatex(0.92, 0.77, "Nonprompt J/#psi"); // globtex->SetTextSize(0.035); // globtex->SetTextFont(42); // if (isPA==0) globtex->DrawLatex(0.91, 0.80, "Global uncertainty : 4 \%"); // else globtex->DrawLatex(0.91, 0.80, "Global uncertainty : 3.5 \%"); CMS_lumi( c_fw, isPA, iPos ); c_fw->Update(); if (isPA==0){ if (noPtWeight) { c_fw->SaveAs(Form("plot_cross/pp_fw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.pdf",(int)isPrompt,(int)isLog,(int)isScale)); c_fw->SaveAs(Form("plot_cross/pp_fw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.png",(int)isPrompt,(int)isLog,(int)isScale)); } else { c_fw->SaveAs(Form("plot_cross/pp_fw_cross_pt_isPrompt%d_isLog%d_isScale%d.pdf",(int)isPrompt,(int)isLog,(int)isScale)); c_fw->SaveAs(Form("plot_cross/pp_fw_cross_pt_isPrompt%d_isLog%d_isScale%d.png",(int)isPrompt,(int)isLog,(int)isScale)); } } else { if (noPtWeight) { c_fw->SaveAs(Form("plot_cross/pA_fw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.pdf",(int)isPrompt,(int)isLog,(int)isScale)); c_fw->SaveAs(Form("plot_cross/pA_fw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.png",(int)isPrompt,(int)isLog,(int)isScale)); } else { c_fw->SaveAs(Form("plot_cross/pA_fw_cross_pt_isPrompt%d_isLog%d_isScale%d.pdf",(int)isPrompt,(int)isLog,(int)isScale)); c_fw->SaveAs(Form("plot_cross/pA_fw_cross_pt_isPrompt%d_isLog%d_isScale%d.png",(int)isPrompt,(int)isLog,(int)isScale)); } } legBLFW->Clear(); //////// Backward TCanvas* c_bw = new TCanvas("c_bw","c_bw",200,10,600,600); c_bw->cd(); if (isLog) gPad->SetLogy(1); else gPad->SetLogy(0); //// 1) cross_sys for (Int_t iy = bw_init; iy < nRap; iy++) { if (iy==bw_init) g_cross_sys[iy]->Draw("A5"); else g_cross_sys[iy]->Draw("5"); } //// 2) cross for (Int_t iy = bw_init; iy < nRap; iy++) { g_cross[iy]->Draw("P"); } //// leg legBLBW->SetTextSize(0.032*1.2); legBLBW -> SetHeader("Backward rapidity"); legBLBW->SetTextSize(0.032); for (Int_t iy = bw_init; iy < nRap; iy++) { if (isScale && scaleF[iy]!=1.) legBLBW -> AddEntry(g_cross[iy],Form("%s (x%.0f)",rapArr[iy].Data(),scaleF[iy]),"lp"); else legBLBW -> AddEntry(g_cross[iy],Form("%s",rapArr[iy].Data()),"lp"); } if (isLog) legBLBW->Draw(); globtex->SetTextSize(0.048); globtex->SetTextFont(42); if (isPrompt) globtex->DrawLatex(0.92, 0.77, "Prompt J/#psi"); else globtex->DrawLatex(0.92, 0.77, "Nonprompt J/#psi"); // globtex->SetTextSize(0.035); // globtex->SetTextFont(42); // if (isPA==0) globtex->DrawLatex(0.91, 0.80, "Global uncertainty : 4 \%"); // else globtex->DrawLatex(0.91, 0.80, "Global uncertainty : 3.5 \%"); CMS_lumi( c_bw, isPA, iPos ); c_bw->Update(); if (isPA==0){ if (noPtWeight) { c_bw->SaveAs(Form("plot_cross/pp_bw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.pdf",(int)isPrompt,(int)isLog,(int)isScale)); c_bw->SaveAs(Form("plot_cross/pp_bw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.png",(int)isPrompt,(int)isLog,(int)isScale)); } else { c_bw->SaveAs(Form("plot_cross/pp_bw_cross_pt_isPrompt%d_isLog%d_isScale%d.pdf",(int)isPrompt,(int)isLog,(int)isScale)); c_bw->SaveAs(Form("plot_cross/pp_bw_cross_pt_isPrompt%d_isLog%d_isScale%d.png",(int)isPrompt,(int)isLog,(int)isScale)); } } else { if (noPtWeight) { c_bw->SaveAs(Form("plot_cross/pA_bw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.pdf",(int)isPrompt,(int)isLog,(int)isScale)); c_bw->SaveAs(Form("plot_cross/pA_bw_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.png",(int)isPrompt,(int)isLog,(int)isScale)); } else { c_bw->SaveAs(Form("plot_cross/pA_bw_cross_pt_isPrompt%d_isLog%d_isScale%d.pdf",(int)isPrompt,(int)isLog,(int)isScale)); c_bw->SaveAs(Form("plot_cross/pA_bw_cross_pt_isPrompt%d_isLog%d_isScale%d.png",(int)isPrompt,(int)isLog,(int)isScale)); } } legBLBW->Clear(); /////////////////////////////////////////////////////////////////// //// save as a root file TFile *outFile; if (isPA==0) { if (noPtWeight) { outFile = new TFile(Form("plot_cross/pp_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.root",(int)isPrompt,(int)isLog,(int)isScale),"RECREATE"); } else { outFile = new TFile(Form("plot_cross/pp_cross_pt_isPrompt%d_isLog%d_isScale%d.root",(int)isPrompt,(int)isLog,(int)isScale),"RECREATE"); } }else { if (noPtWeight) { outFile = new TFile(Form("plot_cross/pA_cross_pt_isPrompt%d_isLog%d_isScale%d_noPtWeight.root",(int)isPrompt,(int)isLog,(int)isScale),"RECREATE"); } else { outFile = new TFile(Form("plot_cross/pA_cross_pt_isPrompt%d_isLog%d_isScale%d.root",(int)isPrompt,(int)isLog,(int)isScale),"RECREATE"); } } outFile->cd(); for (Int_t iy = 0; iy < nRap; iy++) { g_cross_sys[iy]->Write(); g_cross[iy]->Write(); } outFile->Close(); return; } // end of main func.
void //HTT_ET_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="eleTau_$CATEGORY") HTT_ET_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., TString datacard="htt_et_1_7TeV", string inputfile="root/$HISTFILE", const char* directory="eleTau_$CATEGORY") { // defining the common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category = ""; const char* category_extra = ""; const char* category_extra2 = ""; if(std::string(directory) == std::string("eleTau_0jet_low" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_0jet_low" )){ category_extra = "0-jet low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_0jet_medium" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_0jet_medium" )){ category_extra = "0-jet low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_0jet_high" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_0jet_high" )){ category_extra = "0-jet high p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_1jet_medium" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_1jet_medium" )){ category_extra = "1-jet low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_1jet_high_lowhiggs" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_1jet_high_lowhiggs" )){ category_extra= "1-jet high p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_1jet_high_mediumhiggs")){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_1jet_high_mediumhiggs")){ category_extra= "1-jet high p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_1jet_high_mediumhiggs")){ category_extra2= "boosted"; } if(std::string(directory) == std::string("eleTau_vbf" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_vbf" )){ category_extra = "VBF tag"; } if(std::string(directory) == std::string("eleTau_vbf_loose" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_vbf_loose" )){ category_extra = "Loose VBF tag"; } if(std::string(directory) == std::string("eleTau_vbf_tight" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_vbf_tight" )){ category_extra = "Tight VBF tag"; } if(std::string(directory) == std::string("eleTau_nobtag" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_nobtag" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("eleTau_btag" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_btag" )){ category_extra = "b-tag"; } if(std::string(directory) == std::string("eleTau_nobtag_low" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_nobtag_low" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("eleTau_nobtag_low" )){ category_extra2 = "low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_nobtag_medium" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_nobtag_medium" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("eleTau_nobtag_medium" )){ category_extra2 = "medium p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_nobtag_high" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_nobtag_high" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("eleTau_nobtag_high" )){ category_extra2 = "high p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_btag_low" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_btag_low" )){ category_extra = "b-tag"; } if(std::string(directory) == std::string("eleTau_btag_low" )){ category_extra2 = "low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_btag_high" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_btag_high" )){ category_extra = "b-tag"; } if(std::string(directory) == std::string("eleTau_btag_high" )){ category_extra2 = "high p_{T}^{#tau_{h}}"; } const char* dataset; #ifdef MSSM if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 4.9 fb^{-1} (7 TeV)";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 19.7 fb^{-1} (8 TeV)";} #else if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS, 4.9 fb^{-1} at 7 TeV";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS, 19.7 fb^{-1} at 8 TeV";} #endif TFile* input = new TFile(inputfile.c_str()); #ifdef MSSM TFile* input2 = new TFile((inputfile+"_$MA_$TANB").c_str()); #endif TH1F* Fakes = refill((TH1F*)input->Get(TString::Format("%s/QCD" , directory)), "QCD"); InitHist(Fakes, "", "", TColor::GetColor(250,202,255), 1001); TH1F* EWK0 = refill((TH1F*)input->Get(TString::Format("%s/VV" , directory)), "VV" ); InitHist(EWK0 , "", "", TColor::GetColor(222,90,106), 1001); TH1F* EWK1 = refill((TH1F*)input->Get(TString::Format("%s/W" , directory)), "W" ); InitHist(EWK1 , "", "", TColor::GetColor(222,90,106), 1001); #ifdef EXTRA_SAMPLES TH1F* EWK2 = refill((TH1F*)input->Get(TString::Format("%s/ZJ" , directory)), "ZJ" ); InitHist(EWK2 , "", "", TColor::GetColor(100,182,232), 1001); TH1F* EWK = refill((TH1F*)input->Get(TString::Format("%s/ZL" , directory)), "ZL" ); InitHist(EWK , "", "", TColor::GetColor(100,182,232), 1001); #else TH1F* EWK = refill((TH1F*)input->Get(TString::Format("%s/ZLL" , directory)), "ZLL"); InitHist(EWK , "", "", TColor::GetColor(100,182,232), 1001); #endif TH1F* ttbar = refill((TH1F*)input->Get(TString::Format("%s/TT" , directory)), "TT" ); InitHist(ttbar, "", "", TColor::GetColor(155,152,204), 1001); TH1F* Ztt = refill((TH1F*)input->Get(TString::Format("%s/ZTT" , directory)), "ZTT"); InitHist(Ztt , "", "", TColor::GetColor(248,206,104), 1001); #ifdef MSSM TH1F* ggH = refill((TH1F*)input2->Get(TString::Format("%s/ggH$MA" , directory)), "ggH"); InitSignal(ggH); ggH->Scale($TANB); TH1F* bbH = refill((TH1F*)input2->Get(TString::Format("%s/bbH$MA" , directory)), "bbH"); InitSignal(bbH); bbH->Scale($TANB); #else #ifndef DROP_SIGNAL TH1F* ggH = refill((TH1F*)input->Get(TString::Format("%s/ggH125" , directory)), "ggH"); InitSignal(ggH); ggH->Scale(SIGNAL_SCALE); TH1F* qqH = refill((TH1F*)input->Get(TString::Format("%s/qqH125" , directory)), "qqH"); InitSignal(qqH); qqH->Scale(SIGNAL_SCALE); TH1F* VH = refill((TH1F*)input->Get(TString::Format("%s/VH125" , directory)), "VH" ); InitSignal(VH ); VH ->Scale(SIGNAL_SCALE); #endif #endif #ifdef ASIMOV TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs_asimov", directory)), "data", true); #else TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); #endif InitHist(data, "#bf{m_{#tau#tau} [GeV]}", "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)Fakes->Clone("ref"); ref->Add(EWK0 ); ref->Add(EWK1 ); #ifdef EXTRA_SAMPLES ref->Add(EWK2 ); #endif ref->Add(EWK ); ref->Add(ttbar); ref->Add(Ztt ); double unscaled[7]; unscaled[0] = Fakes->Integral(); unscaled[1] = EWK ->Integral(); unscaled[1]+= EWK0 ->Integral(); unscaled[1]+= EWK1 ->Integral(); #ifdef EXTRA_SAMPLES unscaled[1]+= EWK2 ->Integral(); #endif unscaled[2] = ttbar->Integral(); unscaled[3] = Ztt ->Integral(); #ifdef MSSM unscaled[4] = ggH ->Integral(); unscaled[5] = bbH ->Integral(); unscaled[6] = 0; #else #ifndef DROP_SIGNAL unscaled[4] = ggH ->Integral(); unscaled[5] = qqH ->Integral(); unscaled[6] = VH ->Integral(); #endif #endif if(scaled){ /* Fakes = refill(shape_histos(Fakes, datacard, "QCD"), "QCD"); EWK0 = refill(shape_histos(EWK0, datacard, "VV"), "VV"); EWK1 = refill(shape_histos(EWK1, datacard, "W"), "W"); #ifdef EXTRA_SAMPLES EWK2 = refill(shape_histos(EWK2, datacard, "ZJ"), "ZJ"); EWK = refill(shape_histos(EWK, datacard, "ZL"), "ZL"); #else // EWK = refill(shape_histos(EWK, datacard, "ZLL"), "ZLL"); #endif ttbar = refill(shape_histos(ttbar, datacard, "TT"), "TT"); Ztt = refill(shape_histos(Ztt, datacard, "ZTT"), "ZTT"); #ifdef MSSM ggH = refill(shape_histos(ggH, datacard, "ggH$MA"), "ggH$MA"); bbH = refill(shape_histos(bbH, datacard, "bbH$MA"), "bbH$MA"); #else #ifndef DROP_SIGNAL ggH = refill(shape_histos(ggH, datacard, "ggH"), "ggH"); qqH = refill(shape_histos(qqH, datacard, "qqH"), "qqH"); VH = refill(shape_histos(VH, datacard, "VH"), "VH"); #endif #endif */ rescale(Fakes, 7); rescale(EWK0 , 6); rescale(EWK1 , 3); #ifdef EXTRA_SAMPLES rescale(EWK2 , 4); rescale(EWK , 5); #else rescale(EWK , 4); #endif rescale(ttbar, 2); rescale(Ztt , 1); #ifdef MSSM rescale(ggH , 8); rescale(bbH , 9); #else #ifndef DROP_SIGNAL rescale(ggH , 8); rescale(qqH , 9); rescale(VH ,10); #endif #endif } TH1F* scales[7]; scales[0] = new TH1F("scales-Fakes", "", 7, 0, 7); scales[0]->SetBinContent(1, unscaled[0]>0 ? (Fakes->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-EWK" , "", 7, 0, 7); scales[1]->SetBinContent(2, unscaled[1]>0 ? ((EWK ->Integral() +EWK0 ->Integral() +EWK1 ->Integral() #ifdef EXTRA_SAMPLES +EWK2 ->Integral() #endif )/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-ttbar", "", 7, 0, 7); scales[2]->SetBinContent(3, unscaled[2]>0 ? (ttbar->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-Ztt" , "", 7, 0, 7); scales[3]->SetBinContent(4, unscaled[3]>0 ? (Ztt ->Integral()/unscaled[3]-1.) : 0.); #ifdef MSSM scales[4] = new TH1F("scales-ggH" , "", 7, 0, 7); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH ->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-bbH" , "", 7, 0, 7); scales[5]->SetBinContent(6, unscaled[5]>0 ? (bbH ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-NONE" , "", 7, 0, 7); scales[6]->SetBinContent(7, 0.); #else #ifndef DROP_SIGNAL scales[4] = new TH1F("scales-ggH" , "", 7, 0, 7); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH ->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-qqH" , "", 7, 0, 7); scales[5]->SetBinContent(6, unscaled[5]>0 ? (qqH ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-VH" , "", 7, 0, 7); scales[6]->SetBinContent(7, unscaled[6]>0 ? (VH ->Integral()/unscaled[6]-1.) : 0.); #endif #endif EWK0 ->Add(Fakes); EWK1 ->Add(EWK0 ); #ifdef EXTRA_SAMPLES EWK2 ->Add(EWK1 ); EWK ->Add(EWK2 ); #else EWK ->Add(EWK1 ); #endif ttbar->Add(EWK ); Ztt ->Add(ttbar); if(log){ #ifdef MSSM ggH ->Add(bbH); #else #ifndef DROP_SIGNAL qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } else{ #ifdef MSSM bbH ->Add(Ztt); ggH ->Add(bbH); #else #ifndef DROP_SIGNAL VH ->Add(Ztt); qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } /* Mass plot before and after fit */ TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(345)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(UPPER_EDGE)); }; #else data->GetXaxis()->SetRange(0, data->FindBin(345)); #endif data->SetNdivisions(505); data->SetMinimum(min); #ifndef DROP_SIGNAL data->SetMaximum(max>0 ? max : std::max(std::max(maximum(data, log), maximum(Ztt, log)), maximum(ggH, log))); #else data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log))); #endif data->Draw("e"); TH1F* errorBand = (TH1F*)Ztt ->Clone("errorBand"); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(13); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } if(log){ Ztt ->Draw("histsame"); ttbar->Draw("histsame"); EWK ->Draw("histsame"); EWK1 ->Draw("histsame"); Fakes->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif } else{ #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif Ztt ->Draw("histsame"); ttbar->Draw("histsame"); EWK ->Draw("histsame"); EWK1 ->Draw("histsame"); Fakes->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{e}#tau_{h}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); #if defined MSSM TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "tlbrNDC"); if (category_extra2!="") chan = new TPaveText(0.20, 0.69+0.061, 0.32, 0.74+0.161, "tlbrNDC"); #else TPaveText* chan = new TPaveText(0.52, 0.35, 0.91, 0.55, "tlbrNDC"); #endif chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(category); chan->AddText(category_extra); #if defined MSSM if (category_extra2!="") chan->AddText(category_extra2); #else chan->AddText(category_extra2); #endif chan->Draw(); /* TPaveText* cat = new TPaveText(0.20, 0.71+0.061, 0.32, 0.71+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); TPaveText* cat2 = new TPaveText(0.20, 0.66+0.061, 0.32, 0.66+0.161, "NDC"); cat2->SetBorderSize( 0 ); cat2->SetFillStyle( 0 ); cat2->SetTextAlign( 12 ); cat2->SetTextSize ( 0.05 ); cat2->SetTextColor( 1 ); cat2->SetTextFont ( 62 ); cat2->AddText(category_extra2); cat2->Draw(); */ #ifdef MSSM TPaveText* massA = new TPaveText(0.53, 0.44+0.061, 0.95, 0.44+0.151, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("MSSM m^{h}_{max} scenario"); massA->AddText("m_{A}=$MA GeV, tan#beta=$TANB"); massA->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.53, 0.60, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(ggH , "h,A,H#rightarrow#tau#tau" , "L" ); #else TLegend* leg = new TLegend(0.52, 0.58, 0.92, 0.89); SetLegendStyle(leg); #ifndef DROP_SIGNAL if(SIGNAL_SCALE!=1){ leg->AddEntry(ggH , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" ); } else{ leg->AddEntry(ggH , "SM H(125 GeV)#rightarrow#tau#tau" , "L" ); } #endif #endif #ifdef ASIMOV leg->AddEntry(data , "sum(bkg) + H(125)" , "LP"); #else leg->AddEntry(data , "Observed" , "LP"); #endif leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(EWK , "Z#rightarrow ee" , "F" ); leg->AddEntry(EWK1 , "W+jets" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); $ERROR_LEGEND leg->Draw(); /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* model = (TH1F*)Ztt ->Clone("model"); TH1F* test1 = (TH1F*)data->Clone("test1"); for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){ //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01); model->SetBinError (ibin+1, CONVERVATIVE_CHI2 ? 0. : model->GetBinError (ibin+1)*model->GetBinWidth(ibin+1)); test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1)); test1->SetBinError (ibin+1, test1->GetBinError (ibin+1)*test1->GetBinWidth(ibin+1)); } double chi2prob = test1->Chi2Test (model,"PUW"); std::cout << "chi2prob:" << chi2prob << std::endl; double chi2ndof = test1->Chi2Test (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl; double ksprob = test1->KolmogorovTest(model); std::cout << "ksprob :" << ksprob << std::endl; double ksprobpe = test1->KolmogorovTest(model,"DX"); std::cout << "ksprobpe:" << ksprobpe << std::endl; std::vector<double> edges; TH1F* zero = (TH1F*)ref->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat1"); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ rat1->SetBinContent(ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinContent(ibin+1)/Ztt->GetBinContent(ibin+1) : 0); rat1->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); zero->SetBinContent(ibin+1, 0.); zero->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? Ztt ->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } } float range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+range); rat1->SetMinimum(-range); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat1->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->SetMarkerSize(0.1); zero->Draw("e2histsame"); canv0->RedrawAxis(); TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC"); stat1->SetBorderSize( 0 ); stat1->SetFillStyle( 0 ); stat1->SetTextAlign( 12 ); stat1->SetTextSize ( 0.05 ); stat1->SetTextColor( 1 ); stat1->SetTextFont ( 62 ); stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f", chi2ndof, chi2prob)); //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f, P(KS)=%.3f", chi2ndof, chi2prob, ksprob)); stat1->Draw(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); edges.clear(); TH1F* rat2 = (TH1F*) Ztt->Clone("rat2"); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ rat2->SetBinContent(ibin+1, ref->GetBinContent(ibin+1)>0 ? Ztt->GetBinContent(ibin+1)/ref->GetBinContent(ibin+1) : 0); rat2->SetBinError (ibin+1, ref->GetBinContent(ibin+1)>0 ? Ztt->GetBinError (ibin+1)/ref->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat2->GetBinContent(ibin+1)-1.)+TMath::Abs(rat2->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } #if defined MSSM if(!log){ rat2->GetXaxis()->SetRange(0, rat2->FindBin(345)); } else{ rat2->GetXaxis()->SetRange(0, rat2->FindBin(UPPER_EDGE)); }; #else rat2->GetXaxis()->SetRange(0, rat2->FindBin(345)); #endif rat2->SetNdivisions(505); rat2->SetLineColor(kRed+ 3); rat2->SetMarkerColor(kRed+3); rat2->SetMarkerSize(1.1); rat2->SetMaximum(+range); rat2->SetMinimum(-range); rat2->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat2->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->Draw("e2histsame"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[0], "", "", TColor::GetColor(250,202,255), 1001); InitHist (scales[1], "", "", TColor::GetColor(222,90,106), 1001); InitHist (scales[2], "", "", TColor::GetColor(155,152,204), 1001); InitHist (scales[3], "", "", TColor::GetColor(248,206,104), 1001); #ifndef DROP_SIGNAL InitSignal(scales[4]); InitSignal(scales[5]); InitSignal(scales[6]); #endif scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}" ); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}" ); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}" ); scales[0]->GetXaxis()->SetBinLabel(7, "NONE" ); #else scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{qqH}" ); scales[0]->GetXaxis()->SetBinLabel(7, "#bf{VH}" ); #endif scales[0]->SetMaximum(+0.5); scales[0]->SetMinimum(-0.5); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); #ifndef DROP_SIGNAL scales[4]->Draw("same"); scales[5]->Draw("same"); scales[6]->Draw("same"); #endif TH1F* zero_samples = (TH1F*)scales[0]->Clone("zero_samples"); zero_samples->Clear(); zero_samples->SetBinContent(1,0.); zero_samples->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sfit_%s_%s.png" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.pdf" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.eps" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); if(!log || FULLPLOTS) { canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } if((!log && scaled) || FULLPLOTS) { canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } TFile* output = new TFile(TString::Format("%s_%sfit_%s_%s.root", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"), "update"); output->cd(); data ->Write("data_obs"); Fakes->Write("Fakes" ); EWK ->Write("Zee" ); EWK1 ->Write("EWK" ); //EWK ->Write("EWK" ); EWK1 ->Write("EWK1" ); ttbar->Write("ttbar" ); Ztt ->Write("Ztt" ); #ifdef MSSM ggH ->Write("ggH" ); bbH ->Write("bbH" ); #else #ifndef DROP_SIGNAL ggH ->Write("ggH" ); qqH ->Write("qqH" ); VH ->Write("VH" ); #endif #endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); delete errorBand; delete model; delete test1; delete zero; delete rat1; delete rat2; delete zero_samples; delete ref; }
void bbtt_upg_em(std::string var,int nbins, double xmin, double xmax,std::string xtitle, std::string ytitle, double sigscale=1) { TFile *outDC = new TFile("hh_em_inputs.root","RECREATE"); SetStyle(); gStyle->SetLineStyleString(11,"20 10"); TH1::SetDefaultSumw2(1); //std::string dir = "/data/blue/Bacon/029a/Upgrade/merged_talk_jun30/"; std::string dir = "/afs/cern.ch/work/j/jlawhorn/public/ntuples/"; std::stringstream scale; scale << sigscale; //Cut definitions double luminosity = 3000; std::stringstream lumi; lumi << luminosity; std::string objcut = "(tauCat1==3 && tauCat2==2 && ptTau1>20 && ptTau2>20 && tauIso2<0.4 && tauIso1<0.4 && (bTag1==2||bTag1==3||bTag1==6||bTag1==7) && (bTag2==1||bTag2==3||bTag2==6||bTag2==7) && ptB1>20 && ptB2>20 && sqrt( (etaTau1-etaTau2)**2 + (phiTau1-phiTau2)**2 )>0.4)"; std::string jetcut = objcut+"*(mTT>20 && mTT<90)*(mBB1>70 && mBB1<140)*(mt2pileup>100)*(bdtVal>-0.05)"; //signal region std::string mccut = jetcut+"*eventWeight*"+lumi.str(); std::string sigcut = jetcut+"*eventWeight*"+lumi.str(); std::string zjetcut = jetcut+"*eventWeight*(eventType==4)*"+lumi.str(); std::string wjetcut = jetcut+"*eventWeight*(eventType==3)*"+lumi.str(); std::string ewkcut = jetcut+"*eventWeight*(eventType!=1)*"+lumi.str(); //-------------------------------------------------------------------------- //Get the trees TTree *hhtree = load(dir+"HHToTTBB_14TeV.root"); TTree *tttree = load(dir+"tt.root"); //TTree *vbfhtree = load(dir+"VBFToTT_14TeV_phase2.root"); //TTree *gfhtree = load(dir+"H.root"); //TTree *vjettree = load(dir+"Vjets.root"); //TTree *ewktree = load(dir+"diboson.root"); //------------------------------------------------------------------------- //Get histograms TCanvas *canv0 = MakeCanvas("canv", "histograms", 600, 600); canv0->cd(); std::string vardraw; /* TH1F *Ztt = new TH1F("DY","",nbins,xmin,xmax); vardraw = var+">>"+"DY"; vjettree->Draw(vardraw.c_str(),zjetcut.c_str()); InitHist(Ztt , xtitle.c_str(), ytitle.c_str(), TColor::GetColor(248,206,104), 1001);*/ TH1F *ttbar = new TH1F("TTbar","",nbins,xmin,xmax); vardraw = var+">>"+"TTbar"; tttree->Draw(vardraw.c_str(),mccut.c_str()); InitHist(ttbar, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(155,152,204), 1001); /* TH1F *wjets = new TH1F("Wjets","",nbins,xmin,xmax); vardraw = var+">>"+"Wjets"; vjettree->Draw(vardraw.c_str(),wjetcut.c_str()); InitHist(wjets, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(222,90,106), 1001); TH1F *ewk = new TH1F("Ewk","",nbins,xmin,xmax); vardraw = var+">>"+"Ewk"; ewktree->Draw(vardraw.c_str(),ewkcut.c_str()); InitHist(ewk, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(222,90,106), 1001); TH1F *vbfh = new TH1F("VBFH","",nbins,xmin,xmax); vardraw = var+">>"+"VBFH"; vbfhtree->Draw(vardraw.c_str(),mccut.c_str()); InitHist(vbfh, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(250,202,255), 1001); TH1F *ggh = new TH1F("GGH","",nbins,xmin,xmax); vardraw = var+">>"+"GGH"; gfhtree->Draw(vardraw.c_str(),mccut.c_str()); InitHist(ggh, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(250,202,255), 1001);*/ TH1F *smhh = new TH1F("SMhh","",nbins,xmin,xmax); vardraw = var+">>"+"SMhh"; hhtree->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(smhh); smhh->SetLineColor(kBlack); delete canv0; //--------------------------------------------------------------------------- //Print out the yields Double_t error=999; //ofstream outfile; //outfile.open("yields.txt"); //outfile << "Yields for the signal region." << std::endl; cout << "SM hh " << smhh->IntegralAndError(0,smhh->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; /* outfile << "SM h " << smhh->IntegralAndError(0,smhh->GetNbinsX(),error) << "+/-" << error << endl; outfile << "Ztt " << Ztt->IntegralAndError(0,Ztt->GetNbinsX(),error) << "+/-" << error << endl;*/ cout << "ttbar " << ttbar->IntegralAndError(0,ttbar->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; /* outfile << "ewk " << ewk->IntegralAndError(0,ewk->GetNbinsX(),error) << "+/-" << error << endl; outfile << "wjets " << wjets->IntegralAndError(0,wjets->GetNbinsX(),error) << "+/-" << error << endl;*/ //-------------------------------------------------------------------------- //outfile.close(); outDC->cd(); TDirectory* lTD = outDC->mkdir("emu"); outDC->cd(lTD->GetPath()); ttbar->SetName("data_obs"); ttbar->SetTitle("data_obs"); ttbar->Write(); /*Ztt->SetName("ZTT"); Ztt->SetTitle("ZTT"); Ztt->Write();*/ ttbar->SetName("TT"); ttbar->SetTitle("TT"); ttbar->Write(); /*wjets->SetName("W"); wjets->SetTitle("W"); wjets->Write(); ewk->SetName("VV"); ewk->SetTitle("VV"); ewk->Write(); vbfh->SetName("qqH"); vbfh->SetTitle("qqH"); vbfh->Write(); ggh->SetName("ggH"); ggh->SetTitle("ggH"); ggh->Write();*/ smhh->SetName("ggHH"); smhh->SetTitle("ggHH"); smhh->Write(); outDC->Close(); //stack some histtograms together //vbfh->Add(ggh); //wjets->Add(ewk); //----------------------------------------------------------------------- smhh->Scale(sigscale); //Draw the histograms TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); //wjets->Add(ttbar); //Ztt->Add(wjets); //vbfh->Add(Ztt); //Error band stat //TH1F* errorBand = (TH1F*)vbfh ->Clone("errorBand"); TH1F* errorBand = (TH1F*)ttbar ->Clone("errorBand"); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(13); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); // for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ // if(errorBand->GetBinContent(idx)>0){ // std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; // break; // } //} ttbar->SetMaximum(1.1*std::max(maximum(ttbar, 0), maximum(smhh, 0))); //blind(data,75,150); //data->Draw("e"); //vbfh->Draw("hist"); //Ztt->Draw("histsame"); //wjets->Draw("histsame"); //ttbar->Draw("histsame"); ttbar->SetTitle(""); ttbar->Draw("hist"); //data->Draw("esame"); errorBand->Draw("e2same"); smhh->Draw("histsame"); canv->RedrawAxis(); //canv->SetLogy(1); //--------------------------------------------------------------------------- //Adding a legend TLegend* leg = new TLegend(0.53, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(smhh , TString::Format("%.0f#timeshh#rightarrow#tau#tau bb", sigscale) , "L" ); //leg->AddEntry(smhh , TString::Format("%.0f#timeshh#rightarrow#tau#tau bb", sigscale1) , "L" ); //leg->AddEntry(data , "Observed" , "LP"); //leg->AddEntry(vbfh , "SM H#rightarrow#tau#tau" , "F" ); //leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); //leg->AddEntry(wjets , "Electroweak" , "F" ); leg->AddEntry(errorBand,"bkg. uncertainty","F"); leg->Draw(); //--------------------------------------------------------------------------- //CMS preliminary const char* dataset = "CMS Simulation, 3000 fb^{-1} at 14 TeV"; const char* category = ""; CMSPrelim(dataset, "#tau_{e}#tau_{#mu}", 0.17, 0.835); //CMSPrelim(dataset, "", 0.16, 0.835); TPaveText* chan = new TPaveText(0.52, 0.35, 0.91, 0.55, "tlbrNDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(category); chan->Draw(); //------------------------------------------------------------------------- //Save histograms canv->Print((var+"_em.png").c_str()); /* Ratio Data over MC */ /* TCanvas *canv1 = MakeCanvas("canv0", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); TH1F* model = (TH1F*)Ztt ->Clone("model"); TH1F* test1 = (TH1F*)vbfh->Clone("test1"); for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){ //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01); //model->SetBinError (ibin+1, CONVERVATIVE_CHI2 ? 0. : model->GetBinError (ibin+1)*model->GetBinWidth(ibin+1)); model->SetBinError (ibin+1, 0); test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1)); test1->SetBinError (ibin+1, test1->GetBinError (ibin+1)*test1->GetBinWidth(ibin+1)); } double chi2prob = test1->Chi2Test (model,"PUW"); std::cout << "chi2prob:" << chi2prob << std::endl; double chi2ndof = test1->Chi2Test (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl; double ksprob = test1->KolmogorovTest(model); std::cout << "ksprob :" << ksprob << std::endl; double ksprobpe = test1->KolmogorovTest(model,"DX"); std::cout << "ksprobpe:" << ksprobpe << std::endl; std::vector<double> edges; TH1F* zero = (TH1F*)ttbar->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)vbfh->Clone("rat1"); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ rat1->SetBinContent(ibin+1, Ztt->GetBinContent(ibin+1)>0 ? vbfh->GetBinContent(ibin+1)/Ztt->GetBinContent(ibin+1) : 0); rat1->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? vbfh->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); zero->SetBinContent(ibin+1, 0.); zero->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? Ztt ->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } } float range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+range); rat1->SetMinimum(-range); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat1->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->SetMarkerSize(0.1); zero->Draw("e2histsame"); canv1->RedrawAxis(); TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC"); stat1->SetBorderSize( 0 ); stat1->SetFillStyle( 0 ); stat1->SetTextAlign( 12 ); stat1->SetTextSize ( 0.05 ); stat1->SetTextColor( 1 ); stat1->SetTextFont ( 62 ); stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f", chi2ndof, chi2prob)); //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f, P(KS)=%.3f", chi2ndof, chi2prob, ksprob)); //stat1->Draw(); canv1->Print((var+"_ratio.png").c_str()); */ }
void draw_1D_vsZvtx(int isPA = 2, TString szDir = "dir_vsZvtx") { gROOT->Macro("../Style.C"); // --- read-in file TFile * f01; TFile * f02; TString f01name="prompt"; TString f02name="non-prompt"; TString szPA; if (isPA==0) szPA="pp"; else if (isPA==1) szPA="Pbp"; else if (isPA==2) szPA="pPb"; else {cout << "select among isPA = 0, 1, or 2 (pp, Pbp or pPb) "<< endl; return; } f01 = new TFile(Form("EffAna_8rap9pt_%s_PR_newcut_Zvtx0_SF0_vsZvtx.root",szPA.Data())); f02 = new TFile(Form("EffAna_8rap9pt_%s_NP_newcut_Zvtx0_SF0_vsZvtx.root",szPA.Data())); const int nRap = 8; TH1D* h1D_Eff01[nRap]; TH1D* h1D_Eff02[nRap]; for (int ir=0; ir <nRap; ir++) { h1D_Eff01[ir] = (TH1D*)f01->Get(Form("h1D_Eff_zVtx_%d",ir)); h1D_Eff02[ir] = (TH1D*)f02->Get(Form("h1D_Eff_zVtx_%d",ir)); h1D_Eff01[ir]->SetName(Form("h1D_Eff01_%d",ir)); h1D_Eff02[ir]->SetName(Form("h1D_Eff02_%d",ir)); cout << ir << "th h1D_Eff01 = " << h1D_Eff01[ir] << endl; cout << ir << "th h1D_Eff02 = " << h1D_Eff02[ir] << endl; h1D_Eff01[ir]->GetYaxis()->SetRangeUser(0.,1.); } //// for vsZvtx const int nrap = nRap; Double_t ptLimitPP[9]= {2.0, 4.0, 6.5, 6.5, 6.5, 6.5, 4.0, 2.0}; Double_t ptLimitPbp[9]= {2.0, 4.0, 6.5, 6.5, 6.5, 5.0, 4.0, 2.0}; Double_t ptLimitpPb[9] = {2.0, 4.0, 5.0, 6.5, 6.5, 6.5, 4.0, 2.0}; Double_t ptLimit[nrap]; for (Int_t iy=0; iy<nRap; iy++){ if (isPA==0) ptLimit[iy]=ptLimitPP[iy]; else if (isPA==1) ptLimit[iy]=ptLimitPbp[iy]; else ptLimit[iy]=ptLimitpPb[iy]; cout << iy <<"th ptLimit = " << ptLimit[iy] <<endl; } Double_t rapEdge[nRap+1]; Double_t rapEdgePP[9] = {-2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93, 2.4}; // 8rap9pt Double_t rapEdgePbp[9] = {-2.4, -1.97, -1.37, -0.47, 0.43, 1.03, 1.46, 1.93, 2.4}; // 8rap9pt Double_t rapEdgepPb[9] = {-2.4, -1.93, -1.46, -1.03, -0.43, 0.47, 1.37, 1.97, 2.4}; for (Int_t iy=0; iy<nRap+1; iy++){ if (isPA==0) rapEdge[iy]=rapEdgePP[iy]; else if (isPA==1) rapEdge[iy]=rapEdgePbp[iy]; else rapEdge[iy]=rapEdgepPb[iy]; cout << iy <<"th rapEdge = " << rapEdge[iy] <<endl; } TLegend *legMR = new TLegend(0.53,0.50,0.87,0.67,NULL,"brNDC"); TLegend *legBR = new TLegend(0.53,0.20,0.87,0.37,NULL,"brNDC"); SetLegendStyle(legMR); SetLegendStyle(legBR); TLatex* latex = new TLatex(); latex->SetNDC(); latex->SetTextAlign(12); latex->SetTextSize(0.04); ////////////////////////////////////////////////////////////////// // --- Draw histograms //TCanvas* c1 = new TCanvas("c1","c1",600,600); //c1->cd(); TCanvas* c1 = new TCanvas("c1","c1",1600,800); c1->Divide(4,2); for (Int_t iy = 0; iy < nRap; iy++) { c1->cd(iy+1); //SetHistStyle(h1D_Eff01[iy],0,0); h1D_Eff01[iy]->GetXaxis()->SetTitle("primary Z vertex (cm)"); h1D_Eff01[iy]->GetYaxis()->SetTitle("Efficiency"); h1D_Eff01[iy]->SetMinimum(0.); h1D_Eff01[iy]->SetMaximum(1.); SetHistStyle(h1D_Eff01[iy],1,0); SetHistStyle(h1D_Eff02[iy],2,10); h1D_Eff01[iy]->Draw("pe"); h1D_Eff02[iy]->Draw("pe same"); //if (iy==0) latex->DrawLatex(0.50,0.87,sampleName); //latex->DrawLatex(0.50,0.80,Form("%.2f < y_{lab} < %.2f",rapEdge[iy],rapEdge[iy+1])); //latex->DrawLatex(0.50,0.73,Form("%.1f < p_{T} <30 GeV/c",ptLimit[iy])); latex->DrawLatex(0.53,0.87,Form("%.2f < y_{lab} < %.2f",rapEdge[iy],rapEdge[iy+1])); latex->DrawLatex(0.53,0.80,Form("%.1f < p_{T} <30 (GeV/c)",ptLimit[iy])); if (iy==0){ legBR->AddEntry(h1D_Eff01[iy],f01name,"lp"); legBR->AddEntry(h1D_Eff02[iy],f02name,"lp"); legBR->Draw(); } } c1->SaveAs(Form("%s/%s_vsZvtx.pdf",szDir.Data(),szPA.Data())); return; }
void draw_1D_eff_Zvtx1_Zvtx0_pp(TString szBinning="8rap9pt", bool isPrompt=false, bool isLog=false, bool isNoErr=true) { gROOT->Macro("../Style.C"); double ratiomin = 0.9; double ratiomax = 1.1; TString szPrompt; if (isPrompt) szPrompt = "PR"; else szPrompt = "NP"; ////rap array in yCM (from forward to backward) //Double_t rapArrNumFB[] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87};// for pt dist. Double_t rapArrNumFB[] = {2.4, 1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4};// for pt dist. //Double_t rapArrNumBF[] = {-2.87, -2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist. //Double_t rapArrNumBF[] = {-2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93, 2.4};// for rap dist. const Int_t nRap = sizeof(rapArrNumFB)/sizeof(Double_t)-1; cout << "nRap = " << nRap << endl; Double_t rapBinW[nRap]; for (Int_t iy=0; iy<nRap; iy++) { rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1]; } ////pt array Double_t ptArrNum[] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10., 14., 30.}; //8rap9pt //Double_t ptArrNum[] = {5.0, 6.5, 10., 30.}; //8rap3pt const Int_t nPt = sizeof(ptArrNum)/sizeof(Double_t)-1; cout << "nPt = " << nPt << endl; Double_t ptBinW[nPt]; for (Int_t ipt=0; ipt<nPt; ipt++) { ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt]; } //// array TString TString rapArr[nRap]; for (Int_t iy=0; iy<nRap; iy++) { formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]); cout << iy <<"th rapArr = " << rapArr[iy] << endl; } TString ptArr[nPt]; for (Int_t ipt=0; ipt<nPt; ipt++) { formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]); cout << ipt <<"th ptArr = " << ptArr[ipt] << endl; } // --- read-in file TFile * f2D_pp01 = new TFile(Form("../FittingResult/totalHist_pp_%s_newcut_nominal_Zvtx1_SF1_noPtWeight.root",szBinning.Data())); TFile * f2D_pp02 = new TFile(Form("../FittingResult/totalHist_pp_%s_newcut_nominal_Zvtx0_SF1_noPtWeight.root",szBinning.Data())); // --- read-in 2D hist for data reco dist TH2D* h2D_pp01 = (TH2D*)f2D_pp01->Get(Form("h2D_Eff_%s_pp",szPrompt.Data())); TH2D* h2D_pp02 = (TH2D*)f2D_pp02->Get(Form("h2D_Eff_%s_pp",szPrompt.Data())); cout << "h2D_pp01 = " << h2D_pp01 << endl; cout << "h2D_pp02 = " << h2D_pp02 << endl; const int nbinsX = h2D_pp01->GetNbinsX(); const int nbinsY = h2D_pp01->GetNbinsY(); cout << "nbinsX = " << nbinsX << endl; cout << "nbinsY = " << nbinsY << endl; if (nbinsX != nRap) { cout << " *** Error!!! nbinsX != nRap"; return; }; if (nbinsY != nPt) { cout << " *** Error!!! nbinsY != nPt"; return; }; // --- projection to 1D hist TH1D* h1D_pp01[nbinsX]; TH1D* h1D_pp02[nbinsX]; //// iy=0 refers to forwards !!! (ordering here) for (Int_t iy = 0; iy < nbinsX; iy++) { h1D_pp01[iy] = h2D_pp01->ProjectionY(Form("h1D_pp01_%d",iy),nbinsX-iy,nbinsX-iy); h1D_pp02[iy] = h2D_pp02->ProjectionY(Form("h1D_pp02_%d",iy),nbinsX-iy,nbinsX-iy); } ////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////// //// --- set values as zero for unused bins //// 8rap9pt pp for (Int_t iy = 0; iy < nbinsX; iy++) { if (iy>=1 && iy<=6) { h1D_pp01[iy]->SetBinContent(1,-532); h1D_pp01[iy]->SetBinError(1,0); h1D_pp02[iy]->SetBinContent(1,+532); h1D_pp02[iy]->SetBinError(1,0); h1D_pp01[iy]->SetBinContent(2,-532); h1D_pp01[iy]->SetBinError(2,0); h1D_pp02[iy]->SetBinContent(2,+532); h1D_pp02[iy]->SetBinError(2,0); } if (iy>=2 && iy<=5) { h1D_pp01[iy]->SetBinContent(3,-532); h1D_pp01[iy]->SetBinError(3,0); h1D_pp02[iy]->SetBinContent(3,+532); h1D_pp02[iy]->SetBinError(3,0); } //if (iy>=2 && iy<=4) {}//pp if (iy>=2 && iy<=5) { h1D_pp01[iy]->SetBinContent(4,-532); h1D_pp01[iy]->SetBinError(4,0); h1D_pp02[iy]->SetBinContent(4,+532); h1D_pp02[iy]->SetBinError(4,0); } } /* ////// after zero-bin setting, normalize! for (Int_t iy = 0; iy < nbinsX; iy++) { h1D_pp01[iy]->Scale(1./h1D_pp01[iy]->Integral()); h1D_pp01[iy]->Scale(1,"width"); h1D_pp02[iy]->Scale(1./h1D_pp02[iy]->Integral()); h1D_pp02[iy]->Scale(1,"width"); } */ //// calculate ratio TH1D* hRatio_pp[nRap]; for (Int_t iy = 0; iy < nbinsX; iy++) { hRatio_pp[iy]=(TH1D*)h1D_pp01[iy]->Clone(Form("hRatio_pp_%d",iy)); hRatio_pp[iy]->Divide(h1D_pp02[iy]); if (isNoErr) { for (int ipt=0; ipt<nbinsY; ipt++) { hRatio_pp[iy]->SetBinError(ipt+1,0.); cout << iy <<"th rap, "<<ipt<<"th pT, ratio = "<<hRatio_pp[iy]->GetBinContent(ipt+1)<<endl; } } } ////////////////////////////////////////////////////////////////// //// Draw plots ////////////////////////////////////////////////////////////////// TGraphAsymmErrors* g_pp01[nbinsX]; TGraphAsymmErrors* g_pp02[nbinsX]; TLegend *legBR = new TLegend(0.55, 0.28, 0.86, 0.40); SetLegendStyle(legBR); //latex box for beam, rapidity, pT info TLatex* latex = new TLatex(); latex->SetNDC(); latex->SetTextAlign(12); latex->SetTextSize(0.04); TCanvas* c01 = new TCanvas("c01","c01",200,10,1600,800); c01->Divide(4,2); for (Int_t iy = 0; iy < nbinsX; iy++) { g_pp01[iy]=new TGraphAsymmErrors(h1D_pp01[iy]); g_pp01[iy]->SetName(Form("g_pp01_%d",iy)); g_pp02[iy]=new TGraphAsymmErrors(h1D_pp02[iy]); g_pp02[iy]->SetName(Form("g_pp02_%d",iy)); c01->cd(iy+1); if (isLog) gPad->SetLogy(1); else gPad->SetLogy(0); SetGraphStyle(g_pp01[iy],3,0); SetGraphStyle(g_pp02[iy],4,10); g_pp01[iy]->GetXaxis()->SetTitle("p_{T} (GeV/c)"); g_pp01[iy]->GetXaxis()->CenterTitle(); g_pp01[iy]->GetXaxis()->SetLimits(0.0,30.0); g_pp01[iy]->GetYaxis()->SetTitle("Efficiency"); g_pp01[iy]->GetYaxis()->SetRangeUser(0,1.0); g_pp01[iy]->Draw("AP"); g_pp02[iy]->Draw("P"); if (iy==0) { legBR -> AddEntry(g_pp01[iy],"z vtx weight","lp"); legBR -> AddEntry(g_pp02[iy],"no weight","lp"); legBR->Draw(); if (isPrompt) latex->DrawLatex(0.19,0.23,"pp Prompt J/#psi"); else latex->DrawLatex(0.19, 0.23,"pp Nonprompt J/#psi"); } latex->DrawLatex(0.55,0.23,Form("%s",rapArr[iy].Data())); } c01->Modified(); c01->Update(); c01->SaveAs(Form("dir_1D_%s/eff_isPrompt%d_isLog%d_Zvtx1_Zvtx0_pp.pdf",szBinning.Data(),(int)isPrompt,(int)isLog)); ////////////////////////////////////////////////////////////////// //// hRatio, and convert to gRatio (TGraphAsymErrors) ////////////////////////////////////////////////////////////////// TCanvas* c02 = new TCanvas("c02","c02",200,10,1600,800); c02->Divide(4,2); TGraphAsymmErrors* gRatio_pp[nbinsX]; for (Int_t iy = 0; iy < nbinsX; iy++) { gRatio_pp[iy]=new TGraphAsymmErrors(hRatio_pp[iy]); gRatio_pp[iy]->SetName(Form("gRatio_pp_%d",iy)); SetGraphStyle(gRatio_pp[iy],1,0); /* for (Int_t ipt=0; ipt<nbinsY; ipt++ ){ gRatio_pp[iy]->GetPoint(ipt, pxtmp[iy][ipt], pytmp[iy][ipt]); gRatio_pp[iy]->SetPoint(ipt, px[iy][ipt], pytmp[iy][ipt]); gRatio_pp[iy]->SetPointEXlow(ipt, ex[ipt]); gRatio_pp[iy]->SetPointEXhigh(ipt, ex[ipt]); }*/ c02->cd(iy+1); gRatio_pp[iy]->GetXaxis()->SetLimits(0.0,30.0); gRatio_pp[iy]->GetXaxis()->CenterTitle(); gRatio_pp[iy]->SetMinimum(ratiomin); gRatio_pp[iy]->SetMaximum(ratiomax); gRatio_pp[iy]->GetYaxis()->CenterTitle(); gRatio_pp[iy]->GetXaxis()->SetTitle("p_{T} (GeV/c)"); gRatio_pp[iy]->GetYaxis()->SetTitle("[Weight] / [No weight]"); gRatio_pp[iy]->Draw("AP"); if (iy==0){ if (isPrompt) latex->DrawLatex(0.19,0.23,"pp Prompt J/#psi"); else latex->DrawLatex(0.19, 0.23,"pp Nonprompt J/#psi"); } latex->DrawLatex(0.55,0.23,Form("%s",rapArr[iy].Data())); dashedLine(0.,1.,30.,1.,1,1); } c02->SaveAs(Form("dir_1D_%s/effRatio_isPrompt%d_isLog%d_Zvtx1_Zvtx0_pp.pdf",szBinning.Data(),(int)isPrompt,(int)isLog)); return; } // end of main func.
void bbtt_test(std::string var="mt2pileup",int nbins=8, double xmin=0, double xmax=200,std::string xtitle="mt2pileup", std::string ytitle="Events", double sigscale=1,int hist=1) { double massLEdges[14] = {-0.5,-0.45,-0.4,-0.35,-0.3,-0.25,-0.2,-0.15,-0.1,-0.05,0.0,0.05,0.1,0.2}; //SetStyle(); gStyle->SetLineStyleString(11,"20 10"); //setTDRStyle(); TH1::SetDefaultSumw2(1); std::string dir = "/afs/cern.ch/work/j/jlawhorn/public/holding/"; //std::string dir = "/afs/cern.ch/user/j/jlawhorn/delphes-dihiggs/CombSelection/"; std::stringstream scale; scale << sigscale; //Cut definitions double luminosity = 3000; std::stringstream lumi; lumi << luminosity; std::string objN = "(isBBTT==1 && tauCat1==1 && tauCat2==1 && ptTau1>45 && ptTau2>45 && (bTag1==2||bTag1==3||bTag1==6||bTag1==7) && (bTag2==2||bTag2==3||bTag2==6||bTag2==7) && ptB1>30 && ptB2>30)*(abs(etaB1)<2.5 && abs(etaB2)<2.5 && abs(etaTau1)<2.1 && abs(etaTau2)<2.1 && ptTrk1>0 && ptTrk2>0)*eventWeight*"+lumi.str(); std::string objT = "(isBBTT==1 && tauCat1==1 && tauCat2==1 && ptTau1>45 && ptTau2>45 && ptB1>30 && ptB2>30)*(abs(etaB1)<2.5 && abs(etaB2)<2.5 && abs(etaTau1)<2.1 && abs(etaTau1)<2.5 && ptTrk1>0 && ptTrk2>0)*eventWeight*"+lumi.str(); std::string jetN = objN+"*(m_svpileup>90 && m_svpileup<120 && mBB1>90 && mBB1<140)"; std::string jetT = objT+"*(m_svpileup>90 && m_svpileup<120 && mBB1>90 && mBB1<140)"; //signal region //-------------------------------------------------------------------------- //Get the trees //TTree *tt_nom = load(dir+"tt-4p-0-600-v1510_14TEV_nov.root"); TTree *tt_nom = load(dir+"tt-BLUE.root"); TTree *tt_test = load(dir+"tt_test.root"); TTree *tt_wpuid = load(dir+"tt_wpuid.root"); //TTree *tt_nom = load(dir+"tt-4p-2500-100000-v1510_14TEV.root"); //TTree *tt_test = load(dir+"tt-4p-2500-100000-v1510_14TEV_test.root"); //TTree *tt_wpuid = load(dir+"tt-4p-2500-100000-v1510_14TEV_puid.root"); //------------------------------------------------------------------------- //Get histograms TCanvas *canv0 = MakeCanvas("canv", "histograms", 600, 600); canv0->cd(); std::string vardraw; TH1F *h_nom; if(hist) h_nom = new TH1F("TTnom","",nbins,xmin,xmax); else h_nom = new TH1F("TTnom","",13, massLEdges); vardraw = var+">>"+"TTnom"; tt_nom->Draw(vardraw.c_str(),jetN.c_str()); InitSignal(h_nom); TH1F *h_test; if(hist) h_test = new TH1F("TTtest","",nbins,xmin,xmax); else h_test = new TH1F("TTtest","",13, massLEdges); vardraw = var+">>"+"TTtest"; tt_test->Draw(vardraw.c_str(),objT.c_str()); InitSignal(h_test); TH1F *h_puid; if(hist) h_puid = new TH1F("TTpuid","",nbins,xmin,xmax); else h_puid = new TH1F("TTpuid","",13, massLEdges); vardraw = var+">>"+"TTpuid"; tt_wpuid->Draw(vardraw.c_str(),objT.c_str()); InitSignal(h_puid); delete canv0; Double_t error=999; //cout << objN << endl; //cout << objT << endl; cout << jetN << endl; cout << jetT << endl; cout << "Nominal " << h_nom->IntegralAndError(0,h_nom->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; cout << h_nom->GetEntries() << endl; cout << "Testing " << h_test->IntegralAndError(0,h_test->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; cout << h_test->GetEntries() << endl; cout << "Test+PU " << h_puid->IntegralAndError(0,h_puid->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; cout << h_puid->GetEntries() << endl; Float_t sc_test=h_test->Integral(); Float_t sc_nom=h_nom->Integral(); Float_t sc_puid=h_puid->Integral(); h_test->Scale(sc_nom/sc_test); h_puid->Scale(sc_nom/sc_puid); cout << "----" << endl; cout << "Nominal " << h_nom->IntegralAndError(0,h_nom->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; cout << h_nom->GetEntries() << endl; cout << "Testing " << h_test->IntegralAndError(0,h_test->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; cout << h_test->GetEntries() << endl; cout << "Test+PU " << h_puid->IntegralAndError(0,h_puid->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; cout << h_puid->GetEntries() << endl; TCanvas *canv = MakeCanvas("canv", "histograms", 800, 600); canv->cd(); h_test->SetLineColor(kBlue); h_test->SetLineWidth(2.0); h_puid->SetLineColor(kRed); h_puid->SetLineWidth(2.0); h_nom->SetLineColor(kBlack); h_nom->SetLineWidth(2.0); h_nom->SetMaximum(std::max(maximum(h_puid,0), maximum(h_nom,0))); h_nom->GetXaxis()->SetTitle(xtitle.c_str()); h_nom->GetYaxis()->SetTitle(ytitle.c_str()); h_nom->Draw("hist"); h_test->Draw("histsame"); h_puid->Draw("histsame"); TLegend* leg = new TLegend(0.65, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(h_nom, "Nominal Selection", "L"); leg->AddEntry(h_test, "Generator Matching", "L"); leg->AddEntry(h_puid, "Generator w/PU-ID", "L"); leg->Draw(); canv->Print((var+"_test.png").c_str()); }
void draw_prefit_Sample(std::string inputF, std::string channel, int MaxY, std::string xTitle, std::string nameHisto) { // gStyle->SetOptStat(0); SetStyle(); // InitSubPad TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); float SIGNAL_SCALE = 10; bool scaled = true; bool log = false; TFile* input = new TFile(inputF.c_str()); //cout<<"1"; const char* dataset; // std::string channel = "muTau_btag/"; // std::string channel = "eleTau_inclusive/"; THStack hs("hs", ""); TH1F* data = (TH1F*) input->Get((channel + "data_obs").c_str()); TH1F* zero = (TH1F*) data->Clone("zero"); TH1F* QCD = (TH1F*) input->Get((channel + "QCD").c_str()); InitHist(QCD, "", "", TColor::GetColor(250, 202, 255), 1001); hs.Add(QCD); TH1F* W = (TH1F*) input->Get((channel + "W").c_str()); InitHist(W, "", "", 46, 1001); TH1F* ZJ = (TH1F*) input->Get((channel + "ZJ").c_str()); // InitHist(ZJ, "", "", TColor::GetColor(100, 182, 232), 1001); W->Add(ZJ); TH1F* ZL = (TH1F*) input->Get((channel + "ZL").c_str()); // InitHist(ZL, "", "", TColor::GetColor(100, 182, 232), 1001); W->Add(ZL); TH1F* VV = (TH1F*) input->Get((channel + "VV").c_str()); // InitHist(VV, "", "", TColor::GetColor(100, 182, 232), 1001); W->Add(VV); hs.Add(W); //// TH1F* ZLL = (TH1F*) input->Get((channel +"ZLL"); // InitHist(ttbar, "", "", TColor::GetColor(155, 152, 204), 1001); TH1F* TT = (TH1F*) input->Get((channel + "TT").c_str()); InitHist(TT, "", "", 9, 1001); hs.Add(TT); TH1F* ZTT = (TH1F*) input->Get((channel + "ZTT").c_str()); InitHist(ZTT, "", "", TColor::GetColor(248, 206, 104), 1001); TH1F* ZTTLow = (TH1F*) input->Get((channel + "ZTT_lowMass").c_str()); InitHist(ZTTLow, "", "", TColor::GetColor(248, 206, 104), 1001); ZTT->Add(ZTTLow); hs.Add(ZTT); InitData(data); TH1F* signal = (TH1F*) input->Get((channel + "bba150").c_str()); signal->Scale(10); InitSignal(signal); // signal->SetFillColor(kGreen); // signal->SetLineColor(kGreen); hs.Add(signal); canv->cd(); // const char * MMM = xTitle.c_str(); // hs.GetXaxis()->SetLabelSize(9); zero->Scale(0); zero->GetXaxis()->SetRangeUser(0,60); zero->GetXaxis()->SetTitle(xTitle.c_str()); zero->SetMaximum(MaxY); zero->Draw(); hs.Draw("hsame"); data->SetBinContent(1,0); data->SetBinContent(2,0); data->SetBinContent(3,0); data->SetBinContent(4,0); data->SetBinContent(5,0); data->SetBinContent(6,0); data->SetBinContent(7,0); data->SetBinContent(8,0); data->SetBinContent(9,0); data->SetBinContent(10,0); data->SetBinContent(11,0); data->SetBinContent(12,0); data->SetBinContent(13,0); data->Draw("PEsame"); const char* dataset; dataset = "CMS Preliminary, bba1#rightarrow#tau#tau, 19.7 fb^{-1} at 8 TeV"; CMSPrelim(dataset, "", 0.17, 0.835); TLegend* leg = new TLegend(0.62, 0.58, 0.92, 0.89); SetLegendStyle(leg); leg->AddEntry(signal, TString::Format("a1(50 GeV)#rightarrow#tau#tau [XS= 10 bp]", SIGNAL_SCALE), "L"); leg->AddEntry(data, "observed", "LP"); leg->AddEntry(ZTT, "Z#rightarrow#tau#tau", "F"); leg->AddEntry(TT, "t#bar{t}", "F"); leg->AddEntry(W, "electroweak", "F"); leg->AddEntry(QCD, "QCD", "F"); leg->Draw(); // canv->Print(TString::Format( (nameHisto+".pdf").c_str())); // canv->Print(TString::Format( (nameHisto+".root").c_str())); canv->Print(TString::Format( (nameHisto+"_Low_.pdf").c_str())); canv->Print(TString::Format( (nameHisto+"_Low_.root").c_str())); }
void comp_RpPb_pt_ATLAS(bool isPrompt = true) { gROOT->Macro("./tdrstyle_kyo.C"); int isPA = 10; int iPos=33; //// BR and lumi info. const Double_t br = 0.0593 ; const Double_t brErr = 0.0006; const Double_t pp_lumi_pb =27.972; // 28.0/pb const Double_t pp_lumi_pb_err = 0.643; // 2.3 % const Double_t pPb_lumi_nb = 34.622; // 34.6/nb const Double_t pPb_lumi_nb_err = 1.211; // 3.5 % const Double_t pp_lumi_mub = pp_lumi_pb *1000*1000; const Double_t pPb_lumi_mub_err = pp_lumi_pb_err *1000*1000; double A_pb =208; //// read our result TFile *inFile_pp; if (isPrompt) inFile_pp = new TFile("plot_cross/pp_cross_pt_integ_middle_isPrompt1_isLog0_isScale0_maxrap300.root"); else inFile_pp= new TFile("plot_cross/pp_cross_pt_integ_middle_isPrompt0_isLog0_isScale0_maxrap300.root"); TGraphAsymmErrors* g_cross_fwrap_pp = (TGraphAsymmErrors*)inFile_pp->Get("g_cross_fwrap"); TGraphAsymmErrors* g_cross_sys_fwrap_pp = (TGraphAsymmErrors*)inFile_pp->Get("g_cross_sys_fwrap"); //// read our result TFile *inFile_pA; if (isPrompt) inFile_pA = new TFile("plot_cross/pA_cross_pt_integ_middle_isPrompt1_isLog0_isScale0_maxrap300.root"); else inFile_pA= new TFile("plot_cross/pA_cross_pt_integ_middle_isPrompt0_isLog0_isScale0_maxrap300.root"); TGraphAsymmErrors* g_cross_fwrap_pA = (TGraphAsymmErrors*)inFile_pA->Get("g_cross_fwrap"); TGraphAsymmErrors* g_cross_sys_fwrap_pA = (TGraphAsymmErrors*)inFile_pA->Get("g_cross_sys_fwrap"); const int nPt = 5; double dummy1; double pxtmp[nPt]; double pytmp_pp[nPt]; double pytmp_pA[nPt]; double rppb[nPt]; double eytmp_pp[nPt]; double eytmp_pA[nPt]; double ey_rppb[nPt]; double eysystmp_pp[nPt]; double eysystmp_pA[nPt]; double eysys_rppb[nPt]; for (int ipt=0; ipt<nPt; ipt++) { g_cross_fwrap_pp->GetPoint(ipt+4, pxtmp[ipt], pytmp_pp[ipt]); g_cross_fwrap_pA->GetPoint(ipt+4, pxtmp[ipt], pytmp_pA[ipt]); eytmp_pp[ipt] = g_cross_fwrap_pp->GetErrorY(ipt+4); eytmp_pA[ipt] = g_cross_fwrap_pA->GetErrorY(ipt+4); eysystmp_pp[ipt] = g_cross_sys_fwrap_pp->GetErrorY(ipt+4); eysystmp_pA[ipt] = g_cross_sys_fwrap_pA->GetErrorY(ipt+4); } for (int ipt=0; ipt<nPt; ipt++) { DivideValue(pytmp_pA[ipt],eytmp_pA[ipt],pytmp_pp[ipt],eytmp_pp[ipt],&rppb[ipt],&ey_rppb[ipt]); //actual values DivideValue(pytmp_pA[ipt],eysystmp_pA[ipt],pytmp_pp[ipt],eysystmp_pp[ipt],&dummy1,&eysys_rppb[ipt]); //syst. rppb[ipt]/=A_pb; ey_rppb[ipt]/=A_pb; eysys_rppb[ipt]/=A_pb; cout << " "<<endl; cout << "rppb["<<ipt<<"] =" << rppb[ipt] << endl; cout << "stat.["<<ipt<<"] =" << ey_rppb[ipt] << endl; cout << "syst.["<<ipt<<"] =" << eysys_rppb[ipt] << endl; } Double_t exsys[nPt] = {0.4,0.4,0.4,0.4,0.4}; Double_t exlow[nPt]; Double_t exhigh[nPt]; Double_t ptArrNum[nPt+1] = {6.5, 7.5, 8.5, 10., 14., 30.}; //// ex calculation for (Int_t ipt=0; ipt<nPt; ipt++) { exlow[ipt] = pxtmp[ipt]-ptArrNum[ipt]; exhigh[ipt] = ptArrNum[ipt+1]-pxtmp[ipt]; } /////////////////////////////////////////////////// ///////////////////// ATLAS //////////////////////// /////////////////////////////////////////////////// TFile *inFileATLAS; if (isPrompt) inFileATLAS = new TFile("ATLAS_Jpsi_RpPb/RpPb_PromptJpsi_dpT.root"); else inFileATLAS= new TFile("ATLAS_Jpsi_RpPb/RpPb_NonPromptJpsi_dpT.root"); cout << "inFileATLAS = " << inFileATLAS << endl; TGraphAsymmErrors* g_RpPb_ATLAS_sys; TGraphAsymmErrors* g_RpPb_ATLAS; if (isPrompt) { g_RpPb_ATLAS_sys = (TGraphAsymmErrors*)inFileATLAS->Get("RpPb_p_syst"); g_RpPb_ATLAS = (TGraphAsymmErrors*)inFileATLAS->Get("RpPb_p"); }else { g_RpPb_ATLAS_sys = (TGraphAsymmErrors*)inFileATLAS->Get("RpPb_np_syst"); g_RpPb_ATLAS = (TGraphAsymmErrors*)inFileATLAS->Get("RpPb_np"); } cout << "g_RpPb_ATLAS_sys = " << g_RpPb_ATLAS_sys << endl; cout << "g_RpPb_ATLAS = " << g_RpPb_ATLAS << endl; ////////////////////////////////////////////////////////////// TLatex* globtex = new TLatex(); globtex->SetNDC(); globtex->SetTextAlign(12); //1:left, 2:vertical center //globtex->SetTextAlign(32); //3:right 2:vertical center globtex->SetTextFont(42); globtex->SetTextSize(0.04); TCanvas *c1 = new TCanvas("c1","c1",600,600); g_RpPb_ATLAS_sys->GetXaxis()->SetTitle("p_{T} (GeV/c)"); g_RpPb_ATLAS_sys->GetXaxis()->CenterTitle(); g_RpPb_ATLAS_sys->GetYaxis()->SetTitle("R_{pPb}"); g_RpPb_ATLAS_sys->GetYaxis()->CenterTitle(); g_RpPb_ATLAS_sys->GetXaxis()->SetTitleOffset(1.15); g_RpPb_ATLAS_sys->GetXaxis()->SetLimits(0.,32.); g_RpPb_ATLAS_sys->SetMinimum(0.0); g_RpPb_ATLAS_sys->SetMaximum(2.0); g_RpPb_ATLAS_sys->SetLineColor(kGray); g_RpPb_ATLAS_sys->SetFillColor(kWhite); g_RpPb_ATLAS_sys->SetFillStyle(4000); g_RpPb_ATLAS_sys->SetLineWidth(3); g_RpPb_ATLAS_sys->SetLineStyle(7); g_RpPb_ATLAS_sys->SetFillColor(kGray); SetGraphStyleFinal(g_RpPb_ATLAS, 9, 10); g_RpPb_ATLAS->SetMarkerSize(1.7); //TGraphAsymmErrors* g_RpPb_sys = new TGraphAsymmErrors(nPt, pxtmp, rppb, exsys, exsys, eysys_rppb, eysys_rppb); TGraphAsymmErrors* g_RpPb_sys = new TGraphAsymmErrors(nPt, pxtmp, rppb, exlow, exhigh, eysys_rppb, eysys_rppb); TGraphAsymmErrors* g_RpPb = new TGraphAsymmErrors(nPt, pxtmp, rppb, exsys, exsys, ey_rppb, ey_rppb); g_RpPb_sys->GetXaxis()->SetTitle("p_{T} (GeV/c)"); g_RpPb_sys->GetXaxis()->CenterTitle(); g_RpPb_sys->GetYaxis()->SetTitle("R_{pPb}"); g_RpPb_sys->GetYaxis()->CenterTitle(); g_RpPb_sys->GetXaxis()->SetLimits(0.,30.0); g_RpPb_sys->SetMinimum(0.0); g_RpPb_sys->SetMaximum(2.0); g_RpPb_sys->SetFillColorAlpha(kRed-10,0.5); g_RpPb_sys->SetLineColor(kPink-6); SetGraphStyleFinal(g_RpPb, 1, 0); //g_RpPb->SetMarkerSize(2.1); g_RpPb->SetMarkerSize(1.7); ////// actual draw g_RpPb_ATLAS_sys->Draw("A5"); g_RpPb_sys->Draw("5"); solidLine(0.,1.,32.,1.,1,1); g_RpPb_ATLAS->Draw("p"); g_RpPb->Draw("p"); //TLegend *legBL = new TLegend(0.19,0.18,0.54,0.25); TLegend *legBL = new TLegend(0.18,0.18,0.77,0.32); SetLegendStyle(legBL); legBL->SetTextSize(0.043); legBL->SetTextFont(42); legBL -> AddEntry(g_RpPb,"-1.5 < y_{CM} < 1.5","lp"); legBL -> AddEntry(g_RpPb_ATLAS,"ATLAS: -1.5 < y_{CM} < 1.5","lp"); legBL -> Draw(); globtex->SetTextSize(0.055); globtex->SetTextFont(42); if (isPrompt) globtex->DrawLatex(0.21, 0.84, "Prompt J/#psi"); else globtex->DrawLatex(0.21, 0.84, "Nonprompt J/#psi"); CMS_lumi( c1, isPA, iPos ); c1->Update(); c1->SaveAs(Form("plot_otherExp/comp_RpPb_pt_ATLAS_isPrompt%d.pdf",(int)isPrompt)); c1->SaveAs(Form("plot_otherExp/comp_RpPb_pt_ATLAS_isPrompt%d.png",(int)isPrompt)); return; }
void draw_tt(std::string var="mTT",int nbins=10, double xmin=0, double xmax=200,std::string xtitle="m_{#tau#tau}", std::string ytitle="Events") { SetStyle(); gStyle->SetLineStyleString(11,"20 10"); TH1::SetDefaultSumw2(1); std::string dir = "/afs/cern.ch/work/j/jlawhorn/public/vbf/ntuples/"; double sigscale = 10; double sigscale1 = 10; std::stringstream scale; scale << sigscale; std::stringstream scale1; scale1 << sigscale1; //Cut definitions double luminosity = 3000; std::stringstream lumi; lumi << luminosity; std::string objcut = "(ptTau1>45 && ptTau2>45 && abs(etaTau1) <4.0 && abs(etaTau1)<4.0 )"; std::string jetcut = objcut+"*(ptJet1>30 && ptJet2>30 && abs(etaJet1) <4.7 && abs(etaJet2) <4.7 )"; std::string ththcut = jetcut+"*(tauCat1==1 && tauCat2==1 && mJJ>500 && abs(dEta)>3.5)"; //signal region std::string vbfcut = ththcut+"*eventWeight*(eventType==0)*"+lumi.str(); std::string zttcut = ththcut+"*eventWeight*(eventType==1)*"+lumi.str(); std::string ttbarcut = ththcut+"*eventWeight*(eventType==3)*"+lumi.str(); //std::string ewkcut = ththcut+"*eventWeight*(eventType==2)*"+lumi.str(); std::string othercut = ththcut+"*eventWeight*(eventType==4 || eventType==2)*"+lumi.str(); //-------------------------------------------------------------------------- //Get the trees TTree *tree = load(dir+"vbf_comb.root"); //------------------------------------------------------------------------- //Get histograms TCanvas *canv0 = MakeCanvas("canv", "histograms", 600, 600); canv0->cd(); std::string vardraw; TH1F *vbf = new TH1F("VBFH","",nbins,xmin,xmax); vardraw = var+">>"+"VBFH"; tree->Draw(vardraw.c_str(),vbfcut.c_str()); InitSignal(vbf); vbf->SetLineColor(kBlack); TH1F *ttbar = new TH1F("TTbar","",nbins,xmin,xmax); vardraw = var+">>"+"TTbar"; tree->Draw(vardraw.c_str(),ttbarcut.c_str()); InitHist(ttbar, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(155,152,204), 1001); TH1F *ztt = new TH1F("Ztt","",nbins,xmin,xmax); vardraw = var+">>"+"Ztt"; tree->Draw(vardraw.c_str(),zttcut.c_str()); InitHist(ztt, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(248,206,104), 1001); //TH1F *ewk = new TH1F("Ewk","",nbins,xmin,xmax); //vardraw = var+">>"+"Ewk"; //tree->Draw(vardraw.c_str(),ewkcut.c_str()); //InitHist(ewk, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(222,90,106), 1001); TH1F *other = new TH1F("Other","",nbins,xmin,xmax); vardraw = var+">>"+"Other"; tree->Draw(vardraw.c_str(),othercut.c_str()); InitHist(other, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(222,90,106), 1001); delete canv0; //---------------------------------------------------------------------------- //Print out the yields Double_t error=0.0; ofstream outfile; outfile.open("yields_tt.txt"); outfile << "Yields for the signal region." << std::endl; outfile << "VBF " << vbf->IntegralAndError(0,vbf->GetNbinsX(),error) << "+/-" << error << endl; outfile << "TTbar " << ttbar->IntegralAndError(0,ttbar->GetNbinsX(),error) << "+/-" << error << endl; outfile << "Ztt " << ztt->IntegralAndError(0,ztt->GetNbinsX(),error) << "+/-" << error << endl; //outfile << "ewk " << ewk->IntegralAndError(0,ewk->GetNbinsX(),error) << "+/-" << error << endl; outfile << "other " << other->IntegralAndError(0,other->GetNbinsX(),error) << "+/-" << error << endl; outfile << "S/sqrt(B) " << vbf->Integral()/(other->Integral()+ztt->Integral()+ttbar->Integral()/*+ewk->Integral()*/) << endl; //-------------------------------------------------------------------------- //continue outputing //outfile << "Ewk total " << ewk->IntegralAndError(0,ewk->GetNbinsX(),error) << "+/-" << error << endl; outfile << endl << endl << endl; outfile << "In the signal region (100,150GeV) " <<endl; outfile << "VBF " << vbf->IntegralAndError(5,11,error) << "+/-" << error << endl; outfile << "TTbar " << ttbar->IntegralAndError(5,11,error) << "+/-" << error << endl; outfile << "Ztt " << ztt->IntegralAndError(5,11,error) << "+/-" << error << endl; //outfile << "ewk " << ewk->IntegralAndError(5,11,error) << "+/-" << error << endl; outfile << "other " << other->IntegralAndError(5,11,error) << "+/-" << error << endl; outfile.close(); //----------------------------------------------------------------------- //Draw the histograms TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); //ewk->Add(other); ttbar->Add(ewk); //ztt->Add(ttbar); vbf->Add(ztt); //Error band stat TH1F* errorBand = (TH1F*)vbf ->Clone("errorBand"); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(13); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); // for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ // if(errorBand->GetBinContent(idx)>0){ // std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; // break; // } //} ztt->SetMaximum(1.2*std::max(maximum(ttbar, 0), maximum(ztt, 0))); //blind(vbf,75,150); ztt->Draw("hist"); ttbar->Draw("histsame"); //ewk->Draw("histsame"); other->Draw("histsame"); vbf->Draw("histsame"); //errorBand->Draw("e2same"); canv->RedrawAxis(); //--------------------------------------------------------------------------- //Adding a legend TLegend* leg = new TLegend(0.53, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(vbf , "VBF Signal" , "F"); leg->AddEntry(ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); //leg->AddEntry(ewk , "Electroweak" , "F" ); leg->AddEntry(other, "Other" , "F" ); //leg->AddEntry(errorBand,"bkg. uncertainty","F"); leg->Draw(); //--------------------------------------------------------------------------- //CMS preliminary const char* dataset = "CMS Preliminary, H#rightarrow#tau#tau, 3.0 ab^{-1} at 14 TeV"; const char* category = ""; CMSPrelim(dataset, "#tau_{h}#tau_{h}", 0.17, 0.835); //CMSPrelim(dataset, "", 0.16, 0.835); TPaveText* chan = new TPaveText(0.52, 0.35, 0.91, 0.55, "tlbrNDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(category); chan->Draw(); //------------------------------------------------------------------------- //Save histograms canv->Print((var+"_tt.png").c_str()); /* Ratio Data over MC TCanvas *canv1 = MakeCanvas("canv0", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); */ /* TH1F* model = (TH1F*)ztt ->Clone("model"); TH1F* test1 = (TH1F*)data->Clone("test1"); for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){ //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01); //model->SetBinError (ibin+1, CONVERVATIVE_CHI2 ? 0. : model->GetBinError (ibin+1)*model->GetBinWidth(ibin+1)); model->SetBinError (ibin+1, 0); test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1)); test1->SetBinError (ibin+1, test1->GetBinError (ibin+1)*test1->GetBinWidth(ibin+1)); } double chi2prob = test1->Chi2Test (model,"PUW"); std::cout << "chi2prob:" << chi2prob << std::endl; double chi2ndof = test1->Chi2Test (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl; double ksprob = test1->KolmogorovTest(model); std::cout << "ksprob :" << ksprob << std::endl; double ksprobpe = test1->KolmogorovTest(model,"DX"); std::cout << "ksprobpe:" << ksprobpe << std::endl; std::vector<double> edges; TH1F* zero = (TH1F*)ttbar->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat1"); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ rat1->SetBinContent(ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinContent(ibin+1)/Ztt->GetBinContent(ibin+1) : 0); rat1->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); zero->SetBinContent(ibin+1, 0.); zero->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? Ztt ->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } } float range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+range); rat1->SetMinimum(-range); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat1->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->SetMarkerSize(0.1); zero->Draw("e2histsame"); canv1->RedrawAxis(); TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC"); stat1->SetBorderSize( 0 ); stat1->SetFillStyle( 0 ); stat1->SetTextAlign( 12 ); stat1->SetTextSize ( 0.05 ); stat1->SetTextColor( 1 ); stat1->SetTextFont ( 62 ); stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f", chi2ndof, chi2prob)); //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f, P(KS)=%.3f", chi2ndof, chi2prob, ksprob)); //stat1->Draw(); canv1->Print((var+"_ratio.png").c_str());*/ }
void draw_muonHistos_dmoon(int fileCode=3){ //gROOT->Macro("./JpsiStyle.c"); gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetOptTitle(0); gStyle->SetOptStat(0); gStyle->SetPadTopMargin(0.05); gStyle->SetPadRightMargin(0.05); gStyle->SetPadBottomMargin(0.12); gStyle->SetPadLeftMargin(0.12); TFile* inFile; string samplename; Double_t massMin; Double_t massMax; Double_t ptMin; Double_t ptMax; Double_t diptMin; Double_t diptMax; const int nPtBin = 40; const int nEtaBin = 15; const int nPhiBin = 15; const int nMassBin = 40; //TFile *in = new TFile("HLTrgAna_RelVal_JpsitoMM_20131205.root","READ"); if (fileCode ==0) { inFile = TFile::Open("root://eoscms//eos/cms/store/user/dmoon/cms538HI/HLTrgAna/RelVal/HLTrgAna_RelVal_JpsitoMM_20131205.root","READ"); samplename = "53X_Jpsi"; massMin = 2.6; massMax = 3.5; ptMin = 0.0; ptMax = 20.0; diptMin = 0.0; diptMax = 20.0; } else if (fileCode ==1) { inFile = TFile::Open("root://eoscms//eos/cms/store/user/dmoon/cms538HI/HLTrgAna/RelVal/HLTrgAna_RelVal_ZtoMM_20131205.root","READ"); samplename = "53X_Z"; massMin = 60; massMax = 120; ptMin = 0.0; ptMax =100.0; diptMin = 0.0; diptMax = 50.0; } else if (fileCode ==2) { inFile = TFile::Open("root://eoscms//eos/cms/store/user/dmoon/cms538HI/HLTrgAna/442patch5/HLTrgAna_RelVal_JpsiMM_442patch5_20131210.root","READ"); samplename = "44X_Jpsi"; massMin = 2.6; massMax = 3.5; ptMin = 0.0; ptMax = 20.0; diptMin = 0.0; diptMax = 20.0; } else if (fileCode ==3) { inFile = TFile::Open("root://eoscms//eos/cms/store/user/dmoon/cms538HI/HLTrgAna/442patch5/HLTrgAna_RelVal_ZMM_442patch5_20131210.root","READ"); samplename = "44X_Z"; massMin = 60; massMax = 120; ptMin = 0.0; ptMax =100.0; diptMin = 0.0; diptMax = 50.0; } else std::cout << "*** Error *** Specify the input file" << std::endl; TTree *Ana = (TTree*)inFile->Get("Ana"); // single muon (muon, regitmuon - glb, trk) //pt TH1F *hRecoMuPtGlb = new TH1F("hRecoMuPtGlb",";p_{T} (GeV/c);", nPtBin, ptMin, ptMax); TH1F *hRecoMuPtTrk = new TH1F("hRecoMuPtTrk",";p_{T} (GeV/c);", nPtBin, ptMin, ptMax); hRecoMuPtGlb->Sumw2(); hRecoMuPtTrk->Sumw2(); TH1F *hRegitMuPtGlb = new TH1F("hRegitMuPtGlb",";p_{T} (GeV/c);",nPtBin, ptMin, ptMax); TH1F *hRegitMuPtTrk = new TH1F("hRegitMuPtTrk",";p_{T} (GeV/c);",nPtBin, ptMin, ptMax); hRegitMuPtGlb->Sumw2(); hRegitMuPtTrk->Sumw2(); //eta TH1F *hRecoMuEtaGlb = new TH1F("hRecoMuEtaGlb",";#eta;",nEtaBin, -2.5, 2.5); TH1F *hRecoMuEtaTrk = new TH1F("hRecoMuEtaTrk",";#eta;",nEtaBin, -2.5, 2.5); hRecoMuEtaGlb->Sumw2(); hRecoMuEtaTrk->Sumw2(); TH1F *hRegitMuEtaGlb = new TH1F("hRegitMuEtaGlb",";#eta;",nEtaBin, -2.5, 2.5); TH1F *hRegitMuEtaTrk = new TH1F("hRegitMuEtaTrk",";#eta;",nEtaBin, -2.5, 2.5); hRegitMuEtaGlb->Sumw2(); hRegitMuEtaTrk->Sumw2(); //phi TH1F *hRecoMuPhiGlb = new TH1F("hRecoMuPhiGlb",";#phi;",nPhiBin, 0, 3.2); TH1F *hRecoMuPhiTrk = new TH1F("hRecoMuPhiTrk",";#phi;",nPhiBin, 0, 3.2); hRecoMuPhiGlb->Sumw2(); hRecoMuPhiTrk->Sumw2(); TH1F *hRegitMuPhiGlb = new TH1F("hRegitMuPhiGlb",";#phi;",nPhiBin, 0, 3.2); TH1F *hRegitMuPhiTrk = new TH1F("hRegitMuPhiTrk",";#phi;",nPhiBin, 0, 3.2); hRegitMuPhiGlb->Sumw2(); hRegitMuPhiTrk->Sumw2(); // dimuon (muon, regitmuon - glb, trk) // pt TH1F *hRecoDiMuPt = new TH1F("hRecoDiMuPt",";p_{T} (GeV/c);",nPtBin, diptMin, diptMax); hRecoDiMuPt->Sumw2(); TH1F *hRegitDiMuPt = new TH1F("hRegitDiMuPt",";p_{T} (GeV/c);",nPtBin, diptMin, diptMax); hRegitDiMuPt->Sumw2(); // mass TH1F *hRecoDiMuMass = new TH1F("hRecoDiMuMass",";m_{#mu#mu} (GeV/c^{2});",nMassBin, massMin, massMax); hRecoDiMuMass->Sumw2(); TH1F *hRegitDiMuMass = new TH1F("hRegitDiMuMass",";m_{#mu#mu} (GeV/c^{2});",nMassBin, massMin, massMax); hRegitDiMuMass->Sumw2(); // single muon Ana->Draw("recoMu_pt>>hRecoMuPtGlb","recoMu_Glb==1","E"); Ana->Draw("recoMu_pt>>hRecoMuPtTrk","recoMu_Trk==1","E"); Ana->Draw("regrecoMu_pt>>hRegitMuPtGlb","regrecoMu_Glb==1","E"); Ana->Draw("regrecoMu_pt>>hRegitMuPtTrk","regrecoMu_Trk==1","E"); Ana->Draw("recoMu_eta>>hRecoMuEtaGlb","recoMu_Glb==1","E"); Ana->Draw("recoMu_eta>>hRecoMuEtaTrk","recoMu_Trk==1","E"); Ana->Draw("regrecoMu_eta>>hRegitMuEtaGlb","regrecoMu_Glb==1","E"); Ana->Draw("regrecoMu_eta>>hRegitMuEtaTrk","regrecoMu_Trk==1","E"); Ana->Draw("recoMu_phi>>hRecoMuPhiGlb","recoMu_Glb==1","E"); Ana->Draw("recoMu_phi>>hRecoMuPhiTrk","recoMu_Trk==1","E"); Ana->Draw("regrecoMu_phi>>hRegitMuPhiGlb","regrecoMu_Glb==1","E"); Ana->Draw("regrecoMu_phi>>hRegitMuPhiTrk","regrecoMu_Trk==1","E"); // dimuon Ana->Draw("recoDimu_pt>>hRecoDiMuPt","","E"); Ana->Draw("regrecoDimu_pt>>hRegitDiMuPt","","E"); Ana->Draw("recoDimu_mass>>hRecoDiMuMass","","E"); Ana->Draw("regrecoDimu_mass>>hRegitDiMuMass","","E"); SetHistStyle(hRecoMuPtGlb, 1,0); SetHistStyle(hRegitMuPtGlb, 2,0); SetHistStyle(hRecoMuPtTrk, 1,0); SetHistStyle(hRegitMuPtTrk, 2,0); SetHistStyle(hRecoMuEtaGlb, 1,0); SetHistStyle(hRegitMuEtaGlb, 2,0); SetHistStyle(hRecoMuEtaTrk, 1,0); SetHistStyle(hRegitMuEtaTrk, 2,0); SetHistStyle(hRecoMuPhiGlb, 1,0); SetHistStyle(hRegitMuPhiGlb, 2,0); SetHistStyle(hRecoMuPhiTrk, 1,0); SetHistStyle(hRegitMuPhiTrk, 2,0); SetHistStyle(hRecoDiMuPt, 1,0); SetHistStyle(hRegitDiMuPt, 2,0); SetHistStyle(hRecoDiMuMass, 1,0); SetHistStyle(hRegitDiMuMass, 2,0); TLegend *legUR01 = new TLegend(0.68,0.60,0.87,0.77); TLegend *legUM = new TLegend(0.42,0.70,0.61,0.88); TLegend *legBR = new TLegend(0.64,0.15,0.84,0.33); SetLegendStyle(legUR01); SetLegendStyle(legUM); SetLegendStyle(legBR); //draw and save plots TCanvas *c1 = new TCanvas("c1","",600,600); //single muon hRegitMuPtTrk->SetMinimum(0); hRegitMuPtTrk->Draw(); hRecoMuPtTrk->Draw("same"); legUR01->SetHeader("Tracker Muons"); legUR01->AddEntry(hRecoMuPtTrk,"reco muon","PL"); legUR01->AddEntry(hRegitMuPtTrk,"regit muon","PL"); legUR01->Draw("same"); c1->SaveAs(Form("%s_MuPtTrk_reco_vs_regit.pdf",samplename.c_str())); legUR01->Clear(); c1->Clear(); hRegitMuPtGlb->SetMinimum(0); hRegitMuPtGlb->Draw(); hRecoMuPtGlb->Draw("same"); legUR01->SetHeader("Global Muons"); legUR01->AddEntry(hRecoMuPtGlb,"reco muon","PL"); legUR01->AddEntry(hRegitMuPtGlb,"regit muon","PL"); legUR01->Draw("same"); c1->SaveAs(Form("%s_MuPtGlb_reco_vs_regit.pdf",samplename.c_str())); legUR01->Clear(); c1->Clear(); hRegitMuEtaTrk->SetMinimum(0); hRegitMuEtaTrk->Draw(); hRecoMuEtaTrk->Draw("same"); legUM->SetHeader("Tracker Muons"); legUM->AddEntry(hRecoMuEtaTrk,"reco muon","PL"); legUM->AddEntry(hRegitMuEtaTrk,"regit muon","PL"); legUM->Draw("same"); c1->SaveAs(Form("%s_MuEtaTrk_reco_vs_regit.pdf",samplename.c_str())); legUM->Clear(); c1->Clear(); hRegitMuEtaGlb->SetMinimum(0); hRegitMuEtaGlb->Draw(); hRecoMuEtaGlb->Draw("same"); legUM->SetHeader("Global Muons"); legUM->AddEntry(hRecoMuEtaGlb,"reco muon","PL"); legUM->AddEntry(hRegitMuEtaGlb,"regit muon","PL"); legUM->Draw("same"); c1->SaveAs(Form("%s_MuEtaGlb_reco_vs_regit.pdf",samplename.c_str())); legUM->Clear(); c1->Clear(); hRegitMuPhiTrk->SetMinimum(0); hRegitMuPhiTrk->Draw(); hRecoMuPhiTrk->Draw("same"); legBR->SetHeader("Tracker Muons"); legBR->AddEntry(hRecoMuPhiTrk,"reco muon","PL"); legBR->AddEntry(hRegitMuPhiTrk,"regit muon","PL"); legBR->Draw("same"); c1->SaveAs(Form("%s_MuPhiTrk_reco_vs_regit.pdf",samplename.c_str())); legBR->Clear(); c1->Clear(); hRegitMuPhiGlb->SetMinimum(0); hRegitMuPhiGlb->Draw(); hRecoMuPhiGlb->Draw("same"); legBR->SetHeader("Global Muons"); legBR->AddEntry(hRecoMuPhiGlb,"reco muon","PL"); legBR->AddEntry(hRegitMuPhiGlb,"regit muon","PL"); legBR->Draw("same"); c1->SaveAs(Form("%s_MuPhiGlb_reco_vs_regit.pdf",samplename.c_str())); legBR->Clear(); c1->Clear(); //dimu hRegitDiMuPt->SetMinimum(0); hRegitDiMuPt->Draw(); hRecoDiMuPt->Draw("same"); legUR01->SetHeader("Dimuons"); legUR01->AddEntry(hRecoDiMuPt,"reco muon","PL"); legUR01->AddEntry(hRegitDiMuPt,"regit muon","PL"); legUR01->Draw("same"); c1->SaveAs(Form("%s_DiMuPt_reco_vs_regit.pdf",samplename.c_str())); legUR01->Clear(); c1->Clear(); hRegitDiMuMass->SetMinimum(0); hRegitDiMuMass->Draw(); hRecoDiMuMass->Draw("same"); legUR01->SetHeader("Dimuons"); legUR01->AddEntry(hRecoDiMuMass,"reco muon","PL"); legUR01->AddEntry(hRegitDiMuMass,"regit muon","PL"); legUR01->Draw("same"); c1->SaveAs(Form("%s_DiMuMass_reco_vs_regit.pdf",samplename.c_str())); legUR01->Clear(); c1->Clear(); return; }
void HBB_LEP_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., const char* inputfile="root/$HISTFILE", const char* directory="bb_$CATEGORY") { // define common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category_extra = ""; if(std::string(directory) == std::string("bb_had0" )){ category_extra = "all-had_{0}"; } if(std::string(directory) == std::string("bb_had1" )){ category_extra = "all-had_{1}"; } if(std::string(directory) == std::string("bb_had2" )){ category_extra = "all-had_{2}"; } if(std::string(directory) == std::string("bb_had3" )){ category_extra = "all-had_{3}"; } if(std::string(directory) == std::string("bb_had4" )){ category_extra = "all-had_{4}"; } if(std::string(directory) == std::string("bb_had5" )){ category_extra = "all-had_{5}"; } if(std::string(directory) == std::string("bb_lep" )){ category_extra = "semi-lep"; } const char* dataset; if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "Preliminary, #sqrt{s} = 7 TeV, L = 4.8 fb^{-1}";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "Preliminary, #sqrt{s} = 8 TeV, L = 19.4 fb^{-1}";} TFile* input = new TFile(inputfile); TH1F* bkgBBB = refill((TH1F*)input->Get(TString::Format("%s/bkgBBB" , directory)), "bkgBBB"); InitHist(bkgBBB, "", "", kMagenta-10, 1001);; #ifdef MSSM float bbHScale = 1.; // scenario for MSSM, mhmax, mA=160, tanb=20, A+H for the time being if(std::string(inputfile).find("7TeV")!=std::string::npos){ bbHScale = (23314.3*0.879 + 21999.3*0.877)/1000.; } if(std::string(inputfile).find("8TeV")!=std::string::npos){ bbHScale = (31087.9*0.879 + 29317.8*0.877)/1000.; } // float bbHScale = 1.; // scenario for MSSM, mhmax, mA=160, tanb=10, A+H for the time being // if(std::string(inputfile).find("7TeV")!=std::string::npos){ bbHScale = (6211.6*0.89 + 5145.0*0.85)/1000.; } // if(std::string(inputfile).find("8TeV")!=std::string::npos){ bbHScale = (8282.7*0.89 + 6867.8*0.85)/1000.; } TH1F* bbH = refill((TH1F*)input->Get(TString::Format("%s/bbH160" , directory)), "bbH" ); InitSignal(bbH); bbH->Scale(bbHScale); #endif TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); InitHist(data, "#bf{m_{b#bar{b}} [GeV]}", "#bf{dN/dm_{b#bar{b}} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)bkgBBB->Clone("ref"); double unscaled[7]; unscaled[0] = bkgBBB ->Integral(); #ifdef MSSM unscaled[1] = bbH ->Integral(); unscaled[2] = 0; #endif if(scaled){ rescale(bkgBBB, 1); #ifdef MSSM rescale(bbH, 2); #endif } TH1F* scales[7]; scales[0] = new TH1F("scales-bkgBBB", "", 3, 0, 3); scales[0]->SetBinContent(1, unscaled[0]>0 ? (bkgBBB ->Integral()/unscaled[0]-1.) : 0.); #ifdef MSSM scales[1] = new TH1F("scales-bbH" , "", 3, 0, 3); scales[1]->SetBinContent(2, unscaled[1]>0 ? (bbH ->Integral()/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-NONE" , "", 3, 0, 3); scales[2]->SetBinContent(3, 0.); #endif if(!log){ #ifdef MSSM bbH ->Add(bkgBBB); #endif } /* mass plot before and after fit */ TCanvas* canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(1000)); }; #endif data->SetNdivisions(505); data->SetMinimum(min); data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(bkgBBB, log))); data->Draw("e"); TH1F* errorBand = (TH1F*)bkgBBB ->Clone(); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(1); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); if(log){ bkgBBB ->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL bbH ->Draw("histsame"); #endif } else{ #ifndef DROP_SIGNAL bbH ->Draw("histsame"); #endif bkgBBB ->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "b#bar{b}", 0.17, 0.835); CMSPrelim(dataset, "", 0.17, 0.835); TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText("b#bar{b}"); chan->Draw(); TPaveText* cat = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); #ifdef MSSM TPaveText* massA = new TPaveText(0.75, 0.48+0.061, 0.85, 0.48+0.161, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("m_{A}=160GeV"); massA->Draw(); TPaveText* tanb = new TPaveText(0.75, 0.44+0.061, 0.85, 0.44+0.161, "NDC"); tanb->SetBorderSize( 0 ); tanb->SetFillStyle( 0 ); tanb->SetTextAlign( 12 ); tanb->SetTextSize ( 0.03 ); tanb->SetTextColor( 1 ); tanb->SetTextFont ( 62 ); tanb->AddText("tan#beta=20"); tanb->Draw(); TPaveText* scen = new TPaveText(0.75, 0.40+0.061, 0.85, 0.40+0.161, "NDC"); scen->SetBorderSize( 0 ); scen->SetFillStyle( 0 ); scen->SetTextAlign( 12 ); scen->SetTextSize ( 0.03 ); scen->SetTextColor( 1 ); scen->SetTextFont ( 62 ); scen->AddText("mhmax"); scen->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.55, 0.65, 0.94, 0.90); SetLegendStyle(leg); leg->AddEntry(bbH , "#phi#rightarrowb#bar{b}" , "L" ); #endif leg->AddEntry(data, "observed" , "LP"); leg->AddEntry(bkgBBB, "bkgBBB" , "F" ); $ERROR_LEGEND leg->Draw(); //#ifdef MSSM // TPaveText* mssm = new TPaveText(0.69, 0.85, 0.90, 0.90, "NDC"); // mssm->SetBorderSize( 0 ); // mssm->SetFillStyle( 0 ); // mssm->SetTextAlign( 12 ); // mssm->SetTextSize ( 0.03 ); // mssm->SetTextColor( 1 ); // mssm->SetTextFont ( 62 ); // mssm->AddText("(m_{A}=250, tan#beta=5)"); // mssm->Draw(); //#else // TPaveText* mssm = new TPaveText(0.83, 0.85, 0.95, 0.90, "NDC"); // mssm->SetBorderSize( 0 ); // mssm->SetFillStyle( 0 ); // mssm->SetTextAlign( 12 ); // mssm->SetTextSize ( 0.03 ); // mssm->SetTextColor( 1 ); // mssm->SetTextFont ( 62 ); // mssm->AddText("m_{H}=125"); // mssm->Draw(); //#endif /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* zero = (TH1F*)ref ->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat"); rat1->Divide(bkgBBB); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } zero->SetBinContent(ibin+1, 0.); } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+1.5); rat1->SetMinimum(-1.5); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{b#bar{b}} [GeV]}"); rat1->Draw(); zero->SetLineColor(kBlack); zero->Draw("same"); canv0->RedrawAxis(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); TH1F* rat2 = (TH1F*) bkgBBB->Clone("rat2"); rat2->Divide(ref); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } rat2->SetLineColor(kRed+ 3); rat2->SetFillColor(kRed-10); rat2->SetMaximum(+0.3); rat2->SetMinimum(-0.3); rat2->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); rat2->GetXaxis()->SetTitle("#bf{m_{b#bar{b}} [GeV]}"); rat2->GetXaxis()->SetRange(0, 28); rat2->Draw(); zero->SetLineColor(kBlack); zero->Draw("same"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[0], "", "", kMagenta-10, 1001); scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{bkgBBB}"); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(2, "#bf{bbH}" ); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{NONE}" ); #endif scales[0]->SetMaximum(+1.0); scales[0]->SetMinimum(-1.0); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); zero->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sscaled_%s_%s.png" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sscaled_%s_%s.pdf" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sscaled_%s_%s.eps" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); TFile* output = new TFile(TString::Format("%s_%sscaled_%s_%s.root", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""), "update"); output->cd(); data ->Write("data_obs"); bkgBBB ->Write("bkgBBB" ); #ifdef MSSM bbH ->Write("bbH" ); #endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); }
void test_msv(std::string var="m_sv",int nbins=25, double xmin=0, double xmax=250,std::string xtitle="m_sv", std::string ytitle="Events") { SetStyle(); gStyle->SetLineStyleString(11,"20 10"); TH1::SetDefaultSumw2(1); std::string dir = "/afs/cern.ch/work/a/arapyan/public/svfitsamples/"; double sigscale = 10; double sigscale1 = 10; std::stringstream scale; scale << sigscale; std::stringstream scale1; scale1 << sigscale1; //Cut definitions double luminosity = 3000; std::stringstream lumi; lumi << luminosity; std::string objcut = "(ptTau1>30 && ptTau2>30 && abs(etaTau1) <4.0 && abs(etaTau1)<4.0 )"; //std::string jetcut = objcut+"*(ptJet1>30 && ptJet2>30 && abs(etaJet1) <4.7 && abs(etaJet2) <4.7 )"; std::string mthcut = objcut+"*( ( (tauCat1==3 && tauCat2==2) || (tauCat2==3 && tauCat1==2) ) )"; //signal region //std::string vbfcut = ththcut+"*eventWeight*(eventType==0)*"+lumi.str(); //std::string zttcut = ththcut+"*eventWeight*(eventType==1)*"+lumi.str(); //std::string ttbarcut = ththcut+"*eventWeight*(eventType==3)*"+lumi.str(); //std::string ewkcut = ththcut+"*eventWeight*(eventType==2)*"+lumi.str(); //std::string othercut = ththcut+"*eventWeight*(eventType==4 || eventType==2)*"+lumi.str(); //-------------------------------------------------------------------------- //Get the trees TTree *tree = load(dir+"hh.root"); TTree *tree2 = load(dir+"Bjj-vbf.root"); TTree *tree3 = load(dir+"vbf_bgd.root"); //------------------------------------------------------------------------- //Get histograms TCanvas *canv0 = MakeCanvas("canv", "histograms", 600, 600); canv0->cd(); std::string vardraw; TH1F *vbf = new TH1F("VBFH","",nbins,xmin,xmax); vardraw = var+">>"+"VBFH"; tree->Draw(vardraw.c_str(),mthcut.c_str()); InitSignal(vbf); vbf->SetLineColor(kBlack); //TH1F *ttbar = new TH1F("TTbar","",nbins,xmin,xmax); //vardraw = var+">>"+"TTbar"; //tree->Draw(vardraw.c_str(),ttbarcut.c_str()); //InitHist(ttbar, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(155,152,204), 1001); TH1F *ztt = new TH1F("Ztt","",nbins,xmin,xmax); vardraw = var+">>"+"Ztt"; tree2->Draw(vardraw.c_str(),mthcut.c_str()); InitHist(ztt, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(248,206,104), 1001); //TH1F *ewk = new TH1F("Ewk","",nbins,xmin,xmax); //vardraw = var+">>"+"Ewk"; //tree->Draw(vardraw.c_str(),ewkcut.c_str()); //InitHist(ewk, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(222,90,106), 1001); TH1F *other = new TH1F("Other","",nbins,xmin,xmax); vardraw = var+">>"+"Other"; tree3->Draw(vardraw.c_str(),mthcut.c_str()); InitHist(other, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(222,90,106), 1001); delete canv0; //---------------------------------------------------------------------------- //Print out the yields /* Double_t error=0.0; ofstream outfile; outfile.open("yields_test.txt"); outfile << "Yields for the signal region." << std::endl; outfile << "VBF " << vbf->IntegralAndError(0,vbf->GetNbinsX(),error) << "+/-" << error << endl; outfile << "TTbar " << ttbar->IntegralAndError(0,ttbar->GetNbinsX(),error) << "+/-" << error << endl; outfile << "Ztt " << ztt->IntegralAndError(0,ztt->GetNbinsX(),error) << "+/-" << error << endl; //outfile << "ewk " << ewk->IntegralAndError(0,ewk->GetNbinsX(),error) << "+/-" << error << endl; outfile << "other " << other->IntegralAndError(0,other->GetNbinsX(),error) << "+/-" << error << endl; outfile << "S/sqrt(B) " << vbf->Integral()/(other->Integral()+ztt->Integral()+ttbar->Integral()) << endl; //-------------------------------------------------------------------------- //continue outputing //outfile << "Ewk total " << ewk->IntegralAndError(0,ewk->GetNbinsX(),error) << "+/-" << error << endl; outfile << endl << endl << endl; outfile << "In the signal region (100,150GeV) " <<endl; outfile << "VBF " << vbf->IntegralAndError(5,11,error) << "+/-" << error << endl; outfile << "TTbar " << ttbar->IntegralAndError(5,11,error) << "+/-" << error << endl; outfile << "Ztt " << ztt->IntegralAndError(5,11,error) << "+/-" << error << endl; //outfile << "ewk " << ewk->IntegralAndError(5,11,error) << "+/-" << error << endl; outfile << "other " << other->IntegralAndError(5,11,error) << "+/-" << error << endl; outfile.close();*/ //----------------------------------------------------------------------- //Draw the histograms TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); //ewk->Add(other); ttbar->Add(ewk); //ztt->Add(ttbar); vbf->Add(ztt); other->Add(ztt); //Error band stat TH1F* errorBand = (TH1F*)vbf ->Clone("errorBand"); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(13); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); // for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ // if(errorBand->GetBinContent(idx)>0){ // std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; // break; // } //} Float_t n=other->GetEntries(); other->Scale(1.0/n); n=vbf->GetEntries(); vbf->Scale(1.0/n); //for (Int_t i=1; i<nbins+1; i++) { //cout << "i: " << i << " " << other->GetBinCenter(i) << " " << other->Integral(0,i) << " " << other->Integral(i,nbins+1) << endl; //} cout << " other " << other->Integral(10,15) << endl; cout << " htt " << vbf->Integral(10,15) << endl; //n=ztt->GetEntries(); //ztt->Scale(1.0/n); other->SetMaximum(1.2*std::max(maximum(vbf, 0), maximum(other, 0))); //blind(vbf,75,150); //ttbar->Draw("histsame"); //ewk->Draw("histsame"); other->Draw("hist"); //ztt->Draw("histsame"); vbf->Draw("histsame"); //errorBand->Draw("e2same"); canv->RedrawAxis(); //--------------------------------------------------------------------------- //Adding a legend TLegend* leg = new TLegend(0.53, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(vbf , "HH" , "F"); //leg->AddEntry(ztt , "bjj-vbf" , "F" ); //leg->AddEntry(ttbar, "t#bar{t}" , "F" ); //leg->AddEntry(ewk , "Electroweak" , "F" ); leg->AddEntry(other, "Other" , "F" ); //leg->AddEntry(errorBand,"bkg. uncertainty","F"); leg->Draw(); //--------------------------------------------------------------------------- //CMS preliminary const char* dataset = "CMS Preliminary, H#rightarrow#tau#tau, 3.0 ab^{-1} at 14 TeV"; const char* category = ""; CMSPrelim(dataset, "#mu#tau_{h}", 0.17, 0.835); //CMSPrelim(dataset, "", 0.16, 0.835); TPaveText* chan = new TPaveText(0.52, 0.35, 0.91, 0.55, "tlbrNDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(category); chan->Draw(); //------------------------------------------------------------------------- //Save histograms canv->Print((var+"_test.png").c_str()); }
void makeEfficiency_74X_setBr(bool isPrompt=false, bool isPair=true, bool isEmbedded=true, bool isPtCut = false, bool doWeight = false) { gROOT->Macro("./JpsiStyle.C"); gStyle->SetPaintTextFormat(".3f"); // for text colz //string strDir = "eff_74X_setBr"; // directory name //string strDir = "eff_74X_setBr_wDetached"; // directory name string strDir = "eff_74X_noRegitMuDetached"; // directory name int initev =0; int nevt = -1; //all //int nevt = 1000; int ptbin = 11.; double ptmin = 0.; double ptmax = 11.; if (isEmbedded && !isPrompt) { ptbin = 22.; ptmax = 22.; } int rapbin = 12; double rapmin = -2.4; double rapmax = 2.4; int lxybin = 10; double lxymin = 0.; double lxymax = 1.; string strPrompt; string strEmbd; string strPair; if(isPrompt){ strPrompt = "prompt"; } else { strPrompt = "nonprompt"; } if(isEmbedded){ strEmbd = "embd"; } else { strEmbd = "nonembd"; } if(isPair){ strPair = "Pair"; } else { strPair = "Trk"; } cout << "strPrompt = " << strPrompt.c_str() << endl; cout << "strEmbd = " << strEmbd.c_str() << endl; cout << "strPair = " << strPair.c_str() << endl; ////// read-in file & tree TFile * refFile; if (isEmbedded){ ////// 740pre3 -embd //if (isPrompt){ refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_PromptJpsi_step2nMatch_KYO_regit_embd_20150211.root");} //else { refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_B2JpsiMuMu_step2nMatch_KYO_regit_embd_20150211.root");} ////// 740pre3 -embd with HiDetachedTripletStep //if (isPrompt){ refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_PromptJpsi_step2nMatch_KYO_regit_wDetached_embd_20150224.root");} //else { refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_B2JpsiMuMu_step2nMatch_KYO_regit_wDetached_embd_20150224.root");} ////// 740pre3 - remove some regit : noRegitMuDetached if (isPrompt){ refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_PromptJpsi_step2nMatch_KYO_regit_noRegitMuDetached_embd_20150310.root");} else { refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_B2JpsiMuMu_step2nMatch_KYO_regit_noRegitMuDetached_embd_20150310.root");} } else { //730pre2 -nonembd if (isPrompt){ refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_PromptJpsi_step2nMatch_KYO_regit_20141121.root");} else { refFile = new TFile("/home/songkyo/kyo/regitSample/tot_Pythiagun_B2Jpsi_step2nMatch_KYO_regit_20141203_no9_32_90.root");} } TTree *tr = new TTree(); if(isPair) { tr = (TTree*)refFile->Get("mcmatchanalysis/pnSimRecoPairType1");} else { tr = (TTree*)refFile->Get("mcmatchanalysis/pnSimRecoTrkType1"); } /* //for pT-|y| weight TFile *fWeight; if (isPrompt){ fWeight = new TFile("./pTdist_diffY/pTdist_diffY_prompt.root");} else {fWeight = new TFile("./pTdist_diffY/pTdist_diffY_nonprompt.root");} const int nYBin = 4; TH1D* hWeight[nYBin]; for (int i=0; i< nYBin; i++){ if (isPair) { hWeight[i] = (TH1D*)fWeight->Get(Form("hPairRatio_%d",i)); } else { hWeight[i] = (TH1D*)fWeight->Get(Form("hTrkRatio_%d",i)); }; //cout << i << "th hWeight = " << hWeight[i] << endl; cout << i << "th hWeight Name= " << hWeight[i]->GetName() << endl; } */ /////////////////////////////////////// ////// Pair ////// //gen Float_t pt; Float_t y; Float_t pt1; Float_t eta1; Float_t npixelhits1; Float_t nmuonhits1; Float_t pt2; Float_t eta2; Float_t npixelhits2; Float_t nmuonhits2; //reco Float_t ptreco; Float_t yreco; Float_t minvreco; Float_t ptreco1; Float_t etareco1; Float_t nvalidpixelhitsreco1; Float_t nvalidmuonhitsreco1; Float_t nmatch1; Float_t chi2ndofreco1; Float_t ptreco2; Float_t etareco2; Float_t nvalidpixelhitsreco2; Float_t nvalidmuonhitsreco2; Float_t nmatch2; Float_t chi2ndofreco2; // for lxy Float_t vtxz1; Float_t vtxy1; Float_t bx; Float_t by; ////// Trk (additional)////// //gen Float_t eta; Float_t idparent; Float_t npixelhits; Float_t nmuonhits; //reco Float_t etareco; Float_t nvalidpixelhitsreco; Float_t nvalidmuonhitsreco; Float_t nmatch; Float_t chi2ndofreco; // for lxy Float_t vtxz; Float_t vtxy; /////////////////////////////////////// //Branches /////////////////////////////////////// TBranch *b_pt; TBranch *b_y; TBranch *b_pt1; TBranch *b_eta1; TBranch *b_npixelhits1; TBranch *b_nmuonhits1; TBranch *b_pt2; TBranch *b_eta2; TBranch *b_npixelhits2; TBranch *b_nmuonhits2; //reco TBranch *b_ptreco; TBranch *b_yreco; TBranch *b_minvreco; TBranch *b_ptreco1; TBranch *b_etareco1; TBranch *b_nvalidpixelhitsreco1; TBranch *b_nvalidmuonhitsreco1; TBranch *b_nmatch1; TBranch *b_chi2ndofreco1; TBranch *b_ptreco2; TBranch *b_etareco2; TBranch *b_nvalidpixelhitsreco2; TBranch *b_nvalidmuonhitsreco2; TBranch *b_nmatch2; TBranch *b_chi2ndofreco2; // for lxy TBranch *b_vtxz1; TBranch *b_vtxy1; TBranch *b_bx; TBranch *b_by; ////// Trk (additional)////// //gen TBranch *b_eta; TBranch *b_idparent; TBranch *b_npixelhits; TBranch *b_nmuonhits; //reco TBranch *b_etareco; TBranch *b_nvalidpixelhitsreco; TBranch *b_nvalidmuonhitsreco; TBranch *b_nmatch; TBranch *b_chi2ndofreco; // for lxy TBranch *b_vtxz; TBranch *b_vtxy; /////////////////////////////////////// //BranchAddress /////////////////////////////////////// tr->SetBranchAddress("pt",&pt,&b_pt); tr->SetBranchAddress("ptreco",&ptreco,&b_ptreco); tr->SetBranchAddress("bx",&bx,&b_bx); tr->SetBranchAddress("by",&by,&b_by); if (isPair) { tr->SetBranchAddress("y",&y,&b_y); tr->SetBranchAddress("pt1",&pt1,&b_pt1); tr->SetBranchAddress("eta1",&eta1,&b_eta1); tr->SetBranchAddress("npixelhits1",&npixelhits1,&b_npixelhits1); tr->SetBranchAddress("nmuonhits1",&nmuonhits1,&b_nmuonhits1); tr->SetBranchAddress("pt2",&pt2,&b_pt2); tr->SetBranchAddress("eta2",&eta2,&b_eta2); tr->SetBranchAddress("npixelhits2",&npixelhits2,&b_npixelhits2); tr->SetBranchAddress("nmuonhits2",&nmuonhits2,&b_nmuonhits2); tr->SetBranchAddress("yreco",&yreco,&b_yreco); tr->SetBranchAddress("minvreco",&minvreco,&b_minvreco); tr->SetBranchAddress("ptreco1",&ptreco1,&b_ptreco1); tr->SetBranchAddress("etareco1",&etareco1,&b_etareco1); tr->SetBranchAddress("nvalidpixelhitsreco1",&nvalidpixelhitsreco1,&b_nvalidpixelhitsreco1); tr->SetBranchAddress("nvalidmuonhitsreco1",&nvalidmuonhitsreco1,&b_nvalidmuonhitsreco1); tr->SetBranchAddress("nmatch1",&nmatch1,&b_nmatch1); tr->SetBranchAddress("chi2ndofreco1",&chi2ndofreco1,&b_chi2ndofreco1); tr->SetBranchAddress("ptreco2",&ptreco2,&b_ptreco2); tr->SetBranchAddress("etareco2",&etareco2,&b_etareco2); tr->SetBranchAddress("nvalidpixelhitsreco2",&nvalidpixelhitsreco2,&b_nvalidpixelhitsreco2); tr->SetBranchAddress("nvalidmuonhitsreco2",&nvalidmuonhitsreco2,&b_nvalidmuonhitsreco2); tr->SetBranchAddress("nmatch2",&nmatch2,&b_nmatch2); tr->SetBranchAddress("chi2ndofreco2",&chi2ndofreco2,&b_chi2ndofreco2); tr->SetBranchAddress("vtxz1",&vtxz1,&b_vtxz1); tr->SetBranchAddress("vtxy1",&vtxy1,&b_vtxy1); } else { tr->SetBranchAddress("eta",&eta,&b_eta); tr->SetBranchAddress("etareco",&etareco,&b_etareco); tr->SetBranchAddress("idparent",&idparent,&b_idparent); tr->SetBranchAddress("npixelhits",&npixelhits,&b_npixelhits); tr->SetBranchAddress("nmuonhits",&nmuonhits,&b_nmuonhits); tr->SetBranchAddress("nvalidpixelhitsreco",&nvalidpixelhitsreco,&b_nvalidpixelhitsreco); tr->SetBranchAddress("nvalidmuonhitsreco",&nvalidmuonhitsreco,&b_nvalidmuonhitsreco); tr->SetBranchAddress("nmatch",&nmatch,&b_nmatch); tr->SetBranchAddress("chi2ndofreco",&chi2ndofreco,&b_chi2ndofreco); tr->SetBranchAddress("vtxz",&vtxz,&b_vtxz); tr->SetBranchAddress("vtxy",&vtxy,&b_vtxy); } //2D hist. just check TH2D* hGenPtY = new TH2D("hGenPtY","hGenPtY",50,rapmin,rapmax,50,ptmin,ptmax); TH2D* hRecoPtY = new TH2D("hRecoPtY","hRecoPtY",50,rapmin,rapmax,50,ptmin,ptmax); TH2D* hEffPtY = new TH2D("hEffPtY","hEffPtY",50,rapmin,rapmax,50,ptmin,ptmax); TH1D* hGenPt = new TH1D("hGenPt","hGenPt",ptbin,ptmin,ptmax); TH1D* hRecoPt = new TH1D("hRecoPt","hRecoPt",ptbin,ptmin,ptmax); TH1D* hEffPt = new TH1D("hEffPt","hEffPt",ptbin,ptmin,ptmax); TH1D* hGenRap = new TH1D("hGenRap","hGenRap",rapbin,rapmin,rapmax); TH1D* hRecoRap = new TH1D("hRecoRap","hRecoRap",rapbin,rapmin,rapmax); TH1D* hEffRap = new TH1D("hEffRap","hEffRap",rapbin,rapmin,rapmax); TH1D* hGenLxy = new TH1D("hGenLxy","hGenLxy",lxybin,lxymin,lxymax); TH1D* hRecoLxy = new TH1D("hRecoLxy","hRecoLxy",lxybin,lxymin,lxymax); TH1D* hEffLxy = new TH1D("hEffLxy","hEffLxy",lxybin,lxymin,lxymax); hGenPtY->Sumw2(); hRecoPtY->Sumw2(); hEffPtY->Sumw2(); hGenPt->Sumw2(); hRecoPt->Sumw2(); hEffPt->Sumw2(); hGenRap->Sumw2(); hRecoRap->Sumw2(); hEffRap->Sumw2(); hGenLxy->Sumw2(); hRecoLxy->Sumw2(); hEffLxy->Sumw2(); //event loop start if(nevt == -1) nevt = tr->GetEntries(); for (int iev=initev; iev<nevt; iev++){ tr->GetEntry(iev); bool yngen = false; bool ynreco = false; float weightF = 1.; float lxy = -531.; /// give a cut to Gen and Reco separately if (isPair) { if (isPtCut) { if ( !(pt<15.) ) continue; } /// define IP lxy = TMath::Sqrt((vtxz1-bx)*(vtxz1-bx)+(vtxy1-by)*(vtxy1-by)); if (kineCut(pt1,eta1) && kineCut(pt2,eta2) && idCut(npixelhits1,nmuonhits1) && idCut(npixelhits2,nmuonhits2) ) { yngen=true; } if (kineCut(ptreco1,etareco1) && kineCut(ptreco2,etareco2) && idCut(nvalidpixelhitsreco1,nvalidmuonhitsreco1) && idCut(nvalidpixelhitsreco2,nvalidmuonhitsreco2) //&& idRecoCut(nmatch1, chi2ndofreco1) //&& idRecoCut(nmatch2, chi2ndofreco2) && chi2ndofreco1 < 4. && chi2ndofreco2 < 4. && massCut(minvreco) ) { ynreco=true;} } else { if (isPtCut) { if (!(pt >1. && pt<15. ) ) continue; } /// define IP lxy = TMath::Sqrt((vtxz-bx)*(vtxz-bx)+(vtxy-by)*(vtxy-by)); if ( (!isEmbedded) && TMath::Abs(eta) < 2.4 && TMath::Abs(idparent)>442 && TMath::Abs(idparent)<550 && idCut(npixelhits,nmuonhits) ) { yngen=true; } else if ( isEmbedded && TMath::Abs(eta) < 2.4 //&& TMath::Abs(idparent)>442 //&& TMath::Abs(idparent)<550 && idCut(npixelhits,nmuonhits) ) { yngen=true; } if ( (!isEmbedded) //TMath::Abs(etareco) < 2.4 && TMath::Abs(eta) < 2.4 && TMath::Abs(idparent)>442 && TMath::Abs(idparent)<550 && idCut(nvalidpixelhitsreco,nvalidmuonhitsreco) && idRecoCut(nmatch, chi2ndofreco) ) { ynreco=true;} else if ( isEmbedded //TMath::Abs(etareco) < 2.4 && TMath::Abs(eta) < 2.4 //&& TMath::Abs(idparent)>442 //&& TMath::Abs(idparent)<550 && idCut(nvalidpixelhitsreco,nvalidmuonhitsreco) && idRecoCut(nmatch, chi2ndofreco) ) { ynreco=true;} } /// weight if "doWeight" && fill the histogram if (isPair){ if (doWeight) {weightF = getWeight(isPrompt, isPair, pt,y);} // cout << "weightF = " <<weightF << endl; if (yngen) { hGenPtY->Fill(y,pt,weightF); hGenPt->Fill(pt,weightF); hGenRap->Fill(y,weightF); hGenLxy->Fill(lxy,weightF); } if (ynreco) { hRecoPtY->Fill(yreco,ptreco,weightF); hRecoPt->Fill(ptreco, weightF); hRecoRap->Fill(yreco, weightF); hRecoLxy->Fill(lxy, weightF); } }else { if (doWeight) {weightF = getWeight(isPrompt, isPair, pt,eta);} // cout << "weightF = " <<weightF << endl; if (yngen) { hGenPtY->Fill(eta,pt,weightF); hGenPt->Fill(pt,weightF); hGenRap->Fill(eta,weightF); hGenLxy->Fill(lxy,weightF); } if (ynreco) { hRecoPtY->Fill(etareco,ptreco,weightF); hRecoPt->Fill(ptreco,weightF); hRecoRap->Fill(etareco,weightF); hRecoLxy->Fill(lxy, weightF); } } }// end of event loop cout << "hGenPt integral = " << hGenPt->Integral() << endl; cout << "hRecoPt integral = " << hRecoPt->Integral() << endl; cout << "hGenRap integral = " << hGenRap->Integral() << endl; cout << "hRecoRap integral = " << hRecoRap->Integral() << endl; cout << "hGenLxy integral = " << hGenLxy->Integral() << endl; cout << "hRecoLxy integral = " << hRecoLxy->Integral() << endl; //calculate efficiency hEffPtY->Divide(hRecoPtY,hGenPtY,1,1,"b"); hEffPt->Divide(hRecoPt,hGenPt,1,1,"b"); hEffRap->Divide(hRecoRap,hGenRap,1,1,"b"); hEffLxy->Divide(hRecoLxy,hGenLxy,1,1,"b"); //Legend TLegend *legUR = new TLegend(0.56,0.68,0.90,0.90,NULL,"brNDC"); TLegend *legUL = new TLegend(0.17,0.68,0.51,0.90,NULL,"brNDC"); TLegend *legBM = new TLegend(0.40,0.20,0.75,0.35,NULL,"brNDC"); TLegend *legBR = new TLegend(0.56,0.20,0.90,0.42,NULL,"brNDC"); SetLegendStyle(legUR); SetLegendStyle(legUL); SetLegendStyle(legBM); SetLegendStyle(legBR); TCanvas *c1 = new TCanvas("c1","c1",600,600); //draw 2D Pt-y TPaletteAxis* pal; hEffPtY->SetMinimum(0.0); hEffPtY->SetMaximum(1.0); if (isPair) hEffPtY->GetXaxis()->SetTitle("y"); else hEffPtY->GetXaxis()->SetTitle("#eta"); hEffPtY->GetXaxis()->CenterTitle(); hEffPtY->GetYaxis()->SetTitle("p_{T} (GeV)"); hEffPtY->Draw("colz"); c1->Update(); pal = (TPaletteAxis*)hEffPtY->GetListOfFunctions()->FindObject("palette"); pal->SetX2NDC(0.92); c1->Modified(); c1->Update(); c1->SaveAs(Form("%s/EffPtY_isPtCut%d_doWeight%d_isEmbedded%d_%s_%s_%s.pdf",strDir.c_str(),(int)isPtCut,(int)doWeight,(int)isEmbedded,strPrompt.c_str(),strEmbd.c_str(),strPair.c_str())); c1->Clear(); //draw EffPt SetHistStyle(hEffPt,3,0); hEffPt->SetMinimum(0.0); hEffPt->SetMaximum(1.0); if (isPair) hEffPt->GetXaxis()->SetTitle("Pair p_{T} (GeV)"); else hEffPt->GetXaxis()->SetTitle("Trk p_{T} (GeV)"); hEffPt->GetYaxis()->SetTitle("Efficiency"); hEffPt->Draw("pe"); c1->SaveAs(Form("%s/EffPt_isPtCut%d_doWeight%d_isEmbedded%d_%s_%s_%s.pdf",strDir.c_str(),(int)isPtCut,(int)doWeight,(int)isEmbedded,strPrompt.c_str(),strEmbd.c_str(),strPair.c_str())); c1->Clear(); //draw EffRap SetHistStyle(hEffRap,3,0); hEffRap->SetMinimum(0.0); hEffRap->SetMaximum(1.0); if (isPair) hEffRap->GetXaxis()->SetTitle("y"); else hEffRap->GetXaxis()->SetTitle("#eta"); hEffRap->GetXaxis()->CenterTitle(); hEffRap->GetYaxis()->SetTitle("Efficiency"); hEffRap->Draw("pe"); c1->SaveAs(Form("%s/EffRap_isPtCut%d_doWeight%d_isEmbedded%d_%s_%s_%s.pdf",strDir.c_str(),(int)isPtCut,(int)doWeight,(int)isEmbedded,strPrompt.c_str(),strEmbd.c_str(),strPair.c_str())); c1->Clear(); //draw EffLxy SetHistStyle(hEffLxy,3,0); hEffLxy->SetMinimum(0.0); hEffLxy->SetMaximum(1.0); hEffLxy->GetXaxis()->SetTitle("Lxy"); hEffLxy->GetYaxis()->SetTitle("Efficiency"); hEffLxy->Draw("pe"); c1->SaveAs(Form("%s/EffLxy_isPtCut%d_doWeight%d_isEmbedded%d_%s_%s_%s.pdf",strDir.c_str(),(int)isPtCut,(int)doWeight,(int)isEmbedded,strPrompt.c_str(),strEmbd.c_str(),strPair.c_str())); c1->Clear(); //save as a root file TFile* outFile = new TFile(Form("%s/Eff_isPtCut%d_doWeight%d_isEmbedded%d_%s_%s_%s.root",strDir.c_str(),(int)isPtCut,(int)doWeight,(int)isEmbedded,strPrompt.c_str(),strEmbd.c_str(),strPair.c_str()),"RECREATE"); outFile->cd(); hGenPtY->Write(); hRecoPtY->Write(); hEffPtY->Write(); hGenPt->Write(); hGenRap->Write(); hGenLxy->Write(); hRecoPt->Write(); hRecoRap->Write(); hRecoLxy->Write(); hEffPt->Write(); hEffRap->Write(); hEffLxy->Write(); outFile->Close(); return; }
int rootAna_meanPt_wBkg(char *strBin = "8rap9pt"){ //const int nbin = 100; //arbitrary binning for each pT hist. const int nbin = 20; //arbitrary binning for each pT hist. const int nEntry = 10000; gROOT->Macro("./JpsiStyle.C"); // read-in root file (data) TFile *fDataPbp1; // 210498<= runNb <= 210658 should be rejected TFile *fDataPbp2; // only 210498<= runNb <= 210658 will be used : 1st 7 run (Reprocessed) TFile *fDatapPb; fDataPbp1 = new TFile("/home/songkyo/kyo/pPbDataSample/Data/pPbData_1st_ntuple_PromptReco-v1_GR_P_V43D_pileupRej_newAccCut_tot.root"); fDataPbp2 = new TFile("/home/songkyo/kyo/pPbDataSample/Data/pPbData_1st_ntuple_PromptReco-v1_GR_P_V43F_pileupRej_newAccCut_tot.root"); fDatapPb = new TFile("/home/songkyo/kyo/pPbDataSample/Data/pPbData_2nd_PromptReco-v1_GR_P_V43D_pileupRej_newAccCut_tot.root"); TTree *treeDataPbp1 = (TTree*)fDataPbp1->Get("myTree"); TTree *treeDataPbp2 = (TTree*)fDataPbp2->Get("myTree"); TTree *treeDatapPb = (TTree*)fDatapPb->Get("myTree"); ///////////////////////////////////////////////////////////// ////////////// binning Double_t ptArr[] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10.0, 14.0, 30.0}; // 8rap9pt const Int_t nPt = sizeof(ptArr)/sizeof(double)-1; cout << "nPt=" << nPt << endl; // in Ycm (will be change to 1st lab and 2nd lab later) Double_t yArr[] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87}; // 8rap9pt const Int_t nRap = sizeof(yArr)/sizeof(double)-1; cout << "nRap=" << nRap << endl; string rapstrArr[nRap]; for (int ir=0; ir<nRap; ir++){ formRapArr(yArr[ir+1], yArr[ir], &rapstrArr[ir]); cout << "rap string arr = " << rapstrArr[ir].c_str() << endl; } Double_t etArr[] = {0.0, 120.0}; // 8rap9pt //Double_t etArr[] = {0.0, 20., 30., 120.0}; // ethf const Int_t nEt = sizeof(etArr)/sizeof(double)-1; cout << "nEt=" << nEt << endl; string etstrArr[nEt]; for (int in=0; in<nEt; in++){ formEtArr(etArr[in], etArr[in+1], &etstrArr[in]); cout << "et string arr = " << etstrArr[in].c_str() << endl; } ///////////////////////////////////////////////////////////// ////////////// cut definitions TCut trigCut = "( (Reco_QQ_trig&1)==1 && (HLTriggers&1)==1 )"; TCut recoCut = "Reco_QQ_size>=1 && Reco_QQ_sign==0"; // TCut massRange = "Reco_QQ_4mom.M() >2.6 && Reco_QQ_4mom.M() < 3.5"; TCut massRange = "Reco_QQ_4mom.M() >2.9 && Reco_QQ_4mom.M() < 3.3"; TCut massRangeBkg = "((2.6 < Reco_QQ_4mom.M() && Reco_QQ_4mom.M() <2.9) || (3.3 < Reco_QQ_4mom.M() && Reco_QQ_4mom.M() < 3.5))"; TCut ctauRange = "Reco_QQ_ctau > -3.0 && Reco_QQ_ctau < 5.0 && Reco_QQ_ctauErr > 0.0 && Reco_QQ_ctauErr < 1.0"; TCut accRecoPlus = "(TMath::Abs(Reco_QQ_mupl_4mom.Eta())<2.4) && ( (TMath::Abs(Reco_QQ_mupl_4mom.Eta())<1.2 && Reco_QQ_mupl_4mom.Pt()>=3.3) || ( 1.2<= TMath::Abs(Reco_QQ_mupl_4mom.Eta()) && TMath::Abs(Reco_QQ_mupl_4mom.Eta()) < 2.1 && Reco_QQ_mupl_4mom.Pt() >= -(1.0/0.9)*TMath::Abs(Reco_QQ_mupl_4mom.Eta())+(1.2*(1.0/0.9)+2.6)) ||(2.1<=TMath::Abs(Reco_QQ_mupl_4mom.Eta()) && Reco_QQ_mupl_4mom.Pt()>=1.3) )"; TCut accRecoMinus = "(TMath::Abs(Reco_QQ_mumi_4mom.Eta())<2.4) && ( (TMath::Abs(Reco_QQ_mumi_4mom.Eta())<1.2 && Reco_QQ_mumi_4mom.Pt()>=3.3) || ( 1.2<= TMath::Abs(Reco_QQ_mumi_4mom.Eta()) && TMath::Abs(Reco_QQ_mumi_4mom.Eta()) < 2.1 && Reco_QQ_mumi_4mom.Pt() >= -(1.0/0.9)*TMath::Abs(Reco_QQ_mumi_4mom.Eta())+(1.2*(1.0/0.9)+2.6)) ||(2.1<=TMath::Abs(Reco_QQ_mumi_4mom.Eta()) && Reco_QQ_mumi_4mom.Pt()>=1.3) )"; TCut ptRange[nEt][nRap][nPt]; TCut rapRangePbp[nEt][nRap][nPt]; TCut rapRangepPb[nEt][nRap][nPt]; TCut totalCutPbp[nEt][nRap][nPt]; TCut totalCutpPb[nEt][nRap][nPt]; TCut totalCutBkgPbp[nEt][nRap][nPt]; TCut totalCutBkgpPb[nEt][nRap][nPt]; TCut runCut = "runNb >=210498 && runNb <= 210658"; //1st 7 run // forming TCut for diffential binning for (int in=0; in<nEt; in++){ for (int ir=0; ir<nRap; ir++ ) { for (int ipt=0; ipt<nPt; ipt++) { ptRange[in][ir][ipt] = Form("Reco_QQ_4mom.Pt()>%.1f && Reco_QQ_4mom.Pt()<%.1f",ptArr[ipt] , ptArr[ipt+1]); //change y_CM to y_lab rapRangePbp[in][ir][ipt] = Form("-0.47-1.*Reco_QQ_4mom.Rapidity()>%.2f && -0.47-1.*Reco_QQ_4mom.Rapidity()<%.2f",yArr[ir+1] , yArr[ir]); rapRangepPb[in][ir][ipt] = Form("-0.47+Reco_QQ_4mom.Rapidity()>%.2f && -0.47+Reco_QQ_4mom.Rapidity()<%.2f",yArr[ir+1] , yArr[ir]); cout << "ptRange = " <<ptRange[in][ir][ipt] << endl; cout << "rapRangePbp = " <<rapRangePbp[in][ir][ipt] << endl; cout << "rapRangepPb = " <<rapRangepPb[in][ir][ipt] << endl; totalCutPbp[in][ir][ipt] = trigCut && recoCut && massRange && ctauRange && accRecoPlus && accRecoMinus && rapRangePbp[in][ir][ipt] && ptRange[in][ir][ipt]; totalCutpPb[in][ir][ipt] = trigCut && recoCut && massRange && ctauRange && accRecoPlus && accRecoMinus && rapRangepPb[in][ir][ipt] && ptRange[in][ir][ipt]; totalCutBkgPbp[in][ir][ipt] = trigCut && recoCut && massRangeBkg && ctauRange && accRecoPlus && accRecoMinus && rapRangePbp[in][ir][ipt] && ptRange[in][ir][ipt]; totalCutBkgpPb[in][ir][ipt] = trigCut && recoCut && massRangeBkg && ctauRange && accRecoPlus && accRecoMinus && rapRangepPb[in][ir][ipt] && ptRange[in][ir][ipt]; } } } ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // define 1D hist TH1D *hMeanPt[nEt][nRap][nPt]; TH1D *hMeanPtBkg[nEt][nRap][nPt]; double meanVal[nEt][nRap][nPt]; double maxVal[nEt][nRap][nPt]; double meanValBkg[nEt][nRap][nPt]; double maxValBkg[nEt][nRap][nPt]; //TCanvas* c1 = new TCanvas("c1","c1",600,600); TCanvas* cmulti[nEt][nRap]; TLegend *legUR = new TLegend(0.58,0.68,0.90,0.90,NULL,"brNDC"); TLegend *legUM = new TLegend(0.30,0.68,0.65,0.90,NULL,"brNDC"); TLegend *legUL = new TLegend(0.17,0.68,0.51,0.90,NULL,"brNDC"); TLegend *legBM = new TLegend(0.30,0.20,0.65,0.42,NULL,"brNDC"); SetLegendStyle(legUR); SetLegendStyle(legUM); SetLegendStyle(legUL); SetLegendStyle(legBM); TLatex* latex = new TLatex(); latex->SetNDC(); latex->SetTextAlign(12); latex->SetTextSize(0.04); for (int in=0; in<nEt; in++){ for (int ir=0; ir<nRap; ir++ ) { cmulti[in][ir]= new TCanvas(Form("cmulti_%d_%d",in,ir),Form("%s",rapstrArr[ir].c_str()),1500,600); cmulti[in][ir]->Divide(5,2); for (int ipt=0; ipt<nPt; ipt++) { hMeanPt[in][ir][ipt] = new TH1D(Form("hMeanPt_%d_%d_%d",in, ir, ipt),";p_{T} (GeV/c);events", nbin, ptArr[ipt], ptArr[ipt+1]); hMeanPt[in][ir][ipt] ->Sumw2(); SetHistStyle(hMeanPt[in][ir][ipt],4,0); hMeanPtBkg[in][ir][ipt] = new TH1D(Form("hMeanPtBkg_%d_%d_%d",in, ir, ipt),";p_{T} (GeV/c);events", nbin, ptArr[ipt], ptArr[ipt+1]); hMeanPtBkg[in][ir][ipt] ->Sumw2(); SetHistStyle(hMeanPtBkg[in][ir][ipt],3,10); cmulti[in][ir]->cd(ipt+1); gPad->SetLogy(1); /* treeDataPbp1->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPt[in][ir][ipt]->GetName()),(totalCutPbp[in][ir][ipt]&&(!runCut)),"",nEntry); treeDataPbp2->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPt[in][ir][ipt]->GetName()),(totalCutPbp[in][ir][ipt]&&runCut),"",nEntry); treeDatapPb->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPt[in][ir][ipt]->GetName()),totalCutpPb[in][ir][ipt],"",nEntry); treeDataPbp1->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPtBkg[in][ir][ipt]->GetName()),(totalCutBkgPbp[in][ir][ipt]&&(!runCut)),"pe same",nEntry); treeDataPbp2->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPtBkg[in][ir][ipt]->GetName()),(totalCutBkgPbp[in][ir][ipt]&&runCut),"pe same",nEntry); treeDatapPb->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPtBkg[in][ir][ipt]->GetName()),totalCutBkgpPb[in][ir][ipt],"pe same",nEntry); */ treeDataPbp1->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPt[in][ir][ipt]->GetName()),(totalCutPbp[in][ir][ipt]&&(!runCut)),""); treeDataPbp2->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPt[in][ir][ipt]->GetName()),(totalCutPbp[in][ir][ipt]&&runCut),""); treeDatapPb->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPt[in][ir][ipt]->GetName()),totalCutpPb[in][ir][ipt],""); treeDataPbp1->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPtBkg[in][ir][ipt]->GetName()),(totalCutBkgPbp[in][ir][ipt]&&(!runCut)),"pe same"); treeDataPbp2->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPtBkg[in][ir][ipt]->GetName()),(totalCutBkgPbp[in][ir][ipt]&&runCut),"pe same"); treeDatapPb->Draw(Form("Reco_QQ_4mom.Pt()>>+%s",hMeanPtBkg[in][ir][ipt]->GetName()),totalCutBkgpPb[in][ir][ipt],"pe same"); meanVal[in][ir][ipt] = hMeanPt[in][ir][ipt]->GetMean(1); maxVal[in][ir][ipt] = 50*hMeanPt[in][ir][ipt]->GetMaximum(); meanValBkg[in][ir][ipt] = hMeanPtBkg[in][ir][ipt]->GetMean(1); maxValBkg[in][ir][ipt] = 50*hMeanPtBkg[in][ir][ipt]->GetMaximum(); hMeanPt[in][ir][ipt]->GetYaxis()->SetRangeUser(0.1,maxVal[in][ir][ipt]); hMeanPtBkg[in][ir][ipt]->GetYaxis()->SetRangeUser(0.1,maxValBkg[in][ir][ipt]); std::cout << hMeanPt[in][ir][ipt]->GetName() <<" : entries = " << hMeanPt[in][ir][ipt]->GetEntries() << std::endl; cout << " Cand <p_{T}> = " << meanVal[in][ir][ipt] << endl; cout << " Bkg <p_{T}> = " << meanValBkg[in][ir][ipt] << endl; latex->DrawLatex(0.54, 0.87, rapstrArr[ir].c_str()); latex->DrawLatex(0.54, 0.80, Form("Cand <p_{T}> = %.2f (GeV/c)",meanVal[in][ir][ipt])); latex->DrawLatex(0.54, 0.72, Form("Bkg <p_{T}> = %.2f (GeV/c)",meanValBkg[in][ir][ipt])); //c1->Update(); //c1->SaveAs(Form("%s.png",hMeanPt[in][ir][ipt]->GetName())); //c1->Clear(); } cmulti[in][ir]->Update(); cmulti[in][ir]->SaveAs(Form("dir_meanPt/meanPt_%s_%d_%d_wBkg.pdf",strBin,in,ir)); //cmulti[in][ir]->Clear(); } } /// Save as a root file TFile *outFile = new TFile(Form("meanPt_%s_wBkg.root",strBin),"RECREATE"); std::cout << "strBin : " << strBin << std::endl; outFile->cd(); for (int in=0; in<nEt; in++){ for (int ir=0; ir<nRap; ir++ ) { for (int ipt=0; ipt<nPt; ipt++) { hMeanPt[in][ir][ipt]->Write(); hMeanPtBkg[in][ir][ipt]->Write(); } } } outFile->Close(); return 0; }
// examples macro void etauAfterFit_novbf(bool scaled = true, bool log = true) { // defining the common canvas, axes pad styles SetStyle(); // open example histogram file TFile* exampleFile = new TFile("eleTau_sm.root"); //load example histograms TH1F* data = (TH1F*)exampleFile->Get("eleTau_SM0/data_obs"); if(data) {InitHist(data, "#bf{m_{vis} [GeV]}", "#bf{Events}"); InitData(data);} else{std::cout << "can't find hitogram " << "eleTau_SM0/data_obs" << std::endl;} TH1F* Fakes = refill((TH1F*)exampleFile->Get("eleTau_SM0/QCD")) ; InitHist(Fakes, "", "", kMagenta-10, 1001); TH1F* EWK1 = refill((TH1F*)exampleFile->Get("eleTau_SM0/W" )) ; InitHist(EWK1 , "", "", kRed + 2, 1001); TH1F* EWK2 = refill((TH1F*)exampleFile->Get("eleTau_SM0/ZJ" )) ; InitHist(EWK2 , "", "", kRed + 2, 1001); TH1F* EWK3 = refill((TH1F*)exampleFile->Get("eleTau_SM0/ZL" )) ; InitHist(EWK3 , "", "", kRed + 2, 1001); TH1F* EWK = refill((TH1F*)exampleFile->Get("eleTau_SM0/VV" )) ; InitHist(EWK , "", "", kRed + 2, 1001); TH1F* ttbar = refill((TH1F*)exampleFile->Get("eleTau_SM0/TT" )) ; InitHist(ttbar, "", "", kBlue - 8, 1001); TH1F* Ztt = refill((TH1F*)exampleFile->Get("eleTau_SM0/ZTT")) ; InitHist(Ztt , "", "", kOrange - 4, 1001); TH1F* ggH = refill((TH1F*)exampleFile->Get("eleTau_SM0/SM120" )) ; InitSignal(ggH); ggH ->Scale(10*16.63*0.071*16.083/ggH ->Integral()); TH1F* qqH = refill((TH1F*)exampleFile->Get("eleTau_SM0/VBF120")) ; InitSignal(qqH); qqH ->Scale(10*1.269*0.071* 1.105/qqH ->Integral()); if(scaled){ rescale(Fakes, 2); rescale(EWK1 , 3); rescale(EWK2 , 4); rescale(EWK3 , 5); rescale(EWK , 7); rescale(ttbar, 6); rescale(Ztt , 1); rescale(ggH , 8); rescale(qqH , 9); } if(log){ qqH ->Add(ggH ); Fakes->Add(qqH ); EWK1 ->Add(Fakes); EWK2 ->Add(EWK1 ); EWK3 ->Add(EWK2 ); EWK ->Add(EWK3 ); ttbar->Add(EWK ); Ztt ->Add(ttbar); } else{ EWK1 ->Add(Fakes); EWK2 ->Add(EWK1 ); EWK3 ->Add(EWK2 ); EWK ->Add(EWK3 ); ttbar->Add(EWK ); Ztt ->Add(ttbar); ggH ->Add(Ztt ); qqH ->Add(ggH ); } // define canvas TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); data->SetMinimum(5.0); data->SetMaximum(500000.); } else{ data->SetMaximum(4000.); } data->SetNdivisions(505); data->Draw("e"); if(log){ Ztt->Draw("same"); ttbar->Draw("same"); EWK->Draw("same"); Fakes->Draw("same"); qqH->Draw("same"); } else{ qqH->Draw("same"); Ztt->Draw("same"); ttbar->Draw("same"); EWK->Draw("same"); Fakes->Draw("same"); } data->Draw("esame"); canv->RedrawAxis(); CMSPrelim("#tau_{e}#tau_{h}", 0.45, 0.75); TLegend* leg = new TLegend(0.45, 0.45, 0.9, 0.75); SetLegendStyle(leg); leg->AddEntry(qqH , "(10x) H#rightarrow#tau#tau" , "L" ); leg->AddEntry(data , "Observed" , "LP"); leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(EWK , "Electroweak" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); leg->Draw(); TPaveText* mssm = new TPaveText(0.78, 0.70, 0.90, 0.74, "NDC"); mssm->SetBorderSize( 0 ); mssm->SetFillStyle( 0 ); mssm->SetTextAlign( 12 ); mssm->SetTextSize ( 0.04 ); mssm->SetTextColor( 1 ); mssm->SetTextFont ( 62 ); mssm->AddText("m_{H}=120"); mssm->Draw(); if(log){ if(scaled) canv->Print("etau_rescaled_novbf_LOG.pdf"); else canv->Print("etau_unscaled_novbf_LOG.pdf"); if(scaled) canv->Print("etau_rescaled_novbf_LOG.png"); else canv->Print("etau_unscaled_novbf_LOG.png"); } else{ if(scaled) canv->Print("etau_rescaled_novbf.pdf"); else canv->Print("etau_unscaled_novbf.pdf"); if(scaled) canv->Print("etau_rescaled_novbf.png"); else canv->Print("etau_unscaled_novbf.png"); } }
void //HHH_TT_X_notag(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="tauTau_$CATEGORY") HHH_TT_X_notag(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="tauTau_$CATEGORY") { // defining the common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category = ""; const char* category_extra = ""; const char* category_extra2 = ""; if(std::string(directory) == std::string("tauTau_2jet0tag")){ category = "#tau_{h}#tau_{h}"; } if(std::string(directory) == std::string("tauTau_2jet0tag")){ category_extra= "2-jet 0 b-tag"; } if(std::string(directory) == std::string("tauTau_2jet1tag" )){ category = "#tau_{h}#tau_{h}"; } if(std::string(directory) == std::string("tauTau_2jet1tag" )){ category_extra= "2-jet 1 b-tag"; } if(std::string(directory) == std::string("tauTau_2jet2tag" )){ category = "#tau_{h}#tau_{h}"; } if(std::string(directory) == std::string("tauTau_2jet2tag" )){ category_extra = "2-jet 2 b-tag"; } const char* dataset; #ifdef MSSM if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 4.9 fb^{-1} (7 TeV)";} if(std::string(inputfile).find("8TeV")!=std::string::npos){ if(std::string(directory).find("btag")!=std::string::npos){ dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 18.3 fb^{-1} (8 TeV)"; } else{ dataset = "#scale[1.5]{CMS} H#rightarrow hh#rightarrow#tau#tau bb 19.7 fb^{-1} (8 TeV)"; } } #else if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS, 19.7 fb^{-1} at 8 TeV";} #endif // open example histogram file TFile* input = new TFile(inputfile.c_str()); #ifdef MSSM TFile* input2 = new TFile((inputfile+"_$MH_$TANB").c_str()); #endif TH1F* Fakes = refill((TH1F*)input->Get(TString::Format("%s/QCD" , directory)), "QCD"); InitHist(Fakes, "", "", TColor::GetColor(250,202,255), 1001); TH1F* EWK1 = refill((TH1F*)input->Get(TString::Format("%s/W" , directory)), "W" ); InitHist(EWK1 , "", "", TColor::GetColor(222,90,106), 1001); TH1F* EWK2 = refill((TH1F*)input->Get(TString::Format("%s/ZLL" , directory)), "ZLL" ); InitHist(EWK2 , "", "", TColor::GetColor(222,90,106), 1001); //TH1F* EWK3 = refill((TH1F*)input->Get(TString::Format("%s/ZL" , directory)), "ZL" ); InitHist(EWK3 , "", "", TColor::GetColor(222,90,106), 1001); TH1F* EWK = refill((TH1F*)input->Get(TString::Format("%s/VV" , directory)), "VV" ); InitHist(EWK , "", "", TColor::GetColor(222,90,106), 1001); TH1F* ttbar = refill((TH1F*)input->Get(TString::Format("%s/TT" , directory)), "TT" ); InitHist(ttbar, "", "", TColor::GetColor(155,152,204), 1001); TH1F* Ztt = refill((TH1F*)input->Get(TString::Format("%s/ZTT" , directory)), "ZTT"); InitHist(Ztt , "", "", TColor::GetColor(248,206,104), 1001); #ifdef MSSM TH1F* ggHTohhTo2Tau2B = refill((TH1F*)input2->Get(TString::Format("%s/ggHTohhTo2Tau2B$MH" , directory)), "ggHTohhTo2Tau2B"); InitSignal(ggHTohhTo2Tau2B); ggHTohhTo2Tau2B->Scale($TANB*SIGNAL_SCALE); // if(std::string(directory)=="tauTau_2jet0tag") ggHTohhTo2Tau2B->Scale(4); /* TH1F* ggH_SM125 = refill((TH1F*)input->Get(TString::Format("%s/ggH_SM125",directory)),"ggH_SM125");InitSignal(ggH_SM125);ggH_SM125->Scale(SIGNAL_SCALE); TH1F* qqH_SM125 = refill((TH1F*)input->Get(TString::Format("%s/qqH_SM125",directory)),"qqH_SM125");InitSignal(qqH_SM125);qqH_SM125->Scale(SIGNAL_SCALE); TH1F* VH_SM125 = refill((TH1F*)input->Get(TString::Format("%s/VH_SM125",directory)),"VH_SM125");InitSignal(VH_SM125);VH_SM125->Scale(SIGNAL_SCALE); TH1F* WHToBB_SM125 = refill((TH1F*)input->Get(TString::Format("%s/WHToBB_SM125",directory)),"WHToBB_SM125");InitSignal(WHToBB_SM125);WHToBB_SM125->Scale(SIGNAL_SCALE); TH1F* ZHToBB_SM125 = refill((TH1F*)input->Get(TString::Format("%s/ZHToBB_SM125",directory)),"ZHToBB_SM125");InitSignal(ZHToBB_SM125);ZHToBB_SM125->Scale(SIGNAL_SCALE); */ /* TH1F* ggAToZhToLLTauTau = refill((TH1F*)input2->Get(TString::Format("%s/ggAToZhToLLTauTau$MH",directory)),"ggAToZhToLLTauTau"); InitSignal(ggAToZhToLLTauTau); TH1F* ggAToZhToLLBB = refill((TH1F*)input2->Get(TString::Format("%s/ggAToZhToLLBB$MH",directory)),"ggAToZhToLLBB"); InitSignal(ggAToZhToLLBB); TH1F* bbH = refill((TH1F*)input2->Get(TString::Format("%s/bbH$MH" , directory)), "bbH"); InitSignal(bbH); */ #endif #ifdef ASIMOV TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs_asimov", directory)), "data", true); #else TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data",true); #endif InitHist(data, "#bf{m_{H} [GeV]}", "#bf{dN/dm_{H} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)Fakes->Clone("ref"); ref->Add(EWK1 ); ref->Add(EWK2 ); //ref->Add(EWK3 ); ref->Add(EWK ); ref->Add(ttbar); ref->Add(Ztt ); double unscaled[8]; unscaled[0] = Fakes->Integral(); unscaled[1] = EWK ->Integral(); unscaled[1]+= EWK1 ->Integral(); unscaled[1]+= EWK2 ->Integral(); //unscaled[1]+= EWK3 ->Integral(); unscaled[2] = ttbar->Integral(); unscaled[3] = Ztt ->Integral(); #ifdef MSSM unscaled[4] = ggHTohhTo2Tau2B ->Integral(); /* unscaled[5] = ggH_SM125->Integral(); unscaled[5]+= qqH_SM125->Integral(); unscaled[5]+= VH_SM125->Integral(); */ /* unscaled[5] = ggAToZhToLLTauTau->Integral(); unscaled[6] = ggAToZhToLLBB->Integral(); unscaled[7] = bbH ->Integral(); */ #endif if(scaled){ /* Fakes = refill(shape_histos(Fakes, datacard, "QCD"), "QCD"); EWK1 = refill(shape_histos(EWK1, datacard, "W"), "W"); EWK2 = refill(shape_histos(EWK2, datacard, "ZJ"), "ZJ"); EWK = refill(shape_histos(EWK, datacard, "VV"), "VV"); ttbar = refill(shape_histos(ttbar, datacard, "TT"), "TT"); Ztt = refill(shape_histos(Ztt, datacard, "ZTT"), "ZTT"); #ifdef MSSM ggH = refill(shape_histos(ggH, datacard, "ggH$MH"), "ggH$MH"); bbH = refill(shape_histos(bbH, datacard, "bbH$MH"), "bbH$MH"); #else ggH = refill(shape_histos(ggH, datacard, "ggH"), "ggH"); qqH = refill(shape_histos(qqH, datacard, "qqH"), "qqH"); VH = refill(shape_histos(VH, datacard, "VH"), "VH"); #endif */ rescale(Fakes, 7); rescale(EWK1 , 3); rescale(EWK2 , 4); //rescale(EWK3 , 5); rescale(EWK , 6); rescale(ttbar, 2); rescale(Ztt , 1); #ifdef MSSM rescale(ggHTohhTo2Tau2B , 8); /* rescale(ggAToZhToLLTauTau,9); rescale(ggAToZhToLLBB,10); rescale(bbH , 11); */ #endif } TH1F* scales[8]; scales[0] = new TH1F("scales-Fakes", "", 8, 0, 8); scales[0]->SetBinContent(1, unscaled[0]>0 ? (Fakes->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-EWK" , "", 8, 0, 8); scales[1]->SetBinContent(2, unscaled[1]>0 ? ((EWK ->Integral() +EWK1 ->Integral() +EWK2 ->Integral() //+EWK3 ->Integral() )/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-ttbar", "", 8, 0, 8); scales[2]->SetBinContent(3, unscaled[2]>0 ? (ttbar->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-Ztt" , "", 8, 0, 8); scales[3]->SetBinContent(4, unscaled[3]>0 ? (Ztt ->Integral()/unscaled[3]-1.) : 0.); #ifdef MSSM scales[4] = new TH1F("scales-ggHTohhTo2Tau2B" , "", 8, 0, 8); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggHTohhTo2Tau2B ->Integral()/unscaled[4]-1.) : 0.); /* scales[5] = new TH1F("scales-sm","",8,0,8); scales[5]->SetBinContent(6, unscaled[5]>0 ? ((ggH_SM125->Integral()+qqH_SM125->Integral()+VH_SM125->Integral())/unscaled[5]-1.) : 0.); */ /* scales[5] = new TH1F("scales-ggAToZhToLLTauTau" , "", 8, 0, 8); scales[5]->SetBinContent(6, unscaled[5]>0 ? (ggAToZhToLLTauTau ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-ggAToZhToLLBB" , "", 8, 0, 8); scales[6]->SetBinContent(7, unscaled[6]>0 ? (ggAToZhToLLBB ->Integral()/unscaled[6]-1.) : 0.); scales[7] = new TH1F("scales-bbH" , "", 8, 0, 8); scales[7]->SetBinContent(8, unscaled[7]>0 ? (bbH ->Integral()/unscaled[7]-1.) : 0.); */ #endif //#ifdef MSSM // qqH_SM125->Add(ggH_SM125); // VH_SM125->Add(qqH_SM125); // Fakes->Add(VH_SM125); //#endif Fakes->Add(ttbar); EWK1 ->Add(Fakes); EWK2 ->Add(Fakes ); //EWK3 ->Add(EWK2 ); //EWK ->Add(EWK3 ); EWK ->Add(EWK2 ); // ttbar->Add(EWK ); Ztt ->Add(EWK); /*ggH_SM125->Add(qqH_SM125); ggH_SM125->Add(VH_SM125); ggH_SM125->Add(ZHToBB_SM125); ggH_SM125->Add(WHToBB_SM125); */ //if(log){ //#ifdef MSSM // ggH->Add(bbH); //#else // qqH->Add(VH ); // ggH->Add(qqH); //#endif // } //else{ //#ifdef MSSM // bbH->Add(Ztt); // ggH->Add(bbH); //#else // VH ->Add(Ztt); // qqH->Add(VH ); // ggH->Add(qqH); //#endif // } /* Mass plot before and after fit */ TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(200, data->FindBin(UPPER_EDGE)); } else{ data->GetXaxis()->SetRange(200, data->FindBin(UPPER_EDGE)); }; #else data->GetXaxis()->SetRange(200, data->FindBin(UPPER_EDGE)); #endif data->SetNdivisions(505); data->SetMinimum(min); data->SetMaximum(max>0 ? max : std::max(std::max(maximum(data, log), maximum(Ztt, log)), maximum(ggHTohhTo2Tau2B, log))); data->Draw("e"); TH1F* errorBand = (TH1F*)Ztt ->Clone(); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(13); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } if(log){ Ztt ->Draw("histsame"); // ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); ttbar->Draw("histsame"); //#ifdef MSSM // VH_SM125->Draw("histsame"); //#endif $DRAW_ERROR ggHTohhTo2Tau2B ->Draw("histsame"); /* ggH_SM125->SetLineColor(kRed); ggH_SM125->Draw("histsame"); */ } else{ Ztt ->Draw("histsame"); // ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); ttbar->Draw("histsame"); #ifdef MSSM //VH_SM125->Draw("histsame"); #endif $DRAW_ERROR ggHTohhTo2Tau2B ->Draw("histsame"); /*ggH_SM125->SetLineColor(kRed); ggH_SM125->Draw("histsame"); */ } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{h}#tau_{h}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); #if defined MSSM TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "tlbrNDC"); if (strcmp(category_extra2,"")!=0) chan = new TPaveText(0.20, 0.69+0.061, 0.32, 0.74+0.161, "tlbrNDC"); #else TPaveText* chan = new TPaveText(0.52, 0.35, 0.91, 0.55, "tlbrNDC"); #endif chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(category); chan->AddText(category_extra); #if defined MSSM if (strcmp(category_extra2,"")!=0) chan->AddText(category_extra2); #else chan->AddText(category_extra2); #endif chan->Draw(); /* TPaveText* cat = new TPaveText(0.20, 0.71+0.061, 0.32, 0.71+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); TPaveText* cat2 = new TPaveText(0.20, 0.66+0.061, 0.32, 0.66+0.161, "NDC"); cat2->SetBorderSize( 0 ); cat2->SetFillStyle( 0 ); cat2->SetTextAlign( 12 ); cat2->SetTextSize ( 0.05 ); cat2->SetTextColor( 1 ); cat2->SetTextFont ( 62 ); cat2->AddText(category_extra2); cat2->Draw(); */ #ifdef MSSM TPaveText* massA = new TPaveText(0.53, 0.44+0.061, 0.95, 0.44+0.151, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("MSSM m^{h}_{mod+} scenario"); massA->AddText("m_{H}=$MH GeV, tan#beta=$TANB"); massA->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.53, 0.60, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(ggHTohhTo2Tau2B , TString::Format("%0.f #times H#rightarrowhh#rightarrow#tau#taubb", SIGNAL_SCALE) , "L" ); //leg->AddEntry(ggH_SM125, TString::Format("%0.f #times SM H(125 GeV) #rightarrow #tau#tau/bb", SIGNAL_SCALE), "L"); #endif #ifdef ASIMOV leg->AddEntry(data , "sum(bkg) + H(125)" , "LP"); #else leg->AddEntry(data , "Observed" , "LP"); #endif leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(EWK , "Electroweak" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); /*#ifdef MSSM leg->AddEntry(VH_SM125, "SM H(125 GeV) #rightarrow #tau#tau", "F" ); #endif */ $ERROR_LEGEND leg->Draw(); /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* model = (TH1F*)Ztt ->Clone("model"); TH1F* test1 = (TH1F*)data->Clone("test1"); for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){ //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01); model->SetBinError (ibin+1, CONSERVATIVE_CHI2 ? 0. : model->GetBinError (ibin+1)*model->GetBinWidth(ibin+1)); test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1)); test1->SetBinError (ibin+1, test1->GetBinError (ibin+1)*test1->GetBinWidth(ibin+1)); } double chi2prob=0.; double chi2ndof=0.; double ksprob=0.; double ksprobpe=0.; if(!BLIND_DATA){ chi2prob = test1->Chi2Test (model,"PUW"); std::cout << "chi2prob:" << chi2prob << std::endl; chi2ndof = test1->Chi2Test (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl; ksprob = test1->KolmogorovTest(model); std::cout << "ksprob :" << ksprob << std::endl; ksprobpe = test1->KolmogorovTest(model,"DX"); std::cout << "ksprobpe:" << ksprobpe << std::endl; } std::vector<double> edges; TH1F* zero = (TH1F*)ref->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat1"); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ rat1->SetBinContent(ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinContent(ibin+1)/Ztt->GetBinContent(ibin+1) : 0); rat1->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); zero->SetBinContent(ibin+1, 0.); zero->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? Ztt ->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } } float range = 0.1; std::sort(edges.begin(), edges.end()); if(edges.size()>1){ if (edges[edges.size()-2]>0.1) { range = 0.2; } else if (edges[edges.size()-2]>0.2) { range = 0.5; } else if (edges[edges.size()-2]>0.5) { range = 1.0; } else if (edges[edges.size()-2]>1.0) { range = 1.5; } else if (edges[edges.size()-2]>1.5) { range = 2.0; } } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+range); rat1->SetMinimum(-range); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{H} [GeV]}"); rat1->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->SetMarkerSize(0.1); zero->Draw("e2histsame"); canv0->RedrawAxis(); TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC"); stat1->SetBorderSize( 0 ); stat1->SetFillStyle( 0 ); stat1->SetTextAlign( 12 ); stat1->SetTextSize ( 0.05 ); stat1->SetTextColor( 1 ); stat1->SetTextFont ( 62 ); if(!BLIND_DATA){ stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f", chi2ndof, chi2prob)); } //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f, P(KS)=%.3f", chi2ndof, chi2prob, ksprob)); stat1->Draw(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); edges.clear(); TH1F* rat2 = (TH1F*) Ztt->Clone("rat2"); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ rat2->SetBinContent(ibin+1, ref->GetBinContent(ibin+1)>0 ? Ztt->GetBinContent(ibin+1)/ref->GetBinContent(ibin+1) : 0); rat2->SetBinError (ibin+1, ref->GetBinContent(ibin+1)>0 ? Ztt->GetBinError (ibin+1)/ref->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat2->GetBinContent(ibin+1)-1.)+TMath::Abs(rat2->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } range = 0.1; std::sort(edges.begin(), edges.end()); if(edges.size()>1){ if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } } #if defined MSSM if(!log){ rat2->GetXaxis()->SetRange(200, rat2->FindBin(UPPER_EDGE)); } else{ rat2->GetXaxis()->SetRange(200, rat2->FindBin(UPPER_EDGE)); }; #else rat2->GetXaxis()->SetRange(200, rat2->FindBin(UPPER_EDGE)); #endif rat2->SetNdivisions(505); rat2->SetLineColor(kRed+ 3); rat2->SetMarkerColor(kRed+3); rat2->SetMarkerSize(1.1); rat2->SetMaximum(+range); rat2->SetMinimum(-range); rat2->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); rat2->GetXaxis()->SetTitle("#bf{m_{H} [GeV]}"); rat2->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->Draw("e2histsame"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[0], "", "", TColor::GetColor(250,202,255), 1001); InitHist (scales[1], "", "", TColor::GetColor(222,90,106), 1001); InitHist (scales[2], "", "", TColor::GetColor(155,152,204), 1001); InitHist (scales[3], "", "", TColor::GetColor(248,206,104), 1001); InitHist(scales[4],"","",kGreen+2,1001); /* InitHist(scales[5],"","",kGreen+2,1001); InitHist(scales[6],"","",kGreen+2,1001); InitHist(scales[7],"","",kGreen+2,1001); */ scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}" ); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}" ); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggHTohhTo2tau2B}" ); /* scales[0]->GetXaxis()->SetBinLabel(6, "#bf{ggAToZhToLLTauTau}"); scales[0]->GetXaxis()->SetBinLabel(7, "#bf{ggAToZhToLLBB}"); scales[0]->GetXaxis()->SetBinLabel(8, "#bf{bbH}" ); */ #endif scales[0]->SetMaximum(+0.5); scales[0]->SetMinimum(-0.5); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); scales[4]->Draw("same"); /* scales[5]->Draw("same"); scales[6]->Draw("same"); */ TH1F* zero_samples = (TH1F*)scales[0]->Clone("zero_samples"); zero_samples->Clear(); zero_samples->SetBinContent(1,0.); zero_samples->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sfit_%s_%s.png" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.pdf" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.eps" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); if(!log || FULLPLOTS) { canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } if((!log && scaled) || FULLPLOTS) { canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } TFile* output = new TFile(TString::Format("%s_%sfit_%s_%s.root", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"), "update"); output->cd(); data ->Write("data_obs"); Fakes->Write("Fakes" ); EWK ->Write("EWK" ); ttbar->Write("ttbar" ); Ztt ->Write("Ztt" ); #ifdef MSSM ggHTohhTo2Tau2B ->Write("ggHTohhTo2Tau2B" ); /* ggAToZhToLLTauTau->Write("ggAToZhToLLTauTau"); ggAToZhToLLBB->Write("ggAToZhToLLBB"); bbH ->Write("bbH" ); */ #endif output->Close(); delete errorBand; delete model; delete test1; delete zero; delete rat1; delete rat2; delete zero_samples; delete ref; }
void HTT_EE_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="ee_$CATEGORY") { // define common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category = ""; const char* category_extra = ""; const char* category_extra2 = ""; if(std::string(directory) == std::string("ee_0jet_low" )){ category = "ee, 0 jet"; } if(std::string(directory) == std::string("ee_0jet_low" )){ category_extra = "p_{T}(lep1) low"; } if(std::string(directory) == std::string("ee_0jet_high" )){ category = "ee, 0 jet"; } if(std::string(directory) == std::string("ee_0jet_high" )){ category_extra = "p_{T}(lep1) high"; } if(std::string(directory) == std::string("ee_1jet_low" )){ category = "ee, 1 jet"; } if(std::string(directory) == std::string("ee_1jet_low" )){ category_extra = "p_{T}(lep1) low"; } if(std::string(directory) == std::string("ee_1jet_high" )){ category = "ee, 1 jet"; } if(std::string(directory) == std::string("ee_1jet_high" )){ category_extra = "p_{T}(lep1) high"; } if(std::string(directory) == std::string("ee_vbf" )){ category = "ee, 2 jet"; } if(std::string(directory) == std::string("ee_vbf" )){ category_extra = "VBF"; } if(std::string(directory) == std::string("ee_nobtag" )){ category = "ee"; } if(std::string(directory) == std::string("ee_nobtag" )){ category_extra = "No B-Tag"; } if(std::string(directory) == std::string("ee_btag" )){ category = "ee"; } if(std::string(directory) == std::string("ee_btag" )){ category_extra = "B-Tag"; } const char* dataset; if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 19.8 fb^{-1} at 8 TeV";} TFile* input = new TFile(inputfile.c_str()); #ifdef MSSM TFile* input2 = new TFile((inputfile+"_$MA_$TANB").c_str()); #endif TH1F* ZTT = refill((TH1F*)input ->Get(TString::Format("%s/ZTT" , directory)), "ZTT" ); InitHist(ZTT , "", "", kOrange - 4, 1001); TH1F* ZEE = refill((TH1F*)input ->Get(TString::Format("%s/ZEE" , directory)), "ZEE" ); InitHist(ZEE , "", "", kAzure + 2, 1001); TH1F* TTJ = refill((TH1F*)input ->Get(TString::Format("%s/TTJ" , directory)), "TTJ" ); InitHist(TTJ , "", "", kBlue - 8, 1001); TH1F* QCD = refill((TH1F*)input ->Get(TString::Format("%s/QCD" , directory)), "QCD" ); InitHist(QCD , "", "", kMagenta - 10, 1001); TH1F* Dibosons= refill((TH1F*)input ->Get(TString::Format("%s/Dibosons", directory)), "Dibosons"); InitHist(Dibosons, "", "", kGreen - 4, 1001); TH1F* WJets = refill((TH1F*)input ->Get(TString::Format("%s/WJets" , directory)), "WJets" ); InitHist(WJets , "", "", kRed + 2, 1001); #ifdef MSSM TH1F* ggH = refill((TH1F*)input2->Get(TString::Format("%s/ggH$MA" , directory)), "ggH" ); InitSignal(ggH); ggH->Scale($TANB); TH1F* bbH = refill((TH1F*)input2->Get(TString::Format("%s/bbH$MA" , directory)), "bbH" ); InitSignal(bbH); bbH->Scale($TANB); #else #ifndef DROP_SIGNAL TH1F* ggH = refill((TH1F*)input ->Get(TString::Format("%s/ggH125" , directory)), "ggH" ); InitSignal(ggH); ggH->Scale(SIGNAL_SCALE); TH1F* qqH = refill((TH1F*)input ->Get(TString::Format("%s/qqH125" , directory)), "qqH" ); InitSignal(qqH); qqH->Scale(SIGNAL_SCALE); TH1F* VH = refill((TH1F*)input ->Get(TString::Format("%s/VH125" , directory)), "VH" ); InitSignal(VH ); VH ->Scale(SIGNAL_SCALE); #endif #endif #ifdef ASIMOV TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs_asimov", directory)), "data", true); #else TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); #endif #ifdef MSSM InitHist(data, "#bf{m_{#tau#tau} [GeV]}" , "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data); #else InitHist(data, "#bf{D}", "#bf{dN/dD}" ); InitData(data); #endif TH1F* ref=(TH1F*)ZTT->Clone("ref"); ref->Add(ZEE); ref->Add(TTJ); ref->Add(QCD); ref->Add(Dibosons); ref->Add(WJets); double unscaled[9]; unscaled[0] = ZTT->Integral(); unscaled[1] = ZEE->Integral(); unscaled[2] = TTJ->Integral(); unscaled[3] = QCD->Integral(); unscaled[4] = Dibosons->Integral(); unscaled[5] = WJets->Integral(); #ifdef MSSM unscaled[6] = ggH->Integral(); unscaled[7] = bbH->Integral(); unscaled[8] = 0; #else #ifndef DROP_SIGNAL unscaled[6] = ggH->Integral(); unscaled[7] = qqH->Integral(); unscaled[8] = VH ->Integral(); #endif #endif if(scaled){ rescale(ZTT, 1); rescale(ZEE, 2); rescale(TTJ, 3); rescale(QCD, 4); rescale(Dibosons, 5); rescale(WJets, 6); #ifdef MSSM rescale(ggH, 7); rescale(bbH, 8); #else #ifndef DROP_SIGNAL rescale(ggH, 7); rescale(qqH, 8); rescale(VH, 9); #endif #endif } TH1F* scales[9]; scales[0] = new TH1F("scales-ZTT", "", 9, 0, 9); scales[0]->SetBinContent(1, unscaled[0]>0 ? (ZTT->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-ZEE" , "", 9, 0, 9); scales[1]->SetBinContent(2, unscaled[1]>0 ? (ZEE->Integral()/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-TTJ", "", 9, 0, 9); scales[2]->SetBinContent(3, unscaled[2]>0 ? (TTJ->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-QCD" , "", 9, 0, 9); scales[3]->SetBinContent(4, unscaled[3]>0 ? (QCD->Integral()/unscaled[3]-1.) : 0.); scales[4] = new TH1F("scales-Dibosons", "", 9, 0, 9); scales[4]->SetBinContent(5, unscaled[4]>0 ? (Dibosons->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-WJets" , "", 9, 0, 9); scales[5]->SetBinContent(6, unscaled[5]>0 ? (WJets->Integral()/unscaled[5]-1.) : 0.); #ifdef MSSM scales[6] = new TH1F("scales-ggH" , "", 9, 0, 9); scales[6]->SetBinContent(7, unscaled[6]>0 ? (ggH->Integral()/unscaled[6]-1.) : 0.); scales[7] = new TH1F("scales-bbH" , "", 9, 0, 9); scales[7]->SetBinContent(8, unscaled[7]>0 ? (bbH->Integral()/unscaled[7]-1.) : 0.); scales[8] = new TH1F("scales-NONE" , "", 9, 0, 9); scales[8]->SetBinContent(9, 0.); #else #ifndef DROP_SIGNAL scales[6] = new TH1F("scales-ggH" , "", 9, 0, 9); scales[6]->SetBinContent(7, unscaled[6]>0 ? (ggH->Integral()/unscaled[4]-1.) : 0.); scales[7] = new TH1F("scales-qqH" , "", 9, 0, 9); scales[7]->SetBinContent(8, unscaled[7]>0 ? (qqH->Integral()/unscaled[5]-1.) : 0.); scales[8] = new TH1F("scales-VH" , "", 9, 0, 9); scales[8]->SetBinContent(9, unscaled[8]>0 ? (VH ->Integral()/unscaled[6]-1.) : 0.); #endif #endif WJets->Add(Dibosons); QCD->Add(WJets); TTJ->Add(QCD); ZTT->Add(TTJ); ZEE->Add(ZTT); if(log){ #ifdef MSSM ggH ->Add(bbH); #else #ifndef DROP_SIGNAL qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } else{ #ifdef MSSM bbH ->Add(WJets); ggH ->Add(bbH); #else #ifndef DROP_SIGNAL VH ->Add(WJets); qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } /* mass plot before and after fit */ TCanvas* canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(345)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(UPPER_EDGE)); }; #else data->GetXaxis()->SetRange(0, data->FindBin(345)); #endif data->SetNdivisions(505); data->SetMinimum(min); #ifndef DROP_SIGNAL data->SetMaximum(max>0 ? max : std::max(std::max(maximum(data, log), maximum(ZTT, log)), maximum(ggH, log))); #else data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(ZTT, log))); #endif data->Draw("e"); TH1F* errorBand = (TH1F*)ZEE ->Clone("errorBand"); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(1); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } if(log){ ZEE->Draw("histsame"); ZTT->Draw("histsame"); TTJ->Draw("histsame"); QCD->Draw("histsame"); WJets->Draw("histsame"); //Dibosons->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL ggH->Draw("histsame"); #endif } else{ #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif ZEE->Draw("histsame"); ZTT->Draw("histsame"); TTJ->Draw("histsame"); QCD->Draw("histsame"); WJets->Draw("histsame"); //Dibosons->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{e}#tau_{e}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); TPaveText* chan = new TPaveText(0.20, (category_extra2 && category_extra2[0]=='\0') ? 0.65+0.061 : 0.65+0.061, 0.32, 0.75+0.161, "tlbrNDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(category); chan->AddText(category_extra); chan->AddText(category_extra2); chan->Draw(); /* TPaveText* cat = new TPaveText(0.20, 0.71+0.061, 0.32, 0.71+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); */ #ifdef MSSM TPaveText* massA = new TPaveText(0.55, 0.50+0.061, 0.95, 0.50+0.161, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("m^{h}_{max} (m_{A}=$MA GeV, tan#beta=$TANB)"); massA->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.55, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(ggH , "#phi#rightarrow#tau#tau" , "L" ); #else TLegend* leg = new TLegend(0.50, 0.65, 0.95, 0.90); SetLegendStyle(leg); #ifndef DROP_SIGNAL if(SIGNAL_SCALE!=1){ leg->AddEntry(ggH , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" ); } else{ leg->AddEntry(ggH , "H(125 GeV)#rightarrow#tau#tau" , "L" ); } #endif #endif #ifdef ASIMOV leg->AddEntry(data , "sum(bkg) + H(125)" , "LP"); #else leg->AddEntry(data , "observed" , "LP"); #endif leg->AddEntry(ZEE , "Z#rightarrowee" , "F" ); leg->AddEntry(ZTT , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(TTJ , "t#bar{t}" , "F" ); leg->AddEntry(QCD , "QCD" , "F" ); leg->AddEntry(WJets, "electroweak" , "F" ); //leg->AddEntry(Dibosons , "Dibosons" , "F" ); $ERROR_LEGEND leg->Draw(); /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* model = (TH1F*)ZEE ->Clone("model"); TH1F* test1 = (TH1F*)data->Clone("test1"); for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){ //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01); model->SetBinError (ibin+1, CONVERVATIVE_CHI2 ? 0. : model->GetBinError (ibin+1)*model->GetBinWidth(ibin+1)); test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1)); test1->SetBinError (ibin+1, test1->GetBinError (ibin+1)*test1->GetBinWidth(ibin+1)); } double chi2prob = test1->Chi2Test (model,"PUW"); std::cout << "chi2prob:" << chi2prob << std::endl; double chi2ndof = test1->Chi2Test (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl; double ksprob = test1->KolmogorovTest(model); std::cout << "ksprob :" << ksprob << std::endl; double ksprobpe = test1->KolmogorovTest(model,"DX"); std::cout << "ksprobpe:" << ksprobpe << std::endl; std::vector<double> edges; TH1F* zero = (TH1F*)ref ->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat1"); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ rat1->SetBinContent(ibin+1, ZEE->GetBinContent(ibin+1)>0 ? data->GetBinContent(ibin+1)/ZEE->GetBinContent(ibin+1) : 0); rat1->SetBinError (ibin+1, ZEE->GetBinContent(ibin+1)>0 ? data->GetBinError (ibin+1)/ZEE->GetBinContent(ibin+1) : 0); zero->SetBinContent(ibin+1, 0.); zero->SetBinError (ibin+1, ZEE->GetBinContent(ibin+1)>0 ? ZEE ->GetBinError (ibin+1)/ZEE->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } } float range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+range); rat1->SetMinimum(-range); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); #ifdef MSSM rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); #else rat1->GetXaxis()->SetTitle("#bf{D}"); #endif rat1->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->SetMarkerSize(0.1); zero->Draw("e2histsame"); canv0->RedrawAxis(); TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC"); stat1->SetBorderSize( 0 ); stat1->SetFillStyle( 0 ); stat1->SetTextAlign( 12 ); stat1->SetTextSize ( 0.05 ); stat1->SetTextColor( 1 ); stat1->SetTextFont ( 62 ); stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f", chi2ndof, chi2prob)); //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f, P(KS)=%.3f", chi2ndof, chi2prob, ksprob)); stat1->Draw(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); edges.clear(); TH1F* rat2 = (TH1F*) ZEE->Clone("rat2"); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ rat2->SetBinContent(ibin+1, ref->GetBinContent(ibin+1)>0 ? ZEE->GetBinContent(ibin+1)/ref->GetBinContent(ibin+1) : 0); rat2->SetBinError (ibin+1, ref->GetBinContent(ibin+1)>0 ? ZEE->GetBinError (ibin+1)/ref->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat2->GetBinContent(ibin+1)-1.)+TMath::Abs(rat2->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } #if defined MSSM if(!log){ rat2->GetXaxis()->SetRange(0, rat2->FindBin(345)); } else{ rat2->GetXaxis()->SetRange(0, rat2->FindBin(UPPER_EDGE)); }; #else rat2->GetXaxis()->SetRange(0, rat2->FindBin(345)); #endif rat2->SetNdivisions(505); rat2->SetLineColor(kRed+ 3); rat2->SetMarkerColor(kRed+3); rat2->SetMarkerSize(1.1); rat2->SetMaximum(+range); rat2->SetMinimum(-range); rat2->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); #if defined MSSM rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); #else rat2->GetXaxis()->SetTitle("#bf{D}"); #endif rat2->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->Draw("e2histsame"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[0], "", "", kOrange - 4, 1001); InitHist (scales[1], "", "", kAzure + 2, 1001); InitHist (scales[2], "", "", kBlue - 8, 1001); InitHist (scales[3], "", "", kMagenta - 10, 1001); InitHist (scales[4], "", "", kGreen - 4, 1001); InitHist (scales[5], "", "", kRed + 2, 1001); #ifndef DROP_SIGNAL InitSignal(scales[6]); InitSignal(scales[7]); InitSignal(scales[8]); #endif scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{ZTT}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{ZEE}" ); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{TTJ}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{QCD}" ); scales[0]->GetXaxis()->SetBinLabel(5, "#bf{Dibosons}"); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{WJets}" ); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(7, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(8, "#bf{bbH}" ); scales[0]->GetXaxis()->SetBinLabel(9, "#bf{NONE}" ); #else scales[0]->GetXaxis()->SetBinLabel(7, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(8, "#bf{qqH}" ); scales[0]->GetXaxis()->SetBinLabel(9, "#bf{VH}" ); #endif scales[0]->SetMaximum(+0.5); scales[0]->SetMinimum(-0.5); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); scales[4]->Draw("same"); scales[5]->Draw("same"); #ifndef DROP_SIGNAL scales[6]->Draw("same"); scales[7]->Draw("same"); scales[8]->Draw("same"); #endif TH1F* zero_samples = (TH1F*)scales[0]->Clone("zero_samples"); zero_samples->Clear(); zero_samples->SetBinContent(1,0.); zero_samples->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sfit_%s_%s.png" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.pdf" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.eps" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); if(log || FULLPLOTS) { canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } if((log && scaled) || FULLPLOTS) { canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } TFile* output = new TFile(TString::Format("%s_%sfit_%s_%s.root", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"), "update"); output->cd(); data ->Write("data_obs"); ZTT->Write("Ztt" ); ZEE->Write("Zee" ); TTJ->Write("ttbar"); QCD->Write("Fakes"); Dibosons->Write("Dibosons"); WJets->Write("EWK"); #ifdef MSSM ggH ->Write("ggH"); bbH ->Write("bbH"); #else #ifndef DROP_SIGNAL ggH ->Write("ggH"); qqH ->Write("qqH"); VH ->Write("VH" ); #endif #endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); delete errorBand; delete model; delete test1; delete zero; delete rat1; delete rat2; delete zero_samples; delete ref; }
void draw_RFB_pt_mergedBin(bool sysByHand=false, bool noPtWeight=false, bool isPrompt=false) { gROOT->Macro("./tdrstyle_kyo.C"); //cmsTextFont = 42; // for b.hong //extraTextFont = 42; // for b.hong int isPA = 1; // 0:pp, 1:pPb //int iPos=0; //outside topleft int iPos=33; //right corner //// BR and lumi info. const Double_t br = 0.0593 ; const Double_t brErr = 0.0006; const Double_t pPb_lumi_nb = 34.622; // 34.6/nb const Double_t pPb_lumi_nb_err = 1.211; // 3.5 % const Double_t pPb_lumi_mub = pPb_lumi_nb * 1000; // (nb)^{-1} -> {#mub}^{-1} const Double_t pPb_lumi_mub_err = pPb_lumi_nb_err * 1000; // (nb)^{-1} -> {#mub}^{-1} ///////////////////////////////////////////////////////////////////////// // bin center & systematic uncertainties by hand // for 1.5 - 1.93 const int nRap = 8; const int nPt = 9; const int nRapTmp = nRap + 1; const int nPtTmp = nPt + 1; const int nRapRFB = 3; const int nPtRFB = 3; Double_t pxtmp[nRapRFB][nPtRFB]; //x point to fill remporarily Double_t pytmp[nRapRFB][nPtRFB]; //y point to fill remporarily Double_t eytmp[nRapRFB][nPtRFB]; //y point error to fill remporarily /// 2015 PAS Double_t px[nRapRFB][nPtRFB] = { // x point (mean pT) {5.75945, 7.90077, 13.2826}, //1.5-1.93 {-531, 7.98106, 13.2588}, //0.9-1.5 {-531, 8.2616, 13.5598} //0.0-0.9 }; Double_t ex[nPtRFB] = {0.,0.,0.}; // x stat error (0) Double_t exlow[nRapRFB][nPtRFB]; Double_t exhigh[nRapRFB][nPtRFB]; //Double_t exsys[nPtRFB] = {0.25,0.25,0.25}; // x sys err (box width) Double_t exsys[nPtRFB] = {0.3,0.3,0.3}; // x sys err (box width) Double_t eysys[nRapRFB][nPtRFB]; //absolute y sys error //Double_t eysysrel[nRapRFB][nPtRFB]; //relative y sys error /* Double_t eysysrelPR[nRapRFB][nPtRFB] = { {0.04529, 0.04795, 0.06486}, //1.5-1.03 {0.00, 0.04245, 0.03360}, //0.9-1.5 {0.00, 0.04694, 0.03705} //0.0-0.9 }; Double_t eysysrelNP[nRapRFB][nPtRFB] = { {0.06133, 0.10487, 0.09280}, {0.00, 0.06288, 0.05592}, {0.00, 0.07412, 0.04483} }; for (int iy=0; iy<nRapRFB; iy++){ for (int ipt=0; ipt<nPtRFB; ipt++){ if(isPrompt) eysysrel[iy][ipt] = eysysrelPR[iy][ipt]; else eysysrel[iy][ipt] = eysysrelNP[iy][ipt]; } } */ //// 1) y_CM array (from forward to backward) Double_t rapArrNumFB[nRapTmp] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87};// for pt dist. //Double_t rapArrNumBF[nRapTmp] = {-2.87, -2.4, -1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist. Double_t rapBinW[nRap]; for (Int_t iy=0; iy<nRap; iy++) { rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1]; //cout << iy <<"th rapBinW = " << rapBinW[iy] <<endl; } //// 2) pt array Double_t ptArrNum[nPtTmp] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10., 14., 30.}; Double_t ptBinW[nPt]; for (Int_t ipt=0; ipt<nPt; ipt++) { ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt]; //cout << ipt <<"th ptBinW = " << ptBinW[ipt] <<endl; } //// array string TString rapArr[nRap]; for (Int_t iy=0; iy<nRap; iy++) { formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]); cout << iy <<"th rapArr = " << rapArr[iy] << endl; } TString ptArr[nPt]; for (Int_t ipt=0; ipt<nPt; ipt++) { formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]); cout << ipt <<"th ptArr = " << ptArr[ipt] << endl; } ////////////////////////////////////////////////////////////// //// read-in sys. file TFile * fSys; if (isPA==0) fSys = new TFile("../TotalSys/TotSys_8rap9pt_pp_etOpt0.root"); else fSys = new TFile("../TotalSys/TotSys_8rap9pt_pA_etOpt0.root"); TH2D* h2D_SysErr; if (isPrompt) h2D_SysErr = (TH2D*)fSys->Get("hTotalPR"); else h2D_SysErr = (TH2D*)fSys->Get("hTotalNP"); // cout << " *** h2D_SysErr = " << h2D_SysErr << endl; ///////////////////////////////////////////////////////////////////////// //// read-in file TFile * f2D; if (noPtWeight) f2D = new TFile("../FittingResult/totalHist_pA_8rap9pt_newcut_nominal_Zvtx1_SF1_etOpt0_noPtWeight.root"); else f2D = new TFile("../FittingResult/totalHist_pA_8rap9pt_newcut_nominal_Zvtx1_SF1_etOpt0.root"); //// read-in 2D hist TH2D* h2D_CorrY; if (isPrompt) h2D_CorrY = (TH2D*)f2D->Get("h2D_CorrY_PR_pA"); else h2D_CorrY = (TH2D*)f2D->Get("h2D_CorrY_NP_pA"); h2D_CorrY->SetName("h2D_CorrY"); const int nbinsX = h2D_CorrY->GetNbinsX(); const int nbinsY = h2D_CorrY->GetNbinsY(); if (nbinsX != nRap) { cout << " *** Error!!! nbinsX != nRap"; return; }; if (nbinsY != nPt) { cout << " *** Error!!! nbinsY != nPt"; return; }; //// projection to 1D hist : iy=0 refers to forwards !!! (ordering here) TH1D* h1D_CorrY[nRap]; TH1D* h1D_SysErr[nRap]; for (Int_t iy = 0; iy < nRap; iy++) { h1D_CorrY[iy] = h2D_CorrY->ProjectionY(Form("h1D_CorrY_%d",iy),iy+1,iy+1); h1D_SysErr[iy] = h2D_SysErr->ProjectionY(Form("h1D_SysErr_%d",iy),iy+1,iy+1); } ////////////////////////////////////////////////////////////////// //// calculate RFB TH1D* h1D_RFB_tmp[nRap]; // CorrYield with merged pT TH1D* h1D_RFB[nRapRFB]; // actual RFB TH1D* h1D_RFBSys_tmp[nRap]; // Sys with merged pT TH1D* h1D_RFBSys[nRapRFB]; // Sys F/B //// RFB bin setting TString rapAbsArr[nRap]; for (Int_t iy=0; iy<nRapRFB; iy++) { formAbsRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapAbsArr[iy]); cout << iy <<"th rapAbsArr = " << rapAbsArr[iy] << endl; } Double_t ptArrRFBNum[nPtRFB+1] = {5.0, 6.5, 10., 30.}; //// ex calculation for (Int_t iy=0; iy<nRapRFB; iy++) { for (Int_t ipt=0; ipt<nPtRFB; ipt++) { exlow[iy][ipt] = px[iy][ipt]-ptArrRFBNum[ipt]; exhigh[iy][ipt] = ptArrRFBNum[ipt+1]-px[iy][ipt]; //cout << iy<<"th y, "<<ipt<<"th pt"<<endl; //cout << "exlow = "<< exlow[iy][ipt] << endl; //cout << "exhigh = " <<exhigh[iy][ipt] << endl; } } //// take proper error propagataion for sys (merge pT bins (KYO - byHand)) double tmpsys01, tmpsys02, tmpsys03; double actsys01, actsys02, actsys03; for (int iy=0; iy<nRapRFB*2; iy++){ h1D_RFBSys_tmp[iy]= new TH1D(Form("h1D_RFBSys_tmp_%d",iy),Form("h1D_RFBSys_tmp_%d",iy),nPtRFB,ptArrRFBNum); h1D_RFBSys_tmp[iy]->Sumw2(); actsys01=0; actsys02=0; actsys03=0; //// 1) pT 5-6.5 GeV tmpsys01=0; tmpsys02=0;tmpsys03=0; if (iy==0 || iy==nRapRFB*2-1){ //// from relative error to absolute error //actsys01=h1D_SysErr[iy]->GetBinContent(4); actsys01=h1D_SysErr[iy]->GetBinContent(4)*h1D_CorrY[iy]->GetBinContent(4); h1D_RFBSys_tmp[iy]->SetBinContent(1,actsys01); } else { h1D_RFBSys_tmp[iy]->SetBinContent(1,0.); } //// 2) pT 6.5-10. GeV tmpsys01=0; tmpsys02=0;tmpsys03=0; //// from relative error to absolute error tmpsys01=h1D_SysErr[iy]->GetBinContent(5)*h1D_CorrY[iy]->GetBinContent(5); tmpsys02=h1D_SysErr[iy]->GetBinContent(6)*h1D_CorrY[iy]->GetBinContent(6); tmpsys03=h1D_SysErr[iy]->GetBinContent(7)*h1D_CorrY[iy]->GetBinContent(7); //actsys02=TMath::Sqrt( TMath::Power(tmpsys01,2) + TMath::Power(tmpsys02,2) +TMath::Power(tmpsys03,2) ); actsys02= TMath::Abs(tmpsys01) + TMath::Abs(tmpsys02) +TMath::Abs(tmpsys03) ; h1D_RFBSys_tmp[iy]->SetBinContent(2,actsys02); //// 3) pT 10.-30. GeV tmpsys01=0; tmpsys02=0;tmpsys03=0; //// from relative error to absolute error tmpsys01=h1D_SysErr[iy]->GetBinContent(8)*h1D_CorrY[iy]->GetBinContent(8); tmpsys02=h1D_SysErr[iy]->GetBinContent(9)*h1D_CorrY[iy]->GetBinContent(9); //actsys03=TMath::Sqrt( TMath::Power(tmpsys01,2) + TMath::Power(tmpsys02,2) ); actsys03= TMath::Abs(tmpsys01) + TMath::Abs(tmpsys02) ; h1D_RFBSys_tmp[iy]->SetBinContent(3,actsys03); } //TCanvas *ctmp = new TCanvas("ctmp","",1200,800); ctmp->Divide(3,2); //for (int iy=0; iy<nRapRFB*2; iy++){ // ctmp->cd(iy+1); // h1D_RFBSys_tmp[iy]->Draw(""); //} //// merge pT bins (KYO - byHand) double tmpPRval01, tmpPRerr01, tmpPRval02, tmpPRerr02, tmpPRval03, tmpPRerr03; double actPRval01, actPRerr01, actPRval02, actPRerr02, actPRval03, actPRerr03; for (int iy=0; iy<nRapRFB*2; iy++){ h1D_RFB_tmp[iy]= new TH1D(Form("h1D_RFB_tmp_%d",iy),Form("h1D_RFB_tmp_%d",iy),nPtRFB,ptArrRFBNum); h1D_RFB_tmp[iy]->Sumw2(); actPRval01=0; actPRval02=0; actPRval03=0; actPRerr01=0; actPRerr02=0; actPRerr03=0; //// 1) pT 5-6.5 GeV tmpPRval01=0; tmpPRval02=0;tmpPRval03=0; tmpPRerr01=0; tmpPRerr02=0;tmpPRerr03=0; if (iy==0 || iy==nRapRFB*2-1){ actPRval01=h1D_CorrY[iy]->GetBinContent(4); actPRerr01=h1D_CorrY[iy]->GetBinError(4); h1D_RFB_tmp[iy]->SetBinContent(1,actPRval01); h1D_RFB_tmp[iy]->SetBinError(1,actPRerr01); } else { h1D_RFB_tmp[iy]->SetBinContent(1,0.); h1D_RFB_tmp[iy]->SetBinError(1,0.); } //// 2) pT 6.5-10. GeV tmpPRval01=0; tmpPRval02=0;tmpPRval03=0; tmpPRerr01=0; tmpPRerr02=0;tmpPRerr03=0; tmpPRval01=h1D_CorrY[iy]->GetBinContent(5); tmpPRerr01=h1D_CorrY[iy]->GetBinError(5); tmpPRval02=h1D_CorrY[iy]->GetBinContent(6); tmpPRerr02=h1D_CorrY[iy]->GetBinError(6); tmpPRval03=h1D_CorrY[iy]->GetBinContent(7); tmpPRerr03=h1D_CorrY[iy]->GetBinError(7); actPRval02=tmpPRval01+tmpPRval02+tmpPRval03; actPRerr02=TMath::Sqrt( TMath::Power(tmpPRerr01,2) + TMath::Power(tmpPRerr02,2) +TMath::Power(tmpPRerr03,2) ); h1D_RFB_tmp[iy]->SetBinContent(2,actPRval02); h1D_RFB_tmp[iy]->SetBinError(2,actPRerr02); //// 3) pT 10.-30. GeV tmpPRval01=0; tmpPRval02=0;tmpPRval03=0; tmpPRerr01=0; tmpPRerr02=0;tmpPRerr03=0; tmpPRval01=h1D_CorrY[iy]->GetBinContent(8); tmpPRerr01=h1D_CorrY[iy]->GetBinError(8); tmpPRval02=h1D_CorrY[iy]->GetBinContent(9); tmpPRerr02=h1D_CorrY[iy]->GetBinError(9); actPRval03=tmpPRval01+tmpPRval02; actPRerr03=TMath::Sqrt( TMath::Power(tmpPRerr01,2) + TMath::Power(tmpPRerr02,2) ); h1D_RFB_tmp[iy]->SetBinContent(3,actPRval03); h1D_RFB_tmp[iy]->SetBinError(3,actPRerr03); //for (int ipt=0; ipt<nPtRFB; ipt++){ // cout << iy<<"th rap, pT merged PR CorrYield = " << h1D_RFB_tmp[iy]->GetBinContent(ipt+1) <<endl; //} } ////////////////////////////////////////////////////////////////// //// actual RFB calculation for (int iy=0; iy<nRapRFB; iy++){ h1D_RFB[iy] = (TH1D*)h1D_RFB_tmp[iy]->Clone(Form("h1D_RFB_%d",iy)); h1D_RFB[iy]->Divide(h1D_RFB_tmp[2*nRapRFB-iy-1]); } //// sys F/B calculation Double_t dummy; for (int iy=0; iy<nRapRFB; iy++){ for (int ipt=0; ipt<nPtRFB; ipt++){ //eysysrel[iy][ipt] = TMath::Sqrt(h1D_RFBSys_tmp[iy]->GetBinContent(ipt+1)*h1D_RFBSys_tmp[iy]->GetBinContent(ipt+1)+ h1D_RFBSys_tmp[2*nRapRFB-iy-1]->GetBinContent(ipt+1)*h1D_RFBSys_tmp[2*nRapRFB-iy-1]->GetBinContent(ipt+1)); DivideValue(h1D_RFB_tmp[iy]->GetBinContent(ipt+1),h1D_RFBSys_tmp[iy]->GetBinContent(ipt+1),h1D_RFB_tmp[2*nRapRFB-iy-1]->GetBinContent(ipt+1),h1D_RFBSys_tmp[2*nRapRFB-iy-1]->GetBinContent(ipt+1),&dummy,&eysys[iy][ipt]); //cout << "FW bin = " << h1D_RFBSys_tmp[iy]->GetBinContent(ipt+1) << endl; //cout << "BW bin = " << h1D_RFBSys_tmp[2*nRapRFB-iy-1]->GetBinContent(ipt+1) << endl; //cout << "dummy = " << dummy << endl; //cout << "eysys["<<iy<<"]["<<ipt<<"] = " << eysys[iy][ipt] << endl; } } ////////////////////////////////////////////////////////////////// TLegend *legBR = new TLegend(0.50, 0.18, 0.70, 0.39); SetLegendStyle(legBR); legBR->SetTextSize(0.05); TLatex* globtex = new TLatex(); globtex->SetNDC(); globtex->SetTextAlign(12); //1:left, 2:vertical center //globtex->SetTextAlign(32); //3:right 2:vertical center globtex->SetTextFont(42); globtex->SetTextSize(0.04); //TCanvas* c1 = new TCanvas("c1","c1",600,600); //c1->cd(); ////////////////////////////////////////////////////////////////// //// convert to TGraphAsymErrors const int fw_init = 0; //// 1) sys graph TGraphAsymmErrors*gRFB_sys[nRapRFB]; for (int iy=0; iy<nRapRFB; iy++){ gRFB_sys[iy] = new TGraphAsymmErrors(h1D_RFB[iy]); gRFB_sys[iy] -> SetName(Form("gRFB_sys_%d",iy)); for (int ipt=0; ipt<nPtRFB; ipt++){ gRFB_sys[iy]->GetPoint(ipt, pxtmp[iy][ipt], pytmp[iy][ipt]); gRFB_sys[iy]->SetPoint(ipt, px[iy][ipt], pytmp[iy][ipt]); //// absolute err calculation //eysys[iy][ipt]=eysysrel[iy][ipt]*pytmp[iy][ipt]; //gRFB_sys[iy]->SetPointError(ipt, exsys[ipt], exsys[ipt], eysys[iy][ipt], eysys[iy][ipt]); gRFB_sys[iy]->SetPointError(ipt, exlow[iy][ipt], exhigh[iy][ipt], eysys[iy][ipt], eysys[iy][ipt]); } gRFB_sys[iy]->GetXaxis()->SetTitle("p_{T} (GeV/c)"); gRFB_sys[iy]->GetXaxis()->CenterTitle(); gRFB_sys[iy]->GetYaxis()->SetTitle("R_{FB}"); gRFB_sys[iy]->GetYaxis()->CenterTitle(); gRFB_sys[iy]->GetXaxis()->SetLimits(0.,32.0); gRFB_sys[iy]->SetMinimum(0.0); gRFB_sys[iy]->SetMaximum(1.8); } gRFB_sys[0]->SetFillColorAlpha(kGreen-10,0.5); gRFB_sys[1]->SetFillColorAlpha(kRed-10,0.5); gRFB_sys[2]->SetFillColorAlpha(kBlue-10,0.5); gRFB_sys[0]->SetLineColor(kGreen+3); gRFB_sys[1]->SetLineColor(kPink-6); gRFB_sys[2]->SetLineColor(kBlue-3); //// 2) RFB graph TGraphAsymmErrors*gRFB[nRapRFB]; for (int iy=0; iy<nRapRFB; iy++){ gRFB[iy] = new TGraphAsymmErrors(h1D_RFB[iy]); gRFB[iy] -> SetName(Form("gRFB_%d",iy)); cout << "::: for excel ::: iy= " << iy << endl; for (int ipt=0; ipt<nPtRFB; ipt++){ gRFB[iy]->GetPoint(ipt, pxtmp[iy][ipt], pytmp[iy][ipt]); eytmp[iy][ipt] = gRFB[iy]-> GetErrorY(ipt); gRFB[iy]->SetPoint(ipt, px[iy][ipt], pytmp[iy][ipt]); gRFB[iy]->SetPointEXlow(ipt, ex[iy]); gRFB[iy]->SetPointEXhigh(ipt, ex[iy]); cout << pytmp[iy][ipt] <<"\t"<<eytmp[iy][ipt] << "\t "<<eysys[iy][ipt]<<endl; } } SetGraphStyleFinal(gRFB[0], 0, 5); //1.5-1.93 SetGraphStyleFinal(gRFB[1], 1, 3); //0.9-1.5 SetGraphStyleFinal(gRFB[2], 2, 0); //0-0.9 gRFB[0]->SetMarkerSize(2.6); gRFB[1]->SetMarkerSize(1.4); gRFB[2]->SetMarkerSize(1.4); ///////////////// CANVAS 1 TCanvas* c1 = new TCanvas("c1","c1",600,600); c1->cd(); gRFB_sys[0]->Draw("A5"); solidLine(0.,1.,32.,1.,1,1); gRFB[0]->Draw("P"); TLegendEntry *le1=legBR->AddEntry("le1",Form(" %s", rapAbsArr[2].Data()),"lpf"); le1->SetFillColorAlpha(kBlue-10,0.5); le1->SetFillStyle(1001); le1->SetLineColor(kBlue-3); le1->SetMarkerStyle(kFullCircle); le1->SetMarkerColor(kBlue-3); le1->SetMarkerSize(2.1); TLegendEntry *le2=legBR->AddEntry("le2",Form(" %s", rapAbsArr[1].Data()),"lpf"); le2->SetFillColorAlpha(kRed-10,0.5); le2->SetFillStyle(1001); le2->SetLineColor(kPink-6); le2->SetMarkerStyle(kFullSquare); le2->SetMarkerColor(kPink-6); le2->SetMarkerSize(2.1); TLegendEntry *le3=legBR->AddEntry("le3",Form(" %s", rapAbsArr[0].Data()),"lpf"); le3->SetFillColorAlpha(kGreen-10,0.5); le3->SetFillStyle(1001); le3->SetLineColor(kGreen+3); le3->SetMarkerStyle(kFullDiamond); le3->SetMarkerColor(kGreen+3); le3->SetMarkerSize(3.3); //legBR->Draw(); globtex->SetTextAlign(32); //3:right 2:vertical center globtex->SetTextFont(42); globtex->SetTextSize(0.05); globtex->DrawLatex(0.9, 0.23, rapAbsArr[0].Data()); globtex->SetTextAlign(12); //1:left, 2:vertical center globtex->SetTextSize(0.055); globtex->SetTextFont(42); if (isPrompt) globtex->DrawLatex(0.21, 0.84, "Prompt J/#psi"); else globtex->DrawLatex(0.21, 0.84, "Nonprompt J/#psi"); CMS_lumi( c1, isPA, iPos ); c1->Update(); if (noPtWeight) { c1->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight_rap1.pdf",(int)isPrompt)); c1->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight_rap1.png",(int)isPrompt)); } else { c1->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_rap1.pdf",(int)isPrompt)); c1->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_rap1.png",(int)isPrompt)); } ///////////////// CANVAS 2 TCanvas* c2 = new TCanvas("c2","c2",600,600); c2->cd(); gRFB_sys[1]->Draw("A5"); solidLine(0.,1.,32.,1.,1,1); gRFB[1]->Draw("P"); //legBR->Draw(); globtex->SetTextAlign(32); //3:right 2:vertical center globtex->SetTextFont(42); globtex->SetTextSize(0.05); globtex->DrawLatex(0.9, 0.23, rapAbsArr[1].Data()); globtex->SetTextAlign(12); //1:left, 2:vertical center globtex->SetTextSize(0.055); globtex->SetTextFont(42); if (isPrompt) globtex->DrawLatex(0.21, 0.84, "Prompt J/#psi"); else globtex->DrawLatex(0.21, 0.84, "Nonprompt J/#psi"); CMS_lumi( c2, isPA, iPos ); c2->Update(); if (noPtWeight) { c2->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight_rap2.pdf",(int)isPrompt)); c2->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight_rap2.png",(int)isPrompt)); } else { c2->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_rap2.pdf",(int)isPrompt)); c2->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_rap2.png",(int)isPrompt)); } ///////////////// CANVAS 3 TCanvas* c3 = new TCanvas("c3","c3",600,600); c3->cd(); gRFB_sys[2]->Draw("A5"); solidLine(0.,1.,32.,1.,1,1); gRFB[2]->Draw("P"); ///legBR->Draw(); globtex->SetTextAlign(32); //3:right 2:vertical center globtex->SetTextFont(42); globtex->SetTextSize(0.05); globtex->DrawLatex(0.9, 0.23, rapAbsArr[2].Data()); globtex->SetTextAlign(12); //1:left, 2:vertical center globtex->SetTextSize(0.055); globtex->SetTextFont(42); if (isPrompt) globtex->DrawLatex(0.21, 0.84, "Prompt J/#psi"); else globtex->DrawLatex(0.21, 0.84, "Nonprompt J/#psi"); CMS_lumi( c3, isPA, iPos ); c3->Update(); if (noPtWeight) { c3->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight_rap3.pdf",(int)isPrompt)); c3->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight_rap3.png",(int)isPrompt)); } else { c3->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_rap3.pdf",(int)isPrompt)); c3->SaveAs(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_rap3.png",(int)isPrompt)); } /////////////////////////////////////////////////////////////////// //// save as a root file TFile *outFile; if (noPtWeight) outFile = new TFile(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d_noPtWeight.root",(int)isPrompt),"RECREATE"); else outFile = new TFile(Form("plot_RFB/RFB_pt_mergedBin_isPrompt%d.root",(int)isPrompt),"RECREATE"); outFile->cd(); for (int iy=0; iy<nRapRFB; iy++){ gRFB_sys[iy]->Write(); gRFB[iy]->Write(); } outFile->Close(); return; } // end of main func.
void HBB_HAD_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="bb_$CATEGORY") { // define common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); const char* category_extra = ""; if(std::string(directory) == std::string("bb_had0" )){ category_extra = "all-had_{0}"; } if(std::string(directory) == std::string("bb_had1" )){ category_extra = "all-had_{1}"; } if(std::string(directory) == std::string("bb_had2" )){ category_extra = "all-had_{2}"; } if(std::string(directory) == std::string("bb_had3" )){ category_extra = "all-had_{3}"; } if(std::string(directory) == std::string("bb_had4" )){ category_extra = "all-had_{4}"; } if(std::string(directory) == std::string("bb_had5" )){ category_extra = "all-had_{5}"; } if(std::string(directory) == std::string("bb_lep" )){ category_extra = "semi-lep"; } const char* dataset; if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "Preliminary, #sqrt{s} = 7 TeV, L = 2.7 fb^{-1}";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "Preliminary, #sqrt{s} = 8 TeV, L = 19.4 fb^{-1}";} TFile* input = new TFile(inputfile.c_str()); #ifdef MSSM TFile* input2 = new TFile((inputfile+"_$MA_$TANB").c_str()); #endif TH1F* Bbb = refill((TH1F*)input->Get(TString::Format("%s/Bbb" , directory)), "Bbb"); InitHist(Bbb, "", "", kMagenta-10, 1001); TH1F* Cbb = refill((TH1F*)input->Get(TString::Format("%s/Cbb" , directory)), "Cbb"); InitHist(Cbb, "", "", kRed + 2, 1001); TH1F* Qbb = refill((TH1F*)input->Get(TString::Format("%s/Qbb" , directory)), "Qbb"); InitHist(Qbb, "", "", kBlue - 8, 1001); TH1F* bbB = refill((TH1F*)input->Get(TString::Format("%s/bbB" , directory)), "bbB"); InitHist(bbB, "", "", kOrange - 4, 1001); TH1F* bbX = refill((TH1F*)input->Get(TString::Format("%s/bbX" , directory)), "bbX"); InitHist(bbX, "", "", kViolet - 0, 1001); #ifdef MSSM //float bbHScale = 1.; //ggHScale = ($MSSM_SIGNAL_ggH_xseff_A + $MSSM_SIGNAL_ggH_xseff_hH); //bbHScale = ($MSSM_SIGNAL_bbH_xseff_A + $MSSM_SIGNAL_bbH_xseff_hH); TH1F* bbH = refill((TH1F*)input2->Get(TString::Format("%s/bbH$MA" , directory)), "bbH" ); InitSignal(bbH); bbH->Scale($TANB); //bbH->Scale(bbHScale); #endif #ifdef ASIMOV TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs_asimov", directory)), "data", true); #else TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); #endif InitHist(data, "#bf{m_{b#bar{b}} [GeV]}", "#bf{dN/dm_{b#bar{b}} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)Qbb->Clone("ref"); ref->Add(bbX); ref->Add(Cbb); ref->Add(bbB); ref->Add(Bbb); double unscaled[7]; unscaled[0] = Qbb ->Integral(); unscaled[1] = bbX ->Integral(); unscaled[2] = Cbb ->Integral(); unscaled[3] = bbB ->Integral(); unscaled[4] = Bbb ->Integral(); #ifdef MSSM unscaled[5] = bbH ->Integral(); unscaled[6] = 0; #endif if(scaled){ rescale(Bbb, 1); rescale(bbB, 4); rescale(Cbb, 2); rescale(bbX, 5); rescale(Qbb, 3); #ifdef MSSM rescale(bbH, 6); #endif } TH1F* scales[7]; scales[0] = new TH1F("scales-Qbb", "", 7, 0, 7); scales[0]->SetBinContent(1, unscaled[0]>0 ? (Qbb ->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-bbX" , "", 7, 0, 7); scales[1]->SetBinContent(2, unscaled[1]>0 ? (bbX ->Integral()/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-Cbb", "", 7, 0, 7); scales[2]->SetBinContent(3, unscaled[2]>0 ? (Cbb ->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-bbB" , "", 7, 0, 7); scales[3]->SetBinContent(4, unscaled[3]>0 ? (bbB ->Integral()/unscaled[3]-1.) : 0.); scales[4] = new TH1F("scales-Bbb" , "", 7, 0, 7); scales[4]->SetBinContent(5, unscaled[4]>0 ? (Bbb ->Integral()/unscaled[4]-1.) : 0.); #ifdef MSSM scales[5] = new TH1F("scales-bbH" , "", 7, 0, 7); scales[5]->SetBinContent(6, unscaled[5]>0 ? (bbH ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-NONE" , "", 7, 0, 7); scales[6]->SetBinContent(7, 0.); #endif bbX ->Add(Qbb); Cbb ->Add(bbX); bbB ->Add(Cbb); Bbb ->Add(bbB); if(!log){ #ifdef MSSM bbH ->Add(Bbb); #endif } /* mass plot before and after fit */ TCanvas* canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(1000)); }; #endif data->SetNdivisions(505); data->SetMinimum(min); data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Bbb, log))); data->Draw("e"); TH1F* errorBand = (TH1F*)Bbb ->Clone(); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(1); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); if(log){ Bbb ->Draw("histsame"); bbB ->Draw("histsame"); Cbb ->Draw("histsame"); bbX ->Draw("histsame"); Qbb ->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL bbH ->Draw("histsame"); #endif } else{ #ifndef DROP_SIGNAL bbH ->Draw("histsame"); #endif Bbb ->Draw("histsame"); bbB ->Draw("histsame"); Cbb ->Draw("histsame"); bbX ->Draw("histsame"); Qbb ->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "b#bar{b}", 0.17, 0.835); CMSPrelim(dataset, "", 0.17, 0.835); TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText("b#bar{b}"); chan->Draw(); TPaveText* cat = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); #ifdef MSSM TPaveText* massA = new TPaveText(0.75, 0.48+0.061, 0.85, 0.48+0.161, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("m_{A}=$MA GeV"); massA->Draw(); TPaveText* tanb = new TPaveText(0.75, 0.44+0.061, 0.85, 0.44+0.161, "NDC"); tanb->SetBorderSize( 0 ); tanb->SetFillStyle( 0 ); tanb->SetTextAlign( 12 ); tanb->SetTextSize ( 0.03 ); tanb->SetTextColor( 1 ); tanb->SetTextFont ( 62 ); tanb->AddText("tan#beta=$TANB"); tanb->Draw(); TPaveText* scen = new TPaveText(0.75, 0.40+0.061, 0.85, 0.40+0.161, "NDC"); scen->SetBorderSize( 0 ); scen->SetFillStyle( 0 ); scen->SetTextAlign( 12 ); scen->SetTextSize ( 0.03 ); scen->SetTextColor( 1 ); scen->SetTextFont ( 62 ); scen->AddText("m^{h}_{max}"); scen->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.55, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(bbH , "#phi#rightarrowb#bar{b}" , "L" ); #endif #ifdef ASIMOV leg->AddEntry(data , "sum(bkg) + SM125 GeV signal" , "LP"); #else leg->AddEntry(data , "observed" , "LP"); #endif leg->AddEntry(Bbb, "Bbb" , "F" ); leg->AddEntry(bbB, "bbB" , "F" ); leg->AddEntry(Cbb, "Cbb" , "F" ); leg->AddEntry(bbX, "bbX" , "F" ); leg->AddEntry(Qbb, "Qbb" , "F" ); $ERROR_LEGEND leg->Draw(); //#ifdef MSSM // TPaveText* mssm = new TPaveText(0.69, 0.85, 0.90, 0.90, "NDC"); // mssm->SetBorderSize( 0 ); // mssm->SetFillStyle( 0 ); // mssm->SetTextAlign( 12 ); // mssm->SetTextSize ( 0.03 ); // mssm->SetTextColor( 1 ); // mssm->SetTextFont ( 62 ); // mssm->AddText("(m_{A}=250, tan#beta=5)"); // mssm->Draw(); //#else // TPaveText* mssm = new TPaveText(0.83, 0.85, 0.95, 0.90, "NDC"); // mssm->SetBorderSize( 0 ); // mssm->SetFillStyle( 0 ); // mssm->SetTextAlign( 12 ); // mssm->SetTextSize ( 0.03 ); // mssm->SetTextColor( 1 ); // mssm->SetTextFont ( 62 ); // mssm->AddText("m_{H}=125"); // mssm->Draw(); //#endif /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* zero = (TH1F*)ref ->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat"); rat1->Divide(Bbb); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } zero->SetBinContent(ibin+1, 0.); } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+1.5); rat1->SetMinimum(-1.5); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{b#bar{b}} [GeV]}"); rat1->Draw(); zero->SetLineColor(kBlack); zero->Draw("same"); canv0->RedrawAxis(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); TH1F* rat2 = (TH1F*) Bbb->Clone("rat2"); rat2->Divide(ref); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } rat2->SetLineColor(kRed+ 3); rat2->SetFillColor(kRed-10); rat2->SetMaximum(+0.3); rat2->SetMinimum(-0.3); rat2->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); rat2->GetXaxis()->SetTitle("#bf{m_{b#bar{b}} [GeV]}"); rat2->GetXaxis()->SetRange(0, 28); rat2->Draw(); zero->SetLineColor(kBlack); zero->Draw("same"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[4], "", "", kMagenta-10, 1001); InitHist (scales[2], "", "", kRed + 2, 1001); InitHist (scales[0], "", "", kBlue - 8, 1001); InitHist (scales[3], "", "", kOrange - 4, 1001); InitHist (scales[1], "", "", kViolet - 0, 1001); scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Qbb}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{bbX}"); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{Cbb}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{bbB}"); scales[0]->GetXaxis()->SetBinLabel(5, "#bf{Bbb}"); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}" ); scales[0]->GetXaxis()->SetBinLabel(7, "#bf{NONE}" ); #endif scales[0]->SetMaximum(+1.0); scales[0]->SetMinimum(-1.0); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); scales[4]->Draw("same"); zero->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sfit_%s_%s.png" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sfit_%s_%s.pdf" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sfit_%s_%s.eps" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); if(!log || FULLPLOTS) { canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); } if((!log && scaled) || FULLPLOTS) { canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); } TFile* output = new TFile(TString::Format("%s_%sfit_%s_%s.root", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""), "update"); output->cd(); data ->Write("data_obs"); Qbb ->Write("Qbb" ); bbX ->Write("bbX" ); Cbb ->Write("Cbb" ); bbB ->Write("bbB" ); Bbb ->Write("Bbb" ); #ifdef MSSM bbH ->Write("bbH" ); #endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); }
//szPA = "pp" or "pa" int draw_bkgSubtracted(TString szPA = "pp") { gROOT->Macro("../Style.C"); // read-in root file TFile *fIn = new TFile(Form("dir_muID/%s_muIDvariables_isScaled0.root",szPA.Data())); //// define 1D hist const int nbin[] = {2, 2, 2, 20, 6, 90, 88}; const double minbin[] = {0, 0., 0., 0, 0, -4.5, -22.}; const double maxbin[] = {2, 2., 2., 20, 6, 4.5, 22.}; //// for dashedLine (valid for isScaled) double xmin[] = {1., 1., 1., 6., 1., -0.3, -20.}; double xmax[] = {531., 531., 531., 531., 531., 0.3, 20.}; double ymin[] = {0., 0., 0., 0., 0., 0.00001, 0.00001}; double ymax[] = {1.1, 1.1, 1.1, 0.25, 0.8, 1, 1}; TString histName[] = {"highPurity", "TrkMuArb", "TMOneStaTight", "nTrkWMea", "nPixWMea", "dxy", "dz"}; if (strcmp(szPA,"pa")==0) {histName[0]="isHighPurity";} TString histTitle[] = {"high purity flag", "tracker muon arbitrated flag", "TMOneStationTight flag", "# of trk layers w/ measurement", "# of pixel layers w/ measurement", "dxy (cm)", "dz (cm)"}; const int nHist = sizeof(nbin)/sizeof(int); cout << "nHist = "<<nHist<<endl; TH1D *hMass[nHist]; //mass distibution for yield checks TH1D *hSig[nHist]; // in 2.9 - 3.3 GeV TH1D *hSigSub[nHist]; // Sig - scaledBkg TH1D *hBkg[nHist]; // out of 2.9 - 3.3 GeV TH1D *hPRMC[nHist]; // in 2.9 - 3.3 GeV TCanvas* c1[nHist]; //TLegend *legUR = new TLegend(0.58,0.75,0.88,0.90,NULL,"brNDC"); TLegend *legUR = new TLegend(0.58,0.70,0.88,0.90,NULL,"brNDC"); SetLegendStyle(legUR); TLatex* latex = new TLatex(); latex->SetNDC(); latex->SetTextAlign(12); latex->SetTextFont(42); latex->SetTextSize(0.04); for (int ih=0; ih<nHist; ih++) { hMass[ih] = (TH1D*)fIn->Get(Form("hMass_%s",histName[ih].Data())); hSig[ih] = (TH1D*)fIn->Get(Form("hSig_%s",histName[ih].Data())); hBkg[ih] = (TH1D*)fIn->Get(Form("hBkg_%s",histName[ih].Data())); hPRMC[ih] = (TH1D*)fIn->Get(Form("hPRMC_%s",histName[ih].Data())); //// get yields from mass distributions for scaling double nSig = calculInteg(hMass[ih],2.9,3.3); double nBkg = calculInteg(hMass[ih],2.6,2.9); cout << "1) nBkg = " << nBkg << endl; nBkg += calculInteg(hMass[ih],3.3,3.5); cout << "2 nBkg = " << nBkg << endl; nBkg *= (0.4/0.5); // in 2.9-3.3 double nBkgToSig = nBkg/nSig; cout << ih <<"th hist name = " << histName[ih].Data() << endl; cout << "nSig = " << nSig << endl; cout << "nBkg = " << nBkg << endl; cout << "nBkgToSig = " << nBkgToSig << endl; ////// background subtraction /// 1) subtracted signal hist. hSigSub[ih] = (TH1D*)hSig[ih]->Clone(Form("hSigSub_%s",histName[ih].Data())); /// 2) First, normalized by their integral hSig[ih]->Scale(1/hSig[ih]->Integral()); hSigSub[ih]->Scale(1/hSigSub[ih]->Integral()); hBkg[ih]->Scale(1/hBkg[ih]->Integral()); /// 3) Bkg normalized to nBkgToSig and subtract from the signal hBkg[ih] ->Scale(nBkgToSig); //hBkg[ih] ->Scale(0.4/0.5); hSigSub[ih]->Add(hBkg[ih],-1); /// 4) set zero if BinContent is negative double tmpbin; for (int ibin=0; ibin < hSigSub[ih]->GetNbinsX(); ibin++) { tmpbin = hSigSub[ih]->GetBinContent(ibin+1); if (tmpbin < 0.) {cout << " **** "<<ibin<<"th tmpbin = " << tmpbin<< endl; hSigSub[ih]->SetBinContent(ibin+1,0.);} } /// 5) normalize again by integral hSig[ih]->Scale(1/hSig[ih]->Integral()); hSigSub[ih]->Scale(1/hSigSub[ih]->Integral()); hBkg[ih]->Scale(1/hBkg[ih]->Integral()); hPRMC[ih]->Scale(1/hPRMC[ih]->Integral()); c1[ih] = new TCanvas(Form("c1_%s",histName[ih].Data()),"",600,600); c1[ih]->cd(); if (strcmp(histName[ih],"dxy")==0 || strcmp(histName[ih],"dz")==0) {gPad->SetLogy(1);} else { gPad->SetLogy(0);} SetHistStyle(hSigSub[ih],1,0); SetHistStyle(hBkg[ih],2,10); SetHistStyle(hPRMC[ih],4,0); hPRMC[ih]->SetFillColor(kGreen+9); hPRMC[ih]->SetFillStyle(3003); hPRMC[ih]->SetAxisRange(ymin[ih],ymax[ih],"Y"); hPRMC[ih]->Draw("hist"); hSigSub[ih]->Draw("pe same"); hBkg[ih]->Draw("pe same"); if (ih==nHist-1){ legUR->AddEntry(hSigSub[ih],"RD: Signal","lp"); legUR->AddEntry(hSigSub[ih],"(Bkg subtracted)",""); legUR->AddEntry(hBkg[ih],"RD: Background","lp"); legUR->AddEntry(hPRMC[ih],"MC","f"); legUR->Draw(); } //// line for actual cut regions dashedLine(xmin[ih],ymin[ih],xmin[ih],ymax[ih]); dashedLine(xmax[ih],ymin[ih],xmax[ih],ymax[ih]); //// check integral over cut regions double nsig=-999, nmc=-999, nratio=-999; nsig = calculInteg(hSigSub[ih],xmin[ih],xmax[ih]); nmc = calculInteg(hPRMC[ih],xmin[ih],xmax[ih]); //nratio = nsig/nmc; //nratio = (1.-nsig)/(1.-nmc); nratio = (1.-nmc)/(1.-nsig); cout << "nsig = " << nsig << ", nmc = " << nmc << ", nratio = " << nratio << endl; //latex->DrawLatex(0.16,0.80,"#int_{out}Data/#int_{out}MC"); //latex->DrawLatex(0.16,0.70,Form("= %.3f / %.3f = %.2f",1.-nsig,1.-nmc,nratio)); latex->DrawLatex(0.16,0.80,"#int_{out}MC/#int_{out}Data"); latex->DrawLatex(0.16,0.70,Form("= %.3f / %.3f = %.2f",1.-nmc,1.-nsig,nratio)); c1[ih]->SaveAs(Form("dir_muID/%s_muIDvariables_%s_bkgSubtracted.pdf",szPA.Data(),histName[ih].Data())); } return 0; }
// no ordering in rap (just y_lab) void draw_compRatio(bool isPrompt = true, bool is1st = true, char* dirName02 = "draw_compRatio_newcut", bool isNoError=true) { gROOT->Macro("./JpsiStyle.C"); // --- read-in file // hRatio = f01 / f02 TFile * f01; TFile * f02; char* f01name="old cut"; char* f02name="new cut"; double ratiomin=0.85; double ratiomax=1.45; char* strPrompt; char* str1st; if (isPrompt) strPrompt = "PRMC"; else strPrompt = "NPMC"; if (is1st) str1st = "Pbp"; else str1st = "pPb"; const char* sampleName = Form("%spythia_%s",strPrompt,str1st); cout << "sampleName = " << sampleName << endl; f01 = new TFile(Form("./draw_1D_acc/8rap9pt2gev_%s_AccPt.root",strPrompt)); f02 = new TFile(Form("./draw_1D_acc_newcut/8rap9pt2gev_newcut_%s_AccPt.root",strPrompt)); cout << "sampleName = " << sampleName << endl; // --- read-in tree TTree *tr = (TTree*)f01->Get("tRap"); int nEdge; double rapEdge[531]; TBranch *b_nEdge; TBranch *b_rapEdge; tr->SetBranchAddress("nEdge",&nEdge,&b_nEdge); tr->SetBranchAddress("rapEdge",&rapEdge,&b_rapEdge); cout << "tr entries = " << tr->GetEntries() << endl; for (int ev=0; ev <tr->GetEntries(); ev++){ tr->GetEntry(ev); } cout << "nEdge = " << nEdge << endl; for (Int_t i=0; i< nEdge; i++) { cout << "rapEdge["<<i<<"] = " << rapEdge[i] << endl; } // --- read-in eff hist const int nRap = nEdge -1 ; cout << "nRap = " << nRap << endl; TH1D* h1D_AccPt01[nRap]; TH1D* h1D_AccPt02[nRap]; TH1D *hRatio[nRap]; //f01/f02 TH1D *hRel[nRap]; // (f01-f02)/f02 for (int iy=0; iy < nRap; iy ++){ h1D_AccPt01[iy] = (TH1D*)f01->Get(Form("h1D_AccPt_%d",iy)); h1D_AccPt02[iy] = (TH1D*)f02->Get(Form("h1D_AccPt_%d",iy)); cout << "h1D_AccPt01["<<iy<<"] = " << h1D_AccPt01[iy] << endl; cout << "h1D_AccPt02["<<iy<<"] = " << h1D_AccPt02[iy] << endl; hRatio[iy]=(TH1D*)h1D_AccPt01[iy]->Clone(Form("hRatio_%d",iy)); hRatio[iy]->Divide(h1D_AccPt02[iy]); hRel[iy]=(TH1D*)h1D_AccPt01[iy]->Clone(Form("hRel_%d",iy)); hRel[iy]->Add(h1D_AccPt02[iy],-1); hRel[iy]->Divide(h1D_AccPt02[iy]); } //latex box for beam, rapidity, pT info TLatex* latex = new TLatex(); latex->SetNDC(); latex->SetTextAlign(12); latex->SetTextSize(0.04); ////////////////////////////////////////////////////////////////// // --- Draw histograms TCanvas* c1 = new TCanvas("c1","c1",1600,800); c1->Divide(4,2); // TCanvas* c2 = new TCanvas("c2","c2",1600,800); // c2->Divide(4,2); // TCanvas* c3 = new TCanvas("c3","c3",1600,800); // c3->Divide(4,2); //TLegend *legBR = new TLegend(0.58,0.30,0.85,0.40,NULL,"brNDC"); TLegend *legBR = new TLegend(0.50,0.30,0.80,0.41,NULL,"brNDC"); SetLegendStyle(legBR); for (Int_t iy = 0; iy < nRap; iy++) { //// 1) distributions //c1->cd(); c1->cd(iy+1); SetHistStyle(h1D_AccPt01[iy],3,0); //SetHistStyle(h1D_AccPt02[iy],4,0); SetHistStyle(h1D_AccPt02[iy],4,10); h1D_AccPt01[iy]->GetXaxis()->SetTitle("p_{T} (GeV)"); h1D_AccPt01[iy]->GetYaxis()->SetTitle("Acceptance"); h1D_AccPt01[iy]->SetMinimum(0.); h1D_AccPt01[iy]->SetMaximum(1.); h1D_AccPt01[iy]->GetXaxis()->SetRangeUser(0., 30.); h1D_AccPt01[iy]->Draw("pe"); h1D_AccPt02[iy]->Draw("pe same"); if (is1st) { if (iy==0 || iy==7) dashedLine (2.,0.,2.,1.,2,.8); else if (iy==1 || iy==6) dashedLine (3.,0.,3.,1.,2,.8); else if (iy==5) dashedLine (5.,0.,5.,1.,2,.8); else if (iy==2 || iy==3 || iy==4) dashedLine (6.5,0.,6.5,1.,2,.8); } else { if (iy==0 || iy==7) dashedLine (2.,0.,2.,1.,2,.8); else if (iy==1 || iy==6) dashedLine (3.,0.,3.,1.,2,.8); else if (iy==2) dashedLine (5.,0.,5.,1.,2,.8); else if (iy==3 || iy==4 || iy==5) dashedLine (6.5,0.,6.5,1.,2,.8); } latex->DrawLatex(0.53,0.25,sampleName); latex->DrawLatex(0.53,0.19,Form("%.2f < y_{lab} < %.2f",rapEdge[iy],rapEdge[iy+1])); if (iy==0) { // legBR->AddEntry(h1D_AccPt01[iy],f01name,"lp"); // legBR->AddEntry(h1D_AccPt02[iy],f02name,"lp"); // legBR->Draw(); } //c1->SaveAs(Form("%s/%s_compEff_%d.pdf",dirName02,sampleName,iy)); //legBR->Clear(); //c1->Clear(); /* //// 2) ratio f01/f02 //c2->cd(); c2->cd(iy+1); SetHistStyle(hRatio[iy],5,0); hRatio[iy]->GetXaxis()->SetTitle("p_{T} (GeV)"); hRatio[iy]->GetYaxis()->SetTitle(Form("[ %s ]/[ %s ]",f01name,f02name)); hRatio[iy]->SetMinimum(ratiomin); hRatio[iy]->SetMaximum(ratiomax); hRatio[iy]->GetXaxis()->SetRangeUser(0.,30.); if (isNoError) { for (int ipt=0; ipt<9; ipt++) { hRatio[iy]->SetBinError(ipt+1,0.); } } hRatio[iy]->Draw("pe"); dashedLine(0.,1.,30.,1.,1,.8); if (is1st) { if (iy==0 || iy==7) dashedLine (2.,ratiomin,2.,ratiomax,2,.8); else if (iy==1 || iy==6) dashedLine (3.,ratiomin,3.,ratiomax,2,.8); else if (iy==5) dashedLine (5.,ratiomin,5.,ratiomax,2,.8); else if (iy==2 || iy==3 || iy==4) dashedLine (6.5,ratiomin,6.5,ratiomax,2,.8); } else { if (iy==0 || iy==7) dashedLine (2.,ratiomin,2.,ratiomax,2,.8); else if (iy==1 || iy==6) dashedLine (3.,ratiomin,3.,ratiomax,2,.8); else if (iy==2) dashedLine (5.,ratiomin,5.,ratiomax,2,.8); else if (iy==3 || iy==4 || iy==5) dashedLine (6.5,ratiomin,6.5,ratiomax,2,.8); } latex->DrawLatex(0.53,0.25,sampleName); latex->DrawLatex(0.53,0.19,Form("%.2f < y_{lab} < %.2f",rapEdge[iy],rapEdge[iy+1])); //c2->SaveAs(Form("%s/%s_compRatio_%d.pdf",dirName02,sampleName,iy)); //c2->Clear(); //// 3) relative (f01-f02)/f02 //c3->cd(); c3->cd(iy+1); SetHistStyle(hRel[iy],5,0); hRel[iy]->GetXaxis()->SetTitle("p_{T} (GeV)"); hRel[iy]->GetYaxis()->SetTitle(Form("(%s-%s) / %s",f01name,f02name,f02name)); hRel[iy]->SetMinimum(relmin); hRel[iy]->SetMaximum(relmax); hRel[iy]->Draw("pe"); dashedLine(0.,0.,30.,0.,1,.8); if (iy==1 || iy==6) dashedLine (3.,relmin,3.,relmax,2,.8); else if (iy==2) dashedLine (5.,relmin,5.,relmax,2,.8); else if (iy==3 || iy==4 || iy==5) dashedLine (6.5,relmin,6.5,relmax,2,.8); latex->DrawLatex(0.53,0.25,sampleName); latex->DrawLatex(0.53,0.19,Form("%.2f < y_{lab} < %.2f",rapEdge[iy],rapEdge[iy+1])); //c3->SaveAs(Form("%s/%s_compRel_%d.pdf",dirName02,sampleName,iy)); //c3->Clear(); */ } c1->SaveAs(Form("%s/%s_compAcc.pdf",dirName02,strPrompt)); // c2->SaveAs(Form("%s/%s_compRatio.pdf",dirName02,strPrompt)); // c3->SaveAs(Form("%s/%s_compRel.pdf",dirName02,sampleName)); return; }
int cndr_rootAna_meanPt_wBkg_2(TString szPA="pa", bool isSmall=true){ //int rootAna_muIDvariables(TString szPA = "pa", bool isScaled = true, bool isSmall =true){ //const int nbin = 100; //arbitrary binning for each pT hist. const int nbin = 20; //arbitrary binning for each pT hist. const int nEntry = 10000; gROOT->Macro("../Style.C"); //// read-in root file TFile *fData; TFile *fPRMC; TTree *treeData; TTree *treePRMC; if (strcmp(szPA,"pp")==0) { fData = new TFile("/storage/OniaTree/Onia5TeV/ppData/OniaTree_DoubleMu_Run2015E-PromptReco-v1_Run_262157_262328_noCUT_TRKMU.root"); fPRMC = new TFile("/storage/OniaTree/Onia5TeV/ppOfficialMC/OniaTree_JpsiMM_5p02TeV_TuneCUETP8M1_Trk_HINppWinter16DR-75X_mcRun2_asymptotic_ppAt5TeV_v3-v1.root"); treeData = (TTree*)fData->Get("hionia/myTree"); treePRMC = (TTree*)fPRMC->Get("hionia/myTree"); } else if (strcmp(szPA,"pa")==0) { fData = new TFile("/home/songkyo/kyo/pPbDataSample/Data/RD2013_pa_1st_run_210676-211256_GR_P_V43D_nocut.root"); fPRMC = new TFile("/home/songkyo/kyo/pPbDataSample/EfficiencySample/MCJPsiWithFSR_pa_1st_run_STARTHI53_V27_ext1_nocut.root"); treeData = (TTree*)fData->Get("myTree"); treePRMC = (TTree*)fPRMC->Get("myTree"); } else { cout << "WARNING :: Select among szPA = \"pp\" or \"pa\" "; return 0; } ///////////////////////////////////////////////////////////// ////////////// binning Double_t ptArr[] = {2.0, 3.0, 4.0, 5.0, 6.5, 7.5, 8.5, 10.0, 14.0, 30.0}; // 8rap9pt const Int_t nPt = sizeof(ptArr)/sizeof(double)-1; cout << "nPt=" << nPt << endl; //// in Ycm (will be change to 1st lab and 2nd lab later) const int nRap = 1; const int nRapTmp = nRap+1; Double_t yArr[nRapTmp] = {0.9, 0.0}; //Double_t yArr[] = {2.4, 1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4}; // 8rap9pt pp //Double_t yArr[] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93, -2.4, -2.87}; // 8rap9pt pA //const Int_t nRap = sizeof(yArr)/sizeof(double)-1; cout << "nRap=" << nRap << endl; TString rapstrArr[nRap]; for (int ir=0; ir<nRap; ir++){ formRapArr(yArr[ir+1], yArr[ir], &rapstrArr[ir]); cout << "rap string arr = " << rapstrArr[ir].Data() << endl; } Double_t etArr[] = {0.0, 120.0}; // 8rap9pt //Double_t etArr[] = {0.0, 20., 30., 120.0}; // ethf const Int_t nEt = sizeof(etArr)/sizeof(double)-1; cout << "nEt=" << nEt << endl; TString etstrArr[nEt]; for (int in=0; in<nEt; in++){ formEtArr(etArr[in], etArr[in+1], &etstrArr[in]); cout << "et string arr = " << etstrArr[in].Data() << endl; } ///////////////////////////////////////////////////////////// //// cut definitions TCut trigCut = "((Reco_QQ_trig&1)==1 && (HLTriggers&1)==1 )"; TCut recoPairCut = "Reco_QQ_sign==0 && Reco_QQ_VtxProb > 0.01"; TCut massNarrow = "Reco_QQ_4mom.M() >2.9 && Reco_QQ_4mom.M() < 3.3"; TCut massWide = "Reco_QQ_4mom.M() >2.6 && Reco_QQ_4mom.M() < 3.5"; TCut ctauCut = "-1.5 < Reco_QQ_ctau && Reco_QQ_ctau < 3.0 && 0 < Reco_QQ_ctauErr && Reco_QQ_ctauErr < 1"; //// new cut TCut accNewRecoPlus = "(TMath::Abs(Reco_QQ_mupl_4mom.Eta()) < 2.4 && ((TMath::Abs(Reco_QQ_mupl_4mom.Eta()) < 1.2 && Reco_QQ_mupl_4mom.Pt() >=3.3) || (1.2 <= TMath::Abs(Reco_QQ_mupl_4mom.Eta()) && TMath::Abs(Reco_QQ_mupl_4mom.Eta()) < 2.1 && Reco_QQ_mupl_4mom.Pt() >= 3.93-1.11*TMath::Abs(Reco_QQ_mupl_4mom.Eta())) || (2.1 <= TMath::Abs(Reco_QQ_mupl_4mom.Eta()) && Reco_QQ_mupl_4mom.Pt() >= 1.3)))"; TCut accNewRecoMinus = "(TMath::Abs(Reco_QQ_mumi_4mom.Eta()) < 2.4 && ((TMath::Abs(Reco_QQ_mumi_4mom.Eta()) < 1.2 && Reco_QQ_mumi_4mom.Pt() >=3.3) || (1.2 <= TMath::Abs(Reco_QQ_mumi_4mom.Eta()) && TMath::Abs(Reco_QQ_mumi_4mom.Eta()) < 2.1 && Reco_QQ_mumi_4mom.Pt() >= 3.93-1.11*TMath::Abs(Reco_QQ_mumi_4mom.Eta())) || (2.1 <= TMath::Abs(Reco_QQ_mumi_4mom.Eta()) && Reco_QQ_mumi_4mom.Pt() >= 1.3)))"; //// muID TCut muIDPlus; TCut muIDMinus; if(strcmp(szPA,"pp")==0) { muIDPlus = "Reco_QQ_mupl_highPurity && Reco_QQ_mupl_TrkMuArb && Reco_QQ_mupl_TMOneStaTight && Reco_QQ_mupl_nTrkWMea > 5 && Reco_QQ_mupl_nPixWMea > 0 && TMath::Abs(Reco_QQ_mupl_dxy) < 0.3 && TMath::Abs(Reco_QQ_mupl_dz) < 20."; muIDMinus = "Reco_QQ_mumi_highPurity && Reco_QQ_mumi_TrkMuArb && Reco_QQ_mumi_TMOneStaTight && Reco_QQ_mumi_nTrkWMea > 5 && Reco_QQ_mumi_nPixWMea > 0 && TMath::Abs(Reco_QQ_mumi_dxy) < 0.3 && TMath::Abs(Reco_QQ_mumi_dz) < 20."; } else if (strcmp(szPA,"pa")==0) { muIDPlus = "Reco_QQ_mupl_isHighPurity && Reco_QQ_mupl_TrkMuArb && Reco_QQ_mupl_TMOneStaTight && Reco_QQ_mupl_nTrkWMea > 5 && Reco_QQ_mupl_nPixWMea > 0 && TMath::Abs(Reco_QQ_mupl_dxy) < 0.3 && TMath::Abs(Reco_QQ_mupl_dz) < 20."; muIDMinus = "Reco_QQ_mumi_isHighPurity && Reco_QQ_mumi_TrkMuArb && Reco_QQ_mumi_TMOneStaTight && Reco_QQ_mumi_nTrkWMea > 5 && Reco_QQ_mumi_nPixWMea > 0 && TMath::Abs(Reco_QQ_mumi_dxy) < 0.3 && TMath::Abs(Reco_QQ_mumi_dz) < 20."; } //TCut totalCut = recoPairCut && rapRange && ptRange && accNewRecoPlus && accNewRecoMinus; //TCut totalCutMC = recoPairCut && rapRange && ptRange && accNewRecoPlus && accNewRecoMinus; TCut ptRange[nEt][nRap][nPt]; TCut rapRange[nEt][nRap][nPt]; TCut totalCut[nEt][nRap][nPt]; TCut totalCutBkg[nEt][nRap][nPt]; //// forming TCut for diffential binning for (int in=0; in<nEt; in++){ for (int ir=0; ir<nRap; ir++ ) { for (int ipt=0; ipt<nPt; ipt++) { ptRange[in][ir][ipt] = Form("Reco_QQ_4mom.Pt()>%.1f && Reco_QQ_4mom.Pt()<%.1f",ptArr[ipt] , ptArr[ipt+1]); //// change y_CM to y_lab if(strcmp(szPA,"pp")==0) { rapRange[in][ir][ipt] = Form("Reco_QQ_4mom.Rapidity()>%.2f && Reco_QQ_4mom.Rapidity()<%.2f",yArr[ir+1] , yArr[ir]); } else { rapRange[in][ir][ipt] = Form("-0.47-1.*Reco_QQ_4mom.Rapidity()>%.2f && -0.47-1.*Reco_QQ_4mom.Rapidity()<%.2f",yArr[ir+1] , yArr[ir]); //rapRangepPb[in][ir][ipt] = Form("-0.47+Reco_QQ_4mom.Rapidity()>%.2f && -0.47+Reco_QQ_4mom.Rapidity()<%.2f",yArr[ir+1] , yArr[ir]); } cout << "ptRange = " <<ptRange[in][ir][ipt] << endl; cout << "rapRange = " <<rapRange[in][ir][ipt] << endl; totalCut[in][ir][ipt] = trigCut && recoPairCut && massNarrow && ctauCut && accNewRecoPlus && accNewRecoMinus && muIDPlus && muIDMinus && rapRange[in][ir][ipt] && ptRange[in][ir][ipt]; totalCutBkg[in][ir][ipt] = trigCut && recoPairCut && massWide && (!massNarrow) && ctauCut && accNewRecoPlus && accNewRecoMinus && muIDPlus && muIDMinus && rapRange[in][ir][ipt] && ptRange[in][ir][ipt]; } } } ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// //// define 1D hist TH1D *hMeanPt[nEt][nRap][nPt]; TH1D *hMeanPtBkg[nEt][nRap][nPt]; double meanVal[nEt][nRap][nPt]; double maxVal[nEt][nRap][nPt]; double meanValBkg[nEt][nRap][nPt]; double maxValBkg[nEt][nRap][nPt]; TCanvas* cmulti[nEt][nRap]; TLegend *legUR = new TLegend(0.58,0.68,0.90,0.90,NULL,"brNDC"); TLegend *legUM = new TLegend(0.30,0.68,0.65,0.90,NULL,"brNDC"); TLegend *legUL = new TLegend(0.17,0.68,0.51,0.90,NULL,"brNDC"); TLegend *legBM = new TLegend(0.30,0.20,0.65,0.42,NULL,"brNDC"); SetLegendStyle(legUR); SetLegendStyle(legUM); SetLegendStyle(legUL); SetLegendStyle(legBM); TLatex* latex = new TLatex(); latex->SetNDC(); latex->SetTextAlign(12); latex->SetTextSize(0.04); for (int in=0; in<nEt; in++){ for (int ir=0; ir<nRap; ir++ ) { cmulti[in][ir]= new TCanvas(Form("cmulti_%d_%d",in,ir),Form("%s",rapstrArr[ir].Data()),1500,600); cmulti[in][ir]->Divide(5,2); for (int ipt=0; ipt<nPt; ipt++) { hMeanPt[in][ir][ipt] = new TH1D(Form("hMeanPt_%d_%d_%d",in, ir, ipt),";p_{T} (GeV/c);events", nbin, ptArr[ipt], ptArr[ipt+1]); hMeanPt[in][ir][ipt] ->Sumw2(); SetHistStyle(hMeanPt[in][ir][ipt],4,0); hMeanPtBkg[in][ir][ipt] = new TH1D(Form("hMeanPtBkg_%d_%d_%d",in, ir, ipt),";p_{T} (GeV/c);events", nbin, ptArr[ipt], ptArr[ipt+1]); hMeanPtBkg[in][ir][ipt] ->Sumw2(); SetHistStyle(hMeanPtBkg[in][ir][ipt],3,10); cmulti[in][ir]->cd(ipt+1); gPad->SetLogy(1); if (isSmall) { treeData->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPt[in][ir][ipt]->GetName()),totalCut[in][ir][ipt],"",nEntry); treeData->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPtBkg[in][ir][ipt]->GetName()),totalCutBkg[in][ir][ipt],"pe same",nEntry); } else { treeData->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPt[in][ir][ipt]->GetName()),totalCut[in][ir][ipt],""); treeData->Draw(Form("Reco_QQ_4mom.Pt()>>%s",hMeanPtBkg[in][ir][ipt]->GetName()),totalCutBkg[in][ir][ipt],"pe same"); } meanVal[in][ir][ipt] = hMeanPt[in][ir][ipt]->GetMean(1); maxVal[in][ir][ipt] = 50*hMeanPt[in][ir][ipt]->GetMaximum(); meanValBkg[in][ir][ipt] = hMeanPtBkg[in][ir][ipt]->GetMean(1); maxValBkg[in][ir][ipt] = 50*hMeanPtBkg[in][ir][ipt]->GetMaximum(); hMeanPt[in][ir][ipt]->GetYaxis()->SetRangeUser(0.1,maxVal[in][ir][ipt]); hMeanPtBkg[in][ir][ipt]->GetYaxis()->SetRangeUser(0.1,maxValBkg[in][ir][ipt]); std::cout << hMeanPt[in][ir][ipt]->GetName() <<" : entries = " << hMeanPt[in][ir][ipt]->GetEntries() << std::endl; cout << " Cand <p_{T}> = " << meanVal[in][ir][ipt] << endl; cout << " Bkg <p_{T}> = " << meanValBkg[in][ir][ipt] << endl; latex->DrawLatex(0.54, 0.87, rapstrArr[ir].Data()); latex->DrawLatex(0.54, 0.80, Form("Cand <p_{T}> = %.2f (GeV/c)",meanVal[in][ir][ipt])); latex->DrawLatex(0.54, 0.72, Form("Bkg <p_{T}> = %.2f (GeV/c)",meanValBkg[in][ir][ipt])); //c1->Update(); //c1->SaveAs(Form("%s.png",hMeanPt[in][ir][ipt]->GetName())); //c1->Clear(); } cmulti[in][ir]->Update(); cmulti[in][ir]->SaveAs(Form("dir_meanPt_n%d_%dpt/meanPt_%dpt_%d_%d_wBkg_2.pdf",nbin,nPt,nPt,in,ir)); //cmulti[in][ir]->Clear(); } } /// Save as a root file TFile *outFile = new TFile(Form("dir_meanPt_n%d_%dpt/meanPt_%dpt_wBkg_2.root",nbin,nPt,nPt),"RECREATE"); outFile->cd(); for (int in=0; in<nEt; in++){ for (int ir=0; ir<nRap; ir++ ) { for (int ipt=0; ipt<nPt; ipt++) { hMeanPt[in][ir][ipt]->Write(); hMeanPtBkg[in][ir][ipt]->Write(); } } } outFile->Close(); return 0; }
void postfit_use(const char* inputfile, const char* analysis = "SM", const char* dataset = "2011+2012", const char* extra="", const char* extra2="", float min=0.1, float max=-1., bool log=true) { // defining the common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // switch for MSSM/SM bool MSSM = std::string(analysis) == std::string("MSSM"); // determine label if (std::string(dataset) == std::string("2011" )){ dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV"; } if (std::string(dataset) == std::string("2012" )){ dataset = "CMS Preliminary, H#rightarrow#tau#tau, 19.8 fb^{-1} at 8 TeV"; } if (std::string(dataset) == std::string("2011+2012")){ dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV, 19.8 fb^{-1} at 8 TeV"; } // determine category tag const char* category_extra = ""; if(std::string(extra2) == std::string("0jet_low" )){ category_extra = "0 jet, low p_{T}"; } if(std::string(extra2) == std::string("0jet_high" )){ category_extra = "0 jet, high p_{T}"; } if(std::string(extra2) == std::string("0jet" )){ category_extra = "0 jet"; } if(std::string(extra2) == std::string("1jet_low" )){ category_extra = "1 jet, low p_{T}"; } if(std::string(extra2) == std::string("1jet_high" )){ category_extra = "1 jet, high p_{T}"; } if(std::string(extra2) == std::string("1jet" )){ category_extra = "1 jet"; } if(std::string(extra2) == std::string("vbf" )){ category_extra = "2 jet (VBF)"; } if(std::string(extra2) == std::string("nobtag" )){ category_extra = "No B-Tag"; } if(std::string(extra2) == std::string("btag" )){ category_extra = "B-Tag"; } TFile* input = new TFile(inputfile); TH1F* Fakes = refill((TH1F*)input->Get("Fakes" ), "Fakes/QCD"); TH1F* EWK = refill((TH1F*)input->Get("EWK" ), "EWK" ); TH1F* ttbar = refill((TH1F*)input->Get("ttbar" ), "ttbar" ); TH1F* Ztt = refill((TH1F*)input->Get("Ztt" ), "Ztt" ); TH1F* Zmm = refill((TH1F*)input->Get("Zmm" ), "Zmm" ); TH1F* Zee = refill((TH1F*)input->Get("Zee" ), "Zee" ); TH1F* ggH = refill((TH1F*)input->Get("ggH" ), "ggH" ); TH1F* data = (TH1F*)input->Get("data_obs"); // determine channel for etau Z->ee (EWK) will be shown separated from the rest (EWK1) TH1F* EWK1 = 0; if(std::string(extra) == std::string("e#tau_{h}")){ EWK1 = refill((TH1F*)input->Get("EWK1"), "EWK1"); } TH1F* ggH_hww = 0; if(std::string(extra) == std::string("e#mu") and HWWBG){ ggH_hww= refill((TH1F*)input->Get("ggH_hww" ), "ggH_hww" ); } TH1F* errorBand = (TH1F*)input->Get("errorBand"); /* mass plot before and after fit */ TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); if(log) canv->SetLogy(1); // reduce the axis range if necessary for linea plots and SM if(MSSM && !log){ data->GetXaxis()->SetRange(0, data->FindBin(345)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(UPPER_EDGE)); }; if(!MSSM){ data->GetXaxis()->SetRange(0, data->FindBin(345)); } data->SetNdivisions(505); data->SetMinimum(min); if(std::string(extra) == std::string("#mu#mu")){ data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Zmm, log))); data->Draw("e"); if(log){ Zmm ->Draw("same"); Ztt ->Draw("same"); ttbar->Draw("same"); Fakes->Draw("same"); EWK ->Draw("same"); if(ggH) ggH ->Draw("histsame"); } } else if(std::string(extra) == std::string("ee")){ data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Zee, log))); data->Draw("e"); if(log){ Zee ->Draw("same"); Ztt ->Draw("same"); ttbar->Draw("same"); Fakes->Draw("same"); EWK ->Draw("same"); if(ggH) ggH ->Draw("histsame"); } } else if(std::string(extra) == std::string("e#tau_{h}")){ data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log))); data->Draw("e"); if(log){ Ztt ->Draw("same"); ttbar->Draw("same"); EWK ->Draw("same"); EWK1 ->Draw("same"); Fakes->Draw("same"); if(ggH) ggH ->Draw("histsame"); } else{ if(ggH) ggH ->Draw("histsame"); Ztt ->Draw("same"); ttbar->Draw("same"); EWK ->Draw("same"); EWK1 ->Draw("same"); Fakes->Draw("same"); } } else if(std::string(extra) == std::string("e#mu") && HWWBG){ data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(ggH_hww, log))); data->Draw("e"); if(log){ ggH_hww -> Draw("same"); Ztt ->Draw("same"); ttbar->Draw("same"); EWK ->Draw("same"); Fakes->Draw("same"); if(ggH) ggH ->Draw("histsame"); } else{ if(ggH) ggH ->Draw("histsame"); ggH_hww -> Draw("same"); Ztt ->Draw("same"); ttbar->Draw("same"); EWK ->Draw("same"); Fakes->Draw("same"); } } else{ data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log))); data->Draw("e"); if(log){ Ztt ->Draw("same"); ttbar->Draw("same"); EWK ->Draw("same"); Fakes->Draw("same"); if(ggH) ggH ->Draw("histsame"); } else{ if(ggH) ggH ->Draw("histsame"); Ztt ->Draw("same"); ttbar->Draw("same"); EWK ->Draw("same"); Fakes->Draw("same"); } } if(errorBand){ errorBand->Draw("e2same"); } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, extra, 0.17, 0.835); CMSPrelim(dataset, "", 0.18, 0.835); TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(extra); chan->Draw(); TPaveText* cat = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); if(MSSM){ float lower_bound = EWK1 ? 0.45 : 0.50; TPaveText* massA = new TPaveText(0.55, lower_bound+0.061, 0.95, lower_bound+0.161, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("m^{h}_{max} (m_{A}=$MA GeV, tan#beta=$TANB)"); massA->Draw(); } float lower_bound = EWK1 ? 0.60 : 0.65; TLegend* leg = new TLegend(MSSM ? 0.55 : 0.50, lower_bound, 0.93, 0.90); SetLegendStyle(leg); if(MSSM){ leg->AddEntry(ggH , "#phi#rightarrow#tau#tau", "L" ); } else{ if(ggH){ if(SIGNAL_SCALE!=1){ leg->AddEntry(ggH , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" ); } else{ leg->AddEntry(ggH , "H(125 GeV)#rightarrow#tau#tau" , "L" ); } } } leg->AddEntry(data , "observed" , "LP"); if(std::string(extra) == std::string("#mu#mu")){ leg->AddEntry(Zmm , "Z#rightarrow#mu#mu" , "F" ); leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); leg->AddEntry(EWK , "electroweak" , "F" ); } else if(std::string(extra) == std::string("ee")){ leg->AddEntry(Zee , "Z#rightarrowee" , "F" ); leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); leg->AddEntry(EWK , "electroweak" , "F" ); } else if(std::string(extra) == std::string("e#tau_{h}")){ leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(EWK , "Z#rightarrow ee" , "F" ); leg->AddEntry(EWK1 , "electroweak" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); } else if(std::string(extra) == std::string("e#mu") && HWWBG){ leg->AddEntry(ggH_hww , "H(125 GeV)#rightarrowWW" , "F" ); leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(EWK , "electroweak" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); } else{ leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(EWK , "electroweak" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); } if(errorBand){ leg->AddEntry(errorBand, "bkg. uncertainty" , "F" ); } leg->Draw(); /* prepare output */ std::string newName = std::string(inputfile).substr(0, std::string(inputfile).find(".root")); canv->Print(TString::Format("%s.png", newName.c_str())); canv->Print(TString::Format("%s.pdf", newName.c_str())); canv->Print(TString::Format("%s.eps", newName.c_str())); /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* model; if(CONSERVATIVE_CHI2){ if(std::string(extra) == std::string("#mu#mu")){ model = (TH1F*)Zmm ->Clone("model"); } else if(std::string(extra) == std::string("ee")){ model = (TH1F*)Zee ->Clone("model"); } else if(std::string(extra) == std::string("e#mu") && HWWBG){ model = (TH1F*)ggH_hww ->Clone("model"); } else{ model = (TH1F*)Ztt ->Clone("model"); } } else{ model = (TH1F*)errorBand->Clone("model"); } TH1F* test1 = (TH1F*)data->Clone("test1"); for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){ //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01); model->SetBinError (ibin+1, CONSERVATIVE_CHI2 ? 0. : model->GetBinError (ibin+1)*model->GetBinWidth(ibin+1)); test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1)); test1->SetBinError (ibin+1, test1->GetBinError (ibin+1)*test1->GetBinWidth(ibin+1)); } double chi2prob = test1->Chi2Test (model,"PUW"); std::cout << "chi2prob:" << chi2prob << std::endl; double chi2ndof = test1->Chi2Test (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl; double ksprob = test1->KolmogorovTest(model); std::cout << "ksprob :" << ksprob << std::endl; double ksprobpe = test1->KolmogorovTest(model,"DX"); std::cout << "ksprobpe:" << ksprobpe << std::endl; std::vector<double> edges; TH1F* zero = (TH1F*)Ztt->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat"); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ rat1->SetBinContent(ibin+1, errorBand->GetBinContent(ibin+1)>0 ? data->GetBinContent(ibin+1)/errorBand->GetBinContent(ibin+1) : 0); rat1->SetBinError (ibin+1, errorBand->GetBinContent(ibin+1)>0 ? data->GetBinError (ibin+1)/errorBand->GetBinContent(ibin+1) : 0); zero->SetBinContent(ibin+1, 0.); zero->SetBinError (ibin+1, errorBand->GetBinContent(ibin+1)>0 ? errorBand ->GetBinError (ibin+1)/errorBand->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } zero->SetBinContent(ibin+1, 0.); } float range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+range); rat1->SetMinimum(-range); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); if((std::string(extra) == std::string("#mu#mu") || std::string(extra) == std::string("ee")) && !MSSM){ rat1->GetXaxis()->SetTitle("#bf{D}"); } else{ rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); } rat1->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->SetMarkerSize(0.1); zero->Draw("e2histsame"); canv0->RedrawAxis(); TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC"); stat1->SetBorderSize( 0 ); stat1->SetFillStyle( 0 ); stat1->SetTextAlign( 12 ); stat1->SetTextSize ( 0.05 ); stat1->SetTextColor( 1 ); stat1->SetTextFont ( 62 ); stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f", chi2ndof, chi2prob)); //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f, P(KS)=%.3f", chi2ndof, chi2prob, ksprob)); stat1->Draw(); /* prepare output */ newName = std::string(inputfile).substr(0, std::string(inputfile).find(".root")) + "_datamc"; canv0->Print(TString::Format("%s.png", newName.c_str())); canv0->Print(TString::Format("%s.pdf", newName.c_str())); canv0->Print(TString::Format("%s.eps", newName.c_str())); }
void comp_RpPb_pt_Bmeson(bool isPrompt = false) { gROOT->Macro("./tdrstyle_kyo.C"); int isPA = 10; int iPos=33; //// BR and lumi info. const Double_t br = 0.0593 ; const Double_t brErr = 0.0006; const Double_t pp_lumi_pb =27.972; // 28.0/pb const Double_t pp_lumi_pb_err = 0.643; // 2.3 % const Double_t pPb_lumi_nb = 34.622; // 34.6/nb const Double_t pPb_lumi_nb_err = 1.211; // 3.5 % const Double_t pp_lumi_mub = pp_lumi_pb *1000*1000; const Double_t pPb_lumi_mub_err = pp_lumi_pb_err *1000*1000; double A_pb =208; //// read our result TFile *inFile_pp; if (isPrompt) inFile_pp = new TFile("plot_cross/pp_cross_pt_integ_middle_isPrompt1_isLog0_isScale0_maxrap386.root"); else inFile_pp= new TFile("plot_cross/pp_cross_pt_integ_middle_isPrompt0_isLog0_isScale0_maxrap386.root"); TGraphAsymmErrors* g_cross_fwrap_pp = (TGraphAsymmErrors*)inFile_pp->Get("g_cross_fwrap"); TGraphAsymmErrors* g_cross_sys_fwrap_pp = (TGraphAsymmErrors*)inFile_pp->Get("g_cross_sys_fwrap"); //// read our result TFile *inFile_pA; if (isPrompt) inFile_pA = new TFile("plot_cross/pA_cross_pt_integ_middle_isPrompt1_isLog0_isScale0_maxrap386.root"); else inFile_pA= new TFile("plot_cross/pA_cross_pt_integ_middle_isPrompt0_isLog0_isScale0_maxrap386.root"); TGraphAsymmErrors* g_cross_fwrap_pA = (TGraphAsymmErrors*)inFile_pA->Get("g_cross_fwrap"); TGraphAsymmErrors* g_cross_sys_fwrap_pA = (TGraphAsymmErrors*)inFile_pA->Get("g_cross_sys_fwrap"); const int nPt = 5; double dummy1; double pxtmp[nPt]; double pytmp_pp[nPt]; double pytmp_pA[nPt]; double rppb[nPt]; double eytmp_pp[nPt]; double eytmp_pA[nPt]; double ey_rppb[nPt]; double eysystmp_pp[nPt]; double eysystmp_pA[nPt]; double eysys_rppb[nPt]; for (int ipt=0; ipt<nPt; ipt++) { g_cross_fwrap_pp->GetPoint(ipt+4, pxtmp[ipt], pytmp_pp[ipt]); g_cross_fwrap_pA->GetPoint(ipt+4, pxtmp[ipt], pytmp_pA[ipt]); eytmp_pp[ipt] = g_cross_fwrap_pp->GetErrorY(ipt+4); eytmp_pA[ipt] = g_cross_fwrap_pA->GetErrorY(ipt+4); eysystmp_pp[ipt] = g_cross_sys_fwrap_pp->GetErrorY(ipt+4); eysystmp_pA[ipt] = g_cross_sys_fwrap_pA->GetErrorY(ipt+4); } cout << "::: for excel ::: " << endl; for (int ipt=0; ipt<nPt; ipt++) { DivideValue(pytmp_pA[ipt],eytmp_pA[ipt],pytmp_pp[ipt],eytmp_pp[ipt],&rppb[ipt],&ey_rppb[ipt]); //actual values DivideValue(pytmp_pA[ipt],eysystmp_pA[ipt],pytmp_pp[ipt],eysystmp_pp[ipt],&dummy1,&eysys_rppb[ipt]); //syst. rppb[ipt]/=A_pb; ey_rppb[ipt]/=A_pb; eysys_rppb[ipt]/=A_pb; //cout << " "<<endl; //cout << "rppb["<<ipt<<"] =" << rppb[ipt] << endl; //cout << "stat.["<<ipt<<"] =" << ey_rppb[ipt] << endl; //cout << "syst.["<<ipt<<"] =" << eysys_rppb[ipt] << endl; cout << rppb[ipt] <<"\t"<<ey_rppb[ipt] << "\t "<<eysys_rppb[ipt]<<endl; } Double_t exsys[nPt] = {0.4,0.4,0.4,0.4,0.4}; Double_t exlow[nPt]; Double_t exhigh[nPt]; Double_t ptArrNum[nPt+1] = {6.5, 7.5, 8.5, 10., 14., 30.}; //// ex calculation for (Int_t ipt=0; ipt<nPt; ipt++) { exlow[ipt] = pxtmp[ipt]-ptArrNum[ipt]; exhigh[ipt] = ptArrNum[ipt+1]-pxtmp[ipt]; } /////////////////////////////////////////////////// ///////////////////// Bmeson //////////////////////// /////////////////////////////////////////////////// TCanvas *c1 = new TCanvas("c1","c1",600,600); const int nPtBmeson = 5; double px_Bmeson[nPtBmeson] = {12.5, 17.5, 22.5, 27.5, 45}; double rppb_Bmeson[nPtBmeson] = {1.11, 1.19, 0.91, 0.86, 1.14}; double ex_Bmeson[nPtBmeson] = {0,0,0,0,0}; double exsys_Bmeson[nPtBmeson] = {2.5, 2.5, 2.5, 2.5, 15.}; double ey_Bmeson[nPtBmeson] = {0.08, 0.10, 0.12, 0.18, 0.19}; double eysys_Bmeson[nPtBmeson] = {0.17, 0.17, 0.13, 0.12, 0.17}; double eysysFONLLlow_Bmeson[nPtBmeson] = {0.29,0.28,0.19,0.16,0.18}; double eysysFONLLhigh_Bmeson[nPtBmeson] = {0.33,0.31,0.21,0.18,0.21}; TGraphAsymmErrors* g_RpPb_Bmeson_sys = new TGraphAsymmErrors(nPtBmeson, px_Bmeson, rppb_Bmeson, exsys_Bmeson, exsys_Bmeson, eysys_Bmeson, eysys_Bmeson); TGraphAsymmErrors* g_RpPb_Bmeson_sysFONLL = new TGraphAsymmErrors(nPtBmeson, px_Bmeson, rppb_Bmeson, exsys_Bmeson, exsys_Bmeson, eysysFONLLlow_Bmeson, eysysFONLLhigh_Bmeson); TGraphAsymmErrors* g_RpPb_Bmeson = new TGraphAsymmErrors(nPtBmeson, px_Bmeson, rppb_Bmeson, ex_Bmeson, ex_Bmeson, ey_Bmeson, ey_Bmeson); g_RpPb_Bmeson_sysFONLL->GetXaxis()->SetTitle("p_{T} (GeV/c)"); g_RpPb_Bmeson_sysFONLL->GetXaxis()->CenterTitle(); g_RpPb_Bmeson_sysFONLL->GetYaxis()->SetTitle("R_{pPb}"); g_RpPb_Bmeson_sysFONLL->GetYaxis()->CenterTitle(); g_RpPb_Bmeson_sysFONLL->GetXaxis()->SetLimits(0.,62.0); g_RpPb_Bmeson_sysFONLL->SetMinimum(0.0); g_RpPb_Bmeson_sysFONLL->SetMaximum(2.0); g_RpPb_Bmeson_sysFONLL->SetLineColor(kGray); g_RpPb_Bmeson_sysFONLL->SetFillColor(kWhite); g_RpPb_Bmeson_sysFONLL->SetFillStyle(4000); g_RpPb_Bmeson_sysFONLL->SetLineWidth(3); g_RpPb_Bmeson_sysFONLL->SetLineStyle(7); g_RpPb_Bmeson_sys->SetFillColor(kGray); //g_RpPb_Bmeson_sys->SetFillStyle(3001); SetGraphStyleFinal(g_RpPb_Bmeson, 9, 13); g_RpPb_Bmeson->SetMarkerSize(1.2); ////////////////////////////////////////////////////////////// TLatex* globtex = new TLatex(); globtex->SetNDC(); globtex->SetTextAlign(12); //1:left, 2:vertical center //globtex->SetTextAlign(32); //3:right 2:vertical center globtex->SetTextFont(42); globtex->SetTextSize(0.04); TBox * globbox_br = new TBox(2, 0.969, 4, 1.031); //for B+ branching ratio globbox_br->SetFillColorAlpha(kWhite,0.5); globbox_br->SetLineColor(kBlack); //// our results TGraphAsymmErrors* g_RpPb_sys = new TGraphAsymmErrors(nPt, pxtmp, rppb, exlow, exhigh, eysys_rppb, eysys_rppb); TGraphAsymmErrors* g_RpPb = new TGraphAsymmErrors(nPt, pxtmp, rppb, exsys, exsys, ey_rppb, ey_rppb); g_RpPb_sys->SetFillColorAlpha(kRed-10,0.5); g_RpPb_sys->SetLineColor(kPink-6); SetGraphStyleFinal(g_RpPb, 1, 0); g_RpPb->SetMarkerSize(1.2); ////// actual draw g_RpPb_Bmeson_sysFONLL->Draw("A5"); g_RpPb_Bmeson_sys->Draw("2"); g_RpPb_sys->Draw("5"); solidLine(0.,1.,62.,1.,1,1); g_RpPb->Draw("p"); g_RpPb_Bmeson->Draw("p"); //TLegend *legBL = new TLegend(0.50,0.18,0.90,0.25); TLegend *legBL = new TLegend(0.18,0.18,0.77,0.32); SetLegendStyle(legBL); //legBL->SetTextSize(0.037); legBL->SetTextSize(0.043); legBL->SetTextFont(42); legBL -> AddEntry(g_RpPb,"Nonprompt J/#psi: |y_{CM}| < 1.93","lp"); legBL -> AddEntry(g_RpPb_Bmeson,"B^{+}: -2.86 < y_{CM} < 1.93","lp"); legBL -> Draw(); globtex->SetTextSize(0.055); globtex->SetTextFont(42); globtex->DrawLatex(0.212, 0.852, "Open beauty"); //if (isPrompt) globtex->DrawLatex(0.212, 0.852, "Prompt J/#psi"); //else globtex->DrawLatex(0.212, 0.852, "Nonprompt J/#psi"); CMS_lumi( c1, isPA, iPos ); c1->Update(); c1->SaveAs(Form("plot_otherExp/comp_RpPb_pt_Bmeson_isPrompt%d.pdf",(int)isPrompt)); c1->SaveAs(Form("plot_otherExp/comp_RpPb_pt_Bmeson_isPrompt%d.png",(int)isPrompt)); return; }
void HTT_MT_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., const char* inputfile="root/$HISTFILE", const char* directory="muTau_$CATEGORY") { // defining the common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category_extra = ""; if(std::string(directory) == std::string("muTau_0jet_low" )){ category_extra = "0 jet, low p_{T}"; } if(std::string(directory) == std::string("muTau_0jet_high" )){ category_extra = "0 jet, high p_{T}"; } if(std::string(directory) == std::string("muTau_boost_low" )){ category_extra = "1 jet, low p_{T}"; } if(std::string(directory) == std::string("muTau_boost_high")){ category_extra = "1 jet, high p_{T}"; } if(std::string(directory) == std::string("muTau_vbf" )){ category_extra = "2 jet (VBF)"; } if(std::string(directory) == std::string("muTau_nobtag" )){ category_extra = "No B-Tag"; } if(std::string(directory) == std::string("muTau_btag" )){ category_extra = "B-Tag"; } const char* dataset; if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 19.4 fb^{-1} at 8 TeV";} #ifdef MSSM if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 12.1 fb^{-1} at 8 TeV";} #endif // open example histogram file TFile* input = new TFile(inputfile); TH1F* Fakes = refill((TH1F*)input->Get(TString::Format("%s/QCD" , directory)), "QCD"); InitHist(Fakes, "", "", kMagenta-10, 1001); TH1F* EWK1 = refill((TH1F*)input->Get(TString::Format("%s/W" , directory)), "W" ); InitHist(EWK1 , "", "", kRed + 2, 1001); #ifdef EXTRA_SAMPLES TH1F* EWK2 = refill((TH1F*)input->Get(TString::Format("%s/ZJ" , directory)), "ZJ" ); InitHist(EWK2 , "", "", kRed + 2, 1001); TH1F* EWK3 = refill((TH1F*)input->Get(TString::Format("%s/ZL" , directory)), "ZL" ); InitHist(EWK3 , "", "", kRed + 2, 1001); #else TH1F* EWK2 = refill((TH1F*)input->Get(TString::Format("%s/ZLL" , directory)), "ZLL"); InitHist(EWK2 , "", "", kRed + 2, 1001); #endif TH1F* EWK = refill((TH1F*)input->Get(TString::Format("%s/VV" , directory)), "VV" ); InitHist(EWK , "", "", kRed + 2, 1001); TH1F* ttbar = refill((TH1F*)input->Get(TString::Format("%s/TT" , directory)), "TT" ); InitHist(ttbar, "", "", kBlue - 8, 1001); TH1F* Ztt = refill((TH1F*)input->Get(TString::Format("%s/ZTT" , directory)), "ZTT"); InitHist(Ztt , "", "", kOrange - 4, 1001); #ifdef MSSM float ggHScale = 1., bbHScale = 1.; // scenario for MSSM, mhmax, mA=160, tanb=20, A + H for the time being if(std::string(inputfile).find("7TeV")!=std::string::npos){ ggHScale = ( 9157.9*0.119 + 10180.7*0.120)/1000.; bbHScale = (23314.3*0.119 + 21999.3*0.120)/1000.; } if(std::string(inputfile).find("8TeV")!=std::string::npos){ ggHScale = (11815.3*0.119 + 13124.9*0.120)/1000.; bbHScale = (31087.9*0.119 + 29317.8*0.120)/1000.; } // float ggHScale = 1., bbHScale = 1.; // scenario for MSSM, mhmax, mA=160, tanb=10, A + H for the time being // if(std::string(inputfile).find("7TeV")!=std::string::npos){ ggHScale = (2111.4*0.11 + 4022.9*0.11)/1000.; // bbHScale = (6211.6*0.11 + 5147.0*0.11)/1000.; } // if(std::string(inputfile).find("8TeV")!=std::string::npos){ ggHScale = (2729.9*0.11 + 5193.2*0.11)/1000.; // bbHScale = (8282.7*0.11 + 6867.8*0.11)/1000.; } TH1F* ggH = refill((TH1F*)input->Get(TString::Format("%s/ggH160", directory)), "ggH"); InitSignal(ggH); ggH ->Scale(ggHScale); TH1F* bbH = refill((TH1F*)input->Get(TString::Format("%s/bbH160", directory)), "bbH"); InitSignal(bbH); bbH ->Scale(bbHScale); #else #ifndef DROP_SIGNAL TH1F* ggH = refill((TH1F*)input->Get(TString::Format("%s/ggH125", directory)), "ggH"); InitSignal(ggH); ggH ->Scale(SIGNAL_SCALE); TH1F* qqH = refill((TH1F*)input->Get(TString::Format("%s/qqH125", directory)), "qqH"); InitSignal(qqH); qqH ->Scale(SIGNAL_SCALE); TH1F* VH = refill((TH1F*)input->Get(TString::Format("%s/VH125" , directory)), "VH" ); InitSignal(VH ); VH ->Scale(SIGNAL_SCALE); #endif #endif TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); InitHist(data, "#bf{m_{#tau#tau} [GeV]}", "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)Fakes->Clone("ref"); ref->Add(EWK1 ); ref->Add(EWK2 ); #ifdef EXTRA_SAMPLES ref->Add(EWK3 ); #endif ref->Add(EWK ); ref->Add(ttbar); ref->Add(Ztt ); double unscaled[7]; unscaled[0] = Fakes->Integral(); unscaled[1] = EWK ->Integral(); unscaled[1]+= EWK1 ->Integral(); unscaled[1]+= EWK2 ->Integral(); #ifdef EXTRA_SAMPLES unscaled[1]+= EWK3 ->Integral(); #endif unscaled[2] = ttbar->Integral(); unscaled[3] = Ztt ->Integral(); #ifdef MSSM unscaled[4] = ggH ->Integral(); unscaled[5] = bbH ->Integral(); unscaled[6] = 0; #else #ifndef DROP_SIGNAL unscaled[4] = ggH ->Integral(); unscaled[5] = qqH ->Integral(); unscaled[6] = VH ->Integral(); #endif #endif if(scaled){ rescale(Fakes, 7); rescale(EWK1 , 3); rescale(EWK2 , 4); #ifdef EXTRA_SAMPLES rescale(EWK3 , 5); #endif rescale(EWK , 6); rescale(ttbar, 2); rescale(Ztt , 1); #ifdef MSSM rescale(ggH , 8); rescale(bbH , 9); #else #ifndef DROP_SIGNAL rescale(ggH , 8); rescale(qqH , 9); rescale(VH ,10); #endif #endif } TH1F* scales[7]; scales[0] = new TH1F("scales-Fakes", "", 7, 0, 7); scales[0]->SetBinContent(1, unscaled[0]>0 ? (Fakes->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-EWK" , "", 7, 0, 7); scales[1]->SetBinContent(2, unscaled[1]>0 ? ((EWK ->Integral() +EWK1 ->Integral() +EWK2 ->Integral() #ifdef EXTRA_SAMPLES +EWK3 ->Integral() #endif )/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-ttbar", "", 7, 0, 7); scales[2]->SetBinContent(3, unscaled[2]>0 ? (ttbar->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-Ztt" , "", 7, 0, 7); scales[3]->SetBinContent(4, unscaled[3]>0 ? (Ztt ->Integral()/unscaled[3]-1.) : 0.); #ifdef MSSM scales[4] = new TH1F("scales-ggH" , "", 7, 0, 7); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH ->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-bbH" , "", 7, 0, 7); scales[5]->SetBinContent(6, unscaled[5]>0 ? (bbH ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-NONE" , "", 7, 0, 7); scales[6]->SetBinContent(7, 0.); #else #ifndef DROP_SIGNAL scales[4] = new TH1F("scales-ggH" , "", 7, 0, 7); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH ->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-qqH" , "", 7, 0, 7); scales[5]->SetBinContent(6, unscaled[5]>0 ? (qqH ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-VH" , "", 7, 0, 7); scales[6]->SetBinContent(7, unscaled[6]>0 ? (VH ->Integral()/unscaled[6]-1.) : 0.); #endif #endif EWK1 ->Add(Fakes); EWK2 ->Add(EWK1 ); #ifdef EXTRA_SAMPLES EWK3 ->Add(EWK2 ); EWK ->Add(EWK3 ); #else EWK ->Add(EWK2 ); #endif ttbar->Add(EWK ); Ztt ->Add(ttbar); if(log){ #ifdef MSSM ggH ->Add(bbH); #else #ifndef DROP_SIGNAL qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } else{ #ifdef MSSM bbH ->Add(Ztt); ggH ->Add(bbH); #else #ifndef DROP_SIGNAL VH ->Add(Ztt); qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } /* Mass plot before and after fit */ TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(1000)); }; #else data->GetXaxis()->SetRange(0, data->FindBin(350)); #endif data->SetNdivisions(505); data->SetMinimum(min); data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log))); data->Draw("e"); TH1F* errorBand = (TH1F*)Ztt ->Clone(); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(1); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } if(log){ Ztt ->Draw("histsame"); ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif } else{ #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif Ztt ->Draw("histsame"); ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{#mu}#tau_{h}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText("#mu#tau_{h}"); chan->Draw(); TPaveText* cat = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); #ifdef MSSM TPaveText* massA = new TPaveText(0.75, 0.48+0.061, 0.85, 0.48+0.161, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("m_{A}=160GeV"); massA->Draw(); TPaveText* tanb = new TPaveText(0.75, 0.44+0.061, 0.85, 0.44+0.161, "NDC"); tanb->SetBorderSize( 0 ); tanb->SetFillStyle( 0 ); tanb->SetTextAlign( 12 ); tanb->SetTextSize ( 0.03 ); tanb->SetTextColor( 1 ); tanb->SetTextFont ( 62 ); tanb->AddText("tan#beta=20"); tanb->Draw(); TPaveText* scen = new TPaveText(0.75, 0.40+0.061, 0.85, 0.40+0.161, "NDC"); scen->SetBorderSize( 0 ); scen->SetFillStyle( 0 ); scen->SetTextAlign( 12 ); scen->SetTextSize ( 0.03 ); scen->SetTextColor( 1 ); scen->SetTextFont ( 62 ); scen->AddText("mhmax"); scen->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.45, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(ggH , "#phi#rightarrow#tau#tau" , "L" ); #else TLegend* leg = new TLegend(0.50, 0.65, 0.95, 0.90); SetLegendStyle(leg); #ifndef DROP_SIGNAL if(SIGNAL_SCALE!=1){ leg->AddEntry(ggH , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" ); } else{ leg->AddEntry(ggH , "H(125 GeV)#rightarrow#tau#tau" , "L" ); } #endif #endif leg->AddEntry(data , "observed" , "LP"); leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(EWK , "electroweak" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); $ERROR_LEGEND leg->Draw(); //#ifdef MSSM // TPaveText* mssm = new TPaveText(0.69, 0.85, 0.90, 0.90, "NDC"); // mssm->SetBorderSize( 0 ); // mssm->SetFillStyle( 0 ); // mssm->SetTextAlign( 12 ); // mssm->SetTextSize ( 0.03 ); // mssm->SetTextColor( 1 ); // mssm->SetTextFont ( 62 ); // mssm->AddText("(m_{A}=120, tan#beta=10)"); // mssm->Draw(); //#else // TPaveText* mssm = new TPaveText(0.83, 0.85, 0.95, 0.90, "NDC"); // mssm->SetBorderSize( 0 ); // mssm->SetFillStyle( 0 ); // mssm->SetTextAlign( 12 ); // mssm->SetTextSize ( 0.03 ); // mssm->SetTextColor( 1 ); // mssm->SetTextFont ( 62 ); // mssm->AddText("m_{H}=125"); // mssm->Draw(); //#endif /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* zero = (TH1F*)ref->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat"); rat1->Divide(Ztt); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } zero->SetBinContent(ibin+1, 0.); } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+0.5); rat1->SetMinimum(-0.5); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat1->Draw(); zero->SetLineColor(kBlack); zero->Draw("same"); canv0->RedrawAxis(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); TH1F* rat2 = (TH1F*) Ztt->Clone("rat2"); rat2->Divide(ref); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } rat2->SetLineColor(kRed+ 3); rat2->SetFillColor(kRed-10); rat2->SetMaximum(+0.3); rat2->SetMinimum(-0.3); rat2->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat2->Draw(); zero->SetLineColor(kBlack); zero->Draw("same"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[0], "", "", kMagenta-10, 1001); InitHist (scales[1], "", "", kRed + 2, 1001); InitHist (scales[2], "", "", kBlue - 8, 1001); InitHist (scales[3], "", "", kOrange - 4, 1001); #ifndef DROP_SIGNAL InitSignal(scales[4]); InitSignal(scales[5]); InitSignal(scales[6]); #endif scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}" ); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}" ); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}" ); scales[0]->GetXaxis()->SetBinLabel(7, "NONE" ); #else scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{qqH}" ); scales[0]->GetXaxis()->SetBinLabel(7, "#bf{VH}" ); #endif scales[0]->SetMaximum(+1.0); scales[0]->SetMinimum(-1.0); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); #ifndef DROP_SIGNAL scales[4]->Draw("same"); scales[5]->Draw("same"); scales[6]->Draw("same"); #endif zero->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sscaled_%s_%s.png" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sscaled_%s_%s.pdf" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sscaled_%s_%s.eps" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); TFile* output = new TFile(TString::Format("%s_%sscaled_%s_%s.root", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""), "update"); output->cd(); data ->Write("data_obs"); Fakes->Write("Fakes" ); EWK ->Write("EWK" ); ttbar->Write("ttbar" ); Ztt ->Write("Ztt" ); #ifdef MSSM ggH ->Write("ggH" ); bbH ->Write("bbH" ); #else #ifndef DROP_SIGNAL ggH ->Write("ggH" ); qqH ->Write("qqH" ); VH ->Write("VH" ); #endif #endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); }
void postfit(const char* inputfile, const char* analysis = "SM", const char* dataset = "2011+2012", const char* extra="", const char* extra2="", float min=0.1, float max=-1., bool log=true) { // defining the common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // switch for MSSM/SM bool MSSM = std::string(analysis) == std::string("MSSM"); // determine label if (std::string(dataset) == std::string("2011" )){ dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV"; } if (std::string(dataset) == std::string("2012" )){ if (std::string(extra) == std::string("#mu#mu") ) dataset = "MS Preliminary, H#rightarrow#tau#tau, 18.7 fb^{-1} at 8 TeV"; else dataset = "MS Preliminary, H#rightarrow#tau#tau, 19.4 fb^{-1} at 8 TeV"; } if (std::string(dataset) == std::string("2011+2012")){ if (std::string(extra) == std::string("#mu#mu") ) dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV, 18.6 fb^{-1} at 8 TeV"; else dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV, 19.4 fb^{-1} at 8 TeV"; if (MSSM) dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV, 12.1 fb^{-1} at 8 TeV"; } // determine category tag const char* category_extra = ""; if(std::string(extra2) == std::string("0jet_low" )){ category_extra = "0 jet, low p_{T}"; } if(std::string(extra2) == std::string("0jet_high" )){ category_extra = "0 jet, high p_{T}"; } if(std::string(extra2) == std::string("0jet" )){ category_extra = "0 jet"; } if(std::string(extra2) == std::string("boost_low" )){ category_extra = "1 jet, low p_{T}"; } if(std::string(extra2) == std::string("boost_high")){ category_extra = "1 jet, high p_{T}"; } if(std::string(extra2) == std::string("boost" )){ category_extra = "1 jet"; } if(std::string(extra2) == std::string("vbf" )){ category_extra = "2 jet (VBF)"; } if(std::string(extra2) == std::string("nobtag" )){ category_extra = "No B-Tag"; } if(std::string(extra2) == std::string("btag" )){ category_extra = "B-Tag"; } TFile* input = new TFile(inputfile); TH1F* Fakes = refill((TH1F*)input->Get("Fakes" ), "Fakes/QCD"); TH1F* EWK = refill((TH1F*)input->Get("EWK" ), "EWK" ); TH1F* ttbar = refill((TH1F*)input->Get("ttbar" ), "ttbar" ); TH1F* Ztt = refill((TH1F*)input->Get("Ztt" ), "Ztt" ); TH1F* Zmm = refill((TH1F*)input->Get("Zmm" ), "Zmm" ); TH1F* ggH = refill((TH1F*)input->Get("ggH" ), "ggH" ); TH1F* data = (TH1F*)input->Get("data_obs"); // determine channel for etau Z->ee (EWK) will be shown separated from the rest (EWK1) TH1F* EWK1 = 0; if(std::string(extra) == std::string("e#tau_{h}")){ EWK1 = refill((TH1F*)input->Get("EWK1"), "EWK1"); } TH1F* errorBand = (TH1F*)input->Get("errorBand"); /* mass plot before and after fit */ TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); if(log) canv->SetLogy(1); // reduce the axis range if necessary for linea plots and SM if(MSSM && !log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(490)); }; if(!MSSM){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } data->SetNdivisions(505); data->SetMinimum(min); if(Zmm){ data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(EWK, log))); } else{ data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log))); } data->Draw("e"); if(log){ if(Zmm){ EWK ->Draw("same"); ttbar->Draw("same"); Fakes->Draw("same"); Zmm ->Draw("same"); Ztt ->Draw("same"); } else{ Ztt ->Draw("same"); ttbar->Draw("same"); EWK ->Draw("same"); if(EWK1){ EWK1->Draw("same"); } if(Fakes){ Fakes->Draw("same"); } } if(ggH) ggH ->Draw("histsame"); } else{ if(ggH) ggH ->Draw("histsame"); if(Zmm){ EWK->Draw("same"); Fakes->Draw("same"); ttbar->Draw("same"); Zmm->Draw("same"); Ztt->Draw("same"); } else{ Ztt ->Draw("same"); ttbar->Draw("same"); EWK ->Draw("same"); if(EWK1){ EWK1->Draw("same"); } if(Fakes){ Fakes->Draw("same"); } } } if(errorBand){ errorBand->Draw("e2same"); } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, extra, 0.17, 0.835); CMSPrelim(dataset, "", 0.18, 0.835); TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(extra); chan->Draw(); TPaveText* cat = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); if(MSSM){ TPaveText* massA = new TPaveText(0.75, 0.48+0.061, 0.85, 0.48+0.161, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("m_{A}=160GeV"); massA->Draw(); TPaveText* tanb = new TPaveText(0.75, 0.44+0.061, 0.85, 0.44+0.161, "NDC"); tanb->SetBorderSize( 0 ); tanb->SetFillStyle( 0 ); tanb->SetTextAlign( 12 ); tanb->SetTextSize ( 0.03 ); tanb->SetTextColor( 1 ); tanb->SetTextFont ( 62 ); tanb->AddText("tan#beta=20"); tanb->Draw(); TPaveText* scen = new TPaveText(0.75, 0.40+0.061, 0.85, 0.40+0.161, "NDC"); scen->SetBorderSize( 0 ); scen->SetFillStyle( 0 ); scen->SetTextAlign( 12 ); scen->SetTextSize ( 0.03 ); scen->SetTextColor( 1 ); scen->SetTextFont ( 62 ); scen->AddText("mhmax"); scen->Draw(); } float lower_bound = EWK1 ? 0.60 : 0.65; TLegend* leg = new TLegend(MSSM ? 0.45 : 0.50, lower_bound, 0.93, 0.90); SetLegendStyle(leg); if(MSSM){ leg->AddEntry(ggH , "#phi#rightarrow#tau#tau", "L" ); } else{ if(ggH){ if(SIGNAL_SCALE!=1){ leg->AddEntry(ggH , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" ); } else{ leg->AddEntry(ggH , "H(125 GeV)#rightarrow#tau#tau" , "L" ); } } } leg->AddEntry(data , "observed" , "LP"); leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); if(Zmm){ leg->AddEntry(Zmm , "Z#rightarrow#mu#mu" , "F" ); } if(EWK1){ leg->AddEntry(EWK , "Z#rightarrow ee" , "F" ); leg->AddEntry(EWK1 , "electroweak" , "F" ); } else{ leg->AddEntry(EWK , "electroweak" , "F" ); } leg->AddEntry(ttbar, "t#bar{t}" , "F" ); if(Fakes){ leg->AddEntry(Fakes, "QCD" , "F" ); } if(errorBand){ leg->AddEntry(errorBand, "bkg. uncertainty" , "F" ); } leg->Draw(); /* TPaveText* ext0 = new TPaveText(0.50, lower_bound-0.08, 0.70, lower_bound-0.03, "NDC"); ext0->SetBorderSize( 0 ); ext0->SetFillStyle( 0 ); ext0->SetTextAlign( 12 ); ext0->SetTextSize ( 0.035 ); ext0->SetTextColor( 1 ); ext0->SetTextFont ( 42 ); ext0->AddText("CMS Preliminary"); ext0->Draw(); TPaveText* ext1 = new TPaveText(0.50, lower_bound-0.13, 0.70, lower_bound-0.08, "NDC"); ext1->SetBorderSize( 0 ); ext1->SetFillStyle( 0 ); ext1->SetTextAlign( 12 ); ext1->SetTextSize ( 0.035 ); ext1->SetTextColor( 1 ); ext1->SetTextFont ( 42 ); ext1->AddText("#sqrt{s} = 7 TeV, L = 4.9 fb^{-1}"); ext1->Draw(); TPaveText* ext2 = new TPaveText(0.50, lower_bound-0.18, 0.70, lower_bound-0.13, "NDC"); ext2->SetBorderSize( 0 ); ext2->SetFillStyle( 0 ); ext2->SetTextAlign( 12 ); ext2->SetTextSize ( 0.035 ); ext2->SetTextColor( 1 ); ext2->SetTextFont ( 42 ); ext2->AddText("#sqrt{s} = 8 TeV, L = 19.4 fb^{-1}"); ext2->Draw(); TPaveText* ext3 = new TPaveText(0.50, lower_bound-0.23, 0.70, lower_bound-0.18, "NDC"); ext3->SetBorderSize( 0 ); ext3->SetFillStyle( 0 ); ext3->SetTextAlign( 12 ); ext3->SetTextSize ( 0.035 ); ext3->SetTextColor( 1 ); ext3->SetTextFont ( 42 ); ext3->AddText("H#rightarrow#tau#tau"); ext3->Draw(); */ /* prepare output */ std::string newName = std::string(inputfile).substr(0, std::string(inputfile).find(".root")); //canv->Print(TString::Format("%s%s.png", newName.c_str(), log ? "_LOG" : "")); //canv->Print(TString::Format("%s%s.pdf", newName.c_str(), log ? "_LOG" : "")); //canv->Print(TString::Format("%s%s.eps", newName.c_str(), log ? "_LOG" : "")); canv->Print(TString::Format("%s.png", newName.c_str())); canv->Print(TString::Format("%s.pdf", newName.c_str())); canv->Print(TString::Format("%s.eps", newName.c_str())); }