rf211_paramconv.C

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'ADDITION AND CONVOLUTION' RooFit tutorial macro #211
00004 // 
00005 // Working a with a p.d.f. with a convolution operator in terms
00006 // of a parameter
00007 //
00008 // (require ROOT to be compiled with --enable-fftw3)
00009 // 
00010 //
00011 // 04/2009 - Wouter Verkerke 
00012 //
00013 /////////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef __CINT__
00016 #include "RooGlobalFunc.h"
00017 #endif
00018 #include "RooRealVar.h"
00019 #include "RooDataHist.h"
00020 #include "RooGaussian.h"
00021 #include "RooGenericPdf.h"
00022 #include "RooFormulaVar.h"
00023 #include "RooFFTConvPdf.h"
00024 #include "RooPlot.h"
00025 #include "TCanvas.h"
00026 #include "TAxis.h"
00027 #include "TH2.h"
00028 using namespace RooFit ;
00029 
00030 
00031 void rf211_paramconv()
00032 {
00033   // S e t u p   c o m p o n e n t   p d f s 
00034   // ---------------------------------------
00035   
00036   // Gaussian g(x ; mean,sigma) 
00037   RooRealVar x("x","x",-10,10) ;
00038   RooRealVar mean("mean","mean",-3,3) ;
00039   RooRealVar sigma("sigma","sigma",0.5,0.1,10) ;
00040   RooGaussian modelx("gx","gx",x,mean,sigma) ;
00041 
00042   // Block function in mean
00043   RooRealVar a("a","a",2,1,10) ;
00044   RooGenericPdf model_mean("model_mean","abs(mean)<a",RooArgList(mean,a)) ;
00045 
00046   // Convolution in mean parameter model = g(x,mean,sigma) (x) block(mean)
00047   x.setBins(1000,"cache") ;
00048   mean.setBins(50,"cache") ;
00049   RooFFTConvPdf model("model","model",mean,modelx,model_mean) ;
00050 
00051   // Configure convolution to construct a 2-D cache in (x,mean)
00052   // rather than a 1-d cache in mean that needs to be recalculated
00053   // for each value of x
00054   model.setCacheObservables(x) ;
00055   model.setBufferFraction(1.0) ;
00056 
00057   // Integrate model over mean projModel = Int model dmean
00058   RooAbsPdf* projModel = model.createProjection(mean) ;
00059 
00060   // Generate 1000 toy events
00061   RooDataHist* d = projModel->generateBinned(x,1000) ;
00062 
00063   // Fit p.d.f. to toy data
00064   projModel->fitTo(*d,Verbose()) ;
00065 
00066   // Plot data and fitted p.d.f.
00067   RooPlot* frame = x.frame(Bins(25)) ;
00068   d->plotOn(frame) ;
00069   projModel->plotOn(frame) ;
00070 
00071   // Make 2d histogram of model(x;mean)
00072   TH1* hh = model.createHistogram("hh",x,Binning(50),YVar(mean,Binning(50)),ConditionalObservables(mean)) ;
00073   hh->SetTitle("histogram of model(x|mean)") ;
00074   hh->SetLineColor(kBlue) ;
00075 
00076   // Draw frame on canvas
00077   TCanvas* c = new TCanvas("rf211_paramconv","rf211_paramconv",800,400) ;
00078   c->Divide(2) ;
00079   c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;
00080   c->cd(2) ; gPad->SetLeftMargin(0.20) ; hh->GetZaxis()->SetTitleOffset(2.5) ; hh->Draw("surf") ;
00081 
00082 }

Generated on Tue Jul 5 15:45:03 2011 for ROOT_528-00b_version by  doxygen 1.5.1