Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from kreczko/tau-svd-unfolding
Browse files Browse the repository at this point in the history
Tau svd unfolding
  • Loading branch information
kreczko committed Mar 5, 2015
2 parents 5e00dbe + 35f41bd commit 093d5fd
Show file tree
Hide file tree
Showing 25 changed files with 2,374 additions and 47 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ Makefile
*~
*Dict.cxx
*Dict_rdict.pcm
Test*
Test/*
/Test/
*.pyc
4 changes: 2 additions & 2 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ echo "Checking PyROOT installation"
time python -c 'import ROOT; ROOT.TBrowser()'

# Check that RooUnfold can be imported
echo "Checking RooUnfold library"
echo "Checking RooUnfold library in PyROOT"
time python -c 'from ROOT import gSystem; gSystem.Load("libRooUnfold.so");from ROOT import RooUnfoldResponse'

time python test/test_pyroot.py
echo "Executing unit tests"
make test
2 changes: 1 addition & 1 deletion examples/RooUnfoldDagostini.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef ROOUNFOLDDAGOSTINI_H_
#define ROOUNFOLDDAGOSTINI_H_

#include "RooUnfold.h"
#include "../include/RooUnfold.h"

class RooUnfoldResponse;
class TH1;
Expand Down
4 changes: 2 additions & 2 deletions examples/RooUnfoldExample.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ using std::endl;
#include "TRandom.h"
#include "TH1D.h"

#include "RooUnfoldResponse.h"
#include "RooUnfoldBayes.h"
#include "../include/RooUnfoldResponse.h"
#include "../include/RooUnfoldBayes.h"
//#include "RooUnfoldSvd.h"
//#include "RooUnfoldTUnfold.h"
#endif
Expand Down
2 changes: 1 addition & 1 deletion examples/RooUnfoldTestHarness.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#if !defined(__CINT__) || defined(__MAKECINT__)
#include "TNamed.h"
#include "TString.h"
#include "RooUnfold.h"
#include "../include/RooUnfold.h"
#if ROOT_VERSION_CODE >= ROOT_VERSION(5,0,0)
#include "TVectorDfwd.h"
#include "TMatrixDfwd.h"
Expand Down
10 changes: 5 additions & 5 deletions examples/RooUnfoldTestHarness.icc
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
#include "TLine.h"
#include "TNtuple.h"
#include "TProfile.h"
#include "RooUnfoldErrors.h"
#include "RooUnfoldParms.h"
#include "RooUnfoldResponse.h"
#include "RooUnfold.h"
#include "RooUnfoldSvd.h"
#include "../include/RooUnfoldErrors.h"
#include "../include/RooUnfoldParms.h"
#include "../include/RooUnfoldResponse.h"
#include "../include/RooUnfold.h"
#include "../include/RooUnfoldSvd.h"
#ifdef USE_TUNFOLD_H
#include "RooUnfoldTUnfold.h"
#endif
Expand Down
2 changes: 1 addition & 1 deletion examples/RooUnfoldTestHarness2D.icc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "TVectorD.h"
#include "TLine.h"

#include "RooUnfoldResponse.h"
#include "../include/RooUnfoldResponse.h"
#endif

#include "ArgVars.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/RooUnfoldTestHarness3D.icc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "TVectorD.h"
#include "TLine.h"

#include "RooUnfoldResponse.h"
#include "../include/RooUnfoldResponse.h"
#endif

#include "ArgVars.h"
Expand Down
17 changes: 13 additions & 4 deletions include/RooUnfoldSvd.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RooUnfoldResponse;
class TH1;
class TH1D;
class TH2D;
class TSVDUnfold;
class TSVDUnfold_local;

class RooUnfoldSvd : public RooUnfold {

Expand All @@ -38,16 +38,20 @@ class RooUnfoldSvd : public RooUnfold {

RooUnfoldSvd (const RooUnfoldResponse* res, const TH1* meas, Int_t kreg= 0, Int_t ntoyssvd= 1000,
const char* name= 0, const char* title= 0);
RooUnfoldSvd (const RooUnfoldResponse* res, const TH1* meas, double taureg, Int_t ntoyssvd= 1000,
const char* name= 0, const char* title= 0);

void SetKterm (Int_t kreg);
void SetTauTerm (double taureg);
void SetNtoysSVD (Int_t ntoyssvd);
Int_t GetKterm() const;
double GetTauTerm() const;
Int_t GetNtoysSVD() const;

virtual void SetRegParm (Double_t parm);
virtual Double_t GetRegParm() const;
virtual void Reset();
TSVDUnfold* Impl();
TSVDUnfold_local* Impl();

protected:
void Assign (const RooUnfoldSvd& rhs); // implementation of assignment operator
Expand All @@ -62,8 +66,10 @@ class RooUnfoldSvd : public RooUnfold {

protected:
// instance variables
TSVDUnfold* _svd; //! Implementation in TSVDUnfold object (no streamer)
TSVDUnfold_local* _svd; //! Implementation in TSVDUnfold object (no streamer)
Int_t _kreg;
double _taureg;
bool _use_tau_unfolding;
Int_t _nb;
Int_t _ntoyssvd;

Expand Down Expand Up @@ -155,7 +161,10 @@ inline
Double_t RooUnfoldSvd::GetRegParm() const
{
// Return regularisation parameter
return GetKterm();
if (_use_tau_unfolding)
return _taureg;
else
return _kreg;
}

#endif
24 changes: 24 additions & 0 deletions include/RooUnfoldUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* RooUnfoldUtils.h
*
* Created on: 24 Feb 2015
* Author: kreczko
*/

#ifndef INCLUDE_ROOUNFOLDUTILS_H
#define INCLUDE_ROOUNFOLDUTILS_H

#include "TVectorD.h"
namespace RooUnfoldUtils {

/**
* Calculates equidistant points on a logarithmic scale
*
* parameters:
* - tau_min: minimal tau value (> 0)
* - tau_max: maximal tau value
* - n_points: number of points (> 3)
*/
TVectorD* calculate_tau_scan_points(double tau_min, double tau_max, unsigned int n_points);
}
#endif /* INCLUDE_ROOUNFOLDUTILS_H */
3 changes: 3 additions & 0 deletions include/RooUnfold_LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#pragma link C++ class RooUnfoldParms+;
#pragma link C++ class RooUnfoldInvert+;
#pragma link C++ class RooUnfoldTUnfold+;
#pragma link C++ class TauSVDUnfold+;
#pragma link C++ class TSVDUnfold_local+;
#pragma link C++ class RooUnfoldUtils+;
//#pragma link C++ class RooUnfoldDagostini+;

#endif
162 changes: 162 additions & 0 deletions include/TSVDUnfold_local.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Author: Kerstin Tackmann, Andreas Hoecker, Heiko Lacker

/**********************************************************************************
* *
* Project: TSVDUnfold_local - data unfolding based on Singular Value Decomposition *
* Package: ROOT *
* Class : TSVDUnfold_local *
* *
* Description: *
* Single class implementation of SVD data unfolding based on: *
* A. Hoecker, V. Kartvelishvili, *
* "SVD approach to data unfolding" *
* NIM A372, 469 (1996) [hep-ph/9509307] *
* *
* Authors: *
* Kerstin Tackmann <[email protected]> - CERN, Switzerland *
* Andreas Hoecker <[email protected]> - CERN, Switzerland *
* Heiko Lacker <[email protected]> - Humboldt U, Germany *
* *
* Copyright (c) 2010: *
* CERN, Switzerland *
* Humboldt University, Germany *
* *
**********************************************************************************/

//////////////////////////////////////////////////////////////////////////
// //
// TSVDUnfold_local //
// //
// Data unfolding using Singular Value Decomposition (hep-ph/9509307) //
// Authors: Kerstin Tackmann, Andreas Hoecker, Heiko Lacker //
// //
//////////////////////////////////////////////////////////////////////////

#ifndef TSVDUNFOLD_LOCAL_H
#define TSVDUNFOLD_LOCAL_H

#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TMatrixD
#include "TMatrixD.h"
#endif
#ifndef ROOT_TVectorD
#include "TVectorD.h"
#endif
#ifndef ROOT_TMatrixDSym
#include "TMatrixDSym.h"
#endif

class TH1D;
class TH2D;

class TSVDUnfold_local : public TObject {

public:

// Constructor
// Initialisation of unfolding
// "bdat" - measured data distribution (number of events)
// "Bcov" - covariance matrix for measured data distribution
// "bini" - reconstructed MC distribution (number of events)
// "xini" - truth MC distribution (number of events)
// "Adet" - detector response matrix (number of events)
TSVDUnfold_local( const TH1D* bdat, const TH1D* bini, const TH1D* xini, const TH2D* Adet );
TSVDUnfold_local( const TH1D* bdat, TH2D* Bcov, const TH1D* bini, const TH1D* xini, const TH2D* Adet );
TSVDUnfold_local( const TSVDUnfold_local& other );

// Destructor
virtual ~TSVDUnfold_local();

// Set option to normalize unfolded spectrum to unit area
// "normalize" - switch
void SetNormalize ( Bool_t normalize ) { fNormalize = normalize; }

// Do the unfolding
// "kreg" - number of singular values used (regularisation)
TH1D* Unfold ( Int_t kreg );

// Determine for given input error matrix covariance matrix of unfolded
// spectrum from toy simulation
// "cov" - covariance matrix on the measured spectrum, to be propagated
// "ntoys" - number of pseudo experiments used for the propagation
// "seed" - seed for pseudo experiments
virtual TH2D* GetUnfoldCovMatrix( const TH2D* cov, Int_t ntoys, Int_t seed = 1 );

// Determine covariance matrix of unfolded spectrum from finite statistics in
// response matrix
// "ntoys" - number of pseudo experiments used for the propagation
// "seed" - seed for pseudo experiments
virtual TH2D* GetAdetCovMatrix( Int_t ntoys, Int_t seed=1 );

// Regularisation parameter
Int_t GetKReg() const { return fKReg; }

// Obtain the distribution of |d| (for determining the regularization)
TH1D* GetD() const;

// Obtain the distribution of singular values
TH1D* GetSV() const;

// Obtain the computed regularized covariance matrix
TH2D* GetXtau() const;

// Obtain the computed inverse of the covariance matrix
TH2D* GetXinv() const;

//Obtain the covariance matrix on the data
TH2D* GetBCov() const;

// Helper functions
Double_t ComputeChiSquared( const TH1D& truspec, const TH1D& unfspec );

// only difference to TSVDUnfold in ROOT
protected:

// Helper functions for vector and matrix operations
void FillCurvatureMatrix( TMatrixD& tCurv, TMatrixD& tC ) const;
static Double_t GetCurvature ( const TVectorD& vec, const TMatrixD& curv );

void InitHistos ( );

// Helper functions
static void H2V ( const TH1D* histo, TVectorD& vec );
static void H2Verr ( const TH1D* histo, TVectorD& vec );
static void V2H ( const TVectorD& vec, TH1D& histo );
static void H2M ( const TH2D* histo, TMatrixD& mat );
static void M2H ( const TMatrixD& mat, TH2D& histo );
static TMatrixD MatDivVec( const TMatrixD& mat, const TVectorD& vec, Int_t zero=0 );
static TVectorD CompProd ( const TVectorD& vec1, const TVectorD& vec2 );

static TVectorD VecDiv ( const TVectorD& vec1, const TVectorD& vec2, Int_t zero = 0 );
static void RegularisedSymMatInvert( TMatrixDSym& mat, Double_t eps = 1e-3 );

// Class members
Int_t fNdim; //! Truth and reconstructed dimensions
Int_t fDdim; //! Derivative for curvature matrix
Bool_t fNormalize; //! Normalize unfolded spectrum to 1
Int_t fKReg; //! Regularisation parameter
TH1D* fDHist; //! Distribution of d (for checking regularization)
TH1D* fSVHist; //! Distribution of singular values
TH2D* fXtau; //! Computed regularized covariance matrix
TH2D* fXinv; //! Computed inverse of covariance matrix

// Input histos
const TH1D* fBdat; // measured distribution (data)
TH2D* fBcov; // covariance matrix of measured distribution (data)
const TH1D* fBini; // reconstructed distribution (MC)
const TH1D* fXini; // truth distribution (MC)
const TH2D* fAdet; // Detector response matrix

// Evaluation of covariance matrices
TH1D* fToyhisto; //! Toy MC histogram
TH2D* fToymat; //! Toy MC detector response matrix
Bool_t fToyMode; //! Internal switch for covariance matrix propagation
Bool_t fMatToyMode; //! Internal switch for evaluation of statistical uncertainties from response matrix


ClassDef( TSVDUnfold_local, 0 ) // Data unfolding using Singular Value Decomposition (hep-ph/9509307)
};

#endif
Loading

0 comments on commit 093d5fd

Please sign in to comment.