CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TKinFitter.h
Go to the documentation of this file.
1 #ifndef TKinFitter_h
2 #define TKinFitter_h
3 
4 #include <vector>
5 #include "TMatrixD.h"
6 #include "TNamed.h"
8 
10 class TH1D;
11 class TLorentzVector;
12 
13 class TKinFitter : public TNamed {
14 public:
15  TKinFitter();
16  TKinFitter(const TString& name, const TString& title);
17  ~TKinFitter() override;
18  void reset();
19  void resetStatus();
20 
21  Int_t fit();
22 
23  void addMeasParticle(TAbsFitParticle* particle);
25  TAbsFitParticle* p2 = nullptr,
26  TAbsFitParticle* p3 = nullptr,
27  TAbsFitParticle* p4 = nullptr,
28  TAbsFitParticle* p5 = nullptr,
29  TAbsFitParticle* p6 = nullptr,
30  TAbsFitParticle* p7 = nullptr,
31  TAbsFitParticle* p8 = nullptr,
32  TAbsFitParticle* p9 = nullptr);
33  void addUnmeasParticle(TAbsFitParticle* particle);
35  TAbsFitParticle* p2 = nullptr,
36  TAbsFitParticle* p3 = nullptr,
37  TAbsFitParticle* p4 = nullptr,
38  TAbsFitParticle* p5 = nullptr,
39  TAbsFitParticle* p6 = nullptr,
40  TAbsFitParticle* p7 = nullptr,
41  TAbsFitParticle* p8 = nullptr,
42  TAbsFitParticle* p9 = nullptr);
44 
45  Int_t getNDF() { return (_constraints.size() - _nParA); }
46  Int_t getNParA() { return _nParA; }
47  Int_t getNParB() { return _nParB; }
48  void setMaxNbIter(Int_t maxNbIter) { _maxNbIter = maxNbIter; }
49  Int_t getMaxNumberIter() { return _maxNbIter; }
50  Int_t getNbIter() { return _nbIter; }
51  Int_t getStatus() { return _status; }
52  void setMaxDeltaS(Double_t maxDeltaS) { _maxDeltaS = TMath::Abs(maxDeltaS); }
53  Double_t getMaxDeltaS() { return _maxDeltaS; }
54  void setMaxF(Double_t maxF) { _maxF = TMath::Abs(maxF); }
55  Double_t getMaxF() { return _maxF; }
56  const TMatrixD* getCovMatrix() { return &_V; }
57  void setCovMatrix(TMatrixD& V);
58  const TMatrixD* getCovMatrixFit() { return &_yaVFit; }
59  Double_t getS();
60  Double_t getF();
61  void setVerbosity(Int_t verbosity = 1);
62  Int_t getVerbosity() { return _verbosity; }
63 
64  Int_t nbMeasParticles() { return _measParticles.size(); }
66  const TLorentzVector* get4Vec(Int_t index) { return (_measParticles[index])->getCurr4Vec(); }
67 
68  Int_t nbUnmeasParticles() { return _unmeasParticles.size(); }
70  Int_t nbConstraints() { return _constraints.size(); }
71 
72  void print();
73 
74 protected:
75  Bool_t calcA();
76  Bool_t calcB();
77  Bool_t calcVA();
78  Bool_t calcVB();
79  Bool_t calcC();
80 
81  Bool_t calcC11();
82  Bool_t calcC21();
83  Bool_t calcC22();
84  Bool_t calcC31();
85  Bool_t calcC32();
86  Bool_t calcC33();
87 
88  Bool_t calcDeltaA();
89  Bool_t calcDeltaY();
90  Bool_t calcLambda();
91 
92  Bool_t calcV();
93  Bool_t calcVFit();
94 
95  Bool_t applyDeltaA();
96  Bool_t applyDeltaY();
97  void applyVFit();
98 
99  Bool_t converged(Double_t F, Double_t prevS, Double_t currS);
100 
101  TString getStatusString();
102  void countMeasParams();
103  void countUnmeasParams();
104  void resetParams();
105 
106  void printMatrix(const TMatrixD& matrix, const TString& name = "");
107 
108 private:
109  Int_t _maxNbIter; // Maximum number of iterations
110  Double_t _maxDeltaS; // Convergence criterium for deltaS
111  Double_t _maxF; // Convergence criterium for F
112  Int_t _verbosity; // Verbosty of the fitter 0: quiet, 1: print result, 2: print iterations, 3: print also matrices
113 
114  TMatrixD _A; // Jacobi Matrix of unmeasured parameters
115  TMatrixD _AT; // Transposed Jacobi Matrix of unmeasured parameters
116  TMatrixD _B; // Jacobi Matrix of measured parameters
117  TMatrixD _BT; // Transposed Jacobi Matrix of measured parameters
118  TMatrixD _V; // Covariance matrix
119  TMatrixD _Vinv; // Inverse covariance matrix
120  TMatrixD _VB; // VB = ( B*V*BT )^(-1)
121  TMatrixD _VBinv; // VBinv = ( B*V*BT )
122  TMatrixD _VA; // VA = ( AT*VB*A )
123  TMatrixD _VAinv; // VAinv = ( AT*VB*A )^(-1)
124  TMatrixD _c; // Vector c = A*delta(a*) + B*delta(y*) - f*
125 
126  TMatrixD _C11; // Matrix C11
127  TMatrixD _C11T; // Matrix C11T
128  TMatrixD _C21; // Matrix C21
129  TMatrixD _C21T; // Matrix C21T
130  TMatrixD _C22; // Matrix C22
131  TMatrixD _C22T; // Matrix C22T
132  TMatrixD _C31; // Matrix C31
133  TMatrixD _C31T; // Matrix C31T
134  TMatrixD _C32; // Matrix C32
135  TMatrixD _C32T; // Matrix C32T
136  TMatrixD _C33; // Matrix C33
137  TMatrixD _C33T; // Matrix C33T
138 
139  TMatrixD _deltaA; // The correction vector deltaA for unmeasured particles of the current iteration
140  TMatrixD _deltaY; // The correction vector deltaY for measured particles of the current iteration
141  TMatrixD _deltaAstar; // The correction vector deltaA for unmeasured particles of the previous iteration
142  TMatrixD _deltaYstar; // The correction vector deltaY for measured particles of the previous iteration
143  TMatrixD _lambda; // The column vector of Lagrange multiplicators (likelihood L = S + 2 sum_i lambda_i * f_i)
144  TMatrixD _lambdaT; // The row vector of Lagrange multiplicators (likelihood L = S + 2 sum_i lambda_i * f_i)
145 
146  TMatrixD _lambdaVFit; // Covariance matrix of lambda after the fit
147  TMatrixD _yaVFit; // Combined covariance matrix of y and a after the fit
148 
149  Int_t _nParA; // Number of unmeasured parameters
150  Int_t _nParB; // Number of measured parameters
151 
152  std::vector<TAbsFitConstraint*> _constraints; // vector with constraints
153  std::vector<TAbsFitParticle*> _measParticles; // vector with measured particles
154  std::vector<TAbsFitParticle*> _unmeasParticles; // vector with unmeasured particles
155 
156  Int_t _status; // Status of the last fit;_
157  Int_t _nbIter; // number of iteration performed in the fit
158 
159  ClassDefOverride(TKinFitter, 0)
160 };
161 
162 #endif
TMatrixD _deltaY
Definition: TKinFitter.h:140
Int_t getNbIter()
Definition: TKinFitter.h:50
TMatrixD _C11
Definition: TKinFitter.h:126
Double_t getMaxDeltaS()
Definition: TKinFitter.h:53
Bool_t calcC33()
Definition: TKinFitter.cc:759
Bool_t calcV()
Definition: TKinFitter.cc:474
void setMaxF(Double_t maxF)
Definition: TKinFitter.h:54
void countMeasParams()
Definition: TKinFitter.cc:173
Bool_t converged(Double_t F, Double_t prevS, Double_t currS)
Definition: TKinFitter.cc:1081
Bool_t calcVFit()
Definition: TKinFitter.cc:916
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
Bool_t calcVB()
Definition: TKinFitter.cc:618
Bool_t calcC11()
Definition: TKinFitter.cc:658
Int_t fit()
Definition: TKinFitter.cc:318
const TString p2
Definition: fwPaths.cc:13
void setMaxDeltaS(Double_t maxDeltaS)
Definition: TKinFitter.h:52
TString getStatusString()
Definition: TKinFitter.cc:1096
Int_t getMaxNumberIter()
Definition: TKinFitter.h:49
Int_t _nParA
Definition: TKinFitter.h:149
TMatrixD _C33T
Definition: TKinFitter.h:137
TMatrixD _lambda
Definition: TKinFitter.h:143
TMatrixD _C32T
Definition: TKinFitter.h:135
Bool_t calcC21()
Definition: TKinFitter.cc:687
TMatrixD _V
Definition: TKinFitter.h:118
void reset()
Definition: TKinFitter.cc:97
TMatrixD _C21T
Definition: TKinFitter.h:129
void addUnmeasParticles(TAbsFitParticle *p1, TAbsFitParticle *p2=nullptr, TAbsFitParticle *p3=nullptr, TAbsFitParticle *p4=nullptr, TAbsFitParticle *p5=nullptr, TAbsFitParticle *p6=nullptr, TAbsFitParticle *p7=nullptr, TAbsFitParticle *p8=nullptr, TAbsFitParticle *p9=nullptr)
Definition: TKinFitter.cc:257
TMatrixD _VB
Definition: TKinFitter.h:120
void addMeasParticles(TAbsFitParticle *p1, TAbsFitParticle *p2=nullptr, TAbsFitParticle *p3=nullptr, TAbsFitParticle *p4=nullptr, TAbsFitParticle *p5=nullptr, TAbsFitParticle *p6=nullptr, TAbsFitParticle *p7=nullptr, TAbsFitParticle *p8=nullptr, TAbsFitParticle *p9=nullptr)
Definition: TKinFitter.cc:208
TMatrixD _C31T
Definition: TKinFitter.h:133
const TAbsFitParticle * getUnmeasParticle(Int_t index)
Definition: TKinFitter.h:69
void resetParams()
Definition: TKinFitter.cc:154
TMatrixD _yaVFit
Definition: TKinFitter.h:147
TMatrixD _C32
Definition: TKinFitter.h:134
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154
Double_t getMaxF()
Definition: TKinFitter.h:55
TMatrixD _VA
Definition: TKinFitter.h:122
Double_t getS()
Definition: TKinFitter.cc:1066
TMatrixD _deltaA
Definition: TKinFitter.h:139
void applyVFit()
Definition: TKinFitter.cc:959
Bool_t applyDeltaY()
Definition: TKinFitter.cc:1023
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
~TKinFitter() override
Definition: TKinFitter.cc:171
Int_t _maxNbIter
Definition: TKinFitter.h:109
Bool_t calcB()
Definition: TKinFitter.cc:556
void print()
Definition: TKinFitter.cc:1125
TMatrixD _C33
Definition: TKinFitter.h:136
TMatrixD _deltaAstar
Definition: TKinFitter.h:141
Bool_t calcDeltaY()
Definition: TKinFitter.cc:883
void addConstraint(TAbsFitConstraint *constraint)
Definition: TKinFitter.cc:292
Bool_t calcA()
Definition: TKinFitter.cc:521
Bool_t calcLambda()
Definition: TKinFitter.cc:901
Bool_t calcC31()
Definition: TKinFitter.cc:718
Int_t nbUnmeasParticles()
Definition: TKinFitter.h:68
void countUnmeasParams()
Definition: TKinFitter.cc:185
Int_t getVerbosity()
Definition: TKinFitter.h:62
Int_t getStatus()
Definition: TKinFitter.h:51
const TString p1
Definition: fwPaths.cc:12
Int_t _status
Definition: TKinFitter.h:156
TMatrixD _B
Definition: TKinFitter.h:116
const TAbsFitParticle * getMeasParticle(Int_t index)
Definition: TKinFitter.h:65
TMatrixD _C22T
Definition: TKinFitter.h:131
void addUnmeasParticle(TAbsFitParticle *particle)
Definition: TKinFitter.cc:243
TMatrixD _VAinv
Definition: TKinFitter.h:123
Int_t getNDF()
Definition: TKinFitter.h:45
void addMeasParticle(TAbsFitParticle *particle)
Definition: TKinFitter.cc:194
TMatrixD _C22
Definition: TKinFitter.h:130
TMatrixD _c
Definition: TKinFitter.h:124
Double_t _maxDeltaS
Definition: TKinFitter.h:110
const TMatrixD * getCovMatrixFit()
Definition: TKinFitter.h:58
void setCovMatrix(TMatrixD &V)
Definition: TKinFitter.cc:462
TMatrixD _A
Definition: TKinFitter.h:114
TMatrixD _lambdaT
Definition: TKinFitter.h:144
void setVerbosity(Int_t verbosity=1)
Definition: TKinFitter.cc:304
const TMatrixD * getCovMatrix()
Definition: TKinFitter.h:56
Bool_t calcVA()
Definition: TKinFitter.cc:638
void printMatrix(const TMatrixD &matrix, const TString &name="")
Definition: TKinFitter.cc:1205
TMatrixD _lambdaVFit
Definition: TKinFitter.h:146
TMatrixD _C31
Definition: TKinFitter.h:132
void resetStatus()
Definition: TKinFitter.cc:147
Bool_t applyDeltaA()
Definition: TKinFitter.cc:1005
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
TMatrixD _deltaYstar
Definition: TKinFitter.h:142
Int_t getNParB()
Definition: TKinFitter.h:47
TMatrixD _BT
Definition: TKinFitter.h:117
TMatrixD _AT
Definition: TKinFitter.h:115
void setMaxNbIter(Int_t maxNbIter)
Definition: TKinFitter.h:48
Int_t nbConstraints()
Definition: TKinFitter.h:70
Int_t _nbIter
Definition: TKinFitter.h:157
Bool_t calcC32()
Definition: TKinFitter.cc:744
Int_t _verbosity
Definition: TKinFitter.h:112
Double_t getF()
Definition: TKinFitter.cc:1054
TMatrixD _VBinv
Definition: TKinFitter.h:121
Bool_t calcC22()
Definition: TKinFitter.cc:705
Bool_t calcC()
Definition: TKinFitter.cc:781
Int_t _nParB
Definition: TKinFitter.h:150
TMatrixD _C11T
Definition: TKinFitter.h:127
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
Int_t nbMeasParticles()
Definition: TKinFitter.h:64
TMatrixD _C21
Definition: TKinFitter.h:128
TMatrixD _Vinv
Definition: TKinFitter.h:119
Bool_t calcDeltaA()
Definition: TKinFitter.cc:865
const TLorentzVector * get4Vec(Int_t index)
Definition: TKinFitter.h:66
Int_t getNParA()
Definition: TKinFitter.h:46
Double_t _maxF
Definition: TKinFitter.h:111