rf205_compplot.cxx

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'ADDITION AND CONVOLUTION' RooFit tutorial macro #205
00004 // 
00005 // Options for plotting components of composite p.d.f.s.
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 "RooAddPdf.h"
00020 #include "RooChebychev.h"
00021 #include "RooExponential.h"
00022 #include "TCanvas.h"
00023 #include "RooPlot.h"
00024 using namespace RooFit ;
00025 
00026 
00027 class TestBasic205 : public RooFitTestUnit
00028 {
00029 public: 
00030   TestBasic205(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Component plotting variations",refFile,writeRef,verbose) {} ;
00031   Bool_t testCode() {
00032 
00033     // S e t u p   c o m p o s i t e    p d f
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 sigma1("sigma1","width of gaussians",0.5) ;
00042     RooRealVar sigma2("sigma2","width of gaussians",1) ;
00043     RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;  
00044     RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;  
00045     
00046     // Sum the signal components into a composite signal p.d.f.
00047     RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
00048     RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
00049     
00050     // Build Chebychev polynomial p.d.f.  
00051     RooRealVar a0("a0","a0",0.5,0.,1.) ;
00052     RooRealVar a1("a1","a1",-0.2,0.,1.) ;
00053     RooChebychev bkg1("bkg1","Background 1",x,RooArgSet(a0,a1)) ;
00054     
00055     // Build expontential pdf
00056     RooRealVar alpha("alpha","alpha",-1) ;
00057     RooExponential bkg2("bkg2","Background 2",x,alpha) ;
00058     
00059     // Sum the background components into a composite background p.d.f.
00060     RooRealVar bkg1frac("sig1frac","fraction of component 1 in background",0.2,0.,1.) ;
00061     RooAddPdf bkg("bkg","Signal",RooArgList(bkg1,bkg2),sig1frac) ;
00062     
00063     // Sum the composite signal and background 
00064     RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ;
00065     RooAddPdf  model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ;
00066     
00067     
00068     
00069     // S e t u p   b a s i c   p l o t   w i t h   d a t a   a n d   f u l l   p d f 
00070     // ------------------------------------------------------------------------------
00071     
00072     // Generate a data sample of 1000 events in x from model
00073     RooDataSet *data = model.generate(x,1000) ;
00074     
00075     // Plot data and complete PDF overlaid
00076     RooPlot* xframe  = x.frame(Title("Component plotting of pdf=(sig1+sig2)+(bkg1+bkg2)")) ;
00077     data->plotOn(xframe) ;
00078     model.plotOn(xframe) ;
00079     
00080     // Clone xframe for use below
00081     RooPlot* xframe2 = x.frame(Title("Component plotting of pdf=(sig1+sig2)+(bkg1+bkg2)"),Name("xframe2")) ;
00082     
00083     
00084     // M a k e   c o m p o n e n t   b y   o b j e c t   r e f e r e n c e 
00085     // --------------------------------------------------------------------
00086     
00087     // Plot single background component specified by object reference
00088     model.plotOn(xframe,Components(bkg),LineColor(kRed)) ;
00089     
00090     // Plot single background component specified by object reference
00091     model.plotOn(xframe,Components(bkg2),LineStyle(kDashed),LineColor(kRed)) ;
00092     
00093     // Plot multiple background components specified by object reference
00094     // Note that specified components may occur at any level in object tree
00095     // (e.g bkg is component of 'model' and 'sig2' is component 'sig')
00096     model.plotOn(xframe,Components(RooArgSet(bkg,sig2)),LineStyle(kDotted)) ;
00097     
00098     
00099     
00100     // M a k e   c o m p o n e n t   b y   n a m e  /   r e g e x p  
00101     // ------------------------------------------------------------
00102     
00103     // Plot single background component specified by name
00104     model.plotOn(xframe2,Components("bkg"),LineColor(kCyan)) ;
00105     
00106     // Plot multiple background components specified by name
00107     model.plotOn(xframe2,Components("bkg1,sig2"),LineStyle(kDotted),LineColor(kCyan)) ;
00108     
00109     // Plot multiple background components specified by regular expression on name
00110     model.plotOn(xframe2,Components("sig*"),LineStyle(kDashed),LineColor(kCyan)) ;
00111     
00112     // Plot multiple background components specified by multiple regular expressions on name
00113     model.plotOn(xframe2,Components("bkg1,sig*"),LineStyle(kDashed),LineColor(kYellow),Invisible()) ;
00114     
00115     
00116     regPlot(xframe,"rf205_plot1") ;
00117     regPlot(xframe2,"rf205_plot2") ;
00118 
00119     delete data ;
00120     return kTRUE ;
00121 
00122   }
00123 
00124 } ;

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