00001 // Author: Stefan Schmitt 00002 // DESY, 14.10.2008 00003 00004 // Version 17.6, updated for writing out XML code 00005 // 00006 // History: 00007 // Version 17.5, updated for writing out XML code 00008 // Version 17.4, updated for writing out XML code 00009 // Version 17.3, updated for writing out XML code 00010 // Version 17.2, updated for writing out XML code 00011 // Version 17.1, in parallel to changes in TUnfold 00012 // Version 17.0 example for multi-dimensional unfolding 00013 // 00014 00015 #include <iostream> 00016 #include <fstream> 00017 #include <TFile.h> 00018 #include "TUnfoldBinningXML.h" 00019 #include <TF2.h> 00020 00021 using namespace std; 00022 00023 /* 00024 This file is part of TUnfold. 00025 00026 TUnfold is free software: you can redistribute it and/or modify 00027 it under the terms of the GNU General Public License as published by 00028 the Free Software Foundation, either version 3 of the License, or 00029 (at your option) any later version. 00030 00031 TUnfold is distributed in the hope that it will be useful, 00032 but WITHOUT ANY WARRANTY; without even the implied warranty of 00033 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00034 GNU General Public License for more details. 00035 00036 You should have received a copy of the GNU General Public License 00037 along with TUnfold. If not, see <http://www.gnu.org/licenses/>. 00038 */ 00039 00040 /////////////////////////////////////////////////////////////////////// 00041 // 00042 // Test program for the classes TUnfoldDensity and TUnfoldBinning 00043 // 00044 // A toy test of the TUnfold package 00045 // 00046 // This is an example of unfolding a two-dimensional distribution 00047 // also using an auxillary measurement to constrain some background 00048 // 00049 // The example comprizes several macros 00050 // testUnfold5a.C create root files with TTree objects for 00051 // signal, background and data 00052 // -> write files testUnfold5_signal.root 00053 // testUnfold5_background.root 00054 // testUnfold5_data.root 00055 // 00056 // testUnfold5b.C create a root file with the TUnfoldBinning objects 00057 // -> write file testUnfold5_binning.root 00058 // 00059 // testUnfold5c.C loop over trees and fill histograms based on the 00060 // TUnfoldBinning objects 00061 // -> read testUnfold5_binning.root 00062 // testUnfold5_signal.root 00063 // testUnfold5_background.root 00064 // testUnfold5_data.root 00065 // 00066 // -> write testUnfold5_histograms.root 00067 // 00068 // testUnfold5d.C run the unfolding 00069 // -> read testUnfold5_histograms.root 00070 // -> write testUnfold5_result.root 00071 // testUnfold5_result.ps 00072 // 00073 /////////////////////////////////////////////////////////////////////// 00074 00075 void testUnfold5b() 00076 { 00077 00078 // write binning schemes to root file 00079 TFile *binningSchemes=new TFile("testUnfold5_binning.root","recreate"); 00080 00081 // reconstructed pt, eta, discriminator 00082 #define NBIN_PT_FINE 8 00083 #define NBIN_ETA_FINE 10 00084 #define NBIN_DISCR 4 00085 00086 // generated pt, eta 00087 #define NBIN_PT_COARSE 3 00088 #define NBIN_ETA_COARSE 3 00089 00090 // pt binning 00091 Double_t ptBinsFine[NBIN_PT_FINE+1]= 00092 {3.5,4.0,4.5,5.0,6.0,7.0,8.0,10.0,13.0}; 00093 Double_t ptBinsCoarse[NBIN_PT_COARSE+1]= 00094 { 4.0, 5.0, 7.0, 10.0}; 00095 // eta binning 00096 Double_t etaBinsFine[NBIN_ETA_FINE+1]= 00097 {-3.,-2.5,-2.0,-1.,-0.5,0.0,0.5,1.,2.,2.5,3.}; 00098 Double_t etaBinsCoarse[NBIN_ETA_COARSE+1]= 00099 { -2.0, -0.5, 0.5, 2. }; 00100 00101 // discriminator bins 00102 Double_t discrBins[NBIN_DISCR+1]={0.,0.15,0.5,0.85,1.0}; 00103 00104 //======================================================================= 00105 // detector level binning scheme 00106 00107 TUnfoldBinning *detectorBinning=new TUnfoldBinning("detector"); 00108 // highest discriminator bin has fine binning 00109 TUnfoldBinning *detectorDistribution= 00110 detectorBinning->AddBinning("detectordistribution"); 00111 detectorDistribution->AddAxis("pt",NBIN_PT_FINE,ptBinsFine, 00112 false, // no underflow bin (not reconstructed) 00113 true // overflow bin 00114 ); 00115 detectorDistribution->AddAxis("eta",NBIN_ETA_FINE,etaBinsFine, 00116 false, // no underflow bin (not reconstructed) 00117 false // no overflow bin (not reconstructed) 00118 ); 00119 detectorDistribution->AddAxis("discriminator",NBIN_DISCR,discrBins, 00120 false, // no underflow bin (empty) 00121 false // no overflow bin (empty) 00122 ); 00123 /* TUnfoldBinning *detectorExtra= 00124 detectorBinning->AddBinning("detectorextra",7,"one;zwei;three"); 00125 detectorBinning->PrintStream(cout); */ 00126 00127 //======================================================================= 00128 // generator level binning 00129 TUnfoldBinning *generatorBinning=new TUnfoldBinning("generator"); 00130 00131 // signal distribution is measured with coarse binning 00132 // underflow and overflow bins are needed ot take care of 00133 // what happens outside the phase-space 00134 TUnfoldBinning *signalBinning = generatorBinning->AddBinning("signal"); 00135 signalBinning->AddAxis("ptgen",NBIN_PT_COARSE,ptBinsCoarse, 00136 true, // underflow bin 00137 true // overflow bin 00138 ); 00139 signalBinning->AddAxis("etagen",NBIN_ETA_COARSE,etaBinsCoarse, 00140 true, // underflow bin 00141 true // overflow bin 00142 ); 00143 00144 // this is just an example how to set bin-dependent factors 00145 // for the regularisation 00146 TF2 *userFunc=new TF2("userfunc","1./x+0.2*y^2",ptBinsCoarse[0], 00147 ptBinsCoarse[NBIN_PT_COARSE], 00148 etaBinsCoarse[0],etaBinsCoarse[NBIN_ETA_COARSE]); 00149 signalBinning->SetBinFactorFunction(1.0,userFunc); 00150 00151 // background distribution is unfolded with fine binning 00152 // !!! in the reconstructed variable !!! 00153 // 00154 // This has the effect of "normalizing" the background in each 00155 // pt,eta bin to the low discriminator values 00156 // Only the shape of the discriminator in each (pt,eta) bin 00157 // is taken from Monte Carlo 00158 // 00159 // This method has been applied e.g. in 00160 // H1 Collaboration, "Prompt photons in Photoproduction" 00161 // Eur.Phys.J. C66 (2010) 17 00162 // 00163 TUnfoldBinning *bgrBinning = generatorBinning->AddBinning("background"); 00164 bgrBinning->AddAxis("ptrec",NBIN_PT_FINE,ptBinsFine, 00165 false, // no underflow bin (not reconstructed) 00166 true // overflow bin 00167 ); 00168 bgrBinning->AddAxis("etarec",NBIN_ETA_FINE,etaBinsFine, 00169 false, // no underflow bin (not reconstructed) 00170 false // no overflow bin (not reconstructed) 00171 ); 00172 generatorBinning->PrintStream(cout); 00173 00174 detectorBinning->Write(); 00175 generatorBinning->Write(); 00176 00177 ofstream xmlOut("testUnfold5binning.xml"); 00178 TUnfoldBinningXML::ExportXML(*detectorBinning,xmlOut,kTRUE,kFALSE); 00179 TUnfoldBinningXML::ExportXML(*generatorBinning,xmlOut,kFALSE,kTRUE); 00180 TUnfoldBinningXML::WriteDTD(); 00181 xmlOut.close(); 00182 00183 delete binningSchemes; 00184 }