# Rf 8 0 1_Mcstudy¶

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

Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, January 19, 2022 at 10:37 AM.

In [1]:
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooChebychev.h"
#include "RooMCStudy.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH2.h"
#include "RooFitResult.h"
#include "TStyle.h"
#include "TDirectory.h"

In [2]:
%%cpp -d
// This is a workaround to make sure the namespace is used inside functions
using namespace RooFit;


## Create model¶

Declare observable x

In [3]:
RooRealVar x("x", "x", 0, 10);
x.setBins(40);

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University



Create two gaussian pdfs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters

In [4]:
RooRealVar mean("mean", "mean of gaussians", 5, 0, 10);
RooRealVar sigma1("sigma1", "width of gaussians", 0.5);
RooRealVar sigma2("sigma2", "width of gaussians", 1);

RooGaussian sig1("sig1", "Signal component 1", x, mean, sigma1);
RooGaussian sig2("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 [5]:
RooRealVar a0("a0", "a0", 0.5, 0., 1.);
RooRealVar a1("a1", "a1", -0.2, -1, 1.);
RooChebychev bkg("bkg", "Background", x, RooArgSet(a0, a1));


Sum the signal components into a composite signal pdf

In [6]:
RooRealVar sig1frac("sig1frac", "fraction of component 1 in signal", 0.8, 0., 1.);
RooAddPdf sig("sig", "Signal", RooArgList(sig1, sig2), sig1frac);


Sum the composite signal and background

In [7]:
RooRealVar nbkg("nbkg", "number of background events,", 150, 0, 1000);
RooRealVar nsig("nsig", "number of signal events", 150, 0, 1000);
RooAddPdf model("model", "g1+g2+a", RooArgList(bkg, sig), RooArgList(nbkg, nsig));


## Create manager¶

Instantiate roomcstudy manager on model with x as observable and given choice of fit options

The Silence() option kills all messages below the PROGRESS level, leaving only a single message per sample executed, and 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, the fit result of each experiment is saved by the manager

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

In [8]:
RooMCStudy *mcstudy =
new RooMCStudy(model, x, Binned(kTRUE), Silence(), Extended(), FitOptions(Save(kTRUE), PrintEvalErrors(0)));


## Generate and fit events¶

Generate and fit 1000 samples of poisson(nexpected) events

In [9]:
mcstudy->generateAndFit(1000);

[#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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] 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
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 errors
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] 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
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 errors
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] 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
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 errors
RooNLLVar::nll_model_genData[ paramSet=(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 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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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
RooNLLVar::nll_model_genData[ paramSet=(a0,a1,mean,nbkg,nsig,sig1frac,sigma1,sigma2) ] has 1 errors
RooChebychev::bkg[ x=x coefList=(a0,a1) ] has 1 errors
RooAddPdf::model[ nbkg * bkg + nsig * sig ] has 2 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, the error on mean and the pull of mean

In [10]:
RooPlot *frame1 = mcstudy->plotParam(mean, Bins(40));
RooPlot *frame2 = mcstudy->plotError(mean, Bins(40));
RooPlot *frame3 = mcstudy->plotPull(mean, Bins(40), FitGauss(kTRUE));

[#0] WARNING:Plotting -- Cannot apply a bin width correction and use Poisson errors. Not correcting for bin width.
[#0] WARNING:Plotting -- Cannot apply a bin width correction and use Poisson errors. Not correcting for bin width.
[#0] WARNING:Plotting -- Cannot apply a bin width correction and use Poisson errors. Not correcting for bin width.

[#1] INFO:NumericIntegration -- RooRealIntegral::init(pullGauss_Int[meanpull]) using numeric integrator RooIntegrator1D to calculate Int(meanpull)
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#1] INFO:NumericIntegration -- RooRealIntegral::init(pullGauss_Int[meanpull]) using numeric integrator RooIntegrator1D to calculate Int(meanpull)


Plot distribution of minimized likelihood

In [11]:
RooPlot *frame4 = mcstudy->plotNLL(Bins(40));

[#0] WARNING:Plotting -- Cannot apply a bin width correction and use Poisson errors. Not correcting for bin width.


Make some histograms from the parameter dataset

In [12]:
TH1 *hh_cor_a0_s1f = mcstudy->fitParDataSet().createHistogram("hh", a1, YVar(sig1frac));
TH1 *hh_cor_a0_a1 = mcstudy->fitParDataSet().createHistogram("hh", a0, YVar(a1));


Access some of the saved fit results from individual toys

In [13]:
TH2 *corrHist000 = mcstudy->fitResult(0)->correlationHist("c000");
TH2 *corrHist127 = mcstudy->fitResult(127)->correlationHist("c127");
TH2 *corrHist953 = mcstudy->fitResult(953)->correlationHist("c953");


Draw all plots on a canvas

In [14]:
gStyle->SetOptStat(0);
TCanvas *c = new 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");


Make roomcstudy object available on command line after macro finishes

In [15]:
gDirectory->Add(mcstudy);


Draw all canvases

In [16]:
%jsroot on
gROOT->GetListOfCanvases()->Draw()