Hi,
I have a problem in plotting the correct PDF projection using RooSimultaneous and RooSimPDFBuiler when one or more splitCat are involved.
I’ve modified a roofit tutorial macro ($ROOTSYS/tutorials/roofit/rf501_simultaneouspdf.C) in order to
reproduce the error.
I have a PDF called “model” and two categories of events: “peaches” and
"apples". I generate the events belonging to the two categories with the
same PDF (model) but with two different means. Then I fit them
simultaneously allowing for different means: the fit is good.
Then I try to plot the “apples” data and PDF in a frame and the “peaches” data and
PDF in another frame but I got the wrong PDF projection for the “apples” category.
The macro is:
#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooChebychev.h"
#include "RooAddPdf.h"
#include "RooSimultaneous.h"
#include "RooCategory.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit ;
void testPlot()
{
// C r e a t e m o d e l f o r p h y s i c s s a m p l e
// -------------------------------------------------------------
// Create observables
RooRealVar x("x","x",-8,8) ;
// Construct signal pdf
RooRealVar mean("mean","mean",1,-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.1,-1,1) ;
RooRealVar a1("a1","a1",0.004,-1,1) ;
RooChebychev px("px","px",x,RooArgSet(a0,a1)) ;
// Construct composite pdf
RooRealVar f("f","f",0.2,0.,1.) ;
RooAddPdf model("model","model",RooArgList(gx,px),f) ;
// G e n e r a t e e v e n t s f o r b o t h s a m p l e s
// ---------------------------------------------------------------
// Generate 1000 events in x and y from model
RooDataSet *data_apples = model.generate(RooArgSet(x),1000) ;
mean.setVal(-1);
RooDataSet *data_peaches = model.generate(RooArgSet(x),1000) ;
// C r e a t e i n d e x c a t e g o r y a n d j o i n s a m p l e s
// ---------------------------------------------------------------------------
// Define category to distinguish physics and control samples events
RooCategory sample("sample","sample") ;
sample.defineType("apples") ;
sample.defineType("peaches") ;
// Construct combined dataset in (x,sample)
RooDataSet combData("combData","combined data",x,Index(sample),Import("apples",*data_apples),Import("peaches",*data_peaches)) ;
// C o n s t r u c t a s i m u l t a n e o u s p d f i n ( x , s a m p l e )
// -----------------------------------------------------------------------------------
RooSimPdfBuilder builder(model);
RooArgSet *configuration = builder.createProtoBuildConfig();
configuration->readFromFile("testPlot.config",0,"Fit Models");
//testPlot.config
//[Fit Models]
//================
//physModels = model
//splitCats = sample
//model = sample : mean
RooSimultaneous *simPdf;
simPdf = builder.buildPdf(*configuration,&combData);
// P e r f o r m a s i m u l t a n e o u s f i t
// ---------------------------------------------------
// Perform simultaneous fit of model to data and model_ctl to data_ctl
simPdf->fitTo(combData) ;
// P l o t m o d e l s l i c e s o n d a t a s l i c e s
// ----------------------------------------------------------------
// Make a frame for the physics sample"<<endl;
RooPlot* frame1 = x.frame(Bins(30),Title("apples sample")) ;
// Plot all data tagged as physics sample"<<endl;
combData.plotOn(frame1,Cut("sample==sample::apples")) ;
// Plot physics slice of simultaneous pdf. NBL You _must_ project the sample index category with data using ProjWData as a RooSimultaneous makes no prediction on the shape in the index category and can thus not be integrated
simPdf->plotOn(frame1,Slice(sample,"apples"),ProjWData(sample,combData)) ;
simPdf->plotOn(frame1,Slice(sample,"apples"),Components("px"),ProjWData(sample,combData),LineStyle(kDashed)) ;
// The same plot for the control sample slice
RooPlot* frame2 = x.frame(Bins(30),Title("peaches sample")) ;
combData.plotOn(frame2,Cut("sample==sample::peaches")) ;
simPdf->plotOn(frame2,Slice(sample,"peaches"),ProjWData(sample,combData)) ;
simPdf->plotOn(frame2,Slice(sample,"peaches"),Components("px"),ProjWData(sample,combData),LineStyle(kDashed)) ;
TCanvas* c = new TCanvas("testPlot","test plot",800,400) ;
c->Divide(2) ;
c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ;
c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
}
I got this plots: slac.stanford.edu/~gcasa/tes … stPlot.png
It’s clear that the PDF in the “apple” case is not correct since it has the wrong mean.
You can find here: slac.stanford.edu/~gcasa/tes … stPlot.log
the log file
Does anyone have any idea of why the wrong PDF projection is plotted?
I’ve run this macro on root 5.24, root 5.26 and also 5.28 but the output does not change.
thank you,
Giulia