ROOT  6.06/09
Reference Guide
TSVDUnfold.h
Go to the documentation of this file.
1 // Author: Kerstin Tackmann, Andreas Hoecker, Heiko Lacker
2 
3 /**********************************************************************************
4  * *
5  * Project: TSVDUnfold - data unfolding based on Singular Value Decomposition *
6  * Package: ROOT *
7  * Class : TSVDUnfold *
8  * *
9  * Description: *
10  * Single class implementation of SVD data unfolding based on: *
11  * A. Hoecker, V. Kartvelishvili, *
12  * "SVD approach to data unfolding" *
13  * NIM A372, 469 (1996) [hep-ph/9509307] *
14  * *
15  * Authors: *
16  * Kerstin Tackmann <Kerstin.Tackmann@cern.ch> - CERN, Switzerland *
17  * Andreas Hoecker <Andreas.Hoecker@cern.ch> - CERN, Switzerland *
18  * Heiko Lacker <lacker@physik.hu-berlin.de> - Humboldt U, Germany *
19  * *
20  * Copyright (c) 2010: *
21  * CERN, Switzerland *
22  * Humboldt University, Germany *
23  * *
24  **********************************************************************************/
25 
26 //////////////////////////////////////////////////////////////////////////
27 // //
28 // TSVDUnfold //
29 // //
30 // Data unfolding using Singular Value Decomposition (hep-ph/9509307) //
31 // Authors: Kerstin Tackmann, Andreas Hoecker, Heiko Lacker //
32 // //
33 //////////////////////////////////////////////////////////////////////////
34 
35 #ifndef TSVDUNFOLD_H
36 #define TSVDUNFOLD_H
37 
38 #ifndef ROOT_TObject
39 #include "TObject.h"
40 #endif
41 #ifndef ROOT_TMatrixD
42 #include "TMatrixD.h"
43 #endif
44 #ifndef ROOT_TVectorD
45 #include "TVectorD.h"
46 #endif
47 #ifndef ROOT_TMatrixDSym
48 #include "TMatrixDSym.h"
49 #endif
50 
51 class TH1D;
52 class TH2D;
53 
54 class TSVDUnfold : public TObject {
55 
56 public:
57 
58  // Constructor
59  // Initialisation of unfolding
60  // "bdat" - measured data distribution (number of events)
61  // "Bcov" - covariance matrix for measured data distribution
62  // "bini" - reconstructed MC distribution (number of events)
63  // "xini" - truth MC distribution (number of events)
64  // "Adet" - detector response matrix (number of events)
65  TSVDUnfold( const TH1D* bdat, const TH1D* bini, const TH1D* xini, const TH2D* Adet );
66  TSVDUnfold( const TH1D* bdat, TH2D* Bcov, const TH1D* bini, const TH1D* xini, const TH2D* Adet );
67  TSVDUnfold( const TSVDUnfold& other );
68 
69  // Destructor
70  virtual ~TSVDUnfold();
71 
72  // Set option to normalize unfolded spectrum to unit area
73  // "normalize" - switch
74  void SetNormalize ( Bool_t normalize ) { fNormalize = normalize; }
75 
76  // Do the unfolding
77  // "kreg" - number of singular values used (regularisation)
78  TH1D* Unfold ( Int_t kreg );
79 
80  // Determine for given input error matrix covariance matrix of unfolded
81  // spectrum from toy simulation
82  // "cov" - covariance matrix on the measured spectrum, to be propagated
83  // "ntoys" - number of pseudo experiments used for the propagation
84  // "seed" - seed for pseudo experiments
85  TH2D* GetUnfoldCovMatrix( const TH2D* cov, Int_t ntoys, Int_t seed = 1 );
86 
87  // Determine covariance matrix of unfolded spectrum from finite statistics in
88  // response matrix
89  // "ntoys" - number of pseudo experiments used for the propagation
90  // "seed" - seed for pseudo experiments
91  TH2D* GetAdetCovMatrix( Int_t ntoys, Int_t seed=1 );
92 
93  // Regularisation parameter
94  Int_t GetKReg() const { return fKReg; }
95 
96  // Obtain the distribution of |d| (for determining the regularization)
97  TH1D* GetD() const;
98 
99  // Obtain the distribution of singular values
100  TH1D* GetSV() const;
101 
102  // Obtain the computed regularized covariance matrix
103  TH2D* GetXtau() const;
104 
105  // Obtain the computed inverse of the covariance matrix
106  TH2D* GetXinv() const;
107 
108  //Obtain the covariance matrix on the data
109  TH2D* GetBCov() const;
110 
111  // Helper functions
112  Double_t ComputeChiSquared( const TH1D& truspec, const TH1D& unfspec );
113 
114 private:
115 
116  // Helper functions for vector and matrix operations
117  void FillCurvatureMatrix( TMatrixD& tCurv, TMatrixD& tC ) const;
118  static Double_t GetCurvature ( const TVectorD& vec, const TMatrixD& curv );
119 
120  void InitHistos ( );
121 
122  // Helper functions
123  static void H2V ( const TH1D* histo, TVectorD& vec );
124  static void H2Verr ( const TH1D* histo, TVectorD& vec );
125  static void V2H ( const TVectorD& vec, TH1D& histo );
126  static void H2M ( const TH2D* histo, TMatrixD& mat );
127  static void M2H ( const TMatrixD& mat, TH2D& histo );
128  static TMatrixD MatDivVec( const TMatrixD& mat, const TVectorD& vec, Int_t zero=0 );
129  static TVectorD CompProd ( const TVectorD& vec1, const TVectorD& vec2 );
130 
131  static TVectorD VecDiv ( const TVectorD& vec1, const TVectorD& vec2, Int_t zero = 0 );
132  static void RegularisedSymMatInvert( TMatrixDSym& mat, Double_t eps = 1e-3 );
133 
134  // Class members
135  Int_t fNdim; //! Truth and reconstructed dimensions
136  Int_t fDdim; //! Derivative for curvature matrix
137  Bool_t fNormalize; //! Normalize unfolded spectrum to 1
138  Int_t fKReg; //! Regularisation parameter
139  TH1D* fDHist; //! Distribution of d (for checking regularization)
140  TH1D* fSVHist; //! Distribution of singular values
141  TH2D* fXtau; //! Computed regularized covariance matrix
142  TH2D* fXinv; //! Computed inverse of covariance matrix
143 
144  // Input histos
145  const TH1D* fBdat; // measured distribution (data)
146  TH2D* fBcov; // covariance matrix of measured distribution (data)
147  const TH1D* fBini; // reconstructed distribution (MC)
148  const TH1D* fXini; // truth distribution (MC)
149  const TH2D* fAdet; // Detector response matrix
150 
151  // Evaluation of covariance matrices
152  TH1D* fToyhisto; //! Toy MC histogram
153  TH2D* fToymat; //! Toy MC detector response matrix
154  Bool_t fToyMode; //! Internal switch for covariance matrix propagation
155  Bool_t fMatToyMode; //! Internal switch for evaluation of statistical uncertainties from response matrix
156 
157 
158  ClassDef( TSVDUnfold, 0 ) // Data unfolding using Singular Value Decomposition (hep-ph/9509307)
159 };
160 
161 #endif
Bool_t fMatToyMode
Internal switch for covariance matrix propagation.
Definition: TSVDUnfold.h:155
TH2D * fXtau
Distribution of singular values.
Definition: TSVDUnfold.h:141
SVD Approach to Data Unfolding.
Definition: TSVDUnfold.h:54
const TH1D * fXini
Definition: TSVDUnfold.h:148
static void H2Verr(const TH1D *histo, TVectorD &vec)
Fill 1D histogram errors into vector.
Definition: TSVDUnfold.cxx:634
Bool_t fToyMode
Toy MC detector response matrix.
Definition: TSVDUnfold.h:154
static Double_t GetCurvature(const TVectorD &vec, const TMatrixD &curv)
Compute curvature of vector.
Definition: TSVDUnfold.cxx:718
TH2D * fBcov
Definition: TSVDUnfold.h:146
TH1D * fSVHist
Distribution of d (for checking regularization)
Definition: TSVDUnfold.h:140
TH1D * Unfold(Int_t kreg)
Perform the unfolding with regularisation parameter kreg.
Definition: TSVDUnfold.cxx:243
TH2D * GetXinv() const
Returns the computed inverse of the covariance matrix.
Definition: TSVDUnfold.cxx:610
Int_t fKReg
Normalize unfolded spectrum to 1.
Definition: TSVDUnfold.h:138
TH2D * GetUnfoldCovMatrix(const TH2D *cov, Int_t ntoys, Int_t seed=1)
Determine for given input error matrix covariance matrix of unfolded spectrum from toy simulation giv...
Definition: TSVDUnfold.cxx:411
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
static TMatrixD MatDivVec(const TMatrixD &mat, const TVectorD &vec, Int_t zero=0)
Divide matrix entries by vector.
Definition: TSVDUnfold.cxx:690
Bool_t fNormalize
Derivative for curvature matrix.
Definition: TSVDUnfold.h:137
TSVDUnfold(const TH1D *bdat, const TH1D *bini, const TH1D *xini, const TH2D *Adet)
Alternative constructor User provides data and MC test spectra, as well as detector response matrix...
Definition: TSVDUnfold.cxx:79
TH2D * fXinv
Computed regularized covariance matrix.
Definition: TSVDUnfold.h:142
TH2D * GetBCov() const
Returns the covariance matrix.
Definition: TSVDUnfold.cxx:618
void SetNormalize(Bool_t normalize)
Definition: TSVDUnfold.h:74
#define ClassDef(name, id)
Definition: Rtypes.h:254
TH1D * GetSV() const
Returns singular values vector.
Definition: TSVDUnfold.cxx:593
Double_t ComputeChiSquared(const TH1D &truspec, const TH1D &unfspec)
Helper routine to compute chi-squared between distributions using the computed inverse of the covaria...
Definition: TSVDUnfold.cxx:886
TH1D * GetD() const
Returns d vector (for choosing appropriate regularisation)
Definition: TSVDUnfold.cxx:582
Int_t fDdim
Truth and reconstructed dimensions.
Definition: TSVDUnfold.h:136
static void RegularisedSymMatInvert(TMatrixDSym &mat, Double_t eps=1e-3)
naive regularised inversion cuts off small elements
Definition: TSVDUnfold.cxx:833
static void H2V(const TH1D *histo, TVectorD &vec)
Fill 1D histogram into vector.
Definition: TSVDUnfold.cxx:626
const TH1D * fBdat
Computed inverse of covariance matrix.
Definition: TSVDUnfold.h:145
TH2D * fToymat
Toy MC histogram.
Definition: TSVDUnfold.h:153
TH2D * GetXtau() const
Returns the computed regularized covariance matrix corresponding to total uncertainties on measured s...
Definition: TSVDUnfold.cxx:602
static void V2H(const TVectorD &vec, TH1D &histo)
Fill vector into 1D histogram.
Definition: TSVDUnfold.cxx:642
static void H2M(const TH2D *histo, TMatrixD &mat)
Fill 2D histogram into matrix.
Definition: TSVDUnfold.cxx:650
TH2D * GetAdetCovMatrix(Int_t ntoys, Int_t seed=1)
Determine covariance matrix of unfolded spectrum from finite statistics in response matrix using pseu...
Definition: TSVDUnfold.cxx:517
Int_t fNdim
Definition: TSVDUnfold.h:135
static TVectorD VecDiv(const TVectorD &vec1, const TVectorD &vec2, Int_t zero=0)
Divide entries of two vectors.
Definition: TSVDUnfold.cxx:674
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:613
static TVectorD CompProd(const TVectorD &vec1, const TVectorD &vec2)
Multiply entries of two vectors.
Definition: TSVDUnfold.cxx:708
Int_t GetKReg() const
Definition: TSVDUnfold.h:94
const TH1D * fBini
Definition: TSVDUnfold.h:147
double Double_t
Definition: RtypesCore.h:55
TH1D * fDHist
Regularisation parameter.
Definition: TSVDUnfold.h:139
void InitHistos()
Definition: TSVDUnfold.cxx:813
Mother of all ROOT objects.
Definition: TObject.h:58
TH1D * fToyhisto
Definition: TSVDUnfold.h:152
static void M2H(const TMatrixD &mat, TH2D &histo)
Fill 2D histogram into matrix.
Definition: TSVDUnfold.cxx:662
void FillCurvatureMatrix(TMatrixD &tCurv, TMatrixD &tC) const
Definition: TSVDUnfold.cxx:725
virtual ~TSVDUnfold()
Destructor.
Definition: TSVDUnfold.cxx:202
const TH2D * fAdet
Definition: TSVDUnfold.h:149
2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:297