ROOT  6.06/09
Reference Guide
rf804_mcstudy_constr.cxx
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////
2 //
3 // 'VALIDATION AND MC STUDIES' RooFit tutorial macro #804
4 //
5 // Using RooMCStudy on models with constrains
6 //
7 //
8 // 07/2008 - Wouter Verkerke
9 //
10 /////////////////////////////////////////////////////////////////////////
11 
12 #ifndef __CINT__
13 #include "RooGlobalFunc.h"
14 #endif
15 #include "RooRealVar.h"
16 #include "RooDataSet.h"
17 #include "RooGaussian.h"
18 #include "RooPolynomial.h"
19 #include "RooAddPdf.h"
20 #include "RooProdPdf.h"
21 #include "RooMCStudy.h"
22 #include "RooPlot.h"
23 #include "TCanvas.h"
24 #include "TH1.h"
25 using namespace RooFit ;
26 
27 
28 class TestBasic804 : public RooFitTestUnit
29 {
30 public:
31  TestBasic804(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("MC Studies with aux. obs. constraints",refFile,writeRef,verbose) {} ;
32 
33  Double_t htol() { return 0.1 ; } // numerically very difficult test
34 
35  Bool_t testCode() {
36 
37  // C r e a t e m o d e l w i t h p a r a m e t e r c o n s t r a i n t
38  // ---------------------------------------------------------------------------
39 
40  // Observable
41  RooRealVar x("x","x",-10,10) ;
42 
43  // Signal component
44  RooRealVar m("m","m",0,-10,10) ;
45  RooRealVar s("s","s",2,0.1,10) ;
46  RooGaussian g("g","g",x,m,s) ;
47 
48  // Background component
49  RooPolynomial p("p","p",x) ;
50 
51  // Composite model
52  RooRealVar f("f","f",0.4,0.,1.) ;
53  RooAddPdf sum("sum","sum",RooArgSet(g,p),f) ;
54 
55  // Construct constraint on parameter f
56  RooGaussian fconstraint("fconstraint","fconstraint",f,RooConst(0.7),RooConst(0.1)) ;
57 
58  // Multiply constraint with p.d.f
59  RooProdPdf sumc("sumc","sum with constraint",RooArgSet(sum,fconstraint)) ;
60 
61 
62 
63  // S e t u p t o y s t u d y w i t h m o d e l
64  // ---------------------------------------------------
65 
66  // Perform toy study with internal constraint on f
68 
69  // Run 50 toys of 2000 events.
70  // Before each toy is generated, a value for the f is sampled from the constraint pdf and
71  // that value is used for the generation of that toy.
72  mcs.generateAndFit(50,2000) ;
73 
74  // Make plot of distribution of generated value of f parameter
75  RooRealVar* f_gen = (RooRealVar*) mcs.fitParDataSet().get()->find("f_gen") ;
76  TH1* h_f_gen = new TH1F("h_f_gen","",40,0,1) ;
77  mcs.fitParDataSet().fillHistogram(h_f_gen,*f_gen) ;
78 
79  // Make plot of distribution of fitted value of f parameter
80  RooPlot* frame1 = mcs.plotParam(f,Bins(40),Range(0.4,1)) ;
81  frame1->SetTitle("Distribution of fitted f values") ;
82 
83  // Make plot of pull distribution on f
84  RooPlot* frame2 = mcs.plotPull(f,Bins(40),Range(-3,3)) ;
85  frame1->SetTitle("Distribution of f pull values") ;
86 
87  regTH(h_f_gen,"rf804_h_f_gen") ;
88  regPlot(frame1,"rf804_plot1") ;
89  regPlot(frame2,"rf804_plot2") ;
90 
91  return kTRUE ;
92  }
93 } ;
94 
RooCmdArg Binned(Bool_t flag=kTRUE)
RooCmdArg PrintLevel(Int_t code)
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
THist< 1, float > TH1F
Definition: THist.h:315
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void SetTitle(const char *name)
Set the title of the RooPlot to 'title'.
Definition: RooPlot.cxx:1099
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
Double_t x[n]
Definition: legend1.C:17
RooCmdArg Silence(Bool_t flag=kTRUE)
RooCmdArg FitOptions(const char *opts)
TMarker * m
Definition: textangle.C:8
bool verbose
double f(double x)
double Double_t
Definition: RtypesCore.h:55
The TH1 histogram class.
Definition: TH1.h:80
RooConstVar & RooConst(Double_t val)
RooCmdArg Bins(Int_t nbin)
const Bool_t kTRUE
Definition: Rtypes.h:91
RooCmdArg Constrain(const RooArgSet &params)