{ using namespace RooFit; TFile *fin = new TFile("example_data.root"); TNtupleD* nt = (TNtupleD *)fin->Get("nt"); RooRealVar mass("mass","mass",0.,2.); RooDataSet data("data","data",nt,RooArgSet(mass)); RooRealVar mu("mu","mu",1.0,0.5,1.5); RooRealVar sigma("sigma","sigma",0.05,0.001,0.15); RooGaussian gaus("gaus","gaus",mass,mu,sigma); RooRealVar slope("slope","slope",-0.3,-10.,10.); RooPolynomial linear("linear","linear",mass,RooArgSet(slope)); RooRealVar frac("frac","frac",0.2,0.,1.); RooAddPdf model("model","model",RooArgList(gaus,linear),RooArgList(frac)); RooRealVar ns("ns","# of signal",2000.,0.,20000.); RooRealVar nb("nb","# of background",8000.,0.,20000.); RooAddPdf model_ext("model_ext","model w/ ext likelihood", RooArgList(gaus,linear),RooArgList(ns,nb)); RooFitResult *res = model.fitTo(data,Save(true),Minos(true)); RooAbsReal* nll = model.createNLL(data); TH1D *scan_std = new TH1D("scan_std","Standard Likelihood",100, 1850., 2200.); for(int bin=1; bin<=scan_std->GetNbinsX(); bin++) { frac.setVal(scan_std->GetBinCenter(bin)/10000.); frac.setConstant(true); model.fitTo(data); scan_std->SetBinContent(bin,(nll->getVal()-res->minNll())*2.); } RooFitResult *res_ext = model_ext.fitTo(data,Save(true),Minos(true)); RooAbsReal* nll_ext = model_ext.createNLL(data); TH1D *scan_ext = new TH1D("scan_ext","Extended likelihood",100, 1850., 2200.); for(int bin=1; bin<=scan_ext->GetNbinsX(); bin++) { ns.setVal(scan_ext->GetBinCenter(bin)); ns.setConstant(true); model_ext.fitTo(data); scan_ext->SetBinContent(bin,(nll_ext->getVal()-res_ext->minNll())*2.); } scan_std->SetStats(false); scan_std->SetLineWidth(2); scan_std->SetLineColor(kRed); scan_std->SetMinimum(-1.); scan_std->SetMaximum(12.); scan_std->GetXaxis()->SetTitle("frac"); scan_std->Draw("axis"); TLine lin; lin.SetLineColor(kGray+2); lin.SetLineStyle(kDashed); for(int n=0; n<=3; n++) lin.DrawLine(1850.,n*n,2200.,n*n); scan_std->Draw("csame"); scan_ext->SetStats(false); scan_ext->SetLineWidth(2); scan_ext->SetLineColor(kRed); scan_ext->SetLineStyle(kDashed); scan_ext->Draw("csame"); }