Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
rf803_mcstudy_addons2.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// Validation and MC studies: RooMCStudy - Using the randomizer and profile likelihood add-on models
5 ///
6 /// \macro_image
7 /// \macro_output
8 /// \macro_code
9 /// \author 07/2008 - Wouter Verkerke
10 
11 #include "RooRealVar.h"
12 #include "RooDataSet.h"
13 #include "RooGaussian.h"
14 #include "RooConstVar.h"
15 #include "RooChebychev.h"
16 #include "RooAddPdf.h"
17 #include "RooMCStudy.h"
20 #include "RooPlot.h"
21 #include "TCanvas.h"
22 #include "TAxis.h"
23 #include "TH1.h"
24 #include "TDirectory.h"
25 
26 using namespace RooFit;
27 
28 void rf803_mcstudy_addons2()
29 {
30  // C r e a t e m o d e l
31  // -----------------------
32 
33  // Simulation of signal and background of top quark decaying into
34  // 3 jets with background
35 
36  // Observable
37  RooRealVar mjjj("mjjj", "m(3jet) (GeV)", 100, 85., 350.);
38 
39  // Signal component (Gaussian)
40  RooRealVar mtop("mtop", "m(top)", 162);
41  RooRealVar wtop("wtop", "m(top) resolution", 15.2);
42  RooGaussian sig("sig", "top signal", mjjj, mtop, wtop);
43 
44  // Background component (Chebychev)
45  RooRealVar c0("c0", "Chebychev coefficient 0", -0.846, -1., 1.);
46  RooRealVar c1("c1", "Chebychev coefficient 1", 0.112, -1., 1.);
47  RooRealVar c2("c2", "Chebychev coefficient 2", 0.076, -1., 1.);
48  RooChebychev bkg("bkg", "combinatorial background", mjjj, RooArgList(c0, c1, c2));
49 
50  // Composite model
51  RooRealVar nsig("nsig", "number of signal events", 53, 0, 1e3);
52  RooRealVar nbkg("nbkg", "number of background events", 103, 0, 5e3);
53  RooAddPdf model("model", "model", RooArgList(sig, bkg), RooArgList(nsig, nbkg));
54 
55  // C r e a t e m a n a g e r
56  // ---------------------------
57 
58  // Configure manager to perform binned extended likelihood fits (Binned(),Extended()) on data generated
59  // with a Poisson fluctuation on Nobs (Extended())
60  RooMCStudy *mcs = new RooMCStudy(model, mjjj, Binned(), Silence(), Extended(kTRUE),
61  FitOptions(Extended(kTRUE), PrintEvalErrors(-1)));
62 
63  // C u s t o m i z e m a n a g e r
64  // ---------------------------------
65 
66  // Add module that randomizes the summed value of nsig+nbkg
67  // sampling from a uniform distribution between 0 and 1000
68  //
69  // In general one can randomize a single parameter, or a
70  // sum of N parameters, using either a uniform or a Gaussian
71  // distribution. Multiple randomization can be executed
72  // by a single randomizer module
73 
74  RooRandomizeParamMCSModule randModule;
75  randModule.sampleSumUniform(RooArgSet(nsig, nbkg), 50, 500);
76  mcs->addModule(randModule);
77 
78  // Add profile likelihood calculation of significance. Redo each
79  // fit while keeping parameter nsig fixed to zero. For each toy,
80  // the difference in -log(L) of both fits is stored, as well
81  // a simple significance interpretation of the delta(-logL)
82  // using Dnll = 0.5 sigma^2
83 
84  RooDLLSignificanceMCSModule sigModule(nsig, 0);
85  mcs->addModule(sigModule);
86 
87  // R u n m a n a g e r , m a k e p l o t s
88  // ---------------------------------------------
89 
90  // Run 1000 experiments. This configuration will generate a fair number
91  // of (harmless) MINUIT warnings due to the instability of the Chebychev polynomial fit
92  // at low statistics.
93  mcs->generateAndFit(500);
94 
95  // Make some plots
96  TH1 *dll_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,dll_nullhypo_nsig", -40, -40);
97  TH1 *z_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,significance_nullhypo_nsig", -40, -40);
98  TH1 *errnsig_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,nsigerr", -40, -40);
99  TH1 *errnsig_vs_nsig = mcs->fitParDataSet().createHistogram("nsig,nsigerr", -40, -40);
100 
101  // Draw plots on canvas
102  TCanvas *c = new TCanvas("rf803_mcstudy_addons2", "rf802_mcstudy_addons2", 800, 800);
103  c->Divide(2, 2);
104  c->cd(1);
105  gPad->SetLeftMargin(0.15);
106  dll_vs_ngen->GetYaxis()->SetTitleOffset(1.6);
107  dll_vs_ngen->Draw("box");
108  c->cd(2);
109  gPad->SetLeftMargin(0.15);
110  z_vs_ngen->GetYaxis()->SetTitleOffset(1.6);
111  z_vs_ngen->Draw("box");
112  c->cd(3);
113  gPad->SetLeftMargin(0.15);
114  errnsig_vs_ngen->GetYaxis()->SetTitleOffset(1.6);
115  errnsig_vs_ngen->Draw("box");
116  c->cd(4);
117  gPad->SetLeftMargin(0.15);
118  errnsig_vs_nsig->GetYaxis()->SetTitleOffset(1.6);
119  errnsig_vs_nsig->Draw("box");
120 
121  // Make RooMCStudy object available on command line after
122  // macro finishes
123  gDirectory->Add(mcs);
124 }