//************************************************* //* Main part to generate qqbar event //************************************************* int zha() { file = new TFile(outputfile,"RECREATE"); // Output file fin = new TFile(inputfile); // Input simulator data jsf = new JSFSteer(); gSystem->Load("libMyAnalysis.so"); jsf->SetInput(*fin); jsf->SetOutput(*file); InitHist(); // Initialize histogram jsf->Initialize(); // JSF Module initialization. jsf->BeginRun(1); // Set run number to 1. for(Int_t ev=1;ev<=maxevt;ev++){ Int_t ib; if( ! (ib=jsf->GetEvent(ev)) ) break ; if( ! jsf->Process(ev) ) break ; Analize(ev); // Event selection and do histogram } jsf->Terminate(); Terminate(); // Terminate process specific to this analysis file->Write(); }
void //HTT_ET_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="eleTau_$CATEGORY") HTT_ET_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., TString datacard="htt_et_1_7TeV", string inputfile="root/$HISTFILE", const char* directory="eleTau_$CATEGORY") { // defining the common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category = ""; const char* category_extra = ""; const char* category_extra2 = ""; if(std::string(directory) == std::string("eleTau_0jet_low" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_0jet_low" )){ category_extra = "0-jet low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_0jet_medium" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_0jet_medium" )){ category_extra = "0-jet low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_0jet_high" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_0jet_high" )){ category_extra = "0-jet high p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_1jet_medium" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_1jet_medium" )){ category_extra = "1-jet low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_1jet_high_lowhiggs" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_1jet_high_lowhiggs" )){ category_extra= "1-jet high p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_1jet_high_mediumhiggs")){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_1jet_high_mediumhiggs")){ category_extra= "1-jet high p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_1jet_high_mediumhiggs")){ category_extra2= "boosted"; } if(std::string(directory) == std::string("eleTau_vbf" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_vbf" )){ category_extra = "VBF tag"; } if(std::string(directory) == std::string("eleTau_vbf_loose" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_vbf_loose" )){ category_extra = "Loose VBF tag"; } if(std::string(directory) == std::string("eleTau_vbf_tight" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_vbf_tight" )){ category_extra = "Tight VBF tag"; } if(std::string(directory) == std::string("eleTau_nobtag" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_nobtag" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("eleTau_btag" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_btag" )){ category_extra = "b-tag"; } if(std::string(directory) == std::string("eleTau_nobtag_low" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_nobtag_low" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("eleTau_nobtag_low" )){ category_extra2 = "low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_nobtag_medium" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_nobtag_medium" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("eleTau_nobtag_medium" )){ category_extra2 = "medium p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_nobtag_high" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_nobtag_high" )){ category_extra = "no b-tag"; } if(std::string(directory) == std::string("eleTau_nobtag_high" )){ category_extra2 = "high p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_btag_low" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_btag_low" )){ category_extra = "b-tag"; } if(std::string(directory) == std::string("eleTau_btag_low" )){ category_extra2 = "low p_{T}^{#tau_{h}}"; } if(std::string(directory) == std::string("eleTau_btag_high" )){ category = "e#tau_{h}"; } if(std::string(directory) == std::string("eleTau_btag_high" )){ category_extra = "b-tag"; } if(std::string(directory) == std::string("eleTau_btag_high" )){ category_extra2 = "high p_{T}^{#tau_{h}}"; } const char* dataset; #ifdef MSSM if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 4.9 fb^{-1} (7 TeV)";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 19.7 fb^{-1} (8 TeV)";} #else if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS, 4.9 fb^{-1} at 7 TeV";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS, 19.7 fb^{-1} at 8 TeV";} #endif TFile* input = new TFile(inputfile.c_str()); #ifdef MSSM TFile* input2 = new TFile((inputfile+"_$MA_$TANB").c_str()); #endif TH1F* Fakes = refill((TH1F*)input->Get(TString::Format("%s/QCD" , directory)), "QCD"); InitHist(Fakes, "", "", TColor::GetColor(250,202,255), 1001); TH1F* EWK0 = refill((TH1F*)input->Get(TString::Format("%s/VV" , directory)), "VV" ); InitHist(EWK0 , "", "", TColor::GetColor(222,90,106), 1001); TH1F* EWK1 = refill((TH1F*)input->Get(TString::Format("%s/W" , directory)), "W" ); InitHist(EWK1 , "", "", TColor::GetColor(222,90,106), 1001); #ifdef EXTRA_SAMPLES TH1F* EWK2 = refill((TH1F*)input->Get(TString::Format("%s/ZJ" , directory)), "ZJ" ); InitHist(EWK2 , "", "", TColor::GetColor(100,182,232), 1001); TH1F* EWK = refill((TH1F*)input->Get(TString::Format("%s/ZL" , directory)), "ZL" ); InitHist(EWK , "", "", TColor::GetColor(100,182,232), 1001); #else TH1F* EWK = refill((TH1F*)input->Get(TString::Format("%s/ZLL" , directory)), "ZLL"); InitHist(EWK , "", "", TColor::GetColor(100,182,232), 1001); #endif TH1F* ttbar = refill((TH1F*)input->Get(TString::Format("%s/TT" , directory)), "TT" ); InitHist(ttbar, "", "", TColor::GetColor(155,152,204), 1001); TH1F* Ztt = refill((TH1F*)input->Get(TString::Format("%s/ZTT" , directory)), "ZTT"); InitHist(Ztt , "", "", TColor::GetColor(248,206,104), 1001); #ifdef MSSM TH1F* ggH = refill((TH1F*)input2->Get(TString::Format("%s/ggH$MA" , directory)), "ggH"); InitSignal(ggH); ggH->Scale($TANB); TH1F* bbH = refill((TH1F*)input2->Get(TString::Format("%s/bbH$MA" , directory)), "bbH"); InitSignal(bbH); bbH->Scale($TANB); #else #ifndef DROP_SIGNAL TH1F* ggH = refill((TH1F*)input->Get(TString::Format("%s/ggH125" , directory)), "ggH"); InitSignal(ggH); ggH->Scale(SIGNAL_SCALE); TH1F* qqH = refill((TH1F*)input->Get(TString::Format("%s/qqH125" , directory)), "qqH"); InitSignal(qqH); qqH->Scale(SIGNAL_SCALE); TH1F* VH = refill((TH1F*)input->Get(TString::Format("%s/VH125" , directory)), "VH" ); InitSignal(VH ); VH ->Scale(SIGNAL_SCALE); #endif #endif #ifdef ASIMOV TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs_asimov", directory)), "data", true); #else TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); #endif InitHist(data, "#bf{m_{#tau#tau} [GeV]}", "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)Fakes->Clone("ref"); ref->Add(EWK0 ); ref->Add(EWK1 ); #ifdef EXTRA_SAMPLES ref->Add(EWK2 ); #endif ref->Add(EWK ); ref->Add(ttbar); ref->Add(Ztt ); double unscaled[7]; unscaled[0] = Fakes->Integral(); unscaled[1] = EWK ->Integral(); unscaled[1]+= EWK0 ->Integral(); unscaled[1]+= EWK1 ->Integral(); #ifdef EXTRA_SAMPLES unscaled[1]+= EWK2 ->Integral(); #endif unscaled[2] = ttbar->Integral(); unscaled[3] = Ztt ->Integral(); #ifdef MSSM unscaled[4] = ggH ->Integral(); unscaled[5] = bbH ->Integral(); unscaled[6] = 0; #else #ifndef DROP_SIGNAL unscaled[4] = ggH ->Integral(); unscaled[5] = qqH ->Integral(); unscaled[6] = VH ->Integral(); #endif #endif if(scaled){ /* Fakes = refill(shape_histos(Fakes, datacard, "QCD"), "QCD"); EWK0 = refill(shape_histos(EWK0, datacard, "VV"), "VV"); EWK1 = refill(shape_histos(EWK1, datacard, "W"), "W"); #ifdef EXTRA_SAMPLES EWK2 = refill(shape_histos(EWK2, datacard, "ZJ"), "ZJ"); EWK = refill(shape_histos(EWK, datacard, "ZL"), "ZL"); #else // EWK = refill(shape_histos(EWK, datacard, "ZLL"), "ZLL"); #endif ttbar = refill(shape_histos(ttbar, datacard, "TT"), "TT"); Ztt = refill(shape_histos(Ztt, datacard, "ZTT"), "ZTT"); #ifdef MSSM ggH = refill(shape_histos(ggH, datacard, "ggH$MA"), "ggH$MA"); bbH = refill(shape_histos(bbH, datacard, "bbH$MA"), "bbH$MA"); #else #ifndef DROP_SIGNAL ggH = refill(shape_histos(ggH, datacard, "ggH"), "ggH"); qqH = refill(shape_histos(qqH, datacard, "qqH"), "qqH"); VH = refill(shape_histos(VH, datacard, "VH"), "VH"); #endif #endif */ rescale(Fakes, 7); rescale(EWK0 , 6); rescale(EWK1 , 3); #ifdef EXTRA_SAMPLES rescale(EWK2 , 4); rescale(EWK , 5); #else rescale(EWK , 4); #endif rescale(ttbar, 2); rescale(Ztt , 1); #ifdef MSSM rescale(ggH , 8); rescale(bbH , 9); #else #ifndef DROP_SIGNAL rescale(ggH , 8); rescale(qqH , 9); rescale(VH ,10); #endif #endif } TH1F* scales[7]; scales[0] = new TH1F("scales-Fakes", "", 7, 0, 7); scales[0]->SetBinContent(1, unscaled[0]>0 ? (Fakes->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-EWK" , "", 7, 0, 7); scales[1]->SetBinContent(2, unscaled[1]>0 ? ((EWK ->Integral() +EWK0 ->Integral() +EWK1 ->Integral() #ifdef EXTRA_SAMPLES +EWK2 ->Integral() #endif )/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-ttbar", "", 7, 0, 7); scales[2]->SetBinContent(3, unscaled[2]>0 ? (ttbar->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-Ztt" , "", 7, 0, 7); scales[3]->SetBinContent(4, unscaled[3]>0 ? (Ztt ->Integral()/unscaled[3]-1.) : 0.); #ifdef MSSM scales[4] = new TH1F("scales-ggH" , "", 7, 0, 7); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH ->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-bbH" , "", 7, 0, 7); scales[5]->SetBinContent(6, unscaled[5]>0 ? (bbH ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-NONE" , "", 7, 0, 7); scales[6]->SetBinContent(7, 0.); #else #ifndef DROP_SIGNAL scales[4] = new TH1F("scales-ggH" , "", 7, 0, 7); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH ->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-qqH" , "", 7, 0, 7); scales[5]->SetBinContent(6, unscaled[5]>0 ? (qqH ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-VH" , "", 7, 0, 7); scales[6]->SetBinContent(7, unscaled[6]>0 ? (VH ->Integral()/unscaled[6]-1.) : 0.); #endif #endif EWK0 ->Add(Fakes); EWK1 ->Add(EWK0 ); #ifdef EXTRA_SAMPLES EWK2 ->Add(EWK1 ); EWK ->Add(EWK2 ); #else EWK ->Add(EWK1 ); #endif ttbar->Add(EWK ); Ztt ->Add(ttbar); if(log){ #ifdef MSSM ggH ->Add(bbH); #else #ifndef DROP_SIGNAL qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } else{ #ifdef MSSM bbH ->Add(Ztt); ggH ->Add(bbH); #else #ifndef DROP_SIGNAL VH ->Add(Ztt); qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } /* Mass plot before and after fit */ TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(345)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(UPPER_EDGE)); }; #else data->GetXaxis()->SetRange(0, data->FindBin(345)); #endif data->SetNdivisions(505); data->SetMinimum(min); #ifndef DROP_SIGNAL data->SetMaximum(max>0 ? max : std::max(std::max(maximum(data, log), maximum(Ztt, log)), maximum(ggH, log))); #else data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log))); #endif data->Draw("e"); TH1F* errorBand = (TH1F*)Ztt ->Clone("errorBand"); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(13); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } if(log){ Ztt ->Draw("histsame"); ttbar->Draw("histsame"); EWK ->Draw("histsame"); EWK1 ->Draw("histsame"); Fakes->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif } else{ #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif Ztt ->Draw("histsame"); ttbar->Draw("histsame"); EWK ->Draw("histsame"); EWK1 ->Draw("histsame"); Fakes->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{e}#tau_{h}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); #if defined MSSM TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "tlbrNDC"); if (category_extra2!="") chan = new TPaveText(0.20, 0.69+0.061, 0.32, 0.74+0.161, "tlbrNDC"); #else TPaveText* chan = new TPaveText(0.52, 0.35, 0.91, 0.55, "tlbrNDC"); #endif chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(category); chan->AddText(category_extra); #if defined MSSM if (category_extra2!="") chan->AddText(category_extra2); #else chan->AddText(category_extra2); #endif chan->Draw(); /* TPaveText* cat = new TPaveText(0.20, 0.71+0.061, 0.32, 0.71+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); TPaveText* cat2 = new TPaveText(0.20, 0.66+0.061, 0.32, 0.66+0.161, "NDC"); cat2->SetBorderSize( 0 ); cat2->SetFillStyle( 0 ); cat2->SetTextAlign( 12 ); cat2->SetTextSize ( 0.05 ); cat2->SetTextColor( 1 ); cat2->SetTextFont ( 62 ); cat2->AddText(category_extra2); cat2->Draw(); */ #ifdef MSSM TPaveText* massA = new TPaveText(0.53, 0.44+0.061, 0.95, 0.44+0.151, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("MSSM m^{h}_{max} scenario"); massA->AddText("m_{A}=$MA GeV, tan#beta=$TANB"); massA->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.53, 0.60, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(ggH , "h,A,H#rightarrow#tau#tau" , "L" ); #else TLegend* leg = new TLegend(0.52, 0.58, 0.92, 0.89); SetLegendStyle(leg); #ifndef DROP_SIGNAL if(SIGNAL_SCALE!=1){ leg->AddEntry(ggH , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" ); } else{ leg->AddEntry(ggH , "SM H(125 GeV)#rightarrow#tau#tau" , "L" ); } #endif #endif #ifdef ASIMOV leg->AddEntry(data , "sum(bkg) + H(125)" , "LP"); #else leg->AddEntry(data , "Observed" , "LP"); #endif leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(EWK , "Z#rightarrow ee" , "F" ); leg->AddEntry(EWK1 , "W+jets" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); $ERROR_LEGEND leg->Draw(); /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* model = (TH1F*)Ztt ->Clone("model"); TH1F* test1 = (TH1F*)data->Clone("test1"); for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){ //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01); model->SetBinError (ibin+1, CONVERVATIVE_CHI2 ? 0. : model->GetBinError (ibin+1)*model->GetBinWidth(ibin+1)); test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1)); test1->SetBinError (ibin+1, test1->GetBinError (ibin+1)*test1->GetBinWidth(ibin+1)); } double chi2prob = test1->Chi2Test (model,"PUW"); std::cout << "chi2prob:" << chi2prob << std::endl; double chi2ndof = test1->Chi2Test (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl; double ksprob = test1->KolmogorovTest(model); std::cout << "ksprob :" << ksprob << std::endl; double ksprobpe = test1->KolmogorovTest(model,"DX"); std::cout << "ksprobpe:" << ksprobpe << std::endl; std::vector<double> edges; TH1F* zero = (TH1F*)ref->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat1"); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ rat1->SetBinContent(ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinContent(ibin+1)/Ztt->GetBinContent(ibin+1) : 0); rat1->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); zero->SetBinContent(ibin+1, 0.); zero->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? Ztt ->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } } float range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+range); rat1->SetMinimum(-range); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat1->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->SetMarkerSize(0.1); zero->Draw("e2histsame"); canv0->RedrawAxis(); TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC"); stat1->SetBorderSize( 0 ); stat1->SetFillStyle( 0 ); stat1->SetTextAlign( 12 ); stat1->SetTextSize ( 0.05 ); stat1->SetTextColor( 1 ); stat1->SetTextFont ( 62 ); stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f", chi2ndof, chi2prob)); //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f, P(KS)=%.3f", chi2ndof, chi2prob, ksprob)); stat1->Draw(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); edges.clear(); TH1F* rat2 = (TH1F*) Ztt->Clone("rat2"); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ rat2->SetBinContent(ibin+1, ref->GetBinContent(ibin+1)>0 ? Ztt->GetBinContent(ibin+1)/ref->GetBinContent(ibin+1) : 0); rat2->SetBinError (ibin+1, ref->GetBinContent(ibin+1)>0 ? Ztt->GetBinError (ibin+1)/ref->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat2->GetBinContent(ibin+1)-1.)+TMath::Abs(rat2->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } range = 0.1; std::sort(edges.begin(), edges.end()); if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } #if defined MSSM if(!log){ rat2->GetXaxis()->SetRange(0, rat2->FindBin(345)); } else{ rat2->GetXaxis()->SetRange(0, rat2->FindBin(UPPER_EDGE)); }; #else rat2->GetXaxis()->SetRange(0, rat2->FindBin(345)); #endif rat2->SetNdivisions(505); rat2->SetLineColor(kRed+ 3); rat2->SetMarkerColor(kRed+3); rat2->SetMarkerSize(1.1); rat2->SetMaximum(+range); rat2->SetMinimum(-range); rat2->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat2->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->Draw("e2histsame"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[0], "", "", TColor::GetColor(250,202,255), 1001); InitHist (scales[1], "", "", TColor::GetColor(222,90,106), 1001); InitHist (scales[2], "", "", TColor::GetColor(155,152,204), 1001); InitHist (scales[3], "", "", TColor::GetColor(248,206,104), 1001); #ifndef DROP_SIGNAL InitSignal(scales[4]); InitSignal(scales[5]); InitSignal(scales[6]); #endif scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}" ); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}" ); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}" ); scales[0]->GetXaxis()->SetBinLabel(7, "NONE" ); #else scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{qqH}" ); scales[0]->GetXaxis()->SetBinLabel(7, "#bf{VH}" ); #endif scales[0]->SetMaximum(+0.5); scales[0]->SetMinimum(-0.5); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); #ifndef DROP_SIGNAL scales[4]->Draw("same"); scales[5]->Draw("same"); scales[6]->Draw("same"); #endif TH1F* zero_samples = (TH1F*)scales[0]->Clone("zero_samples"); zero_samples->Clear(); zero_samples->SetBinContent(1,0.); zero_samples->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sfit_%s_%s.png" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.pdf" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.eps" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); if(!log || FULLPLOTS) { canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } if((!log && scaled) || FULLPLOTS) { canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } TFile* output = new TFile(TString::Format("%s_%sfit_%s_%s.root", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"), "update"); output->cd(); data ->Write("data_obs"); Fakes->Write("Fakes" ); EWK ->Write("Zee" ); EWK1 ->Write("EWK" ); //EWK ->Write("EWK" ); EWK1 ->Write("EWK1" ); ttbar->Write("ttbar" ); Ztt ->Write("Ztt" ); #ifdef MSSM ggH ->Write("ggH" ); bbH ->Write("bbH" ); #else #ifndef DROP_SIGNAL ggH ->Write("ggH" ); qqH ->Write("qqH" ); VH ->Write("VH" ); #endif #endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); delete errorBand; delete model; delete test1; delete zero; delete rat1; delete rat2; delete zero_samples; delete ref; }
void 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 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()); */ }
// 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 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(); }
//------------------------------------------------------------------------------ //--- Initialize the histogram after the default constructor has been used //--- Parameters: //--- frame count(int) //--- frame width(int) //--- frame height(int) //------------------------------------------------------------------------------ void c_Histogram::Initialize(const int fc, const int w, const int h, const int c, const int sm) { InitHist(fc, w * h, c, sm); }
void draw_prefit_Sample(std::string inputF, std::string channel, int MaxY, std::string xTitle, std::string nameHisto) { // gStyle->SetOptStat(0); SetStyle(); // InitSubPad TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); float SIGNAL_SCALE = 10; bool scaled = true; bool log = false; TFile* input = new TFile(inputF.c_str()); //cout<<"1"; const char* dataset; // std::string channel = "muTau_btag/"; // std::string channel = "eleTau_inclusive/"; THStack hs("hs", ""); TH1F* data = (TH1F*) input->Get((channel + "data_obs").c_str()); TH1F* zero = (TH1F*) data->Clone("zero"); TH1F* QCD = (TH1F*) input->Get((channel + "QCD").c_str()); InitHist(QCD, "", "", TColor::GetColor(250, 202, 255), 1001); hs.Add(QCD); TH1F* W = (TH1F*) input->Get((channel + "W").c_str()); InitHist(W, "", "", 46, 1001); TH1F* ZJ = (TH1F*) input->Get((channel + "ZJ").c_str()); // InitHist(ZJ, "", "", TColor::GetColor(100, 182, 232), 1001); W->Add(ZJ); TH1F* ZL = (TH1F*) input->Get((channel + "ZL").c_str()); // InitHist(ZL, "", "", TColor::GetColor(100, 182, 232), 1001); W->Add(ZL); TH1F* VV = (TH1F*) input->Get((channel + "VV").c_str()); // InitHist(VV, "", "", TColor::GetColor(100, 182, 232), 1001); W->Add(VV); hs.Add(W); //// TH1F* ZLL = (TH1F*) input->Get((channel +"ZLL"); // InitHist(ttbar, "", "", TColor::GetColor(155, 152, 204), 1001); TH1F* TT = (TH1F*) input->Get((channel + "TT").c_str()); InitHist(TT, "", "", 9, 1001); hs.Add(TT); TH1F* ZTT = (TH1F*) input->Get((channel + "ZTT").c_str()); InitHist(ZTT, "", "", TColor::GetColor(248, 206, 104), 1001); TH1F* ZTTLow = (TH1F*) input->Get((channel + "ZTT_lowMass").c_str()); InitHist(ZTTLow, "", "", TColor::GetColor(248, 206, 104), 1001); ZTT->Add(ZTTLow); hs.Add(ZTT); InitData(data); TH1F* signal = (TH1F*) input->Get((channel + "bba150").c_str()); signal->Scale(10); InitSignal(signal); // signal->SetFillColor(kGreen); // signal->SetLineColor(kGreen); hs.Add(signal); canv->cd(); // const char * MMM = xTitle.c_str(); // hs.GetXaxis()->SetLabelSize(9); zero->Scale(0); zero->GetXaxis()->SetRangeUser(0,60); zero->GetXaxis()->SetTitle(xTitle.c_str()); zero->SetMaximum(MaxY); zero->Draw(); hs.Draw("hsame"); data->SetBinContent(1,0); data->SetBinContent(2,0); data->SetBinContent(3,0); data->SetBinContent(4,0); data->SetBinContent(5,0); data->SetBinContent(6,0); data->SetBinContent(7,0); data->SetBinContent(8,0); data->SetBinContent(9,0); data->SetBinContent(10,0); data->SetBinContent(11,0); data->SetBinContent(12,0); data->SetBinContent(13,0); data->Draw("PEsame"); const char* dataset; dataset = "CMS Preliminary, bba1#rightarrow#tau#tau, 19.7 fb^{-1} at 8 TeV"; CMSPrelim(dataset, "", 0.17, 0.835); TLegend* leg = new TLegend(0.62, 0.58, 0.92, 0.89); SetLegendStyle(leg); leg->AddEntry(signal, TString::Format("a1(50 GeV)#rightarrow#tau#tau [XS= 10 bp]", SIGNAL_SCALE), "L"); leg->AddEntry(data, "observed", "LP"); leg->AddEntry(ZTT, "Z#rightarrow#tau#tau", "F"); leg->AddEntry(TT, "t#bar{t}", "F"); leg->AddEntry(W, "electroweak", "F"); leg->AddEntry(QCD, "QCD", "F"); leg->Draw(); // canv->Print(TString::Format( (nameHisto+".pdf").c_str())); // canv->Print(TString::Format( (nameHisto+".root").c_str())); canv->Print(TString::Format( (nameHisto+"_Low_.pdf").c_str())); canv->Print(TString::Format( (nameHisto+"_Low_.root").c_str())); }
void 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 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 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 comp(int s1 = 7, int s2 = 18, TString str1 = "|#eta| < 2.4", TString str2 = "|#eta| < 0.8") { // bool bAlice = false; bool bAlice = true; SetStyle(); if ( bAlice ) ALICE(); TFile * f1 = new TFile(Form("%s/out_rebin.root", ftxt[s1])); TFile * f2 = new TFile(Form("%s/out_rebin.root", ftxt[s2])); TH1D * h3PartSS_Cent1 = (TH1D*) f1->Get("h3PartSS_Cent"); TH1D * h3PartOS_Cent1 = (TH1D*) f1->Get("h3PartOS_Cent"); TH1D * h3PartSS_Cent2 = (TH1D*) f2->Get("h3PartSS_Cent"); TH1D * h3PartOS_Cent2 = (TH1D*) f2->Get("h3PartOS_Cent"); TCanvas * c1 = MakeCanvas("c1", "c1", 500, 400); TH2D * hframe_3part = new TH2D("hframe_3part", "hframe_3part", 1, 0, 200, 1, -0.001, 0.002); InitHist(hframe_3part, "Centrality Bin", "cos(#phi_{#alpha}+#phi_{#beta}-2#Psi_{2})"); hframe_3part->Draw(); TLine * zero = new TLine(0, 0, 200, 0); zero->Draw(); h3PartSS_Cent1->SetMarkerStyle(kFullCircle); h3PartOS_Cent1->SetMarkerStyle(kFullCircle); h3PartSS_Cent1->SetMarkerColor(kRed); h3PartOS_Cent1->SetMarkerColor(kBlue); h3PartSS_Cent1->SetLineColor(kRed); h3PartOS_Cent1->SetLineColor(kBlue); h3PartSS_Cent2->SetMarkerStyle(kFullSquare); h3PartOS_Cent2->SetMarkerStyle(kFullSquare); h3PartSS_Cent2->SetMarkerColor(kRed); h3PartOS_Cent2->SetMarkerColor(kBlue); h3PartSS_Cent2->SetLineColor(kRed); h3PartOS_Cent2->SetLineColor(kBlue); h3PartSS_Cent1->Draw("same"); h3PartOS_Cent1->Draw("same"); h3PartSS_Cent2->Draw("same"); h3PartOS_Cent2->Draw("same"); if ( bAlice ) gr_ALICE_3part_tpccumu_os->Draw("psame"); if ( bAlice ) gr_ALICE_3part_tpccumu_ss->Draw("psame"); TLegend * leg1 = new TLegend(0.2, 0.5, 0.5, 0.9); leg1->SetFillColor(kWhite); leg1->SetTextFont(42); leg1->SetTextSize(0.06); leg1->SetBorderSize(0); leg1->AddEntry(h3PartSS_Cent1, Form("SS %s", str1.Data()), "p"); leg1->AddEntry(h3PartOS_Cent1, Form("OS %s", str1.Data()), "p"); leg1->AddEntry(h3PartSS_Cent2, Form("SS %s", str2.Data()), "p"); leg1->AddEntry(h3PartOS_Cent2, Form("OS %s", str2.Data()), "p"); if ( bAlice ) leg1->AddEntry(gr_ALICE_3part_tpccumu_ss, "ALICE SS", "p"); else leg1->AddEntry(gr_ALICE_3part_tpccumu_ss, " ", ""); if ( bAlice ) leg1->AddEntry(gr_ALICE_3part_tpccumu_os, "ALICE OS", "p"); else leg1->AddEntry(gr_ALICE_3part_tpccumu_os, " ", ""); leg1->Draw(); /////////// TCanvas * c2 = MakeCanvas("c2", "c2", 500, 400); TH2D * hframe_2part = new TH2D("hframe_2part", "hframe_2part", 1, 0, 200, 1, -0.01, 0.03); InitHist(hframe_2part, "Centrality Bin", "#LTcos(#phi_{#alpha}-#phi_{#beta})#GT"); TH1D * hQ1pp_Cent1 = (TH1D*) f1->Get("hQ1pp_Cent"); TH1D * hQ1nn_Cent1 = (TH1D*) f1->Get("hQ1nn_Cent"); TH1D * hQ1pn_Cent1 = (TH1D*) f1->Get("hQ1pn_Cent"); TH1D * hQ1ppw_Cent1= (TH1D*) f1->Get("hQ1ppw_Cent"); TH1D * hQ1nnw_Cent1= (TH1D*) f1->Get("hQ1nnw_Cent"); TH1D * hQ1pnw_Cent1= (TH1D*) f1->Get("hQ1pnw_Cent"); TH1D * hQ1pp_Cent2 = (TH1D*) f2->Get("hQ1pp_Cent"); TH1D * hQ1nn_Cent2 = (TH1D*) f2->Get("hQ1nn_Cent"); TH1D * hQ1pn_Cent2 = (TH1D*) f2->Get("hQ1pn_Cent"); TH1D * hQ1ppw_Cent2= (TH1D*) f2->Get("hQ1ppw_Cent"); TH1D * hQ1nnw_Cent2= (TH1D*) f2->Get("hQ1nnw_Cent"); TH1D * hQ1pnw_Cent2= (TH1D*) f2->Get("hQ1pnw_Cent"); hQ1pp_Cent1->Add(hQ1nn_Cent1); hQ1ppw_Cent1->Add(hQ1nnw_Cent1); hQ1pp_Cent2->Add(hQ1nn_Cent2); hQ1ppw_Cent2->Add(hQ1nnw_Cent2); hQ1pp_Cent1->Divide(hQ1ppw_Cent1); hQ1pp_Cent2->Divide(hQ1ppw_Cent2); hQ1pn_Cent1->Divide(hQ1pnw_Cent1); hQ1pn_Cent2->Divide(hQ1pnw_Cent2); hQ1pp_Cent1->SetMarkerStyle(kFullCircle); hQ1pn_Cent1->SetMarkerStyle(kFullCircle); hQ1pp_Cent1->SetMarkerColor(kRed); hQ1pn_Cent1->SetMarkerColor(kBlue); hQ1pp_Cent1->SetLineColor(kRed); hQ1pn_Cent1->SetLineColor(kBlue); hQ1pp_Cent2->SetMarkerStyle(kFullSquare); hQ1pn_Cent2->SetMarkerStyle(kFullSquare); hQ1pp_Cent2->SetMarkerColor(kRed); hQ1pn_Cent2->SetMarkerColor(kBlue); hQ1pp_Cent2->SetLineColor(kRed); hQ1pn_Cent2->SetLineColor(kBlue); hframe_2part->Draw(); zero->Draw(); hQ1pp_Cent1->Draw("same"); hQ1pn_Cent1->Draw("same"); hQ1pp_Cent2->Draw("same"); hQ1pn_Cent2->Draw("same"); if ( bAlice ) gr_ALICE_2part_tpccumu_os->Draw("psame"); if ( bAlice ) gr_ALICE_2part_tpccumu_ss->Draw("psame"); TLegend * leg2 = new TLegend(0.2, 0.5, 0.5, 0.9); leg2->SetFillColor(kWhite); leg2->SetTextFont(42); leg2->SetTextSize(0.06); leg2->SetBorderSize(0); leg2->AddEntry(hQ1pp_Cent1, Form("SS %s", str1.Data()), "p"); leg2->AddEntry(hQ1pn_Cent1, Form("OS %s", str1.Data()), "p"); leg2->AddEntry(hQ1pp_Cent2, Form("SS %s", str2.Data()), "p"); leg2->AddEntry(hQ1pn_Cent2, Form("OS %s", str2.Data()), "p"); if ( bAlice ) leg2->AddEntry(gr_ALICE_2part_tpccumu_ss, "ALICE SS", "p"); else leg2->AddEntry(gr_ALICE_2part_tpccumu_ss, " ", ""); if ( bAlice ) leg2->AddEntry(gr_ALICE_2part_tpccumu_os, "ALICE OS", "p"); else leg2->AddEntry(gr_ALICE_2part_tpccumu_os, " ", ""); leg2->Draw(); /////////////// TH1D * hCC_SS1 = (TH1D*)hQ1pp_Cent1->Clone("hCC_SS1"); TH1D * hCC_OS1 = (TH1D*)hQ1pn_Cent1->Clone("hCC_OS1"); TH1D * hCC_SS2 = (TH1D*)hQ1pp_Cent2->Clone("hCC_SS2"); TH1D * hCC_OS2 = (TH1D*)hQ1pn_Cent2->Clone("hCC_OS2"); hCC_SS1->Add(h3PartSS_Cent1); hCC_SS1->Scale(0.5); hCC_OS1->Add(h3PartOS_Cent1); hCC_OS1->Scale(0.5); hCC_SS2->Add(h3PartSS_Cent2); hCC_SS2->Scale(0.5); hCC_OS2->Add(h3PartOS_Cent2); hCC_OS2->Scale(0.5); TH1D * hSS_SS1 = (TH1D*)hQ1pp_Cent1->Clone("hSS_SS1"); TH1D * hSS_OS1 = (TH1D*)hQ1pn_Cent1->Clone("hSS_OS1"); TH1D * hSS_SS2 = (TH1D*)hQ1pp_Cent2->Clone("hSS_SS2"); TH1D * hSS_OS2 = (TH1D*)hQ1pn_Cent2->Clone("hSS_OS2"); hSS_SS1->Add(h3PartSS_Cent1, -1); hSS_SS1->Scale(0.5); hSS_OS1->Add(h3PartOS_Cent1, -1); hSS_OS1->Scale(0.5); hSS_SS2->Add(h3PartSS_Cent2, -1); hSS_SS2->Scale(0.5); hSS_OS2->Add(h3PartOS_Cent2, -1); hSS_OS2->Scale(0.5); //// TCanvas * c3 = MakeCanvas("c3", "c3", 500, 400); TH2D * hframe_cos = new TH2D("hframe_cos", "hframe_cos", 1, 0, 200, 1, -0.01, 0.02); InitHist(hframe_cos, "Centrality Bin", "#LTcos(#Delta#phi_{#alpha})cos(#Delta#phi_{#beta})"); hframe_cos->Draw(); zero->Draw(); hCC_SS1->Draw("same"); hCC_SS2->Draw("same"); hCC_OS1->Draw("same"); hCC_OS2->Draw("same"); if ( bAlice ) gr_ALICE_coscos_ss->Draw("psame"); if ( bAlice ) gr_ALICE_coscos_os->Draw("psame"); TLegend * leg_cos = new TLegend(0.2, 0.5, 0.5, 0.9); leg_cos->SetFillColor(kWhite); leg_cos->SetTextFont(42); leg_cos->SetTextSize(0.06); leg_cos->SetBorderSize(0); leg_cos->AddEntry(hCC_SS1, Form("SS %s", str1.Data()), "p"); leg_cos->AddEntry(hCC_OS1, Form("OS %s", str1.Data()), "p"); leg_cos->AddEntry(hCC_SS2, Form("SS %s", str2.Data()), "p"); leg_cos->AddEntry(hCC_OS2, Form("OS %s", str2.Data()), "p"); if ( bAlice ) leg_cos->AddEntry(gr_ALICE_coscos_ss, "ALICE SS", "p"); else leg_cos->AddEntry(gr_ALICE_coscos_ss, " ", ""); if ( bAlice ) leg_cos->AddEntry(gr_ALICE_coscos_os, "ALICE OS", "p"); else leg_cos->AddEntry(gr_ALICE_coscos_os, " ", ""); leg_cos->Draw(); /// TCanvas * c4 = MakeCanvas("c4", "c4", 500, 400); TH2D * hframe_sin = new TH2D("hframe_sin", "hframe_sin", 1, 0, 200, 1, -0.01, 0.02); InitHist(hframe_sin, "Centrality Bin", "#LTsin(#Delta#phi_{#alpha})sin(#Delta#phi_{#beta})"); hframe_sin->Draw(); zero->Draw(); hSS_SS1->Draw("same"); hSS_SS2->Draw("same"); hSS_OS1->Draw("same"); hSS_OS2->Draw("same"); if ( bAlice ) gr_ALICE_sinsin_ss->Draw("psame"); if ( bAlice ) gr_ALICE_sinsin_os->Draw("psame"); TLegend * leg_sin = new TLegend(0.2, 0.5, 0.5, 0.9); leg_sin->SetFillColor(kWhite); leg_sin->SetTextFont(42); leg_sin->SetTextSize(0.06); leg_sin->SetBorderSize(0); leg_sin->AddEntry(hSS_SS1, Form("SS %s", str1.Data()), "p"); leg_sin->AddEntry(hSS_OS1, Form("OS %s", str1.Data()), "p"); leg_sin->AddEntry(hSS_SS2, Form("SS %s", str2.Data()), "p"); leg_sin->AddEntry(hSS_OS2, Form("OS %s", str2.Data()), "p"); if ( bAlice ) leg_sin->AddEntry(gr_ALICE_sinsin_ss, "ALICE SS", "p"); else leg_sin->AddEntry(gr_ALICE_sinsin_ss, " ", ""); if ( bAlice ) leg_sin->AddEntry(gr_ALICE_sinsin_os, "ALICE OS", "p"); else leg_sin->AddEntry(gr_ALICE_sinsin_os, " ", ""); leg_sin->Draw(); c1->SaveAs(Form("3part%s_%i_%i.pdf", bAlice?"_Alice":"", s1, s2)); c2->SaveAs(Form("2part%s_%i_%i.pdf", bAlice?"_Alice":"", s1, s2)); c3->SaveAs(Form("coscos%s_%i_%i.pdf", bAlice?"_Alice":"", s1, s2)); c4->SaveAs(Form("sinsin%s_%i_%i.pdf", bAlice?"_Alice":"", s1, s2)); }
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); }
//------------------------------------------------------------------------------ //--- Initialize the histogram after the default constructor has been used //--- Parameters: //--- frame count(int) //--- frame size (int): width x height //------------------------------------------------------------------------------ void c_Histogram::Initialize(const int fc, const int fz, const int c, const int sm) { InitHist(fc, fz, c, sm); }
void HBB_HAD_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="bb_$CATEGORY") { // define common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); const char* category_extra = ""; if(std::string(directory) == std::string("bb_had0" )){ category_extra = "all-had_{0}"; } if(std::string(directory) == std::string("bb_had1" )){ category_extra = "all-had_{1}"; } if(std::string(directory) == std::string("bb_had2" )){ category_extra = "all-had_{2}"; } if(std::string(directory) == std::string("bb_had3" )){ category_extra = "all-had_{3}"; } if(std::string(directory) == std::string("bb_had4" )){ category_extra = "all-had_{4}"; } if(std::string(directory) == std::string("bb_had5" )){ category_extra = "all-had_{5}"; } if(std::string(directory) == std::string("bb_lep" )){ category_extra = "semi-lep"; } const char* dataset; if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "Preliminary, #sqrt{s} = 7 TeV, L = 2.7 fb^{-1}";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "Preliminary, #sqrt{s} = 8 TeV, L = 19.4 fb^{-1}";} TFile* input = new TFile(inputfile.c_str()); #ifdef MSSM TFile* input2 = new TFile((inputfile+"_$MA_$TANB").c_str()); #endif TH1F* Bbb = refill((TH1F*)input->Get(TString::Format("%s/Bbb" , directory)), "Bbb"); InitHist(Bbb, "", "", kMagenta-10, 1001); TH1F* Cbb = refill((TH1F*)input->Get(TString::Format("%s/Cbb" , directory)), "Cbb"); InitHist(Cbb, "", "", kRed + 2, 1001); TH1F* Qbb = refill((TH1F*)input->Get(TString::Format("%s/Qbb" , directory)), "Qbb"); InitHist(Qbb, "", "", kBlue - 8, 1001); TH1F* bbB = refill((TH1F*)input->Get(TString::Format("%s/bbB" , directory)), "bbB"); InitHist(bbB, "", "", kOrange - 4, 1001); TH1F* bbX = refill((TH1F*)input->Get(TString::Format("%s/bbX" , directory)), "bbX"); InitHist(bbX, "", "", kViolet - 0, 1001); #ifdef MSSM //float bbHScale = 1.; //ggHScale = ($MSSM_SIGNAL_ggH_xseff_A + $MSSM_SIGNAL_ggH_xseff_hH); //bbHScale = ($MSSM_SIGNAL_bbH_xseff_A + $MSSM_SIGNAL_bbH_xseff_hH); TH1F* bbH = refill((TH1F*)input2->Get(TString::Format("%s/bbH$MA" , directory)), "bbH" ); InitSignal(bbH); bbH->Scale($TANB); //bbH->Scale(bbHScale); #endif #ifdef ASIMOV TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs_asimov", directory)), "data", true); #else TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); #endif InitHist(data, "#bf{m_{b#bar{b}} [GeV]}", "#bf{dN/dm_{b#bar{b}} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)Qbb->Clone("ref"); ref->Add(bbX); ref->Add(Cbb); ref->Add(bbB); ref->Add(Bbb); double unscaled[7]; unscaled[0] = Qbb ->Integral(); unscaled[1] = bbX ->Integral(); unscaled[2] = Cbb ->Integral(); unscaled[3] = bbB ->Integral(); unscaled[4] = Bbb ->Integral(); #ifdef MSSM unscaled[5] = bbH ->Integral(); unscaled[6] = 0; #endif if(scaled){ rescale(Bbb, 1); rescale(bbB, 4); rescale(Cbb, 2); rescale(bbX, 5); rescale(Qbb, 3); #ifdef MSSM rescale(bbH, 6); #endif } TH1F* scales[7]; scales[0] = new TH1F("scales-Qbb", "", 7, 0, 7); scales[0]->SetBinContent(1, unscaled[0]>0 ? (Qbb ->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-bbX" , "", 7, 0, 7); scales[1]->SetBinContent(2, unscaled[1]>0 ? (bbX ->Integral()/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-Cbb", "", 7, 0, 7); scales[2]->SetBinContent(3, unscaled[2]>0 ? (Cbb ->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-bbB" , "", 7, 0, 7); scales[3]->SetBinContent(4, unscaled[3]>0 ? (bbB ->Integral()/unscaled[3]-1.) : 0.); scales[4] = new TH1F("scales-Bbb" , "", 7, 0, 7); scales[4]->SetBinContent(5, unscaled[4]>0 ? (Bbb ->Integral()/unscaled[4]-1.) : 0.); #ifdef MSSM scales[5] = new TH1F("scales-bbH" , "", 7, 0, 7); scales[5]->SetBinContent(6, unscaled[5]>0 ? (bbH ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-NONE" , "", 7, 0, 7); scales[6]->SetBinContent(7, 0.); #endif bbX ->Add(Qbb); Cbb ->Add(bbX); bbB ->Add(Cbb); Bbb ->Add(bbB); if(!log){ #ifdef MSSM bbH ->Add(Bbb); #endif } /* mass plot before and after fit */ TCanvas* canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(1000)); }; #endif data->SetNdivisions(505); data->SetMinimum(min); data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Bbb, log))); data->Draw("e"); TH1F* errorBand = (TH1F*)Bbb ->Clone(); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(1); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); if(log){ Bbb ->Draw("histsame"); bbB ->Draw("histsame"); Cbb ->Draw("histsame"); bbX ->Draw("histsame"); Qbb ->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL bbH ->Draw("histsame"); #endif } else{ #ifndef DROP_SIGNAL bbH ->Draw("histsame"); #endif Bbb ->Draw("histsame"); bbB ->Draw("histsame"); Cbb ->Draw("histsame"); bbX ->Draw("histsame"); Qbb ->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "b#bar{b}", 0.17, 0.835); CMSPrelim(dataset, "", 0.17, 0.835); TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText("b#bar{b}"); chan->Draw(); TPaveText* cat = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); #ifdef MSSM TPaveText* massA = new TPaveText(0.75, 0.48+0.061, 0.85, 0.48+0.161, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("m_{A}=$MA GeV"); massA->Draw(); TPaveText* tanb = new TPaveText(0.75, 0.44+0.061, 0.85, 0.44+0.161, "NDC"); tanb->SetBorderSize( 0 ); tanb->SetFillStyle( 0 ); tanb->SetTextAlign( 12 ); tanb->SetTextSize ( 0.03 ); tanb->SetTextColor( 1 ); tanb->SetTextFont ( 62 ); tanb->AddText("tan#beta=$TANB"); tanb->Draw(); TPaveText* scen = new TPaveText(0.75, 0.40+0.061, 0.85, 0.40+0.161, "NDC"); scen->SetBorderSize( 0 ); scen->SetFillStyle( 0 ); scen->SetTextAlign( 12 ); scen->SetTextSize ( 0.03 ); scen->SetTextColor( 1 ); scen->SetTextFont ( 62 ); scen->AddText("m^{h}_{max}"); scen->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.55, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(bbH , "#phi#rightarrowb#bar{b}" , "L" ); #endif #ifdef ASIMOV leg->AddEntry(data , "sum(bkg) + SM125 GeV signal" , "LP"); #else leg->AddEntry(data , "observed" , "LP"); #endif leg->AddEntry(Bbb, "Bbb" , "F" ); leg->AddEntry(bbB, "bbB" , "F" ); leg->AddEntry(Cbb, "Cbb" , "F" ); leg->AddEntry(bbX, "bbX" , "F" ); leg->AddEntry(Qbb, "Qbb" , "F" ); $ERROR_LEGEND leg->Draw(); //#ifdef MSSM // TPaveText* mssm = new TPaveText(0.69, 0.85, 0.90, 0.90, "NDC"); // mssm->SetBorderSize( 0 ); // mssm->SetFillStyle( 0 ); // mssm->SetTextAlign( 12 ); // mssm->SetTextSize ( 0.03 ); // mssm->SetTextColor( 1 ); // mssm->SetTextFont ( 62 ); // mssm->AddText("(m_{A}=250, tan#beta=5)"); // mssm->Draw(); //#else // TPaveText* mssm = new TPaveText(0.83, 0.85, 0.95, 0.90, "NDC"); // mssm->SetBorderSize( 0 ); // mssm->SetFillStyle( 0 ); // mssm->SetTextAlign( 12 ); // mssm->SetTextSize ( 0.03 ); // mssm->SetTextColor( 1 ); // mssm->SetTextFont ( 62 ); // mssm->AddText("m_{H}=125"); // mssm->Draw(); //#endif /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* zero = (TH1F*)ref ->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat"); rat1->Divide(Bbb); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } zero->SetBinContent(ibin+1, 0.); } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+1.5); rat1->SetMinimum(-1.5); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{b#bar{b}} [GeV]}"); rat1->Draw(); zero->SetLineColor(kBlack); zero->Draw("same"); canv0->RedrawAxis(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); TH1F* rat2 = (TH1F*) Bbb->Clone("rat2"); rat2->Divide(ref); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } rat2->SetLineColor(kRed+ 3); rat2->SetFillColor(kRed-10); rat2->SetMaximum(+0.3); rat2->SetMinimum(-0.3); rat2->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); rat2->GetXaxis()->SetTitle("#bf{m_{b#bar{b}} [GeV]}"); rat2->GetXaxis()->SetRange(0, 28); rat2->Draw(); zero->SetLineColor(kBlack); zero->Draw("same"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[4], "", "", kMagenta-10, 1001); InitHist (scales[2], "", "", kRed + 2, 1001); InitHist (scales[0], "", "", kBlue - 8, 1001); InitHist (scales[3], "", "", kOrange - 4, 1001); InitHist (scales[1], "", "", kViolet - 0, 1001); scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Qbb}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{bbX}"); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{Cbb}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{bbB}"); scales[0]->GetXaxis()->SetBinLabel(5, "#bf{Bbb}"); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}" ); scales[0]->GetXaxis()->SetBinLabel(7, "#bf{NONE}" ); #endif scales[0]->SetMaximum(+1.0); scales[0]->SetMinimum(-1.0); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); scales[4]->Draw("same"); zero->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sfit_%s_%s.png" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sfit_%s_%s.pdf" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sfit_%s_%s.eps" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); if(!log || FULLPLOTS) { canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); } if((!log && scaled) || FULLPLOTS) { canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); } TFile* output = new TFile(TString::Format("%s_%sfit_%s_%s.root", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""), "update"); output->cd(); data ->Write("data_obs"); Qbb ->Write("Qbb" ); bbX ->Write("bbX" ); Cbb ->Write("Cbb" ); bbB ->Write("bbB" ); Bbb ->Write("Bbb" ); #ifdef MSSM bbH ->Write("bbH" ); #endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); }
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 HTT_TT_X(bool scaled=true, bool log=false, float min=0., float max=-1., const char* inputfile="root/$HISTFILE", const char* directory="$CATEGORY") { // define common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category_extra = ""; if(std::string(directory) == std::string("emu_0jet_low" )){ category_extra = "0 jet, low p_{T}"; } if(std::string(directory) == std::string("emu_0jet_high" )){ category_extra = "0 jet, high p_{T}"; } if(std::string(directory) == std::string("emu_boost_low" )){ category_extra = "1 jet, low p_{T}"; } if(std::string(directory) == std::string("emu_boost_high")){ category_extra = "1 jet, high p_{T}"; } if(std::string(directory) == std::string("emu_vbf" )){ category_extra = "2 jet (VBF)"; } if(std::string(directory) == std::string("emu_nobtag" )){ category_extra = "No B-Tag"; } if(std::string(directory) == std::string("emu_btag" )){ category_extra = "B-Tag"; } const char* dataset; if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS Preliminary, ZH#rightarrow#lltau#tau, 4.9 fb^{-1} at 7 TeV";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, ZH#rightarrowll#tau#tau, 19.4 fb^{-1} at 8 TeV";} #ifdef MSSM if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 19.4 fb^{-1} at 8 TeV";} #endif TFile* input = new TFile(inputfile); TH1F* ZZ = refill((TH1F*)input->Get(TString::Format("%s/ZZ" , directory)), "ZZ"); InitHist(ZZ, "", "", kMagenta-10, 1001); TH1F* GGToZZ2L2L = refill((TH1F*)input->Get(TString::Format("%s/GGToZZ2L2L" , directory)), "GGToZZ2L2L"); InitHist(GGToZZ2L2L, "", "", kMagenta-10, 1001); TH1F* Zjets = refill((TH1F*)input->Get(TString::Format("%s/Zjets" , directory)), "Zjets" ); InitHist(Zjets , "", "", kRed + 2, 1001); #ifndef DROP_SIGNAL TH1F* ZH_htt = refill((TH1F*)input->Get(TString::Format("%s/ZH_htt" , directory)+"125"), "ZH_htt" ); InitSignal(ZH_htt); ZH_htt->Scale(SIGNAL_SCALE); TH1F* ZH_hww = refill((TH1F*)input->Get(TString::Format("%s/ZH_hww" , directory)+"125"), "ZH_hww" ); InitSignal(ZH_hww); ZH_hww->Scale(SIGNAL_SCALE); #endif TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); InitHist(data, "#bf{m_{#tau#tau} [GeV]}", "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)ZZ->Clone("ref"); ref->Add(GGToZZ2L2L); ref->Add(Zjets ); double unscaled[5]; unscaled[0] = ZZ->Integral(); unscaled[1] = GGToZZ2L2L->Integral(); unscaled[2] = Zjets ->Integral(); #ifndef DROP_SIGNAL unscaled[3] = ZH_htt ->Integral(); unscaled[4] = ZH_hww ->Integral(); #endif if(scaled){ rescale(ZZ, 1); rescale(GGToZZ2L2L, 2); rescale(Zjets, 3); #ifndef DROP_SIGNAL rescale(ZH_htt, 4); rescale(ZH_hww, 5); #endif } TH1F* scales[5]; scales[0] = new TH1F("scales-ZZ", "", 5, 0, 5); scales[0]->SetBinContent(1, unscaled[0]>0 ? (ZZ->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-GGToZZ2L2L", "", 5, 0, 5); scales[1]->SetBinContent(2, unscaled[1]>0 ? (GGToZZ2L2L->Integral()/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-Zjets" , "", 5, 0, 5); scales[2]->SetBinContent(3, unscaled[2]>0 ? (Zjets ->Integral()/unscaled[2]-1.) : 0.); #ifndef DROP_SIGNAL scales[3] = new TH1F("scales-ZH_htt" , "", 5, 0, 5); scales[3]->SetBinContent(4, unscaled[3]>0 ? (ZH_htt ->Integral()/unscaled[3]-1.) : 0.); scales[4] = new TH1F("scales-ZH_hww" , "", 5, 0, 5); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ZH_hww ->Integral()/unscaled[4]-1.) : 0.); #endif GGToZZ2L2L->Add(Zjets); ZZ ->Add(GGToZZ2L2L); if(log){ #ifndef DROP_SIGNAL ZH_htt ->Add(ZH_hww ); #endif } else{ #ifndef DROP_SIGNAL ZH_htt ->Add(ZH_hww); #endif } /* mass plot before and after fit */ TCanvas* canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(1000)); }; #else data->GetXaxis()->SetRange(0, data->FindBin(350)); #endif data->SetNdivisions(505); data->SetMinimum(min); float maxZZ=ZZ->GetBinContent(ZZ->GetMaximumBin()); float maxdata=data->GetBinContent(data->GetMaximumBin()); if (maxdata>maxZZ) data->SetMaximum(1.8*maxdata); else data->SetMaximum(1.8*maxZZ); data->Draw("e"); // TH1F* errorBand = (TH1F*)ZZ ->Clone(); TH1F* errorBand = (TH1F*)Zjets ->Clone(); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(1); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); errorBand ->Scale(0.15); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } //if(log){ ZZ ->Draw("histsame"); Zjets->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL ZH_htt ->Draw("histsame"); #endif //} //else{ //#ifndef DROP_SIGNAL // ggH ->Draw("histsame"); //#endif // Ztt ->Draw("histsame"); // ttbar->Draw("histsame"); // EWK ->Draw("histsame"); // Fakes->Draw("histsame"); // $DRAW_ERROR // } data->Draw("esame"); canv->RedrawAxis(); // //CMSPrelim(dataset, "#tau_{e}#tau_{#mu}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); if (directory=="eett_zh") chan->AddText("#tau#tau"); else chan->AddText("#mu#mu#tau#tau"); chan->Draw(); // // TPaveText* cat = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC"); // cat->SetBorderSize( 0 ); // cat->SetFillStyle( 0 ); // cat->SetTextAlign( 12 ); // cat->SetTextSize ( 0.05 ); // cat->SetTextColor( 1 ); // cat->SetTextFont ( 62 ); // cat->AddText(category_extra); // cat->Draw(); // //#ifdef MSSM // TPaveText* massA = new TPaveText(0.75, 0.48+0.061, 0.85, 0.48+0.161, "NDC"); // massA->SetBorderSize( 0 ); // massA->SetFillStyle( 0 ); // massA->SetTextAlign( 12 ); // massA->SetTextSize ( 0.03 ); // massA->SetTextColor( 1 ); // massA->SetTextFont ( 62 ); // massA->AddText("m_{A}=$MAGeV"); // massA->Draw(); // // TPaveText* tanb = new TPaveText(0.75, 0.44+0.061, 0.85, 0.44+0.161, "NDC"); // tanb->SetBorderSize( 0 ); // tanb->SetFillStyle( 0 ); // tanb->SetTextAlign( 12 ); // tanb->SetTextSize ( 0.03 ); // tanb->SetTextColor( 1 ); // tanb->SetTextFont ( 62 ); // tanb->AddText("tan#beta=$TANB"); // tanb->Draw(); // // TPaveText* scen = new TPaveText(0.75, 0.40+0.061, 0.85, 0.40+0.161, "NDC"); // scen->SetBorderSize( 0 ); // scen->SetFillStyle( 0 ); // scen->SetTextAlign( 12 ); // scen->SetTextSize ( 0.03 ); // scen->SetTextColor( 1 ); // scen->SetTextFont ( 62 ); // scen->AddText("mhmax"); // scen->Draw(); //#endif // //#ifdef MSSM // TLegend* leg = new TLegend(0.45, 0.65, 0.95, 0.90); // SetLegendStyle(leg); // leg->AddEntry(ggH , "#phi#rightarrow#tau#tau" , "L" ); //#else TLegend* leg = new TLegend(0.50, 0.65, 0.95, 0.90); SetLegendStyle(leg); //#ifndef DROP_SIGNAL // if(SIGNAL_SCALE!=1){ leg->AddEntry(ZH_htt , TString::Format("%.0f#timesZH(125 GeV)#rightarrowll#tau#tau", SIGNAL_SCALE) , "L" ); // } // else{ // leg->AddEntry(ggH , "H(125 GeV)#rightarrow#tau#tau" , "L" ); // } //#endif //#endif leg->AddEntry(data , "observed" , "LP"); leg->AddEntry(ZZ , "ZZ" , "F" ); leg->AddEntry(Zjets, "Reducible" , "F" ); // leg->AddEntry(EWK , "electroweak" , "F" ); // leg->AddEntry(Fakes, "QCD" , "F" ); $ERROR_LEGEND leg->Draw(); // ////#ifdef MSSM //// TPaveText* mssm = new TPaveText(0.69, 0.85, 0.90, 0.90, "NDC"); //// mssm->SetBorderSize( 0 ); //// mssm->SetFillStyle( 0 ); //// mssm->SetTextAlign( 12 ); //// mssm->SetTextSize ( 0.03 ); //// mssm->SetTextColor( 1 ); //// mssm->SetTextFont ( 62 ); //// mssm->AddText("(m_{A}=250, tan#beta=5)"); //// mssm->Draw(); ////#else //// TPaveText* mssm = new TPaveText(0.83, 0.85, 0.95, 0.90, "NDC"); //// mssm->SetBorderSize( 0 ); //// mssm->SetFillStyle( 0 ); //// mssm->SetTextAlign( 12 ); //// mssm->SetTextSize ( 0.03 ); //// mssm->SetTextColor( 1 ); //// mssm->SetTextFont ( 62 ); //// mssm->AddText("m_{H}=125"); //// mssm->Draw(); ////#endif // // /* // Ratio Data over MC // */ // TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); // canv0->SetGridx(); // canv0->SetGridy(); // canv0->cd(); // // TH1F* zero = (TH1F*)ref ->Clone("zero"); zero->Clear(); // TH1F* rat1 = (TH1F*)data->Clone("rat"); // rat1->Divide(Ztt); // for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ // if(rat1->GetBinContent(ibin+1)>0){ // // catch cases of 0 bins, which would lead to 0-alpha*0-1 // rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); // } // zero->SetBinContent(ibin+1, 0.); // } // rat1->SetLineColor(kBlack); // rat1->SetFillColor(kGray ); // rat1->SetMaximum(+0.5); // rat1->SetMinimum(-0.5); // rat1->GetYaxis()->CenterTitle(); // rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); // rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); // rat1->Draw(); // zero->SetLineColor(kBlack); // zero->Draw("same"); // canv0->RedrawAxis(); // // /* // Ratio After fit over Prefit // */ // TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); // canv1->SetGridx(); // canv1->SetGridy(); // canv1->cd(); // // TH1F* rat2 = (TH1F*) Ztt->Clone("rat2"); // rat2->Divide(ref); // for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ // if(rat2->GetBinContent(ibin+1)>0){ // // catch cases of 0 bins, which would lead to 0-alpha*0-1 // rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); // } // } // rat2->SetLineColor(kRed+ 3); // rat2->SetFillColor(kRed-10); // rat2->SetMaximum(+0.3); // rat2->SetMinimum(-0.3); // rat2->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); // rat2->GetYaxis()->CenterTitle(); // rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); // rat2->GetXaxis()->SetRange(0, 28); // rat2->Draw(); // zero->SetLineColor(kBlack); // zero->Draw("same"); // canv1->RedrawAxis(); // // /* // Relative shift per sample // */ // TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); // canv2->SetGridx(); // canv2->SetGridy(); // canv2->cd(); // // InitHist (scales[0], "", "", kMagenta-10, 1001); // InitHist (scales[1], "", "", kRed + 2, 1001); // InitHist (scales[2], "", "", kBlue - 8, 1001); // InitHist (scales[3], "", "", kOrange - 4, 1001); //#ifndef DROP_SIGNAL // InitSignal(scales[4]); // InitSignal(scales[5]); // InitSignal(scales[6]); //#endif // scales[0]->Draw(); // scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}"); // scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}" ); // scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}"); // scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}" ); //#ifdef MSSM // scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); // scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}" ); // scales[0]->GetXaxis()->SetBinLabel(7, "#bf{NONE}" ); //#else // scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); // scales[0]->GetXaxis()->SetBinLabel(6, "#bf{qqH}" ); // scales[0]->GetXaxis()->SetBinLabel(7, "#bf{VH}" ); //#endif // scales[0]->SetMaximum(+1.0); // scales[0]->SetMinimum(-1.0); // scales[0]->GetYaxis()->CenterTitle(); // scales[0]->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); // scales[1]->Draw("same"); // scales[2]->Draw("same"); // scales[3]->Draw("same"); //#ifndef DROP_SIGNAL // scales[4]->Draw("same"); // scales[5]->Draw("same"); // scales[6]->Draw("same"); //#endif // zero->Draw("same"); // canv2->RedrawAxis(); // // /* // prepare output // */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sscaled_%s_%s.png" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sscaled_%s_%s.pdf" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sscaled_%s_%s.eps" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); // canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); TFile* output = new TFile(TString::Format("%s_%sscaled_%s_%s.root", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""), "update"); output->cd(); data ->Write("data_obs"); ZZ->Write("ZZ" ); Zjets ->Write("Zjets" ); ZH_htt->Write("ZH_htt" ); ZH_hww ->Write("ZH_hww" ); //#ifdef MSSM // ggH ->Write("ggH" ); // bbH ->Write("bbH" ); //#else //#ifndef DROP_SIGNAL // ggH ->Write("ggH" ); // qqH ->Write("qqH" ); // VH ->Write("VH" ); //#endif //#endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); }
void //HHH_TT_X_notag(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="tauTau_$CATEGORY") HHH_TT_X_notag(bool scaled=true, bool log=true, float min=0.1, float max=-1., string inputfile="root/$HISTFILE", const char* directory="tauTau_$CATEGORY") { // defining the common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category = ""; const char* category_extra = ""; const char* category_extra2 = ""; if(std::string(directory) == std::string("tauTau_2jet0tag")){ category = "#tau_{h}#tau_{h}"; } if(std::string(directory) == std::string("tauTau_2jet0tag")){ category_extra= "2-jet 0 b-tag"; } if(std::string(directory) == std::string("tauTau_2jet1tag" )){ category = "#tau_{h}#tau_{h}"; } if(std::string(directory) == std::string("tauTau_2jet1tag" )){ category_extra= "2-jet 1 b-tag"; } if(std::string(directory) == std::string("tauTau_2jet2tag" )){ category = "#tau_{h}#tau_{h}"; } if(std::string(directory) == std::string("tauTau_2jet2tag" )){ category_extra = "2-jet 2 b-tag"; } const char* dataset; #ifdef MSSM if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 4.9 fb^{-1} (7 TeV)";} if(std::string(inputfile).find("8TeV")!=std::string::npos){ if(std::string(directory).find("btag")!=std::string::npos){ dataset = "#scale[1.5]{CMS} h,H,A#rightarrow#tau#tau 18.3 fb^{-1} (8 TeV)"; } else{ dataset = "#scale[1.5]{CMS} H#rightarrow hh#rightarrow#tau#tau bb 19.7 fb^{-1} (8 TeV)"; } } #else if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS, 19.7 fb^{-1} at 8 TeV";} #endif // open example histogram file TFile* input = new TFile(inputfile.c_str()); #ifdef MSSM TFile* input2 = new TFile((inputfile+"_$MH_$TANB").c_str()); #endif TH1F* Fakes = refill((TH1F*)input->Get(TString::Format("%s/QCD" , directory)), "QCD"); InitHist(Fakes, "", "", TColor::GetColor(250,202,255), 1001); TH1F* EWK1 = refill((TH1F*)input->Get(TString::Format("%s/W" , directory)), "W" ); InitHist(EWK1 , "", "", TColor::GetColor(222,90,106), 1001); TH1F* EWK2 = refill((TH1F*)input->Get(TString::Format("%s/ZLL" , directory)), "ZLL" ); InitHist(EWK2 , "", "", TColor::GetColor(222,90,106), 1001); //TH1F* EWK3 = refill((TH1F*)input->Get(TString::Format("%s/ZL" , directory)), "ZL" ); InitHist(EWK3 , "", "", TColor::GetColor(222,90,106), 1001); TH1F* EWK = refill((TH1F*)input->Get(TString::Format("%s/VV" , directory)), "VV" ); InitHist(EWK , "", "", TColor::GetColor(222,90,106), 1001); TH1F* ttbar = refill((TH1F*)input->Get(TString::Format("%s/TT" , directory)), "TT" ); InitHist(ttbar, "", "", TColor::GetColor(155,152,204), 1001); TH1F* Ztt = refill((TH1F*)input->Get(TString::Format("%s/ZTT" , directory)), "ZTT"); InitHist(Ztt , "", "", TColor::GetColor(248,206,104), 1001); #ifdef MSSM TH1F* ggHTohhTo2Tau2B = refill((TH1F*)input2->Get(TString::Format("%s/ggHTohhTo2Tau2B$MH" , directory)), "ggHTohhTo2Tau2B"); InitSignal(ggHTohhTo2Tau2B); ggHTohhTo2Tau2B->Scale($TANB*SIGNAL_SCALE); // if(std::string(directory)=="tauTau_2jet0tag") ggHTohhTo2Tau2B->Scale(4); /* TH1F* ggH_SM125 = refill((TH1F*)input->Get(TString::Format("%s/ggH_SM125",directory)),"ggH_SM125");InitSignal(ggH_SM125);ggH_SM125->Scale(SIGNAL_SCALE); TH1F* qqH_SM125 = refill((TH1F*)input->Get(TString::Format("%s/qqH_SM125",directory)),"qqH_SM125");InitSignal(qqH_SM125);qqH_SM125->Scale(SIGNAL_SCALE); TH1F* VH_SM125 = refill((TH1F*)input->Get(TString::Format("%s/VH_SM125",directory)),"VH_SM125");InitSignal(VH_SM125);VH_SM125->Scale(SIGNAL_SCALE); TH1F* WHToBB_SM125 = refill((TH1F*)input->Get(TString::Format("%s/WHToBB_SM125",directory)),"WHToBB_SM125");InitSignal(WHToBB_SM125);WHToBB_SM125->Scale(SIGNAL_SCALE); TH1F* ZHToBB_SM125 = refill((TH1F*)input->Get(TString::Format("%s/ZHToBB_SM125",directory)),"ZHToBB_SM125");InitSignal(ZHToBB_SM125);ZHToBB_SM125->Scale(SIGNAL_SCALE); */ /* TH1F* ggAToZhToLLTauTau = refill((TH1F*)input2->Get(TString::Format("%s/ggAToZhToLLTauTau$MH",directory)),"ggAToZhToLLTauTau"); InitSignal(ggAToZhToLLTauTau); TH1F* ggAToZhToLLBB = refill((TH1F*)input2->Get(TString::Format("%s/ggAToZhToLLBB$MH",directory)),"ggAToZhToLLBB"); InitSignal(ggAToZhToLLBB); TH1F* bbH = refill((TH1F*)input2->Get(TString::Format("%s/bbH$MH" , directory)), "bbH"); InitSignal(bbH); */ #endif #ifdef ASIMOV TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs_asimov", directory)), "data", true); #else TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data",true); #endif InitHist(data, "#bf{m_{H} [GeV]}", "#bf{dN/dm_{H} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)Fakes->Clone("ref"); ref->Add(EWK1 ); ref->Add(EWK2 ); //ref->Add(EWK3 ); ref->Add(EWK ); ref->Add(ttbar); ref->Add(Ztt ); double unscaled[8]; unscaled[0] = Fakes->Integral(); unscaled[1] = EWK ->Integral(); unscaled[1]+= EWK1 ->Integral(); unscaled[1]+= EWK2 ->Integral(); //unscaled[1]+= EWK3 ->Integral(); unscaled[2] = ttbar->Integral(); unscaled[3] = Ztt ->Integral(); #ifdef MSSM unscaled[4] = ggHTohhTo2Tau2B ->Integral(); /* unscaled[5] = ggH_SM125->Integral(); unscaled[5]+= qqH_SM125->Integral(); unscaled[5]+= VH_SM125->Integral(); */ /* unscaled[5] = ggAToZhToLLTauTau->Integral(); unscaled[6] = ggAToZhToLLBB->Integral(); unscaled[7] = bbH ->Integral(); */ #endif if(scaled){ /* Fakes = refill(shape_histos(Fakes, datacard, "QCD"), "QCD"); EWK1 = refill(shape_histos(EWK1, datacard, "W"), "W"); EWK2 = refill(shape_histos(EWK2, datacard, "ZJ"), "ZJ"); EWK = refill(shape_histos(EWK, datacard, "VV"), "VV"); ttbar = refill(shape_histos(ttbar, datacard, "TT"), "TT"); Ztt = refill(shape_histos(Ztt, datacard, "ZTT"), "ZTT"); #ifdef MSSM ggH = refill(shape_histos(ggH, datacard, "ggH$MH"), "ggH$MH"); bbH = refill(shape_histos(bbH, datacard, "bbH$MH"), "bbH$MH"); #else ggH = refill(shape_histos(ggH, datacard, "ggH"), "ggH"); qqH = refill(shape_histos(qqH, datacard, "qqH"), "qqH"); VH = refill(shape_histos(VH, datacard, "VH"), "VH"); #endif */ rescale(Fakes, 7); rescale(EWK1 , 3); rescale(EWK2 , 4); //rescale(EWK3 , 5); rescale(EWK , 6); rescale(ttbar, 2); rescale(Ztt , 1); #ifdef MSSM rescale(ggHTohhTo2Tau2B , 8); /* rescale(ggAToZhToLLTauTau,9); rescale(ggAToZhToLLBB,10); rescale(bbH , 11); */ #endif } TH1F* scales[8]; scales[0] = new TH1F("scales-Fakes", "", 8, 0, 8); scales[0]->SetBinContent(1, unscaled[0]>0 ? (Fakes->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-EWK" , "", 8, 0, 8); scales[1]->SetBinContent(2, unscaled[1]>0 ? ((EWK ->Integral() +EWK1 ->Integral() +EWK2 ->Integral() //+EWK3 ->Integral() )/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-ttbar", "", 8, 0, 8); scales[2]->SetBinContent(3, unscaled[2]>0 ? (ttbar->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-Ztt" , "", 8, 0, 8); scales[3]->SetBinContent(4, unscaled[3]>0 ? (Ztt ->Integral()/unscaled[3]-1.) : 0.); #ifdef MSSM scales[4] = new TH1F("scales-ggHTohhTo2Tau2B" , "", 8, 0, 8); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggHTohhTo2Tau2B ->Integral()/unscaled[4]-1.) : 0.); /* scales[5] = new TH1F("scales-sm","",8,0,8); scales[5]->SetBinContent(6, unscaled[5]>0 ? ((ggH_SM125->Integral()+qqH_SM125->Integral()+VH_SM125->Integral())/unscaled[5]-1.) : 0.); */ /* scales[5] = new TH1F("scales-ggAToZhToLLTauTau" , "", 8, 0, 8); scales[5]->SetBinContent(6, unscaled[5]>0 ? (ggAToZhToLLTauTau ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-ggAToZhToLLBB" , "", 8, 0, 8); scales[6]->SetBinContent(7, unscaled[6]>0 ? (ggAToZhToLLBB ->Integral()/unscaled[6]-1.) : 0.); scales[7] = new TH1F("scales-bbH" , "", 8, 0, 8); scales[7]->SetBinContent(8, unscaled[7]>0 ? (bbH ->Integral()/unscaled[7]-1.) : 0.); */ #endif //#ifdef MSSM // qqH_SM125->Add(ggH_SM125); // VH_SM125->Add(qqH_SM125); // Fakes->Add(VH_SM125); //#endif Fakes->Add(ttbar); EWK1 ->Add(Fakes); EWK2 ->Add(Fakes ); //EWK3 ->Add(EWK2 ); //EWK ->Add(EWK3 ); EWK ->Add(EWK2 ); // ttbar->Add(EWK ); Ztt ->Add(EWK); /*ggH_SM125->Add(qqH_SM125); ggH_SM125->Add(VH_SM125); ggH_SM125->Add(ZHToBB_SM125); ggH_SM125->Add(WHToBB_SM125); */ //if(log){ //#ifdef MSSM // ggH->Add(bbH); //#else // qqH->Add(VH ); // ggH->Add(qqH); //#endif // } //else{ //#ifdef MSSM // bbH->Add(Ztt); // ggH->Add(bbH); //#else // VH ->Add(Ztt); // qqH->Add(VH ); // ggH->Add(qqH); //#endif // } /* Mass plot before and after fit */ TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(200, data->FindBin(UPPER_EDGE)); } else{ data->GetXaxis()->SetRange(200, data->FindBin(UPPER_EDGE)); }; #else data->GetXaxis()->SetRange(200, data->FindBin(UPPER_EDGE)); #endif data->SetNdivisions(505); data->SetMinimum(min); data->SetMaximum(max>0 ? max : std::max(std::max(maximum(data, log), maximum(Ztt, log)), maximum(ggHTohhTo2Tau2B, log))); data->Draw("e"); TH1F* errorBand = (TH1F*)Ztt ->Clone(); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(13); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } if(log){ Ztt ->Draw("histsame"); // ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); ttbar->Draw("histsame"); //#ifdef MSSM // VH_SM125->Draw("histsame"); //#endif $DRAW_ERROR ggHTohhTo2Tau2B ->Draw("histsame"); /* ggH_SM125->SetLineColor(kRed); ggH_SM125->Draw("histsame"); */ } else{ Ztt ->Draw("histsame"); // ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); ttbar->Draw("histsame"); #ifdef MSSM //VH_SM125->Draw("histsame"); #endif $DRAW_ERROR ggHTohhTo2Tau2B ->Draw("histsame"); /*ggH_SM125->SetLineColor(kRed); ggH_SM125->Draw("histsame"); */ } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{h}#tau_{h}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); #if defined MSSM TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "tlbrNDC"); if (strcmp(category_extra2,"")!=0) chan = new TPaveText(0.20, 0.69+0.061, 0.32, 0.74+0.161, "tlbrNDC"); #else TPaveText* chan = new TPaveText(0.52, 0.35, 0.91, 0.55, "tlbrNDC"); #endif chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText(category); chan->AddText(category_extra); #if defined MSSM if (strcmp(category_extra2,"")!=0) chan->AddText(category_extra2); #else chan->AddText(category_extra2); #endif chan->Draw(); /* TPaveText* cat = new TPaveText(0.20, 0.71+0.061, 0.32, 0.71+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); TPaveText* cat2 = new TPaveText(0.20, 0.66+0.061, 0.32, 0.66+0.161, "NDC"); cat2->SetBorderSize( 0 ); cat2->SetFillStyle( 0 ); cat2->SetTextAlign( 12 ); cat2->SetTextSize ( 0.05 ); cat2->SetTextColor( 1 ); cat2->SetTextFont ( 62 ); cat2->AddText(category_extra2); cat2->Draw(); */ #ifdef MSSM TPaveText* massA = new TPaveText(0.53, 0.44+0.061, 0.95, 0.44+0.151, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("MSSM m^{h}_{mod+} scenario"); massA->AddText("m_{H}=$MH GeV, tan#beta=$TANB"); massA->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.53, 0.60, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(ggHTohhTo2Tau2B , TString::Format("%0.f #times H#rightarrowhh#rightarrow#tau#taubb", SIGNAL_SCALE) , "L" ); //leg->AddEntry(ggH_SM125, TString::Format("%0.f #times SM H(125 GeV) #rightarrow #tau#tau/bb", SIGNAL_SCALE), "L"); #endif #ifdef ASIMOV leg->AddEntry(data , "sum(bkg) + H(125)" , "LP"); #else leg->AddEntry(data , "Observed" , "LP"); #endif leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(EWK , "Electroweak" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); /*#ifdef MSSM leg->AddEntry(VH_SM125, "SM H(125 GeV) #rightarrow #tau#tau", "F" ); #endif */ $ERROR_LEGEND leg->Draw(); /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* model = (TH1F*)Ztt ->Clone("model"); TH1F* test1 = (TH1F*)data->Clone("test1"); for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){ //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01); model->SetBinError (ibin+1, CONSERVATIVE_CHI2 ? 0. : model->GetBinError (ibin+1)*model->GetBinWidth(ibin+1)); test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1)); test1->SetBinError (ibin+1, test1->GetBinError (ibin+1)*test1->GetBinWidth(ibin+1)); } double chi2prob=0.; double chi2ndof=0.; double ksprob=0.; double ksprobpe=0.; if(!BLIND_DATA){ chi2prob = test1->Chi2Test (model,"PUW"); std::cout << "chi2prob:" << chi2prob << std::endl; chi2ndof = test1->Chi2Test (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl; ksprob = test1->KolmogorovTest(model); std::cout << "ksprob :" << ksprob << std::endl; ksprobpe = test1->KolmogorovTest(model,"DX"); std::cout << "ksprobpe:" << ksprobpe << std::endl; } std::vector<double> edges; TH1F* zero = (TH1F*)ref->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat1"); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ rat1->SetBinContent(ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinContent(ibin+1)/Ztt->GetBinContent(ibin+1) : 0); rat1->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? data->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); zero->SetBinContent(ibin+1, 0.); zero->SetBinError (ibin+1, Ztt->GetBinContent(ibin+1)>0 ? Ztt ->GetBinError (ibin+1)/Ztt->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } } float range = 0.1; std::sort(edges.begin(), edges.end()); if(edges.size()>1){ if (edges[edges.size()-2]>0.1) { range = 0.2; } else if (edges[edges.size()-2]>0.2) { range = 0.5; } else if (edges[edges.size()-2]>0.5) { range = 1.0; } else if (edges[edges.size()-2]>1.0) { range = 1.5; } else if (edges[edges.size()-2]>1.5) { range = 2.0; } } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+range); rat1->SetMinimum(-range); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{H} [GeV]}"); rat1->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->SetMarkerSize(0.1); zero->Draw("e2histsame"); canv0->RedrawAxis(); TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC"); stat1->SetBorderSize( 0 ); stat1->SetFillStyle( 0 ); stat1->SetTextAlign( 12 ); stat1->SetTextSize ( 0.05 ); stat1->SetTextColor( 1 ); stat1->SetTextFont ( 62 ); if(!BLIND_DATA){ stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f", chi2ndof, chi2prob)); } //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f, P(#chi^{2})=%.3f, P(KS)=%.3f", chi2ndof, chi2prob, ksprob)); stat1->Draw(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); edges.clear(); TH1F* rat2 = (TH1F*) Ztt->Clone("rat2"); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ rat2->SetBinContent(ibin+1, ref->GetBinContent(ibin+1)>0 ? Ztt->GetBinContent(ibin+1)/ref->GetBinContent(ibin+1) : 0); rat2->SetBinError (ibin+1, ref->GetBinContent(ibin+1)>0 ? Ztt->GetBinError (ibin+1)/ref->GetBinContent(ibin+1) : 0); } for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ edges.push_back(TMath::Abs(rat2->GetBinContent(ibin+1)-1.)+TMath::Abs(rat2->GetBinError(ibin+1))); // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } range = 0.1; std::sort(edges.begin(), edges.end()); if(edges.size()>1){ if (edges[edges.size()-2]>0.1) { range = 0.2; } if (edges[edges.size()-2]>0.2) { range = 0.5; } if (edges[edges.size()-2]>0.5) { range = 1.0; } if (edges[edges.size()-2]>1.0) { range = 1.5; } if (edges[edges.size()-2]>1.5) { range = 2.0; } } #if defined MSSM if(!log){ rat2->GetXaxis()->SetRange(200, rat2->FindBin(UPPER_EDGE)); } else{ rat2->GetXaxis()->SetRange(200, rat2->FindBin(UPPER_EDGE)); }; #else rat2->GetXaxis()->SetRange(200, rat2->FindBin(UPPER_EDGE)); #endif rat2->SetNdivisions(505); rat2->SetLineColor(kRed+ 3); rat2->SetMarkerColor(kRed+3); rat2->SetMarkerSize(1.1); rat2->SetMaximum(+range); rat2->SetMinimum(-range); rat2->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); rat2->GetXaxis()->SetTitle("#bf{m_{H} [GeV]}"); rat2->Draw(); zero->SetFillStyle( 3013); zero->SetFillColor(kBlack); zero->SetLineColor(kBlack); zero->Draw("e2histsame"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[0], "", "", TColor::GetColor(250,202,255), 1001); InitHist (scales[1], "", "", TColor::GetColor(222,90,106), 1001); InitHist (scales[2], "", "", TColor::GetColor(155,152,204), 1001); InitHist (scales[3], "", "", TColor::GetColor(248,206,104), 1001); InitHist(scales[4],"","",kGreen+2,1001); /* InitHist(scales[5],"","",kGreen+2,1001); InitHist(scales[6],"","",kGreen+2,1001); InitHist(scales[7],"","",kGreen+2,1001); */ scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}" ); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}" ); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggHTohhTo2tau2B}" ); /* scales[0]->GetXaxis()->SetBinLabel(6, "#bf{ggAToZhToLLTauTau}"); scales[0]->GetXaxis()->SetBinLabel(7, "#bf{ggAToZhToLLBB}"); scales[0]->GetXaxis()->SetBinLabel(8, "#bf{bbH}" ); */ #endif scales[0]->SetMaximum(+0.5); scales[0]->SetMinimum(-0.5); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Postfit/Prefit-1}"); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); scales[4]->Draw("same"); /* scales[5]->Draw("same"); scales[6]->Draw("same"); */ TH1F* zero_samples = (TH1F*)scales[0]->Clone("zero_samples"); zero_samples->Clear(); zero_samples->SetBinContent(1,0.); zero_samples->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sfit_%s_%s.png" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.pdf" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv ->Print(TString::Format("%s_%sfit_%s_%s.eps" , directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); if(!log || FULLPLOTS) { canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv0->Print(TString::Format("%s_datamc_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } if((!log && scaled) || FULLPLOTS) { canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv1->Print(TString::Format("%s_prefit_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.png", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.pdf", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); canv2->Print(TString::Format("%s_sample_%sfit_%s_%s.eps", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN")); } TFile* output = new TFile(TString::Format("%s_%sfit_%s_%s.root", directory, scaled ? "post" : "pre", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "LIN"), "update"); output->cd(); data ->Write("data_obs"); Fakes->Write("Fakes" ); EWK ->Write("EWK" ); ttbar->Write("ttbar" ); Ztt ->Write("Ztt" ); #ifdef MSSM ggHTohhTo2Tau2B ->Write("ggHTohhTo2Tau2B" ); /* ggAToZhToLLTauTau->Write("ggAToZhToLLTauTau"); ggAToZhToLLBB->Write("ggAToZhToLLBB"); bbH ->Write("bbH" ); */ #endif output->Close(); delete errorBand; delete model; delete test1; delete zero; delete rat1; delete rat2; delete zero_samples; delete ref; }
void HTT_MT_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., const char* inputfile="root/$HISTFILE", const char* directory="muTau_$CATEGORY") { // defining the common canvas, axes pad styles SetStyle(); gStyle->SetLineStyleString(11,"20 10"); // determine category tag const char* category_extra = ""; if(std::string(directory) == std::string("muTau_0jet_low" )){ category_extra = "0 jet, low p_{T}"; } if(std::string(directory) == std::string("muTau_0jet_high" )){ category_extra = "0 jet, high p_{T}"; } if(std::string(directory) == std::string("muTau_boost_low" )){ category_extra = "1 jet, low p_{T}"; } if(std::string(directory) == std::string("muTau_boost_high")){ category_extra = "1 jet, high p_{T}"; } if(std::string(directory) == std::string("muTau_vbf" )){ category_extra = "2 jet (VBF)"; } if(std::string(directory) == std::string("muTau_nobtag" )){ category_extra = "No B-Tag"; } if(std::string(directory) == std::string("muTau_btag" )){ category_extra = "B-Tag"; } const char* dataset; if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV";} if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 19.4 fb^{-1} at 8 TeV";} #ifdef MSSM if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary, H#rightarrow#tau#tau, 12.1 fb^{-1} at 8 TeV";} #endif // open example histogram file TFile* input = new TFile(inputfile); TH1F* Fakes = refill((TH1F*)input->Get(TString::Format("%s/QCD" , directory)), "QCD"); InitHist(Fakes, "", "", kMagenta-10, 1001); TH1F* EWK1 = refill((TH1F*)input->Get(TString::Format("%s/W" , directory)), "W" ); InitHist(EWK1 , "", "", kRed + 2, 1001); #ifdef EXTRA_SAMPLES TH1F* EWK2 = refill((TH1F*)input->Get(TString::Format("%s/ZJ" , directory)), "ZJ" ); InitHist(EWK2 , "", "", kRed + 2, 1001); TH1F* EWK3 = refill((TH1F*)input->Get(TString::Format("%s/ZL" , directory)), "ZL" ); InitHist(EWK3 , "", "", kRed + 2, 1001); #else TH1F* EWK2 = refill((TH1F*)input->Get(TString::Format("%s/ZLL" , directory)), "ZLL"); InitHist(EWK2 , "", "", kRed + 2, 1001); #endif TH1F* EWK = refill((TH1F*)input->Get(TString::Format("%s/VV" , directory)), "VV" ); InitHist(EWK , "", "", kRed + 2, 1001); TH1F* ttbar = refill((TH1F*)input->Get(TString::Format("%s/TT" , directory)), "TT" ); InitHist(ttbar, "", "", kBlue - 8, 1001); TH1F* Ztt = refill((TH1F*)input->Get(TString::Format("%s/ZTT" , directory)), "ZTT"); InitHist(Ztt , "", "", kOrange - 4, 1001); #ifdef MSSM float ggHScale = 1., bbHScale = 1.; // scenario for MSSM, mhmax, mA=160, tanb=20, A + H for the time being if(std::string(inputfile).find("7TeV")!=std::string::npos){ ggHScale = ( 9157.9*0.119 + 10180.7*0.120)/1000.; bbHScale = (23314.3*0.119 + 21999.3*0.120)/1000.; } if(std::string(inputfile).find("8TeV")!=std::string::npos){ ggHScale = (11815.3*0.119 + 13124.9*0.120)/1000.; bbHScale = (31087.9*0.119 + 29317.8*0.120)/1000.; } // float ggHScale = 1., bbHScale = 1.; // scenario for MSSM, mhmax, mA=160, tanb=10, A + H for the time being // if(std::string(inputfile).find("7TeV")!=std::string::npos){ ggHScale = (2111.4*0.11 + 4022.9*0.11)/1000.; // bbHScale = (6211.6*0.11 + 5147.0*0.11)/1000.; } // if(std::string(inputfile).find("8TeV")!=std::string::npos){ ggHScale = (2729.9*0.11 + 5193.2*0.11)/1000.; // bbHScale = (8282.7*0.11 + 6867.8*0.11)/1000.; } TH1F* ggH = refill((TH1F*)input->Get(TString::Format("%s/ggH160", directory)), "ggH"); InitSignal(ggH); ggH ->Scale(ggHScale); TH1F* bbH = refill((TH1F*)input->Get(TString::Format("%s/bbH160", directory)), "bbH"); InitSignal(bbH); bbH ->Scale(bbHScale); #else #ifndef DROP_SIGNAL TH1F* ggH = refill((TH1F*)input->Get(TString::Format("%s/ggH125", directory)), "ggH"); InitSignal(ggH); ggH ->Scale(SIGNAL_SCALE); TH1F* qqH = refill((TH1F*)input->Get(TString::Format("%s/qqH125", directory)), "qqH"); InitSignal(qqH); qqH ->Scale(SIGNAL_SCALE); TH1F* VH = refill((TH1F*)input->Get(TString::Format("%s/VH125" , directory)), "VH" ); InitSignal(VH ); VH ->Scale(SIGNAL_SCALE); #endif #endif TH1F* data = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true); InitHist(data, "#bf{m_{#tau#tau} [GeV]}", "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data); TH1F* ref=(TH1F*)Fakes->Clone("ref"); ref->Add(EWK1 ); ref->Add(EWK2 ); #ifdef EXTRA_SAMPLES ref->Add(EWK3 ); #endif ref->Add(EWK ); ref->Add(ttbar); ref->Add(Ztt ); double unscaled[7]; unscaled[0] = Fakes->Integral(); unscaled[1] = EWK ->Integral(); unscaled[1]+= EWK1 ->Integral(); unscaled[1]+= EWK2 ->Integral(); #ifdef EXTRA_SAMPLES unscaled[1]+= EWK3 ->Integral(); #endif unscaled[2] = ttbar->Integral(); unscaled[3] = Ztt ->Integral(); #ifdef MSSM unscaled[4] = ggH ->Integral(); unscaled[5] = bbH ->Integral(); unscaled[6] = 0; #else #ifndef DROP_SIGNAL unscaled[4] = ggH ->Integral(); unscaled[5] = qqH ->Integral(); unscaled[6] = VH ->Integral(); #endif #endif if(scaled){ rescale(Fakes, 7); rescale(EWK1 , 3); rescale(EWK2 , 4); #ifdef EXTRA_SAMPLES rescale(EWK3 , 5); #endif rescale(EWK , 6); rescale(ttbar, 2); rescale(Ztt , 1); #ifdef MSSM rescale(ggH , 8); rescale(bbH , 9); #else #ifndef DROP_SIGNAL rescale(ggH , 8); rescale(qqH , 9); rescale(VH ,10); #endif #endif } TH1F* scales[7]; scales[0] = new TH1F("scales-Fakes", "", 7, 0, 7); scales[0]->SetBinContent(1, unscaled[0]>0 ? (Fakes->Integral()/unscaled[0]-1.) : 0.); scales[1] = new TH1F("scales-EWK" , "", 7, 0, 7); scales[1]->SetBinContent(2, unscaled[1]>0 ? ((EWK ->Integral() +EWK1 ->Integral() +EWK2 ->Integral() #ifdef EXTRA_SAMPLES +EWK3 ->Integral() #endif )/unscaled[1]-1.) : 0.); scales[2] = new TH1F("scales-ttbar", "", 7, 0, 7); scales[2]->SetBinContent(3, unscaled[2]>0 ? (ttbar->Integral()/unscaled[2]-1.) : 0.); scales[3] = new TH1F("scales-Ztt" , "", 7, 0, 7); scales[3]->SetBinContent(4, unscaled[3]>0 ? (Ztt ->Integral()/unscaled[3]-1.) : 0.); #ifdef MSSM scales[4] = new TH1F("scales-ggH" , "", 7, 0, 7); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH ->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-bbH" , "", 7, 0, 7); scales[5]->SetBinContent(6, unscaled[5]>0 ? (bbH ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-NONE" , "", 7, 0, 7); scales[6]->SetBinContent(7, 0.); #else #ifndef DROP_SIGNAL scales[4] = new TH1F("scales-ggH" , "", 7, 0, 7); scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH ->Integral()/unscaled[4]-1.) : 0.); scales[5] = new TH1F("scales-qqH" , "", 7, 0, 7); scales[5]->SetBinContent(6, unscaled[5]>0 ? (qqH ->Integral()/unscaled[5]-1.) : 0.); scales[6] = new TH1F("scales-VH" , "", 7, 0, 7); scales[6]->SetBinContent(7, unscaled[6]>0 ? (VH ->Integral()/unscaled[6]-1.) : 0.); #endif #endif EWK1 ->Add(Fakes); EWK2 ->Add(EWK1 ); #ifdef EXTRA_SAMPLES EWK3 ->Add(EWK2 ); EWK ->Add(EWK3 ); #else EWK ->Add(EWK2 ); #endif ttbar->Add(EWK ); Ztt ->Add(ttbar); if(log){ #ifdef MSSM ggH ->Add(bbH); #else #ifndef DROP_SIGNAL qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } else{ #ifdef MSSM bbH ->Add(Ztt); ggH ->Add(bbH); #else #ifndef DROP_SIGNAL VH ->Add(Ztt); qqH ->Add(VH ); ggH ->Add(qqH); #endif #endif } /* Mass plot before and after fit */ TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600); canv->cd(); if(log){ canv->SetLogy(1); } #if defined MSSM if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(1000)); }; #else data->GetXaxis()->SetRange(0, data->FindBin(350)); #endif data->SetNdivisions(505); data->SetMinimum(min); data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log))); data->Draw("e"); TH1F* errorBand = (TH1F*)Ztt ->Clone(); errorBand ->SetMarkerSize(0); errorBand ->SetFillColor(1); errorBand ->SetFillStyle(3013); errorBand ->SetLineWidth(1); for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){ if(errorBand->GetBinContent(idx)>0){ std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl; break; } } if(log){ Ztt ->Draw("histsame"); ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); $DRAW_ERROR #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif } else{ #ifndef DROP_SIGNAL ggH ->Draw("histsame"); #endif Ztt ->Draw("histsame"); ttbar->Draw("histsame"); EWK ->Draw("histsame"); Fakes->Draw("histsame"); $DRAW_ERROR } data->Draw("esame"); canv->RedrawAxis(); //CMSPrelim(dataset, "#tau_{#mu}#tau_{h}", 0.17, 0.835); CMSPrelim(dataset, "", 0.16, 0.835); TPaveText* chan = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC"); chan->SetBorderSize( 0 ); chan->SetFillStyle( 0 ); chan->SetTextAlign( 12 ); chan->SetTextSize ( 0.05 ); chan->SetTextColor( 1 ); chan->SetTextFont ( 62 ); chan->AddText("#mu#tau_{h}"); chan->Draw(); TPaveText* cat = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC"); cat->SetBorderSize( 0 ); cat->SetFillStyle( 0 ); cat->SetTextAlign( 12 ); cat->SetTextSize ( 0.05 ); cat->SetTextColor( 1 ); cat->SetTextFont ( 62 ); cat->AddText(category_extra); cat->Draw(); #ifdef MSSM TPaveText* massA = new TPaveText(0.75, 0.48+0.061, 0.85, 0.48+0.161, "NDC"); massA->SetBorderSize( 0 ); massA->SetFillStyle( 0 ); massA->SetTextAlign( 12 ); massA->SetTextSize ( 0.03 ); massA->SetTextColor( 1 ); massA->SetTextFont ( 62 ); massA->AddText("m_{A}=160GeV"); massA->Draw(); TPaveText* tanb = new TPaveText(0.75, 0.44+0.061, 0.85, 0.44+0.161, "NDC"); tanb->SetBorderSize( 0 ); tanb->SetFillStyle( 0 ); tanb->SetTextAlign( 12 ); tanb->SetTextSize ( 0.03 ); tanb->SetTextColor( 1 ); tanb->SetTextFont ( 62 ); tanb->AddText("tan#beta=20"); tanb->Draw(); TPaveText* scen = new TPaveText(0.75, 0.40+0.061, 0.85, 0.40+0.161, "NDC"); scen->SetBorderSize( 0 ); scen->SetFillStyle( 0 ); scen->SetTextAlign( 12 ); scen->SetTextSize ( 0.03 ); scen->SetTextColor( 1 ); scen->SetTextFont ( 62 ); scen->AddText("mhmax"); scen->Draw(); #endif #ifdef MSSM TLegend* leg = new TLegend(0.45, 0.65, 0.95, 0.90); SetLegendStyle(leg); leg->AddEntry(ggH , "#phi#rightarrow#tau#tau" , "L" ); #else TLegend* leg = new TLegend(0.50, 0.65, 0.95, 0.90); SetLegendStyle(leg); #ifndef DROP_SIGNAL if(SIGNAL_SCALE!=1){ leg->AddEntry(ggH , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" ); } else{ leg->AddEntry(ggH , "H(125 GeV)#rightarrow#tau#tau" , "L" ); } #endif #endif leg->AddEntry(data , "observed" , "LP"); leg->AddEntry(Ztt , "Z#rightarrow#tau#tau" , "F" ); leg->AddEntry(ttbar, "t#bar{t}" , "F" ); leg->AddEntry(EWK , "electroweak" , "F" ); leg->AddEntry(Fakes, "QCD" , "F" ); $ERROR_LEGEND leg->Draw(); //#ifdef MSSM // TPaveText* mssm = new TPaveText(0.69, 0.85, 0.90, 0.90, "NDC"); // mssm->SetBorderSize( 0 ); // mssm->SetFillStyle( 0 ); // mssm->SetTextAlign( 12 ); // mssm->SetTextSize ( 0.03 ); // mssm->SetTextColor( 1 ); // mssm->SetTextFont ( 62 ); // mssm->AddText("(m_{A}=120, tan#beta=10)"); // mssm->Draw(); //#else // TPaveText* mssm = new TPaveText(0.83, 0.85, 0.95, 0.90, "NDC"); // mssm->SetBorderSize( 0 ); // mssm->SetFillStyle( 0 ); // mssm->SetTextAlign( 12 ); // mssm->SetTextSize ( 0.03 ); // mssm->SetTextColor( 1 ); // mssm->SetTextFont ( 62 ); // mssm->AddText("m_{H}=125"); // mssm->Draw(); //#endif /* Ratio Data over MC */ TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400); canv0->SetGridx(); canv0->SetGridy(); canv0->cd(); TH1F* zero = (TH1F*)ref->Clone("zero"); zero->Clear(); TH1F* rat1 = (TH1F*)data->Clone("rat"); rat1->Divide(Ztt); for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){ if(rat1->GetBinContent(ibin+1)>0){ // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.); } zero->SetBinContent(ibin+1, 0.); } rat1->SetLineColor(kBlack); rat1->SetFillColor(kGray ); rat1->SetMaximum(+0.5); rat1->SetMinimum(-0.5); rat1->GetYaxis()->CenterTitle(); rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}"); rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat1->Draw(); zero->SetLineColor(kBlack); zero->Draw("same"); canv0->RedrawAxis(); /* Ratio After fit over Prefit */ TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400); canv1->SetGridx(); canv1->SetGridy(); canv1->cd(); TH1F* rat2 = (TH1F*) Ztt->Clone("rat2"); rat2->Divide(ref); for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){ if(rat2->GetBinContent(ibin+1)>0){ // catch cases of 0 bins, which would lead to 0-alpha*0-1 rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.); } } rat2->SetLineColor(kRed+ 3); rat2->SetFillColor(kRed-10); rat2->SetMaximum(+0.3); rat2->SetMinimum(-0.3); rat2->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); rat2->GetYaxis()->CenterTitle(); rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}"); rat2->Draw(); zero->SetLineColor(kBlack); zero->Draw("same"); canv1->RedrawAxis(); /* Relative shift per sample */ TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400); canv2->SetGridx(); canv2->SetGridy(); canv2->cd(); InitHist (scales[0], "", "", kMagenta-10, 1001); InitHist (scales[1], "", "", kRed + 2, 1001); InitHist (scales[2], "", "", kBlue - 8, 1001); InitHist (scales[3], "", "", kOrange - 4, 1001); #ifndef DROP_SIGNAL InitSignal(scales[4]); InitSignal(scales[5]); InitSignal(scales[6]); #endif scales[0]->Draw(); scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}"); scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}" ); scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}"); scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}" ); #ifdef MSSM scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}" ); scales[0]->GetXaxis()->SetBinLabel(7, "NONE" ); #else scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}" ); scales[0]->GetXaxis()->SetBinLabel(6, "#bf{qqH}" ); scales[0]->GetXaxis()->SetBinLabel(7, "#bf{VH}" ); #endif scales[0]->SetMaximum(+1.0); scales[0]->SetMinimum(-1.0); scales[0]->GetYaxis()->CenterTitle(); scales[0]->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}"); scales[1]->Draw("same"); scales[2]->Draw("same"); scales[3]->Draw("same"); #ifndef DROP_SIGNAL scales[4]->Draw("same"); scales[5]->Draw("same"); scales[6]->Draw("same"); #endif zero->Draw("same"); canv2->RedrawAxis(); /* prepare output */ bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos; canv ->Print(TString::Format("%s_%sscaled_%s_%s.png" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sscaled_%s_%s.pdf" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv ->Print(TString::Format("%s_%sscaled_%s_%s.eps" , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); TFile* output = new TFile(TString::Format("%s_%sscaled_%s_%s.root", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""), "update"); output->cd(); data ->Write("data_obs"); Fakes->Write("Fakes" ); EWK ->Write("EWK" ); ttbar->Write("ttbar" ); Ztt ->Write("Ztt" ); #ifdef MSSM ggH ->Write("ggH" ); bbH ->Write("bbH" ); #else #ifndef DROP_SIGNAL ggH ->Write("ggH" ); qqH ->Write("qqH" ); VH ->Write("VH" ); #endif #endif if(errorBand){ errorBand->Write("errorBand"); } output->Close(); }
//------------------------------------------------------------------------------ //--- Constructor 2 //--- Parameters: //--- frame count(int) //--- frame size (int): width x height //------------------------------------------------------------------------------ c_Histogram::c_Histogram(const int fc, const int fz, const int c, const int sm) { isInitialized = false; InitHist(fc, fz, c, sm); }