Extend PDFs via composition
// Extend PDFs via composition
intro4()
{
// Build Gaussian PDF
RooRealVar x("x","x",-10,10) ;
RooRealVar y("y","y",0,3) ;
// g(x,m,s)
// m -> m(y) = m0 + m1*y
// g(x,m(y),s)
// Build a parameterized mean variable for gauss
RooRealVar mean0("mean0","offset of mean function",0.5) ;
RooRealVar mean1("mean1","slope of mean function",3.0) ;
RooFormulaVar mean("mean","parameterized mean","mean0+mean1*y",RooArgList(mean0,mean1,y)) ;
RooRealVar sigma("sigma","width of gaussian",3) ;
RooGaussian gauss("gauss","gaussian PDF",x,mean,sigma) ;
// Generate a toy MC set
RooDataSet* data = gauss.generate(RooArgList(x,y),10000) ;
// Plot data and PDF overlaid
TCanvas *c = new TCanvas("c","c",800, 600);
c->Divide(2,1);
// Plot x projection
c->cd(1) ;
RooPlot* xframe = x.frame() ;
data->plotOn(xframe) ;
gauss->plotOn(xframe) ; // plots f(x) = Int(dy) pdf(x,y)
xframe->Draw() ;
// Plot y projection
c->cd(2) ;
RooPlot* yframe = y.frame() ;
data->plotOn(yframe) ;
gauss->plotOn(yframe) ; // plots f(y) = Int(dx) pdf(x,y)
yframe->Draw() ;
}
Copyright © 2000-2005 University of California, Stanford University
|