/// Example demonstrating problem with projections /// Based on 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #310 #include "RooRealVar.h" #include "RooDataSet.h" #include "RooGaussian.h" #include "RooConstVar.h" #include "RooProdPdf.h" #include "RooAddPdf.h" #include "RooPolynomial.h" #include "TCanvas.h" #include "TAxis.h" #include "RooPlot.h" using namespace RooFit ; void min_example() { // C r e a t e 3 D p d f a n d d a t a // ------------------------------------------- // Create observables RooRealVar x("x","x",-5,5) ; RooRealVar y("y","y",-5,5) ; RooRealVar z("z","z",-5,5) ; // Create signal pdf gauss(x)*gauss(y)*gauss(z) RooGaussian gx("gx","gx",x,RooConst(0),RooConst(1)) ; RooGaussian gy("gy","gy",y,RooConst(0),RooConst(1)) ; RooGaussian gz("gz","gz",z,RooConst(0),RooConst(1)) ; RooProdPdf sig("sig","sig",RooArgSet(gx,gy,gz)) ; // Create RooHistPdf for signal shape RooDataSet* signal_data = sig.generate(RooArgSet(x,y,z),20000) ; x.setBins(40); y.setBins(40); RooDataHist dh("dh","binned version of d",RooArgSet(x,y),*signal_data); RooHistPdf sig_xy_hist("sig_xy_hist","sig_xy_hist",RooArgSet(x,y), dh); RooProdPdf sig_hist("sig_hist","sig_hist",RooArgSet(sig_xy_hist,gz)) ; // Create background pdf poly(x)*poly(y)*poly(z) RooPolynomial px("px","px",x,RooArgSet(RooConst(-0.1),RooConst(0.004))) ; RooPolynomial py("py","py",y,RooArgSet(RooConst(0.1),RooConst(-0.004))) ; RooPolynomial pz("pz","pz",z) ; RooProdPdf bkg("bkg","bkg",RooArgSet(px,py,pz)) ; // Create composite pdf sig+bkg RooRealVar fsig("fsig","signal fraction",0.1,0.,1.) ; RooAddPdf model("model","model",RooArgList(sig,bkg),fsig) ; RooAddPdf model_hist("model_hist","model_hist",RooArgList(sig_hist,bkg),fsig) ; RooDataSet* data = model.generate(RooArgSet(x,y,z),20000) ; // P r o j e c t p d f a n d d a t a o n x // ------------------------------------------------- // Make plain projection of data and pdf on x observable RooPlot* frame = x.frame(Title("Projection of 3D data and pdf on X"),Bins(40)) ; data->plotOn(frame) ; model.plotOn(frame) ; // Do the same thing for the model with RooHistPdf RooPlot* frame_hist = x.frame(Title("Projection of 3D data and pdf on X"),Bins(40)) ; data->plotOn(frame_hist) ; model_hist.plotOn(frame_hist) ; // P r o j e c t p d f a n d d a t a o n x i n s i g n a l r a n g e // ---------------------------------------------------------------------------------- // Define signal region in y and z observables y.setRange("sigRegion",-1,1) ; z.setRange("sigRegion",-1,1) ; // Make plot frame RooPlot* frame2 = x.frame(Title("Same projection on X in signal range of (Y,Z)"),Bins(40)) ; RooPlot* frame2_hist = x.frame(Title("Same projection on X in signal range of (Y,Z)"),Bins(40)) ; // Plot subset of data in which all observables are inside "sigRegion" // For observables that do not have an explicit "sigRegion" range defined (e.g. observable) // an implicit definition is used that is identical to the full range (i.e. [-5,5] for x) data->plotOn(frame2,CutRange("sigRegion")) ; data->plotOn(frame2_hist,CutRange("sigRegion")) ; // Project model on x, integrating projected observables (y,z) only in "sigRegion" model.plotOn(frame2,ProjectionRange("sigRegion")) ; // And the same thing for model with RooHistPdf model_hist.plotOn(frame2_hist,ProjectionRange("sigRegion")) ; TCanvas* c = new TCanvas("rf311_rangeplot","rf310_rangeplot",800,400) ; c->Divide(2) ; c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ; c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ; TCanvas* c_hist = new TCanvas("rf311_rangeplot_hist","rf310_rangeplot_hist",800,400) ; c_hist->Divide(2) ; c_hist->cd(1) ; gPad->SetLeftMargin(0.15) ; frame_hist->GetYaxis()->SetTitleOffset(1.4) ; frame_hist->Draw() ; c_hist->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2_hist->GetYaxis()->SetTitleOffset(1.4) ; frame2_hist->Draw() ; }