CMS 3D CMS Logo

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