Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:35

0001 #ifndef TKinFitter_h
0002 #define TKinFitter_h
0003 
0004 #include <vector>
0005 #include "TMatrixD.h"
0006 #include "TNamed.h"
0007 #include "PhysicsTools/KinFitter/interface/TAbsFitParticle.h"
0008 
0009 class TAbsFitConstraint;
0010 class TH1D;
0011 class TLorentzVector;
0012 
0013 class TKinFitter : public TNamed {
0014 public:
0015   TKinFitter();
0016   TKinFitter(const TString& name, const TString& title);
0017   ~TKinFitter() override;
0018   void reset();
0019   void resetStatus();
0020 
0021   Int_t fit();
0022 
0023   void addMeasParticle(TAbsFitParticle* particle);
0024   void addMeasParticles(TAbsFitParticle* p1,
0025                         TAbsFitParticle* p2 = nullptr,
0026                         TAbsFitParticle* p3 = nullptr,
0027                         TAbsFitParticle* p4 = nullptr,
0028                         TAbsFitParticle* p5 = nullptr,
0029                         TAbsFitParticle* p6 = nullptr,
0030                         TAbsFitParticle* p7 = nullptr,
0031                         TAbsFitParticle* p8 = nullptr,
0032                         TAbsFitParticle* p9 = nullptr);
0033   void addUnmeasParticle(TAbsFitParticle* particle);
0034   void addUnmeasParticles(TAbsFitParticle* p1,
0035                           TAbsFitParticle* p2 = nullptr,
0036                           TAbsFitParticle* p3 = nullptr,
0037                           TAbsFitParticle* p4 = nullptr,
0038                           TAbsFitParticle* p5 = nullptr,
0039                           TAbsFitParticle* p6 = nullptr,
0040                           TAbsFitParticle* p7 = nullptr,
0041                           TAbsFitParticle* p8 = nullptr,
0042                           TAbsFitParticle* p9 = nullptr);
0043   void addConstraint(TAbsFitConstraint* constraint);
0044 
0045   Int_t getNDF() { return (_constraints.size() - _nParA); }
0046   Int_t getNParA() { return _nParA; }
0047   Int_t getNParB() { return _nParB; }
0048   void setMaxNbIter(Int_t maxNbIter) { _maxNbIter = maxNbIter; }
0049   Int_t getMaxNumberIter() { return _maxNbIter; }
0050   Int_t getNbIter() { return _nbIter; }
0051   Int_t getStatus() { return _status; }
0052   void setMaxDeltaS(Double_t maxDeltaS) { _maxDeltaS = TMath::Abs(maxDeltaS); }
0053   Double_t getMaxDeltaS() { return _maxDeltaS; }
0054   void setMaxF(Double_t maxF) { _maxF = TMath::Abs(maxF); }
0055   Double_t getMaxF() { return _maxF; }
0056   const TMatrixD* getCovMatrix() { return &_V; }
0057   void setCovMatrix(TMatrixD& V);
0058   const TMatrixD* getCovMatrixFit() { return &_yaVFit; }
0059   Double_t getS();
0060   Double_t getF();
0061   void setVerbosity(Int_t verbosity = 1);
0062   Int_t getVerbosity() { return _verbosity; }
0063 
0064   Int_t nbMeasParticles() { return _measParticles.size(); }
0065   const TAbsFitParticle* getMeasParticle(Int_t index) { return _measParticles[index]; }
0066   const TLorentzVector* get4Vec(Int_t index) { return (_measParticles[index])->getCurr4Vec(); }
0067 
0068   Int_t nbUnmeasParticles() { return _unmeasParticles.size(); }
0069   const TAbsFitParticle* getUnmeasParticle(Int_t index) { return _unmeasParticles[index]; }
0070   Int_t nbConstraints() { return _constraints.size(); }
0071 
0072   void print();
0073 
0074 protected:
0075   Bool_t calcA();
0076   Bool_t calcB();
0077   Bool_t calcVA();
0078   Bool_t calcVB();
0079   Bool_t calcC();
0080 
0081   Bool_t calcC11();
0082   Bool_t calcC21();
0083   Bool_t calcC22();
0084   Bool_t calcC31();
0085   Bool_t calcC32();
0086   Bool_t calcC33();
0087 
0088   Bool_t calcDeltaA();
0089   Bool_t calcDeltaY();
0090   Bool_t calcLambda();
0091 
0092   Bool_t calcV();
0093   Bool_t calcVFit();
0094 
0095   Bool_t applyDeltaA();
0096   Bool_t applyDeltaY();
0097   void applyVFit();
0098 
0099   Bool_t converged(Double_t F, Double_t prevS, Double_t currS);
0100 
0101   TString getStatusString();
0102   void countMeasParams();
0103   void countUnmeasParams();
0104   void resetParams();
0105 
0106   void printMatrix(const TMatrixD& matrix, const TString& name = "");
0107 
0108 private:
0109   Int_t _maxNbIter;     // Maximum number of iterations
0110   Double_t _maxDeltaS;  // Convergence criterium for deltaS
0111   Double_t _maxF;       // Convergence criterium for F
0112   Int_t _verbosity;     // Verbosty of the fitter 0: quiet, 1: print result, 2: print iterations, 3: print also matrices
0113 
0114   TMatrixD _A;      // Jacobi Matrix of unmeasured parameters
0115   TMatrixD _AT;     // Transposed Jacobi Matrix of unmeasured parameters
0116   TMatrixD _B;      // Jacobi Matrix of measured parameters
0117   TMatrixD _BT;     // Transposed Jacobi Matrix of measured parameters
0118   TMatrixD _V;      // Covariance matrix
0119   TMatrixD _Vinv;   // Inverse covariance matrix
0120   TMatrixD _VB;     // VB    = ( B*V*BT )^(-1)
0121   TMatrixD _VBinv;  // VBinv = ( B*V*BT )
0122   TMatrixD _VA;     // VA    = ( AT*VB*A )
0123   TMatrixD _VAinv;  // VAinv = ( AT*VB*A )^(-1)
0124   TMatrixD _c;      // Vector c = A*delta(a*) + B*delta(y*) - f*
0125 
0126   TMatrixD _C11;   // Matrix C11
0127   TMatrixD _C11T;  // Matrix C11T
0128   TMatrixD _C21;   // Matrix C21
0129   TMatrixD _C21T;  // Matrix C21T
0130   TMatrixD _C22;   // Matrix C22
0131   TMatrixD _C22T;  // Matrix C22T
0132   TMatrixD _C31;   // Matrix C31
0133   TMatrixD _C31T;  // Matrix C31T
0134   TMatrixD _C32;   // Matrix C32
0135   TMatrixD _C32T;  // Matrix C32T
0136   TMatrixD _C33;   // Matrix C33
0137   TMatrixD _C33T;  // Matrix C33T
0138 
0139   TMatrixD _deltaA;      // The correction vector deltaA for unmeasured particles of the current iteration
0140   TMatrixD _deltaY;      // The correction vector deltaY for measured particles of the current iteration
0141   TMatrixD _deltaAstar;  // The correction vector deltaA for unmeasured particles of the previous iteration
0142   TMatrixD _deltaYstar;  // The correction vector deltaY for measured particles of the previous iteration
0143   TMatrixD _lambda;      // The column vector of Lagrange multiplicators (likelihood L = S + 2 sum_i lambda_i * f_i)
0144   TMatrixD _lambdaT;     // The row vector of Lagrange multiplicators (likelihood L = S + 2 sum_i lambda_i * f_i)
0145 
0146   TMatrixD _lambdaVFit;  // Covariance matrix of lambda after the fit
0147   TMatrixD _yaVFit;      // Combined covariance matrix of y and a after the fit
0148 
0149   Int_t _nParA;  // Number of unmeasured parameters
0150   Int_t _nParB;  // Number of measured parameters
0151 
0152   std::vector<TAbsFitConstraint*> _constraints;    // vector with constraints
0153   std::vector<TAbsFitParticle*> _measParticles;    // vector with measured particles
0154   std::vector<TAbsFitParticle*> _unmeasParticles;  // vector with unmeasured particles
0155 
0156   Int_t _status;  // Status of the last fit;_
0157   Int_t _nbIter;  // number of iteration performed in the fit
0158 
0159   ClassDefOverride(TKinFitter, 0)
0160 };
0161 
0162 #endif