Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TUnfoldSys.h
Go to the documentation of this file.
1 // Author: Stefan Schmitt
2 // DESY, 23/01/09
3 
4 // Version 17.5, bug fixes in TUnfold fix problem with GetEmatrixSysUncorr
5 //
6 // History:
7 // Version 17.4, in parallel to changes in TUnfoldBinning
8 // Version 17.3, in parallel to changes in TUnfoldBinning
9 // Version 17.2, add methods to find back systematic and background sources
10 // Version 17.1, bug fix with background uncertainty
11 // Version 17.0, possibility to specify an error matrix with SetInput
12 // Version 16.2, bug-fix with the calculation of background errors
13 // Version 16.1, parallel to changes in TUnfold
14 // Version 16.0, parallel to changes in TUnfold
15 // Version 15, fix bugs with uncorr. uncertainties, add backgnd subtraction
16 // Version 14, with changes in TUnfoldSys.cxx
17 // Version 13, support for systematic errors
18 
19 #ifndef ROOT_TUnfoldSys
20 #define ROOT_TUnfoldSys
21 
22 //////////////////////////////////////////////////////////////////////////
23 // //
24 // //
25 // TUnfoldSys, an extension of the class TUnfold to correct for //
26 // migration effects. It provides methods for background subtraction //
27 // and propagation of systematic uncertainties //
28 // //
29 // Citation: S.Schmitt, JINST 7 (2012) T10003 [arXiv:1205.6201] //
30 // //
31 //////////////////////////////////////////////////////////////////////////
32 
33 /*
34  This file is part of TUnfold.
35 
36  TUnfold is free software: you can redistribute it and/or modify
37  it under the terms of the GNU General Public License as published by
38  the Free Software Foundation, either version 3 of the License, or
39  (at your option) any later version.
40 
41  TUnfold is distributed in the hope that it will be useful,
42  but WITHOUT ANY WARRANTY; without even the implied warranty of
43  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44  GNU General Public License for more details.
45 
46  You should have received a copy of the GNU General Public License
47  along with TUnfold. If not, see <http://www.gnu.org/licenses/>.
48 */
49 
50 #include <TMap.h>
51 #include <TSortedList.h>
52 #include "TUnfold.h"
53 
54 
55 class TUnfoldSys : public TUnfold {
56  private:
57  void InitTUnfoldSys(void); // initialize all data members
58  protected:
59  /// Input: normalized errors from input matrix
60  TMatrixDSparse *fDAinRelSq;
61  /// Input: normalized column err.sq. (inp.matr.)
62  TMatrixD* fDAinColRelSq;
63  /// Input: underflow/overflow bins
64  TMatrixD* fAoutside;
65  /// Input: correlated errors
66  TMap *fSysIn;
67  /// Input: size of background sources
68  TMap *fBgrIn;
69  /// Input: uncorr error squared from bgr sources
70  TMap *fBgrErrUncorrInSq;
71  /// Input: background sources correlated error
72  TMap *fBgrErrScaleIn;
73  /// Input: error on tau
74  Double_t fDtau;
75  /// Input: fY prior to bgr subtraction
76  TMatrixD *fYData;
77  /// Input: error on fY prior to bgr subtraction
78  TMatrixDSparse *fVyyData;
79  /// Result: syst.error from fDA2 on fX
80  TMatrixDSparse *fEmatUncorrX;
81  /// Result: syst.error from fDA2 on fAx
82  TMatrixDSparse *fEmatUncorrAx;
83  /// Result: syst.shift from fSysIn on fX
84  TMap *fDeltaCorrX;
85  /// Result: syst.shift from fSysIn on fAx
86  TMap *fDeltaCorrAx;
87  /// Result: systematic shift from tau
88  TMatrixDSparse *fDeltaSysTau;
89  protected:
90  virtual void ClearResults(void); // clear all results
91  virtual void PrepareSysError(void); // common calculations for syst.errors
92  virtual TMatrixDSparse *PrepareUncorrEmat(const TMatrixDSparse *m1,const TMatrixDSparse *m2); // calculate uncorrelated error matrix
93  virtual TMatrixDSparse *PrepareCorrEmat(const TMatrixDSparse *m1,const TMatrixDSparse *m2,const TMatrixDSparse *dsys); // calculate correlated error matrix
94  void ScaleColumnsByVector(TMatrixDSparse *m,const TMatrixTBase<Double_t> *v) const; // scale columns of m by the corresponding rows of v
95  void VectorMapToHist(TH1 *hist_delta,const TMatrixDSparse *delta,const Int_t *binMap); // map and sum vector delta, save in hist_delta
96  void GetEmatrixFromVyy(const TMatrixDSparse *vyy,TH2 *ematrix,const Int_t *binMap,Bool_t clearEmat); // propagate error matrix vyy to the result
97  void DoBackgroundSubtraction(void);
98  TMatrixDSparse *GetSummedErrorMatrixYY(void);
99  TMatrixDSparse *GetSummedErrorMatrixXX(void);
100  public:
101  /// type of matrix specified with AddSysError()
102  enum ESysErrMode {
103  /// matrix is an alternative to the default matrix, the errors are the difference to the original matrix
104  kSysErrModeMatrix=0,
105  /// matrix gives the absolute shifts
106  kSysErrModeShift=1,
107  /// matrix gives the relative shifts
108  kSysErrModeRelative=2
109  };
110  TUnfoldSys(const TH2 *hist_A, EHistMap histmap, ERegMode regmode = kRegModeSize,
111  EConstraint constraint=kEConstraintArea); // constructor
112  TUnfoldSys(void); // for derived classes
113  virtual ~ TUnfoldSys(void); // delete data members
114  void AddSysError(const TH2 *sysError,const char *name, EHistMap histmap,
115  ESysErrMode mode); // add a systematic error source
116  void SubtractBackground(const TH1 *hist_bgr,const char *name,
117  Double_t scale=1.0,
118  Double_t scale_error=0.0); // subtract background prior to unfolding
119  virtual Int_t SetInput(const TH1 *hist_y,Double_t scaleBias=0.0,Double_t oneOverZeroError=0.0,const TH2 *hist_vyy=0,const TH2 *hist_vyy_inv=0); // define input consistently in case of background subtraction
120  void SetTauError(Double_t delta_tau); // set uncertainty on tau
121  TSortedList *GetBgrSources(void) const; // get names of background sources
122  TSortedList *GetSysSources(void) const; // get names of systematic sources
123  void GetBackground(TH1 *bgr,const char *bgrSource=0,const Int_t *binMap=0,Int_t includeError=3,Bool_t clearHist=kTRUE) const; // get background as histogram
124  void GetEmatrixSysBackgroundUncorr(TH2 *ematrix,const char *source,
125  const Int_t *binMap=0,Bool_t clearEmat=kTRUE); // get error matrix from uncorrelated error of one background source
126  void GetEmatrixSysBackgroundScale(TH2 *ematrix,const char *source,
127  const Int_t *binMap=0,Bool_t clearEmat=kTRUE); // get error matrix from the scale error of one background source
128  Bool_t GetDeltaSysBackgroundScale(TH1 *delta,const char *source,
129  const Int_t *binMap=0); // get correlated uncertainty induced by the scale uncertainty of a background source
130  void GetEmatrixSysUncorr(TH2 *ematrix,const Int_t *binMap=0,Bool_t clearEmat=kTRUE); // get error matrix contribution from uncorrelated errors on the matrix A
131  void GetEmatrixSysSource(TH2 *ematrix,const char *source,
132  const Int_t *binMap=0,Bool_t clearEmat=kTRUE); // get error matrix from one systematic source
133  Bool_t GetDeltaSysSource(TH1 *hist_delta,const char *source,
134  const Int_t *binMap=0); // get systematic shifts from one systematic source
135  void GetEmatrixSysTau(TH2 *ematrix,
136  const Int_t *binMap=0,Bool_t clearEmat=kTRUE); // get error matrix from tau variation
137  Bool_t GetDeltaSysTau(TH1 *delta,const Int_t *binMap=0); // get correlated uncertainty from varying tau
138  void GetEmatrixInput(TH2 *ematrix,const Int_t *binMap=0,Bool_t clearEmat=kTRUE); // get error contribution from input vector
139  void GetEmatrixTotal(TH2 *ematrix,const Int_t *binMap=0); // get total error including systematic,statistical,background,tau errors
140  void GetRhoItotal(TH1 *rhoi,const Int_t *binMap=0,TH2 *invEmat=0); // get global correlation coefficients including systematic,statistical,background,tau errors
141  Double_t GetChi2Sys(void); // get total chi**2 including all systematic errors
142  ClassDef(TUnfoldSys, TUnfold_CLASS_VERSION) //Unfolding with support for systematic error propagation
143 };
144 
145 #endif