Plotting issue with multiple filled PDFs using AddTo()

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() ;
}

Dear Dan,

It looks as a sort of known issue (cfr: Odd behaviour using DrawOption("F")). I have asked some roofit experts to comment.
In the meanwhile, as a possible workaround, redrawing the background with a separate name seems to do the job:

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) ;
px.plotOn(frame1,Normalization( n_phys_bg.getVal() , RooAbsReal::NumEvent ) ,
          RooFit::DrawOption("F") , RooFit::FillColor(46) , Name("px_phys")) ;

Hope it helps.
G Ganis

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.