rf603_multicpu.C

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'LIKELIHOOD AND MINIMIZATION' RooFit tutorial macro #603
00004 // 
00005 // Setting up a multi-core parallelized unbinned maximum likelihood fit
00006 //
00007 //
00008 //
00009 // 07/2008 - Wouter Verkerke 
00010 // 
00011 /////////////////////////////////////////////////////////////////////////
00012 
00013 #ifndef __CINT__
00014 #include "RooGlobalFunc.h"
00015 #endif
00016 #include "RooRealVar.h"
00017 #include "RooDataSet.h"
00018 #include "RooGaussian.h"
00019 #include "RooConstVar.h"
00020 #include "RooPolynomial.h"
00021 #include "RooAddPdf.h"
00022 #include "RooProdPdf.h"
00023 #include "TCanvas.h"
00024 #include "TAxis.h"
00025 #include "RooPlot.h"
00026 using namespace RooFit ;
00027 
00028 
00029 void rf603_multicpu()
00030 {
00031 
00032   // C r e a t e   3 D   p d f   a n d   d a t a 
00033   // -------------------------------------------
00034 
00035   // Create observables
00036   RooRealVar x("x","x",-5,5) ;
00037   RooRealVar y("y","y",-5,5) ;
00038   RooRealVar z("z","z",-5,5) ;
00039 
00040   // Create signal pdf gauss(x)*gauss(y)*gauss(z) 
00041   RooGaussian gx("gx","gx",x,RooConst(0),RooConst(1)) ;
00042   RooGaussian gy("gy","gy",y,RooConst(0),RooConst(1)) ;
00043   RooGaussian gz("gz","gz",z,RooConst(0),RooConst(1)) ;
00044   RooProdPdf sig("sig","sig",RooArgSet(gx,gy,gz)) ;
00045 
00046   // Create background pdf poly(x)*poly(y)*poly(z) 
00047   RooPolynomial px("px","px",x,RooArgSet(RooConst(-0.1),RooConst(0.004))) ;
00048   RooPolynomial py("py","py",y,RooArgSet(RooConst(0.1),RooConst(-0.004))) ;
00049   RooPolynomial pz("pz","pz",z) ;
00050   RooProdPdf bkg("bkg","bkg",RooArgSet(px,py,pz)) ;
00051 
00052   // Create composite pdf sig+bkg
00053   RooRealVar fsig("fsig","signal fraction",0.1,0.,1.) ;
00054   RooAddPdf model("model","model",RooArgList(sig,bkg),fsig) ;
00055 
00056   // Generate large dataset
00057   RooDataSet* data = model.generate(RooArgSet(x,y,z),200000) ;
00058 
00059 
00060 
00061   // P a r a l l e l   f i t t i n g 
00062   // -------------------------------
00063 
00064   // In parallel mode the likelihood calculation is split in N pieces,
00065   // that are calculated in parallel and added a posteriori before passing
00066   // it back to MINUIT.
00067 
00068   // Use four processes and time results both in wall time and CPU time
00069   model.fitTo(*data,NumCPU(4),Timer(kTRUE)) ;
00070 
00071 
00072 
00073   // P a r a l l e l   M C   p r o j e c t i o n s 
00074   // ----------------------------------------------
00075 
00076   // Construct signal, total likelihood projection on (y,z) observables and likelihood ratio
00077   RooAbsPdf* sigyz = sig.createProjection(x) ;
00078   RooAbsPdf* totyz = model.createProjection(x) ;
00079   RooFormulaVar llratio_func("llratio","log10(@0)-log10(@1)",RooArgList(*sigyz,*totyz)) ;
00080 
00081   // Calculate likelihood ratio for each event, define subset of events with high signal likelihood
00082   data->addColumn(llratio_func) ;
00083   RooDataSet* dataSel = (RooDataSet*) data->reduce(Cut("llratio>0.7")) ;
00084 
00085   // Make plot frame and plot data
00086   RooPlot* frame = x.frame(Title("Projection on X with LLratio(y,z)>0.7"),Bins(40)) ;
00087   dataSel->plotOn(frame) ;
00088 
00089   // Perform parallel projection using MC integration of pdf using given input dataSet. 
00090   // In this mode the data-weighted average of the pdf is calculated by splitting the
00091   // input dataset in N equal pieces and calculating in parallel the weighted average
00092   // one each subset. The N results of those calculations are then weighted into the
00093   // final result
00094   
00095   // Use four processes
00096   model.plotOn(frame,ProjWData(*dataSel),NumCPU(4)) ;
00097 
00098 
00099   new TCanvas("rf603_multicpu","rf603_multicpu",600,600) ;
00100   gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.6) ; frame->Draw() ;
00101 
00102 }

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