// 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 //HTT_MT_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="muTau_$CATEGORY") HTT_MT_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., TString datacard="htt_mt_1_7TeV", string 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 = ""; const char* category_extra = ""; const char* category_extra2 = ""; if(std::string(directory) == std::string("muTau_0jet_low" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_0jet_low" )){ category_extra = "0-jet low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("muTau_0jet_medium" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_0jet_medium" )){ category_extra = "0-jet low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("muTau_0jet_high" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_0jet_high" )){ category_extra = "0-jet high p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("muTau_1jet_medium" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_1jet_medium" )){ category_extra = "1-jet low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("muTau_1jet_high_lowhiggs" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_1jet_high_lowhiggs" )){ category_extra= "1-jet high p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("muTau_1jet_high_mediumhiggs")){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_1jet_high_mediumhiggs")){ category_extra= "1-jet high p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("muTau_1jet_high_mediumhiggs")){ category_extra2= "boosted"; } if(std::string(directory) == std::string("muTau_vbf" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_vbf" )){ category_extra = "VBF tag"; } if(std::string(directory) == std::string("muTau_vbf_loose" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_vbf_loose" )){ category_extra = "Loose VBF tag"; } if(std::string(directory) == std::string("muTau_vbf_tight" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_vbf_tight" )){ category_extra = "Tight VBF tag"; } if(std::string(directory) == std::string("muTau_nobtag" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_nobtag" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("muTau_btag" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_btag" )){ category_extra = "b-tag"; } if(std::string(directory) == std::string("muTau_nobtag_low" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_nobtag_low" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("muTau_nobtag_low" )){ category_extra2 = "low"; } if(std::string(directory) == std::string("muTau_nobtag_medium" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_nobtag_medium" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("muTau_nobtag_medium" )){ category_extra2 = "medium"; } if(std::string(directory) == std::string("muTau_nobtag_high" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_nobtag_high" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("muTau_nobtag_high" )){ category_extra2 = "high"; } if(std::string(directory) == std::string("muTau_btag_low" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_btag_low" )){ category_extra = "b-tag"; } if(std::string(directory) == std::string("muTau_btag_low" )){ category_extra2 = "low"; } if(std::string(directory) == std::string("muTau_btag_high" )){ category = "#mu#tau_{h}"; } if(std::string(directory) == std::string("muTau_btag_high" )){ category_extra = "b-tag"; } if(std::string(directory) == std::string("muTau_btag_high" )){ category_extra2 = "high"; } 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 // open example histogram file 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* 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(222,90,106), 1001); TH1F* EWK3 = refill((TH1F*)input->Get(TString::Format("%s/ZL" , directory)), "ZL" ); InitHist(EWK3 , "", "", TColor::GetColor(222,90,106), 1001); #else TH1F* EWK2 = refill((TH1F*)input->Get(TString::Format("%s/ZLL" , directory)), "ZLL"); InitHist(EWK2 , "", "", TColor::GetColor(222,90,106), 1001); #endif 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* 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); TH1F* ggH_SM125= refill((TH1F*)input->Get(TString::Format("%s/ggH_SM125" , directory)), "ggH_SM125"); InitHist(ggH_SM125, "", "", kGreen+2, 1001); TH1F* qqH_SM125= refill((TH1F*)input->Get(TString::Format("%s/qqH_SM125" , directory)), "qqH_SM125"); InitHist(qqH_SM125, "", "", kGreen+2, 1001); TH1F* VH_SM125 = refill((TH1F*)input->Get(TString::Format("%s/VH_SM125" , directory)), "VH_SM125" ); InitHist(VH_SM125, "", "", kGreen+2, 1001); #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(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){ /* Fakes = refill(shape_histos(Fakes, datacard, "QCD"), "QCD"); EWK1 = refill(shape_histos(EWK1, datacard, "W"), "W"); #ifdef EXTRA_SAMPLES EWK2 = refill(shape_histos(EWK2, datacard, "ZJ"), "ZJ"); EWK3 = refill(shape_histos(EWK3, datacard, "ZL"), "ZL"); #else // EWK2 = refill(shape_histos(EWK2, datacard, "ZLL"), "ZLL"); #endif 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$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(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 #ifdef MSSM qqH_SM125->Add(ggH_SM125); VH_SM125->Add(qqH_SM125); Fakes->Add(VH_SM125); #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(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"); Fakes->Draw("histsame"); #ifdef MSSM VH_SM125->Draw("histsame"); #endif $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"); #ifdef MSSM VH_SM125->Draw("histsame"); #endif $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{#mu}#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}_{mod+} 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(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(EWK , "Electroweak" , "F" ); leg->AddEntry(Fakes, "QCD" , "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, 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("EWK" ); ttbar->Write("ttbar" ); Ztt ->Write("Ztt" ); #ifdef MSSM ggH ->Write("ggH" ); bbH ->Write("bbH" ); ggH_SM125->Write("ggH_SM125"); qqH_SM125->Write("qqH_SM125"); VH_SM125 ->Write("VH_SM125"); #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 HTT_TT_X(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_extra = ""; if(std::string(directory) == std::string("tauTau_1jet" )){ category_extra = "1 jet"; } if(std::string(directory) == std::string("tauTau_vbf" )){ category_extra = "2 jet (VBF)"; } if(std::string(directory) == std::string("tauTau_nobtag" )){ category_extra = "No B-Tag"; } if(std::string(directory) == std::string("tauTau_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";} #ifdef MSSM if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, #sqrt{s} = 8 TeV, L = 19.8 fb^{-1}, H #rightarrow #tau #tau";} #endif // open example histogram file 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, "", "", kMagenta-10, 1001); TH1F* EWK1 = refill((TH1F*)input->Get(TString::Format("%s/W" , directory)), "W" ); InitHist(EWK1 , "", "", kRed + 2, 1001); 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); 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.; // ggHScale = ($MSSM_SIGNAL_ggH_xseff_A + $MSSM_SIGNAL_ggH_xseff_hH); // bbHScale = ($MSSM_SIGNAL_bbH_xseff_A + $MSSM_SIGNAL_bbH_xseff_hH); TH1F* ggH = refill((TH1F*)input2->Get(TString::Format("%s/ggH$MA", directory)), "ggH"); InitSignal(ggH); ggH->Scale($TANB); //ggH ->Scale(ggHScale); TH1F* bbH = refill((TH1F*)input2->Get(TString::Format("%s/bbH$MA", directory)), "bbH"); InitSignal(bbH); bbH->Scale($TANB); //bbH ->Scale(bbHScale); #else 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 #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(EWK1 ); ref->Add(EWK2 ); //ref->Add(EWK3 ); 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(); //unscaled[1]+= EWK3 ->Integral(); unscaled[2] = ttbar->Integral(); unscaled[3] = Ztt ->Integral(); #ifdef MSSM unscaled[4] = ggH ->Integral(); unscaled[5] = bbH ->Integral(); unscaled[6] = 0; #else unscaled[4] = ggH ->Integral(); unscaled[5] = qqH ->Integral(); unscaled[6] = VH ->Integral(); #endif if(scaled){ rescale(Fakes, 7); rescale(EWK1 , 3); rescale(EWK2 , 4); //rescale(EWK3 , 5); rescale(EWK , 6); rescale(ttbar, 2); rescale(Ztt , 1); #ifdef MSSM rescale(ggH , 8); rescale(bbH , 9); #else rescale(ggH , 8); rescale(qqH , 9); rescale(VH ,10); #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() //+EWK3 ->Integral() )/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 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 EWK1 ->Add(Fakes); EWK2 ->Add(EWK1 ); //EWK3 ->Add(EWK2 ); //EWK ->Add(EWK3 ); EWK ->Add(EWK2 ); ttbar->Add(EWK ); Ztt ->Add(ttbar); 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(0, data->FindBin(500)); } 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 ggH ->Draw("histsame"); } else{ ggH ->Draw("histsame"); Ztt ->Draw("histsame"); ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{h}#tau_{h}", 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("#tau_{h}#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}=$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.45, 0.65, 0.95, 0.88); SetLegendStyle(leg); leg->AddEntry(ggH , "#phi#rightarrow#tau#tau" , "L" ); #else TLegend* leg = new TLegend(0.50, 0.65, 0.95, 0.88); SetLegendStyle(leg); 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 #ifdef ASIMOV leg->AddEntry(data , "sum(bkg) + SM125 GeV signal" , "LP"); #else leg->AddEntry(data , "observed" , "LP"); #endif 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); InitSignal(scales[4]); InitSignal(scales[5]); InitSignal(scales[6]); 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"); scales[4]->Draw("same"); scales[5]->Draw("same"); scales[6]->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" : "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 ? "pre" : "post", 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 ggH ->Write("ggH" ); bbH ->Write("bbH" ); #else ggH ->Write("ggH" ); qqH ->Write("qqH" ); VH ->Write("VH" ); #endif output->Close(); }
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 HTT_MT_X(bool scaled=true, bool log=true, float min=0.1, float max=2000., const char* inputfile="root/$HISTFILE", const char* directory="muTau_$CATEGORY") { // defining the common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); const char* dataset; if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "#sqrt{s} = 7 TeV, L = 4.9 fb^{-1}";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "#sqrt{s} = 8 TeV, L = 5.0 fb^{-1}";} // 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 TH1F* ggH = refill((TH1F*)input->Get(TString::Format("%s/ggH120", directory)), "ggH"); InitSignal(ggH); ggH ->Scale(5); TH1F* bbH = refill((TH1F*)input->Get(TString::Format("%s/bbH120", directory)), "bbH"); InitSignal(bbH); bbH ->Scale(5); #else TH1F* ggH = refill((TH1F*)input->Get(TString::Format("%s/ggH125", directory)), "ggH"); InitSignal(ggH); ggH ->Scale(5); TH1F* qqH = refill((TH1F*)input->Get(TString::Format("%s/qqH125", directory)), "qqH"); InitSignal(qqH); qqH ->Scale(5); TH1F* VH = refill((TH1F*)input->Get(TString::Format("%s/VH125" , directory)), "VH" ); InitSignal(VH ); VH ->Scale(5); #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 unscaled[4] = ggH ->Integral(); unscaled[5] = qqH ->Integral(); unscaled[6] = VH ->Integral(); #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 rescale(ggH , 8); rescale(qqH , 9); rescale(VH ,10); #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 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 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 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); } // reduce the axis range if necessary //data->GetXaxis()->SetRange(0, 28); data->SetNdivisions(505); data->SetMinimum(min); data->SetMaximum(max); data->Draw("e"); TH1F* errorBand = (TH1F*)Ztt ->Clone(); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(1); errorBand ->SetFillStyle(3013); if(log){ Ztt ->Draw("histsame"); ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); ggH ->Draw("histsame"); $DRAW_ERROR } else{
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 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())); }
int main(int argc, char *argv[]) { int ret = 1; g_main_window=NULL; /* for UpdateMenuLink (check "first call") */ g_quality_dialog = NULL; /* for UpdateMenuLink (check "first call") */ bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset( PACKAGE, "UTF-8" ); textdomain(PACKAGE); gtk_set_locale(); // Set gtk resource file. SetGtkResourceFile(); gtk_init(&argc, &argv); #ifdef USE_LIB_GLADE // Initialize the glade library. glade_init(); #endif // Parse options. InitOption(argc, argv); // Set the directory name for storing keytext files. SetKeyTextDir(PACKAGE_DATA_DIR); #ifndef USE_LIB_GLADE // Set the directory name for storing xpm files. SetPixmapDir(PACKAGE_DATA_DIR); #endif // Load fontset. //g_main_font = LoadFontSet(); g_main_font = NULL; // Initialize signal control level. InitSignal(); // Load the glade and keytext file. if( LoadResources() ) { // Initialize databases. InitDataBase(g_model_name); // Initialize printint type table. InitPrintingType(); // Create main dialog, and realize it. g_main_window = CreateMainWindow(); gtk_widget_realize(UI_DIALOG(g_main_window)->window); // Create dialogs. CreateDialogs(); // Connect signal handlers. ConnectSignalHandlers(); // Update widgets. DisableSignal(); UpdateWidgets(UI_DIALOG(g_main_window)->window, NULL); EnableSignal(); // Set window title. snprintf(g_window_title, sizeof(g_window_title), "Canon %s", GetDispModelName()); //Ver.2.90(s) gtk_window_set_title( GTK_WINDOW(UI_DIALOG(g_main_window)->window), g_window_title); // Show widgets depend on model. ShowModelDependWidgets(g_main_window); gtk_widget_show(UI_DIALOG(g_main_window)->window); gtk_main(); ret = 0; // Dispose dialogs. DisposeDialogs(); // Dispose main dialog. DisposeDialog(UI_DIALOG(g_main_window)); // Free databases. FreeDataBase(); // Free resources. FreeResources(); } // Free Gdk resource. if( g_main_font ) gdk_font_unref(g_main_font); // Free option strings. FreeOption(); return ret; }
int main(int argc, char* argv[], char* envp[]) { // 로그 초기화 LogSystem::setSubstitutedValue("logfile", "Login"); LogSystem::configureXml("../log.xml"); PrintExcuteInfo::Instance()->PrintStart("Login", LC_LOCAL_STRING); if (InitSignal(process_after_signal) == false) return 1; if (!gserver.LoadSettingFile()) { LOG_INFO("Load Setting File Error!!"); exit(0); } if (!gserver.ConnectDB()) { LOG_INFO("Connect DB Error!!"); exit(0); } if (!gserver.InitGame()) return 1; mysql_close(&gserver.m_dbdata); #if !defined(CIRCLE_WINDOWS) && defined(DEV_GAMIGO_HTTPS) //char * ipAddr = inet_ntoa( *gserver.GetBindAddr() ); //if( strcmp(ipAddr, "10.1.90.31") !=0 && strcmp(ipAddr, "10.1.90.34") !=0 && strcmp(ipAddr, "10.1.90.35") !=0 && strcmp(ipAddr, "101.79.53.208") !=0) if ( gserver.DoHttpsAuth() ) { CLCHttps gamigoAuth; if( gamigoAuth.Connect("https://chk.global.lc.gamigo.com/auth", "E8:E6:4C:1B:58:40:C9:70:A4:74:EB:F9:CF:C6:19:17:E3:F8:A7:DD") != CLCHttps::E_MATCH_FINGERPRINT ) { LOG_INFO("Connect Fingerprint Error"); return 1; } } #endif // Linux Lib 사용에 GER 만 적용, // Gamigo 요청 Https 인증 방식 LOG_INFO("Login Server Running..."); atexit (at_exit_exec); ////////////////////////////////////////////////////////////////////////// std::string bind_host = gserver.m_config.Find("Server", "IP"); if (bind_host == "ALL") bind_host = "0.0.0.0"; int bind_port = atoi(gserver.m_config.Find("Server", "Port")); if (bnf::instance()->CreateListen(bind_host, bind_port, 15, &gserver) == SessionBase::INVALID_SESSION_HANDLE) { puts("Login : can't bind listen session"); return 1; } bnf::instance()->CreateMSecTimer(1 * 1000, CServerTimer::instance()); CServerTimerPerMinute::instance()->Init(); MessengerInLogin::instance()->Connect(); #ifdef SERVER_AUTHENTICATION if (ServerAuthentication::instance()->isValidCompileTime() == false) return 1; #endif puts("Login server started..."); bnf::instance()->Run(); ////////////////////////////////////////////////////////////////////////// if (gserver.m_bshutdown) { remove(LOGIN_SERVER_OPEN_CHECK_FILENAME); FILE *fp = fopen (".shutdown", "w"); fclose (fp); } PrintExcuteInfo::Instance()->PrintEnd(); return 0; }
int main(int argc, char* argv[], char* envp[]) { if (!gserver.LoadSettingFile()) { puts("error load Setting File"); exit(0); } // 로그 초기화 std::string tstr = boost::str(boost::format("Connector_%1%") % gserver.m_config.Find("Server", "Number")); LogSystem::setSubstitutedValue("logfile", tstr.c_str()); LogSystem::configureXml("../log.xml"); PrintExcuteInfo::Instance()->PrintStart("Connector", LC_LOCAL_STRING); if (InitSignal(process_after_signal) == false) return 1; if (!gserver.ConnectDB()) { GAMELOG << init("SYS_ERR") << "Connect DB" << end; exit(0); } if (!gserver.InitGame()) { GAMELOG << init("SYS_ERR") << "Initialize Connector" << end; return 1; } ////////////////////////////////////////////////////////////////////////// // GameServer용 listen std::string bind_host = gserver.m_config.Find("Server", "IP"); if (bind_host == "ALL") bind_host = "0.0.0.0"; int bind_port = atoi(gserver.m_config.Find("Server", "Port")); if (bnf::instance()->CreateListen(bind_host, bind_port, 0, &gserver) == SessionBase::INVALID_SESSION_HANDLE) { puts("Connector : can't bind listen session"); return 1; } // 빌링 서버에 연결 gserver.m_billing.connect(); // HeartBeat timer bnf::instance()->CreateMSecTimer(1 * 1000, (void *)HeartBeatTimer::instance()); // alive timer to billing bnf::instance()->CreateMSecTimer(2 * 60 * 1000, (void *)ServerAliveTimer::instance()); #ifdef SERVER_AUTHENTICATION if (ServerAuthentication::instance()->isValidCompileTime() == false) return 1; #endif puts("Connect server started..."); bnf::instance()->Run(); ////////////////////////////////////////////////////////////////////////// gserver.Close(); if (gserver.m_bshutdown) { FILE *fp = fopen (".shutdown", "w"); fclose (fp); } PrintExcuteInfo::Instance()->PrintEnd(); return 0; }
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 HTT_MM_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., const char* inputfile="root/$HISTFILE", const char* directory="mumu_$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("mumu_0jet_low" )){ category_extra = "0 jet, low p_{T}"; } if(std::string(directory) == std::string("mumu_0jet_high" )){ category_extra = "0 jet, high p_{T}"; } if(std::string(directory) == std::string("mumu_boost_low" )){ category_extra = "1 jet, low p_{T}"; } if(std::string(directory) == std::string("mumu_boost_high")){ category_extra = "1 jet, high p_{T}"; } if(std::string(directory) == std::string("mumu_vbf" )){ category_extra = "2 jet (VBF)"; } if(std::string(directory) == std::string("mumu_nobtag" )){ category_extra = "No B-Tag"; } if(std::string(directory) == std::string("mumu_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, 18.7 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 TFile* input = new TFile(inputfile); TH1F* ZTT = refill((TH1F*)input->Get(TString::Format("%s/ZTT" , directory)), "ZTT"); InitHist(ZTT, "", "", kOrange-4, 1001); TH1F* ZMM = refill((TH1F*)input->Get(TString::Format("%s/ZMM" , directory)), "ZMM"); InitHist(ZMM , "", "", 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 float ggHScale = 1., bbHScale = 1.; ggHScale = ($MSSM_SIGNAL_ggH_xseff_A + $MSSM_SIGNAL_ggH_xseff_hH); bbHScale = ($MSSM_SIGNAL_bbH_xseff_A + $MSSM_SIGNAL_bbH_xseff_hH); // 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.49*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*)ZTT->Clone("ref"); ref->Add(ZMM ); ref->Add(TTJ); ref->Add(QCD ); ref->Add(Dibosons); ref->Add(WJets ); double unscaled[9]; unscaled[0] = ZTT->Integral(); unscaled[1] = ZMM ->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(ZMM, 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-ZMM" , "", 9, 0, 9); scales[1]->SetBinContent(2, unscaled[1]>0 ? (ZMM ->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[4]-1.) : 0.); scales[7] = new TH1F("scales-bbH" , "", 9, 0, 9); scales[7]->SetBinContent(8, unscaled[7]>0 ? (bbH ->Integral()/unscaled[5]-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 ZMM->Add(ZTT); QCD->Add(ZMM); TTJ->Add(QCD); Dibosons->Add(TTJ); WJets->Add(Dibosons); 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(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(WJets, log))); data->Draw("e"); TH1F* errorBand = (TH1F*)WJets ->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){ WJets->Draw("histsame"); //Dibosons->Draw("histsame"); TTJ->Draw("histsame"); QCD->Draw("histsame"); ZMM->Draw("histsame"); ZTT->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL ggH->Draw("histsame"); #endif } else{ #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif WJets->Draw("histsame"); //Dibosons->Draw("histsame"); TTJ->Draw("histsame"); QCD->Draw("histsame"); ZMM->Draw("histsame"); ZTT->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{#mu}#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 ); chan->AddText("#mu#mu"); 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(ZMM , "Z#rightarrow#mu#mu" , "F" ); leg->AddEntry(TTJ , "t#bar{t}" , "F" ); leg->AddEntry(QCD , "QCD" , "F" ); //leg->AddEntry(Dibosons , "Dibosons" , "F" ); leg->AddEntry(WJets, "electroweak" , "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(WJets); 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*) WJets->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], "", "", kGreen - 4, 1001); InitHist (scales[1], "", "", kYellow - 4, 1001); InitHist (scales[2], "", "", kMagenta-10, 1001); InitHist (scales[3], "", "", kRed + 2, 1001); InitHist (scales[4], "", "", kBlue - 8, 1001); InitHist (scales[5], "", "", kOrange - 4, 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{ZMM}" ); 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(+1.5); scales[0]->SetMinimum(-1.5); 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"); scales[5]->Draw("same"); #ifndef DROP_SIGNAL scales[6]->Draw("same"); scales[7]->Draw("same"); scales[8]->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"); ZTT->Write("Ztt" ); ZMM->Write("Zmm" ); 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(); }
void bbtt_upg_mt(std::string var,int nbins, double xmin, double xmax,std::string xtitle, std::string ytitle, 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}; TFile *outDC = new TFile("hh_mt_inputs.root","RECREATE"); //SetStyle(); gStyle->SetLineStyleString(11,"20 10"); setTDRStyle(); TH1::SetDefaultSumw2(1); std::string dir = "/data/blue/Bacon/029a/Upgrade/sep-2-bbtt/"; std::stringstream scale; scale << sigscale; //Cut definitions double luminosity = 3000; std::stringstream lumi; lumi << luminosity; std::string objcut = "(tauCat1==1 && tauCat2==3 && ptTau1>30 && ptTau2>30 && (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.5 && ptTrk1>0)";//*(tauIso2<0.15)"; std::string jetcut = objcut+"*(m_svpileup>100 && m_svpileup<150 && mBB1>90 && mBB1<130 && mt2pileup>100)"; //std::string jetcut = objcut+"*(m_svpileup>100 && m_svpileup<150 && mBB1>90 && mBB1<130)"; //std::string jetcut = objcut+"*(1.0)"; //signal region std::string mccut = jetcut+"*eventWeight*"+lumi.str(); std::string sigcut = jetcut+"*eventWeight*"+lumi.str(); std::string zjetcut = jetcut+"*eventWeight*(eventType!=3&&eventType!=1)*"+lumi.str(); std::string wjetcut = jetcut+"*eventWeight*(eventType==3&&eventType!=1)*"+lumi.str(); std::string ewkcut = jetcut+"*eventWeight*(eventType!=1)*"+lumi.str(); std::string vbfcut = jetcut+"*eventWeight*49470*0.0632*"+lumi.str(); //-------------------------------------------------------------------------- //Get the trees TTree *hhtree = load(dir+"gFHHTobbtautau.root"); TTree *hhtree_m1 = load(dir+"gFHHTobbtautaulam1m.root"); TTree *hhtree_m5 = load(dir+"gFHHTobbtautaulam5m.root"); TTree *hhtree_0 = load(dir+"gFHHTobbtautaulam0.root"); TTree *hhtree_p5 = load(dir+"gFHHTobbtautaulam5p.root"); TTree *hhtree_vbf = load("/data/blue/Bacon/029a/Upgrade/sep-10-bbtt/vbfHHTobbtautau.root"); TTree *tttree = load(dir+"tt.root"); TTree *vbfhtree = load(dir+"VBFHToTauTau.root"); TTree *gfhtree = load(dir+"ggFHToTauTau.root"); TTree *assohtree = load(dir+"vH_ttH.root"); TTree *vjettree = load(dir+"Bjets.root"); TTree *ewktree = load(dir+"ewk.root"); //------------------------------------------------------------------------- //Get histograms TCanvas *canv0 = MakeCanvas("canv", "histograms", 600, 600); canv0->cd(); std::string vardraw; TH1F *Ztt; if(hist) Ztt = new TH1F("DY","",nbins,xmin,xmax); else Ztt = new TH1F("DY","",13, massLEdges); 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; if(hist) ttbar = new TH1F("TTbar","",nbins,xmin,xmax); else ttbar = new TH1F("TTbar","",13, massLEdges); 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; if(hist) wjets= new TH1F("Wjets","",nbins,xmin,xmax); else wjets = new TH1F("Wjets","",13, massLEdges); 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; if(hist) ewk = new TH1F("Ewk","",nbins,xmin,xmax); else ewk = new TH1F("Ewk","",13,massLEdges); 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; if(hist) vbfh = new TH1F("VBFH","",nbins,xmin,xmax); else vbfh = new TH1F("VBFH","",13,massLEdges); vardraw = var+">>"+"VBFH"; vbfhtree->Draw(vardraw.c_str(),vbfcut.c_str()); InitHist(vbfh, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(250,202,255), 1001); TH1F *ggh; if(hist) ggh = new TH1F("GGH","",nbins,xmin,xmax); else ggh = new TH1F("GGH","",13,massLEdges); 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 *assoh; if(hist) assoh = new TH1F("AH","",nbins,xmin,xmax); else assoh = new TH1F("AH","",13,massLEdges); vardraw = var+">>"+"AH"; assohtree->Draw(vardraw.c_str(),mccut.c_str()); InitHist(assoh, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(250,202,255), 1001); TH1F *smhh; if(hist) smhh= new TH1F("SMhh","",nbins,xmin,xmax); else smhh= new TH1F("SMhh","",13,massLEdges); vardraw = var+">>"+"SMhh"; hhtree->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(smhh); smhh->SetLineColor(kBlack); TH1F *hh_0 = new TH1F("hh_0","",nbins,xmin,xmax); vardraw = var+">>"+"hh_0"; hhtree_0->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(hh_0); hh_0->SetLineColor(kBlack); TH1F *hh_m1; if(hist) hh_m1 = new TH1F("hh_m1","",nbins,xmin,xmax); else hh_m1 = new TH1F("hh_m1","",13,massLEdges); vardraw = var+">>"+"hh_m1"; hhtree_m1->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(hh_m1); hh_m1->SetLineColor(kBlack); TH1F *hh_m5; if(hist) hh_m5 = new TH1F("hh_m5","",nbins,xmin,xmax); else hh_m5 = new TH1F("hh_m5","",13,massLEdges); vardraw = var+">>"+"hh_m5"; hhtree_m5->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(hh_m5); hh_m5->SetLineColor(kBlack); TH1F *hh_p5; if(hist) hh_p5= new TH1F("hh_p5","",nbins,xmin,xmax); else hh_p5= new TH1F("hh_p5","",13,massLEdges); vardraw = var+">>"+"hh_p5"; hhtree_p5->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(hh_p5); hh_p5->SetLineColor(kBlack); TH1F *hh_vbf; if(hist) hh_vbf= new TH1F("hh_vbf","",nbins,xmin,xmax); else hh_vbf= new TH1F("hh_vbf","",13,massLEdges); vardraw = var+">>"+"hh_vbf"; hhtree_vbf->Draw(vardraw.c_str(),sigcut.c_str()); InitSignal(hh_vbf); hh_vbf->SetLineColor(kBlue); delete canv0; //for(int i0 = 0; i0 < ewk->GetNbinsX()+1; i0++) // if(ewk->GetBinContent(i0) == 0) // ewk->SetBinError(i0,2.8); //--------------------------------------------------------------------------- //Print out the yields Double_t error=999; Double_t sigN=0; Double_t sigSig=0; Double_t bgdN=0; Double_t bgdSig=0; //ofstream outfile; //outfile.open("yields.txt"); //outfile << "Yields for the signal region." << std::endl; cout << jetcut << endl; cout << "SM hh " << smhh->IntegralAndError(0,smhh->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; cout << " VBF HH " << hh_vbf->IntegralAndError(0,hh_vbf->GetNbinsX(),error) << "+/-"; sigN+=smhh->IntegralAndError(0,smhh->GetNbinsX(),error); sigSig+=error; cout << error << endl; error=999; cout << "ttbar " << ttbar->IntegralAndError(0,ttbar->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=ttbar->IntegralAndError(0,ttbar->GetNbinsX(),error);bgdSig+=error*error; cout << "Ztt " << Ztt->IntegralAndError(0,Ztt->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=Ztt->IntegralAndError(0,Ztt->GetNbinsX(),error);bgdSig+=error*error; cout << "ewk " << ewk->IntegralAndError(0,ewk->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=ewk->IntegralAndError(0,ewk->GetNbinsX(),error);bgdSig+=error*error; cout << "wjets " << wjets->IntegralAndError(0,wjets->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=wjets->IntegralAndError(0,wjets->GetNbinsX(),error);bgdSig+=error*error; cout << "ggH " << ggh->IntegralAndError(0,ggh->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=ggh->IntegralAndError(0,ggh->GetNbinsX(),error);bgdSig+=error*error; cout << "vbfH " << vbfh->IntegralAndError(0,vbfh->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=vbfh->IntegralAndError(0,vbfh->GetNbinsX(),error);bgdSig+=error*error; cout << "vH/ttH " << assoh->IntegralAndError(0,assoh->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; bgdN+=assoh->IntegralAndError(0,assoh->GetNbinsX(),error); bgdSig+=error*error; cout << "S = " << sigN << "+/-" << sigSig << endl; cout << "B = " << bgdN << "+/-" << TMath::Sqrt(bgdSig) << endl; cout << "S/sqrt(B) = " << sigN/TMath::Sqrt(bgdN) << endl; //-------------------------------------------------------------------------- //outfile.close(); outDC->cd(); TDirectory* lTD = outDC->mkdir("mutau"); 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(); assoh->SetName("assoH"); assoh->SetTitle("assoH"); assoh->Write(); smhh->SetName("ggHH"); smhh->SetTitle("ggHH"); smhh->Write(); hh_0->SetName("lam0"); hh_0->SetTitle("lam0"); hh_0->Write(); hh_m5->SetName("lamm5"); hh_m5->SetTitle("lamm5"); hh_m5->Write(); hh_m1->SetName("lamm1"); hh_m1->SetTitle("lamm1"); hh_m1->Write(); hh_p5->SetName("lamp5"); hh_p5->SetTitle("lamp5"); hh_p5->Write(); hh_vbf->SetName("qqHH"); hh_vbf->SetTitle("qqHH"); hh_vbf->Write(); outDC->Close(); //stack some histtograms together vbfh->Add(ggh); vbfh->Add(assoh); cout << "Single H " << vbfh->IntegralAndError(0,vbfh->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; wjets->Add(ewk); cout << "Total Electroweak " << wjets->IntegralAndError(0,wjets->GetNbinsX(),error) << "+/-"; cout << error << endl; error=999; //----------------------------------------------------------------------- smhh->Scale(sigscale); //Draw the histograms TCanvas *canv = MakeCanvas("canv", "histograms", 800, 600); canv->cd(); wjets->Add(ttbar); Ztt->Add(wjets); vbfh->Add(Ztt); //Error band stat TH1F* errorBand = (TH1F*)vbfh->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; // } //} vbfh->SetMaximum(1.0*std::max(maximum(vbfh, 0), maximum(smhh, 0))); //blind(data,75,150); //data->Draw("e"); vbfh->Draw("hist"); Ztt->Draw("histsame"); wjets->Draw("histsame"); //ggh->Draw("histsame"); ttbar->Draw("histsame"); //qcd->Draw("histsame"); //data->Draw("esame"); errorBand->Draw("e2same"); smhh->Draw("histsame"); canv->RedrawAxis(); //canv->SetLogy(1); //--------------------------------------------------------------------------- //Adding a legend TLegend* leg = new TLegend(0.65, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(smhh , TString::Format("%.0f#timeshh#rightarrow#tau#tau bb", sigscale) , "L" ); leg->AddEntry(vbfh , "SM H#rightarrow#tau#tau" , "F" ); leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(wjets , "Electroweak" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(errorBand,"bkg. uncertainty","F"); leg->Draw(); //--------------------------------------------------------------------------- //CMS_lumi_v2( canv, 14, 11 ); //CMS preliminary //const char* dataset = "CMS Simulation, 3000 fb^{-1} at 14 TeV"; const char* category = ""; //CMSPrelim(dataset, "#tau_{#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+"_mt.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 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 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 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_obj(std::string var="ptTau1", std::string cut="(ptTau2>45 && abs(etaTau1)<4.0 && abs(etaTau2)<4.0)", int chan_cat=1, int yTau=0, int yB=1, int nbins=10, double xmin=0, double xmax=500,std::string xtitle="leading #tau p_{T}", std::string ytitle="Events") { SetStyle(); gStyle->SetLineStyleString(11,"20 10"); TH1::SetDefaultSumw2(1); std::string dir = "/afs/cern.ch/work/j/jlawhorn/public/comb_ntuples/"; double sigscale = 1000; 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 ttcut = "(tauCat1==1 && tauCat2==1 && bTag1>0 && bTag2>0 && ptTau1>45 && ptTau2>45)"; std::string mtcut = "((tauCat1==1 && tauCat2==3)||(tauCat2==1 && tauCat1==3))*(bTag1>0 && bTag2>0 && ptTau1>30 && ptTau2>30)"; std::string etcut = "((tauCat1==1 && tauCat2==2)||(tauCat2==1 && tauCat1==2))*(bTag1>0 && bTag2>0 && ptTau1>30 && ptTau2>30)"; std::string emcut = "((tauCat1==3 && tauCat2==2)||(tauCat2==3 && tauCat1==2))*(bTag1>0 && bTag2>0 && ptTau1>30 && ptTau2>30)"; std::string taucut = "(abs(etaTau1)<4.0 && abs(etaTau2)<4.0)"; std::string bcut = "(ptB1>30 && ptB2>30 && abs(etaB1)<4.0 && abs(etaB2)<4.0)"; std::string optcut = cut; if (chan_cat==0) { //tt optcut = cut+"*"+ttcut; if (yTau==1) optcut+="*"+taucut+"*(ptTau1>45 && ptTau2>45)"; } else if (chan_cat==1) { //mt optcut = cut+"*"+mtcut; if (yTau==1) optcut+="*"+taucut+"*(ptTau1>30 && ptTau2>30)"; } else if (chan_cat==2) { //et optcut = cut+"*"+etcut; if (yTau==1) optcut+="*"+taucut+"*(ptTau1>30 && ptTau2>30)"; } else if (chan_cat==3) { //em optcut = cut+"*"+emcut; if (yTau==1) optcut+="*"+taucut+"*(ptTau1>30 && ptTau2>30)"; } if (yB==1) optcut+="*"+bcut; //cout << optcut << endl; //signal region std::string hhcut = optcut+"*"+scale.str()+"*eventWeight*(1)*"+lumi.str(); std::string ttbarcut = optcut+"*eventWeight*(1)*"+lumi.str(); std::string hcut = optcut+"*eventWeight*(1)*"+lumi.str(); std::string zjetcut = optcut+"*eventWeight*(eventType==4)*"+lumi.str(); std::string ewkcut = optcut+"*eventWeight*(eventType!=4)*"+lumi.str(); //-------------------------------------------------------------------------- //Get the trees TTree *ttbartree = load(dir+"tt.root"); TTree *htree = load(dir+"H.root"); TTree *ewktree = load(dir+"EWK.root"); TTree *sigtree = load(dir+"HHToTTBB_14TeV.root"); //------------------------------------------------------------------------- //Get histograms TCanvas *canv0 = MakeCanvas("canv", "histograms", 600, 600); canv0->cd(); std::string vardraw; TH1F *sig = new TH1F("HH","",nbins,xmin,xmax); vardraw = var+">>"+"HH"; sigtree->Draw(vardraw.c_str(),hhcut.c_str()); InitSignal(sig); sig->SetLineColor(kBlack); TH1F *ttbar = new TH1F("TTbar","",nbins,xmin,xmax); vardraw = var+">>"+"TTbar"; ttbartree->Draw(vardraw.c_str(),ttbarcut.c_str()); InitHist(ttbar, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(155,152,204), 1001); TH1F *hbg = new TH1F("H","",nbins,xmin,xmax); vardraw = var+">>"+"H"; htree->Draw(vardraw.c_str(),hcut.c_str()); InitHist(hbg, xtitle.c_str(), ytitle.c_str(), TColor::GetColor(141,201,159), 1001); TH1F *zjet = new TH1F("Zjets","",nbins,xmin,xmax); vardraw = var+">>"+"Zjets"; ewktree->Draw(vardraw.c_str(),zjetcut.c_str()); InitHist(zjet, 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(248,206,104), 1001); cout << sig->GetEntries() << endl; cout << ttbar->GetEntries() << endl; cout << hbg->GetEntries() << endl; cout << zjet->GetEntries() << endl; cout << ewk->GetEntries() << endl; delete canv0; //----------------------------------------------------------------------- //Draw the histograms TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); zjet->Add(ewk); hbg->Add(zjet); ttbar->Add(hbg); //Error band stat TH1F* errorBand = (TH1F*)sig ->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.2*std::max(maximum(ttbar, 0), maximum(ewk, 0))); //blind(sig,75,150); ttbar->Draw("hist"); hbg->Draw("histsame"); zjet->Draw("histsame"); ewk->Draw("histsame"); sig->Draw("histsame"); //errorBand->Draw("e2same"); canv->RedrawAxis(); //--------------------------------------------------------------------------- //Adding a legend TLegend* leg = new TLegend(0.53, 0.73, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(sig , TString::Format("%.0f#timeshh#rightarrow#tau#tau bb", sigscale) , "L"); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(hbg , "H" , "F" ); leg->AddEntry(zjet , "Z+jets" , "F" ); leg->AddEntry(ewk , "EWK" , "F" ); //leg->AddEntry(errorBand,"bkg. uncertainty","F"); leg->Draw(); //--------------------------------------------------------------------------- //CMS preliminary const char* dataset = "CMS Preliminary, HH#rightarrow bb#tau#tau, 3.0 ab^{-1} at 14 TeV"; char category[50]; if (chan_cat==0) sprintf(category,"#tau_{h}#tau_{h}"); if (chan_cat==1) sprintf(category,"#mu#tau_{h}"); if (chan_cat==2) sprintf(category,"e#tau_{h}"); if (chan_cat==3) sprintf(category,"e#mu"); //CMSPrelim(dataset, "#tau_{h}#tau_{h}", 0.17, 0.835); //CMSPrelim(dataset, "#tau_{h}#tau_{h}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); TPaveText* chan = new TPaveText(0.26, 0.77, 0.37, 0.85, "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 char outfile[50]; if (chan_cat==0) sprintf(outfile, "%s_tt.png", var.c_str()); if (chan_cat==1) sprintf(outfile, "%s_mt.png", var.c_str()); if (chan_cat==2) sprintf(outfile, "%s_et.png", var.c_str()); if (chan_cat==3) sprintf(outfile, "%s_em.png", var.c_str()); canv->Print(outfile); }