TSpectrumFit.h

Go to the documentation of this file.
00001 // @(#)root/spectrum:$Id: TSpectrumFit.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_TSpectrumFit
00012 #define ROOT_TSpectrumFit
00013 
00014 //////////////////////////////////////////////////////////////////////////
00015 //                                                                      //
00016 // TSpectrumFit                                                         //
00017 //                                                                      //
00018 // Class for fitting 1D 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 TH1;
00031 
00032 class TSpectrumFit : public TNamed {
00033 protected:
00034    Int_t     fNPeaks;                    //number of peaks present in fit, input parameter, it should be > 0
00035    Int_t     fNumberIterations;          //number of iterations in fitting procedure, input parameter, it should be > 0
00036    Int_t     fXmin;                      //first fitted channel
00037    Int_t     fXmax;                      //last fitted channel
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 *fPositionInit;              //[fNPeaks] array of initial values of peaks positions, input parameters
00045    Double_t *fPositionCalc;              //[fNPeaks] array of calculated values of fitted positions, output parameters
00046    Double_t *fPositionErr;               //[fNPeaks] array of position errors
00047    Double_t *fAmpInit;                   //[fNPeaks] array of initial values of peaks amplitudes, input parameters
00048    Double_t *fAmpCalc;                   //[fNPeaks] array of calculated values of fitted amplitudes, output parameters
00049    Double_t *fAmpErr;                    //[fNPeaks] array of amplitude errors
00050    Double_t *fArea;                      //[fNPeaks] array of calculated areas of peaks
00051    Double_t *fAreaErr;                   //[fNPeaks] array of errors of peak areas
00052    Double_t  fSigmaInit;                 //initial value of sigma parameter
00053    Double_t  fSigmaCalc;                 //calculated value of sigma parameter
00054    Double_t  fSigmaErr;                  //error value of sigma parameter
00055    Double_t  fTInit;                     //initial value of t parameter (relative amplitude of tail), for details see html manual and references
00056    Double_t  fTCalc;                     //calculated value of t parameter
00057    Double_t  fTErr;                      //error value of t parameter
00058    Double_t  fBInit;                     //initial value of b parameter (slope), for details see html manual and references
00059    Double_t  fBCalc;                     //calculated value of b parameter
00060    Double_t  fBErr;                      //error value of b parameter
00061    Double_t  fSInit;                     //initial value of s parameter (relative amplitude of step), for details see html manual and references
00062    Double_t  fSCalc;                     //calculated value of s parameter
00063    Double_t  fSErr;                      //error value of s parameter
00064    Double_t  fA0Init;                    //initial value of background a0 parameter(backgroud is estimated as a0+a1*x+a2*x*x)
00065    Double_t  fA0Calc;                    //calculated value of background a0 parameter
00066    Double_t  fA0Err;                     //error value of background a0 parameter
00067    Double_t  fA1Init;                    //initial value of background a1 parameter(backgroud is estimated as a0+a1*x+a2*x*x)
00068    Double_t  fA1Calc;                    //calculated value of background a1 parameter
00069    Double_t  fA1Err;                     //error value of background a1 parameter
00070    Double_t  fA2Init;                    //initial value of background a2 parameter(backgroud is estimated as a0+a1*x+a2*x*x)
00071    Double_t  fA2Calc;                    //calculated value of background a2 parameter
00072    Double_t  fA2Err;                     //error value of background a2 parameter
00073    Bool_t   *fFixPosition;               //[fNPeaks] array of logical values which allow to fix appropriate positions (not fit). However they are present in the estimated functional   
00074    Bool_t   *fFixAmp;                    //[fNPeaks] array of logical values which allow to fix appropriate amplitudes (not fit). However they are present in the estimated functional      
00075    Bool_t    fFixSigma;                  //logical value of sigma parameter, which allows to fix the parameter (not to fit).   
00076    Bool_t    fFixT;                      //logical value of t parameter, which allows to fix the parameter (not to fit).      
00077    Bool_t    fFixB;                      //logical value of b parameter, which allows to fix the parameter (not to fit).   
00078    Bool_t    fFixS;                      //logical value of s parameter, which allows to fix the parameter (not to fit).      
00079    Bool_t    fFixA0;                     //logical value of a0 parameter, which allows to fix the parameter (not to fit).
00080    Bool_t    fFixA1;                     //logical value of a1 parameter, which allows to fix the parameter (not to fit).   
00081    Bool_t    fFixA2;                     //logical value of a2 parameter, which allows to fix the parameter (not to fit).
00082 
00083 public:
00084    enum {
00085        kFitOptimChiCounts =0,
00086        kFitOptimChiFuncValues =1,
00087        kFitOptimMaxLikelihood =2,
00088        kFitAlphaHalving =0,
00089        kFitAlphaOptimal =1,
00090        kFitPower2 =2,
00091        kFitPower4 =4,
00092        kFitPower6 =6,
00093        kFitPower8 =8,
00094        kFitPower10 =10,
00095        kFitPower12 =12,
00096        kFitTaylorOrderFirst =0,
00097        kFitTaylorOrderSecond =1,
00098        kFitNumRegulCycles =100
00099    };
00100    TSpectrumFit(void); //default constructor     
00101    TSpectrumFit(Int_t numberPeaks); 
00102    virtual ~TSpectrumFit();
00103 
00104    //auxiliary functions for 1. parameter fit functions
00105 protected:   
00106    Double_t            Area(Double_t a,Double_t sigma,Double_t t,Double_t b);
00107    Double_t            Dera1(Double_t i);
00108    Double_t            Dera2(Double_t i);
00109    Double_t            Deramp(Double_t i,Double_t i0,Double_t sigma,Double_t t,Double_t s,Double_t b);   
00110    Double_t            Derb(Int_t num_of_fitted_peaks,Double_t i,const Double_t* parameter,Double_t sigma,Double_t t,Double_t b);
00111    Double_t            Derderi0(Double_t i,Double_t amp,Double_t i0,Double_t sigma);
00112    Double_t            Derdersigma(Int_t num_of_fitted_peaks,Double_t i,const Double_t* parameter,Double_t sigma);
00113    Double_t            Derfc(Double_t x);
00114    Double_t            Deri0(Double_t i,Double_t amp,Double_t i0,Double_t sigma,Double_t t,Double_t s,Double_t b);   
00115    Double_t            Derpa(Double_t sigma,Double_t t,Double_t b);
00116    Double_t            Derpb(Double_t a,Double_t sigma,Double_t t,Double_t b);
00117    Double_t            Derpsigma(Double_t a,Double_t t,Double_t b);
00118    Double_t            Derpt(Double_t a,Double_t sigma,Double_t b);
00119    Double_t            Ders(Int_t num_of_fitted_peaks,Double_t i,const Double_t* parameter,Double_t sigma);
00120    Double_t            Dersigma(Int_t num_of_fitted_peaks,Double_t i,const Double_t* parameter,Double_t sigma,Double_t t,Double_t s,Double_t b);
00121    Double_t            Dert(Int_t num_of_fitted_peaks,Double_t i,const Double_t* parameter,Double_t sigma,Double_t b);
00122    Double_t            Erfc(Double_t x);
00123    Double_t            Ourpowl(Double_t a,Int_t pw);   
00124    Double_t            Shape(Int_t num_of_fitted_peaks,Double_t i,const Double_t *parameter,Double_t sigma,Double_t t,Double_t s,Double_t b,Double_t a0,Double_t a1,Double_t a2);
00125    void                StiefelInversion(Double_t **a,Int_t rozmer);
00126 
00127 public:
00128    void                FitAwmi(float *source); 
00129    void                FitStiefel(float *source); 
00130    Double_t           *GetAmplitudes() const {return fAmpCalc;}   
00131    Double_t           *GetAmplitudesErrors() const {return fAmpErr;}
00132    Double_t           *GetAreas() const {return fArea;}            
00133    Double_t           *GetAreasErrors() const {return fAreaErr;}               
00134    void                GetBackgroundParameters(Double_t &a0, Double_t &a0Err, Double_t &a1, Double_t &a1Err, Double_t &a2, Double_t &a2Err);
00135    Double_t            GetChi() const {return fChi;}
00136    Double_t           *GetPositions() const {return fPositionCalc;}
00137    Double_t           *GetPositionsErrors() const {return fPositionErr;}   
00138    void                GetSigma(Double_t &sigma, Double_t &sigmaErr);
00139    void                GetTailParameters(Double_t &t, Double_t &tErr, Double_t &b, Double_t &bErr, Double_t &s, Double_t &sErr);
00140    void                SetBackgroundParameters(Double_t a0Init, Bool_t fixA0, Double_t a1Init, Bool_t fixA1, Double_t a2Init, Bool_t fixA2);
00141    void                SetFitParameters(Int_t xmin,Int_t xmax, Int_t numberIterations, Double_t alpha, Int_t statisticType, Int_t alphaOptim, Int_t power, Int_t fitTaylor);
00142    void                SetPeakParameters(Double_t sigma, Bool_t fixSigma, const Float_t *positionInit, const Bool_t *fixPosition, const Float_t *ampInit, const Bool_t *fixAmp);    
00143    void                SetTailParameters(Double_t tInit, Bool_t fixT, Double_t bInit, Bool_t fixB, Double_t sInit, Bool_t fixS); 
00144 
00145    ClassDef(TSpectrumFit,1)  //Spectrum Fitter using algorithm without matrix inversion and conjugate gradient method for symmetrical matrices (Stiefel-Hestens method)
00146 };
00147 
00148 #endif
00149 

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