TSpectrum2Fit.h

Go to the documentation of this file.
00001 // @(#)root/spectrum:$Id: TSpectrum2Fit.h 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Miroslav Morhac   25/09/06
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 #ifndef ROOT_TSpectrum2Fit
00012 #define ROOT_TSpectrum2Fit
00013 
00014 //////////////////////////////////////////////////////////////////////////
00015 //                                                                      //
00016 // TSpectrum2Fit                                                        //
00017 //                                                                      //
00018 // Class for fitting 2D spectra using AWMI (algorithm without matrix    //
00019 // inversion) and conjugate gradient algorithms for symmetrical         //
00020 // matrices (Stiefel-Hestens method). AWMI method allows to fit         //
00021 // simulaneously 100s up to 1000s peaks. Stiefel method is very stable, //
00022 // it converges faster, but is more time consuming                      //
00023 //                                                                      //
00024 //////////////////////////////////////////////////////////////////////////
00025 
00026 #ifndef ROOT_TNamed
00027 #include "TNamed.h"
00028 #endif
00029 
00030 class TSpectrum2Fit : public TNamed {
00031 protected:
00032    Int_t     fNPeaks;                        //number of peaks present in fit, input parameter, it should be > 0
00033    Int_t     fNumberIterations;              //number of iterations in fitting procedure, input parameter, it should be > 0
00034    Int_t     fXmin;                          //first fitted channel in x direction
00035    Int_t     fXmax;                          //last fitted channel in x direction
00036    Int_t     fYmin;                          //first fitted channel in y direction
00037    Int_t     fYmax;                          //last fitted channel in y direction
00038    Int_t     fStatisticType;                 //type of statistics, possible values kFitOptimChiCounts (chi square statistics with counts as weighting coefficients), kFitOptimChiFuncValues (chi square statistics with function values as weighting coefficients),kFitOptimMaxLikelihood
00039    Int_t     fAlphaOptim;                    //optimization of convergence algorithm, possible values kFitAlphaHalving, kFitAlphaOptimal
00040    Int_t     fPower;                         //possible values kFitPower2,4,6,8,10,12, for details see references. It applies only for Awmi fitting function.
00041    Int_t     fFitTaylor;                     //order of Taylor expansion, possible values kFitTaylorOrderFirst, kFitTaylorOrderSecond. It applies only for Awmi fitting function.
00042    Double_t  fAlpha;                         //convergence coefficient, input parameter, it should be positive number and <=1, for details see references
00043    Double_t  fChi;                           //here the fitting functions return resulting chi square   
00044    Double_t *fPositionInitX;                 //[fNPeaks] array of initial values of x positions of 2D peaks, input parameters
00045    Double_t *fPositionCalcX;                 //[fNPeaks] array of calculated values of x positions of 2D peaks, output parameters
00046    Double_t *fPositionErrX;                  //[fNPeaks] array of error values of x positions of 2D peaks, output parameters
00047    Double_t *fPositionInitY;                 //[fNPeaks] array of initial values of y positions of 2D peaks, input parameters
00048    Double_t *fPositionCalcY;                 //[fNPeaks] array of calculated values of y positions of 2D peaks, output parameters
00049    Double_t *fPositionErrY;                  //[fNPeaks] array of error values of y positions of 2D peaks, output parameters
00050    Double_t *fPositionInitX1;                //[fNPeaks] array of initial x positions of 1D ridges, input parameters
00051    Double_t *fPositionCalcX1;                //[fNPeaks] array of calculated x positions of 1D ridges, output parameters
00052    Double_t *fPositionErrX1;                 //[fNPeaks] array of x positions errors of 1D ridges, output parameters
00053    Double_t *fPositionInitY1;                //[fNPeaks] array of initial y positions of 1D ridges, input parameters
00054    Double_t *fPositionCalcY1;                //[fNPeaks] array of calculated y positions of 1D ridges, output parameters
00055    Double_t *fPositionErrY1;                 //[fNPeaks] array of y positions errors of 1D ridges, output parameters
00056    Double_t *fAmpInit;                       //[fNPeaks] array of initial values of amplitudes of 2D peaks, input parameters
00057    Double_t *fAmpCalc;                       //[fNPeaks] array of calculated values of amplitudes of 2D peaks, output parameters
00058    Double_t *fAmpErr;                        //[fNPeaks] array of amplitudes errors of 2D peaks, output parameters
00059    Double_t *fAmpInitX1;                     //[fNPeaks] array of initial values of amplitudes of 1D ridges in x direction, input parameters
00060    Double_t *fAmpCalcX1;                     //[fNPeaks] array of calculated values of amplitudes of 1D ridges in x direction, output parameters
00061    Double_t *fAmpErrX1;                      //[fNPeaks] array of amplitudes errors of 1D ridges in x direction, output parameters
00062    Double_t *fAmpInitY1;                     //[fNPeaks] array of initial values of amplitudes of 1D ridges in y direction, input parameters
00063    Double_t *fAmpCalcY1;                     //[fNPeaks] array of calculated values of amplitudes of 1D ridges in y direction, output parameters
00064    Double_t *fAmpErrY1;                      //[fNPeaks] array of amplitudes errors of 1D ridges in y direction, output parameters
00065    Double_t *fVolume;                        //[fNPeaks] array of calculated volumes of 2D peaks, output parameters
00066    Double_t *fVolumeErr;                     //[fNPeaks] array of volumes errors of 2D peaks, output parameters
00067    Double_t  fSigmaInitX;                    //initial value of sigma x parameter
00068    Double_t  fSigmaCalcX;                    //calculated value of sigma x parameter
00069    Double_t  fSigmaErrX;                     //error value of sigma x parameter
00070    Double_t  fSigmaInitY;                    //initial value of sigma y parameter
00071    Double_t  fSigmaCalcY;                    //calculated value of sigma y parameter
00072    Double_t  fSigmaErrY;                     //error value of sigma y parameter
00073    Double_t  fRoInit;                        //initial value of correlation coefficient
00074    Double_t  fRoCalc;                        //calculated value of correlation coefficient
00075    Double_t  fRoErr;                         //error value of correlation coefficient
00076    Double_t  fTxyInit;                       //initial value of t parameter for 2D peaks (relative amplitude of tail), for details see html manual and references
00077    Double_t  fTxyCalc;                       //calculated value of t parameter for 2D peaks
00078    Double_t  fTxyErr;                        //error value of t parameter for 2D peaks
00079    Double_t  fSxyInit;                       //initial value of s parameter for 2D peaks (relative amplitude of step), for details see html manual and references
00080    Double_t  fSxyCalc;                       //calculated value of s parameter for 2D peaks
00081    Double_t  fSxyErr;                        //error value of s parameter for 2D peaks
00082    Double_t  fTxInit;                        //initial value of t parameter for 1D ridges in x direction (relative amplitude of tail), for details see html manual and references
00083    Double_t  fTxCalc;                        //calculated value of t parameter for 1D ridges in x direction
00084    Double_t  fTxErr;                         //error value of t parameter for 1D ridges in x direction
00085    Double_t  fTyInit;                        //initial value of t parameter for 1D ridges in y direction (relative amplitude of tail), for details see html manual and references
00086    Double_t  fTyCalc;                        //calculated value of t parameter for 1D ridges in y direction
00087    Double_t  fTyErr;                         //error value of t parameter for 1D ridges in y direction
00088    Double_t  fSxInit;                        //initial value of s parameter for 1D ridges in x direction (relative amplitude of step), for details see html manual and references
00089    Double_t  fSxCalc;                        //calculated value of s parameter for 1D ridges in x direction
00090    Double_t  fSxErr;                         //error value of s parameter for 1D ridges in x direction
00091    Double_t  fSyInit;                        //initial value of s parameter for 1D ridges in y direction (relative amplitude of step), for details see html manual and references
00092    Double_t  fSyCalc;                        //calculated value of s parameter for 1D ridges in y direction
00093    Double_t  fSyErr;                         //error value of s parameter for 1D ridges in y direction
00094    Double_t  fBxInit;                        //initial value of b parameter for 1D ridges in x direction (slope), for details see html manual and references
00095    Double_t  fBxCalc;                        //calculated value of b parameter for 1D ridges in x direction
00096    Double_t  fBxErr;                         //error value of b parameter for 1D ridges in x direction
00097    Double_t  fByInit;                        //initial value of b parameter for 1D ridges in y direction (slope), for details see html manual and references
00098    Double_t  fByCalc;                        //calculated value of b parameter for 1D ridges in y direction
00099    Double_t  fByErr;                         //error value of b parameter for 1D ridges in y direction
00100    Double_t  fA0Init;                        //initial value of background a0 parameter(backgroud is estimated as a0+ax*x+ay*y)
00101    Double_t  fA0Calc;                        //calculated value of background a0 parameter
00102    Double_t  fA0Err;                         //error value of background a0 parameter
00103    Double_t  fAxInit;                        //initial value of background ax parameter(backgroud is estimated as a0+ax*x+ay*y)
00104    Double_t  fAxCalc;                        //calculated value of background ax parameter
00105    Double_t  fAxErr;                         //error value of background ax parameter
00106    Double_t  fAyInit;                        //initial value of background ay parameter(backgroud is estimated as a0+ax*x+ay*y)
00107    Double_t  fAyCalc;                        //calculated value of background ay parameter
00108    Double_t  fAyErr;                         //error value of background ay parameter   
00109    Bool_t   *fFixPositionX;                  //[fNPeaks] array of logical values which allow to fix appropriate x positions of 2D peaks (not fit). However they are present in the estimated functional
00110    Bool_t   *fFixPositionY;                  //[fNPeaks] array of logical values which allow to fix appropriate y positions of 2D peaks (not fit). However they are present in the estimated functional
00111    Bool_t   *fFixPositionX1;                 //[fNPeaks] array of logical values which allow to fix appropriate x positions of 1D ridges (not fit). However they are present in the estimated functional
00112    Bool_t   *fFixPositionY1;                 //[fNPeaks] array of logical values which allow to fix appropriate y positions of 1D ridges (not fit). However they are present in the estimated functional
00113    Bool_t   *fFixAmp;                        //[fNPeaks] array of logical values which allow to fix appropriate amplitudes of 2D peaks (not fit). However they are present in the estimated functional
00114    Bool_t   *fFixAmpX1;                      //[fNPeaks] array of logical values which allow to fix appropriate amplitudes of 1D ridges in x direction (not fit). However they are present in the estimated functional
00115    Bool_t   *fFixAmpY1;                      //[fNPeaks] array of logical values which allow to fix appropriate amplitudes of 1D ridges in y direction (not fit). However they are present in the estimated functional
00116    Bool_t    fFixSigmaX;                     //logical value of sigma x parameter, which allows to fix the parameter (not to fit).
00117    Bool_t    fFixSigmaY;                     //logical value of sigma y parameter, which allows to fix the parameter (not to fit).
00118    Bool_t    fFixRo;                         //logical value of correlation coefficient, which allows to fix the parameter (not to fit).
00119    Bool_t    fFixTxy;                        //logical value of t parameter for 2D peaks, which allows to fix the parameter (not to fit).
00120    Bool_t    fFixSxy;                        //logical value of s parameter for 2D peaks, which allows to fix the parameter (not to fit).
00121    Bool_t    fFixTx;                         //logical value of t parameter for 1D ridges in x direction, which allows to fix the parameter (not to fit).
00122    Bool_t    fFixTy;                         //logical value of t parameter for 1D ridges in y direction, which allows to fix the parameter (not to fit).
00123    Bool_t    fFixSx;                         //logical value of s parameter for 1D ridges in x direction, which allows to fix the parameter (not to fit).
00124    Bool_t    fFixSy;                         //logical value of s parameter for 1D ridges in y direction, which allows to fix the parameter (not to fit).
00125    Bool_t    fFixBx;                         //logical value of b parameter for 1D ridges in x direction, which allows to fix the parameter (not to fit).
00126    Bool_t    fFixBy;                         //logical value of b parameter for 1D ridges in y direction, which allows to fix the parameter (not to fit).
00127    Bool_t    fFixA0;                         //logical value of a0 parameter, which allows to fix the parameter (not to fit).
00128    Bool_t    fFixAx;                         //logical value of ax parameter, which allows to fix the parameter (not to fit).
00129    Bool_t    fFixAy;                         //logical value of ay parameter, which allows to fix the parameter (not to fit).
00130 public:
00131    enum {
00132        kFitOptimChiCounts =0,
00133        kFitOptimChiFuncValues =1,
00134        kFitOptimMaxLikelihood =2,
00135        kFitAlphaHalving =0,
00136        kFitAlphaOptimal =1,
00137        kFitPower2 =2,
00138        kFitPower4 =4,
00139        kFitPower6 =6,
00140        kFitPower8 =8,
00141        kFitPower10 =10,
00142        kFitPower12 =12,
00143        kFitTaylorOrderFirst =0,
00144        kFitTaylorOrderSecond =1,
00145        kFitNumRegulCycles =100
00146    };
00147    TSpectrum2Fit(void); //default constructor        
00148    TSpectrum2Fit(Int_t numberPeaks);
00149    virtual ~TSpectrum2Fit();
00150    //auxiliary functions for 2. parameter fit functions
00151 protected:    
00152    Double_t            Deramp2(Double_t x,Double_t y,Double_t x0,Double_t y0,Double_t sigmax,Double_t sigmay,Double_t ro,Double_t txy,Double_t sxy,Double_t bx,Double_t by);
00153    Double_t            Derampx(Double_t x,Double_t x0,Double_t sigmax,Double_t tx,Double_t sx,Double_t bx);   
00154    Double_t            Derbx(Int_t numOfFittedPeaks,Double_t x,Double_t y,const Double_t *parameter,Double_t sigmax,Double_t sigmay,Double_t txy,Double_t tx,Double_t bx,Double_t by);
00155    Double_t            Derby(Int_t numOfFittedPeaks,Double_t x,Double_t y,const Double_t *parameter,Double_t sigmax,Double_t sigmay,Double_t txy,Double_t ty,Double_t bx,Double_t by);
00156    Double_t            Derderi01(Double_t x,Double_t ax,Double_t x0,Double_t sigmax);
00157    Double_t            Derderi02(Double_t x,Double_t y,Double_t a,Double_t x0,Double_t y0,Double_t sigmax,Double_t sigmay,Double_t ro);
00158    Double_t            Derderj02(Double_t x,Double_t y,Double_t a,Double_t x0,Double_t y0,Double_t sigmax,Double_t sigmay,Double_t ro);
00159    Double_t            Derdersigmax(Int_t numOfFittedPeaks,Double_t x,Double_t y,const Double_t *parameter,Double_t sigmax,Double_t sigmay,Double_t ro);
00160    Double_t            Derdersigmay(Int_t numOfFittedPeaks,Double_t x,Double_t y,const Double_t *parameter,Double_t sigmax,Double_t sigmay,Double_t ro);
00161    Double_t            Derfc(Double_t x);
00162    Double_t            Deri01(Double_t x,Double_t ax,Double_t x0,Double_t sigmax,Double_t tx,Double_t sx,Double_t bx);
00163    Double_t            Deri02(Double_t x,Double_t y,Double_t a,Double_t x0,Double_t y0,Double_t sigmax,Double_t sigmay,Double_t ro,Double_t txy,Double_t sxy,Double_t bx,Double_t by);
00164    Double_t            Derj02(Double_t x,Double_t y,Double_t a,Double_t x0,Double_t y0,Double_t sigmax,Double_t sigmay,Double_t ro,Double_t txy,Double_t sxy,Double_t bx,Double_t by);
00165    Double_t            Derpa2(Double_t sx,Double_t sy,Double_t ro);
00166    Double_t            Derpro(Double_t a,Double_t sx,Double_t sy,Double_t ro);
00167    Double_t            Derpsigmax(Double_t a,Double_t sy,Double_t ro);
00168    Double_t            Derpsigmay(Double_t a,Double_t sx,Double_t ro);
00169    Double_t            Derro(Int_t numOfFittedPeaks,Double_t x,Double_t y,const Double_t *parameter,Double_t sx,Double_t sy,Double_t r);
00170    Double_t            Dersigmax(Int_t numOfFittedPeaks,Double_t x,Double_t y,const Double_t *parameter,Double_t sigmax,Double_t sigmay,Double_t ro,Double_t txy,Double_t sxy,Double_t tx,Double_t sx,Double_t bx,Double_t by);
00171    Double_t            Dersigmay(Int_t numOfFittedPeaks,Double_t x,Double_t y,const Double_t *parameter,Double_t sigmax,Double_t sigmay,Double_t ro,Double_t txy,Double_t sxy,Double_t ty,Double_t sy,Double_t bx,Double_t by);
00172    Double_t            Dersx(Int_t numOfFittedPeaks,Double_t x,const Double_t *parameter,Double_t sigmax);
00173    Double_t            Dersxy(Int_t numOfFittedPeaks,Double_t x,Double_t y,const Double_t *parameter,Double_t sigmax,Double_t sigmay);
00174    Double_t            Dersy(Int_t numOfFittedPeaks,Double_t x,const Double_t *parameter,Double_t sigmax);
00175    Double_t            Dertx(Int_t numOfFittedPeaks,Double_t x,const Double_t *parameter,Double_t sigmax,Double_t bx);
00176    Double_t            Dertxy(Int_t numOfFittedPeaks,Double_t x,Double_t y,const Double_t *parameter,Double_t sigmax,Double_t sigmay,Double_t bx,Double_t by);
00177    Double_t            Derty(Int_t numOfFittedPeaks,Double_t x,const Double_t *parameter,Double_t sigmax,Double_t bx);
00178    Double_t            Erfc(Double_t x);
00179    Double_t            Ourpowl(Double_t a,Int_t pw);
00180    Double_t            Shape2(Int_t numOfFittedPeaks,Double_t x,Double_t y,const Double_t *parameter,Double_t sigmax,Double_t sigmay,Double_t ro,Double_t a0,Double_t ax,Double_t ay,Double_t txy,Double_t sxy,Double_t tx,Double_t ty,Double_t sx,Double_t sy,Double_t bx,Double_t by);   
00181    void                StiefelInversion(Double_t **a,Int_t size);
00182    Double_t            Volume(Double_t a,Double_t sx,Double_t sy,Double_t ro);
00183 
00184 public:
00185    void                FitAwmi(Float_t **source);   
00186    void                FitStiefel(Float_t **source);   
00187    void                GetAmplitudes(Float_t *amplitudes, Float_t *amplitudesX1, Float_t *amplitudesY1);
00188    void                GetAmplitudeErrors(Float_t *amplitudeErrors, Float_t *amplitudeErrorsX1, Float_t *amplitudeErrorsY1);
00189    void                GetBackgroundParameters(Double_t &a0, Double_t &a0Err, Double_t &ax, Double_t &axErr, Double_t &ay, Double_t &ayErr);
00190    Double_t            GetChi() const {return fChi;}   
00191    void                GetPositions(Float_t *positionsX, Float_t *positionsY, Float_t *positionsX1, Float_t *positionsY1);
00192    void                GetPositionErrors(Float_t *positionErrorsX, Float_t *positionErrorsY, Float_t *positionErrorsX1, Float_t *positionErrorsY1);
00193    void                GetRo(Double_t &ro, Double_t &roErr);
00194    void                GetSigmaX(Double_t &sigmaX, Double_t &sigmaErrX);
00195    void                GetSigmaY(Double_t &sigmaY, Double_t &sigmaErrY);
00196    void                GetTailParameters(Double_t &txy, Double_t &txyErr, Double_t &tx, Double_t &txErr, Double_t &ty, Double_t &tyErr, Double_t &bx, Double_t &bxErr, Double_t &by, Double_t &byErr, Double_t &sxy, Double_t &sxyErr, Double_t &sx, Double_t &sxErr, Double_t &sy, Double_t &syErr);
00197    void                GetVolumes(Float_t *volumes);
00198    void                GetVolumeErrors(Float_t *volumeErrors);
00199    void                SetBackgroundParameters(Double_t a0Init, Bool_t fixA0, Double_t axInit, Bool_t fixAx, Double_t ayInit, Bool_t fixAy);   
00200    void                SetFitParameters(Int_t xmin,Int_t xmax,Int_t ymin,Int_t ymax, Int_t numberIterations, Double_t alpha, Int_t statisticType, Int_t alphaOptim, Int_t power, Int_t fitTaylor);
00201    void                SetPeakParameters(Double_t sigmaX, Bool_t fixSigmaX, Double_t sigmaY, Bool_t fixSigmaY, Double_t ro, Bool_t fixRo, const Float_t *positionInitX, const Bool_t *fixPositionX, const Float_t *positionInitY, const Bool_t *fixPositionY, const Float_t *positionInitX1, const Bool_t *fixPositionX1, const Float_t *positionInitY1, const Bool_t *fixPositionY1, const Float_t *ampInit, const Bool_t *fixAmp, const Float_t *ampInitX1, const Bool_t *fixAmpX1, const Float_t *ampInitY1, const Bool_t *fixAmpY1);   
00202    void                SetTailParameters(Double_t tInitXY, Bool_t fixTxy, Double_t tInitX, Bool_t fixTx, Double_t tInitY, Bool_t fixTy, Double_t bInitX, Bool_t fixBx, Double_t bInitY, Bool_t fixBy, Double_t sInitXY, Bool_t fixSxy, Double_t sInitX, Bool_t fixSx, Double_t sInitY, Bool_t fixSy);
00203    
00204    ClassDef(TSpectrum2Fit,1)  //Spectrum2 Fitter using algorithm without matrix inversion and conjugate gradient method for symmetrical matrices (Stiefel-Hestens method)
00205 };
00206 
00207 #endif
00208 

Generated on Tue Jul 5 14:24:33 2011 for ROOT_528-00b_version by  doxygen 1.5.1