Hi,
I try to plot a simple two-component fit by accessing the constituent PDFs as follows:
gx.plotOn(frame1,Normalization( n_phys_sig.getVal() , RooAbsReal::NumEvent ) ,
RooFit::DrawOption("F") , RooFit::FillColor(46) , Name("gx_phys") , Invisible() ) ;
px.plotOn(frame1,Normalization( n_phys_bg.getVal() , RooAbsReal::NumEvent ) ,
RooFit::DrawOption("F") , RooFit::FillColor(46) , AddTo("gx_phys")) ;
but there is a problem with the resulting image. It only occurs with filled PDFs. Am I doing this correctly?
Thanks,
Dan
You can reproduce the error using this small piece of code:
using namespace RooFit ;
void example()
{
// Create observables
RooRealVar x("x","x",-8,8) ;
// Construct signal pdf
RooRealVar mean("mean","mean",0,-8,8) ;
RooRealVar sigma("sigma","sigma",0.3,0.1,10) ;
RooGaussian gx("gx","gx",x,mean,sigma) ;
// Construct background pdf
RooRealVar a0("a0","a0",-0.01,-1,1) ;
RooRealVar a1("a1","a1",0.0004,-1,1) ;
RooChebychev px("px","px",x,RooArgSet(a0,a1)) ;
// Combine
RooRealVar n_phys_sig("n_phys_sig","",20,0,1000) ;
RooRealVar n_phys_bg("n_phys_bg","",100,0,1000) ;
RooAddPdf model("model","model",RooArgList(gx,px),RooArgList(n_phys_sig,n_phys_bg)) ;
// Generate events
RooDataSet *data = model.generate(RooArgSet(x),1000) ;
// Perform fit of model to data
model.fitTo(*data) ;
// Plot model and data
RooPlot* frame1 = x.frame(Bins(30),Title("Physics sample")) ;
data->plotOn(frame1) ;
gx.plotOn(frame1,Normalization( n_phys_sig.getVal() , RooAbsReal::NumEvent ) ,
RooFit::DrawOption("F") , RooFit::FillColor(46) , Name("gx_phys") , Invisible() ) ;
px.plotOn(frame1,Normalization( n_phys_bg.getVal() , RooAbsReal::NumEvent ) ,
RooFit::DrawOption("F") , RooFit::FillColor(46) , AddTo("gx_phys")) ;
data->plotOn(frame1) ;
TCanvas* c = new TCanvas() ;
frame1->Draw() ;
}