Logo ROOT   6.07/09
Reference Guide
rf803_mcstudy_addons2.cxx
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////
2 //
3 // 'VALIDATION AND MC STUDIES' RooFit tutorial macro #803
4 //
5 // RooMCStudy: Using the randomizer and profile likelihood add-on models
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 "RooChebychev.h"
19 #include "RooAddPdf.h"
20 #include "RooMCStudy.h"
23 #include "RooPlot.h"
24 #include "TCanvas.h"
25 #include "TH1.h"
26 #include "TDirectory.h"
27 
28 using namespace RooFit ;
29 
30 
31 class TestBasic803 : public RooFitTestUnit
32 {
33 public:
34  TestBasic803(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("MC Study with param rand. and Z calc",refFile,writeRef,verbose) {} ;
35  Bool_t testCode() {
36 
37  // C r e a t e m o d e l
38  // -----------------------
39 
40  // Simulation of signal and background of top quark decaying into
41  // 3 jets with background
42 
43  // Observable
44  RooRealVar mjjj("mjjj","m(3jet) (GeV)",100,85.,350.) ;
45 
46  // Signal component (Gaussian)
47  RooRealVar mtop("mtop","m(top)",162) ;
48  RooRealVar wtop("wtop","m(top) resolution",15.2) ;
49  RooGaussian sig("sig","top signal",mjjj,mtop,wtop) ;
50 
51  // Background component (Chebychev)
52  RooRealVar c0("c0","Chebychev coefficient 0",-0.846,-1.,1.) ;
53  RooRealVar c1("c1","Chebychev coefficient 1", 0.112,-1.,1.) ;
54  RooRealVar c2("c2","Chebychev coefficient 2", 0.076,-1.,1.) ;
55  RooChebychev bkg("bkg","combinatorial background",mjjj,RooArgList(c0,c1,c2)) ;
56 
57  // Composite model
58  RooRealVar nsig("nsig","number of signal events",53,0,1e3) ;
59  RooRealVar nbkg("nbkg","number of background events",103,0,5e3) ;
60  RooAddPdf model("model","model",RooArgList(sig,bkg),RooArgList(nsig,nbkg)) ;
61 
62 
63 
64  // C r e a t e m a n a g e r
65  // ---------------------------
66 
67  // Configure manager to perform binned extended likelihood fits (Binned(),Extended()) on data generated
68  // with a Poisson fluctuation on Nobs (Extended())
69  RooMCStudy* mcs = new RooMCStudy(model,mjjj,Binned(),Silence(),Extended(kTRUE),
71 
72 
73 
74  // C u s t o m i z e m a n a g e r
75  // ---------------------------------
76 
77  // Add module that randomizes the summed value of nsig+nbkg
78  // sampling from a uniform distribution between 0 and 1000
79  //
80  // In general one can randomize a single parameter, or a
81  // sum of N parameters, using either a uniform or a Gaussian
82  // distribution. Multiple randomization can be executed
83  // by a single randomizer module
84 
85  RooRandomizeParamMCSModule randModule ;
86  randModule.sampleSumUniform(RooArgSet(nsig,nbkg),50,500) ;
87  mcs->addModule(randModule) ;
88 
89 
90  // Add profile likelihood calculation of significance. Redo each
91  // fit while keeping parameter nsig fixed to zero. For each toy,
92  // the difference in -log(L) of both fits is stored, as well
93  // a simple significance interpretation of the delta(-logL)
94  // using Dnll = 0.5 sigma^2
95 
96  RooDLLSignificanceMCSModule sigModule(nsig,0) ;
97  mcs->addModule(sigModule) ;
98 
99 
100 
101  // R u n m a n a g e r , m a k e p l o t s
102  // ---------------------------------------------
103 
104  mcs->generateAndFit(50) ;
105 
106  // Make some plots
107  RooRealVar* ngen = (RooRealVar*) mcs->fitParDataSet().get()->find("ngen") ;
108  RooRealVar* dll = (RooRealVar*) mcs->fitParDataSet().get()->find("dll_nullhypo_nsig") ;
109  RooRealVar* z = (RooRealVar*) mcs->fitParDataSet().get()->find("significance_nullhypo_nsig") ;
110  RooRealVar* nsigerr = (RooRealVar*) mcs->fitParDataSet().get()->find("nsigerr") ;
111 
112  TH1* dll_vs_ngen = new TH2F("h_dll_vs_ngen" ,"",40,0,500,40,0,50) ;
113  TH1* z_vs_ngen = new TH2F("h_z_vs_ngen" ,"",40,0,500,40,0,10) ;
114  TH1* errnsig_vs_ngen = new TH2F("h_nsigerr_vs_ngen","",40,0,500,40,0,30) ;
115  TH1* errnsig_vs_nsig = new TH2F("h_nsigerr_vs_nsig","",40,0,200,40,0,30) ;
116 
117  mcs->fitParDataSet().fillHistogram(dll_vs_ngen,RooArgList(*ngen,*dll)) ;
118  mcs->fitParDataSet().fillHistogram(z_vs_ngen,RooArgList(*ngen,*z)) ;
119  mcs->fitParDataSet().fillHistogram(errnsig_vs_ngen,RooArgList(*ngen,*nsigerr)) ;
120  mcs->fitParDataSet().fillHistogram(errnsig_vs_nsig,RooArgList(nsig,*nsigerr)) ;
121 
122  regTH(dll_vs_ngen,"rf803_dll_vs_ngen") ;
123  regTH(z_vs_ngen,"rf803_z_vs_ngen") ;
124  regTH(errnsig_vs_ngen,"rf803_errnsig_vs_ngen") ;
125  regTH(errnsig_vs_nsig,"rf803_errnsig_vs_nsig") ;
126 
127  delete mcs ;
128 
129  return kTRUE ;
130 
131  }
132 } ;
133 
134 
135 
136 
void sampleSumUniform(const RooArgSet &paramSet, Double_t lo, Double_t hi)
Request uniform smearing of sum of parameters in paramSet uniform smearing in range [lo...
RooMCStudy is a help class to facilitate Monte Carlo studies such as 'goodness-of-fit' studies...
Definition: RooMCStudy.h:32
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:29
RooCmdArg Binned(Bool_t flag=kTRUE)
return c1
Definition: legend1.C:41
const RooDataSet & fitParDataSet()
Return a RooDataSet the resulting fit parameters of each toy cycle.
Definition: RooMCStudy.cxx:956
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
RooCmdArg PrintEvalErrors(Int_t numErrors)
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
RooCmdArg Extended(Bool_t flag=kTRUE)
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
void addModule(RooAbsMCStudyModule &module)
Insert given RooMCStudy add-on module to the processing chain of this MCStudy object.
Definition: RooMCStudy.cxx:438
Bool_t generateAndFit(Int_t nSamples, Int_t nEvtPerSample=0, Bool_t keepGenData=kFALSE, const char *asciiFilePat=0)
Generate and fit 'nSamples' samples of 'nEvtPerSample' events.
Definition: RooMCStudy.cxx:653
RooCmdArg Silence(Bool_t flag=kTRUE)
RooDLLSignificanceMCSModule is an add-on modules to RooMCStudy that calculates the significance of a ...
RooCmdArg FitOptions(const char *opts)
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooRandomizeParamMCSModule is an add-on modules to RooMCStudy that allows you to randomize input gene...
bool verbose
return c2
Definition: legend2.C:14
The TH1 histogram class.
Definition: TH1.h:80
virtual TH1 * fillHistogram(TH1 *hist, const RooArgList &plotVars, const char *cuts="", const char *cutRange=0) const
Loop over columns of our tree data and fill the input histogram.
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
Chebychev polynomial p.d.f.
Definition: RooChebychev.h:25
const Bool_t kTRUE
Definition: Rtypes.h:91
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
Definition: THist.hxx:308
virtual const RooArgSet * get(Int_t index) const
Return RooArgSet with coordinates of event &#39;index&#39;.