20 : TNamed(
"UnNamed",
"UnTitled"),
110 _Vinv.ResizeTo(1, 1);
117 _C11T.ResizeTo(1, 1);
119 _C21T.ResizeTo(1, 1);
121 _C22T.ResizeTo(1, 1);
123 _C31T.ResizeTo(1, 1);
125 _C32T.ResizeTo(1, 1);
127 _C33T.ResizeTo(1, 1);
165 for (
unsigned int iC = 0; iC <
_constraints.size(); iC++) {
177 for (
unsigned int indexParticle = 0; indexParticle <
_measParticles.size(); indexParticle++) {
180 for (
unsigned int indexConstraint = 0; indexConstraint <
_constraints.size(); indexConstraint++) {
189 for (
unsigned int indexParticle = 0; indexParticle <
_unmeasParticles.size(); indexParticle++) {
199 if (particle !=
nullptr) {
202 edm::LogError(
"NullPointer") <<
"Measured particle points to NULL. It will not be added to the KinFitter.";
248 if (particle !=
nullptr) {
251 edm::LogError(
"NullPointer") <<
"Unmeasured particle points to NULL. It will not be added to the KinFitter.";
328 Bool_t isConverged =
false;
330 Double_t currF =
getF();
398 if (TMath::IsNaN(currF)) {
399 edm::LogInfo(
"KinFitter") <<
"The current value of F is NaN. Fit will be aborted.";
402 if (TMath::IsNaN(currS)) {
403 edm::LogInfo(
"KinFitter") <<
"The current value of S is NaN. Fit will be aborted.";
409 while (currF >= prevF) {
426 isConverged =
converged(currF, prevS, currS);
466 edm::LogError(
"WrongMatrixSize") <<
"Covariance matrix of measured particles needs to be a " <<
_nParB <<
"x"
483 Int_t nParP = particle->
getNPar();
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);
495 for (
unsigned int iC = 0; iC <
_constraints.size(); iC++) {
498 const TMatrixD* covMatrix =
constraint->getCovMatrix();
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);
514 edm::LogInfo(
"KinFitter") <<
"Failed to invert covariance matrix V. Fit will be aborted.";
528 for (
unsigned int indexConstr = 0; indexConstr <
_constraints.size(); indexConstr++) {
530 for (
unsigned int indexParticle = 0; indexParticle <
_unmeasParticles.size(); indexParticle++) {
535 TMatrixD* derivConstr =
_constraints[indexConstr]->getDerivative(particle);
538 for (
int indexParam = 0; indexParam < deriv.GetNcols(); indexParam++) {
539 _A(indexConstr, indexParam + offsetParam) = deriv(0, indexParam);
541 offsetParam += deriv.GetNcols();
543 delete derivParticle;
549 TMatrixD AT(TMatrixD::kTransposed,
_A);
564 for (
unsigned int indexConstr = 0; indexConstr <
_constraints.size(); indexConstr++) {
566 for (
unsigned int indexParticle = 0; indexParticle <
_measParticles.size(); indexParticle++) {
570 TMatrixD* derivConstr =
_constraints[indexConstr]->getDerivative(particle);
573 TString matrixName =
"B deriv: Particle -> ";
574 matrixName += particle->GetName();
576 matrixName =
"B deriv: Constraint -> ";
578 matrixName +=
" , Particle -> ";
579 matrixName += particle->GetName();
582 for (
int indexParam = 0; indexParam < deriv.GetNcols(); indexParam++) {
583 _B(indexConstr, indexParam + offsetParam) = deriv(0, indexParam);
585 offsetParam += deriv.GetNcols();
587 delete derivParticle;
592 for (
unsigned int iC = 0; iC <
_constraints.size(); iC++) {
594 TMatrixD* deriv =
constraint->getDerivativeAlpha();
596 if (deriv !=
nullptr) {
598 TString matrixName =
"B deriv alpha: Constraint -> ";
602 for (
int indexParam = 0; indexParam < deriv->GetNcols(); indexParam++) {
603 _B(iC, indexParam + offsetParam) = (*deriv)(0, indexParam);
605 offsetParam += deriv->GetNcols();
611 TMatrixD BT(TMatrixD::kTransposed,
_B);
631 edm::LogInfo(
"KinFitter") <<
"Failed to invert matrix VB. Fit will be aborted.";
651 edm::LogInfo(
"KinFitter") <<
"Failed to invert matrix VA. Fit will be aborted.";
680 TMatrixD C11T(TMatrixD::kTransposed,
_C11);
681 _C11T.ResizeTo(C11T);
698 TMatrixD C21T(TMatrixD::kTransposed,
_C21);
699 _C21T.ResizeTo(C21T);
711 TMatrixD C22T(TMatrixD::kTransposed,
_C22);
712 _C22T.ResizeTo(C22T);
737 TMatrixD C31T(TMatrixD::kTransposed,
_C31);
738 _C31T.ResizeTo(C31T);
752 TMatrixD C32T(TMatrixD::kTransposed,
_C32);
753 _C32T.ResizeTo(C32T);
774 TMatrixD C33T(TMatrixD::kTransposed,
_C33);
775 _C33T.ResizeTo(C33T);
787 TMatrixD deltaastar(1, 1);
789 deltaastar.ResizeTo(
_nParA, 1);
790 for (
unsigned int indexParticle = 0; indexParticle <
_unmeasParticles.size(); indexParticle++) {
792 const TMatrixD* astar = particle->
getParCurr();
794 TMatrixD deltaastarpart(*astar);
795 deltaastarpart -= *
a;
797 for (
int indexParam = 0; indexParam < deltaastarpart.GetNrows(); indexParam++) {
798 deltaastar(indexParam + offsetParam, 0) = deltaastarpart(indexParam, 0);
800 offsetParam += deltaastarpart.GetNrows();
809 TMatrixD deltaystar(
_nParB, 1);
811 for (
unsigned int indexParticle = 0; indexParticle <
_measParticles.size(); indexParticle++) {
813 const TMatrixD* ystar = particle->
getParCurr();
815 TMatrixD deltaystarpart(*ystar);
816 deltaystarpart -= *
y;
818 for (
int indexParam = 0; indexParam < deltaystarpart.GetNrows(); indexParam++) {
819 deltaystar(indexParam + offsetParam, 0) = deltaystarpart(indexParam, 0);
821 offsetParam += deltaystarpart.GetNrows();
824 for (
unsigned int iC = 0; iC <
_constraints.size(); iC++) {
828 const TMatrixD* alphastar =
constraint->getParCurr();
831 TMatrixD deltaalphastarpart(*alphastar);
832 deltaalphastarpart -= *
alpha;
834 for (
int indexParam = 0; indexParam < deltaalphastarpart.GetNrows(); indexParam++) {
835 deltaystar(indexParam + offsetParam, 0) = deltaalphastarpart(indexParam, 0);
837 offsetParam += deltaalphastarpart.GetNrows();
847 for (
unsigned int indexConstr = 0; indexConstr <
_constraints.size(); indexConstr++) {
848 fstar(indexConstr, 0) =
_constraints[indexConstr]->getCurrentValue();
909 TMatrixD lambdaT(TMatrixD::kTransposed,
_lambda);
930 Int_t nbRows =
_C11.GetNrows();
931 Int_t nbCols =
_C11.GetNcols();
933 nbRows +=
_C21.GetNrows();
934 nbCols +=
_C21T.GetNcols();
936 _yaVFit.ResizeTo(nbRows, nbCols);
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()) {
947 if (iCol >=
_C11.GetNcols()) {
963 for (
unsigned int indexParticle = 0; indexParticle <
_measParticles.size(); 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);
973 offsetParam += nbParams;
976 for (
unsigned int indexConstraint = 0; indexConstraint <
_constraints.size(); indexConstraint++) {
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);
987 offsetParam += nbParams;
991 for (
unsigned int indexParticle = 0; indexParticle <
_unmeasParticles.size(); 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);
1001 offsetParam += nbParams;
1008 int offsetParam = 0;
1009 for (
unsigned int indexParticle = 0; indexParticle <
_unmeasParticles.size(); indexParticle++) {
1011 Int_t nbParams = particle->
getNPar();
1012 TMatrixD
params(nbParams, 1);
1017 offsetParam += nbParams;
1026 int offsetParam = 0;
1027 for (
unsigned int indexParticle = 0; indexParticle <
_measParticles.size(); indexParticle++) {
1029 Int_t nbParams = particle->
getNPar();
1030 TMatrixD
params(nbParams, 1);
1035 offsetParam += nbParams;
1038 for (
unsigned int indexConstraint = 0; indexConstraint <
_constraints.size(); indexConstraint++) {
1042 TMatrixD
params(nbParams, 1);
1047 offsetParam += nbParams;
1059 for (
unsigned int indexConstr = 0; indexConstr <
_constraints.size(); indexConstr++) {
1073 TMatrixD deltaYTVinv(
_deltaY, TMatrixD::kTransposeMult,
_Vinv);
1084 Bool_t isConverged =
false;
1087 isConverged = (
F <
_maxF);
1090 Double_t deltaS = currS - prevS;
1097 TString statusstring =
"";
1101 statusstring =
"NO FIT PERFORMED";
1105 statusstring =
"RUNNING";
1109 statusstring =
"ABORTED";
1113 statusstring =
"CONVERGED";
1117 statusstring =
"NOT CONVERGED";
1122 return statusstring;
1131 <<
" NDF=" <<
getNDF() <<
"\n";
1133 log <<
"measured particles: \n";
1137 Int_t nParP = particle->
getNPar();
1138 const TMatrixD* par = particle->
getParCurr();
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++) {
1145 log << setiosflags(std::ios::right) << std::setw(21) <<
" ";
1147 TString 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);
1155 log << std::setw(15) << TMath::Sqrt(
_yaVFit(iPar, iPar));
1157 log << std::setw(15) <<
" ";
1159 log << std::setw(15) << TMath::Sqrt((*covP)(iPar, iPar));
1166 log <<
"unmeasured particles: \n";
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++) {
1177 log << setiosflags(std::ios::right) << std::setw(21) <<
" ";
1179 TString 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);
1189 log << std::setw(15) <<
" ";
1198 log <<
"constraints: \n";
1199 for (
unsigned int indexConstr = 0; indexConstr <
_constraints.size(); indexConstr++) {
1217 const Int_t nCols =
matrix.GetNcols();
1218 const Int_t nRows =
matrix.GetNrows();
1219 const Int_t colsPerSheet = 5;
1221 Int_t nk = 6 + 13 *
TMath::Min(colsPerSheet, nCols);
1222 for (Int_t
i = 0;
i < nk;
i++)
1226 Int_t sw = (70 -
name.Length()) / 2;
1228 log << std::setfill(
'=') << std::setw(sw) <<
"= " <<
name << std::setw(sw) << std::left <<
" ="
1230 << std::setfill(
' ') << std::right <<
"\n";
1232 log << nRows <<
"x" << nCols <<
" matrix is as follows \n";
1234 for (Int_t iSheet = 0; iSheet < nCols; iSheet += colsPerSheet) {
1237 for (Int_t iCol = iSheet; iCol < nCols; iCol++) {
1238 if (iCol < iSheet + colsPerSheet)
1239 log << std::setw(8) << iCol <<
" |";
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) <<
" ";