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 auxiliary measurement to constrain some background
The example comprises 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
0.0127820968628
7.74595212936
Processing /mnt/build/workspace/root-makedoc-v614/rootspi/rdoc/src/v6-14-00-patches/tutorials/unfold/testUnfold5d.C...
chi**2=289.624+47.9755 / 213
#include <iostream>
#include <cmath>
#include <map>
#define TEST_INPUT_COVARIANCE
void testUnfold5d()
{
TFile *outputFile=new TFile("testUnfold5_results.root","recreate");
TFile *inputFile=new TFile("testUnfold5_histograms.root");
outputFile->cd();
inputFile->GetObject("detector",detectorBinning);
inputFile->GetObject("generator",generatorBinning);
if((!detectorBinning)||(!generatorBinning)) {
cout<<"problem to read binning schemes\n";
}
detectorBinning->
Write();
generatorBinning->
Write();
TH1 *histDataReco,*histDataTruth;
inputFile->GetObject("histDataReco",histDataReco);
inputFile->GetObject("histDataTruth",histDataTruth);
inputFile->GetObject("histMCGenRec",histMCGenRec);
#ifdef TEST_ZERO_UNCORR_ERROR
for(
int i=0;i<=histMCGenRec->
GetNbinsX()+1;i++) {
for(
int j=0;j<=histMCGenRec->
GetNbinsY()+1;j++) {
}
}
#endif
if((!histDataReco)||(!histDataTruth)||(!histMCGenRec)) {
cout<<"problem to read input histograms\n";
}
const char *REGULARISATION_DISTRIBUTION=0;
const char *REGULARISATION_AXISSTEERING="*[B]";
regMode,constraintMode,densityFlags,
generatorBinning,detectorBinning,
REGULARISATION_DISTRIBUTION,
REGULARISATION_AXISSTEERING);
#ifdef TEST_INPUT_COVARIANCE
for(
int i=1;i<=inputEmatrix->
GetNbinsX();i++) {
}
unfold.SetInput(histDataReco,0.0,0.0,inputEmatrix);
#else
unfold.SetInput(histDataReco );
#endif
#ifdef PRINT_MATRIX_L
TH2 *histL= unfold.GetL(
"L");
cout<<"L["<<unfold.GetLBinning()->GetBinName(j)<<"]";
if(c!=0.0) cout<<
" ["<<i<<
"]="<<
c;
}
cout<<"\n";
}
#endif
const char *SCAN_DISTRIBUTION="signal";
const char *SCAN_AXISSTEERING=0;
Int_t iBest=unfold.ScanTau(nScan,0.,0.,&rhoLogTau,
SCAN_DISTRIBUTION,SCAN_AXISSTEERING,
&lCurve);
rhoLogTau->
GetKnot(iBest,t[0],rho[0]);
for(
Int_t i=0;i<nScan;i++) {
rhoLogTau->
GetKnot(i,tAll[i],rhoAll[i]);
}
cout<<"chi**2="<<unfold.GetChi2A()<<"+"<<unfold.GetChi2L()
<<" / "<<unfold.GetNdf()<<"\n";
TH1 *histDataUnfold=unfold.GetOutput(
"unfolded signal",0,0,0,
kFALSE);
histMCReco->
Scale(scaleFactor);
histMCTruth->
Scale(scaleFactor);
TH2 *histProbability=unfold.GetProbabilityMatrix(
"histProbability");
unfold.GetRhoItotal(
"histGlobalCorr",0,0,0,
kFALSE);
TH1 *histGlobalCorrScan=unfold.GetRhoItotal
(
"histGlobalCorrScan",0,SCAN_DISTRIBUTION,SCAN_AXISSTEERING,
kFALSE);
unfold.GetRhoIJtotal(
"histCorrCoeff",0,0,0,
kFALSE);
canvas.
Print(
"testUnfold5.ps[");
histMCReco->
Draw(
"SAME HIST");
histProbability->
Draw(
"BOX");
histDataUnfold->
Draw(
"E");
histDataTruth->
Draw(
"SAME HIST");
histMCTruth->
Draw(
"SAME HIST");
bestRhoLogTau->
Draw(
"*");
histGlobalCorrScan->
Draw(
"HIST");
canvas.
Print(
"testUnfold5.ps");
canvas.
Print(
"testUnfold5.ps]");
}
Version 17.6, in parallel to changes in TUnfold
History:
- Version 17.5, in parallel to changes in TUnfold
- Version 17.4, in parallel to changes in TUnfold
- Version 17.3, in parallel to changes in TUnfold
- Version 17.2, in parallel to changes in TUnfold
- Version 17.1, in parallel to changes in TUnfold
- Version 17.0 example for multi-dimensional unfolding
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/.
- Author
- Stefan Schmitt DESY, 14.10.2008
Definition in file testUnfold5d.C.