# rf801_mcstudy¶

Validation and MC studies: toy Monte Carlo study that perform cycles of event generation and fitting

Author: Clemens Lange, Wouter Verkerke (C++ version)
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Sunday, November 27, 2022 at 11:08 AM.

In [1]:
import ROOT

Welcome to JupyROOT 6.27/01


## Create model¶

Declare observable x

In [2]:
x = ROOT.RooRealVar("x", "x", 0, 10)
x.setBins(40)


Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters

In [3]:
mean = ROOT.RooRealVar("mean", "mean of gaussians", 5, 0, 10)
sigma1 = ROOT.RooRealVar("sigma1", "width of gaussians", 0.5)
sigma2 = ROOT.RooRealVar("sigma2", "width of gaussians", 1)

sig1 = ROOT.RooGaussian("sig1", "Signal component 1", x, mean, sigma1)
sig2 = ROOT.RooGaussian("sig2", "Signal component 2", x, mean, sigma2)

[#0] WARNING:InputArguments -- The parameter 'sigma1' with range [-1e+30, 1e+30] of the RooGaussian 'sig1' exceeds the safe range of (0, inf). Advise to limit its range.
[#0] WARNING:InputArguments -- The parameter 'sigma2' with range [-1e+30, 1e+30] of the RooGaussian 'sig2' exceeds the safe range of (0, inf). Advise to limit its range.


Build Chebychev polynomial pdf

In [4]:
a0 = ROOT.RooRealVar("a0", "a0", 0.5, 0.0, 1.0)
a1 = ROOT.RooRealVar("a1", "a1", -0.2, -1, 1.0)
bkg = ROOT.RooChebychev("bkg", "Background", x, [a0, a1])


Sum the signal components into a composite signal pdf

In [5]:
sig1frac = ROOT.RooRealVar("sig1frac", "fraction of component 1 in signal", 0.8, 0.0, 1.0)
sig = ROOT.RooAddPdf("sig", "Signal", [sig1, sig2], [sig1frac])


Sum the composite signal and background

In [6]:
nbkg = ROOT.RooRealVar("nbkg", "number of background events, ", 150, 0, 1000)
nsig = ROOT.RooRealVar("nsig", "number of signal events", 150, 0, 1000)
model = ROOT.RooAddPdf("model", "g1+g2+a", [bkg, sig], [nbkg, nsig])


## Create manager¶

Instantiate ROOT.RooMCStudy manager on model with x as observable and given choice of fit options

The Silence() option kills all messages below the PROGRESS level, only a single message per sample executed, any error message that occur during fitting

The Extended() option has two effects: 1) The extended ML term is included in the likelihood and 2) A poisson fluctuation is introduced on the number of generated events

The FitOptions() given here are passed to the fitting stage of each toy experiment. If Save() is specified, fit result of each experiment is saved by the manager

A Binned() option is added in self example to bin the data between generation and fitting to speed up the study at the expemse of some precision

In [7]:
mcstudy = ROOT.RooMCStudy(
model,
{x},
Binned=True,
Silence=True,
Extended=True,
FitOptions=dict(Save=True, PrintEvalErrors=0),
)


## Generate and fit events¶

Generate and fit 1000 samples of Poisson(nExpected) events

In [8]:
mcstudy.generateAndFit(1000)

Out[8]:
False
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 990
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 980
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 970
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 960
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 950
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-797.721) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.716236	a1=-0.675686	mean=5.04367	nbkg=115.661	nsig=155.327	sig1frac=0.880121
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 940
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 930
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-867.289) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.907715	a1=-0.26012	mean=4.95881	nbkg=147.451	nsig=156.366	sig1frac=0.890535
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 920
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 910
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 900
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-871.381) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.716361	a1=-0.355239	mean=5.05578	nbkg=159.647	nsig=151.993	sig1frac=0.742914
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 890
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 880
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 870
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-903.916) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.877959	a1=-0.428367	mean=4.99746	nbkg=167.444	nsig=157.288	sig1frac=0.424997
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 860
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 850
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 840
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 830
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-970.563) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.867793	a1=-0.296045	mean=5.10353	nbkg=164.822	nsig=173.566	sig1frac=0.899431
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 820
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 810
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 800
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 790
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 780
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 770
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 760
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-915.472) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.807508	a1=-0.34963	mean=5.09438	nbkg=142.436	nsig=172.312	sig1frac=0.886183
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 750
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-885.867) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.7962	a1=-0.414289	mean=5.07605	nbkg=135.514	nsig=167.164	sig1frac=0.927781
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-848.597) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.577138	a1=-0.518554	mean=5.09299	nbkg=144.203	nsig=156.938	sig1frac=0.54541
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 740
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 730
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 720
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 710
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 700
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-814.549) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.848973	a1=-0.489149	mean=5.08811	nbkg=132.911	nsig=150.647	sig1frac=0.826731
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 690
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 680
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 670
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-809.662) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.713661	a1=-0.606754	mean=5.02862	nbkg=142.583	nsig=145.399	sig1frac=0.623944
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-861.002) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.744046	a1=-0.311529	mean=5.09799	nbkg=161.409	nsig=148.884	sig1frac=0.512806
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 660
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 650
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 640
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 630
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 620
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 610
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-809.027) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.719517	a1=-0.347533	mean=5.00927	nbkg=127.977	nsig=152.559	sig1frac=0.917291
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 600
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 590
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 580
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-869.586) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.621299	a1=-0.442393	mean=5.13262	nbkg=131.7	nsig=167.982	sig1frac=0.776177
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 570
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 560
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 550
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 540
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 530
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-820.086) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.699182	a1=-0.532303	mean=4.90748	nbkg=130.722	nsig=155.109	sig1frac=0.843514
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 520
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 510
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-814.421) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.729962	a1=-0.49802	mean=4.92039	nbkg=146.276	nsig=144.44	sig1frac=0.620699
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 500
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 490
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 480
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 470
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 460
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 450
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 440
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 430
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-926.481) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.653979	a1=-0.469539	mean=5.00078	nbkg=160.963	nsig=166.526	sig1frac=0.628924
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 420
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-768.847) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.749295	a1=-0.303934	mean=4.98272	nbkg=121.461	nsig=145.338	sig1frac=0.822833
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-798.509) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.791035	a1=-0.287544	mean=4.98693	nbkg=127.577	nsig=149.203	sig1frac=0.914567
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 410
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 400
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 390
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-977.775) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.565967	a1=-0.529635	mean=5.0065	nbkg=153.38	nsig=185.083	sig1frac=0.751239
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 380
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 370
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-945.036) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.824344	a1=-0.338546	mean=5.06339	nbkg=161.705	nsig=169.087	sig1frac=0.910016
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 360
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 350
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 340
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 330
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 320
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 310
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-831.776) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.823781	a1=-0.287947	mean=4.96347	nbkg=133.185	nsig=155.535	sig1frac=0.887106
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 300
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 290
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 280
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-867.974) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.806741	a1=-0.376486	mean=4.95962	nbkg=143.191	nsig=160.421	sig1frac=0.787531
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 270
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-810.184) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.701119	a1=-0.376392	mean=4.96099	nbkg=126.85	nsig=153.527	sig1frac=0.880449
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-845.198) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.74363	a1=-0.435344	mean=5.01952	nbkg=162.467	nsig=143.571	sig1frac=0.630815
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 260
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 250
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-1003.82) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.674666	a1=-0.383697	mean=5.00365	nbkg=169.829	nsig=179.534	sig1frac=0.921743
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-712.949) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.711808	a1=-0.34088	mean=4.99573	nbkg=115.49	nsig=133.015	sig1frac=0.908627
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 240
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 230
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 220
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 210
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 200
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 190
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 180
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 170
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 160
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 150
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-750.903) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.726225	a1=-0.429497	mean=5.03871	nbkg=129.53	nsig=136.644	sig1frac=0.687558
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 140
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-740.756) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.899536	a1=-0.345881	mean=5.03897	nbkg=135.176	nsig=129.13	sig1frac=0.899393
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-677.604) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.766597	a1=-0.547838	mean=5.03836	nbkg=119.039	nsig=121.817	sig1frac=0.213703
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 130
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-777.498) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.527582	a1=-0.893856	mean=5.24753	nbkg=162.951	nsig=65.9357	sig1frac=0.970262
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-777.498) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.516095	a1=-0.955515	mean=5.14443	nbkg=157.502	nsig=97.2821	sig1frac=0.174928
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-777.498) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.510348	a1=-0.776595	mean=5.09286	nbkg=154.805	nsig=114.979	sig1frac=0.0496841
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 120
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 110
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-796.54) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.702991	a1=-0.414346	mean=5.11911	nbkg=145.466	nsig=141.134	sig1frac=0.532895
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 100
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-920.777) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.726241	a1=-0.424659	mean=5.05565	nbkg=151.228	nsig=170.816	sig1frac=0.771802
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors

RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-743.339) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.942558	a1=-0.775768	mean=4.99866	nbkg=187.872	nsig=63.0852	sig1frac=0.868175
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-743.339) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.984478	a1=-0.59938	mean=4.99914	nbkg=173.959	nsig=90.3182	sig1frac=0.461117
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 90
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 80
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 70
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-775.389) to force MIGRAD to back out of this region. Error log follows.
Parameter values: 	a0=0.72761	a1=-0.375581	mean=5.04879	nbkg=141.143	nsig=137.402	sig1frac=0.495257
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 1 errors
RooNLLVar::nll_model_genData[ parameters=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors

[#0] PROGRESS:Generation -- RooMCStudy::run: sample 60
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 50
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 40
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 30
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 20
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 10
[#0] PROGRESS:Generation -- RooMCStudy::run: sample 0
[#0] WARNING:Generation -- Fit parameter 'sigma1' does not have an error. A pull distribution cannot be generated. This might be caused by the parameter being constant or because the fits were not run.
[#0] WARNING:Generation -- Fit parameter 'sigma2' does not have an error. A pull distribution cannot be generated. This might be caused by the parameter being constant or because the fits were not run.


## Explore results of study¶

Make plots of the distributions of mean, error on mean and the pull of mean

In [9]:
frame1 = mcstudy.plotParam(mean, Bins=40)
frame2 = mcstudy.plotError(mean, Bins=40)
frame3 = mcstudy.plotPull(mean, Bins=40, FitGauss=True)

[#1] INFO:ObjectHandling -- RooWorkspace::import() importing RooRealVar::meanpull
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization


Plot distribution of minimized likelihood

In [10]:
frame4 = mcstudy.plotNLL(Bins=40)


Make some histograms from the parameter dataset

In [11]:
hh_cor_a0_s1f = mcstudy.fitParDataSet().createHistogram("hh", a1, YVar=sig1frac)
hh_cor_a0_a1 = mcstudy.fitParDataSet().createHistogram("hh", a0, YVar=a1)


Access some of the saved fit results from individual toys

In [12]:
corrHist000 = mcstudy.fitResult(0).correlationHist("c000")
corrHist127 = mcstudy.fitResult(127).correlationHist("c127")
corrHist953 = mcstudy.fitResult(953).correlationHist("c953")


Draw all plots on a canvas

In [13]:
ROOT.gStyle.SetPalette(1)
ROOT.gStyle.SetOptStat(0)
c = ROOT.TCanvas("rf801_mcstudy", "rf801_mcstudy", 900, 900)
c.Divide(3, 3)
c.cd(1)
frame1.GetYaxis().SetTitleOffset(1.4)
frame1.Draw()
c.cd(2)
frame2.GetYaxis().SetTitleOffset(1.4)
frame2.Draw()
c.cd(3)
frame3.GetYaxis().SetTitleOffset(1.4)
frame3.Draw()
c.cd(4)
frame4.GetYaxis().SetTitleOffset(1.4)
frame4.Draw()
c.cd(5)
hh_cor_a0_s1f.GetYaxis().SetTitleOffset(1.4)
hh_cor_a0_s1f.Draw("box")
c.cd(6)
hh_cor_a0_a1.GetYaxis().SetTitleOffset(1.4)
hh_cor_a0_a1.Draw("box")
c.cd(7)
corrHist000.GetYaxis().SetTitleOffset(1.4)
corrHist000.Draw("colz")
c.cd(8)
corrHist127.GetYaxis().SetTitleOffset(1.4)
corrHist127.Draw("colz")
c.cd(9)
corrHist953.GetYaxis().SetTitleOffset(1.4)
corrHist953.Draw("colz")

c.SaveAs("rf801_mcstudy.png")

Info in <TCanvas::Print>: png file rf801_mcstudy.png has been created


Make ROOT.RooMCStudy object available on command line after macro finishes

In [14]:
ROOT.gDirectory.Add(mcstudy)


Draw all canvases

In [15]:
from ROOT import gROOT
gROOT.GetListOfCanvases().Draw()