{
"cells": [
{
"cell_type": "markdown",
"id": "826247bb",
"metadata": {},
"source": [
"# testUnfold2\n",
" Test program as an example for a user specific regularisation scheme.\n",
"\n",
" 1. Generate Monte Carlo and Data events\n",
" The events consist of:\n",
" - signal\n",
" - background\n",
"\n",
" The signal is a resonance. It is generated with a Breit-Wigner,\n",
" smeared by a Gaussian\n",
"\n",
" 2. Unfold the data. The result is:\n",
" - The background level\n",
" - The shape of the resonance, corrected for detector effects\n",
"\n",
" The regularisation is done on the curvature, excluding the bins\n",
" near the peak.\n",
"\n",
" 3. produce some plots\n",
"\n",
"\n",
" **Version 17.6, in parallel to changes in TUnfold**\n",
"\n",
"#### History:\n",
" - Version 17.5, in parallel to changes in TUnfold\n",
" - Version 17.4, in parallel to changes in TUnfold\n",
" - Version 17.3, in parallel to changes in TUnfold\n",
" - Version 17.2, in parallel to changes in TUnfold\n",
" - Version 17.1, in parallel to changes in TUnfold\n",
" - Version 17.0, updated for changed methods in TUnfold\n",
" - Version 16.1, parallel to changes in TUnfold\n",
" - Version 16.0, parallel to changes in TUnfold\n",
" - Version 15, with automatic L-curve scan, simplified example\n",
" - Version 14, with changes in TUnfoldSys.cxx\n",
" - Version 13, with changes to TUnfold.C\n",
" - Version 12, with improvements to TUnfold.cxx\n",
" - Version 11, print chi**2 and number of degrees of freedom\n",
" - Version 10, with bug-fix in TUnfold.cxx\n",
" - Version 9, with bug-fix in TUnfold.cxx, TUnfold.h\n",
" - Version 8, with bug-fix in TUnfold.cxx, TUnfold.h\n",
" - Version 7, with bug-fix in TUnfold.cxx, TUnfold.h\n",
" - Version 6a, fix problem with dynamic array allocation under windows\n",
" - Version 6, re-include class MyUnfold in the example\n",
" - Version 5, move class MyUnfold to separate files\n",
" - Version 4, with bug-fix in TUnfold.C\n",
" - Version 3, with bug-fix in TUnfold.C\n",
" - Version 2, with changed ScanLcurve() arguments\n",
" - Version 1, remove L curve analysis, use ScanLcurve() method instead\n",
" - Version 0, L curve analysis included here\n",
"\n",
" This file is part of TUnfold.\n",
"\n",
" TUnfold is free software: you can redistribute it and/or modify\n",
" it under the terms of the GNU General Public License as published by\n",
" the Free Software Foundation, either version 3 of the License, or\n",
" (at your option) any later version.\n",
"\n",
" TUnfold is distributed in the hope that it will be useful,\n",
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
" GNU General Public License for more details.\n",
"\n",
" You should have received a copy of the GNU General Public License\n",
" along with TUnfold. If not, see .\n",
"\n",
"\n",
"\n",
"**Author:** Stefan Schmitt DESY, 14.10.2008 \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:11 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "09cfedeb",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:20.759442Z",
"iopub.status.busy": "2026-05-19T20:11:20.759279Z",
"iopub.status.idle": "2026-05-19T20:11:20.766580Z",
"shell.execute_reply": "2026-05-19T20:11:20.766094Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"#include \n",
"#include \n",
"#include \n",
"#include \n",
"#include \n",
"#include \n",
"#include \n",
"#include \"TUnfold.h\"\n",
"\n",
"\n",
"TRandom *rnd=nullptr;"
]
},
{
"cell_type": "markdown",
"id": "d737a008",
"metadata": {},
"source": [
" generate an event\n",
"output:\n",
"negative mass: background event\n",
"positive mass: signal event\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "1dfd84dc",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:20.767857Z",
"iopub.status.busy": "2026-05-19T20:11:20.767741Z",
"iopub.status.idle": "2026-05-19T20:11:20.772105Z",
"shell.execute_reply": "2026-05-19T20:11:20.771629Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"Double_t GenerateEvent(Double_t bgr, // relative fraction of background\n",
" Double_t mass, // peak position\n",
" Double_t gamma) // peak width\n",
"{\n",
" Double_t t;\n",
" if(rnd->Rndm()>bgr) {\n",
" // generate signal event\n",
" // with positive mass\n",
" do {\n",
" do {\n",
" t=rnd->Rndm();\n",
" } while(t>=1.0);\n",
" t=TMath::Tan((t-0.5)*TMath::Pi())*gamma+mass;\n",
" } while(t<=0.0);\n",
" return t;\n",
" } else {\n",
" // generate background event\n",
" // generate events following a power-law distribution\n",
" // f(E) = K * TMath::power((E0+E),N0)\n",
" static Double_t const E0=2.4;\n",
" static Double_t const N0=2.9;\n",
" do {\n",
" do {\n",
" t=rnd->Rndm();\n",
" } while(t>=1.0);\n",
" // the mass is returned negative\n",
" // In our example a convenient way to indicate it is a background event.\n",
" t= -(TMath::Power(1.-t,1./(1.-N0))-1.0)*E0;\n",
" } while(t>=0.0);\n",
" return t;\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "492c40d7",
"metadata": {},
"source": [
" smear the event to detector level\n",
"input:\n",
"mass on generator level (mTrue>0 !)\n",
"output:\n",
"mass on detector level\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d4524113",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:20.773261Z",
"iopub.status.busy": "2026-05-19T20:11:20.773151Z",
"iopub.status.idle": "2026-05-19T20:11:20.775996Z",
"shell.execute_reply": "2026-05-19T20:11:20.775403Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"Double_t DetectorEvent(Double_t mTrue) {\n",
" // smear by double-gaussian\n",
" static Double_t frac=0.1;\n",
" static Double_t wideBias=0.03;\n",
" static Double_t wideSigma=0.5;\n",
" static Double_t smallBias=0.0;\n",
" static Double_t smallSigma=0.1;\n",
" if(rnd->Rndm()>frac) {\n",
" return rnd->Gaus(mTrue+smallBias,smallSigma);\n",
" } else {\n",
" return rnd->Gaus(mTrue+wideBias,wideSigma);\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "05630c38",
"metadata": {},
"source": [
"switch on histogram errors"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ff45e760",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:20.777180Z",
"iopub.status.busy": "2026-05-19T20:11:20.777072Z",
"iopub.status.idle": "2026-05-19T20:11:21.087235Z",
"shell.execute_reply": "2026-05-19T20:11:21.086572Z"
}
},
"outputs": [],
"source": [
"TH1::SetDefaultSumw2();"
]
},
{
"cell_type": "markdown",
"id": "782d087d",
"metadata": {},
"source": [
"random generator"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e35cb24b",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:21.088877Z",
"iopub.status.busy": "2026-05-19T20:11:21.088755Z",
"iopub.status.idle": "2026-05-19T20:11:21.292946Z",
"shell.execute_reply": "2026-05-19T20:11:21.291989Z"
}
},
"outputs": [],
"source": [
"rnd=new TRandom3();"
]
},
{
"cell_type": "markdown",
"id": "00b841fd",
"metadata": {},
"source": [
"data and MC luminosity, cross-section"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "cfa0fae6",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:21.294517Z",
"iopub.status.busy": "2026-05-19T20:11:21.294399Z",
"iopub.status.idle": "2026-05-19T20:11:21.498403Z",
"shell.execute_reply": "2026-05-19T20:11:21.497703Z"
}
},
"outputs": [],
"source": [
"Double_t const luminosityData=100000;\n",
"Double_t const luminosityMC=1000000;\n",
"Double_t const crossSection=1.0;\n",
"\n",
"Int_t const nDet=250;\n",
"Int_t const nGen=100;\n",
"Double_t const xminDet=0.0;\n",
"Double_t const xmaxDet=10.0;\n",
"Double_t const xminGen=0.0;\n",
"Double_t const xmaxGen=10.0;"
]
},
{
"cell_type": "markdown",
"id": "3e386324",
"metadata": {},
"source": [
"============================================\n",
"generate MC distribution"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "35cf4a3e",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:21.500367Z",
"iopub.status.busy": "2026-05-19T20:11:21.500252Z",
"iopub.status.idle": "2026-05-19T20:11:21.830006Z",
"shell.execute_reply": "2026-05-19T20:11:21.829525Z"
}
},
"outputs": [],
"source": [
"TH1D *histMgenMC=new TH1D(\"MgenMC\",\";mass(gen)\",nGen,xminGen,xmaxGen);\n",
"TH1D *histMdetMC=new TH1D(\"MdetMC\",\";mass(det)\",nDet,xminDet,xmaxDet);\n",
"TH2D *histMdetGenMC=new TH2D(\"MdetgenMC\",\";mass(det);mass(gen)\",nDet,xminDet,xmaxDet,\n",
" nGen,xminGen,xmaxGen);\n",
"Int_t neventMC=rnd->Poisson(luminosityMC*crossSection);\n",
"for(Int_t i=0;iFill(mGen,luminosityData/luminosityMC);\n",
" // reconstructed MC distribution (for comparison only)\n",
" histMdetMC->Fill(mDet,luminosityData/luminosityMC);\n",
"\n",
" // matrix describing how the generator input migrates to the\n",
" // reconstructed level. Unfolding input.\n",
" // NOTE on underflow/overflow bins:\n",
" // (1) the detector level under/overflow bins are used for\n",
" // normalisation (\"efficiency\" correction)\n",
" // in our toy example, these bins are populated from tails\n",
" // of the initial MC distribution.\n",
" // (2) the generator level underflow/overflow bins are\n",
" // unfolded. In this example:\n",
" // underflow bin: background events reconstructed in the detector\n",
" // overflow bin: signal events generated at masses > xmaxDet\n",
" // for the unfolded result these bins will be filled\n",
" // -> the background normalisation will be contained in the underflow bin\n",
" histMdetGenMC->Fill(mDet,mGen,luminosityData/luminosityMC);\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "191081ce",
"metadata": {},
"source": [
"============================================\n",
"generate data distribution"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "a1aaa9e6",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:21.835395Z",
"iopub.status.busy": "2026-05-19T20:11:21.835253Z",
"iopub.status.idle": "2026-05-19T20:11:22.037970Z",
"shell.execute_reply": "2026-05-19T20:11:22.036857Z"
}
},
"outputs": [],
"source": [
"TH1D *histMgenData=new TH1D(\"MgenData\",\";mass(gen)\",nGen,xminGen,xmaxGen);\n",
"TH1D *histMdetData=new TH1D(\"MdetData\",\";mass(det)\",nDet,xminDet,xmaxDet);\n",
"Int_t neventData=rnd->Poisson(luminosityData*crossSection);\n",
"for(Int_t i=0;iFill(mGen);\n",
"\n",
" // reconstructed mass, unfolding input\n",
" histMdetData->Fill(mDet);\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "64db51aa",
"metadata": {},
"source": [
"=========================================================================\n",
"set up the unfolding"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "3ebd08b3",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:22.039679Z",
"iopub.status.busy": "2026-05-19T20:11:22.039538Z",
"iopub.status.idle": "2026-05-19T20:11:22.245422Z",
"shell.execute_reply": "2026-05-19T20:11:22.244335Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Info in : fConstraint=1\n",
"Info in : 250 input bins and 102 output bins (includes 2 underflow/overflow bins)\n"
]
}
],
"source": [
"TUnfold unfold(histMdetGenMC,TUnfold::kHistMapOutputVert,\n",
" TUnfold::kRegModeNone);"
]
},
{
"cell_type": "markdown",
"id": "959bc5b4",
"metadata": {},
"source": [
"regularisation\n",
"----------------\n",
"the regularisation is done on the curvature (2nd derivative) of\n",
"the output distribution\n",
"\n",
"One has to exclude the bins near the peak of the Breit-Wigner,\n",
"because there the curvature is high\n",
"(and the regularisation eventually could enforce a small\n",
"curvature, thus biasing result)\n",
"\n",
"in real life, the parameters below would have to be optimized,\n",
"depending on the data peak position and width\n",
"Or maybe one finds a different regularisation scheme... this is\n",
"just an example..."
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "4474b78c",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:22.247401Z",
"iopub.status.busy": "2026-05-19T20:11:22.247277Z",
"iopub.status.idle": "2026-05-19T20:11:22.452056Z",
"shell.execute_reply": "2026-05-19T20:11:22.450644Z"
}
},
"outputs": [],
"source": [
"Double_t estimatedPeakPosition=3.8;\n",
"Int_t nPeek=3;\n",
"TUnfold::ERegMode regMode=TUnfold::kRegModeCurvature;"
]
},
{
"cell_type": "markdown",
"id": "c5af0d23",
"metadata": {},
"source": [
"calculate bin number corresponding to estimated peak position"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "2dcedf55",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:22.454160Z",
"iopub.status.busy": "2026-05-19T20:11:22.454039Z",
"iopub.status.idle": "2026-05-19T20:11:22.658026Z",
"shell.execute_reply": "2026-05-19T20:11:22.656703Z"
}
},
"outputs": [],
"source": [
"Int_t iPeek=(Int_t)(nGen*(estimatedPeakPosition-xminGen)/(xmaxGen-xminGen)\n",
" // offset 1.5\n",
" // accounts for start bin 1\n",
" // and rounding errors +0.5\n",
" +1.5);"
]
},
{
"cell_type": "markdown",
"id": "d5cb9b80",
"metadata": {},
"source": [
"regularize output bins 1..iPeek-nPeek"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "b7eb837f",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:22.660114Z",
"iopub.status.busy": "2026-05-19T20:11:22.659982Z",
"iopub.status.idle": "2026-05-19T20:11:22.864578Z",
"shell.execute_reply": "2026-05-19T20:11:22.863227Z"
}
},
"outputs": [],
"source": [
"unfold.RegularizeBins(1,1,iPeek-nPeek,regMode);"
]
},
{
"cell_type": "markdown",
"id": "eb16c8a1",
"metadata": {},
"source": [
"regularize output bins iPeek+nPeek..nGen"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "9d4e995b",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:22.866527Z",
"iopub.status.busy": "2026-05-19T20:11:22.866404Z",
"iopub.status.idle": "2026-05-19T20:11:23.086437Z",
"shell.execute_reply": "2026-05-19T20:11:23.085235Z"
}
},
"outputs": [],
"source": [
"unfold.RegularizeBins(iPeek+nPeek,1,nGen-(iPeek+nPeek),regMode);"
]
},
{
"cell_type": "markdown",
"id": "8b3dc35f",
"metadata": {},
"source": [
"unfolding\n",
"-----------"
]
},
{
"cell_type": "markdown",
"id": "18e0c538",
"metadata": {},
"source": [
"set input distribution and bias scale (=0)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "1ad3b100",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:23.088238Z",
"iopub.status.busy": "2026-05-19T20:11:23.088100Z",
"iopub.status.idle": "2026-05-19T20:11:23.291123Z",
"shell.execute_reply": "2026-05-19T20:11:23.289757Z"
}
},
"outputs": [],
"source": [
"if(unfold.SetInput(histMdetData,0.0)>=10000) {\n",
" std::cout<<\"Unfolding result may be wrong\\n\";\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "158cd3bc",
"metadata": {},
"source": [
"do the unfolding here"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "1a7780bc",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:23.293236Z",
"iopub.status.busy": "2026-05-19T20:11:23.293111Z",
"iopub.status.idle": "2026-05-19T20:11:23.503061Z",
"shell.execute_reply": "2026-05-19T20:11:23.501696Z"
}
},
"outputs": [],
"source": [
"Double_t tauMin=0.0;\n",
"Double_t tauMax=0.0;\n",
"Int_t nScan=30;\n",
"Int_t iBest;\n",
"TSpline *logTauX,*logTauY;\n",
"TGraph *lCurve;"
]
},
{
"cell_type": "markdown",
"id": "54f38bc9",
"metadata": {},
"source": [
"this method scans the parameter tau and finds the kink in the L curve\n",
"finally, the unfolding is done for the \"best\" choice of tau"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "b04969e3",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:23.505013Z",
"iopub.status.busy": "2026-05-19T20:11:23.504882Z",
"iopub.status.idle": "2026-05-19T20:11:24.970554Z",
"shell.execute_reply": "2026-05-19T20:11:24.970226Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tau=0.000286365\n",
"chi**2=160.946+4.9728 / 147\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Info in : logtau=-Infinity X=2.186918 Y=8.913305\n",
"Info in : logtau=-3.316953 X=2.218441 Y=7.452705\n",
"Info in : logtau=-3.816953 X=2.197007 Y=8.159573\n",
"Info in : logtau=-4.316953 X=2.187673 Y=8.747364\n",
"Info in : logtau=-3.566953 X=2.205690 Y=7.815298\n",
"Info in : logtau=-4.066953 X=2.190590 Y=8.508864\n",
"Info in : logtau=-3.441953 X=2.211366 Y=7.640910\n",
"Info in : logtau=-3.941953 X=2.193437 Y=8.340054\n",
"Info in : logtau=-3.691953 X=2.201051 Y=7.984482\n",
"Info in : logtau=-4.191953 X=2.188699 Y=8.647055\n",
"Info in : logtau=-3.379453 X=2.214719 Y=7.548752\n",
"Info in : logtau=-3.879453 X=2.195152 Y=8.249925\n",
"Info in : logtau=-3.754453 X=2.198973 Y=8.070882\n",
"Info in : logtau=-3.504453 X=2.208369 Y=7.729472\n",
"Info in : logtau=-3.629453 X=2.203272 Y=7.899759\n",
"Info in : logtau=-4.004453 X=2.191902 Y=8.427286\n",
"Info in : logtau=-4.129453 X=2.189523 Y=8.582569\n",
"Info in : logtau=-4.254453 X=2.188095 Y=8.701883\n",
"Info in : logtau=-3.348203 X=2.216535 Y=7.501212\n",
"Info in : logtau=-3.410703 X=2.212997 Y=7.595312\n",
"Info in : logtau=-3.848203 X=2.196065 Y=8.204633\n",
"Info in : logtau=-3.910703 X=2.194275 Y=8.295174\n",
"Info in : logtau=-3.785703 X=2.197977 Y=8.114949\n",
"Info in : logtau=-3.473203 X=2.209825 Y=7.685600\n",
"Info in : logtau=-3.973203 X=2.192644 Y=8.384211\n",
"Info in : logtau=-3.723203 X=2.199997 Y=8.027409\n",
"Info in : logtau=-3.535703 X=2.206993 Y=7.772651\n",
"Info in : logtau=-3.660703 X=2.202141 Y=7.941987\n",
"Info in : logtau=-3.598203 X=2.204453 Y=7.857599\n",
"Info in : logtau=-4.035703 X=2.191216 Y=8.468939\n",
"Info in : Result logtau=-3.543080 X=2.206680 Y=7.782760\n"
]
}
],
"source": [
"iBest=unfold.ScanLcurve(nScan,tauMin,tauMax,&lCurve,&logTauX,&logTauY);\n",
"std::cout<<\"tau=\"<GetKnot(iBest,t[0],x[0]);\n",
"logTauY->GetKnot(iBest,t[0],y[0]);\n",
"TGraph *bestLcurve=new TGraph(1,x,y);\n",
"TGraph *bestLogTauX=new TGraph(1,t,x);"
]
},
{
"cell_type": "markdown",
"id": "992bcf62",
"metadata": {},
"source": [
"============================================================\n",
"extract unfolding results into histograms"
]
},
{
"cell_type": "markdown",
"id": "054d6bec",
"metadata": {},
"source": [
"set up a bin map, excluding underflow and overflow bins\n",
"the binMap relates the output of the unfolding to the final\n",
"histogram bins"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "910c6f97",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:25.188623Z",
"iopub.status.busy": "2026-05-19T20:11:25.188478Z",
"iopub.status.idle": "2026-05-19T20:11:25.392715Z",
"shell.execute_reply": "2026-05-19T20:11:25.391892Z"
}
},
"outputs": [],
"source": [
"Int_t *binMap=new Int_t[nGen+2];\n",
"for(Int_t i=1;i<=nGen;i++) binMap[i]=i;\n",
"binMap[0]=-1;\n",
"binMap[nGen+1]=-1;\n",
"\n",
"TH1D *histMunfold=new TH1D(\"Unfolded\",\";mass(gen)\",nGen,xminGen,xmaxGen);\n",
"unfold.GetOutput(histMunfold,binMap);\n",
"TH1D *histMdetFold=new TH1D(\"FoldedBack\",\"mass(det)\",nDet,xminDet,xmaxDet);\n",
"unfold.GetFoldedOutput(histMdetFold);"
]
},
{
"cell_type": "markdown",
"id": "1d2ed755",
"metadata": {},
"source": [
"store global correlation coefficients"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "c8e00f12",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:25.394491Z",
"iopub.status.busy": "2026-05-19T20:11:25.394347Z",
"iopub.status.idle": "2026-05-19T20:11:25.598766Z",
"shell.execute_reply": "2026-05-19T20:11:25.598029Z"
}
},
"outputs": [],
"source": [
"TH1D *histRhoi=new TH1D(\"rho_I\",\"mass\",nGen,xminGen,xmaxGen);\n",
"unfold.GetRhoI(histRhoi,binMap);\n",
"\n",
"delete[] binMap;\n",
"binMap=nullptr;"
]
},
{
"cell_type": "markdown",
"id": "c49e8490",
"metadata": {},
"source": [
"=====================================================================\n",
"plot some histograms"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "2a7c9e97",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:25.600577Z",
"iopub.status.busy": "2026-05-19T20:11:25.600458Z",
"iopub.status.idle": "2026-05-19T20:11:25.804474Z",
"shell.execute_reply": "2026-05-19T20:11:25.803636Z"
}
},
"outputs": [],
"source": [
"TCanvas output;"
]
},
{
"cell_type": "markdown",
"id": "e65b8cf2",
"metadata": {},
"source": [
"produce some plots"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "5adc6458",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:25.806207Z",
"iopub.status.busy": "2026-05-19T20:11:25.806090Z",
"iopub.status.idle": "2026-05-19T20:11:26.009877Z",
"shell.execute_reply": "2026-05-19T20:11:26.009234Z"
}
},
"outputs": [],
"source": [
"output.Divide(3,2);"
]
},
{
"cell_type": "markdown",
"id": "b126e5b1",
"metadata": {},
"source": [
"Show the matrix which connects input and output\n",
"There are overflow bins at the bottom, not shown in the plot\n",
"These contain the background shape.\n",
"The overflow bins to the left and right contain\n",
"events which are not reconstructed. These are necessary for proper MC\n",
"normalisation"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "aa732ee8",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:26.012141Z",
"iopub.status.busy": "2026-05-19T20:11:26.012022Z",
"iopub.status.idle": "2026-05-19T20:11:26.218993Z",
"shell.execute_reply": "2026-05-19T20:11:26.218503Z"
}
},
"outputs": [],
"source": [
"output.cd(1);\n",
"histMdetGenMC->Draw(\"BOX\");"
]
},
{
"cell_type": "markdown",
"id": "f76e369f",
"metadata": {},
"source": [
"draw generator-level distribution:\n",
"data (red) [for real data this is not available]\n",
"MC input (black) [with completely wrong peak position and shape]\n",
"unfolded data (blue)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "f677e856",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:26.236459Z",
"iopub.status.busy": "2026-05-19T20:11:26.236326Z",
"iopub.status.idle": "2026-05-19T20:11:26.439534Z",
"shell.execute_reply": "2026-05-19T20:11:26.438886Z"
}
},
"outputs": [],
"source": [
"output.cd(2);\n",
"histMunfold->SetLineColor(kBlue);\n",
"histMunfold->Draw();\n",
"histMgenData->SetLineColor(kRed);\n",
"histMgenData->Draw(\"SAME\");\n",
"histMgenMC->Draw(\"SAME HIST\");"
]
},
{
"cell_type": "markdown",
"id": "a9136bd3",
"metadata": {},
"source": [
"show detector level distributions\n",
"data (red)\n",
"MC (black)\n",
"unfolded data (blue)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "17373db4",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:26.441703Z",
"iopub.status.busy": "2026-05-19T20:11:26.441528Z",
"iopub.status.idle": "2026-05-19T20:11:26.660227Z",
"shell.execute_reply": "2026-05-19T20:11:26.659575Z"
}
},
"outputs": [],
"source": [
"output.cd(3);\n",
"histMdetFold->SetLineColor(kBlue);\n",
"histMdetFold->Draw();\n",
"histMdetData->SetLineColor(kRed);\n",
"histMdetData->Draw(\"SAME\");\n",
"histMdetMC->Draw(\"SAME HIST\");"
]
},
{
"cell_type": "markdown",
"id": "0852faef",
"metadata": {},
"source": [
"show correlation coefficients\n",
"all bins outside the peak are found to be highly correlated\n",
"But they are compatible with zero anyway\n",
"If the peak shape is fitted,\n",
"these correlations have to be taken into account, see example"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "c76cb027",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:26.662348Z",
"iopub.status.busy": "2026-05-19T20:11:26.662226Z",
"iopub.status.idle": "2026-05-19T20:11:26.865437Z",
"shell.execute_reply": "2026-05-19T20:11:26.865073Z"
}
},
"outputs": [],
"source": [
"output.cd(4);\n",
"histRhoi->Draw();"
]
},
{
"cell_type": "markdown",
"id": "03aef207",
"metadata": {},
"source": [
"show rhoi_max(tau) distribution"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "6a5dd150",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:26.871408Z",
"iopub.status.busy": "2026-05-19T20:11:26.871286Z",
"iopub.status.idle": "2026-05-19T20:11:27.180042Z",
"shell.execute_reply": "2026-05-19T20:11:27.179491Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Info in : ps file testUnfold2.ps has been created\n"
]
}
],
"source": [
"output.cd(5);\n",
"logTauX->Draw();\n",
"bestLogTauX->SetMarkerColor(kRed);\n",
"bestLogTauX->Draw(\"*\");\n",
"\n",
"output.cd(6);\n",
"lCurve->Draw(\"AL\");\n",
"bestLcurve->SetMarkerColor(kRed);\n",
"bestLcurve->Draw(\"*\");\n",
"\n",
"output.SaveAs(\"testUnfold2.ps\");\n",
"return 0;"
]
},
{
"cell_type": "markdown",
"id": "de64040a",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "4c33533c",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:11:27.181708Z",
"iopub.status.busy": "2026-05-19T20:11:27.181571Z",
"iopub.status.idle": "2026-05-19T20:11:27.384945Z",
"shell.execute_reply": "2026-05-19T20:11:27.384347Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gROOT->GetListOfCanvases()->Draw()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 5
}