rf207_comptools.C

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'ADDITION AND CONVOLUTION' RooFit tutorial macro #207
00004 // 
00005 // Tools and utilities for manipulation of composite objects
00006 //
00007 // 
00008 // 07/2008 - Wouter Verkerke 
00009 //
00010 /////////////////////////////////////////////////////////////////////////
00011 
00012 #ifndef __CINT__
00013 #include "RooGlobalFunc.h"
00014 #endif
00015 #include "RooRealVar.h"
00016 #include "RooDataSet.h"
00017 #include "RooGaussian.h"
00018 #include "RooChebychev.h"
00019 #include "RooExponential.h"
00020 #include "RooAddPdf.h"
00021 #include "RooPlot.h"
00022 #include "RooCustomizer.h"
00023 #include "TCanvas.h"
00024 #include "TAxis.h"
00025 #include "TH1.h"
00026 using namespace RooFit ;
00027 
00028 
00029 
00030 void rf207_comptools()
00031 {
00032   
00033   // S e t u p   c o m p o s i t e    p d f,   d a t a s e t 
00034   // --------------------------------------------------------
00035 
00036   // Declare observable x
00037   RooRealVar x("x","x",0,10) ;
00038 
00039   // Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their paramaters
00040   RooRealVar mean("mean","mean of gaussians",5) ;
00041   RooRealVar sigma("sigma","width of gaussians",0.5) ;
00042   RooGaussian sig("sig","Signal component 1",x,mean,sigma) ;  
00043   
00044   // Build Chebychev polynomial p.d.f.  
00045   RooRealVar a0("a0","a0",0.5,0.,1.) ;
00046   RooRealVar a1("a1","a1",-0.2,0.,1.) ;
00047   RooChebychev bkg1("bkg1","Background 1",x,RooArgSet(a0,a1)) ;
00048 
00049   // Build expontential pdf
00050   RooRealVar alpha("alpha","alpha",-1) ;
00051   RooExponential bkg2("bkg2","Background 2",x,alpha) ;
00052 
00053   // Sum the background components into a composite background p.d.f.
00054   RooRealVar bkg1frac("bkg1frac","fraction of component 1 in background",0.2,0.,1.) ;
00055   RooAddPdf bkg("bkg","Signal",RooArgList(bkg1,bkg2),bkg1frac) ;
00056   
00057   // Sum the composite signal and background 
00058   RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ;
00059   RooAddPdf  model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ;
00060 
00061 
00062 
00063   // Create dummy dataset that has more observables than the above pdf
00064   RooRealVar y("y","y",-10,10) ;
00065   RooDataSet data("data","data",RooArgSet(x,y)) ;
00066 
00067 
00068 
00069 
00070   //////////////////////////////////////////////////////////
00071   // B a s i c   i n f o r m a t i o n   r e q u e s t s  //
00072   //////////////////////////////////////////////////////////
00073 
00074 
00075   // G e t   l i s t   o f   o b s e r v a b l e s
00076   // ---------------------------------------------
00077 
00078   // Get list of observables of pdf in context of a dataset
00079   //
00080   // Observables are define each context as the variables
00081   // shared between a model and a dataset. In this case
00082   // that is the variable 'x'
00083 
00084   RooArgSet* model_obs = model.getObservables(data) ;
00085   model_obs->Print("v") ;
00086   
00087 
00088   // G e t   l i s t   o f   p a r a m e t e r s
00089   // -------------------------------------------
00090 
00091   // Get list of parameters, given list of observables
00092   RooArgSet* model_params = model.getParameters(x) ;
00093   model_params->Print("v") ;
00094 
00095   // Get list of parameters, given a dataset
00096   // (Gives identical results to operation above)
00097   RooArgSet* model_params2 = model.getParameters(data) ;
00098   model_params2->Print() ;
00099 
00100 
00101   // G e t   l i s t   o f   c o m p o n e n t s
00102   // -------------------------------------------
00103 
00104   // Get list of component objects, including top-level node
00105   RooArgSet* model_comps = model.getComponents() ;
00106   model_comps->Print("v") ;
00107 
00108 
00109   /////////////////////////////////////////////////////////////////////////////////////
00110   // M o d i f i c a t i o n s   t o   s t r u c t u r e   o f   c o m p o s i t e s //
00111   /////////////////////////////////////////////////////////////////////////////////////
00112 
00113 
00114   // Create a second Gaussian
00115   RooRealVar sigma2("sigma2","width of gaussians",1) ;
00116   RooGaussian sig2("sig2","Signal component 1",x,mean,sigma2) ;  
00117 
00118   // Create a sum of the original Gaussian plus the new second Gaussian
00119   RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
00120   RooAddPdf sigsum("sigsum","sig+sig2",RooArgList(sig,sig2),sig1frac) ;
00121   
00122   // Construct a customizer utility to customize model
00123   RooCustomizer cust(model,"cust") ;
00124 
00125   // Instruct the customizer to replace node 'sig' with node 'sigsum'
00126   cust.replaceArg(sig,sigsum) ;
00127 
00128   // Build a clone of the input pdf according to the above customization
00129   // instructions. Each node that requires modified is clone so that the
00130   // original pdf remained untouched. The name of each cloned node is that
00131   // of the original node suffixed by the name of the customizer object  
00132   //
00133   // The returned head node own all nodes that were cloned as part of
00134   // the build process so when cust_clone is deleted so will all other
00135   // nodes that were created in the process.
00136   RooAbsPdf* cust_clone = (RooAbsPdf*) cust.build(kTRUE) ;
00137   
00138   // Print structure of clone of model with sig->sigsum replacement.
00139   cust_clone->Print("t") ;
00140 
00141 
00142   delete cust_clone ;
00143 
00144 }

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