ROOT
Version v6.32
master
v6.34
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
▼
ROOT
ROOT Reference Documentation
Tutorials
►
Functional Parts
►
Namespaces
►
All Classes
▼
Files
▼
File List
►
bindings
►
core
►
documentation
►
geom
►
graf2d
►
graf3d
►
gui
►
hist
►
html
►
io
►
main
►
math
►
montecarlo
►
net
►
proof
►
roofit
►
sql
►
tmva
►
tree
▼
tutorials
►
cocoa
►
cont
►
dataframe
►
eve
►
eve7
►
fft
►
fit
►
fitsio
►
foam
►
geom
►
gl
►
graphics
►
graphs
►
gui
►
hist
►
histfactory
►
html
►
http
►
image
►
io
►
legacy
►
math
►
matrix
►
mc
►
multicore
►
net
►
physics
►
proof
►
pyroot
►
pythia
►
quadp
►
r
►
rcanvas
▼
roofit
rf101_basics.C
rf101_basics.py
rf102_dataimport.C
rf102_dataimport.py
rf103_interprfuncs.C
rf103_interprfuncs.py
rf104_classfactory.C
rf104_classfactory.py
rf105_funcbinding.C
rf105_funcbinding.py
rf106_plotdecoration.C
rf106_plotdecoration.py
rf107_plotstyles.C
rf107_plotstyles.py
rf108_plotbinning.C
rf108_plotbinning.py
rf109_chi2residpull.C
rf109_chi2residpull.py
rf110_normintegration.C
rf110_normintegration.py
rf111_derivatives.C
rf111_derivatives.py
rf201_composite.C
rf201_composite.py
rf202_extendedmlfit.C
rf202_extendedmlfit.py
rf203_ranges.C
rf203_ranges.py
rf204a_extendedLikelihood.C
rf204a_extendedLikelihood.py
rf204b_extendedLikelihood_rangedFit.C
rf204b_extendedLikelihood_rangedFit.py
rf205_compplot.C
rf205_compplot.py
rf206_treevistools.C
rf206_treevistools.py
rf207_comptools.C
rf207_comptools.py
rf208_convolution.C
rf208_convolution.py
rf209_anaconv.C
rf209_anaconv.py
rf210_angularconv.C
rf210_angularconv.py
rf211_paramconv.C
rf211_paramconv.py
rf212_plottingInRanges_blinding.C
rf212_plottingInRanges_blinding.py
rf301_composition.C
rf301_composition.py
rf302_utilfuncs.C
rf302_utilfuncs.py
rf303_conditional.C
rf303_conditional.py
rf304_uncorrprod.C
rf304_uncorrprod.py
rf305_condcorrprod.C
rf305_condcorrprod.py
rf306_condpereventerrors.C
rf306_condpereventerrors.py
rf307_fullpereventerrors.C
rf307_fullpereventerrors.py
rf308_normintegration2d.C
rf308_normintegration2d.py
rf309_ndimplot.C
rf309_ndimplot.py
rf310_sliceplot.C
rf310_sliceplot.py
rf311_rangeplot.C
rf311_rangeplot.py
rf312_multirangefit.C
rf312_multirangefit.py
rf313_paramranges.C
rf313_paramranges.py
rf314_paramfitrange.C
rf314_paramfitrange.py
rf315_projectpdf.C
rf315_projectpdf.py
rf316_llratioplot.C
rf316_llratioplot.py
rf401_importttreethx.C
rf401_importttreethx.py
rf402_datahandling.C
rf402_datahandling.py
rf403_weightedevts.C
rf403_weightedevts.py
rf404_categories.C
rf404_categories.py
rf405_realtocatfuncs.C
rf405_realtocatfuncs.py
rf406_cattocatfuncs.C
rf406_cattocatfuncs.py
rf407_latextables.C
rf407_latextables.py
rf408_RDataFrameToRooFit.C
rf408_RDataFrameToRooFit.py
rf409_NumPyPandasToRooFit.py
rf501_simultaneouspdf.C
rf501_simultaneouspdf.py
rf502_wspacewrite.C
rf502_wspacewrite.py
rf503_wspaceread.C
rf503_wspaceread.py
rf504_simwstool.C
rf504_simwstool.py
rf505_asciicfg.C
rf505_asciicfg.py
rf506_msgservice.C
rf506_msgservice.py
rf508_listsetmanip.C
rf508_listsetmanip.py
rf509_wsinteractive.C
rf509_wsinteractive.py
rf510_wsnamedsets.C
rf510_wsnamedsets.py
rf511_wsfactory_basic.C
rf511_wsfactory_basic.py
rf512_wsfactory_oper.C
rf512_wsfactory_oper.py
rf513_wsfactory_tools.C
rf513_wsfactory_tools.py
rf514_RooCustomizer.C
rf514_RooCustomizer.py
rf515_hfJSON.py
rf601_intminuit.C
rf601_intminuit.py
rf602_chi2fit.C
rf602_chi2fit.py
rf603_multicpu.C
rf603_multicpu.py
rf604_constraints.C
rf604_constraints.py
rf605_profilell.C
rf605_profilell.py
rf606_nllerrorhandling.C
rf606_nllerrorhandling.py
rf607_fitresult.C
rf607_fitresult.py
rf608_fitresultaspdf.C
rf608_fitresultaspdf.py
rf609_xychi2fit.C
rf609_xychi2fit.py
rf610_visualerror.C
rf610_visualerror.py
rf611_weightedfits.C
rf612_recoverFromInvalidParameters.C
rf612_recoverFromInvalidParameters.py
rf613_global_observables.C
rf613_global_observables.py
rf614_binned_fit_problems.C
rf614_binned_fit_problems.py
rf701_efficiencyfit.C
rf701_efficiencyfit.py
rf702_efficiencyfit_2D.C
rf702_efficiencyfit_2D.py
rf703_effpdfprod.C
rf703_effpdfprod.py
rf704_amplitudefit.C
rf704_amplitudefit.py
rf705_linearmorph.C
rf705_linearmorph.py
rf706_histpdf.C
rf706_histpdf.py
rf707_kernelestimation.C
rf707_kernelestimation.py
rf708_bphysics.C
rf708_bphysics.py
rf709_BarlowBeeston.C
rf709_BarlowBeeston.py
rf710_roopoly.C
rf710_roopoly.py
rf711_lagrangianmorph.C
rf711_lagrangianmorph.py
rf712_lagrangianmorphfit.C
rf712_lagrangianmorphfit.py
rf801_mcstudy.C
rf801_mcstudy.py
rf802_mcstudy_addons.C
rf802_mcstudy_addons.py
rf803_mcstudy_addons2.C
rf803_mcstudy_addons2.py
rf804_mcstudy_constr.C
rf804_mcstudy_constr.py
rf901_numintconfig.C
rf901_numintconfig.py
rf902_numgenconfig.C
rf902_numgenconfig.py
rf903_numintcache.C
rf903_numintcache.py
►
roostats
►
spectrum
►
splot
►
sql
►
tmva
►
tree
►
unfold
►
unuran
►
v7
►
vecops
►
webgui
►
xml
.rootlogon.py
demos.C
demoshelp.C
hsimple.C
rootlogoff.C
rootlogon.C
►
v6-32-00-patches
►
File Members
Release Notes
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
rf802_mcstudy_addons.py
Go to the documentation of this file.
1
## \ingroup tutorial_roofit
2
## \notebook
3
##
4
## 'VALIDATION AND MC STUDIES' RooFit tutorial macro #802
5
##
6
## RooMCStudy: using separate fit and generator models, the chi^2 calculator model
7
##
8
## \macro_image
9
## \macro_code
10
## \macro_output
11
##
12
## \date February 2018
13
## \author Clemens Lange
14
15
16
import
ROOT
17
18
19
# Create model
20
# -----------------------
21
22
# Observables, parameters
23
x =
ROOT.RooRealVar
(
"x"
,
"x"
, -10, 10)
24
x.setBins
(10)
25
mean =
ROOT.RooRealVar
(
"mean"
,
"mean of gaussian"
, 0, -2.0, 1.8)
26
sigma =
ROOT.RooRealVar
(
"sigma"
,
"width of gaussian"
, 5, 1, 10)
27
28
# Create Gaussian pdf
29
gauss =
ROOT.RooGaussian
(
"gauss"
,
"gaussian PDF"
, x, mean, sigma)
30
31
# Create manager with chi^2 add-on module
32
# ----------------------------------------------------------------------------
33
34
# Create study manager for binned likelihood fits of a Gaussian pdf in 10
35
# bins
36
mcs =
ROOT.RooMCStudy
(gauss, {x}, Silence=
True
, Binned=
True
)
37
38
# Add chi^2 calculator module to mcs
39
chi2mod =
ROOT.RooChi2MCSModule
()
40
mcs.addModule
(chi2mod)
41
42
# Generate 1000 samples of 1000 events
43
mcs.generateAndFit
(2000, 1000)
44
45
# Number of bins for chi2 plots
46
nBins = 100
47
48
# Fill histograms with distributions chi2 and prob(chi2,ndf) that
49
# are calculated by ROOT.RooChiMCSModule
50
hist_chi2 =
mcs.fitParDataSet
().createHistogram(
"chi2"
, AutoBinning=nBins)
51
hist_prob =
mcs.fitParDataSet
().createHistogram(
"prob"
, AutoBinning=nBins)
52
53
# Create manager with separate fit model
54
# ----------------------------------------------------------------------------
55
56
# Create alternate pdf with shifted mean
57
mean2 =
ROOT.RooRealVar
(
"mean2"
,
"mean of gaussian 2"
, 2.0)
58
gauss2 =
ROOT.RooGaussian
(
"gauss2"
,
"gaussian PDF2"
, x, mean2, sigma)
59
60
# Create study manager with separate generation and fit model. ROOT.This configuration
61
# is set up to generate bad fits as the fit and generator model have different means
62
# and the mean parameter is not floating in the fit
63
mcs2 =
ROOT.RooMCStudy
(gauss2, {x}, FitModel=gauss, Silence=
True
, Binned=
True
)
64
65
# Add chi^2 calculator module to mcs
66
chi2mod2 =
ROOT.RooChi2MCSModule
()
67
mcs2.addModule
(chi2mod2)
68
69
# Generate 1000 samples of 1000 events
70
mcs2.generateAndFit
(2000, 1000)
71
72
# Request a the pull plot of mean. The pulls will be one-sided because
73
# `mean` is limited to 1.8.
74
# Note that RooFit will have trouble to compute the pulls because the parameters
75
# are called `mean` in the fit, but `mean2` in the generator model. It is not obvious
76
# that these are related. RooFit will nevertheless compute pulls, but complain that
77
# this is risky.
78
pullMeanFrame =
mcs2.plotPull
(mean)
79
80
# Fill histograms with distributions chi2 and prob(chi2,ndf) that
81
# are calculated by ROOT.RooChiMCSModule
82
hist2_chi2 =
mcs2.fitParDataSet
().createHistogram(
"chi2"
, AutoBinning=nBins)
83
hist2_prob =
mcs2.fitParDataSet
().createHistogram(
"prob"
, AutoBinning=nBins)
84
hist2_chi2.SetLineColor
(
ROOT.kRed
)
85
hist2_prob.SetLineColor
(
ROOT.kRed
)
86
87
c =
ROOT.TCanvas
(
"rf802_mcstudy_addons"
,
"rf802_mcstudy_addons"
, 800, 400)
88
c.Divide
(3)
89
c.cd
(1)
90
ROOT.gPad.SetLeftMargin
(0.15)
91
hist_chi2.GetYaxis
().SetTitleOffset(1.4)
92
hist_chi2.Draw
()
93
hist2_chi2.Draw
(
"esame"
)
94
c.cd
(2)
95
ROOT.gPad.SetLeftMargin
(0.15)
96
hist_prob.GetYaxis
().SetTitleOffset(1.4)
97
hist_prob.Draw
()
98
hist2_prob.Draw
(
"esame"
)
99
c.cd
(3)
100
pullMeanFrame.Draw
()
101
102
c.SaveAs
(
"rf802_mcstudy_addons.png"
)
103
104
# Make RooMCStudy object available on command line after
105
# macro finishes
106
ROOT.gDirectory.Add
(mcs)
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
tutorials
roofit
rf802_mcstudy_addons.py
ROOT v6-32 - Reference Guide Generated on Wed Apr 2 2025 08:24:49 (GVA Time) using Doxygen 1.10.0