Logo ROOT   6.08/07
Reference Guide
rf205_compplot.cxx
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 //
3 // 'ADDITION AND CONVOLUTION' RooFit tutorial macro #205
4 //
5 // Options for plotting components of composite p.d.f.s.
6 //
7 //
8 //
9 // 07/2008 - Wouter Verkerke
10 //
11 /////////////////////////////////////////////////////////////////////////
12 
13 #ifndef __CINT__
14 #include "RooGlobalFunc.h"
15 #endif
16 #include "RooRealVar.h"
17 #include "RooDataSet.h"
18 #include "RooGaussian.h"
19 #include "RooAddPdf.h"
20 #include "RooChebychev.h"
21 #include "RooExponential.h"
22 #include "TCanvas.h"
23 #include "RooPlot.h"
24 using namespace RooFit ;
25 
26 
27 class TestBasic205 : public RooFitTestUnit
28 {
29 public:
30  TestBasic205(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Component plotting variations",refFile,writeRef,verbose) {} ;
31  Bool_t testCode() {
32 
33  // S e t u p c o m p o s i t e p d f
34  // --------------------------------------
35 
36  // Declare observable x
37  RooRealVar x("x","x",0,10) ;
38 
39  // Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters
40  RooRealVar mean("mean","mean of gaussians",5) ;
41  RooRealVar sigma1("sigma1","width of gaussians",0.5) ;
42  RooRealVar sigma2("sigma2","width of gaussians",1) ;
43  RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;
44  RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;
45 
46  // Sum the signal components into a composite signal p.d.f.
47  RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
48  RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
49 
50  // Build Chebychev polynomial p.d.f.
51  RooRealVar a0("a0","a0",0.5,0.,1.) ;
52  RooRealVar a1("a1","a1",-0.2,0.,1.) ;
53  RooChebychev bkg1("bkg1","Background 1",x,RooArgSet(a0,a1)) ;
54 
55  // Build expontential pdf
56  RooRealVar alpha("alpha","alpha",-1) ;
57  RooExponential bkg2("bkg2","Background 2",x,alpha) ;
58 
59  // Sum the background components into a composite background p.d.f.
60  RooRealVar bkg1frac("sig1frac","fraction of component 1 in background",0.2,0.,1.) ;
61  RooAddPdf bkg("bkg","Signal",RooArgList(bkg1,bkg2),sig1frac) ;
62 
63  // Sum the composite signal and background
64  RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ;
65  RooAddPdf model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ;
66 
67 
68 
69  // 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
70  // ------------------------------------------------------------------------------
71 
72  // Generate a data sample of 1000 events in x from model
73  RooDataSet *data = model.generate(x,1000) ;
74 
75  // Plot data and complete PDF overlaid
76  RooPlot* xframe = x.frame(Title("Component plotting of pdf=(sig1+sig2)+(bkg1+bkg2)")) ;
77  data->plotOn(xframe) ;
78  model.plotOn(xframe) ;
79 
80  // Clone xframe for use below
81  RooPlot* xframe2 = x.frame(Title("Component plotting of pdf=(sig1+sig2)+(bkg1+bkg2)"),Name("xframe2")) ;
82 
83 
84  // 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
85  // --------------------------------------------------------------------
86 
87  // Plot single background component specified by object reference
88  model.plotOn(xframe,Components(bkg),LineColor(kRed)) ;
89 
90  // Plot single background component specified by object reference
91  model.plotOn(xframe,Components(bkg2),LineStyle(kDashed),LineColor(kRed)) ;
92 
93  // Plot multiple background components specified by object reference
94  // Note that specified components may occur at any level in object tree
95  // (e.g bkg is component of 'model' and 'sig2' is component 'sig')
96  model.plotOn(xframe,Components(RooArgSet(bkg,sig2)),LineStyle(kDotted)) ;
97 
98 
99 
100  // 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
101  // ------------------------------------------------------------
102 
103  // Plot single background component specified by name
104  model.plotOn(xframe2,Components("bkg"),LineColor(kCyan)) ;
105 
106  // Plot multiple background components specified by name
107  model.plotOn(xframe2,Components("bkg1,sig2"),LineStyle(kDotted),LineColor(kCyan)) ;
108 
109  // Plot multiple background components specified by regular expression on name
110  model.plotOn(xframe2,Components("sig*"),LineStyle(kDashed),LineColor(kCyan)) ;
111 
112  // Plot multiple background components specified by multiple regular expressions on name
113  model.plotOn(xframe2,Components("bkg1,sig*"),LineStyle(kDashed),LineColor(kYellow),Invisible()) ;
114 
115 
116  regPlot(xframe,"rf205_plot1") ;
117  regPlot(xframe2,"rf205_plot2") ;
118 
119  delete data ;
120  return kTRUE ;
121 
122  }
123 
124 } ;
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:29
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Plot dataset on specified frame.
Definition: RooAbsData.cxx:552
RooCmdArg Invisible()
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:61
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Definition: Rtypes.h:61
RooCmdArg Title(const char *name)
Double_t x[n]
Definition: legend1.C:17
RooCmdArg LineStyle(Style_t style)
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
Exponential p.d.f.
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
RooCmdArg Name(const char *name)
bool verbose
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
RooCmdArg Components(const RooArgSet &compSet)
Definition: Rtypes.h:61
Chebychev polynomial p.d.f.
Definition: RooChebychev.h:25
const Bool_t kTRUE
Definition: Rtypes.h:91