{ "cells": [ { "cell_type": "markdown", "id": "7184d954", "metadata": {}, "source": [ "# testUnfold6\n", "Test program for the class TUnfoldBinning.\n", "\n", "read a simple binning scheme and create/test bin maps\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, test bin map functionality in TUnfoldBinning\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": "cb2b79a6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:11:32.840479Z", "iopub.status.busy": "2026-05-19T20:11:32.840356Z", "iopub.status.idle": "2026-05-19T20:11:32.848260Z", "shell.execute_reply": "2026-05-19T20:11:32.847593Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \n", "#include \n", "#include \n", "#include \n", "#include \n", "#include \n", "#include \"TUnfoldBinningXML.h\"\n", "\n", "using std::cout, std::vector, std::map, std::setw;\n", "\n", "void PrintBinMap(TUnfoldBinning *binning,const char * where,\n", " const Int_t *binMap);" ] }, { "cell_type": "markdown", "id": "60f459b7", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 2, "id": "1304a279", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:11:32.849484Z", "iopub.status.busy": "2026-05-19T20:11:32.849363Z", "iopub.status.idle": "2026-05-19T20:11:32.920055Z", "shell.execute_reply": "2026-05-19T20:11:32.919356Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "void PrintBinMap(TUnfoldBinning *binning,const char * where,\n", " const Int_t *binMap) {\n", "\n", " cout<<\"\\n\"<GetEndBin()+1;i++) {\n", " cout<GetEndBin()+1;i++) {\n", " cout< > destBin;\n", " for(int i=0;iGetEndBin()+1;i++) {\n", " destBin[binMap[i]].push_back(i);\n", " }\n", " bool printed=false;\n", " for(map >::const_iterator i=destBin.begin();i!=destBin.end();i++) {\n", " if((*i).first>=0) {\n", " if(!printed) {\n", " cout<<\"\\ndest |contributing bins\\n\"\n", " <<\"=====+======================================\\n\";\n", " printed=true;\n", " }\n", " for(size_t j=0;j<(*i).second.size();j++) {\n", " cout<GetBinName((*i).second[j])<<\"\\n\";\n", " }\n", " cout<<\"=====+======================================\\n\";\n", " }\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 3, "id": "9539f356", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:11:32.921368Z", "iopub.status.busy": "2026-05-19T20:11:32.921245Z", "iopub.status.idle": "2026-05-19T20:11:33.424581Z", "shell.execute_reply": "2026-05-19T20:11:33.424103Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Binning scheme:\n", " =================================\n", "TUnfoldBinning \"binning\" has 20 bins [1,21] nTH1x=20\n", " TUnfoldBinning \"branch1\" has 12 bins [1,13] nTH1x=12\n", " distribution: 12 bins\n", " \"x\" nbin=4\n", " \"y\" nbin=3\n", " TUnfoldBinning \"branch2\" has 6 bins [13,19] nTH1x=6\n", " distribution: 6 bins\n", " \"x\" nbin=3\n", " \"y\" nbin=2\n", " TUnfoldBinning \"branch3\" has 2 bins [19,21] nTH1x=2\n", " distribution: 2 bins\n", " \"x\" nbin=2\n", "\n", "CreateEmptyBinMap\n", "=======================\n", "global bin: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21\n", "mapped to: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n", "\n", "branch1->FillBinMap1D(...,\"y[C]\",...,2)\n", "=======================\n", "global bin: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21\n", "mapped to: -1 2 3 4 5 2 3 4 5 2 3 4 5 -1 -1 -1 -1 -1 -1 -1 -1 -1\n", "\n", "dest |contributing bins\n", "=====+======================================\n", " 2 |#1 (branch1:y[0,1]:x[0,1])\n", " 2 |#5 (branch1:y[1,2]:x[0,1])\n", " 2 |#9 (branch1:y[2,3]:x[0,1])\n", "=====+======================================\n", " 3 |#2 (branch1:y[0,1]:x[1,2])\n", " 3 |#6 (branch1:y[1,2]:x[1,2])\n", " 3 |#10 (branch1:y[2,3]:x[1,2])\n", "=====+======================================\n", " 4 |#3 (branch1:y[0,1]:x[2,3])\n", " 4 |#7 (branch1:y[1,2]:x[2,3])\n", " 4 |#11 (branch1:y[2,3]:x[2,3])\n", "=====+======================================\n", " 5 |#4 (branch1:y[0,1]:x[3,4])\n", " 5 |#8 (branch1:y[1,2]:x[3,4])\n", " 5 |#12 (branch1:y[2,3]:x[3,4])\n", "=====+======================================\n", "\n", "branch2->FillBinMap1D(...,\"x[C]\",...,7)\n", "=======================\n", "global bin: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21\n", "mapped to: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 7 7 7 8 8 8 -1 -1 -1\n", "\n", "dest |contributing bins\n", "=====+======================================\n", " 7 |#13 (branch2:y[0,1]:x[0,1])\n", " 7 |#14 (branch2:y[0,1]:x[1,2])\n", " 7 |#15 (branch2:y[0,1]:x[2,3])\n", "=====+======================================\n", " 8 |#16 (branch2:y[1,2]:x[0,1])\n", " 8 |#17 (branch2:y[1,2]:x[1,2])\n", " 8 |#18 (branch2:y[1,2]:x[2,3])\n", "=====+======================================\n", "\n", "binning->FillBinMap1D(...,\"y[C]\",...,1)\n", "=======================\n", "global bin: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21\n", "mapped to: -1 1 2 3 4 1 2 3 4 1 2 3 4 5 6 7 5 6 7 8 9 -1\n", "\n", "dest |contributing bins\n", "=====+======================================\n", " 1 |#1 (branch1:y[0,1]:x[0,1])\n", " 1 |#5 (branch1:y[1,2]:x[0,1])\n", " 1 |#9 (branch1:y[2,3]:x[0,1])\n", "=====+======================================\n", " 2 |#2 (branch1:y[0,1]:x[1,2])\n", " 2 |#6 (branch1:y[1,2]:x[1,2])\n", " 2 |#10 (branch1:y[2,3]:x[1,2])\n", "=====+======================================\n", " 3 |#3 (branch1:y[0,1]:x[2,3])\n", " 3 |#7 (branch1:y[1,2]:x[2,3])\n", " 3 |#11 (branch1:y[2,3]:x[2,3])\n", "=====+======================================\n", " 4 |#4 (branch1:y[0,1]:x[3,4])\n", " 4 |#8 (branch1:y[1,2]:x[3,4])\n", " 4 |#12 (branch1:y[2,3]:x[3,4])\n", "=====+======================================\n", " 5 |#13 (branch2:y[0,1]:x[0,1])\n", " 5 |#16 (branch2:y[1,2]:x[0,1])\n", "=====+======================================\n", " 6 |#14 (branch2:y[0,1]:x[1,2])\n", " 6 |#17 (branch2:y[1,2]:x[1,2])\n", "=====+======================================\n", " 7 |#15 (branch2:y[0,1]:x[2,3])\n", " 7 |#18 (branch2:y[1,2]:x[2,3])\n", "=====+======================================\n", " 8 |#19 (branch3:x[0,1])\n", "=====+======================================\n", " 9 |#20 (branch3:x[1,2])\n", "=====+======================================\n" ] } ], "source": [ "TDOMParser parser;\n", "ofstream dtdFile(\"tunfoldbinning.dtd\");\n", "TUnfoldBinningXML::WriteDTD(dtdFile);\n", "dtdFile.close();\n", "TString dir = gSystem->UnixPathName(gSystem->GetDirName(__FILE__));\n", "Int_t error=parser.ParseFile(dir+\"/testUnfold6binning.xml\");\n", "if(error) cout<<\"error=\"<PrintStream(cout);\n", " Int_t *binMap = binning->CreateEmptyBinMap();\n", " PrintBinMap(binning,\"CreateEmptyBinMap\",binMap);\n", "\n", " TUnfoldBinning const *branch1 = binning->FindNode(\"branch1\");\n", " branch1->FillBinMap1D(binMap,\"y[C]\",2);\n", " PrintBinMap(binning,\"branch1->FillBinMap1D(...,\\\"y[C]\\\",...,2)\",binMap);\n", "\n", " delete [] binMap;\n", " binMap = binning->CreateEmptyBinMap();\n", " TUnfoldBinning const *branch2=binning->FindNode(\"branch2\");\n", " branch2->FillBinMap1D(binMap,\"x[C]\",7);\n", " PrintBinMap(binning,\"branch2->FillBinMap1D(...,\\\"x[C]\\\",...,7)\",binMap);\n", "\n", " delete [] binMap;\n", " binMap = binning->CreateEmptyBinMap();\n", " binning->FillBinMap1D(binMap,\"y[C]\",1);\n", " PrintBinMap(binning,\"binning->FillBinMap1D(...,\\\"y[C]\\\",...,1)\",binMap);\n", "\n", " binning->ExportXML(\"testUnfold6.out.xml\");\n", "\n", " delete [] binMap;\n", "\n", "}" ] }, { "cell_type": "markdown", "id": "8552040c", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 4, "id": "c9137bf2", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:11:33.426389Z", "iopub.status.busy": "2026-05-19T20:11:33.426263Z", "iopub.status.idle": "2026-05-19T20:11:33.630709Z", "shell.execute_reply": "2026-05-19T20:11:33.629712Z" } }, "outputs": [], "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 }