Logo ROOT  
Reference Guide
testUnfold5b.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_unfold
3/// \notebook
4/// Test program for the classes TUnfoldDensity and TUnfoldBinning.
5///
6/// A toy test of the TUnfold package
7///
8/// This is an example of unfolding a two-dimensional distribution
9/// also using an auxiliary measurement to constrain some background
10///
11/// The example comprises several macros
12/// - testUnfold5a.C create root files with TTree objects for
13/// signal, background and data
14/// - write files testUnfold5_signal.root
15/// testUnfold5_background.root
16/// testUnfold5_data.root
17///
18/// - testUnfold5b.C create a root file with the TUnfoldBinning objects
19/// - write file testUnfold5_binning.root
20///
21/// - testUnfold5c.C loop over trees and fill histograms based on the
22/// TUnfoldBinning objects
23/// - read testUnfold5_binning.root
24/// testUnfold5_signal.root
25/// testUnfold5_background.root
26/// testUnfold5_data.root
27///
28/// - write testUnfold5_histograms.root
29///
30/// - testUnfold5d.C run the unfolding
31/// - read testUnfold5_histograms.root
32/// - write testUnfold5_result.root
33/// testUnfold5_result.ps
34///
35/// \macro_output
36/// \macro_code
37///
38/// **Version 17.6, in parallel to changes in TUnfold**
39///
40/// #### History:
41/// - Version 17.5, updated for writing out XML code
42/// - Version 17.4, updated for writing out XML code
43/// - Version 17.3, updated for writing out XML code
44/// - Version 17.2, updated for writing out XML code
45/// - Version 17.1, in parallel to changes in TUnfold
46/// - Version 17.0 example for multi-dimensional unfolding
47///
48/// This file is part of TUnfold.
49///
50/// TUnfold is free software: you can redistribute it and/or modify
51/// it under the terms of the GNU General Public License as published by
52/// the Free Software Foundation, either version 3 of the License, or
53/// (at your option) any later version.
54///
55/// TUnfold is distributed in the hope that it will be useful,
56/// but WITHOUT ANY WARRANTY; without even the implied warranty of
57/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58/// GNU General Public License for more details.
59///
60/// You should have received a copy of the GNU General Public License
61/// along with TUnfold. If not, see <http://www.gnu.org/licenses/>.
62///
63/// \author Stefan Schmitt DESY, 14.10.2008
64
65#include <iostream>
66#include <fstream>
67#include <TFile.h>
68#include "TUnfoldBinningXML.h"
69#include <TF2.h>
70
71using namespace std;
72
73void testUnfold5b()
74{
75
76 // write binning schemes to root file
77 TFile *binningSchemes=new TFile("testUnfold5_binning.root","recreate");
78
79 // reconstructed pt, eta, discriminator
80#define NBIN_PT_FINE 8
81#define NBIN_ETA_FINE 10
82#define NBIN_DISCR 4
83
84 // generated pt, eta
85#define NBIN_PT_COARSE 3
86#define NBIN_ETA_COARSE 3
87
88 // pt binning
89 Double_t ptBinsFine[NBIN_PT_FINE+1]=
90 {3.5,4.0,4.5,5.0,6.0,7.0,8.0,10.0,13.0};
91 Double_t ptBinsCoarse[NBIN_PT_COARSE+1]=
92 { 4.0, 5.0, 7.0, 10.0};
93 // eta binning
94 Double_t etaBinsFine[NBIN_ETA_FINE+1]=
95 {-3.,-2.5,-2.0,-1.,-0.5,0.0,0.5,1.,2.,2.5,3.};
96 Double_t etaBinsCoarse[NBIN_ETA_COARSE+1]=
97 { -2.0, -0.5, 0.5, 2. };
98
99 // discriminator bins
100 Double_t discrBins[NBIN_DISCR+1]={0.,0.15,0.5,0.85,1.0};
101
102 //=======================================================================
103 // detector level binning scheme
104
105 TUnfoldBinning *detectorBinning=new TUnfoldBinning("detector");
106 // highest discriminator bin has fine binning
107 TUnfoldBinning *detectorDistribution=
108 detectorBinning->AddBinning("detectordistribution");
109 detectorDistribution->AddAxis("pt",NBIN_PT_FINE,ptBinsFine,
110 false, // no underflow bin (not reconstructed)
111 true // overflow bin
112 );
113 detectorDistribution->AddAxis("eta",NBIN_ETA_FINE,etaBinsFine,
114 false, // no underflow bin (not reconstructed)
115 false // no overflow bin (not reconstructed)
116 );
117 detectorDistribution->AddAxis("discriminator",NBIN_DISCR,discrBins,
118 false, // no underflow bin (empty)
119 false // no overflow bin (empty)
120 );
121 /* TUnfoldBinning *detectorExtra=
122 detectorBinning->AddBinning("detectorextra",7,"one;zwei;three");
123 detectorBinning->PrintStream(cout); */
124
125 //=======================================================================
126 // generator level binning
127 TUnfoldBinning *generatorBinning=new TUnfoldBinning("generator");
128
129 // signal distribution is measured with coarse binning
130 // underflow and overflow bins are needed ot take care of
131 // what happens outside the phase-space
132 TUnfoldBinning *signalBinning = generatorBinning->AddBinning("signal");
133 signalBinning->AddAxis("ptgen",NBIN_PT_COARSE,ptBinsCoarse,
134 true, // underflow bin
135 true // overflow bin
136 );
137 signalBinning->AddAxis("etagen",NBIN_ETA_COARSE,etaBinsCoarse,
138 true, // underflow bin
139 true // overflow bin
140 );
141
142 // this is just an example how to set bin-dependent factors
143 // for the regularisation
144 TF2 *userFunc=new TF2("userfunc","1./x+0.2*y^2",ptBinsCoarse[0],
145 ptBinsCoarse[NBIN_PT_COARSE],
146 etaBinsCoarse[0],etaBinsCoarse[NBIN_ETA_COARSE]);
147 signalBinning->SetBinFactorFunction(1.0,userFunc);
148
149 // background distribution is unfolded with fine binning
150 // !!! in the reconstructed variable !!!
151 //
152 // This has the effect of "normalizing" the background in each
153 // pt,eta bin to the low discriminator values
154 // Only the shape of the discriminator in each (pt,eta) bin
155 // is taken from Monte Carlo
156 //
157 // This method has been applied e.g. in
158 // H1 Collaboration, "Prompt photons in Photoproduction"
159 // Eur.Phys.J. C66 (2010) 17
160 //
161 TUnfoldBinning *bgrBinning = generatorBinning->AddBinning("background");
162 bgrBinning->AddAxis("ptrec",NBIN_PT_FINE,ptBinsFine,
163 false, // no underflow bin (not reconstructed)
164 true // overflow bin
165 );
166 bgrBinning->AddAxis("etarec",NBIN_ETA_FINE,etaBinsFine,
167 false, // no underflow bin (not reconstructed)
168 false // no overflow bin (not reconstructed)
169 );
170 generatorBinning->PrintStream(cout);
171
172 detectorBinning->Write();
173 generatorBinning->Write();
174
175 ofstream xmlOut("testUnfold5binning.xml");
176 TUnfoldBinningXML::ExportXML(*detectorBinning,xmlOut,kTRUE,kFALSE);
177 TUnfoldBinningXML::ExportXML(*generatorBinning,xmlOut,kFALSE,kTRUE);
179 xmlOut.close();
180
181 delete binningSchemes;
182}
const Bool_t kFALSE
Definition: RtypesCore.h:88
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
A 2-Dim function with parameters.
Definition: TF2.h:29
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:785
static Int_t ExportXML(const TUnfoldBinning &binning, std::ostream &out, Bool_t writeHeader, Bool_t writeFooter, Int_t indent=0)
Export a binning scheme to a stream in XML format.
static void WriteDTD(const char *fileName="tunfoldbinning.dtd")
Write dtd file.
Binning schemes for use with the unfolding algorithm TUnfoldDensity.
void PrintStream(std::ostream &out, Int_t indent=0, int debug=0) const
Print some information about this binning tree.
void SetBinFactorFunction(Double_t normalisation, TF1 *userFunc=0)
Set normalisation factor and function which are used in calls to GetBinFactor().
TUnfoldBinning * AddBinning(TUnfoldBinning *binning)
Add a TUnfoldBinning as the last child of this node.
Bool_t AddAxis(const char *name, Int_t nBins, const Double_t *binBorders, Bool_t hasUnderflow, Bool_t hasOverflow)
Add an axis with the specified bin borders.