Logo ROOT   6.16/01
Reference Guide
rf802_mcstudy_addons.C File Reference

Detailed Description

View in nbviewer Open in SWAN 'VALIDATION AND MC STUDIES' RooFit tutorial macro #802

RooMCStudy: using separate fit and generator models, using the chi^2 calculator model

␛[1mRooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby␛[0m
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1980
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1960
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1940
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1920
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1900
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1880
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1860
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1840
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1820
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1800
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1780
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1760
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1740
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1720
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1700
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1680
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1660
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1640
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1620
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1600
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1580
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1560
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1540
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1520
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1500
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1480
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1460
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1440
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1420
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1400
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1380
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1360
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1340
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1320
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1300
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1280
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1260
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1240
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1220
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1200
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1180
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1160
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1140
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1120
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1100
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1080
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1060
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1040
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1020
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1000
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 980
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 960
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 940
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 920
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 900
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 880
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 860
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 840
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 820
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 800
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 780
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 760
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 740
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 720
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 700
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 680
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 660
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 640
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 620
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 600
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 580
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 560
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 540
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 520
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 500
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 480
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 460
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 440
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 420
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 400
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 380
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 360
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 340
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 320
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 300
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 280
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 260
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 240
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 220
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 200
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 180
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 160
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 140
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 120
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 100
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 80
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 60
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 40
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 20
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 0
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1980
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1960
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1940
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1920
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1900
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1880
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1860
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1840
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1820
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1800
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1780
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1760
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1740
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1720
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1700
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1680
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1660
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1640
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1620
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1600
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1580
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1560
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1540
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1520
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1500
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1480
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1460
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1440
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1420
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1400
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1380
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1360
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1340
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1320
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1300
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1280
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1260
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1240
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1220
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1200
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1180
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1160
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1140
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1120
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1100
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1080
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1060
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1040
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1020
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 1000
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 980
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 960
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 940
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 920
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 900
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 880
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 860
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 840
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 820
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 800
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 780
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 760
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 740
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 720
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 700
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 680
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 660
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 640
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 620
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 600
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 580
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 560
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 540
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 520
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 500
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 480
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 460
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 440
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 420
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 400
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 380
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 360
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 340
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 320
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 300
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 280
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 260
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 240
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 220
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 200
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 180
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 160
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 140
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 120
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 100
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 80
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 60
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 40
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 20
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 0
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooChebychev.h"
#include "RooAddPdf.h"
#include "RooMCStudy.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
#include "TDirectory.h"
using namespace RooFit ;
void rf802_mcstudy_addons()
{
// C r e a t e m o d e l
// -----------------------
// Observables, parameters
RooRealVar x("x","x",-10,10) ;
x.setBins(10) ;
RooRealVar mean("mean","mean of gaussian",0) ;
RooRealVar sigma("sigma","width of gaussian",5,1,10) ;
// Create Gaussian pdf
RooGaussian gauss("gauss","gaussian PDF",x,mean,sigma) ;
// C r e a t e m a n a g e r w i t h c h i ^ 2 a d d - o n m o d u l e
// ----------------------------------------------------------------------------
// Create study manager for binned likelihood fits of a Gaussian pdf in 10 bins
// Add chi^2 calculator module to mcs
RooChi2MCSModule chi2mod ;
mcs->addModule(chi2mod) ;
// Generate 1000 samples of 1000 events
mcs->generateAndFit(2000,1000) ;
// Fill histograms with distributions chi2 and prob(chi2,ndf) that
// are calculated by RooChiMCSModule
TH1* hist_chi2 = mcs->fitParDataSet().createHistogram("chi2") ;
TH1* hist_prob = mcs->fitParDataSet().createHistogram("prob") ;
// C r e a t e m a n a g e r w i t h s e p a r a t e f i t m o d e l
// ----------------------------------------------------------------------------
// Create alternate pdf with shifted mean
RooRealVar mean2("mean2","mean of gaussian 2",0.5) ;
RooGaussian gauss2("gauss2","gaussian PDF2",x,mean2,sigma) ;
// Create study manager with separate generation and fit model. This configuration
// is set up to generate bad fits as the fit and generator model have different means
// and the mean parameter is not floating in the fit
RooMCStudy* mcs2 = new RooMCStudy(gauss2,x,FitModel(gauss),Silence(),Binned()) ;
// Add chi^2 calculator module to mcs
RooChi2MCSModule chi2mod2 ;
mcs2->addModule(chi2mod2) ;
// Generate 1000 samples of 1000 events
mcs2->generateAndFit(2000,1000) ;
// Fill histograms with distributions chi2 and prob(chi2,ndf) that
// are calculated by RooChiMCSModule
TH1* hist2_chi2 = mcs2->fitParDataSet().createHistogram("chi2") ;
TH1* hist2_prob = mcs2->fitParDataSet().createHistogram("prob") ;
hist2_chi2->SetLineColor(kRed) ;
hist2_prob->SetLineColor(kRed) ;
TCanvas* c = new TCanvas("rf802_mcstudy_addons","rf802_mcstudy_addons",800,400) ;
c->Divide(2) ;
c->cd(1) ; gPad->SetLeftMargin(0.15) ; hist_chi2->GetYaxis()->SetTitleOffset(1.4) ; hist_chi2->Draw() ; hist2_chi2->Draw("esame") ;
c->cd(2) ; gPad->SetLeftMargin(0.15) ; hist_prob->GetYaxis()->SetTitleOffset(1.4) ; hist_prob->Draw() ; hist2_prob->Draw("esame") ;
// Make RooMCStudy object available on command line after
// macro finishes
gDirectory->Add(mcs) ;
}
#define c(i)
Definition: RSha256.hxx:101
@ kRed
Definition: Rtypes.h:63
#define gDirectory
Definition: TDirectory.h:213
#define gPad
Definition: TVirtualPad.h:286
RooChi2MCSModule is an add-on modules to RooMCStudy that calculates the chi-squared of fitted p....
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.
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
RooMCStudy is a help class to facilitate Monte Carlo studies such as 'goodness-of-fit' studies,...
Definition: RooMCStudy.h:32
const RooDataSet & fitParDataSet()
Return a RooDataSet the resulting fit parameters of each toy cycle.
Definition: RooMCStudy.cxx:949
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:646
void addModule(RooAbsMCStudyModule &module)
Insert given RooMCStudy add-on module to the processing chain of this MCStudy object.
Definition: RooMCStudy.cxx:431
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:294
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
The Canvas class.
Definition: TCanvas.h:31
The TH1 histogram class.
Definition: TH1.h:56
TAxis * GetYaxis()
Definition: TH1.h:317
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2974
const Double_t sigma
Double_t x[n]
Definition: legend1.C:17
RooCmdArg Binned(Bool_t flag=kTRUE)
RooCmdArg Silence(Bool_t flag=kTRUE)
void FitModel(RooWorkspace *, std::string data_name="obsData")
static constexpr double gauss
Author
07/2008 - Wouter Verkerke

Definition in file rf802_mcstudy_addons.C.