From $ROOTSYS/tutorials/math/testUnfold5b.C

// Author: Stefan Schmitt
// DESY, 14.10.2008

//  Version 17.0 example for multi-dimensional unfolding
//

#include <iostream>
#include <fstream>
#include <TFile.h>
#include "TUnfoldBinning.h"

using namespace std;

/*
  This file is part of TUnfold.

  TUnfold is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  TUnfold is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with TUnfold.  If not, see <http://www.gnu.org/licenses/>.
*/

///////////////////////////////////////////////////////////////////////
//
// Test program for the classes TUnfoldDensity and TUnfoldBinning
//
// A toy test of the TUnfold package
//
// This is an example of unfolding a two-dimensional distribution
// also using an auxillary measurement to constrain some background
//
// The example comprizes several macros
//   testUnfold5a.C   create root files with TTree objects for
//                      signal, background and data
//            -> write files  testUnfold5_signal.root
//                            testUnfold5_background.root
//                            testUnfold5_data.root
//
//   testUnfold5b.C   create a root file with the TUnfoldBinning objects
//            -> write file  testUnfold5_binning.root
//
//   testUnfold5c.C   loop over trees and fill histograms based on the
//                      TUnfoldBinning objects
//            -> read  testUnfold5_binning.root
//                     testUnfold5_signal.root
//                     testUnfold5_background.root
//                     testUnfold5_data.root
//
//            -> write testUnfold5_histograms.root
//
//   testUnfold5d.C   run the unfolding
//            -> read  testUnfold5_histograms.root
//            -> write testUnfold5_result.root
//                     testUnfold5_result.ps
//
///////////////////////////////////////////////////////////////////////

void testUnfold5b()
{

  // write binning schemes to root file
  TFile *binningSchemes=new TFile("testUnfold5_binning.root","recreate");

  // reconstructed pt, eta, discriminator
#define NBIN_PT_FINE 8
#define NBIN_ETA_FINE 10
#define NBIN_DISCR 4

  // generated pt, eta
#define NBIN_PT_COARSE 3
#define NBIN_ETA_COARSE 3

  // pt binning
  Double_t ptBinsFine[NBIN_PT_FINE+1]=
     {3.5,4.0,4.5,5.0,6.0,7.0,8.0,10.0,13.0};
  Double_t ptBinsCoarse[NBIN_PT_COARSE+1]=
     {    4.0,    5.0,    7.0,    10.0};
  // eta binning
  Double_t etaBinsFine[NBIN_ETA_FINE+1]=
     {-3.,-2.5,-2.0,-1.,-0.5,0.0,0.5,1.,2.,2.5,3.};
  Double_t etaBinsCoarse[NBIN_ETA_COARSE+1]=
     {         -2.0,    -0.5,    0.5,   2. };

  // discriminator bins
  Double_t discrBins[NBIN_DISCR+1]={0.,0.15,0.5,0.85,1.0};

  //=======================================================================
  // detector level binning scheme

  TUnfoldBinning *detectorBinning=new TUnfoldBinning("detector");
  // highest discriminator bin has fine binning
  TUnfoldBinning *detectorDistribution=
     detectorBinning->AddBinning("detectordistribution");
  detectorDistribution->AddAxis("pt",NBIN_PT_FINE,ptBinsFine,
                                false, // no underflow bin (not reconstructed)
                                true // overflow bin
                                );
  detectorDistribution->AddAxis("eta",NBIN_ETA_FINE,etaBinsFine,
                                false, // no underflow bin (not reconstructed)
                                false // no overflow bin (not reconstructed)
                                );
  detectorDistribution->AddAxis("discriminator",NBIN_DISCR,discrBins,
                                false, // no underflow bin (empty)
                                false // no overflow bin (empty)
                                );
  /* TUnfoldBinning *detectorExtra=
     detectorBinning->AddBinning("detectorextra",7,"one;zwei;three"); */
  detectorBinning->PrintStream(cout);

  //=======================================================================
  // generator level binning
  TUnfoldBinning *generatorBinning=new TUnfoldBinning("generator");

  // signal distribution is measured with coarse binning
  // underflow and overflow bins are needed ot take care of
  // what happens outside the phase-space
  TUnfoldBinning *signalBinning = generatorBinning->AddBinning("signal");
  signalBinning->AddAxis("ptgen",NBIN_PT_COARSE,ptBinsCoarse,
                         true, // underflow bin
                         true // overflow bin
                         );
  signalBinning->AddAxis("etagen",NBIN_ETA_COARSE,etaBinsCoarse,
                         true, // underflow bin
                         true // overflow bin
                         );
  // background distribution is unfolded with fine binning
  // !!! in the reconstructed variable !!!
  //
  // This has the effect of "normalizing" the background in each
  // pt,eta bin to the low discriminator values
  // Only the shape of the discriminator in each (pt,eta) bin
  // is taken from Monte Carlo
  //
  // This method has been applied e.g. in
  //   H1 Collaboration, "Prompt photons in Photoproduction"
  //   Eur.Phys.J. C66 (2010) 17
  //
  TUnfoldBinning *bgrBinning = generatorBinning->AddBinning("background");
  bgrBinning->AddAxis("ptrec",NBIN_PT_FINE,ptBinsFine,
                      false, // no underflow bin (not reconstructed)
                      true // overflow bin
                      );
  bgrBinning->AddAxis("etarec",NBIN_ETA_FINE,etaBinsFine,
                      false, // no underflow bin (not reconstructed)
                      false // no overflow bin (not reconstructed)
                      );
  generatorBinning->PrintStream(cout);

  detectorBinning->Write();
  generatorBinning->Write();

  delete binningSchemes;
}
 testUnfold5b.C:1
 testUnfold5b.C:2
 testUnfold5b.C:3
 testUnfold5b.C:4
 testUnfold5b.C:5
 testUnfold5b.C:6
 testUnfold5b.C:7
 testUnfold5b.C:8
 testUnfold5b.C:9
 testUnfold5b.C:10
 testUnfold5b.C:11
 testUnfold5b.C:12
 testUnfold5b.C:13
 testUnfold5b.C:14
 testUnfold5b.C:15
 testUnfold5b.C:16
 testUnfold5b.C:17
 testUnfold5b.C:18
 testUnfold5b.C:19
 testUnfold5b.C:20
 testUnfold5b.C:21
 testUnfold5b.C:22
 testUnfold5b.C:23
 testUnfold5b.C:24
 testUnfold5b.C:25
 testUnfold5b.C:26
 testUnfold5b.C:27
 testUnfold5b.C:28
 testUnfold5b.C:29
 testUnfold5b.C:30
 testUnfold5b.C:31
 testUnfold5b.C:32
 testUnfold5b.C:33
 testUnfold5b.C:34
 testUnfold5b.C:35
 testUnfold5b.C:36
 testUnfold5b.C:37
 testUnfold5b.C:38
 testUnfold5b.C:39
 testUnfold5b.C:40
 testUnfold5b.C:41
 testUnfold5b.C:42
 testUnfold5b.C:43
 testUnfold5b.C:44
 testUnfold5b.C:45
 testUnfold5b.C:46
 testUnfold5b.C:47
 testUnfold5b.C:48
 testUnfold5b.C:49
 testUnfold5b.C:50
 testUnfold5b.C:51
 testUnfold5b.C:52
 testUnfold5b.C:53
 testUnfold5b.C:54
 testUnfold5b.C:55
 testUnfold5b.C:56
 testUnfold5b.C:57
 testUnfold5b.C:58
 testUnfold5b.C:59
 testUnfold5b.C:60
 testUnfold5b.C:61
 testUnfold5b.C:62
 testUnfold5b.C:63
 testUnfold5b.C:64
 testUnfold5b.C:65
 testUnfold5b.C:66
 testUnfold5b.C:67
 testUnfold5b.C:68
 testUnfold5b.C:69
 testUnfold5b.C:70
 testUnfold5b.C:71
 testUnfold5b.C:72
 testUnfold5b.C:73
 testUnfold5b.C:74
 testUnfold5b.C:75
 testUnfold5b.C:76
 testUnfold5b.C:77
 testUnfold5b.C:78
 testUnfold5b.C:79
 testUnfold5b.C:80
 testUnfold5b.C:81
 testUnfold5b.C:82
 testUnfold5b.C:83
 testUnfold5b.C:84
 testUnfold5b.C:85
 testUnfold5b.C:86
 testUnfold5b.C:87
 testUnfold5b.C:88
 testUnfold5b.C:89
 testUnfold5b.C:90
 testUnfold5b.C:91
 testUnfold5b.C:92
 testUnfold5b.C:93
 testUnfold5b.C:94
 testUnfold5b.C:95
 testUnfold5b.C:96
 testUnfold5b.C:97
 testUnfold5b.C:98
 testUnfold5b.C:99
 testUnfold5b.C:100
 testUnfold5b.C:101
 testUnfold5b.C:102
 testUnfold5b.C:103
 testUnfold5b.C:104
 testUnfold5b.C:105
 testUnfold5b.C:106
 testUnfold5b.C:107
 testUnfold5b.C:108
 testUnfold5b.C:109
 testUnfold5b.C:110
 testUnfold5b.C:111
 testUnfold5b.C:112
 testUnfold5b.C:113
 testUnfold5b.C:114
 testUnfold5b.C:115
 testUnfold5b.C:116
 testUnfold5b.C:117
 testUnfold5b.C:118
 testUnfold5b.C:119
 testUnfold5b.C:120
 testUnfold5b.C:121
 testUnfold5b.C:122
 testUnfold5b.C:123
 testUnfold5b.C:124
 testUnfold5b.C:125
 testUnfold5b.C:126
 testUnfold5b.C:127
 testUnfold5b.C:128
 testUnfold5b.C:129
 testUnfold5b.C:130
 testUnfold5b.C:131
 testUnfold5b.C:132
 testUnfold5b.C:133
 testUnfold5b.C:134
 testUnfold5b.C:135
 testUnfold5b.C:136
 testUnfold5b.C:137
 testUnfold5b.C:138
 testUnfold5b.C:139
 testUnfold5b.C:140
 testUnfold5b.C:141
 testUnfold5b.C:142
 testUnfold5b.C:143
 testUnfold5b.C:144
 testUnfold5b.C:145
 testUnfold5b.C:146
 testUnfold5b.C:147
 testUnfold5b.C:148
 testUnfold5b.C:149
 testUnfold5b.C:150
 testUnfold5b.C:151
 testUnfold5b.C:152
 testUnfold5b.C:153
 testUnfold5b.C:154
 testUnfold5b.C:155
 testUnfold5b.C:156
 testUnfold5b.C:157
 testUnfold5b.C:158
 testUnfold5b.C:159
 testUnfold5b.C:160
 testUnfold5b.C:161
 testUnfold5b.C:162