void Fitter::MakePlots(const string& name, const string& title, RooPlot*& pPlot1, RooPlot*& pPlot2, RooAbsPdf* pPdf, RooDataSet* pData) { bool plotbkg = false; RooPlot* pFrame = pPlot1? pPlot1 : pFitVar->frame(RooFit::Bins(50), RooFit::Name(name.c_str()), RooFit::Title(title.c_str())); RooPlot* pFramePull = pPlot2? pPlot2 : pFitVar->frame(RooFit::Bins(50), RooFit::Name((name+"_Pull").c_str()), RooFit::Title((title+" Pull").c_str())); RooHist* pHisPull = NULL; double pullMax = 0.; if(!pPdf && !pData) plotbkg = true; if(!pPdf) pPdf = pTotPdf; if(!pData) pData = this->pData; pData->plotOn(pFrame, RooFit::MarkerSize(0.9)); if(plotbkg) { RooArgList bkgComponent; for(auto& pdf : bkgPdfs) bkgComponent.add(pdf.GetPdf()); pTotPdf->plotOn(pFrame, RooFit::Components(bkgComponent), RooFit::LineColor(kGreen) ); } pPdf->plotOn(pFrame, RooFit::LineColor(kRed)); pPdf->paramOn(pFrame, RooFit::Format("NEU", RooFit::AutoPrecision(1)), RooFit::Layout(0.65, 0.99, 0.93)); pFrame->getAttText()->SetTextSize(0.75*pFrame->GetYaxis()->GetLabelSize()); pHisPull = pFrame->pullHist(); pFramePull->addPlotable(pHisPull, "P"); pullMax = max(fabs(pFramePull->GetMinimum()), pFramePull->GetMaximum()); pFramePull->GetYaxis()->SetRangeUser(-pullMax,pullMax); pPlot1 = pFrame; pPlot2 = pFramePull; }
void MakeSpinPlots::DrawSpinBackground(TString tag, TString mcName,bool signal){ bool drawSM = (smName!="" && smName!=mcName); TCanvas cv; double thisN = ws->data(mcName+"_Combined")->reduce(TString("evtcat==evtcat::")+tag)->sumEntries(); float norm = thisN; //607*lumi/12.*thisN/(totEB+totEE); cout << norm <<endl; if(signal) norm = ws->data(Form("Data_%s_%s_sigWeight",tag.Data(),mcName.Data()))->sumEntries(); RooPlot *frame = ws->var("cosT")->frame(0,1,5); RooDataSet* bkgWeight = (RooDataSet*)ws->data(Form("Data_%s_%s_bkgWeight",tag.Data(),mcName.Data())); RooDataSet* tmp = (RooDataSet*)ws->data("Data_Combined")->reduce(TString("((mass>115 && mass<120) || (mass>130 && mass<135)) && evtcat==evtcat::")+tag); tmp->plotOn(frame,RooFit::Rescale(norm/tmp->sumEntries())); cout << "b" <<endl; ws->pdf(Form("%s_FIT_%s_cosTpdf",mcName.Data(),tag.Data()))->plotOn(frame,RooFit::LineColor(kGreen),RooFit::Normalization(norm/tmp->sumEntries())); if(drawSM) ws->pdf(Form("%s_FIT_%s_cosTpdf",smName.Data(),tag.Data()))->plotOn(frame,RooFit::LineColor(kRed),RooFit::Normalization(norm/tmp->sumEntries())); cout << "c " <<bkgWeight <<endl; bkgWeight->plotOn(frame,RooFit::Rescale(norm/bkgWeight->sumEntries()),RooFit::MarkerColor(kBlue) ); if(signal){ cout << "d" <<endl; ws->data(Form("Data_%s_%s_sigWeight",tag.Data(),mcName.Data()))->plotOn(frame,RooFit::MarkerStyle(4)); } cout << "d" <<endl; frame->SetMaximum(frame->GetMaximum()*(signal?0.8:0.4)*norm/tmp->sumEntries()); frame->SetMinimum(-1*frame->GetMaximum()); TLegend l(0.6,0.2,0.95,0.45); l.SetFillColor(0); l.SetBorderSize(0); l.SetHeader(tag); l.AddEntry(frame->getObject(0),"Data m#in [115,120]#cup[130,135]","p"); l.AddEntry(frame->getObject(1),mcName,"l"); if(drawSM) l.AddEntry(frame->getObject(2),"SM Higgs","l"); l.AddEntry(frame->getObject(2+drawSM),"background weighted Data","p"); if(signal) l.AddEntry(frame->getObject(3+drawSM),"signal weighted Data","p"); cout << "e" <<endl; frame->Draw(); l.Draw("SAME"); cv.SaveAs( basePath+Form("/cosThetaPlots/CosThetaDist_%s%s_%s_%s.png",outputTag.Data(),(signal ? "":"_BLIND"),mcName.Data(),tag.Data()) ); cv.SaveAs( basePath+Form("/cosThetaPlots/C/CosThetaDist_%s%s_%s_%s.C",outputTag.Data(),(signal ? "":"_BLIND"),mcName.Data(),tag.Data()) ); cv.SaveAs( basePath+Form("/cosThetaPlots/CosThetaDist_%s%s_%s_%s.pdf",outputTag.Data(),(signal ? "":"_BLIND"),mcName.Data(),tag.Data()) ); }
void plot(RooRealVar *mass, RooAbsPdf *pdf, RooDataSet *data, string name, int bins, int mhLow, int mhHigh){ RooPlot *plot = mass->frame(); mass->setRange("unblindReg_1",85,95); mass->setRange("unblindReg_2",110,120); if (BLIND) { data->plotOn(plot,Binning(bins),CutRange("unblindReg_1")); data->plotOn(plot,Binning(bins),CutRange("unblindReg_2")); data->plotOn(plot,Binning(bins),Invisible()); } else data->plotOn(plot,Binning(bins)); TCanvas *canv = new TCanvas(); pdf->plotOn(plot);//,RooFit::NormRange("fitdata_1,fitdata_2")); //pdf->paramOn(plot,RooFit::Layout(0.35,0.89,0.89),RooFit::Format("NEA",AutoPrecision(1))); //plot->getAttText()->SetTextSize(0.01); plot->SetMaximum(plot->GetMaximum()*2); if (BLIND) plot->SetMinimum(0.0001); plot->SetTitle(""); plot->SetYTitle(Form("Events / %.2fGeV",float(mhHigh-mhLow)/float(bins))); //plot->GetYaxis()->SetLabelSize(0.05); plot->SetTitleSize(0.045, "Y"); plot->SetTitleOffset(1.,"Y"); //plot->GetXaxis()->SetLabelSize(0.15); //plot->GetYaxis()->SetLabelSize(0.15); plot->SetXTitle("m_{#gamma#gamma}(GeV)"); plot->SetTitleSize(0.15, "X"); plot->Draw(); TLatex *lat = new TLatex(); lat->SetNDC(); lat->SetTextFont(42); lat->DrawLatex(0.68,0.93,"19.7fb^{-1}(8TeV)"); lat->DrawLatex(0.12,0.85,"CMS Preliminary"); string nameTemp = name; int catNum = nameTemp.find("cat"); string catNameOLD = nameTemp.replace(0, catNum, ""); string catName = catNameOLD.replace(catNameOLD.length()-4, 4, ""); lat->DrawLatex(0.1,0.92, Form("%s", catName.c_str())); TLegend *leg = new TLegend(0.12,0.7,0.32,0.8); leg->SetFillColor(0); leg->SetLineColor(1); leg->AddEntry(data,"Data","lep"); leg->Draw("same"); canv->SaveAs(Form("%s.png",name.c_str())); canv->SaveAs(Form("%s.pdf",name.c_str())); delete canv; delete lat; }
void MakeSpinPlots::DrawSpinSubTotBackground(TString mcName,bool signal){ bool drawSM = (smName!="" && smName!=mcName); TCanvas cv; double thisN = ws->data(mcName+"_Combined")->sumEntries(); float norm = thisN; if(signal) norm = ws->var(Form("Data_%s_FULLFIT_Nsig",mcName.Data()))->getVal(); RooPlot *frame = ws->var("cosT")->frame(0,1,10); RooDataSet* tmp = (RooDataSet*)ws->data(Form("Data_Combined"))->reduce("(mass>115 && mass<120) || (mass>130 && mass<135)"); tmp->plotOn(frame,RooFit::Rescale(norm/tmp->sumEntries())); ws->pdf(Form("%s_FIT_cosTpdf",mcName.Data()))->plotOn(frame,RooFit::LineColor(kGreen),RooFit::Normalization(norm/tmp->sumEntries())); if(drawSM) ws->pdf(Form("%s_FIT_cosTpdf",smName.Data()))->plotOn(frame,RooFit::LineColor(kRed),RooFit::Normalization(norm/tmp->sumEntries())); if(signal){ RooDataHist *h = (RooDataHist*)ws->data( Form("Data_%s_Combined_bkgSub_cosT",mcName.Data()) ); h->plotOn(frame,RooFit::MarkerStyle(4)); std::cout << "Nsig: " << h->sumEntries() << std::endl; } frame->SetMaximum(frame->GetMaximum()*(signal?2.:1.2)*norm/tmp->sumEntries()); frame->SetMinimum(-1*frame->GetMaximum()); TLegend l(0.6,0.2,0.95,0.45); l.SetFillColor(0); l.SetBorderSize(0); l.SetHeader("Combined"); l.AddEntry(frame->getObject(0),"Data m#in [115,120]#cup[130,135]","p"); l.AddEntry(frame->getObject(1),mcName,"l"); if(drawSM) l.AddEntry(frame->getObject(2),"SM Higgs","l"); if(signal) l.AddEntry(frame->getObject(2+drawSM),"bkg-subtracted Data","p"); frame->Draw(); l.Draw("SAME"); cv.SaveAs( basePath+Form("/cosThetaPlots/CosThetaDist_SimpleSub_%s%s_%s.png",outputTag.Data(),(signal ? "":"_BLIND"),mcName.Data()) ); cv.SaveAs( basePath+Form("/cosThetaPlots/C/CosThetaDist_SimpleSub_%s%s_%s.C",outputTag.Data(),(signal ? "":"_BLIND"),mcName.Data()) ); cv.SaveAs( basePath+Form("/cosThetaPlots/CosThetaDist_SimpleSub_%s%s_%s.pdf",outputTag.Data(),(signal ? "":"_BLIND"),mcName.Data()) ); }
void draw_data_mgg(TString folderName,bool blind=true,float min=103,float max=160) { TFile inputFile(folderName+"/data.root"); const int nCat = 5; TString cats[5] = {"HighPt","Hbb","Zbb","HighRes","LowRes"}; TCanvas cv; for(int iCat=0; iCat < nCat; iCat++) { RooWorkspace *ws = (RooWorkspace*)inputFile.Get(cats[iCat]+"_mgg_workspace"); RooFitResult* res = (RooFitResult*)ws->obj("fitresult_pdf_data"); RooRealVar * mass = ws->var("mgg"); mass->setRange("all",min,max); mass->setRange("blind",121,130); mass->setRange("low",106,121); mass->setRange("high",130,160); mass->setUnit("GeV"); mass->SetTitle("m_{#gamma#gamma}"); RooAbsPdf * pdf = ws->pdf("pdf"); RooPlot *plot = mass->frame(min,max,max-min); plot->SetTitle(""); RooAbsData* data = ws->data("data")->reduce(Form("mgg > %f && mgg < %f",min,max)); double nTot = data->sumEntries(); if(blind) data = data->reduce("mgg < 121 || mgg>130"); double nBlind = data->sumEntries(); double norm = nTot/nBlind; //normalization for the plot data->plotOn(plot); pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::Range("Full"),RooFit::LineWidth(0.1) ); plot->Print(); //add the fix error band RooCurve* c = plot->getCurve("pdf_Norm[mgg]_Range[Full]_NormRange[Full]"); const int Nc = c->GetN(); //TGraphErrors errfix(Nc); //TGraphErrors errfix2(Nc); TGraphAsymmErrors errfix(Nc); TGraphAsymmErrors errfix2(Nc); Double_t *x = c->GetX(); Double_t *y = c->GetY(); double NtotalFit = ws->var("Nbkg1")->getVal()*ws->var("Nbkg1")->getVal() + ws->var("Nbkg2")->getVal()*ws->var("Nbkg2")->getVal(); for( int i = 0; i < Nc; i++ ) { errfix.SetPoint(i,x[i],y[i]); errfix2.SetPoint(i,x[i],y[i]); mass->setVal(x[i]); double shapeErr = pdf->getPropagatedError(*res)*NtotalFit; //double totalErr = TMath::Sqrt( shapeErr*shapeErr + y[i] ); //total normalization error double totalErr = TMath::Sqrt( shapeErr*shapeErr + y[i]*y[i]/NtotalFit ); if ( y[i] - totalErr > .0 ) { errfix.SetPointError(i, 0, 0, totalErr, totalErr ); } else { errfix.SetPointError(i, 0, 0, y[i] - 0.01, totalErr ); } //2sigma if ( y[i] - 2.*totalErr > .0 ) { errfix2.SetPointError(i, 0, 0, 2.*totalErr, 2.*totalErr ); } else { errfix2.SetPointError(i, 0, 0, y[i] - 0.01, 2.*totalErr ); } /* std::cout << x[i] << " " << y[i] << " " << " ,pdf get Val: " << pdf->getVal() << " ,pdf get Prop Err: " << pdf->getPropagatedError(*res)*NtotalFit << " stat uncertainty: " << TMath::Sqrt(y[i]) << " Ntot: " << NtotalFit << std::endl; */ } errfix.SetFillColor(kYellow); errfix2.SetFillColor(kGreen); //pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::FillColor(kGreen),RooFit::Range("Full"), RooFit::VisualizeError(*res,2.0,kFALSE)); //pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::FillColor(kYellow),RooFit::Range("Full"), RooFit::VisualizeError(*res,1.0,kFALSE)); //pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::FillColor(kGreen),RooFit::Range("Full"), RooFit::VisualizeError(*res,2.0,kTRUE)); //pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::FillColor(kYellow),RooFit::Range("Full"), RooFit::VisualizeError(*res,1.0,kTRUE)); plot->addObject(&errfix,"4"); plot->addObject(&errfix2,"4"); plot->addObject(&errfix,"4"); data->plotOn(plot); TBox blindBox(121,plot->GetMinimum()-(plot->GetMaximum()-plot->GetMinimum())*0.015,130,plot->GetMaximum()); blindBox.SetFillColor(kGray); if(blind) { plot->addObject(&blindBox); pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::FillColor(kGreen),RooFit::Range("Full"), RooFit::VisualizeError(*res,2.0,kTRUE)); pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::FillColor(kYellow),RooFit::Range("Full"), RooFit::VisualizeError(*res,1.0,kTRUE)); } //plot->addObject(&errfix,"4"); //data->plotOn(plot); //pdf->plotOn(plot,RooFit::Normalization( norm ) ); //pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::Range("Full"),RooFit::LineWidth(1.5) ); pdf->plotOn(plot,RooFit::NormRange( "low,high" ),RooFit::Range("Full"), RooFit::LineWidth(1)); data->plotOn(plot); /* pdf->plotOn(plot,RooFit::Normalization(norm),RooFit::Range("all"),RooFit::LineWidth(0.8) ); //pdf->plotOn(plot,RooFit::Normalization(norm),RooFit::FillColor(kGreen),RooFit::Range("all"), RooFit::VisualizeError(*res,2.0,kFALSE)); //pdf->plotOn(plot,RooFit::Normalization(norm),RooFit::FillColor(kYellow),RooFit::Range("all"), RooFit::VisualizeError(*res,1.0,kFALSE)); pdf->plotOn(plot,RooFit::Normalization(norm),RooFit::FillColor(kGreen),RooFit::Range("all"), RooFit::VisualizeError(*res,2.0,kTRUE)); pdf->plotOn(plot,RooFit::Normalization(norm),RooFit::FillColor(kYellow),RooFit::Range("all"), RooFit::VisualizeError(*res,1.0,kTRUE)); data->plotOn(plot); pdf->plotOn(plot,RooFit::Normalization(norm),RooFit::Range("all"),RooFit::LineWidth(0.8) ); */ TLatex lbl0(0.1,0.96,"CMS Preliminary"); lbl0.SetNDC(); lbl0.SetTextSize(0.042); plot->addObject(&lbl0); TLatex lbl(0.4,0.96,Form("%s Box",cats[iCat].Data())); lbl.SetNDC(); lbl.SetTextSize(0.042); plot->addObject(&lbl); TLatex lbl2(0.6,0.96,"#sqrt{s}=8 TeV L = 19.78 fb^{-1}"); lbl2.SetNDC(); lbl2.SetTextSize(0.042); plot->addObject(&lbl2); int iObj=-1; TNamed *obj; while( (obj = (TNamed*)plot->getObject(++iObj)) ) { obj->SetName(Form("Object_%d",iObj)); } plot->Draw(); TString tag = (blind ? "_BLIND" : ""); cv.SaveAs(folderName+"/figs/mgg_data_"+cats[iCat]+tag+TString(Form("_%0.0f_%0.0f",min,max))+".png"); cv.SaveAs(folderName+"/figs/mgg_data_"+cats[iCat]+tag+TString(Form("_%0.0f_%0.0f",min,max))+".pdf"); cv.SaveAs(folderName+"/figs/mgg_data_"+cats[iCat]+tag+TString(Form("_%0.0f_%0.0f",min,max))+".C"); } }
void drawMassFrom2DPlot(RooWorkspace& myws, // Local workspace string outputDir, // Output directory struct InputOpt opt, // Variable with run information (kept for legacy purpose) struct KinCuts cut, // Variable with current kinematic cuts map<string, string> parIni, // Variable containing all initial parameters string plotLabel, // The label used to define the output file name // Select the type of datasets to fit string DSTAG, // Specifies the type of datasets: i.e, DATA, MCJPSINP, ... bool isPbPb, // Define if it is PbPb (True) or PP (False) // Select the type of object to fit bool incJpsi, // Includes Jpsi model bool incPsi2S, // Includes Psi(2S) model bool incBkg, // Includes Background model // Select the fitting options // Select the drawing options bool setLogScale, // Draw plot with log scale bool incSS, // Include Same Sign data double binWidth, // Bin width bool paperStyle=false // if true, print less info ) { RooMsgService::instance().getStream(0).removeTopic(Caching); RooMsgService::instance().getStream(1).removeTopic(Caching); RooMsgService::instance().getStream(0).removeTopic(Plotting); RooMsgService::instance().getStream(1).removeTopic(Plotting); RooMsgService::instance().getStream(0).removeTopic(Integration); RooMsgService::instance().getStream(1).removeTopic(Integration); RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING) ; if (DSTAG.find("_")!=std::string::npos) DSTAG.erase(DSTAG.find("_")); int nBins = min(int( round((cut.dMuon.M.Max - cut.dMuon.M.Min)/binWidth) ), 1000); string pdfTotName = Form("pdfCTAUMASS_Tot_%s", (isPbPb?"PbPb":"PP")); string pdfJpsiPRName = Form("pdfCTAUMASS_JpsiPR_%s", (isPbPb?"PbPb":"PP")); string pdfJpsiNoPRName = Form("pdfCTAUMASS_JpsiNoPR_%s", (isPbPb?"PbPb":"PP")); string pdfPsi2SPRName = Form("pdfCTAUMASS_Psi2SPR_%s", (isPbPb?"PbPb":"PP")); string pdfPsi2SNoPRName = Form("pdfCTAUMASS_Psi2SNoPR_%s", (isPbPb?"PbPb":"PP")); string dsOSName = Form("dOS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP")); string dsOSNameCut = dsOSName+"_CTAUCUT"; string dsSSName = Form("dSS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP")); bool isWeighted = myws.data(dsOSName.c_str())->isWeighted(); bool isMC = (DSTAG.find("MC")!=std::string::npos); double normDSTot = 1.0; if (myws.data(dsOSNameCut.c_str())) { normDSTot = myws.data(dsOSName.c_str())->sumEntries()/myws.data(dsOSNameCut.c_str())->sumEntries(); } // Create the main plot of the fit RooPlot* frame = myws.var("invMass")->frame(Bins(nBins), Range(cut.dMuon.M.Min, cut.dMuon.M.Max)); myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2)); if (paperStyle) TGaxis::SetMaxDigits(3); // to display powers of 10 myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("BKG"),Components(RooArgSet(*myws.pdf(Form("pdfMASS_Bkg_%s", (isPbPb?"PbPb":"PP"))))), FillStyle(paperStyle ? 0 : 1001), FillColor(kAzure-9), VLines(), DrawOption("LCF"), LineColor(kBlue), LineStyle(kDashed) ); if (!paperStyle) { if (incJpsi) { if ( myws.pdf(Form("pdfCTAUMASS_JpsiPR_%s", (isPbPb?"PbPb":"PP"))) ) { myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("JPSIPR"),Components(RooArgSet(*myws.pdf(Form("pdfCTAUMASS_JpsiPR_%s", (isPbPb?"PbPb":"PP"))), *myws.pdf(Form("pdfCTAUMASS_Bkg_%s", (isPbPb?"PbPb":"PP"))))), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kRed+3), LineStyle(1), Precision(1e-4), NumCPU(32) ); } if ( myws.pdf(Form("pdfCTAUMASS_JpsiNoPR_%s", (isPbPb?"PbPb":"PP"))) ) { myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("JPSINOPR"),Components(RooArgSet(*myws.pdf(Form("pdfCTAUMASS_JpsiNoPR_%s", (isPbPb?"PbPb":"PP"))), *myws.pdf(Form("pdfCTAUMASS_Bkg_%s", (isPbPb?"PbPb":"PP"))))), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kGreen+3), LineStyle(1), Precision(1e-4), NumCPU(32) ); } } if (incPsi2S) { if ( myws.pdf(Form("pdfCTAUMASS_Psi2SPR_%s", (isPbPb?"PbPb":"PP"))) ) { myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PSI2SPR"),Components(RooArgSet(*myws.pdf(Form("pdfCTAUMASS_Psi2SPR_%s", (isPbPb?"PbPb":"PP"))))), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kRed+3), LineStyle(1), Precision(1e-4), NumCPU(32) ); } if ( myws.pdf(Form("pdfCTAUMASS_Psi2SNoPR_%s", (isPbPb?"PbPb":"PP"))) ) { myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PSI2SNOPR"),Components(RooArgSet(*myws.pdf(Form("pdfCTAUMASS_Psi2SNoPR_%s", (isPbPb?"PbPb":"PP"))))), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kGreen+3), LineStyle(1), Precision(1e-4), NumCPU(32) ); } } } if (incSS) { myws.data(dsSSName.c_str())->plotOn(frame, Name("dSS"), MarkerColor(kRed), LineColor(kRed), MarkerSize(1.2)); } myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2)); myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PDF"), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kBlack), NumCPU(32) ); // Create the pull distribution of the fit RooPlot* frameTMP = (RooPlot*)frame->Clone("TMP"); int nBinsTMP = nBins; RooHist *hpull = frameTMP->pullHist(0, 0, true); hpull->SetName("hpull"); RooPlot* frame2 = myws.var("invMass")->frame(Title("Pull Distribution"), Bins(nBins), Range(cut.dMuon.M.Min, cut.dMuon.M.Max)); frame2->addPlotable(hpull, "PX"); // set the CMS style setTDRStyle(); // Create the main canvas TCanvas *cFig = new TCanvas(Form("cMassFig_%s", (isPbPb?"PbPb":"PP")), "cMassFig",800,800); TPad *pad1 = new TPad(Form("pad1_%s", (isPbPb?"PbPb":"PP")),"",0,paperStyle ? 0 : 0.23,1,1); TPad *pad2 = new TPad(Form("pad2_%s", (isPbPb?"PbPb":"PP")),"",0,0,1,.228); TLine *pline = new TLine(cut.dMuon.M.Min, 0.0, cut.dMuon.M.Max, 0.0); // TPad *pad4 = new TPad("pad4","This is pad4",0.55,0.46,0.97,0.87); TPad *pad4 = new TPad("pad4","This is pad4",0.55,paperStyle ? 0.29 : 0.36,0.97,paperStyle ? 0.70 : 0.77); pad4->SetFillStyle(0); pad4->SetLeftMargin(0.28); pad4->SetRightMargin(0.10); pad4->SetBottomMargin(0.21); pad4->SetTopMargin(0.072); frame->SetTitle(""); frame->GetXaxis()->CenterTitle(kTRUE); if (!paperStyle) { frame->GetXaxis()->SetTitle(""); frame->GetXaxis()->SetTitleSize(0.045); frame->GetXaxis()->SetTitleFont(42); frame->GetXaxis()->SetTitleOffset(3); frame->GetXaxis()->SetLabelOffset(3); frame->GetYaxis()->SetLabelSize(0.04); frame->GetYaxis()->SetTitleSize(0.04); frame->GetYaxis()->SetTitleOffset(1.7); frame->GetYaxis()->SetTitleFont(42); } else { frame->GetXaxis()->SetTitle("m_{#mu^{+}#mu^{-}} (GeV/c^{2})"); frame->GetXaxis()->SetTitleOffset(1.1); frame->GetYaxis()->SetTitleOffset(1.45); frame->GetXaxis()->SetTitleSize(0.05); frame->GetYaxis()->SetTitleSize(0.05); } setMassFrom2DRange(myws, frame, dsOSName, setLogScale); if (paperStyle) { double Ydown = 0.;//frame->GetMinimum(); double Yup = 0.9*frame->GetMaximum(); frame->GetYaxis()->SetRangeUser(Ydown,Yup); } cFig->cd(); pad2->SetTopMargin(0.02); pad2->SetBottomMargin(0.4); pad2->SetFillStyle(4000); pad2->SetFrameFillStyle(4000); if (!paperStyle) pad1->SetBottomMargin(0.015); //plot fit pad1->Draw(); pad1->cd(); frame->Draw(); printMassFrom2DParameters(myws, pad1, isPbPb, pdfTotName, isWeighted); pad1->SetLogy(setLogScale); // Drawing the text in the plot TLatex *t = new TLatex(); t->SetNDC(); t->SetTextSize(0.032); float dy = 0; t->SetTextSize(0.03); if (!paperStyle) { // do not print selection details for paper style t->DrawLatex(0.20, 0.86-dy, "2015 HI Soft Muon ID"); dy+=0.045; if (isPbPb) { t->DrawLatex(0.20, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=2.0*0.045; } else { t->DrawLatex(0.20, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=2.0*0.045; } } if (cut.dMuon.AbsRap.Min>0.1) {t->DrawLatex(0.5175, 0.86-dy, Form("%.1f < |y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Min,cut.dMuon.AbsRap.Max)); dy+=0.045;} else {t->DrawLatex(0.5175, 0.86-dy, Form("|y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Max)); dy+=0.045;} t->DrawLatex(0.5175, 0.86-dy, Form("%g < p_{T}^{#mu#mu} < %g GeV/c",cut.dMuon.Pt.Min,cut.dMuon.Pt.Max)); dy+=0.045; if (isPbPb) {t->DrawLatex(0.5175, 0.86-dy, Form("Cent. %d-%d%%", (int)(cut.Centrality.Start/2), (int)(cut.Centrality.End/2))); dy+=0.045;} // Drawing the Legend double ymin = 0.7602; if (incPsi2S && incJpsi && incSS) { ymin = 0.7202; } if (incPsi2S && incJpsi && !incSS) { ymin = 0.7452; } if (paperStyle) { ymin = 0.72; } TLegend* leg = new TLegend(0.5175, ymin, 0.7180, 0.8809); leg->SetTextSize(0.03); if (frame->findObject("dOS")) { leg->AddEntry(frame->findObject("dOS"), (incSS?"Opposite Charge":"Data"),"pe"); } if (incSS) { leg->AddEntry(frame->findObject("dSS"),"Same Charge","pe"); } if (frame->findObject("PDF")) { leg->AddEntry(frame->findObject("PDF"),"Total fit","l"); } if (frame->findObject("JPSIPR")) { leg->AddEntry(frame->findObject("JPSIPR"),"Prompt J/#psi","l"); } if (frame->findObject("JPSINOPR")) { leg->AddEntry(frame->findObject("JPSINOPR"),"Non-Prompt J/#psi","l"); } if (incBkg && frame->findObject("BKG")) { leg->AddEntry(frame->findObject("BKG"),"Background",paperStyle ? "l" : "fl"); } leg->Draw("same"); //Drawing the title TString label; if (isPbPb) { if (opt.PbPb.RunNb.Start==opt.PbPb.RunNb.End){ label = Form("PbPb Run %d", opt.PbPb.RunNb.Start); } else { label = Form("%s [%s %d-%d]", "PbPb", "HIOniaL1DoubleMu0", opt.PbPb.RunNb.Start, opt.PbPb.RunNb.End); } } else { if (opt.pp.RunNb.Start==opt.pp.RunNb.End){ label = Form("PP Run %d", opt.pp.RunNb.Start); } else { label = Form("%s [%s %d-%d]", "PP", "DoubleMu0", opt.pp.RunNb.Start, opt.pp.RunNb.End); } } // CMS_lumi(pad1, isPbPb ? 105 : 104, 33, label); CMS_lumi(pad1, isPbPb ? 108 : 107, 33, ""); if (!paperStyle) gStyle->SetTitleFontSize(0.05); pad1->Update(); cFig->cd(); if (!paperStyle) { //---plot pull pad2->Draw(); pad2->cd(); frame2->SetTitle(""); frame2->GetYaxis()->CenterTitle(kTRUE); frame2->GetYaxis()->SetTitleOffset(0.4); frame2->GetYaxis()->SetTitleSize(0.1); frame2->GetYaxis()->SetLabelSize(0.1); frame2->GetYaxis()->SetTitle("Pull"); frame2->GetXaxis()->CenterTitle(kTRUE); frame2->GetXaxis()->SetTitleOffset(1); frame2->GetXaxis()->SetTitleSize(0.12); frame2->GetXaxis()->SetLabelSize(0.1); frame2->GetXaxis()->SetTitle("m_{#mu^{+}#mu^{-}} (GeV/c^{2})"); frame2->GetYaxis()->SetRangeUser(-7.0, 7.0); frame2->Draw(); // *** Print chi2/ndof printChi2(myws, pad2, frameTMP, "invMass", dsOSName.c_str(), pdfTotName.c_str(), nBinsTMP, false); pline->Draw("same"); pad2->Update(); } // Save the plot in different formats gSystem->mkdir(Form("%sctauMass/%s/plot/root/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%sctauMass/%s/plot/root/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.root", outputDir.c_str(), DSTAG.c_str(), "MASS", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End)); gSystem->mkdir(Form("%sctauMass/%s/plot/png/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%sctauMass/%s/plot/png/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.png", outputDir.c_str(), DSTAG.c_str(), "MASS", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End)); gSystem->mkdir(Form("%sctauMass/%s/plot/pdf/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%sctauMass/%s/plot/pdf/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.pdf", outputDir.c_str(), DSTAG.c_str(), "MASS", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End)); cFig->Clear(); cFig->Close(); };
void test(int numbersigmas = 0, Bool_t debugtest = true) { using namespace RooFit; using namespace std; TCanvas *canvas = new TCanvas("canvas","canvas",900,100,500,500); gSystem->Load("libRooFit"); gSystem->AddIncludePath("-I$ROOFITSYS/include"); float ptbinsarray[] = {20.,40.,60.,80.,100.,120.,200.,600.}; std::vector<float> ptbins(ptbinsarray,ptbinsarray+sizeof(ptbinsarray)/sizeof(ptbinsarray[0])); std::vector<std::vector<float> > allbins; allbins.push_back(ptbins); std::vector<TString> VarString; VarString.push_back("VsPt"); std::vector<TString> HistoNameString; HistoNameString.push_back("ptbin"); std::vector<TString> GraphXTitleString; GraphXTitleString.push_back("p_{t} (GeV)"); std::vector<TString> SideBandDefinitions; SideBandDefinitions.push_back("SideBand5_10"); // ------------FOR TESTING---------------- unsigned int sidebandloopmax = 1;//5_10, 5_20, ... unsigned int templatevarsloopmax = 1;//sinin with conv safe veto, sinin, ch isol unsigned int binsloopmax = 1;//pt, eta, phi, pu //----------Open .root Templates //All the Jet Templates TFile *histojetfile = TFile::Open("/afs/cern.ch/user/c/ciperez/CMSSW_7_4_5/src/TemplateHistosJetCheckBinsEndcapsLoose.root"); //TFile *histojetdenfile = TFile::Open("/afs/cern.ch/user/c/ciperez/CMSSW_7_4_5/src/Denominator_FREndCaps.root"); // TFile *histojetdatafile = TFile::Open("/afs/cern.ch/user/c/ciperez/CMSSW_7_4_5/src/Num_Templates.root"); //Real Photon Templates TFile *historealmcfile = TFile::Open("/afs/cern.ch/user/c/ciperez/CMSSW_7_4_5/src/RealPhotonTemplatesEndCaps.root"); //--- Write NEW .root Historams for Fake Rate TFile *FRhistosfile = new TFile("FakeRatePlotsCheckBins.root","recreate"); //loop on error systematics for(unsigned int m = 0; m<templatevarsloopmax; m++) { for(unsigned int l = 0; l<binsloopmax; l++) { TMultiGraph *mg = new TMultiGraph(); TLegend *legendAllGraphs = new TLegend(0.37,0.59,0.57,0.79); legendAllGraphs->SetTextSize(0.02); legendAllGraphs->SetFillColor(kWhite); legendAllGraphs->SetLineColor(kWhite); std::vector<float> fakeratevalues; std::vector<float> fakerateptvalues; std::vector<float> fakerateerrorvalues; for(unsigned int k = 0; k<allbins[0].size()-1; k++) { // for(unsigned int k = 0;k<1;k++){ float binlow = allbins[0][k]; float binmax = allbins[0][k+1]; TString binstring = TString::Format("%4.2f_%4.2f",binlow,binmax); binstring.ReplaceAll(".00",""); binstring.ReplaceAll("-","m"); binstring.ReplaceAll(".","p"); binstring.ReplaceAll("10000","Inf"); cout<<binstring.Data()<<endl; //Histograms for templates //Get histograms from each of the histojetfiles declared earlier //Numerator Fakes - FakePhotonNumEndCaps.root - FakePhoton_num2040... TH1F *h1 = (TH1F*)histojetfile->Get(("histoSininWithPixelSeedFakeJetptbin"+binstring).Data());// .Data() changes to char* h1->Print(); //Numerator Real Photons - RealPhotonTemplatesEndCaps.root - EndCapsMCReal_20_40 TH1F *h2 = (TH1F*)historealmcfile->Get(("EndCapsMCReal_"+binstring).Data()); h2->Print(); //Numerator Templates - Num_Templates.root - num2040... TH1F *hData = (TH1F*)histojetfile->Get(("histoSininWithPixelSeedDataJetptbin"+binstring).Data()); hData->Print(); //Denominator Templates - Denominator_FREndCaps.root -FakePhoton_den2040... TH1F *hnum = (TH1F*)histojetfile->Get(("histoSininWithPixelSeedTightAndFakeJetptbin"+binstring).Data()); hnum->Print(); //avoiding 0 entries in the histograms //fake and real mc histos are the most critical for(int bincount = 1; bincount <= h1->GetNbinsX(); bincount++) { if(h1->GetBinContent(bincount) == 0.) h1->SetBinContent(bincount,1.e-6); } for(int bincount = 1; bincount <= h2->GetNbinsX(); bincount++) { if(h2->GetBinContent(bincount) == 0.) h2->SetBinContent(bincount,1.e-6); } int ndataentries = hData->GetEntries(); float sininmin = 0.; //? sigmaIetaIeta float sininmax = 0.1; //? sigmaIetaIeta // ----------------- Probability Density Function TString roofitvartitle = "#sigma_{i #eta i #eta}"; RooRealVar sinin("sinin",roofitvartitle.Data(),sininmin,sininmax); sinin.setRange("sigrange",0.018,0.06); //? this is the range because? Need to recall. //sinin.setRange("sigrange",0.005, 0.011); //Fake Template pdf RooDataHist faketemplate("faketemplate","fake template",sinin,h1); RooHistPdf fakepdf("fakepdf","test hist fake pdf",sinin,faketemplate); //Real Template pdf RooDataHist realtemplate("realtemplate","real template",sinin,h2); RooHistPdf realpdf("realpdf","test hist real pdf",sinin,realtemplate); //Data to be fitted to RooDataHist data("data","data to be fitted to",sinin,hData); //Declaration of Variables for Fake Rate RooRealVar fsig("fsig","signal fraction",0.1,0,1);// RooRealVar signum("signum","signum",0,ndataentries);// #of real contamination RooRealVar fakenum("fakenum","fakenum",0,ndataentries); //# of fake //Extend RooExtendPdf extpdfsig("Signal","extpdfsig",realpdf,signum,"sigrange"); RooExtendPdf extpdffake("Background","extpdffake",fakepdf,fakenum,"sigrange"); RooAddPdf model("model","sig + background",RooArgList(extpdfsig,extpdffake)); //----------- FITTING TO DATA ------------------- model.fitTo(data,RooFit::Minos()); //Define Plot Frame RooPlot *xframe = sinin.frame(); xframe->SetTitle(""); data.plotOn(xframe); model.plotOn(xframe); model.plotOn(xframe,Components(extpdfsig),LineColor(2),LineStyle(2)); model.plotOn(xframe,Components(extpdffake),LineColor(8),LineStyle(2)); canvas->cd(); canvas->SetGridx(true); canvas->SetGridy(true); xframe->GetXaxis()->SetRangeUser(0.,0.1); float xframemax = xframe->GetMaximum(); xframe->GetYaxis()->SetRangeUser(1.e-1,1.1*xframemax); xframe->Draw(); // ----- DEFINE LEGENDS and their position TLegend *legend = new TLegend(0.62,0.65,0.82,0.85); //Why these values? legend->SetTextSize(0.02); legend->SetFillColor(kWhite); legend->SetLineColor(kWhite); //Legend Header which tells the bin TString legendheader = "Pt (GeV):["+ binstring; legendheader.ReplaceAll("_",","); legendheader.ReplaceAll("m","-"); legendheader.ReplaceAll("p","."); legendheader.Append("]"); cout<<"legend "<<legendheader.Data()<<endl; legend->SetHeader(legendheader.Data()); TObject *objdata; //What is TObect? TObject *objmodel; TObject *objsignal; TObject *objfake; for(int i=0; i<xframe->numItems(); i++) { cout<<xframe->nameOf(i)<<endl; TString objname = xframe->nameOf(i); if(objname.Contains("data")) objdata = (TObject*)xframe->findObject(objname.Data()); if(objname.Contains("model") && !objname.Contains("Comp")) objmodel = (TObject*)xframe->findObject(objname.Data()); if(objname.Contains("model") && objname.Contains("Signal")) objsignal = (TObject*)xframe->findObject(objname.Data()); if(objname.Contains("model") && objname.Contains("Background")) objfake = (TObject*)xframe->findObject(objname.Data()); } //------ LEGEND -------- legend->AddEntry(objdata,"Data","lp"); legend->AddEntry(objsignal,"Signal","l"); legend->AddEntry(objfake,"Background","l"); legend->AddEntry(objmodel,"Signal + Background","l"); legend->Draw("same");//make them overlap for comparison canvas->Print(("Endcapfits"+binstring+".png").Data()); canvas->Print(("TemplateFitResultEndcap"+binstring+".C").Data()); float fakevalue = fakenum.getValV(); float fakeerrorhi = fakenum.getErrorHi(); float fakeerrorlo = fakenum.getErrorLo(); float fakeerrormax = max(fabs(fakeerrorhi),fabs(fakeerrorlo)); TString fakeresults = TString::Format("Fake results %f +%f %f",fakevalue,fakeerrorhi,fakeerrorlo); canvas->SetLogy(0); float sigvalue = signum.getValV(); float sigerrorhi = signum.getErrorHi(); float sigerrorlo = signum.getErrorLo(); float sigerrormax = max(fabs(sigerrorhi),fabs(sigerrorlo)); TString sigresults = TString::Format("Signal results %f +%f %f",sigvalue,sigerrorhi,sigerrorlo); cout<<"sigvalue "<<sigvalue<<" sigerrormax "<<sigerrormax<<" sigerrormax/sigvalue "<<sigerrormax/sigvalue<<endl; cout<<"fakevalue "<<fakevalue<<" fakeerrormax "<<fakeerrormax<<" fakeerrormax/fakevalue "<<fakeerrormax/fakevalue<<endl; cout<<fakeresults.Data()<<endl; cout<<sigresults.Data()<<endl; float Ratio = (fakevalue/(fakevalue+sigvalue)); float RatioError = Ratio*sqrt( ((fakeerrormax/fakevalue)*(fakeerrormax/fakevalue) + (sigerrormax/sigvalue)*(sigerrormax/sigvalue)) ); cout<<"Ratio "<<Ratio<<" +- "<<RatioError<<endl; //---------------------- FAKE RATE CALCULATOR ------------------------- //find the bin corresponding to 0.011 //int binnr = 22; int binnr = 34; //compute the integral of tight and fake in that range float numerator = hData->Integral(0,binnr); //Is the Integral function part of RooFit? float denominator = hnum->Integral(); float contamination = sigvalue; cout<<numerator<<" "<<denominator<<" "<<contamination<<endl; float fakerate = (numerator-contamination)/denominator; float fakerateerror = fakerate * sqrt( (1./numerator) + (1./denominator) + ((sigerrormax/sigvalue)*(sigerrormax/sigvalue)) ); cout<<"Here: "<<fakerate<<" "<<fakerateerror<<endl; //fakerateptvalues.push_back(hnumvspt->GetMean()); fakeratevalues.push_back(fakerate); fakerateerrorvalues.push_back(fakerateerror); cout<<""<<endl; cout<<"***********************************************************"<<endl; cout<<"So in sigmaietaieta < 0.011 there are "<<contamination<<" to subtract from "<<numerator<<endl; cout<<"and thus there are "<<(numerator-contamination)<<" total tight entries "<<endl; cout<<"and there are "<<denominator<<" entries in the tight and fake sample "<<endl; cout<<"and so the fake rate for the pt range "<<binlow<<"-"<<binmax<<" is "<<fakerate<<"+-"<<fakerateerror<<endl; cout<<"***********************************************************"<<endl; cout<<""<<endl; }//loop on all bins /* cout<<fakeratevalues.size()<<endl; for(int k=0;k<fakeratevalues.size();k++){ cout<<"Range: ["<<allbins[l][k]<<"-"<<allbins[l][k+1]<<"] --> fake rate: ("<<fakeratevalues[k]*100<<" +- "<<fakerateerrorvalues[k]*100<<")%"<<endl; }//end of loop over all fake rate values // *************************************************************-// // TGraphErrors *FRgraph = new TGraphErrors(fakeratevalues.size()); for(int k=0;k<fakeratevalues.size();k++){ cout<<(allbins[l][k+1]+allbins[l][k])/2.<<endl; FRgraph->SetPoint(k,(allbins[l][k+1]+allbins[l][k])/2.,fakeratevalues[k]); FRgraph->SetPointError(k,(allbins[l][k+1]-allbins[l][k])/2.,fakerateerrorvalues[k]); }//end of filling TGraph //// FRGraph->SetName(FakeRate.Data()); FRgraph->SetTitle(""); canvas->cd(); canvas->SetLogy(0); FRgraph->Draw("a*"); // **********************************************************-// // ***************************************** //float maxFRvalue = max_element(fakeratevalues.begin(),fakeratevalues.end()); FRgraph->GetYaxis()->SetRangeUser(0.,0.2); FRgraph->GetYaxis()->SetTitle("#epsilon_{FR}"); FRgraph->GetXaxis()->SetTitle((GraphXTitleString[l]).Data()); TString FakeRateFunctionName = " TF1 *FRfunc = new TF1(FakeRateFunctionName.Data(),"[0]+[1]/pow(x,[2])", allbins[l][0],allbins[l][fakeratevalues.size()]); FRfunc->SetParameters(1.,1.,1.); if(l==0){ FRgraph->Fit(FakeRateFunctionName.Data(),"R"); FRgraph->Fit(FakeRateFunctionName.Data()); FRfunc->Draw("same"); } // ******************************************** cout<<"***** Fit function parameters *****"<<endl; cout<<FRfunc->GetParameter(0)<<" " <<FRfunc->GetParameter(1)<<" " <<FRfunc->GetParameter(2)<<" " <<endl; cout<<"***** Fit function errors *****"<<endl; cout<<FRfunc->GetParError(0)<<" " <<FRfunc->GetParError(1)<<" " <<FRfunc->GetParError(2)<<" " <<endl; if(!debugtest){ canvas->Print(("FakeRateJetRun2012ABCD13JulLoose.png").Data(),"png"); canvas->Print(("FakeRateJetRun2012ABCD13JulLoose.gif").Data(),"gif"); canvas->Print(("FakeRateJetRun2012ABCD13JulLoose.eps").Data(),"eps"); canvas->Print(("FakeRateJetRun2012ABCD13JulLoos.pdf").Data(),"pdf"); canvas->Print(("FakeRateJetRun2012ABCD13JulLoose.C").Data(),"cxx"); } canvas->Print(("FakeRateEndCaps.png").Data(),"png"); canvas->Print(("FakeRateEndCaps.C").Data(),"cxx"); // ************************************************ if(!debugtest){ if(count == 0){ FRhistosfile->cd(); FRgraph->Write(); FRfunc->Write(); } } if(numbersigmas != 0){ FRgraph->SetLineColor(count+numbersigmas+1); FRgraph->SetMarkerColor(count+numbersigmas+1); TString numsigmastring = TString::Format("%d #sigma",count); legendAllGraphs->AddEntry(FRgraph,numsigmastring.Data(),"lep"); } mg->Add(FRgraph);*/ // }//end of loop over systematic errors if(numbersigmas != 0) { mg->Draw(); legendAllGraphs->Draw("same"); } }//end of loop over all variables (pt, eta, phi, pu) }//end of loop over template variables histojetfile->cd(); histojetfile->Close(); historealmcfile->cd(); historealmcfile->Close(); FRhistosfile->cd(); FRhistosfile->Close(); // }//end of loop over sideband definitions }//end of method
void drawCtauPlot(RooWorkspace& myws, // Local workspace string outputDir, // Output directory struct InputOpt opt, // Variable with run information (kept for legacy purpose) struct KinCuts cut, // Variable with current kinematic cuts string plotLabel, // The label used to define the output file name // Select the type of datasets to fit string DSTAG, // Specifies the type of datasets: i.e, DATA, MCJPSINP, ... bool isPbPb, // Define if it is PbPb (True) or PP (False) // Select the drawing options bool setLogScale, // Draw plot with log scale bool incSS, // Include Same Sign data int nBins, // Number of bins used for plotting bool paperStyle=false,// if true, print less info bool saveWS=true // save the workspace into a file ) { if (DSTAG.find("_")!=std::string::npos) DSTAG.erase(DSTAG.find("_")); string dsOSName = Form("dOS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP")); string dsSSName = Form("dSS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP")); // Create the main plot of the fit // RooPlot* frame = myws.var("invMass")->frame(Bins(nBins), Range(cut.dMuon.M.Min, cut.dMuon.M.Max)); RooPlot* frame = myws.var("ctau")->frame(Bins(nBins), Range(-1,3)); myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2)); if (paperStyle) TGaxis::SetMaxDigits(3); // to display powers of 10 if (incSS) { myws.data(dsSSName.c_str())->plotOn(frame, Name("dSS"), MarkerColor(kRed), LineColor(kRed), MarkerSize(1.2)); } myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2)); // set the CMS style setTDRStyle(); // Create the main canvas TCanvas *cFig = new TCanvas(Form("cMassFig_%s", (isPbPb?"PbPb":"PP")), "cMassFig",800,800); TPad *pad1 = new TPad(Form("pad1_%s", (isPbPb?"PbPb":"PP")),"",0,paperStyle ? 0 : 0.23,1,1); TPad *pad2 = new TPad(Form("pad2_%s", (isPbPb?"PbPb":"PP")),"",0,0,1,.228); TLine *pline = new TLine(cut.dMuon.M.Min, 0.0, cut.dMuon.M.Max, 0.0); // TPad *pad4 = new TPad("pad4","This is pad4",0.55,0.46,0.97,0.87); TPad *pad4 = new TPad("pad4","This is pad4",0.55,paperStyle ? 0.29 : 0.36,0.97,paperStyle ? 0.70 : 0.77); pad4->SetFillStyle(0); pad4->SetLeftMargin(0.28); pad4->SetRightMargin(0.10); pad4->SetBottomMargin(0.21); pad4->SetTopMargin(0.072); frame->SetTitle(""); frame->GetXaxis()->CenterTitle(kTRUE); if (!paperStyle) { frame->GetXaxis()->SetTitle(""); frame->GetXaxis()->SetTitleSize(0.045); frame->GetXaxis()->SetTitleFont(42); frame->GetXaxis()->SetTitleOffset(3); frame->GetXaxis()->SetLabelOffset(3); frame->GetYaxis()->SetLabelSize(0.04); frame->GetYaxis()->SetTitleSize(0.04); frame->GetYaxis()->SetTitleOffset(1.7); frame->GetYaxis()->SetTitleFont(42); } else { frame->GetXaxis()->SetTitle("#font[12]{l}_{J/#psi} (mm)"); frame->GetXaxis()->SetTitleOffset(1.1); frame->GetYaxis()->SetTitleOffset(1.45); frame->GetXaxis()->SetTitleSize(0.05); frame->GetYaxis()->SetTitleSize(0.05); } setRange(myws, frame, dsOSName, setLogScale, cut.dMuon.AbsRap.Min); if (paperStyle) { double Ydown = 0.1;//frame->GetMinimum(); double Yup = 0.9*frame->GetMaximum(); frame->GetYaxis()->SetRangeUser(Ydown,Yup); } cFig->cd(); pad2->SetTopMargin(0.02); pad2->SetBottomMargin(0.4); pad2->SetFillStyle(4000); pad2->SetFrameFillStyle(4000); if (!paperStyle) pad1->SetBottomMargin(0.015); //plot fit pad1->Draw(); pad1->cd(); frame->Draw(); pad1->SetLogy(setLogScale); // Drawing the text in the plot TLatex *t = new TLatex(); t->SetNDC(); t->SetTextSize(0.032); float dy = 0; t->SetTextSize(0.03); if (!paperStyle) { // do not print selection details for paper style t->DrawLatex(0.21, 0.86-dy, "2015 HI Soft Muon ID"); dy+=0.045; if (isPbPb) { t->DrawLatex(0.21, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=0.045; } else { t->DrawLatex(0.21, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=0.045; } } if (cut.dMuon.AbsRap.Min>0.1) {t->DrawLatex(0.20, 0.86-dy, Form("%.1f < |y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Min,cut.dMuon.AbsRap.Max)); dy+=1.5*0.045;} else {t->DrawLatex(0.20, 0.86-dy, Form("|y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Max)); dy+=1.5*0.045;} t->DrawLatex(0.20, 0.86-dy, Form("%g < p_{T}^{#mu#mu} < %g GeV/c",cut.dMuon.Pt.Min,cut.dMuon.Pt.Max)); dy+=0.045; t->DrawLatex(0.20, 0.86-dy, Form("%g < M^{#mu#mu} < %g GeV/c^{2}",cut.dMuon.M.Min,cut.dMuon.M.Max)); dy+=0.045; if (isPbPb) {t->DrawLatex(0.20, 0.86-dy, Form("Cent. %d-%d%%", (int)(cut.Centrality.Start/2), (int)(cut.Centrality.End/2))); dy+=0.045;} dy+=0.5*0.045; t->DrawLatex(0.20, 0.86-dy, "#mu in acceptance"); dy+=0.045; // Drawing the Legend double ymin = 0.7802; if (paperStyle) { ymin = 0.72; } TLegend* leg = new TLegend(0.5175, ymin, 0.7180, 0.8809); leg->SetTextSize(0.03); leg->AddEntry(frame->findObject("dOS"), (incSS?"Opposite Charge":"Data"),"pe"); if (incSS) { leg->AddEntry(frame->findObject("dSS"),"Same Charge","pe"); } leg->Draw("same"); //Drawing the title TString label; if (isPbPb) { if (opt.PbPb.RunNb.Start==opt.PbPb.RunNb.End){ label = Form("PbPb Run %d", opt.PbPb.RunNb.Start); } else { label = Form("%s [%s %d-%d]", "PbPb", "HIOniaL1DoubleMu0", opt.PbPb.RunNb.Start, opt.PbPb.RunNb.End); } } else { if (opt.pp.RunNb.Start==opt.pp.RunNb.End){ label = Form("PP Run %d", opt.pp.RunNb.Start); } else { label = Form("%s [%s %d-%d]", "PP", "DoubleMu0", opt.pp.RunNb.Start, opt.pp.RunNb.End); } } // CMS_lumi(pad1, isPbPb ? 105 : 104, 33, label); CMS_lumi(pad1, isPbPb ? 108 : 107, 33, ""); if (!paperStyle) gStyle->SetTitleFontSize(0.05); pad1->Update(); cFig->cd(); // Save the plot in different formats gSystem->mkdir(Form("%splot/%s/root/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%splot/%s/root/%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.root", outputDir.c_str(), DSTAG.c_str(), DSTAG.c_str(), "Psi2SJpsi", (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End)); gSystem->mkdir(Form("%splot/%s/png/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%splot/%s/png/%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.png", outputDir.c_str(), DSTAG.c_str(), DSTAG.c_str(), "Psi2SJpsi", (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End)); gSystem->mkdir(Form("%splot/%s/pdf/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%splot/%s/pdf/%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.pdf", outputDir.c_str(), DSTAG.c_str(), DSTAG.c_str(), "Psi2SJpsi", (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End)); cFig->Clear(); cFig->Close(); // Save the workspace if (saveWS) { gSystem->mkdir(Form("%sresult/%s/", outputDir.c_str(), DSTAG.c_str()), kTRUE); TFile *file = NULL; file = new TFile(Form("%sresult/%s/FIT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.root", outputDir.c_str(), DSTAG.c_str(), DSTAG.c_str(), "Psi2SJpsi", (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End), "RECREATE"); if (!file) { cout << "[ERROR] Output root file with fit results could not be created!" << endl; } else { file->cd(); myws.Write("workspace"); file->Write(); file->Close(); delete file; } } }