void performClosure(RooRealVar *mass, RooAbsPdf *pdf, RooDataSet *data, string closurename, double wmin=110., double wmax=130., double slow=110., double shigh=130., double step=0.002) { // plot to perform closure test cout << "Performing closure test..." << endl; double nbins = (wmax-wmin)/step; TH1F *h = new TH1F("h","h",int(floor(nbins+0.5)),wmin,wmax); if (data){ pdf->fillHistogram(h,RooArgList(*mass),data->sumEntries()); h->Scale(2*h->GetNbinsX()/double(binning_)); } else { pdf->fillHistogram(h,RooArgList(*mass)); } int binLow = h->FindBin(slow); int binHigh = h->FindBin(shigh)-1; TH1F *copy = new TH1F("copy","c",binHigh-binLow,h->GetBinLowEdge(binLow),h->GetBinLowEdge(binHigh+1)); for (int b=0; b<copy->GetNbinsX(); b++) copy->SetBinContent(b+1,h->GetBinContent(b+1+binLow)); double areaCov = 100*h->Integral(binLow,binHigh)/h->Integral(); // style h->SetLineColor(kBlue); h->SetLineWidth(3); h->SetLineStyle(7); copy->SetLineWidth(3); copy->SetFillColor(kGray); TCanvas *c = new TCanvas(); if (data){ RooPlot *plot = mass->frame(Bins(binning_),Range("higgsRange")); plot->addTH1(h,"hist"); plot->addTH1(copy,"same f"); if (data) data->plotOn(plot); pdf->plotOn(plot,Normalization(h->Integral(),RooAbsReal::NumEvent),NormRange("higgsRange"),Range("higgsRange"),LineWidth(1),LineColor(kRed),LineStyle(kDashed)); plot->Draw(); c->Print(closurename.c_str()); } else { RooPlot *plot = mass->frame(Bins(binning_),Range("higgsRange")); h->Scale(plot->getFitRangeBinW()/h->GetBinWidth(1)); copy->Scale(plot->getFitRangeBinW()/h->GetBinWidth(1)); pdf->plotOn(plot,LineColor(kRed),LineWidth(3)); plot->Draw(); h->Draw("hist same"); copy->Draw("same f"); c->Print(closurename.c_str()); } cout << "IntH: [" << h->GetBinLowEdge(binLow) << "-" << h->GetBinLowEdge(binHigh+1) << "] Area = " << areaCov << endl; delete c; delete copy; delete h; }
void Plot(RooRealVar *mass, RooDataSet *data, RooAbsPdf *pdf, pair<double,double> sigRange, vector<double> fwhmRange, string title, string savename){ double semin=sigRange.first; double semax=sigRange.second; double fwmin=fwhmRange[0]; double fwmax=fwhmRange[1]; double halfmax=fwhmRange[2]; double binwidth=fwhmRange[3]; RooPlot *plot = mass->frame(Bins(binning_),Range("higgsRange")); if (data) data->plotOn(plot,Invisible()); pdf->plotOn(plot,NormRange("higgsRange"),Range(semin,semax),FillColor(19),DrawOption("F"),LineWidth(2),FillStyle(1001),VLines(),LineColor(15)); TObject *seffLeg = plot->getObject(int(plot->numItems()-1)); pdf->plotOn(plot,NormRange("higgsRange"),Range(semin,semax),LineColor(15),LineWidth(2),FillStyle(1001),VLines()); pdf->plotOn(plot,NormRange("higgsRange"),Range("higgsRange"),LineColor(kBlue),LineWidth(2),FillStyle(0)); TObject *pdfLeg = plot->getObject(int(plot->numItems()-1)); if (data) data->plotOn(plot,MarkerStyle(kOpenSquare)); TObject *dataLeg = plot->getObject(int(plot->numItems()-1)); TLegend *leg = new TLegend(0.15,0.89,0.5,0.55); leg->SetFillStyle(0); leg->SetLineColor(0); leg->SetTextSize(0.03); if (data) leg->AddEntry(dataLeg,"Simulation","lep"); leg->AddEntry(pdfLeg,"Parametric model","l"); leg->AddEntry(seffLeg,Form("#sigma_{eff} = %1.2f GeV",0.5*(semax-semin)),"fl"); plot->GetXaxis()->SetNdivisions(509); halfmax*=(plot->getFitRangeBinW()/binwidth); TArrow *fwhmArrow = new TArrow(fwmin,halfmax,fwmax,halfmax,0.02,"<>"); fwhmArrow->SetLineWidth(2.); TPaveText *fwhmText = new TPaveText(0.15,0.45,0.45,0.58,"brNDC"); fwhmText->SetFillColor(0); fwhmText->SetLineColor(kWhite); fwhmText->SetTextSize(0.03); fwhmText->AddText(Form("FWHM = %1.2f GeV",(fwmax-fwmin))); TLatex lat1(0.65,0.85,"#splitline{CMS Preliminary}{Simulation}"); lat1.SetNDC(1); lat1.SetTextSize(0.03); TLatex lat2(0.65,0.75,title.c_str()); lat2.SetNDC(1); lat2.SetTextSize(0.025); TCanvas *canv = new TCanvas("c","c",600,600); plot->SetTitle(""); plot->GetXaxis()->SetTitle("m_{#gamma#gamma} (GeV)"); plot->Draw(); leg->Draw("same"); fwhmArrow->Draw("same <>"); fwhmText->Draw("same"); lat1.Draw("same"); lat2.Draw("same"); canv->Print(Form("%s.pdf",savename.c_str())); canv->Print(Form("%s.png",savename.c_str())); string path = savename.substr(0,savename.find('/')); canv->Print(Form("%s/animation.gif+100",path.c_str())); delete canv; }