CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/PhysicsTools/KinFitter/interface/TKinFitter.h

Go to the documentation of this file.
00001 #ifndef TKinFitter_h
00002 #define TKinFitter_h
00003 
00004 #include <vector>
00005 #include "TMatrixD.h"
00006 #include "TNamed.h"
00007 
00008 class TAbsFitParticle;
00009 class TAbsFitConstraint;
00010 class TH1D;
00011 
00012 class TKinFitter : public TNamed {
00013 
00014 public :
00015 
00016   TKinFitter();
00017   TKinFitter(const TString &name, const TString &title);  
00018   ~TKinFitter();
00019   void reset();         
00020   void resetStatus();   
00021 
00022   Int_t fit();
00023 
00024   void addMeasParticle( TAbsFitParticle* particle );
00025   void addMeasParticles( TAbsFitParticle* p1, TAbsFitParticle* p2 = 0, TAbsFitParticle* p3 = 0, 
00026                          TAbsFitParticle* p4 = 0, TAbsFitParticle* p5 = 0, TAbsFitParticle* p6 = 0,
00027                          TAbsFitParticle* p7 = 0, TAbsFitParticle* p8 = 0, TAbsFitParticle* p9 = 0);
00028   void addUnmeasParticle( TAbsFitParticle* particle );
00029   void addUnmeasParticles( TAbsFitParticle* p1, TAbsFitParticle* p2 = 0, TAbsFitParticle* p3 = 0, 
00030                            TAbsFitParticle* p4 = 0, TAbsFitParticle* p5 = 0, TAbsFitParticle* p6 = 0,
00031                            TAbsFitParticle* p7 = 0, TAbsFitParticle* p8 = 0, TAbsFitParticle* p9 = 0);
00032   void addConstraint( TAbsFitConstraint* constraint );
00033 
00034   Int_t getNDF() { return  (_constraints.size() - _nParA); }
00035   Int_t getNParA() { return _nParA; }
00036   Int_t getNParB() { return _nParB; }
00037   void setMaxNbIter( Int_t maxNbIter ) { _maxNbIter = maxNbIter; }
00038   Int_t getMaxNumberIter() { return _maxNbIter; }
00039   Int_t getNbIter() { return _nbIter; }
00040   Int_t getStatus() { return _status; }
00041   void setMaxDeltaS( Double_t maxDeltaS ) { _maxDeltaS = TMath::Abs( maxDeltaS ); }
00042   Double_t getMaxDeltaS() { return _maxDeltaS; }
00043   void setMaxF( Double_t maxF ) { _maxF = TMath::Abs( maxF ); }
00044   Double_t getMaxF() { return _maxF; }
00045   const TMatrixD* getCovMatrix() { return &_V; }
00046   void setCovMatrix( TMatrixD &V );
00047   const TMatrixD* getCovMatrixFit() { return &_yaVFit; }
00048   Double_t getS();
00049   Double_t getF();
00050   void setVerbosity( Int_t verbosity = 1 );
00051   Int_t getVerbosity( ) { return _verbosity; }
00052 
00053   Int_t nbMeasParticles() { return _measParticles.size(); }
00054   const TAbsFitParticle* getMeasParticle( Int_t index ) { return _measParticles[index]; }
00055   Int_t nbUnmeasParticles() { return _unmeasParticles.size(); }
00056   const TAbsFitParticle* getUnmeasParticle( Int_t index ) { return _unmeasParticles[index]; }
00057   Int_t nbConstraints() { return _constraints.size(); }
00058 
00059   void print();
00060 
00061 protected:
00062 
00063   Bool_t calcA();
00064   Bool_t calcB();
00065   Bool_t calcVA();
00066   Bool_t calcVB();
00067   Bool_t calcC();
00068 
00069   Bool_t calcC11();
00070   Bool_t calcC21();
00071   Bool_t calcC22();
00072   Bool_t calcC31();
00073   Bool_t calcC32();
00074   Bool_t calcC33();
00075 
00076   Bool_t calcDeltaA();
00077   Bool_t calcDeltaY();
00078   Bool_t calcLambda();
00079 
00080   Bool_t calcV();
00081   Bool_t calcVFit();
00082 
00083   Bool_t applyDeltaA();
00084   Bool_t applyDeltaY();
00085   void applyVFit();
00086 
00087   Bool_t converged(Double_t F, Double_t prevS, Double_t currS);
00088 
00089   TString getStatusString();
00090   void countMeasParams();
00091   void countUnmeasParams();
00092   void resetParams();
00093 
00094   void printMatrix(const TMatrixD &matrix, const TString name = "");
00095 
00096 private :
00097 
00098   Int_t _maxNbIter;       // Maximum number of iterations
00099   Double_t _maxDeltaS;    // Convergence criterium for deltaS
00100   Double_t _maxF;       // Convergence criterium for F
00101   Int_t _verbosity;       // Verbosty of the fitter 0: quiet, 1: print result, 2: print iterations, 3: print also matrices
00102 
00103   TMatrixD _A;      // Jacobi Matrix of unmeasured parameters
00104   TMatrixD _AT;     // Transposed Jacobi Matrix of unmeasured parameters
00105   TMatrixD _B;      // Jacobi Matrix of measured parameters
00106   TMatrixD _BT;     // Transposed Jacobi Matrix of measured parameters
00107   TMatrixD _V;      // Covariance matrix
00108   TMatrixD _Vinv;   // Inverse covariance matrix
00109   TMatrixD _VB;     // VB    = ( B*V*BT )^(-1)
00110   TMatrixD _VBinv;  // VBinv = ( B*V*BT )
00111   TMatrixD _VA;     // VA    = ( AT*VB*A )
00112   TMatrixD _VAinv;  // VAinv = ( AT*VB*A )^(-1)
00113   TMatrixD _c;      // Vector c = A*delta(a*) + B*delta(y*) - f*
00114 
00115   TMatrixD _C11;     // Matrix C11
00116   TMatrixD _C11T;    // Matrix C11T
00117   TMatrixD _C21;     // Matrix C21
00118   TMatrixD _C21T;    // Matrix C21T
00119   TMatrixD _C22;     // Matrix C22
00120   TMatrixD _C22T;    // Matrix C22T
00121   TMatrixD _C31;     // Matrix C31
00122   TMatrixD _C31T;    // Matrix C31T
00123   TMatrixD _C32;     // Matrix C32
00124   TMatrixD _C32T;    // Matrix C32T
00125   TMatrixD _C33;     // Matrix C33
00126   TMatrixD _C33T;    // Matrix C33T
00127 
00128   TMatrixD _deltaA;  // The correction vector deltaA for unmeasured particles of the current iteration
00129   TMatrixD _deltaY;  // The correction vector deltaY for measured particles of the current iteration
00130   TMatrixD _deltaAstar; // The correction vector deltaA for unmeasured particles of the previous iteration
00131   TMatrixD _deltaYstar; // The correction vector deltaY for measured particles of the previous iteration
00132   TMatrixD _lambda;  // The column vector of Lagrange multiplicators (likelihood L = S + 2 sum_i lambda_i * f_i)
00133   TMatrixD _lambdaT; // The row vector of Lagrange multiplicators (likelihood L = S + 2 sum_i lambda_i * f_i)
00134 
00135   TMatrixD _lambdaVFit;   // Covariance matrix of lambda after the fit
00136   TMatrixD _yaVFit;       // Combined covariance matrix of y and a after the fit
00137 
00138   Int_t _nParA;     // Number of unmeasured parameters
00139   Int_t _nParB;     // Number of measured parameters
00140 
00141   std::vector<TAbsFitConstraint*> _constraints;    // vector with constraints
00142   std::vector<TAbsFitParticle*> _measParticles;    // vector with measured particles
00143   std::vector<TAbsFitParticle*> _unmeasParticles;  // vector with unmeasured particles
00144 
00145   Int_t _status;        // Status of the last fit;_
00146   Int_t _nbIter;        // number of iteration performed in the fit
00147 
00148 };
00149 
00150 #endif