Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:28

0001 // Author: Kerstin Tackmann, Andreas Hoecker, Heiko Lacker
0002 
0003 /**********************************************************************************
0004  *                                                                                *
0005  * Project: TSVDUnfold - data unfolding based on Singular Value Decomposition     *
0006  * Package: ROOT                                                                  *
0007  * Class  : TSVDUnfold                                                            *
0008  *                                                                                *
0009  * Description:                                                                   *
0010  *      Single class implementation of SVD data unfolding based on:               *
0011  *          A. Hoecker, V. Kartvelishvili,                                        *
0012  *          "SVD approach to data unfolding"                                      *
0013  *          NIM A372, 469 (1996) [hep-ph/9509307]                                 *
0014  *                                                                                *
0015  * Authors:                                                                       *
0016  *      Kerstin Tackmann <Kerstin.Tackmann@cern.ch>   - CERN, Switzerland         *
0017  *      Andreas Hoecker  <Andreas.Hoecker@cern.ch>    - CERN, Switzerland         *
0018  *      Heiko Lacker     <lacker@physik.hu-berlin.de> - Humboldt U, Germany       *
0019  *                                                                                *
0020  * Copyright (c) 2010:                                                            *
0021  *      CERN, Switzerland                                                         *
0022  *      Humboldt University, Germany                                              *
0023  *                                                                                *
0024  **********************************************************************************/
0025 
0026 //////////////////////////////////////////////////////////////////////////
0027 //                                                                      //
0028 // TSVDUnfold                                                           //
0029 //                                                                      //
0030 // Data unfolding using Singular Value Decomposition (hep-ph/9509307)   //
0031 // Authors: Kerstin Tackmann, Andreas Hoecker, Heiko Lacker             //
0032 //                                                                      //
0033 //////////////////////////////////////////////////////////////////////////
0034 
0035 #ifndef TSVDUNFOLD_H
0036 #define TSVDUNFOLD_H
0037 
0038 #include "TObject.h"
0039 #include "TMatrixD.h"
0040 #include "TVectorD.h"
0041 #include "TMatrixDSym.h"
0042 
0043 class TH1D;
0044 class TH2D;
0045 
0046 class TSVDUnfold : public TObject {
0047 
0048 public:
0049 
0050    // Constructor
0051    // Initialisation of unfolding
0052    // "bdat" - measured data distribution (number of events)
0053    // "Bcov" - covariance matrix for measured data distribution
0054    // "bini" - reconstructed MC distribution (number of events)
0055    // "xini" - truth MC distribution (number of events)
0056    // "Adet" - detector response matrix (number of events)
0057    TSVDUnfold( const TH1D* bdat, const TH1D* bini, const TH1D* xini, const TH2D* Adet );
0058    TSVDUnfold( const TH1D* bdat, TH2D* Bcov, const TH1D* bini, const TH1D* xini, const TH2D* Adet );
0059    TSVDUnfold( const TSVDUnfold& other );
0060 
0061    // Destructor
0062    ~TSVDUnfold() override;
0063 
0064    // Set option to normalize unfolded spectrum to unit area
0065    // "normalize" - switch
0066    void     SetNormalize ( Bool_t normalize ) { fNormalize = normalize; }
0067 
0068    // Do the unfolding
0069    // "kreg"   - number of singular values used (regularisation)
0070    TH1D*    Unfold       ( Int_t kreg );
0071 
0072    // Determine for given input error matrix covariance matrix of unfolded
0073    // spectrum from toy simulation
0074    // "cov"    - covariance matrix on the measured spectrum, to be propagated
0075    // "ntoys"  - number of pseudo experiments used for the propagation
0076    // "seed"   - seed for pseudo experiments
0077    TH2D*    GetUnfoldCovMatrix( const TH2D* cov, Int_t ntoys, Int_t seed = 1 );
0078 
0079    // Determine covariance matrix of unfolded spectrum from finite statistics in
0080    // response matrix
0081    // "ntoys"  - number of pseudo experiments used for the propagation
0082    // "seed"   - seed for pseudo experiments
0083    TH2D*    GetAdetCovMatrix( Int_t ntoys, Int_t seed=1 );
0084 
0085    // Regularisation parameter
0086    Int_t    GetKReg() const { return fKReg; }
0087 
0088    // Obtain the distribution of |d| (for determining the regularization)
0089    TH1D*    GetD() const;
0090 
0091    // Obtain the distribution of singular values
0092    TH1D*    GetSV() const;
0093 
0094    // Obtain the computed regularized covariance matrix
0095    TH2D*    GetXtau() const;
0096 
0097    // Obtain the computed inverse of the covariance matrix
0098    TH2D*    GetXinv() const;
0099 
0100    //Obtain the covariance matrix on the data
0101    TH2D*    GetBCov() const;
0102 
0103    // Helper functions
0104    Double_t ComputeChiSquared( const TH1D& truspec, const TH1D& unfspec );
0105 
0106 private:
0107 
0108    // Helper functions for vector and matrix operations
0109    void            FillCurvatureMatrix( TMatrixD& tCurv, TMatrixD& tC ) const;
0110    static Double_t GetCurvature       ( const TVectorD& vec, const TMatrixD& curv );
0111 
0112    void            InitHistos  ( );
0113 
0114    // Helper functions
0115    static void     H2V      ( const TH1D* histo, TVectorD& vec   );
0116    static void     H2Verr   ( const TH1D* histo, TVectorD& vec   );
0117    static void     V2H      ( const TVectorD& vec, TH1D& histo   );
0118    static void     H2M      ( const TH2D* histo, TMatrixD& mat   );
0119    static void     M2H      ( const TMatrixD& mat, TH2D& histo   );
0120    static TMatrixD MatDivVec( const TMatrixD& mat, const TVectorD& vec, Int_t zero=0 );
0121    static TVectorD CompProd ( const TVectorD& vec1, const TVectorD& vec2 );
0122 
0123    static TVectorD VecDiv                 ( const TVectorD& vec1, const TVectorD& vec2, Int_t zero = 0 );
0124    static void     RegularisedSymMatInvert( TMatrixDSym& mat, Double_t eps = 1e-3 );
0125 
0126    /// @name Class members
0127    ///@{
0128    Int_t       fNdim;        ///<! Truth and reconstructed dimensions
0129    Int_t       fDdim;        ///<! Derivative for curvature matrix
0130    Bool_t      fNormalize;   ///<! Normalize unfolded spectrum to 1
0131    Int_t       fKReg;        ///<! Regularisation parameter
0132    TH1D*       fDHist;       ///<! Distribution of d (for checking regularization)
0133    TH1D*       fSVHist;      ///<! Distribution of singular values
0134    TH2D*       fXtau;        ///<! Computed regularized covariance matrix
0135    TH2D*       fXinv;        ///<! Computed inverse of covariance matrix
0136    ///@}
0137 
0138    /// @name Input histos
0139    ///@{
0140    const TH1D* fBdat;        ///< Measured distribution (data)
0141    TH2D* fBcov;              ///< Covariance matrix of measured distribution (data)
0142    const TH1D* fBini;        ///< Reconstructed distribution (MC)
0143    const TH1D* fXini;        ///< Truth distribution (MC)
0144    const TH2D* fAdet;        ///< Detector response matrix
0145    ///@}
0146 
0147    /// @name Evaluation of covariance matrices
0148    ///@{
0149    TH1D*       fToyhisto;    ///<! Toy MC histogram
0150    TH2D*       fToymat;      ///<! Toy MC detector response matrix
0151    Bool_t      fToyMode;     ///<! Internal switch for covariance matrix propagation
0152    Bool_t      fMatToyMode;  ///<! Internal switch for evaluation of statistical uncertainties from response matrix
0153    ///@}
0154 
0155 
0156    ClassDefOverride( TSVDUnfold, 0 ) // Data unfolding using Singular Value Decomposition (hep-ph/9509307)
0157 };
0158 
0159 #endif