using namespace RooFit; void example_02() { TFile *fin = new TFile("example_splusb.root"); TNtupleD* nt = (TNtupleD *)fin->Get("nt"); RooRealVar mass("mass","mass obs",0.,2.); RooRealVar mu("mu","signal mean",1.0); RooRealVar sigma("sigma","signal width",0.05); RooGaussian gaus("gaus","signal PDF",mass,mu,sigma); RooRealVar slope("slope","background slope",-0.3,-5.,5.); RooPolynomial linear("linear","background PDF",mass,RooArgSet(slope)); RooRealVar ns("ns","ns",10,0.,1000.); RooRealVar nb("nb","nb",90,0.,1000.); RooAddPdf model("model","mass PDF",RooArgList(gaus,linear),RooArgList(ns,nb)); RooRealVar slope_mu("slope_mu","slope mean",-0.3); RooRealVar slope_sigma("slope_sigma","slope sigma",0.03); RooGaussian cons("cons","constrained PDF",slope,slope_mu,slope_sigma); RooDataSet data("data","data",nt,RooArgSet(mass)); model.fitTo(data,ExternalConstraints(cons)); RooPlot *frame = mass.frame(Bins(25)); data.plotOn(frame); model.plotOn(frame); frame->Draw(); }