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/// 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///
10/// \date July 2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "RooChebychev.h"
17#include "RooAddPdf.h"
18#include "RooMCStudy.h"
21#include "RooPlot.h"
22#include "TCanvas.h"
23#include "TAxis.h"
24#include "TH1.h"
25#include "TDirectory.h"
26
27using namespace RooFit;
28
30{
31 // C r e a t e m o d e l
32 // -----------------------
33
34 // Simulation of signal and background of top quark decaying into
35 // 3 jets with background
36
37 // Observable
38 RooRealVar mjjj("mjjj", "m(3jet) (GeV)", 100, 85., 350.);
39
40 // Signal component (Gaussian)
41 RooRealVar mtop("mtop", "m(top)", 162);
42 RooRealVar wtop("wtop", "m(top) resolution", 15.2);
43 RooGaussian sig("sig", "top signal", mjjj, mtop, wtop);
44
45 // Background component (Chebychev)
46 RooRealVar c0("c0", "Chebychev coefficient 0", -0.846, -1., 1.);
47 RooRealVar c1("c1", "Chebychev coefficient 1", 0.112, -1., 1.);
48 RooRealVar c2("c2", "Chebychev coefficient 2", 0.076, -1., 1.);
49 RooChebychev bkg("bkg", "combinatorial background", mjjj, RooArgList(c0, c1, c2));
50
51 // Composite model
52 RooRealVar nsig("nsig", "number of signal events", 53, 0, 1e3);
53 RooRealVar nbkg("nbkg", "number of background events", 103, 0, 5e3);
54 RooAddPdf model("model", "model", RooArgList(sig, bkg), RooArgList(nsig, nbkg));
55
56 // C r e a t e m a n a g e r
57 // ---------------------------
58
59 // Configure manager to perform binned extended likelihood fits (Binned(),Extended()) on data generated
60 // with a Poisson fluctuation on Nobs (Extended())
61 RooMCStudy *mcs = new RooMCStudy(model, mjjj, Binned(), Silence(), Extended(true),
63
64 // C u s t o m i z e m a n a g e r
65 // ---------------------------------
66
67 // Add module that randomizes the summed value of nsig+nbkg
68 // sampling from a uniform distribution between 0 and 1000
69 //
70 // In general one can randomize a single parameter, or a
71 // sum of N parameters, using either a uniform or a Gaussian
72 // distribution. Multiple randomization can be executed
73 // by a single randomizer module
74
76 randModule.sampleSumUniform(RooArgSet(nsig, nbkg), 50, 500);
77 mcs->addModule(randModule);
78
79 // Add profile likelihood calculation of significance. Redo each
80 // fit while keeping parameter nsig fixed to zero. For each toy,
81 // the difference in -log(L) of both fits is stored, as well
82 // a simple significance interpretation of the delta(-logL)
83 // using Dnll = 0.5 sigma^2
84
85 RooDLLSignificanceMCSModule sigModule(nsig, 0);
86 mcs->addModule(sigModule);
87
88 // R u n m a n a g e r , m a k e p l o t s
89 // ---------------------------------------------
90
91 // Run 1000 experiments. This configuration will generate a fair number
92 // of (harmless) MINUIT warnings due to the instability of the Chebychev polynomial fit
93 // at low statistics.
94 mcs->generateAndFit(500);
95
96 // Make some plots
97 TH1 *dll_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,dll_nullhypo_nsig", AutoBinning(40), AutoBinning(40));
98 TH1 *z_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,significance_nullhypo_nsig", AutoBinning(40), AutoBinning(40));
99 TH1 *errnsig_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,nsigerr", AutoBinning(40), AutoBinning(40));
100 TH1 *errnsig_vs_nsig = mcs->fitParDataSet().createHistogram("nsig,nsigerr", AutoBinning(40), AutoBinning(40));
101
102 // Draw plots on canvas
103 TCanvas *c = new TCanvas("rf803_mcstudy_addons2", "rf802_mcstudy_addons2", 800, 800);
104 c->Divide(2, 2);
105 c->cd(1);
106 gPad->SetLeftMargin(0.15);
107 dll_vs_ngen->GetYaxis()->SetTitleOffset(1.6);
108 dll_vs_ngen->Draw("box");
109 c->cd(2);
110 gPad->SetLeftMargin(0.15);
111 z_vs_ngen->GetYaxis()->SetTitleOffset(1.6);
112 z_vs_ngen->Draw("box");
113 c->cd(3);
114 gPad->SetLeftMargin(0.15);
115 errnsig_vs_ngen->GetYaxis()->SetTitleOffset(1.6);
116 errnsig_vs_ngen->Draw("box");
117 c->cd(4);
118 gPad->SetLeftMargin(0.15);
119 errnsig_vs_nsig->GetYaxis()->SetTitleOffset(1.6);
120 errnsig_vs_nsig->Draw("box");
121
122 // Make RooMCStudy object available on command line after
123 // macro finishes
124 gDirectory->Add(mcs);
125}
#define c(i)
Definition: RSha256.hxx:101
#define gDirectory
Definition: TDirectory.h:348
#define gPad
Definition: TVirtualPad.h:288
TH1 * createHistogram(const char *name, const RooAbsRealLValue &xvar, 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
Calls createHistogram(const char *name, const RooAbsRealLValue& xvar, const RooLinkedList& argList) c...
Definition: RooAbsData.cxx:685
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:34
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:56
Chebychev polynomial p.d.f.
Definition: RooChebychev.h:25
RooDLLSignificanceMCSModule is an add-on modules to RooMCStudy that calculates the significance of a ...
Plain Gaussian p.d.f.
Definition: RooGaussian.h:24
RooMCStudy is a helper class to facilitate Monte Carlo studies such as 'goodness-of-fit' studies,...
Definition: RooMCStudy.h:32
const RooDataSet & fitParDataSet()
Return a RooDataSet containing the post-fit parameters of each toy cycle.
Definition: RooMCStudy.cxx:805
bool generateAndFit(Int_t nSamples, Int_t nEvtPerSample=0, bool keepGenData=false, const char *asciiFilePat=nullptr)
Generate and fit 'nSamples' samples of 'nEvtPerSample' events.
Definition: RooMCStudy.cxx:514
void addModule(RooAbsMCStudyModule &module)
Insert given RooMCStudy add-on module to the processing chain of this MCStudy object.
Definition: RooMCStudy.cxx:306
RooRandomizeParamMCSModule is an add-on modules to RooMCStudy that allows you to randomize input gene...
void sampleSumUniform(const RooArgSet &paramSet, double lo, double hi)
Request uniform smearing of sum of parameters in paramSet uniform smearing in range [lo,...
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:301
The Canvas class.
Definition: TCanvas.h:23
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
TAxis * GetYaxis()
Definition: TH1.h:323
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition: TH1.cxx:3060
RooCmdArg FitOptions(const RooCmdArg &arg1, 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())
RooCmdArg AutoBinning(Int_t nbins=100, double marginFactor=0.1)
RooCmdArg Silence(bool flag=true)
RooCmdArg Binned(bool flag=true)
RooCmdArg PrintEvalErrors(Int_t numErrors)
RooCmdArg Extended(bool flag=true)
return c1
Definition: legend1.C:41
return c2
Definition: legend2.C:14
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: Common.h:18