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