Logo ROOT  
Reference Guide
No Matches
testUnfold5b.C File Reference

Detailed Description

View in nbviewer Open in SWAN 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
TUnfoldBinning "generator" has 115 bins [1,116] nTH1x=115
TUnfoldBinning "signal" has 25 bins [1,26] nTH1x=25
distribution: 25 bins
"ptgen" nbin=3 plus underflow plus overflow
"etagen" nbin=3 plus underflow plus overflow
TUnfoldBinning "background" has 90 bins [26,116] nTH1x=90
distribution: 90 bins
"ptrec" nbin=8 plus overflow
"etarec" nbin=10
#include <iostream>
#include <fstream>
#include <TFile.h>
#include <TF2.h>
using namespace std;
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
// pt binning
Double_t ptBinsFine[NBIN_PT_FINE+1]=
Double_t ptBinsCoarse[NBIN_PT_COARSE+1]=
{ 4.0, 5.0, 7.0, 10.0};
// eta binning
Double_t etaBinsFine[NBIN_ETA_FINE+1]=
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=
false, // no underflow bin (not reconstructed)
true // overflow bin
false, // no underflow bin (not reconstructed)
false // no overflow bin (not reconstructed)
false, // no underflow bin (empty)
false // no overflow bin (empty)
/* TUnfoldBinning *detectorExtra=
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");
true, // underflow bin
true // overflow bin
true, // underflow bin
true // overflow bin
// this is just an example how to set bin-dependent factors
// for the regularisation
TF2 *userFunc=new TF2("userfunc","1./x+0.2*y^2",ptBinsCoarse[0],
// 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");
false, // no underflow bin (not reconstructed)
true // overflow bin
false, // no underflow bin (not reconstructed)
false // no overflow bin (not reconstructed)
ofstream xmlOut("testUnfold5binning.xml");
delete binningSchemes;
const Bool_t kFALSE
Definition RtypesCore.h:92
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
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:54
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:798
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.

Version 17.6, in parallel to changes in TUnfold


  • Version 17.5, updated for writing out XML code
  • Version 17.4, updated for writing out XML code
  • Version 17.3, updated for writing out XML code
  • Version 17.2, updated for writing out XML code
  • 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/.

Stefan Schmitt DESY, 14.10.2008

Definition in file testUnfold5b.C.