CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Private Attributes
TKinFitter Class Reference

#include <TKinFitter.h>

Inheritance diagram for TKinFitter:

Public Member Functions

void addConstraint (TAbsFitConstraint *constraint)
 
void addMeasParticle (TAbsFitParticle *particle)
 
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)
 
void addUnmeasParticle (TAbsFitParticle *particle)
 
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)
 
Int_t fit ()
 
const TLorentzVector * get4Vec (Int_t index)
 
const TMatrixD * getCovMatrix ()
 
const TMatrixD * getCovMatrixFit ()
 
Double_t getF ()
 
Double_t getMaxDeltaS ()
 
Double_t getMaxF ()
 
Int_t getMaxNumberIter ()
 
const TAbsFitParticlegetMeasParticle (Int_t index)
 
Int_t getNbIter ()
 
Int_t getNDF ()
 
Int_t getNParA ()
 
Int_t getNParB ()
 
Double_t getS ()
 
Int_t getStatus ()
 
const TAbsFitParticlegetUnmeasParticle (Int_t index)
 
Int_t getVerbosity ()
 
Int_t nbConstraints ()
 
Int_t nbMeasParticles ()
 
Int_t nbUnmeasParticles ()
 
void print ()
 
void reset ()
 
void resetStatus ()
 
void setCovMatrix (TMatrixD &V)
 
void setMaxDeltaS (Double_t maxDeltaS)
 
void setMaxF (Double_t maxF)
 
void setMaxNbIter (Int_t maxNbIter)
 
void setVerbosity (Int_t verbosity=1)
 
 TKinFitter ()
 
 TKinFitter (const TString &name, const TString &title)
 
 ~TKinFitter () override
 

Protected Member Functions

Bool_t applyDeltaA ()
 
Bool_t applyDeltaY ()
 
void applyVFit ()
 
Bool_t calcA ()
 
Bool_t calcB ()
 
Bool_t calcC ()
 
Bool_t calcC11 ()
 
Bool_t calcC21 ()
 
Bool_t calcC22 ()
 
Bool_t calcC31 ()
 
Bool_t calcC32 ()
 
Bool_t calcC33 ()
 
Bool_t calcDeltaA ()
 
Bool_t calcDeltaY ()
 
Bool_t calcLambda ()
 
Bool_t calcV ()
 
Bool_t calcVA ()
 
Bool_t calcVB ()
 
Bool_t calcVFit ()
 
Bool_t converged (Double_t F, Double_t prevS, Double_t currS)
 
void countMeasParams ()
 
void countUnmeasParams ()
 
TString getStatusString ()
 
void printMatrix (const TMatrixD &matrix, const TString &name="")
 
void resetParams ()
 

Private Attributes

TMatrixD _A
 
TMatrixD _AT
 
TMatrixD _B
 
TMatrixD _BT
 
TMatrixD _c
 
TMatrixD _C11
 
TMatrixD _C11T
 
TMatrixD _C21
 
TMatrixD _C21T
 
TMatrixD _C22
 
TMatrixD _C22T
 
TMatrixD _C31
 
TMatrixD _C31T
 
TMatrixD _C32
 
TMatrixD _C32T
 
TMatrixD _C33
 
TMatrixD _C33T
 
std::vector< TAbsFitConstraint * > _constraints
 
TMatrixD _deltaA
 
TMatrixD _deltaAstar
 
TMatrixD _deltaY
 
TMatrixD _deltaYstar
 
TMatrixD _lambda
 
TMatrixD _lambdaT
 
TMatrixD _lambdaVFit
 
Double_t _maxDeltaS
 
Double_t _maxF
 
Int_t _maxNbIter
 
std::vector< TAbsFitParticle * > _measParticles
 
Int_t _nbIter
 
Int_t _nParA
 
Int_t _nParB
 
Int_t _status
 
std::vector< TAbsFitParticle * > _unmeasParticles
 
TMatrixD _V
 
TMatrixD _VA
 
TMatrixD _VAinv
 
TMatrixD _VB
 
TMatrixD _VBinv
 
Int_t _verbosity
 
TMatrixD _Vinv
 
TMatrixD _yaVFit
 

Detailed Description

Definition at line 13 of file TKinFitter.h.

Constructor & Destructor Documentation

◆ TKinFitter() [1/2]

TKinFitter::TKinFitter ( )

Definition at line 19 of file TKinFitter.cc.

References reset().

20  : TNamed("UnNamed", "UnTitled"),
21  _A(1, 1),
22  _AT(1, 1),
23  _B(1, 1),
24  _BT(1, 1),
25  _V(1, 1),
26  _Vinv(1, 1),
27  _VB(1, 1),
28  _VBinv(1, 1),
29  _VA(1, 1),
30  _VAinv(1, 1),
31  _c(1, 1),
32  _C11(1, 1),
33  _C11T(1, 1),
34  _C21(1, 1),
35  _C21T(1, 1),
36  _C22(1, 1),
37  _C22T(1, 1),
38  _C31(1, 1),
39  _C31T(1, 1),
40  _C32(1, 1),
41  _C32T(1, 1),
42  _C33(1, 1),
43  _C33T(1, 1),
44  _deltaA(1, 1),
45  _deltaY(1, 1),
46  _deltaAstar(1, 1),
47  _deltaYstar(1, 1),
48  _lambda(1, 1),
49  _lambdaT(1, 1),
50  _lambdaVFit(1, 1),
51  _yaVFit(1, 1),
52  _constraints(0),
53  _measParticles(0),
54  _unmeasParticles(0) {
55  reset();
56 }
TMatrixD _deltaY
Definition: TKinFitter.h:140
TMatrixD _C11
Definition: TKinFitter.h:126
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
TMatrixD _C33T
Definition: TKinFitter.h:137
TMatrixD _lambda
Definition: TKinFitter.h:143
TMatrixD _C32T
Definition: TKinFitter.h:135
TMatrixD _V
Definition: TKinFitter.h:118
void reset()
Definition: TKinFitter.cc:97
TMatrixD _C21T
Definition: TKinFitter.h:129
TMatrixD _VB
Definition: TKinFitter.h:120
TMatrixD _C31T
Definition: TKinFitter.h:133
TMatrixD _yaVFit
Definition: TKinFitter.h:147
TMatrixD _C32
Definition: TKinFitter.h:134
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154
TMatrixD _VA
Definition: TKinFitter.h:122
TMatrixD _deltaA
Definition: TKinFitter.h:139
TMatrixD _C33
Definition: TKinFitter.h:136
TMatrixD _deltaAstar
Definition: TKinFitter.h:141
TMatrixD _B
Definition: TKinFitter.h:116
TMatrixD _C22T
Definition: TKinFitter.h:131
TMatrixD _VAinv
Definition: TKinFitter.h:123
TMatrixD _C22
Definition: TKinFitter.h:130
TMatrixD _c
Definition: TKinFitter.h:124
TMatrixD _A
Definition: TKinFitter.h:114
TMatrixD _lambdaT
Definition: TKinFitter.h:144
TMatrixD _lambdaVFit
Definition: TKinFitter.h:146
TMatrixD _C31
Definition: TKinFitter.h:132
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
TMatrixD _deltaYstar
Definition: TKinFitter.h:142
TMatrixD _BT
Definition: TKinFitter.h:117
TMatrixD _AT
Definition: TKinFitter.h:115
TMatrixD _VBinv
Definition: TKinFitter.h:121
TMatrixD _C11T
Definition: TKinFitter.h:127
TMatrixD _C21
Definition: TKinFitter.h:128
TMatrixD _Vinv
Definition: TKinFitter.h:119

◆ TKinFitter() [2/2]

TKinFitter::TKinFitter ( const TString &  name,
const TString &  title 
)

Definition at line 58 of file TKinFitter.cc.

References reset().

59  : TNamed(name, title),
60  _A(1, 1),
61  _AT(1, 1),
62  _B(1, 1),
63  _BT(1, 1),
64  _V(1, 1),
65  _Vinv(1, 1),
66  _VB(1, 1),
67  _VBinv(1, 1),
68  _VA(1, 1),
69  _VAinv(1, 1),
70  _c(1, 1),
71  _C11(1, 1),
72  _C11T(1, 1),
73  _C21(1, 1),
74  _C21T(1, 1),
75  _C22(1, 1),
76  _C22T(1, 1),
77  _C31(1, 1),
78  _C31T(1, 1),
79  _C32(1, 1),
80  _C32T(1, 1),
81  _C33(1, 1),
82  _C33T(1, 1),
83  _deltaA(1, 1),
84  _deltaY(1, 1),
85  _deltaAstar(1, 1),
86  _deltaYstar(1, 1),
87  _lambda(1, 1),
88  _lambdaT(1, 1),
89  _lambdaVFit(1, 1),
90  _yaVFit(1, 1),
91  _constraints(0),
92  _measParticles(0),
93  _unmeasParticles(0) {
94  reset();
95 }
TMatrixD _deltaY
Definition: TKinFitter.h:140
TMatrixD _C11
Definition: TKinFitter.h:126
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
TMatrixD _C33T
Definition: TKinFitter.h:137
TMatrixD _lambda
Definition: TKinFitter.h:143
TMatrixD _C32T
Definition: TKinFitter.h:135
TMatrixD _V
Definition: TKinFitter.h:118
void reset()
Definition: TKinFitter.cc:97
TMatrixD _C21T
Definition: TKinFitter.h:129
TMatrixD _VB
Definition: TKinFitter.h:120
TMatrixD _C31T
Definition: TKinFitter.h:133
TMatrixD _yaVFit
Definition: TKinFitter.h:147
TMatrixD _C32
Definition: TKinFitter.h:134
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154
TMatrixD _VA
Definition: TKinFitter.h:122
TMatrixD _deltaA
Definition: TKinFitter.h:139
TMatrixD _C33
Definition: TKinFitter.h:136
TMatrixD _deltaAstar
Definition: TKinFitter.h:141
TMatrixD _B
Definition: TKinFitter.h:116
TMatrixD _C22T
Definition: TKinFitter.h:131
TMatrixD _VAinv
Definition: TKinFitter.h:123
TMatrixD _C22
Definition: TKinFitter.h:130
TMatrixD _c
Definition: TKinFitter.h:124
TMatrixD _A
Definition: TKinFitter.h:114
TMatrixD _lambdaT
Definition: TKinFitter.h:144
TMatrixD _lambdaVFit
Definition: TKinFitter.h:146
TMatrixD _C31
Definition: TKinFitter.h:132
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
TMatrixD _deltaYstar
Definition: TKinFitter.h:142
TMatrixD _BT
Definition: TKinFitter.h:117
TMatrixD _AT
Definition: TKinFitter.h:115
TMatrixD _VBinv
Definition: TKinFitter.h:121
TMatrixD _C11T
Definition: TKinFitter.h:127
TMatrixD _C21
Definition: TKinFitter.h:128
TMatrixD _Vinv
Definition: TKinFitter.h:119

◆ ~TKinFitter()

TKinFitter::~TKinFitter ( )
override

Definition at line 171 of file TKinFitter.cc.

171 {}

Member Function Documentation

◆ addConstraint()

void TKinFitter::addConstraint ( TAbsFitConstraint constraint)

Definition at line 292 of file TKinFitter.cc.

References _constraints, HLT_2024v13_cff::constraint, countMeasParams(), and resetStatus().

Referenced by TSLToyGen::doToyExperiments(), and CandMassKinFitter::set().

292  {
293  // add a constraint
294 
295  resetStatus();
296 
297  if (constraint != nullptr) {
298  _constraints.push_back(constraint);
299  }
300 
301  countMeasParams();
302 }
void countMeasParams()
Definition: TKinFitter.cc:173
void resetStatus()
Definition: TKinFitter.cc:147
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152

◆ addMeasParticle()

void TKinFitter::addMeasParticle ( TAbsFitParticle particle)

Definition at line 194 of file TKinFitter.cc.

References _measParticles, countMeasParams(), and resetStatus().

Referenced by TSLToyGen::doToyExperiments(), and CandMassKinFitter::set().

194  {
195  // add one measured particle
196 
197  resetStatus();
198 
199  if (particle != nullptr) {
200  _measParticles.push_back(particle);
201  } else {
202  edm::LogError("NullPointer") << "Measured particle points to NULL. It will not be added to the KinFitter.";
203  }
204 
205  countMeasParams();
206 }
void countMeasParams()
Definition: TKinFitter.cc:173
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
Log< level::Error, false > LogError
void resetStatus()
Definition: TKinFitter.cc:147

◆ addMeasParticles()

void TKinFitter::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 at line 208 of file TKinFitter.cc.

References _measParticles, countMeasParams(), LaserDQM_cfg::p1, SiStripOfflineCRack_cfg::p2, chargedHadronTrackResolutionFilter_cfi::p3, and resetStatus().

216  {
217  // add many measured particles
218 
219  resetStatus();
220 
221  if (p1 != nullptr)
222  _measParticles.push_back(p1);
223  if (p2 != nullptr)
224  _measParticles.push_back(p2);
225  if (p3 != nullptr)
226  _measParticles.push_back(p3);
227  if (p4 != nullptr)
228  _measParticles.push_back(p4);
229  if (p5 != nullptr)
230  _measParticles.push_back(p5);
231  if (p6 != nullptr)
232  _measParticles.push_back(p6);
233  if (p7 != nullptr)
234  _measParticles.push_back(p7);
235  if (p8 != nullptr)
236  _measParticles.push_back(p8);
237  if (p9 != nullptr)
238  _measParticles.push_back(p9);
239 
240  countMeasParams();
241 }
void countMeasParams()
Definition: TKinFitter.cc:173
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
void resetStatus()
Definition: TKinFitter.cc:147

◆ addUnmeasParticle()

void TKinFitter::addUnmeasParticle ( TAbsFitParticle particle)

Definition at line 243 of file TKinFitter.cc.

References _unmeasParticles, countUnmeasParams(), and resetStatus().

Referenced by TSLToyGen::doToyExperiments().

243  {
244  // add one unmeasured particle
245 
246  resetStatus();
247 
248  if (particle != nullptr) {
249  _unmeasParticles.push_back(particle);
250  } else {
251  edm::LogError("NullPointer") << "Unmeasured particle points to NULL. It will not be added to the KinFitter.";
252  }
253 
255 }
Log< level::Error, false > LogError
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154
void countUnmeasParams()
Definition: TKinFitter.cc:185
void resetStatus()
Definition: TKinFitter.cc:147

◆ addUnmeasParticles()

void TKinFitter::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 at line 257 of file TKinFitter.cc.

References _unmeasParticles, countUnmeasParams(), LaserDQM_cfg::p1, SiStripOfflineCRack_cfg::p2, chargedHadronTrackResolutionFilter_cfi::p3, and resetStatus().

265  {
266  // add many unmeasured particles
267 
268  resetStatus();
269 
270  if (p1 != nullptr)
271  _unmeasParticles.push_back(p1);
272  if (p2 != nullptr)
273  _unmeasParticles.push_back(p2);
274  if (p3 != nullptr)
275  _unmeasParticles.push_back(p3);
276  if (p4 != nullptr)
277  _unmeasParticles.push_back(p4);
278  if (p5 != nullptr)
279  _unmeasParticles.push_back(p5);
280  if (p6 != nullptr)
281  _unmeasParticles.push_back(p6);
282  if (p7 != nullptr)
283  _unmeasParticles.push_back(p7);
284  if (p8 != nullptr)
285  _unmeasParticles.push_back(p8);
286  if (p9 != nullptr)
287  _unmeasParticles.push_back(p9);
288 
290 }
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154
void countUnmeasParams()
Definition: TKinFitter.cc:185
void resetStatus()
Definition: TKinFitter.cc:147

◆ applyDeltaA()

Bool_t TKinFitter::applyDeltaA ( )
protected

Definition at line 1005 of file TKinFitter.cc.

References _deltaA, _unmeasParticles, TAbsFitParticle::applycorr(), TAbsFitParticle::getNPar(), and submitPVValidationJobs::params.

Referenced by fit().

1005  {
1006  //apply corrections to unmeasured particles
1007 
1008  int offsetParam = 0;
1009  for (unsigned int indexParticle = 0; indexParticle < _unmeasParticles.size(); indexParticle++) {
1010  TAbsFitParticle* particle = _unmeasParticles[indexParticle];
1011  Int_t nbParams = particle->getNPar();
1012  TMatrixD params(nbParams, 1);
1013  for (Int_t index = 0; index < nbParams; index++) {
1014  params(index, 0) = _deltaA(index + offsetParam, 0);
1015  }
1016  particle->applycorr(&params);
1017  offsetParam += nbParams;
1018  }
1019 
1020  return true;
1021 }
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154
TMatrixD _deltaA
Definition: TKinFitter.h:139
virtual void applycorr(TMatrixD *corrMatrix)
Int_t getNPar() const

◆ applyDeltaY()

Bool_t TKinFitter::applyDeltaY ( )
protected

Definition at line 1023 of file TKinFitter.cc.

References _constraints, _deltaY, _measParticles, TAbsFitParticle::applycorr(), HLT_2024v13_cff::constraint, TAbsFitParticle::getNPar(), and submitPVValidationJobs::params.

Referenced by fit().

1023  {
1024  //apply corrections to measured particles
1025 
1026  int offsetParam = 0;
1027  for (unsigned int indexParticle = 0; indexParticle < _measParticles.size(); indexParticle++) {
1028  TAbsFitParticle* particle = _measParticles[indexParticle];
1029  Int_t nbParams = particle->getNPar();
1030  TMatrixD params(nbParams, 1);
1031  for (Int_t index = 0; index < nbParams; index++) {
1032  params(index, 0) = _deltaY(index + offsetParam, 0);
1033  }
1034  particle->applycorr(&params);
1035  offsetParam += nbParams;
1036  }
1037 
1038  for (unsigned int indexConstraint = 0; indexConstraint < _constraints.size(); indexConstraint++) {
1039  TAbsFitConstraint* constraint = _constraints[indexConstraint];
1040  Int_t nbParams = constraint->getNPar();
1041  if (nbParams > 0) {
1042  TMatrixD params(nbParams, 1);
1043  for (Int_t index = 0; index < nbParams; index++) {
1044  params(index, 0) = _deltaY(index + offsetParam, 0);
1045  }
1046  constraint->applyDeltaAlpha(&params);
1047  offsetParam += nbParams;
1048  }
1049  }
1050 
1051  return true;
1052 }
TMatrixD _deltaY
Definition: TKinFitter.h:140
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
virtual void applycorr(TMatrixD *corrMatrix)
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
Int_t getNPar() const

◆ applyVFit()

void TKinFitter::applyVFit ( )
protected

Definition at line 959 of file TKinFitter.cc.

References _constraints, _measParticles, _unmeasParticles, _yaVFit, HltBtagPostValidation_cff::c, HLT_2024v13_cff::constraint, TAbsFitParticle::getNPar(), alignCSCRings::r, and TAbsFitParticle::setCovMatrixFit().

Referenced by fit().

959  {
960  // apply fit covariance matrix to measured and unmeasured particles
961 
962  int offsetParam = 0;
963  for (unsigned int indexParticle = 0; indexParticle < _measParticles.size(); indexParticle++) {
964  TAbsFitParticle* particle = _measParticles[indexParticle];
965  Int_t nbParams = particle->getNPar();
966  TMatrixD vfit(nbParams, nbParams);
967  for (Int_t c = 0; c < nbParams; c++) {
968  for (Int_t r = 0; r < nbParams; r++) {
969  vfit(r, c) = _yaVFit(r + offsetParam, c + offsetParam);
970  }
971  }
972  particle->setCovMatrixFit(&vfit);
973  offsetParam += nbParams;
974  }
975 
976  for (unsigned int indexConstraint = 0; indexConstraint < _constraints.size(); indexConstraint++) {
977  TAbsFitConstraint* constraint = _constraints[indexConstraint];
978  Int_t nbParams = constraint->getNPar();
979  if (nbParams > 0) {
980  TMatrixD vfit(nbParams, nbParams);
981  for (Int_t c = 0; c < nbParams; c++) {
982  for (Int_t r = 0; r < nbParams; r++) {
983  vfit(r, c) = _yaVFit(r + offsetParam, c + offsetParam);
984  }
985  }
986  constraint->setCovMatrixFit(&vfit);
987  offsetParam += nbParams;
988  }
989  }
990 
991  for (unsigned int indexParticle = 0; indexParticle < _unmeasParticles.size(); indexParticle++) {
992  TAbsFitParticle* particle = _unmeasParticles[indexParticle];
993  Int_t nbParams = particle->getNPar();
994  TMatrixD vfit(nbParams, nbParams);
995  for (Int_t c = 0; c < nbParams; c++) {
996  for (Int_t r = 0; r < nbParams; r++) {
997  vfit(r, c) = _yaVFit(r + offsetParam, c + offsetParam);
998  }
999  }
1000  particle->setCovMatrixFit(&vfit);
1001  offsetParam += nbParams;
1002  }
1003 }
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
TMatrixD _yaVFit
Definition: TKinFitter.h:147
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
virtual void setCovMatrixFit(const TMatrixD *theCovMatrixFit)
Int_t getNPar() const

◆ calcA()

Bool_t TKinFitter::calcA ( )
protected

Definition at line 521 of file TKinFitter.cc.

References _A, _AT, _constraints, _nParA, _unmeasParticles, TAbsFitParticle::getDerivative(), and JetComb::kMult.

Referenced by fit().

521  {
522  // Calculate the Jacobi matrix of unmeasured parameters df_i/da_i
523  // Row i contains the derivatives of constraint f_i. Column q contains
524  // the derivative wrt. a_q.
525 
526  _A.ResizeTo(_constraints.size(), _nParA);
527 
528  for (unsigned int indexConstr = 0; indexConstr < _constraints.size(); indexConstr++) {
529  int offsetParam = 0;
530  for (unsigned int indexParticle = 0; indexParticle < _unmeasParticles.size(); indexParticle++) {
531  // Calculate matrix product df/dP * dP/dy = (df/dr, df/dtheta, df/dphi, ...)
532 
533  TAbsFitParticle* particle = _unmeasParticles[indexParticle];
534  TMatrixD* derivParticle = particle->getDerivative();
535  TMatrixD* derivConstr = _constraints[indexConstr]->getDerivative(particle);
536  TMatrixD deriv(*derivConstr, TMatrixD::kMult, *derivParticle);
537 
538  for (int indexParam = 0; indexParam < deriv.GetNcols(); indexParam++) {
539  _A(indexConstr, indexParam + offsetParam) = deriv(0, indexParam);
540  }
541  offsetParam += deriv.GetNcols();
542 
543  delete derivParticle;
544  delete derivConstr;
545  }
546  }
547 
548  // Calculate transposed matrix
549  TMatrixD AT(TMatrixD::kTransposed, _A);
550  _AT.ResizeTo(AT);
551  _AT = AT;
552 
553  return true;
554 }
Int_t _nParA
Definition: TKinFitter.h:149
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154
virtual TMatrixD * getDerivative()=0
TMatrixD _A
Definition: TKinFitter.h:114
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
TMatrixD _AT
Definition: TKinFitter.h:115

◆ calcB()

Bool_t TKinFitter::calcB ( )
protected

Definition at line 556 of file TKinFitter.cc.

References _B, _BT, _constraints, _measParticles, _nParB, _verbosity, HLT_2024v13_cff::constraint, TAbsFitParticle::getDerivative(), JetComb::kMult, and printMatrix().

Referenced by fit().

556  {
557  // Calculate the Jacobi matrix of measured parameters df_i/da_i
558  // Row i contains the derivatives of constraint f_i. Column q contains
559  // the derivative wrt. a_q.
560 
561  _B.ResizeTo(_constraints.size(), _nParB);
562 
563  int offsetParam = 0;
564  for (unsigned int indexConstr = 0; indexConstr < _constraints.size(); indexConstr++) {
565  offsetParam = 0;
566  for (unsigned int indexParticle = 0; indexParticle < _measParticles.size(); indexParticle++) {
567  // Calculate matrix product df/dP * dP/dy = (df/dr, df/dtheta, df/dphi, ...)
568  TAbsFitParticle* particle = _measParticles[indexParticle];
569  TMatrixD* derivParticle = particle->getDerivative();
570  TMatrixD* derivConstr = _constraints[indexConstr]->getDerivative(particle);
571  TMatrixD deriv(*derivConstr, TMatrixD::kMult, *derivParticle);
572  if (_verbosity >= 3) {
573  TString matrixName = "B deriv: Particle -> ";
574  matrixName += particle->GetName();
575  printMatrix(*derivParticle, matrixName);
576  matrixName = "B deriv: Constraint -> ";
577  matrixName += _constraints[indexConstr]->GetName();
578  matrixName += " , Particle -> ";
579  matrixName += particle->GetName();
580  printMatrix(*derivConstr, matrixName);
581  }
582  for (int indexParam = 0; indexParam < deriv.GetNcols(); indexParam++) {
583  _B(indexConstr, indexParam + offsetParam) = deriv(0, indexParam);
584  }
585  offsetParam += deriv.GetNcols();
586 
587  delete derivParticle;
588  delete derivConstr;
589  }
590  }
591 
592  for (unsigned int iC = 0; iC < _constraints.size(); iC++) {
594  TMatrixD* deriv = constraint->getDerivativeAlpha();
595 
596  if (deriv != nullptr) {
597  if (_verbosity >= 3) {
598  TString matrixName = "B deriv alpha: Constraint -> ";
599  matrixName += constraint->GetName();
600  printMatrix(*deriv, matrixName);
601  }
602  for (int indexParam = 0; indexParam < deriv->GetNcols(); indexParam++) {
603  _B(iC, indexParam + offsetParam) = (*deriv)(0, indexParam);
604  }
605  offsetParam += deriv->GetNcols();
606 
607  delete deriv;
608  }
609  }
610 
611  TMatrixD BT(TMatrixD::kTransposed, _B);
612  _BT.ResizeTo(BT);
613  _BT = BT;
614 
615  return true;
616 }
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
virtual TMatrixD * getDerivative()=0
TMatrixD _B
Definition: TKinFitter.h:116
void printMatrix(const TMatrixD &matrix, const TString &name="")
Definition: TKinFitter.cc:1205
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
TMatrixD _BT
Definition: TKinFitter.h:117
Int_t _verbosity
Definition: TKinFitter.h:112
Int_t _nParB
Definition: TKinFitter.h:150

◆ calcC()

Bool_t TKinFitter::calcC ( )
protected

Definition at line 781 of file TKinFitter.cc.

References _A, _B, _c, _constraints, _measParticles, _nParA, _nParB, _unmeasParticles, _verbosity, a, simBeamSpotPI::alpha, HLT_2024v13_cff::constraint, TAbsFitParticle::getParCurr(), TAbsFitParticle::getParIni(), JetComb::kMult, printMatrix(), and y.

Referenced by fit().

781  {
782  // Calculate the matrix c = A*deltaAStar + B*deltaYStar - fStar
783 
784  int offsetParam = 0;
785 
786  // calculate delta(a*), = 0 in the first iteration
787  TMatrixD deltaastar(1, 1);
788  if (_nParA > 0) {
789  deltaastar.ResizeTo(_nParA, 1);
790  for (unsigned int indexParticle = 0; indexParticle < _unmeasParticles.size(); indexParticle++) {
791  TAbsFitParticle* particle = _unmeasParticles[indexParticle];
792  const TMatrixD* astar = particle->getParCurr();
793  const TMatrixD* a = particle->getParIni();
794  TMatrixD deltaastarpart(*astar);
795  deltaastarpart -= *a;
796 
797  for (int indexParam = 0; indexParam < deltaastarpart.GetNrows(); indexParam++) {
798  deltaastar(indexParam + offsetParam, 0) = deltaastarpart(indexParam, 0);
799  }
800  offsetParam += deltaastarpart.GetNrows();
801  }
802 
803  if (_verbosity >= 3) {
804  printMatrix(deltaastar, "deltaastar");
805  }
806  }
807 
808  // calculate delta(y*), = 0 in the first iteration
809  TMatrixD deltaystar(_nParB, 1);
810  offsetParam = 0;
811  for (unsigned int indexParticle = 0; indexParticle < _measParticles.size(); indexParticle++) {
812  TAbsFitParticle* particle = _measParticles[indexParticle];
813  const TMatrixD* ystar = particle->getParCurr();
814  const TMatrixD* y = particle->getParIni();
815  TMatrixD deltaystarpart(*ystar);
816  deltaystarpart -= *y;
817 
818  for (int indexParam = 0; indexParam < deltaystarpart.GetNrows(); indexParam++) {
819  deltaystar(indexParam + offsetParam, 0) = deltaystarpart(indexParam, 0);
820  }
821  offsetParam += deltaystarpart.GetNrows();
822  }
823 
824  for (unsigned int iC = 0; iC < _constraints.size(); iC++) {
826 
827  if (constraint->getNPar() > 0) {
828  const TMatrixD* alphastar = constraint->getParCurr();
829  const TMatrixD* alpha = constraint->getParIni();
830 
831  TMatrixD deltaalphastarpart(*alphastar);
832  deltaalphastarpart -= *alpha;
833 
834  for (int indexParam = 0; indexParam < deltaalphastarpart.GetNrows(); indexParam++) {
835  deltaystar(indexParam + offsetParam, 0) = deltaalphastarpart(indexParam, 0);
836  }
837  offsetParam += deltaalphastarpart.GetNrows();
838  }
839  }
840 
841  if (_verbosity >= 3) {
842  printMatrix(deltaystar, "deltaystar");
843  }
844 
845  // calculate f*
846  TMatrixD fstar(_constraints.size(), 1);
847  for (unsigned int indexConstr = 0; indexConstr < _constraints.size(); indexConstr++) {
848  fstar(indexConstr, 0) = _constraints[indexConstr]->getCurrentValue();
849  }
850 
851  // calculate c
852  _c.ResizeTo(fstar);
853  _c = fstar;
854  _c *= (-1.);
855  TMatrixD Bdeltaystar(_B, TMatrixD::kMult, deltaystar);
856  _c += Bdeltaystar;
857  if (_nParA) {
858  TMatrixD Adeltaastar(_A, TMatrixD::kMult, deltaastar);
859  _c += Adeltaastar;
860  }
861 
862  return true;
863 }
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
Int_t _nParA
Definition: TKinFitter.h:149
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154
TMatrixD _B
Definition: TKinFitter.h:116
TMatrixD _c
Definition: TKinFitter.h:124
TMatrixD _A
Definition: TKinFitter.h:114
void printMatrix(const TMatrixD &matrix, const TString &name="")
Definition: TKinFitter.cc:1205
const TMatrixD * getParIni()
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
double a
Definition: hdecay.h:121
Int_t _verbosity
Definition: TKinFitter.h:112
Int_t _nParB
Definition: TKinFitter.h:150
const TMatrixD * getParCurr()

◆ calcC11()

Bool_t TKinFitter::calcC11 ( )
protected

Definition at line 658 of file TKinFitter.cc.

References _A, _AT, _B, _BT, _C11, _C11T, _nParA, _V, _VAinv, _VB, JetComb::kMult, and callgraph::m2.

Referenced by fit().

658  {
659  // Calculate the matrix C11 = V^(-1) - V^(-1)*BT*VB*B*V^(-1) + V^(-1)*BT*VB*A*VA^(-1)*AT*VB*B*V^(-1)
660 
661  TMatrixD VBT(_V, TMatrixD::kMult, _BT);
662  TMatrixD VBB(_VB, TMatrixD::kMult, _B);
663  TMatrixD VBTVBB(VBT, TMatrixD::kMult, VBB);
664  TMatrixD m2(VBTVBB, TMatrixD::kMult, _V);
665 
666  _C11.ResizeTo(_V);
667  _C11 = _V;
668  _C11 -= m2;
669 
670  if (_nParA > 0) {
671  TMatrixD VBA(_VB, TMatrixD::kMult, _A);
672  TMatrixD VBTVBA(VBT, TMatrixD::kMult, VBA);
673  TMatrixD VAinvAT(_VAinv, TMatrixD::kMult, _AT);
674  TMatrixD VBTVBAVAinvAT(VBTVBA, TMatrixD::kMult, VAinvAT);
675  TMatrixD VBTVBAVAinvATVBB(VBTVBAVAinvAT, TMatrixD::kMult, VBB);
676  TMatrixD m3(VBTVBAVAinvATVBB, TMatrixD::kMult, _V);
677  _C11 += m3;
678  }
679 
680  TMatrixD C11T(TMatrixD::kTransposed, _C11);
681  _C11T.ResizeTo(C11T);
682  _C11T = C11T;
683 
684  return true;
685 }
TMatrixD _C11
Definition: TKinFitter.h:126
Int_t _nParA
Definition: TKinFitter.h:149
TMatrixD _V
Definition: TKinFitter.h:118
TMatrixD _VB
Definition: TKinFitter.h:120
TMatrixD _B
Definition: TKinFitter.h:116
TMatrixD _VAinv
Definition: TKinFitter.h:123
TMatrixD _A
Definition: TKinFitter.h:114
TMatrixD _BT
Definition: TKinFitter.h:117
TMatrixD _AT
Definition: TKinFitter.h:115
TMatrixD _C11T
Definition: TKinFitter.h:127

◆ calcC21()

Bool_t TKinFitter::calcC21 ( )
protected

Definition at line 687 of file TKinFitter.cc.

References _AT, _B, _C21, _C21T, _V, _VAinv, _VB, and JetComb::kMult.

Referenced by fit().

687  {
688  // Calculate the matrix C21 = -VA^(-1)*AT*VB*B*V^(-1)
689 
690  TMatrixD VAinvAT(_VAinv, TMatrixD::kMult, _AT);
691  TMatrixD VBB(_VB, TMatrixD::kMult, _B);
692  TMatrixD VAinvATVBB(VAinvAT, TMatrixD::kMult, VBB);
693  TMatrixD C21(VAinvATVBB, TMatrixD::kMult, _V);
694  C21 *= -1.;
695  _C21.ResizeTo(C21);
696  _C21 = C21;
697 
698  TMatrixD C21T(TMatrixD::kTransposed, _C21);
699  _C21T.ResizeTo(C21T);
700  _C21T = C21T;
701 
702  return true;
703 }
TMatrixD _V
Definition: TKinFitter.h:118
TMatrixD _C21T
Definition: TKinFitter.h:129
TMatrixD _VB
Definition: TKinFitter.h:120
TMatrixD _B
Definition: TKinFitter.h:116
TMatrixD _VAinv
Definition: TKinFitter.h:123
TMatrixD _AT
Definition: TKinFitter.h:115
TMatrixD _C21
Definition: TKinFitter.h:128

◆ calcC22()

Bool_t TKinFitter::calcC22 ( )
protected

Definition at line 705 of file TKinFitter.cc.

References _C22, _C22T, and _VAinv.

Referenced by fit().

705  {
706  // Calculate the matrix C22 = VA^(-1)
707 
708  _C22.ResizeTo(_VAinv);
709  _C22 = _VAinv;
710 
711  TMatrixD C22T(TMatrixD::kTransposed, _C22);
712  _C22T.ResizeTo(C22T);
713  _C22T = C22T;
714 
715  return true;
716 }
TMatrixD _C22T
Definition: TKinFitter.h:131
TMatrixD _VAinv
Definition: TKinFitter.h:123
TMatrixD _C22
Definition: TKinFitter.h:130

◆ calcC31()

Bool_t TKinFitter::calcC31 ( )
protected

Definition at line 718 of file TKinFitter.cc.

References _A, _AT, _B, _C31, _C31T, _nParA, _V, _VAinv, _VB, JetComb::kMult, and callgraph::m2.

Referenced by fit().

718  {
719  // Calculate the matrix C31 = VB*B*V^(-1) - VB*A*VA^(-1)*AT*VB*B*V^(-1)
720 
721  TMatrixD VbB(_VB, TMatrixD::kMult, _B);
722  TMatrixD m1(VbB, TMatrixD::kMult, _V);
723 
724  _C31.ResizeTo(m1);
725  _C31 = m1;
726 
727  if (_nParA > 0) {
728  TMatrixD VbA(_VB, TMatrixD::kMult, _A);
729  TMatrixD VAinvAT(_VAinv, TMatrixD::kMult, _AT);
730  TMatrixD VbBV(VbB, TMatrixD::kMult, _V);
731  TMatrixD VbAVAinvAT(VbA, TMatrixD::kMult, VAinvAT);
732  TMatrixD m2(VbAVAinvAT, TMatrixD::kMult, VbBV);
733 
734  _C31 -= m2;
735  }
736 
737  TMatrixD C31T(TMatrixD::kTransposed, _C31);
738  _C31T.ResizeTo(C31T);
739  _C31T = C31T;
740 
741  return true;
742 }
Int_t _nParA
Definition: TKinFitter.h:149
TMatrixD _V
Definition: TKinFitter.h:118
TMatrixD _VB
Definition: TKinFitter.h:120
TMatrixD _C31T
Definition: TKinFitter.h:133
TMatrixD _B
Definition: TKinFitter.h:116
TMatrixD _VAinv
Definition: TKinFitter.h:123
TMatrixD _A
Definition: TKinFitter.h:114
TMatrixD _C31
Definition: TKinFitter.h:132
TMatrixD _AT
Definition: TKinFitter.h:115

◆ calcC32()

Bool_t TKinFitter::calcC32 ( )
protected

Definition at line 744 of file TKinFitter.cc.

References _A, _C32, _C32T, _VAinv, _VB, and JetComb::kMult.

Referenced by fit().

744  {
745  // Calculate the matrix C32 = VB*A*VA^(-1)
746 
747  TMatrixD VbA(_VB, TMatrixD::kMult, _A);
748  TMatrixD C32(VbA, TMatrixD::kMult, _VAinv);
749  _C32.ResizeTo(C32);
750  _C32 = C32;
751 
752  TMatrixD C32T(TMatrixD::kTransposed, _C32);
753  _C32T.ResizeTo(C32T);
754  _C32T = C32T;
755 
756  return true;
757 }
TMatrixD _C32T
Definition: TKinFitter.h:135
TMatrixD _VB
Definition: TKinFitter.h:120
TMatrixD _C32
Definition: TKinFitter.h:134
TMatrixD _VAinv
Definition: TKinFitter.h:123
TMatrixD _A
Definition: TKinFitter.h:114

◆ calcC33()

Bool_t TKinFitter::calcC33 ( )
protected

Definition at line 759 of file TKinFitter.cc.

References _A, _AT, _C33, _C33T, _nParA, _VAinv, _VB, and JetComb::kMult.

Referenced by fit().

759  {
760  // Calculate the matrix C33 = -VB + VB*A*VA^(-1)*AT*VB
761 
762  _C33.ResizeTo(_VB);
763  _C33 = _VB;
764  _C33 *= -1.;
765 
766  if (_nParA > 0) {
767  TMatrixD VbA(_VB, TMatrixD::kMult, _A);
768  TMatrixD VAinvAT(_VAinv, TMatrixD::kMult, _AT);
769  TMatrixD VbAVAinvAT(VbA, TMatrixD::kMult, VAinvAT);
770  TMatrixD C33(VbAVAinvAT, TMatrixD::kMult, _VB);
771  _C33 += C33;
772  }
773 
774  TMatrixD C33T(TMatrixD::kTransposed, _C33);
775  _C33T.ResizeTo(C33T);
776  _C33T = C33T;
777 
778  return true;
779 }
Int_t _nParA
Definition: TKinFitter.h:149
TMatrixD _C33T
Definition: TKinFitter.h:137
TMatrixD _VB
Definition: TKinFitter.h:120
TMatrixD _C33
Definition: TKinFitter.h:136
TMatrixD _VAinv
Definition: TKinFitter.h:123
TMatrixD _A
Definition: TKinFitter.h:114
TMatrixD _AT
Definition: TKinFitter.h:115

◆ calcDeltaA()

Bool_t TKinFitter::calcDeltaA ( )
protected

Definition at line 865 of file TKinFitter.cc.

References _c, _C32T, _deltaA, _deltaAstar, _nbIter, and JetComb::kMult.

Referenced by fit().

865  {
866  // Calculate the matrix deltaA = C32T * c
867  // (corrections to unmeasured parameters)
868 
869  TMatrixD deltaA(_C32T, TMatrixD::kMult, _c);
870  _deltaA.ResizeTo(deltaA);
871 
872  if (_nbIter == 0) {
873  _deltaAstar.ResizeTo(deltaA);
874  _deltaAstar.Zero();
875  } else
877 
878  _deltaA = deltaA;
879 
880  return true;
881 }
TMatrixD _C32T
Definition: TKinFitter.h:135
TMatrixD _deltaA
Definition: TKinFitter.h:139
TMatrixD _deltaAstar
Definition: TKinFitter.h:141
TMatrixD _c
Definition: TKinFitter.h:124
Int_t _nbIter
Definition: TKinFitter.h:157

◆ calcDeltaY()

Bool_t TKinFitter::calcDeltaY ( )
protected

Definition at line 883 of file TKinFitter.cc.

References _c, _C31T, _deltaY, _deltaYstar, _nbIter, and JetComb::kMult.

Referenced by fit().

883  {
884  // Calculate the matrix deltaY = C31T * c
885  // (corrections to measured parameters)
886 
887  TMatrixD deltaY(_C31T, TMatrixD::kMult, _c);
888  _deltaY.ResizeTo(deltaY);
889 
890  if (_nbIter == 0) {
891  _deltaYstar.ResizeTo(deltaY);
892  _deltaYstar.Zero();
893  } else
895 
896  _deltaY = deltaY;
897 
898  return true;
899 }
TMatrixD _deltaY
Definition: TKinFitter.h:140
TMatrixD _C31T
Definition: TKinFitter.h:133
TMatrixD _c
Definition: TKinFitter.h:124
TMatrixD _deltaYstar
Definition: TKinFitter.h:142
Int_t _nbIter
Definition: TKinFitter.h:157

◆ calcLambda()

Bool_t TKinFitter::calcLambda ( )
protected

Definition at line 901 of file TKinFitter.cc.

References _c, _C33, _lambda, _lambdaT, and JetComb::kMult.

Referenced by fit().

901  {
902  // Calculate the matrix Lambda = C33 * c
903  // (Lagrange Multipliers)
904 
905  TMatrixD lambda(_C33, TMatrixD::kMult, _c);
906  _lambda.ResizeTo(lambda);
907  _lambda = lambda;
908 
909  TMatrixD lambdaT(TMatrixD::kTransposed, _lambda);
910  _lambdaT.ResizeTo(lambdaT);
911  _lambdaT = lambdaT;
912 
913  return true;
914 }
TMatrixD _lambda
Definition: TKinFitter.h:143
TMatrixD _C33
Definition: TKinFitter.h:136
TMatrixD _c
Definition: TKinFitter.h:124
TMatrixD _lambdaT
Definition: TKinFitter.h:144

◆ calcV()

Bool_t TKinFitter::calcV ( )
protected

Definition at line 474 of file TKinFitter.cc.

References _constraints, _measParticles, _nParB, _status, _V, _Vinv, HLT_2024v13_cff::constraint, MillePedeFileConverter_cfg::e, TAbsFitParticle::getCovMatrix(), and TAbsFitParticle::getNPar().

Referenced by fit().

474  {
475  // Combines the covariance matrices of all measured particles
476 
477  _V.ResizeTo(_nParB, _nParB);
478  _V.Zero();
479 
480  Int_t offsetP = 0;
481  for (unsigned int iP = 0; iP < _measParticles.size(); iP++) {
482  TAbsFitParticle* particle = _measParticles[iP];
483  Int_t nParP = particle->getNPar();
484  const TMatrixD* covMatrix = particle->getCovMatrix();
485 
486  for (int iX = offsetP; iX < offsetP + nParP; iX++) {
487  for (int iY = offsetP; iY < offsetP + nParP; iY++) {
488  _V(iX, iY) = (*covMatrix)(iX - offsetP, iY - offsetP);
489  }
490  }
491 
492  offsetP += nParP;
493  }
494 
495  for (unsigned int iC = 0; iC < _constraints.size(); iC++) {
497  Int_t nParP = constraint->getNPar();
498  const TMatrixD* covMatrix = constraint->getCovMatrix();
499 
500  for (int iX = offsetP; iX < offsetP + nParP; iX++) {
501  for (int iY = offsetP; iY < offsetP + nParP; iY++) {
502  _V(iX, iY) = (*covMatrix)(iX - offsetP, iY - offsetP);
503  }
504  }
505 
506  offsetP += nParP;
507  }
508 
509  _Vinv.ResizeTo(_V);
510  _Vinv = _V;
511  try {
512  _Vinv.Invert();
513  } catch (cms::Exception& e) {
514  edm::LogInfo("KinFitter") << "Failed to invert covariance matrix V. Fit will be aborted.";
515  _status = -10;
516  }
517 
518  return true;
519 }
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
TMatrixD _V
Definition: TKinFitter.h:118
Int_t _status
Definition: TKinFitter.h:156
Log< level::Info, false > LogInfo
virtual const TMatrixD * getCovMatrix() const
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
Int_t _nParB
Definition: TKinFitter.h:150
TMatrixD _Vinv
Definition: TKinFitter.h:119
Int_t getNPar() const

◆ calcVA()

Bool_t TKinFitter::calcVA ( )
protected

Definition at line 638 of file TKinFitter.cc.

References _A, _AT, _status, _VA, _VAinv, _VB, MillePedeFileConverter_cfg::e, and JetComb::kMult.

Referenced by fit().

638  {
639  // Calculate the matrix VA = (A^T*VB*A)
640 
641  TMatrixD ATVB(_AT, TMatrixD::kMult, _VB);
642  TMatrixD VA(ATVB, TMatrixD::kMult, _A);
643  _VA.ResizeTo(VA);
644  _VA = VA;
645 
646  _VAinv.ResizeTo(_VA);
647  _VAinv = _VA;
648  try {
649  _VAinv.Invert();
650  } catch (cms::Exception& e) {
651  edm::LogInfo("KinFitter") << "Failed to invert matrix VA. Fit will be aborted.";
652  _status = -10;
653  }
654 
655  return true;
656 }
TMatrixD _VB
Definition: TKinFitter.h:120
TMatrixD _VA
Definition: TKinFitter.h:122
Int_t _status
Definition: TKinFitter.h:156
TMatrixD _VAinv
Definition: TKinFitter.h:123
TMatrixD _A
Definition: TKinFitter.h:114
Log< level::Info, false > LogInfo
TMatrixD _AT
Definition: TKinFitter.h:115

◆ calcVB()

Bool_t TKinFitter::calcVB ( )
protected

Definition at line 618 of file TKinFitter.cc.

References _B, _BT, _status, _V, _VB, _VBinv, MillePedeFileConverter_cfg::e, and JetComb::kMult.

Referenced by fit().

618  {
619  // Calculate the matrix V_B = (B*V*B^T)^-1
620 
621  TMatrixD BV(_B, TMatrixD::kMult, _V);
622  TMatrixD VBinv(BV, TMatrixD::kMult, _BT);
623  _VBinv.ResizeTo(VBinv);
624  _VBinv = VBinv;
625 
626  _VB.ResizeTo(_VBinv);
627  _VB = _VBinv;
628  try {
629  _VB.Invert();
630  } catch (cms::Exception& e) {
631  edm::LogInfo("KinFitter") << "Failed to invert matrix VB. Fit will be aborted.";
632  _status = -10;
633  }
634 
635  return true;
636 }
TMatrixD _V
Definition: TKinFitter.h:118
TMatrixD _VB
Definition: TKinFitter.h:120
Int_t _status
Definition: TKinFitter.h:156
TMatrixD _B
Definition: TKinFitter.h:116
Log< level::Info, false > LogInfo
TMatrixD _BT
Definition: TKinFitter.h:117
TMatrixD _VBinv
Definition: TKinFitter.h:121

◆ calcVFit()

Bool_t TKinFitter::calcVFit ( )
protected

Definition at line 916 of file TKinFitter.cc.

References _C11, _C21, _C21T, _C22, _C33, _lambdaVFit, _nParA, and _yaVFit.

Referenced by fit().

916  {
917  // Calculate the covariance matrix of fitted parameters
918  //
919  // Vfit(y) = ( C11 C21T )
920  // (a) ( C21 C22 )
921  //
922  // Vfit(lambda) = (-C33)
923 
924  // Calculate covariance matrix of lambda
925  _lambdaVFit.ResizeTo(_C33);
926  _lambdaVFit = _C33;
927  _lambdaVFit *= -1.;
928 
929  // Calculate combined covariance matrix of y and a
930  Int_t nbRows = _C11.GetNrows();
931  Int_t nbCols = _C11.GetNcols();
932  if (_nParA > 0) {
933  nbRows += _C21.GetNrows();
934  nbCols += _C21T.GetNcols();
935  }
936  _yaVFit.ResizeTo(nbRows, nbCols);
937 
938  for (int iRow = 0; iRow < nbRows; iRow++) {
939  for (int iCol = 0; iCol < nbCols; iCol++) {
940  if (iRow >= _C11.GetNrows()) {
941  if (iCol >= _C11.GetNcols()) {
942  _yaVFit(iRow, iCol) = _C22(iRow - _C11.GetNrows(), iCol - _C11.GetNcols());
943  } else {
944  _yaVFit(iRow, iCol) = _C21(iRow - _C11.GetNrows(), iCol);
945  }
946  } else {
947  if (iCol >= _C11.GetNcols()) {
948  _yaVFit(iRow, iCol) = _C21T(iRow, iCol - _C11.GetNcols());
949  } else {
950  _yaVFit(iRow, iCol) = _C11(iRow, iCol);
951  }
952  }
953  }
954  }
955 
956  return true;
957 }
TMatrixD _C11
Definition: TKinFitter.h:126
Int_t _nParA
Definition: TKinFitter.h:149
TMatrixD _C21T
Definition: TKinFitter.h:129
TMatrixD _yaVFit
Definition: TKinFitter.h:147
TMatrixD _C33
Definition: TKinFitter.h:136
TMatrixD _C22
Definition: TKinFitter.h:130
TMatrixD _lambdaVFit
Definition: TKinFitter.h:146
TMatrixD _C21
Definition: TKinFitter.h:128

◆ converged()

Bool_t TKinFitter::converged ( Double_t  F,
Double_t  prevS,
Double_t  currS 
)
protected

Definition at line 1081 of file TKinFitter.cc.

References _maxDeltaS, _maxF, and F().

Referenced by fit().

1081  {
1082  // check whether convergence criteria are fulfilled
1083 
1084  Bool_t isConverged = false;
1085 
1086  // calculate F, delta(a) and delta(y) already applied
1087  isConverged = (F < _maxF);
1088 
1089  // Calculate current Chi^2 and delta(S)
1090  Double_t deltaS = currS - prevS;
1091  isConverged = isConverged && (TMath::Abs(deltaS) < _maxDeltaS);
1092 
1093  return isConverged;
1094 }
Double_t _maxDeltaS
Definition: TKinFitter.h:110
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
Double_t _maxF
Definition: TKinFitter.h:111

◆ countMeasParams()

void TKinFitter::countMeasParams ( )
protected

Definition at line 173 of file TKinFitter.cc.

References _constraints, _measParticles, and _nParB.

Referenced by addConstraint(), addMeasParticle(), and addMeasParticles().

173  {
174  // count number of measured parameters
175 
176  _nParB = 0;
177  for (unsigned int indexParticle = 0; indexParticle < _measParticles.size(); indexParticle++) {
178  _nParB += _measParticles[indexParticle]->getNPar();
179  }
180  for (unsigned int indexConstraint = 0; indexConstraint < _constraints.size(); indexConstraint++) {
181  _nParB += _constraints[indexConstraint]->getNPar();
182  }
183 }
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
Int_t _nParB
Definition: TKinFitter.h:150

◆ countUnmeasParams()

void TKinFitter::countUnmeasParams ( )
protected

Definition at line 185 of file TKinFitter.cc.

References _nParA, and _unmeasParticles.

Referenced by addUnmeasParticle(), and addUnmeasParticles().

185  {
186  // count number of unmeasured parameters
187 
188  _nParA = 0;
189  for (unsigned int indexParticle = 0; indexParticle < _unmeasParticles.size(); indexParticle++) {
190  _nParA += _unmeasParticles[indexParticle]->getNPar();
191  }
192 }
Int_t _nParA
Definition: TKinFitter.h:149
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154

◆ fit()

Int_t TKinFitter::fit ( )

Definition at line 318 of file TKinFitter.cc.

References _A, _B, _c, _C32T, _deltaA, _deltaAstar, _deltaY, _deltaYstar, _lambda, _lambdaT, _maxNbIter, _nbIter, _nParA, _status, _V, _VB, _VBinv, _verbosity, applyDeltaA(), applyDeltaY(), applyVFit(), calcA(), calcB(), calcC(), calcC11(), calcC21(), calcC22(), calcC31(), calcC32(), calcC33(), calcDeltaA(), calcDeltaY(), calcLambda(), calcV(), calcVA(), calcVB(), calcVFit(), converged(), getF(), getS(), print(), printMatrix(), resetParams(), and resetStatus().

Referenced by TSLToyGen::doToyExperiments(), trackingPlots.Iteration::modules(), and CandMassKinFitter::set().

318  {
319  // Perform the fit
320  // Returns:
321  // 0: converged
322  // 1: not converged
323 
324  resetParams();
325  resetStatus();
326 
327  _nbIter = 0;
328  Bool_t isConverged = false;
329  Double_t prevF;
330  Double_t currF = getF();
331  Double_t prevS;
332  Double_t currS = 0.;
333 
334  // Calculate covariance matrix V
335  calcV();
336 
337  // print status
338  if (_verbosity >= 1) {
339  print();
340  }
341 
342  do {
343  // Reset status to "RUNNING"
344  // (if it was not aborted already due to singular covariance matrix)
345  if (_status != -10) {
346  _status = 10;
347  }
348 
349  // Calculate matrices
350  calcB();
351  calcVB();
352  if (_nParA > 0) {
353  calcA();
354  calcVA();
355  calcC32();
356  }
357  calcC31();
358  calcC33();
359  calcC();
360 
361  // Calculate corretion for a, y, and lambda
362  if (_nParA > 0) {
363  calcDeltaA();
364  }
365  calcDeltaY();
366  calcLambda();
367 
368  if (_verbosity >= 3) {
369  printMatrix(_A, "A");
370  printMatrix(_B, "B");
371  printMatrix(_VBinv, "VBinv");
372  printMatrix(_VB, "VB");
373  printMatrix(_V, "V");
374  printMatrix(_deltaY, "deltaY");
375  printMatrix(_deltaA, "deltaA");
376  printMatrix(_C32T, "C32T");
377  printMatrix(_c, "C");
378  }
379 
380  if (_verbosity >= 2) {
381  print();
382  }
383 
384  // Apply calculated corrections to measured and unmeasured particles
385  if (_nParA > 0) {
386  applyDeltaA();
387  }
388  applyDeltaY();
389 
390  _nbIter++;
391 
392  //calculate F and S
393  prevF = currF;
394  currF = getF();
395  prevS = currS;
396  currS = getS();
397 
398  if (TMath::IsNaN(currF)) {
399  edm::LogInfo("KinFitter") << "The current value of F is NaN. Fit will be aborted.";
400  _status = -10;
401  }
402  if (TMath::IsNaN(currS)) {
403  edm::LogInfo("KinFitter") << "The current value of S is NaN. Fit will be aborted.";
404  _status = -10;
405  }
406 
407  // Reduce step width if F is not getting smaller
408  Int_t nstep = 0;
409  while (currF >= prevF) {
410  nstep++;
411  if (nstep == 10)
412  break;
413  if (_nParA > 0)
414  _deltaA -= (0.5) * (_deltaA - _deltaAstar);
415  _deltaY -= (0.5) * (_deltaY - _deltaYstar);
416  _lambda *= 0.5;
417  _lambdaT *= 0.5;
418  if (_nParA > 0)
419  applyDeltaA();
420  applyDeltaY();
421  currF = getF();
422  currS = getS();
423  }
424 
425  // Test convergence
426  isConverged = converged(currF, prevS, currS);
427 
428  } while ((!isConverged) && (_nbIter < _maxNbIter) && (_status != -10));
429 
430  // Calculate covariance matrices
431  calcB();
432  calcVB();
433 
434  if (_nParA > 0) {
435  calcA();
436  calcVA();
437  calcC21();
438  calcC22();
439  calcC32();
440  }
441  calcC11();
442  calcC31();
443  calcC33();
444  calcVFit();
445  applyVFit();
446 
447  // Set status information
448  if (isConverged) {
449  _status = 0;
450  } else if (_status != -10) {
451  _status = 1;
452  }
453 
454  // print status
455  if (_verbosity >= 1) {
456  print();
457  }
458 
459  return _status;
460 }
TMatrixD _deltaY
Definition: TKinFitter.h:140
Bool_t calcC33()
Definition: TKinFitter.cc:759
Bool_t calcV()
Definition: TKinFitter.cc:474
Bool_t converged(Double_t F, Double_t prevS, Double_t currS)
Definition: TKinFitter.cc:1081
Bool_t calcVFit()
Definition: TKinFitter.cc:916
Bool_t calcVB()
Definition: TKinFitter.cc:618
Bool_t calcC11()
Definition: TKinFitter.cc:658
Int_t _nParA
Definition: TKinFitter.h:149
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
TMatrixD _VB
Definition: TKinFitter.h:120
void resetParams()
Definition: TKinFitter.cc:154
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
Int_t _maxNbIter
Definition: TKinFitter.h:109
Bool_t calcB()
Definition: TKinFitter.cc:556
void print()
Definition: TKinFitter.cc:1125
TMatrixD _deltaAstar
Definition: TKinFitter.h:141
Bool_t calcDeltaY()
Definition: TKinFitter.cc:883
Bool_t calcA()
Definition: TKinFitter.cc:521
Bool_t calcLambda()
Definition: TKinFitter.cc:901
Bool_t calcC31()
Definition: TKinFitter.cc:718
Int_t _status
Definition: TKinFitter.h:156
TMatrixD _B
Definition: TKinFitter.h:116
TMatrixD _c
Definition: TKinFitter.h:124
TMatrixD _A
Definition: TKinFitter.h:114
TMatrixD _lambdaT
Definition: TKinFitter.h:144
Log< level::Info, false > LogInfo
Bool_t calcVA()
Definition: TKinFitter.cc:638
void printMatrix(const TMatrixD &matrix, const TString &name="")
Definition: TKinFitter.cc:1205
void resetStatus()
Definition: TKinFitter.cc:147
Bool_t applyDeltaA()
Definition: TKinFitter.cc:1005
TMatrixD _deltaYstar
Definition: TKinFitter.h:142
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
Bool_t calcDeltaA()
Definition: TKinFitter.cc:865

◆ get4Vec()

const TLorentzVector* TKinFitter::get4Vec ( Int_t  index)
inline

Definition at line 66 of file TKinFitter.h.

References _measParticles.

66 { return (_measParticles[index])->getCurr4Vec(); }
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153

◆ getCovMatrix()

const TMatrixD* TKinFitter::getCovMatrix ( )
inline

Definition at line 56 of file TKinFitter.h.

References _V.

56 { return &_V; }
TMatrixD _V
Definition: TKinFitter.h:118

◆ getCovMatrixFit()

const TMatrixD* TKinFitter::getCovMatrixFit ( )
inline

Definition at line 58 of file TKinFitter.h.

References _yaVFit.

58 { return &_yaVFit; }
TMatrixD _yaVFit
Definition: TKinFitter.h:147

◆ getF()

Double_t TKinFitter::getF ( )

Definition at line 1054 of file TKinFitter.cc.

References _constraints, and F().

Referenced by TSLToyGen::doToyExperiments(), fit(), and print().

1054  {
1055  // calculate current absolut value of constraints
1056  // F = Sum[ Abs(f_k( aStar, yStar)) ]
1057 
1058  Double_t F = 0.;
1059  for (unsigned int indexConstr = 0; indexConstr < _constraints.size(); indexConstr++) {
1060  F += TMath::Abs(_constraints[indexConstr]->getCurrentValue());
1061  }
1062 
1063  return F;
1064 }
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163

◆ getMaxDeltaS()

Double_t TKinFitter::getMaxDeltaS ( )
inline

Definition at line 53 of file TKinFitter.h.

References _maxDeltaS.

53 { return _maxDeltaS; }
Double_t _maxDeltaS
Definition: TKinFitter.h:110

◆ getMaxF()

Double_t TKinFitter::getMaxF ( )
inline

Definition at line 55 of file TKinFitter.h.

References _maxF.

Referenced by TSLToyGen::doToyExperiments().

55 { return _maxF; }
Double_t _maxF
Definition: TKinFitter.h:111

◆ getMaxNumberIter()

Int_t TKinFitter::getMaxNumberIter ( )
inline

Definition at line 49 of file TKinFitter.h.

References _maxNbIter.

49 { return _maxNbIter; }
Int_t _maxNbIter
Definition: TKinFitter.h:109

◆ getMeasParticle()

const TAbsFitParticle* TKinFitter::getMeasParticle ( Int_t  index)
inline

Definition at line 65 of file TKinFitter.h.

References _measParticles.

65 { return _measParticles[index]; }
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153

◆ getNbIter()

Int_t TKinFitter::getNbIter ( )
inline

Definition at line 50 of file TKinFitter.h.

References _nbIter.

Referenced by TSLToyGen::doToyExperiments().

50 { return _nbIter; }
Int_t _nbIter
Definition: TKinFitter.h:157

◆ getNDF()

Int_t TKinFitter::getNDF ( )
inline

Definition at line 45 of file TKinFitter.h.

References _constraints, and _nParA.

Referenced by TSLToyGen::doToyExperiments(), print(), and CandMassKinFitter::set().

45 { return (_constraints.size() - _nParA); }
Int_t _nParA
Definition: TKinFitter.h:149
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152

◆ getNParA()

Int_t TKinFitter::getNParA ( )
inline

Definition at line 46 of file TKinFitter.h.

References _nParA.

46 { return _nParA; }
Int_t _nParA
Definition: TKinFitter.h:149

◆ getNParB()

Int_t TKinFitter::getNParB ( )
inline

Definition at line 47 of file TKinFitter.h.

References _nParB.

47 { return _nParB; }
Int_t _nParB
Definition: TKinFitter.h:150

◆ getS()

Double_t TKinFitter::getS ( )

Definition at line 1066 of file TKinFitter.cc.

References _deltaY, _nbIter, _Vinv, and JetComb::kMult.

Referenced by TSLToyGen::doToyExperiments(), fit(), print(), and CandMassKinFitter::set().

1066  {
1067  // calculate current value of Chi2
1068  // S = deltaYT * V^-1 * deltaY
1069 
1070  Double_t S = 0.;
1071 
1072  if (_nbIter > 0) {
1073  TMatrixD deltaYTVinv(_deltaY, TMatrixD::kTransposeMult, _Vinv);
1074  TMatrixD S2(deltaYTVinv, TMatrixD::kMult, _deltaY);
1075  S = S2(0, 0);
1076  }
1077 
1078  return S;
1079 }
TMatrixD _deltaY
Definition: TKinFitter.h:140
Int_t _nbIter
Definition: TKinFitter.h:157
TMatrixD _Vinv
Definition: TKinFitter.h:119

◆ getStatus()

Int_t TKinFitter::getStatus ( )
inline

Definition at line 51 of file TKinFitter.h.

References _status.

Referenced by TSLToyGen::doToyExperiments().

51 { return _status; }
Int_t _status
Definition: TKinFitter.h:156

◆ getStatusString()

TString TKinFitter::getStatusString ( )
protected

Definition at line 1096 of file TKinFitter.cc.

References _status.

Referenced by print().

1096  {
1097  TString statusstring = "";
1098 
1099  switch (_status) {
1100  case -1: {
1101  statusstring = "NO FIT PERFORMED";
1102  break;
1103  }
1104  case 10: {
1105  statusstring = "RUNNING";
1106  break;
1107  }
1108  case -10: {
1109  statusstring = "ABORTED";
1110  break;
1111  }
1112  case 0: {
1113  statusstring = "CONVERGED";
1114  break;
1115  }
1116  case 1: {
1117  statusstring = "NOT CONVERGED";
1118  break;
1119  }
1120  }
1121 
1122  return statusstring;
1123 }
Int_t _status
Definition: TKinFitter.h:156

◆ getUnmeasParticle()

const TAbsFitParticle* TKinFitter::getUnmeasParticle ( Int_t  index)
inline

Definition at line 69 of file TKinFitter.h.

References _unmeasParticles.

69 { return _unmeasParticles[index]; }
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154

◆ getVerbosity()

Int_t TKinFitter::getVerbosity ( )
inline

Definition at line 62 of file TKinFitter.h.

References _verbosity.

62 { return _verbosity; }
Int_t _verbosity
Definition: TKinFitter.h:112

◆ nbConstraints()

Int_t TKinFitter::nbConstraints ( )
inline

Definition at line 70 of file TKinFitter.h.

References _constraints.

70 { return _constraints.size(); }
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152

◆ nbMeasParticles()

Int_t TKinFitter::nbMeasParticles ( )
inline

Definition at line 64 of file TKinFitter.h.

References _measParticles.

64 { return _measParticles.size(); }
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153

◆ nbUnmeasParticles()

Int_t TKinFitter::nbUnmeasParticles ( )
inline

Definition at line 68 of file TKinFitter.h.

References _unmeasParticles.

68 { return _unmeasParticles.size(); }
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154

◆ print()

void TKinFitter::print ( void  )

Definition at line 1125 of file TKinFitter.cc.

References _constraints, _measParticles, _nbIter, _nParB, _status, _unmeasParticles, _yaVFit, TAbsFitParticle::getCovMatrix(), getF(), TAbsFitParticle::getInfoString(), getNDF(), TAbsFitParticle::getNPar(), TAbsFitParticle::getParCurr(), getS(), getStatusString(), and dqm-mbProfile::log.

Referenced by fit().

1125  {
1126  edm::LogVerbatim log("KinFitter");
1127  log << "\n"
1128  << "\n";
1129  // Print status of fit
1130  log << "Status: " << getStatusString() << " F=" << getF() << " S=" << getS() << " N=" << _nbIter
1131  << " NDF=" << getNDF() << "\n";
1132  // Print measured particles
1133  log << "measured particles: \n";
1134  Int_t parIndex = 0;
1135  for (unsigned int iP = 0; iP < _measParticles.size(); iP++) {
1136  TAbsFitParticle* particle = _measParticles[iP];
1137  Int_t nParP = particle->getNPar();
1138  const TMatrixD* par = particle->getParCurr();
1139  const TMatrixD* covP = particle->getCovMatrix();
1140  log << std::setw(3) << setiosflags(std::ios::right) << iP;
1141  log << std::setw(15) << setiosflags(std::ios::right) << particle->GetName();
1142  log << std::setw(3) << " ";
1143  for (int iPar = 0; iPar < nParP; iPar++) {
1144  if (iPar > 0) {
1145  log << setiosflags(std::ios::right) << std::setw(21) << " ";
1146  }
1147  TString colstr = "";
1148  colstr += parIndex;
1149  colstr += ":";
1150  log << std::setw(4) << colstr;
1151  log << std::setw(2) << " ";
1152  log << setiosflags(std::ios::left) << setiosflags(std::ios::scientific) << std::setprecision(3);
1153  log << std::setw(15) << (*par)(iPar, 0);
1154  if (_nbIter > 0 && _status < 10) {
1155  log << std::setw(15) << TMath::Sqrt(_yaVFit(iPar, iPar));
1156  } else {
1157  log << std::setw(15) << " ";
1158  }
1159  log << std::setw(15) << TMath::Sqrt((*covP)(iPar, iPar));
1160  log << "\n";
1161  parIndex++;
1162  }
1163  log << particle->getInfoString();
1164  }
1165  // Print unmeasured particles
1166  log << "unmeasured particles: \n";
1167  parIndex = 0;
1168  for (unsigned int iP = 0; iP < _unmeasParticles.size(); iP++) {
1169  TAbsFitParticle* particle = _unmeasParticles[iP];
1170  Int_t nParP = particle->getNPar();
1171  const TMatrixD* par = particle->getParCurr();
1172  log << std::setw(3) << setiosflags(std::ios::right) << iP;
1173  log << std::setw(15) << particle->GetName();
1174  log << std::setw(3) << " ";
1175  for (int iPar = 0; iPar < nParP; iPar++) {
1176  if (iPar > 0) {
1177  log << setiosflags(std::ios::right) << std::setw(21) << " ";
1178  }
1179  TString colstr = "";
1180  colstr += parIndex;
1181  colstr += ":";
1182  log << std::setw(4) << colstr;
1183  log << std::setw(2) << " ";
1184  log << setiosflags(std::ios::left) << setiosflags(std::ios::scientific) << std::setprecision(3);
1185  log << std::setw(15) << (*par)(iPar, 0);
1186  if (_nbIter > 0 && _status < 10) {
1187  log << std::setw(15) << TMath::Sqrt(_yaVFit(iPar + _nParB, iPar + _nParB));
1188  } else {
1189  log << std::setw(15) << " ";
1190  }
1191  log << "\n";
1192  parIndex++;
1193  }
1194  log << particle->getInfoString();
1195  }
1196  log << "\n";
1197  // Print constraints
1198  log << "constraints: \n";
1199  for (unsigned int indexConstr = 0; indexConstr < _constraints.size(); indexConstr++) {
1200  log << _constraints[indexConstr]->getInfoString();
1201  }
1202  log << "\n";
1203 }
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
TString getInfoString()
TString getStatusString()
Definition: TKinFitter.cc:1096
TMatrixD _yaVFit
Definition: TKinFitter.h:147
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154
Double_t getS()
Definition: TKinFitter.cc:1066
Int_t _status
Definition: TKinFitter.h:156
Int_t getNDF()
Definition: TKinFitter.h:45
virtual const TMatrixD * getCovMatrix() const
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
Int_t _nbIter
Definition: TKinFitter.h:157
Double_t getF()
Definition: TKinFitter.cc:1054
Int_t _nParB
Definition: TKinFitter.h:150
const TMatrixD * getParCurr()
Int_t getNPar() const

◆ printMatrix()

void TKinFitter::printMatrix ( const TMatrixD &  matrix,
const TString &  name = "" 
)
protected

Definition at line 1205 of file TKinFitter.cc.

References mps_fire::i, dqm-mbProfile::log, makeMuonMisalignmentScenario::matrix, METSkim_cff::Min, and Skims_PA_cff::name.

Referenced by calcB(), calcC(), and fit().

1205  {
1206  // produce a tabular printout for matrices
1207  // this function is a modified version of Root's TMatrixTBase<Element>::Print method
1208  // which could not be used together with the MessageLogger
1209 
1210  if (!matrix.IsValid()) {
1211  edm::LogWarning("InvalidMatrix") << "Matrix " << name << " is invalid.";
1212  return;
1213  }
1214 
1215  edm::LogVerbatim log("KinFitter");
1216 
1217  const Int_t nCols = matrix.GetNcols();
1218  const Int_t nRows = matrix.GetNrows();
1219  const Int_t colsPerSheet = 5;
1220  char topbar[100];
1221  Int_t nk = 6 + 13 * TMath::Min(colsPerSheet, nCols);
1222  for (Int_t i = 0; i < nk; i++)
1223  topbar[i] = '-';
1224  topbar[nk] = 0;
1225 
1226  Int_t sw = (70 - name.Length()) / 2;
1227 
1228  log << std::setfill('=') << std::setw(sw) << "= " << name << std::setw(sw) << std::left << " ="
1229  << "\n"
1230  << std::setfill(' ') << std::right << "\n";
1231 
1232  log << nRows << "x" << nCols << " matrix is as follows \n";
1233 
1234  for (Int_t iSheet = 0; iSheet < nCols; iSheet += colsPerSheet) {
1235  log << "\n"
1236  << " |";
1237  for (Int_t iCol = iSheet; iCol < nCols; iCol++) {
1238  if (iCol < iSheet + colsPerSheet)
1239  log << std::setw(8) << iCol << " |";
1240  }
1241  log << "\n" << topbar << " \n";
1242  for (Int_t iRow = 0; iRow < nRows; iRow++) {
1243  log << std::setw(4) << iRow << " |";
1244  for (Int_t iCol = iSheet; iCol < nCols; iCol++) {
1245  if (iCol < iSheet + colsPerSheet)
1246  log << std::setw(12) << matrix(iRow, iCol) << " ";
1247  }
1248  log << "\n";
1249  }
1250  }
1251 }
Log< level::Warning, false > LogWarning

◆ reset()

void TKinFitter::reset ( void  )

Definition at line 97 of file TKinFitter.cc.

References _A, _AT, _B, _BT, _c, _C11, _C11T, _C21, _C21T, _C22, _C22T, _C31, _C31T, _C32, _C32T, _C33, _C33T, _constraints, _deltaA, _deltaAstar, _deltaY, _deltaYstar, _lambda, _lambdaT, _lambdaVFit, _maxDeltaS, _maxF, _maxNbIter, _measParticles, _nbIter, _nParA, _nParB, _status, _unmeasParticles, _V, _VA, _VAinv, _VB, _VBinv, _verbosity, _Vinv, _yaVFit, and MillePedeFileConverter_cfg::e.

Referenced by TKinFitter().

97  {
98  // reset all internal parameters of the fitter
99 
100  _status = -1;
101  _nbIter = 0;
102  _nParA = 0;
103  _nParB = 0;
104  _verbosity = 1;
105  _A.ResizeTo(1, 1);
106  _AT.ResizeTo(1, 1);
107  _B.ResizeTo(1, 1);
108  _BT.ResizeTo(1, 1);
109  _V.ResizeTo(1, 1);
110  _Vinv.ResizeTo(1, 1);
111  _VB.ResizeTo(1, 1);
112  _VBinv.ResizeTo(1, 1);
113  _VA.ResizeTo(1, 1);
114  _VAinv.ResizeTo(1, 1);
115  _c.ResizeTo(1, 1);
116  _C11.ResizeTo(1, 1);
117  _C11T.ResizeTo(1, 1);
118  _C21.ResizeTo(1, 1);
119  _C21T.ResizeTo(1, 1);
120  _C22.ResizeTo(1, 1);
121  _C22T.ResizeTo(1, 1);
122  _C31.ResizeTo(1, 1);
123  _C31T.ResizeTo(1, 1);
124  _C32.ResizeTo(1, 1);
125  _C32T.ResizeTo(1, 1);
126  _C33.ResizeTo(1, 1);
127  _C33T.ResizeTo(1, 1);
128  _deltaA.ResizeTo(1, 1);
129  _deltaY.ResizeTo(1, 1);
130  _deltaAstar.ResizeTo(1, 1);
131  _deltaYstar.ResizeTo(1, 1);
132  _lambda.ResizeTo(1, 1);
133  _lambdaT.ResizeTo(1, 1);
134  _lambdaVFit.ResizeTo(1, 1);
135  _yaVFit.ResizeTo(1, 1);
136 
137  _constraints.clear();
138  _measParticles.clear();
139  _unmeasParticles.clear();
140 
141  // Set to default values
142  _maxNbIter = 50;
143  _maxDeltaS = 5e-3;
144  _maxF = 1e-4;
145 }
TMatrixD _deltaY
Definition: TKinFitter.h:140
TMatrixD _C11
Definition: TKinFitter.h:126
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
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
TMatrixD _V
Definition: TKinFitter.h:118
TMatrixD _C21T
Definition: TKinFitter.h:129
TMatrixD _VB
Definition: TKinFitter.h:120
TMatrixD _C31T
Definition: TKinFitter.h:133
TMatrixD _yaVFit
Definition: TKinFitter.h:147
TMatrixD _C32
Definition: TKinFitter.h:134
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154
TMatrixD _VA
Definition: TKinFitter.h:122
TMatrixD _deltaA
Definition: TKinFitter.h:139
Int_t _maxNbIter
Definition: TKinFitter.h:109
TMatrixD _C33
Definition: TKinFitter.h:136
TMatrixD _deltaAstar
Definition: TKinFitter.h:141
Int_t _status
Definition: TKinFitter.h:156
TMatrixD _B
Definition: TKinFitter.h:116
TMatrixD _C22T
Definition: TKinFitter.h:131
TMatrixD _VAinv
Definition: TKinFitter.h:123
TMatrixD _C22
Definition: TKinFitter.h:130
TMatrixD _c
Definition: TKinFitter.h:124
Double_t _maxDeltaS
Definition: TKinFitter.h:110
TMatrixD _A
Definition: TKinFitter.h:114
TMatrixD _lambdaT
Definition: TKinFitter.h:144
TMatrixD _lambdaVFit
Definition: TKinFitter.h:146
TMatrixD _C31
Definition: TKinFitter.h:132
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152
TMatrixD _deltaYstar
Definition: TKinFitter.h:142
TMatrixD _BT
Definition: TKinFitter.h:117
TMatrixD _AT
Definition: TKinFitter.h:115
Int_t _nbIter
Definition: TKinFitter.h:157
Int_t _verbosity
Definition: TKinFitter.h:112
TMatrixD _VBinv
Definition: TKinFitter.h:121
Int_t _nParB
Definition: TKinFitter.h:150
TMatrixD _C11T
Definition: TKinFitter.h:127
TMatrixD _C21
Definition: TKinFitter.h:128
TMatrixD _Vinv
Definition: TKinFitter.h:119
Double_t _maxF
Definition: TKinFitter.h:111

◆ resetParams()

void TKinFitter::resetParams ( )
protected

Definition at line 154 of file TKinFitter.cc.

References _constraints, _measParticles, _unmeasParticles, HLT_2024v13_cff::constraint, and TAbsFitParticle::reset().

Referenced by fit().

154  {
155  // reset all particles to their initial parameters
156 
157  for (unsigned int iP = 0; iP < _measParticles.size(); iP++) {
158  TAbsFitParticle* particle = _measParticles[iP];
159  particle->reset();
160  }
161  for (unsigned int iP = 0; iP < _unmeasParticles.size(); iP++) {
162  TAbsFitParticle* particle = _unmeasParticles[iP];
163  particle->reset();
164  }
165  for (unsigned int iC = 0; iC < _constraints.size(); iC++) {
167  constraint->reset();
168  }
169 }
std::vector< TAbsFitParticle * > _measParticles
Definition: TKinFitter.h:153
virtual void reset()
std::vector< TAbsFitParticle * > _unmeasParticles
Definition: TKinFitter.h:154
std::vector< TAbsFitConstraint * > _constraints
Definition: TKinFitter.h:152

◆ resetStatus()

void TKinFitter::resetStatus ( )

Definition at line 147 of file TKinFitter.cc.

References _nbIter, and _status.

Referenced by addConstraint(), addMeasParticle(), addMeasParticles(), addUnmeasParticle(), addUnmeasParticles(), and fit().

147  {
148  // reset status of the fit
149 
150  _status = -1;
151  _nbIter = 0;
152 }
Int_t _status
Definition: TKinFitter.h:156
Int_t _nbIter
Definition: TKinFitter.h:157

◆ setCovMatrix()

void TKinFitter::setCovMatrix ( TMatrixD &  V)

Definition at line 462 of file TKinFitter.cc.

References _nParB, _V, and cms::cuda::V.

462  {
463  // Set the covariance matrix of the measured particles
464 
465  if ((V.GetNrows() != _nParB) || (V.GetNcols() != _nParB)) {
466  edm::LogError("WrongMatrixSize") << "Covariance matrix of measured particles needs to be a " << _nParB << "x"
467  << _nParB << " matrix.";
468  } else {
469  _V.ResizeTo(V);
470  _V = V;
471  }
472 }
TMatrixD _V
Definition: TKinFitter.h:118
Log< level::Error, false > LogError
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
Int_t _nParB
Definition: TKinFitter.h:150

◆ setMaxDeltaS()

void TKinFitter::setMaxDeltaS ( Double_t  maxDeltaS)
inline

Definition at line 52 of file TKinFitter.h.

References _maxDeltaS, and StEvtSolProducer_cfi::maxDeltaS.

Referenced by TSLToyGen::doToyExperiments(), and CandMassKinFitter::set().

52 { _maxDeltaS = TMath::Abs(maxDeltaS); }
Double_t _maxDeltaS
Definition: TKinFitter.h:110

◆ setMaxF()

void TKinFitter::setMaxF ( Double_t  maxF)
inline

Definition at line 54 of file TKinFitter.h.

References _maxF, and StEvtSolProducer_cfi::maxF.

Referenced by TSLToyGen::doToyExperiments(), and CandMassKinFitter::set().

54 { _maxF = TMath::Abs(maxF); }
Double_t _maxF
Definition: TKinFitter.h:111

◆ setMaxNbIter()

void TKinFitter::setMaxNbIter ( Int_t  maxNbIter)
inline

Definition at line 48 of file TKinFitter.h.

References _maxNbIter.

Referenced by TSLToyGen::doToyExperiments(), and CandMassKinFitter::set().

48 { _maxNbIter = maxNbIter; }
Int_t _maxNbIter
Definition: TKinFitter.h:109

◆ setVerbosity()

void TKinFitter::setVerbosity ( Int_t  verbosity = 1)

Definition at line 304 of file TKinFitter.cc.

References _verbosity, and verbosity.

Referenced by TSLToyGen::doToyExperiments(), and CandMassKinFitter::set().

304  {
305  // Set verbosity of the fitter:
306  // 0: quiet
307  // 1: print information before and after the fit
308  // 2: print output for every iteration of the fit
309  // 3: print debug information
310 
311  if (verbosity < 0)
312  verbosity = 0;
313  if (verbosity > 3)
314  verbosity = 3;
316 }
const int verbosity
Int_t _verbosity
Definition: TKinFitter.h:112

Member Data Documentation

◆ _A

TMatrixD TKinFitter::_A
private

Definition at line 114 of file TKinFitter.h.

Referenced by calcA(), calcC(), calcC11(), calcC31(), calcC32(), calcC33(), calcVA(), fit(), and reset().

◆ _AT

TMatrixD TKinFitter::_AT
private

Definition at line 115 of file TKinFitter.h.

Referenced by calcA(), calcC11(), calcC21(), calcC31(), calcC33(), calcVA(), and reset().

◆ _B

TMatrixD TKinFitter::_B
private

Definition at line 116 of file TKinFitter.h.

Referenced by calcB(), calcC(), calcC11(), calcC21(), calcC31(), calcVB(), fit(), and reset().

◆ _BT

TMatrixD TKinFitter::_BT
private

Definition at line 117 of file TKinFitter.h.

Referenced by calcB(), calcC11(), calcVB(), and reset().

◆ _c

TMatrixD TKinFitter::_c
private

Definition at line 124 of file TKinFitter.h.

Referenced by calcC(), calcDeltaA(), calcDeltaY(), calcLambda(), fit(), and reset().

◆ _C11

TMatrixD TKinFitter::_C11
private

Definition at line 126 of file TKinFitter.h.

Referenced by calcC11(), calcVFit(), and reset().

◆ _C11T

TMatrixD TKinFitter::_C11T
private

Definition at line 127 of file TKinFitter.h.

Referenced by calcC11(), and reset().

◆ _C21

TMatrixD TKinFitter::_C21
private

Definition at line 128 of file TKinFitter.h.

Referenced by calcC21(), calcVFit(), and reset().

◆ _C21T

TMatrixD TKinFitter::_C21T
private

Definition at line 129 of file TKinFitter.h.

Referenced by calcC21(), calcVFit(), and reset().

◆ _C22

TMatrixD TKinFitter::_C22
private

Definition at line 130 of file TKinFitter.h.

Referenced by calcC22(), calcVFit(), and reset().

◆ _C22T

TMatrixD TKinFitter::_C22T
private

Definition at line 131 of file TKinFitter.h.

Referenced by calcC22(), and reset().

◆ _C31

TMatrixD TKinFitter::_C31
private

Definition at line 132 of file TKinFitter.h.

Referenced by calcC31(), and reset().

◆ _C31T

TMatrixD TKinFitter::_C31T
private

Definition at line 133 of file TKinFitter.h.

Referenced by calcC31(), calcDeltaY(), and reset().

◆ _C32

TMatrixD TKinFitter::_C32
private

Definition at line 134 of file TKinFitter.h.

Referenced by calcC32(), and reset().

◆ _C32T

TMatrixD TKinFitter::_C32T
private

Definition at line 135 of file TKinFitter.h.

Referenced by calcC32(), calcDeltaA(), fit(), and reset().

◆ _C33

TMatrixD TKinFitter::_C33
private

Definition at line 136 of file TKinFitter.h.

Referenced by calcC33(), calcLambda(), calcVFit(), and reset().

◆ _C33T

TMatrixD TKinFitter::_C33T
private

Definition at line 137 of file TKinFitter.h.

Referenced by calcC33(), and reset().

◆ _constraints

std::vector<TAbsFitConstraint*> TKinFitter::_constraints
private

◆ _deltaA

TMatrixD TKinFitter::_deltaA
private

Definition at line 139 of file TKinFitter.h.

Referenced by applyDeltaA(), calcDeltaA(), fit(), and reset().

◆ _deltaAstar

TMatrixD TKinFitter::_deltaAstar
private

Definition at line 141 of file TKinFitter.h.

Referenced by calcDeltaA(), fit(), and reset().

◆ _deltaY

TMatrixD TKinFitter::_deltaY
private

Definition at line 140 of file TKinFitter.h.

Referenced by applyDeltaY(), calcDeltaY(), fit(), getS(), and reset().

◆ _deltaYstar

TMatrixD TKinFitter::_deltaYstar
private

Definition at line 142 of file TKinFitter.h.

Referenced by calcDeltaY(), fit(), and reset().

◆ _lambda

TMatrixD TKinFitter::_lambda
private

Definition at line 143 of file TKinFitter.h.

Referenced by calcLambda(), fit(), and reset().

◆ _lambdaT

TMatrixD TKinFitter::_lambdaT
private

Definition at line 144 of file TKinFitter.h.

Referenced by calcLambda(), fit(), and reset().

◆ _lambdaVFit

TMatrixD TKinFitter::_lambdaVFit
private

Definition at line 146 of file TKinFitter.h.

Referenced by calcVFit(), and reset().

◆ _maxDeltaS

Double_t TKinFitter::_maxDeltaS
private

Definition at line 110 of file TKinFitter.h.

Referenced by converged(), getMaxDeltaS(), reset(), and setMaxDeltaS().

◆ _maxF

Double_t TKinFitter::_maxF
private

Definition at line 111 of file TKinFitter.h.

Referenced by converged(), getMaxF(), reset(), and setMaxF().

◆ _maxNbIter

Int_t TKinFitter::_maxNbIter
private

Definition at line 109 of file TKinFitter.h.

Referenced by fit(), getMaxNumberIter(), reset(), and setMaxNbIter().

◆ _measParticles

std::vector<TAbsFitParticle*> TKinFitter::_measParticles
private

◆ _nbIter

Int_t TKinFitter::_nbIter
private

Definition at line 157 of file TKinFitter.h.

Referenced by calcDeltaA(), calcDeltaY(), fit(), getNbIter(), getS(), print(), reset(), and resetStatus().

◆ _nParA

Int_t TKinFitter::_nParA
private

◆ _nParB

Int_t TKinFitter::_nParB
private

Definition at line 150 of file TKinFitter.h.

Referenced by calcB(), calcC(), calcV(), countMeasParams(), getNParB(), print(), reset(), and setCovMatrix().

◆ _status

Int_t TKinFitter::_status
private

Definition at line 156 of file TKinFitter.h.

Referenced by calcV(), calcVA(), calcVB(), fit(), getStatus(), getStatusString(), print(), reset(), and resetStatus().

◆ _unmeasParticles

std::vector<TAbsFitParticle*> TKinFitter::_unmeasParticles
private

◆ _V

TMatrixD TKinFitter::_V
private

Definition at line 118 of file TKinFitter.h.

Referenced by calcC11(), calcC21(), calcC31(), calcV(), calcVB(), fit(), getCovMatrix(), reset(), and setCovMatrix().

◆ _VA

TMatrixD TKinFitter::_VA
private

Definition at line 122 of file TKinFitter.h.

Referenced by calcVA(), and reset().

◆ _VAinv

TMatrixD TKinFitter::_VAinv
private

Definition at line 123 of file TKinFitter.h.

Referenced by calcC11(), calcC21(), calcC22(), calcC31(), calcC32(), calcC33(), calcVA(), and reset().

◆ _VB

TMatrixD TKinFitter::_VB
private

Definition at line 120 of file TKinFitter.h.

Referenced by calcC11(), calcC21(), calcC31(), calcC32(), calcC33(), calcVA(), calcVB(), fit(), and reset().

◆ _VBinv

TMatrixD TKinFitter::_VBinv
private

Definition at line 121 of file TKinFitter.h.

Referenced by calcVB(), fit(), and reset().

◆ _verbosity

Int_t TKinFitter::_verbosity
private

Definition at line 112 of file TKinFitter.h.

Referenced by calcB(), calcC(), fit(), getVerbosity(), reset(), and setVerbosity().

◆ _Vinv

TMatrixD TKinFitter::_Vinv
private

Definition at line 119 of file TKinFitter.h.

Referenced by calcV(), getS(), and reset().

◆ _yaVFit

TMatrixD TKinFitter::_yaVFit
private

Definition at line 147 of file TKinFitter.h.

Referenced by applyVFit(), calcVFit(), getCovMatrixFit(), print(), and reset().