{ "cells": [ { "cell_type": "markdown", "id": "b43d72c1", "metadata": {}, "source": [ "# rf801_mcstudy\n", "Validation and MC studies: toy Monte Carlo study that perform cycles of event generation and fitting\n", "\n", "\n", "\n", "\n", "**Author:** Wouter Verkerke \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, March 19, 2024 at 07:17 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "e4119879", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:17:56.514012Z", "iopub.status.busy": "2024-03-19T19:17:56.513622Z", "iopub.status.idle": "2024-03-19T19:17:56.549560Z", "shell.execute_reply": "2024-03-19T19:17:56.548642Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"RooRealVar.h\"\n", "#include \"RooDataSet.h\"\n", "#include \"RooGaussian.h\"\n", "#include \"RooChebychev.h\"\n", "#include \"RooAddPdf.h\"\n", "#include \"RooMCStudy.h\"\n", "#include \"RooPlot.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TAxis.h\"\n", "#include \"TH2.h\"\n", "#include \"RooFitResult.h\"\n", "#include \"TStyle.h\"\n", "#include \"TDirectory.h\"\n", "\n", "using namespace RooFit;" ] }, { "cell_type": "markdown", "id": "c24c9130", "metadata": {}, "source": [ "Create model\n", "-----------------------" ] }, { "cell_type": "markdown", "id": "8e6f1565", "metadata": {}, "source": [ "Declare observable x" ] }, { "cell_type": "code", "execution_count": 2, "id": "d0cf82fd", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:17:56.556549Z", "iopub.status.busy": "2024-03-19T19:17:56.556045Z", "iopub.status.idle": "2024-03-19T19:17:57.487091Z", "shell.execute_reply": "2024-03-19T19:17:57.474492Z" } }, "outputs": [], "source": [ "RooRealVar x(\"x\", \"x\", 0, 10);\n", "x.setBins(40);" ] }, { "cell_type": "markdown", "id": "806b525b", "metadata": {}, "source": [ "Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters" ] }, { "cell_type": "code", "execution_count": 3, "id": "16f53d5e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:17:57.534039Z", "iopub.status.busy": "2024-03-19T19:17:57.522377Z", "iopub.status.idle": "2024-03-19T19:17:57.922205Z", "shell.execute_reply": "2024-03-19T19:17:57.921359Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#0] WARNING:InputArguments -- The parameter 'sigma1' with range [-inf, inf] of the RooGaussian 'sig1' exceeds the safe range of (0, inf). Advise to limit its range.\n", "[#0] WARNING:InputArguments -- The parameter 'sigma2' with range [-inf, inf] of the RooGaussian 'sig2' exceeds the safe range of (0, inf). Advise to limit its range.\n" ] } ], "source": [ "RooRealVar mean(\"mean\", \"mean of gaussians\", 5, 0, 10);\n", "RooRealVar sigma1(\"sigma1\", \"width of gaussians\", 0.5);\n", "RooRealVar sigma2(\"sigma2\", \"width of gaussians\", 1);\n", "\n", "RooGaussian sig1(\"sig1\", \"Signal component 1\", x, mean, sigma1);\n", "RooGaussian sig2(\"sig2\", \"Signal component 2\", x, mean, sigma2);" ] }, { "cell_type": "markdown", "id": "f8f78634", "metadata": {}, "source": [ "Build Chebychev polynomial pdf" ] }, { "cell_type": "code", "execution_count": 4, "id": "afb32fba", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:17:57.940295Z", "iopub.status.busy": "2024-03-19T19:17:57.939879Z", "iopub.status.idle": "2024-03-19T19:17:58.348821Z", "shell.execute_reply": "2024-03-19T19:17:58.347587Z" } }, "outputs": [], "source": [ "RooRealVar a0(\"a0\", \"a0\", 0.5, 0., 1.);\n", "RooRealVar a1(\"a1\", \"a1\", -0.2, -1, 1.);\n", "RooChebychev bkg(\"bkg\", \"Background\", x, RooArgSet(a0, a1));" ] }, { "cell_type": "markdown", "id": "1c98dca1", "metadata": {}, "source": [ "Sum the signal components into a composite signal pdf" ] }, { "cell_type": "code", "execution_count": 5, "id": "5a0d321b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:17:58.375474Z", "iopub.status.busy": "2024-03-19T19:17:58.375059Z", "iopub.status.idle": "2024-03-19T19:17:58.748857Z", "shell.execute_reply": "2024-03-19T19:17:58.747723Z" } }, "outputs": [], "source": [ "RooRealVar sig1frac(\"sig1frac\", \"fraction of component 1 in signal\", 0.8, 0., 1.);\n", "RooAddPdf sig(\"sig\", \"Signal\", RooArgList(sig1, sig2), sig1frac);" ] }, { "cell_type": "markdown", "id": "07877224", "metadata": {}, "source": [ "Sum the composite signal and background" ] }, { "cell_type": "code", "execution_count": 6, "id": "0d525950", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:17:58.779877Z", "iopub.status.busy": "2024-03-19T19:17:58.779481Z", "iopub.status.idle": "2024-03-19T19:17:59.066500Z", "shell.execute_reply": "2024-03-19T19:17:59.039418Z" } }, "outputs": [], "source": [ "RooRealVar nbkg(\"nbkg\", \"number of background events,\", 150, 0, 1000);\n", "RooRealVar nsig(\"nsig\", \"number of signal events\", 150, 0, 1000);\n", "RooAddPdf model(\"model\", \"g1+g2+a\", RooArgList(bkg, sig), RooArgList(nbkg, nsig));" ] }, { "cell_type": "markdown", "id": "b7546118", "metadata": {}, "source": [ "Create manager\n", "---------------------------" ] }, { "cell_type": "markdown", "id": "f617bd55", "metadata": {}, "source": [ "Instantiate RooMCStudy manager on model with x as observable and given choice of fit options\n", "\n", "The Silence() option kills all messages below the PROGRESS level, leaving only a single message\n", "per sample executed, and any error message that occur during fitting\n", "\n", "The Extended() option has two effects:\n", "1) The extended ML term is included in the likelihood and\n", "2) A poisson fluctuation is introduced on the number of generated events\n", "\n", "The FitOptions() given here are passed to the fitting stage of each toy experiment.\n", "If Save() is specified, the fit result of each experiment is saved by the manager\n", "\n", "A Binned() option is added in this example to bin the data between generation and fitting\n", "to speed up the study at the expense of some precision" ] }, { "cell_type": "code", "execution_count": 7, "id": "af5967ab", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:17:59.080837Z", "iopub.status.busy": "2024-03-19T19:17:59.080441Z", "iopub.status.idle": "2024-03-19T19:17:59.349559Z", "shell.execute_reply": "2024-03-19T19:17:59.348522Z" } }, "outputs": [], "source": [ "RooMCStudy *mcstudy =\n", " new RooMCStudy(model, x, Binned(true), Silence(), Extended(), FitOptions(Save(true), PrintEvalErrors(0)));" ] }, { "cell_type": "markdown", "id": "26ef5017", "metadata": {}, "source": [ "Generate and fit events\n", "---------------------------------------------" ] }, { "cell_type": "markdown", "id": "64153353", "metadata": {}, "source": [ "Generate and fit 1000 samples of Poisson(nExpected) events" ] }, { "cell_type": "code", "execution_count": 8, "id": "fafd7c5b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:17:59.360928Z", "iopub.status.busy": "2024-03-19T19:17:59.360558Z", "iopub.status.idle": "2024-03-19T19:18:01.976404Z", "shell.execute_reply": "2024-03-19T19:18:01.975326Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 990\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 980\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 970\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 960\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 950\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-797.721) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.716236\ta1=-0.675686\tmean=5.04367\tnbkg=115.661\tnsig=155.327\tsig1frac=0.880121\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 940\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 930\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-867.289) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.907715\ta1=-0.26012\tmean=4.95881\tnbkg=147.451\tnsig=156.366\tsig1frac=0.890535\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 920\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 910\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 900\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-871.381) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.716361\ta1=-0.355239\tmean=5.05578\tnbkg=159.647\tnsig=151.993\tsig1frac=0.742914\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 890\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 880\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 870\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-903.916) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.877959\ta1=-0.428367\tmean=4.99746\tnbkg=167.444\tnsig=157.288\tsig1frac=0.424997\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 860\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 850\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 840\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 830\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-970.563) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.867793\ta1=-0.296045\tmean=5.10353\tnbkg=164.822\tnsig=173.566\tsig1frac=0.899431\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 820\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 810\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 800\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 790\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 780\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 770\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 760\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-915.472) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.807508\ta1=-0.34963\tmean=5.09438\tnbkg=142.436\tnsig=172.312\tsig1frac=0.886183\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 750\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-885.867) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.7962\ta1=-0.414289\tmean=5.07605\tnbkg=135.514\tnsig=167.164\tsig1frac=0.927781\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-848.597) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.577138\ta1=-0.518554\tmean=5.09299\tnbkg=144.203\tnsig=156.938\tsig1frac=0.54541\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 740\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 730\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 720\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 710\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 700\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-814.549) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.848973\ta1=-0.489149\tmean=5.08811\tnbkg=132.911\tnsig=150.647\tsig1frac=0.826731\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 690\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 680\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 670\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-809.662) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.713661\ta1=-0.606754\tmean=5.02862\tnbkg=142.583\tnsig=145.399\tsig1frac=0.623944\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-861.002) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.744046\ta1=-0.311529\tmean=5.09799\tnbkg=161.409\tnsig=148.884\tsig1frac=0.512806\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 660\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 650\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 640\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 630\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 620\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 610\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-809.027) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.719517\ta1=-0.347533\tmean=5.00927\tnbkg=127.977\tnsig=152.559\tsig1frac=0.917291\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 600\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 590\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 580\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-869.586) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.621299\ta1=-0.442393\tmean=5.13262\tnbkg=131.7\tnsig=167.982\tsig1frac=0.776177\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 570\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 560\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 550\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 540\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 530\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-820.086) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.699182\ta1=-0.532303\tmean=4.90748\tnbkg=130.722\tnsig=155.109\tsig1frac=0.843514\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 520\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 510\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-814.421) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.729962\ta1=-0.49802\tmean=4.92039\tnbkg=146.276\tnsig=144.44\tsig1frac=0.620699\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 500\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 490\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 480\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 470\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 460\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 450\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 440\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 430\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-926.481) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.653979\ta1=-0.469539\tmean=5.00078\tnbkg=160.963\tnsig=166.526\tsig1frac=0.628924\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 420\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-768.847) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.749295\ta1=-0.303934\tmean=4.98272\tnbkg=121.461\tnsig=145.338\tsig1frac=0.822833\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-798.509) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.791035\ta1=-0.287544\tmean=4.98693\tnbkg=127.577\tnsig=149.203\tsig1frac=0.914567\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 410\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 400\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 390\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-977.775) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.565967\ta1=-0.529635\tmean=5.0065\tnbkg=153.38\tnsig=185.083\tsig1frac=0.751239\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 380\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 370\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-945.036) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.824344\ta1=-0.338546\tmean=5.06339\tnbkg=161.705\tnsig=169.087\tsig1frac=0.910016\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 360\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 350\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 340\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 330\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 320\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 310\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-831.776) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.823781\ta1=-0.287947\tmean=4.96347\tnbkg=133.185\tnsig=155.535\tsig1frac=0.887106\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 300\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 290\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 280\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-867.974) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.806741\ta1=-0.376486\tmean=4.95962\tnbkg=143.191\tnsig=160.421\tsig1frac=0.787531\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 270\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-810.184) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.701119\ta1=-0.376392\tmean=4.96099\tnbkg=126.85\tnsig=153.527\tsig1frac=0.880449\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-845.198) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.74363\ta1=-0.435344\tmean=5.01952\tnbkg=162.467\tnsig=143.571\tsig1frac=0.630815\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 260\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 250\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-1003.82) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.674666\ta1=-0.383697\tmean=5.00365\tnbkg=169.829\tnsig=179.534\tsig1frac=0.921743\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-712.949) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.711808\ta1=-0.34088\tmean=4.99573\tnbkg=115.49\tnsig=133.015\tsig1frac=0.908627\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 240\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 230\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 220\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 210\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 200\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 190\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 180\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 170\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 160\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 150\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-750.903) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.726225\ta1=-0.429497\tmean=5.03871\tnbkg=129.53\tnsig=136.644\tsig1frac=0.687558\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 140\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-740.756) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.899536\ta1=-0.345881\tmean=5.03897\tnbkg=135.176\tnsig=129.13\tsig1frac=0.899393\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-677.604) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.766597\ta1=-0.547838\tmean=5.03836\tnbkg=119.039\tnsig=121.817\tsig1frac=0.213703\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 130\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-777.498) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.527582\ta1=-0.893856\tmean=5.24753\tnbkg=162.951\tnsig=65.9357\tsig1frac=0.970262\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-777.498) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.516095\ta1=-0.955515\tmean=5.14443\tnbkg=157.502\tnsig=97.2821\tsig1frac=0.174928\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-777.498) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.510348\ta1=-0.776595\tmean=5.09286\tnbkg=154.805\tnsig=114.979\tsig1frac=0.0496841\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 120\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 110\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-796.54) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.702991\ta1=-0.414346\tmean=5.11911\tnbkg=145.466\tnsig=141.134\tsig1frac=0.532895\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 100\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-920.777) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.726241\ta1=-0.424659\tmean=5.05565\tnbkg=151.228\tnsig=170.816\tsig1frac=0.771802\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-743.339) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.942558\ta1=-0.775768\tmean=4.99866\tnbkg=187.872\tnsig=63.0852\tsig1frac=0.868175\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-743.339) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.984478\ta1=-0.59938\tmean=4.99914\tnbkg=173.959\tnsig=90.3182\tsig1frac=0.461117\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 90\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 80\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 70\n", "RooAbsMinimizerFcn: Minimized function has error status.\n", "Returning maximum FCN so far (-775.389) to force MIGRAD to back out of this region. Error log follows.\n", "Parameter values: \ta0=0.72761\ta1=-0.375581\tmean=5.04879\tnbkg=141.143\tnsig=137.402\tsig1frac=0.495257\n", "RooAddPdf::model[ nbkg * bkg_over_bkg_Int[x] + nsig * sig ] has 1 errors\n", "\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 60\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 50\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 40\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 30\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 20\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 10\n", "[#0] PROGRESS:Generation -- RooMCStudy::run: sample 0\n", "[#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.\n", "[#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.\n" ] } ], "source": [ "mcstudy->generateAndFit(1000);" ] }, { "cell_type": "markdown", "id": "6dfa03e9", "metadata": {}, "source": [ "Explore results of study\n", "------------------------------------------------" ] }, { "cell_type": "markdown", "id": "cc1eb6a3", "metadata": {}, "source": [ "Make plots of the distributions of mean, the error on mean and the pull of mean" ] }, { "cell_type": "code", "execution_count": 9, "id": "13f9ffa3", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:18:01.985717Z", "iopub.status.busy": "2024-03-19T19:18:01.985335Z", "iopub.status.idle": "2024-03-19T19:18:02.203061Z", "shell.execute_reply": "2024-03-19T19:18:02.201908Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[#1] INFO:ObjectHandling -- RooWorkspace::import() importing RooRealVar::meanpull\n", "\n", "[#1] INFO:Fitting -- RooAbsPdf::fitTo(pullGauss_over_pullGauss_Int[meanpull]) fixing normalization set for coefficient determination to observables in data\n", "[#1] INFO:Fitting -- using CPU computation library compiled with -mavx2\n", "[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_pullGauss_over_pullGauss_Int[meanpull]_fitParData_model) Summation contains a RooNLLVar, using its error level\n", "[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization\n", "[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization\n" ] } ], "source": [ "RooPlot *frame1 = mcstudy->plotParam(mean, Bins(40));\n", "RooPlot *frame2 = mcstudy->plotError(mean, Bins(40));\n", "RooPlot *frame3 = mcstudy->plotPull(mean, Bins(40), FitGauss(true));" ] }, { "cell_type": "markdown", "id": "13363317", "metadata": {}, "source": [ "Plot distribution of minimized likelihood" ] }, { "cell_type": "code", "execution_count": 10, "id": "cd2861d3", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:18:02.209756Z", "iopub.status.busy": "2024-03-19T19:18:02.209383Z", "iopub.status.idle": "2024-03-19T19:18:02.462400Z", "shell.execute_reply": "2024-03-19T19:18:02.455549Z" } }, "outputs": [], "source": [ "RooPlot *frame4 = mcstudy->plotNLL(Bins(40));" ] }, { "cell_type": "markdown", "id": "b1fcc2ef", "metadata": {}, "source": [ "Make some histograms from the parameter dataset" ] }, { "cell_type": "code", "execution_count": 11, "id": "e97a9b1b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:18:02.474362Z", "iopub.status.busy": "2024-03-19T19:18:02.473967Z", "iopub.status.idle": "2024-03-19T19:18:02.692437Z", "shell.execute_reply": "2024-03-19T19:18:02.691234Z" } }, "outputs": [], "source": [ "TH1 *hh_cor_a0_s1f = mcstudy->fitParDataSet().createHistogram(\"hh\", a1, YVar(sig1frac));\n", "TH1 *hh_cor_a0_a1 = mcstudy->fitParDataSet().createHistogram(\"hh\", a0, YVar(a1));" ] }, { "cell_type": "markdown", "id": "4b0cfc29", "metadata": {}, "source": [ "Access some of the saved fit results from individual toys" ] }, { "cell_type": "code", "execution_count": 12, "id": "fa1fa415", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:18:02.698705Z", "iopub.status.busy": "2024-03-19T19:18:02.698363Z", "iopub.status.idle": "2024-03-19T19:18:02.939487Z", "shell.execute_reply": "2024-03-19T19:18:02.920826Z" } }, "outputs": [], "source": [ "TH2 *corrHist000 = mcstudy->fitResult(0)->correlationHist(\"c000\");\n", "TH2 *corrHist127 = mcstudy->fitResult(127)->correlationHist(\"c127\");\n", "TH2 *corrHist953 = mcstudy->fitResult(953)->correlationHist(\"c953\");" ] }, { "cell_type": "markdown", "id": "f32dbb21", "metadata": {}, "source": [ "Draw all plots on a canvas" ] }, { "cell_type": "code", "execution_count": 13, "id": "40bb2321", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:18:02.976474Z", "iopub.status.busy": "2024-03-19T19:18:02.975820Z", "iopub.status.idle": "2024-03-19T19:18:03.333756Z", "shell.execute_reply": "2024-03-19T19:18:03.332730Z" } }, "outputs": [], "source": [ "gStyle->SetOptStat(0);\n", "TCanvas *c = new TCanvas(\"rf801_mcstudy\", \"rf801_mcstudy\", 900, 900);\n", "c->Divide(3, 3);\n", "c->cd(1);\n", "gPad->SetLeftMargin(0.15);\n", "frame1->GetYaxis()->SetTitleOffset(1.4);\n", "frame1->Draw();\n", "c->cd(2);\n", "gPad->SetLeftMargin(0.15);\n", "frame2->GetYaxis()->SetTitleOffset(1.4);\n", "frame2->Draw();\n", "c->cd(3);\n", "gPad->SetLeftMargin(0.15);\n", "frame3->GetYaxis()->SetTitleOffset(1.4);\n", "frame3->Draw();\n", "c->cd(4);\n", "gPad->SetLeftMargin(0.15);\n", "frame4->GetYaxis()->SetTitleOffset(1.4);\n", "frame4->Draw();\n", "c->cd(5);\n", "gPad->SetLeftMargin(0.15);\n", "hh_cor_a0_s1f->GetYaxis()->SetTitleOffset(1.4);\n", "hh_cor_a0_s1f->Draw(\"box\");\n", "c->cd(6);\n", "gPad->SetLeftMargin(0.15);\n", "hh_cor_a0_a1->GetYaxis()->SetTitleOffset(1.4);\n", "hh_cor_a0_a1->Draw(\"box\");\n", "c->cd(7);\n", "gPad->SetLeftMargin(0.15);\n", "corrHist000->GetYaxis()->SetTitleOffset(1.4);\n", "corrHist000->Draw(\"colz\");\n", "c->cd(8);\n", "gPad->SetLeftMargin(0.15);\n", "corrHist127->GetYaxis()->SetTitleOffset(1.4);\n", "corrHist127->Draw(\"colz\");\n", "c->cd(9);\n", "gPad->SetLeftMargin(0.15);\n", "corrHist953->GetYaxis()->SetTitleOffset(1.4);\n", "corrHist953->Draw(\"colz\");" ] }, { "cell_type": "markdown", "id": "b648273b", "metadata": {}, "source": [ "Make RooMCStudy object available on command line after\n", "macro finishes" ] }, { "cell_type": "code", "execution_count": 14, "id": "4dde3321", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:18:03.343829Z", "iopub.status.busy": "2024-03-19T19:18:03.343322Z", "iopub.status.idle": "2024-03-19T19:18:03.560788Z", "shell.execute_reply": "2024-03-19T19:18:03.559693Z" } }, "outputs": [], "source": [ "gDirectory->Add(mcstudy);" ] }, { "cell_type": "markdown", "id": "dcdfdde2", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 15, "id": "8babb3a9", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2024-03-19T19:18:03.566996Z", "iopub.status.busy": "2024-03-19T19:18:03.566600Z", "iopub.status.idle": "2024-03-19T19:18:04.251088Z", "shell.execute_reply": "2024-03-19T19:18:04.234998Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "