22 TNamed(
"UnNamed",
"UnTitled"),
118 _Vinv.ResizeTo(1, 1);
125 _C11T.ResizeTo(1, 1);
127 _C21T.ResizeTo(1, 1);
129 _C22T.ResizeTo(1, 1);
131 _C31T.ResizeTo(1, 1);
133 _C32T.ResizeTo(1, 1);
135 _C33T.ResizeTo(1, 1);
175 for (
unsigned int iC = 0; iC <
_constraints.size(); iC++) {
190 for (
unsigned int indexParticle = 0; indexParticle <
_measParticles.size(); indexParticle++) {
193 for (
unsigned int indexConstraint = 0; indexConstraint <
_constraints.size(); indexConstraint++) {
203 for (
unsigned int indexParticle = 0; indexParticle <
_unmeasParticles.size(); indexParticle++) {
214 if ( particle != 0 ) {
217 edm::LogError (
"NullPointer") <<
"Measured particle points to NULL. It will not be added to the KinFitter.";
250 if ( particle != 0 ) {
253 edm::LogError (
"NullPointer") <<
"Unmeasured particle points to NULL. It will not be added to the KinFitter.";
286 if ( constraint != 0 ) {
302 if ( verbosity < 0 ) verbosity = 0;
303 if ( verbosity > 3 ) verbosity = 3;
319 Bool_t isConverged =
false;
321 Double_t currF =
getF();
390 if( TMath::IsNaN(currF) ) {
391 edm::LogInfo (
"KinFitter") <<
"The current value of F is NaN. Fit will be aborted.";
394 if( TMath::IsNaN(currS) ) {
395 edm::LogInfo (
"KinFitter") <<
"The current value of S is NaN. Fit will be aborted.";
401 while (currF >= prevF) {
403 if (nstep == 10)
break;
415 isConverged =
converged(currF, prevS, currS);
457 if ( (V.GetNrows() !=
_nParB) || (V.GetNcols() !=
_nParB) ) {
459 <<
"Covariance matrix of measured particles needs to be a " <<
_nParB <<
"x" <<
_nParB <<
" matrix.";
476 Int_t nParP = particle->
getNPar();
479 for (
int iX = offsetP; iX < offsetP + nParP; iX++) {
480 for (
int iY = offsetP; iY < offsetP + nParP; iY++) {
482 _V(iX, iY) = (*covMatrix)(iX-offsetP, iY-offsetP);
490 for (
unsigned int iC = 0; iC <
_constraints.size(); iC++) {
492 Int_t nParP = constraint->
getNPar();
495 for (
int iX = offsetP; iX < offsetP + nParP; iX++) {
496 for (
int iY = offsetP; iY < offsetP + nParP; iY++) {
498 _V(iX, iY) = (*covMatrix)(iX-offsetP, iY-offsetP);
511 edm::LogInfo (
"KinFitter") <<
"Failed to invert covariance matrix V. Fit will be aborted.";
526 for (
unsigned int indexConstr = 0; indexConstr <
_constraints.size(); indexConstr++) {
529 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;
550 TMatrixD AT(TMatrixD::kTransposed,
_A);
566 for (
unsigned int indexConstr = 0; indexConstr <
_constraints.size(); indexConstr++) {
569 for (
unsigned int indexParticle = 0; indexParticle <
_measParticles.size(); indexParticle++) {
574 TMatrixD* derivConstr =
_constraints[indexConstr]->getDerivative( particle );
577 TString matrixName =
"B deriv: Particle -> ";
578 matrixName += particle->GetName();
580 matrixName =
"B deriv: Constraint -> ";
582 matrixName +=
" , Particle -> ";
583 matrixName += particle->GetName();
586 for (
int indexParam = 0; indexParam < deriv.GetNcols(); indexParam++) {
587 _B(indexConstr,indexParam+offsetParam) = deriv(0, indexParam);
589 offsetParam += deriv.GetNcols();
591 delete derivParticle;
597 for (
unsigned int iC = 0; iC <
_constraints.size(); iC++) {
605 TString matrixName =
"B deriv alpha: Constraint -> ";
606 matrixName += constraint->GetName();
609 for (
int indexParam = 0; indexParam < deriv->GetNcols(); indexParam++) {
610 _B( iC, indexParam+offsetParam ) = (*deriv)(0, indexParam);
612 offsetParam += deriv->GetNcols();
618 TMatrixD BT( TMatrixD::kTransposed,
_B );
639 edm::LogInfo (
"KinFitter") <<
"Failed to invert matrix VB. Fit will be aborted.";
660 edm::LogInfo (
"KinFitter") <<
"Failed to invert matrix VA. Fit will be aborted.";
690 TMatrixD C11T( TMatrixD::kTransposed,
_C11 );
691 _C11T.ResizeTo( C11T );
706 _C21.ResizeTo( C21 );
709 TMatrixD C21T( TMatrixD::kTransposed,
_C21 );
710 _C21T.ResizeTo( C21T );
723 TMatrixD C22T( TMatrixD::kTransposed,
_C22 );
724 _C22T.ResizeTo( C22T );
750 TMatrixD C31T( TMatrixD::kTransposed,
_C31 );
751 _C31T.ResizeTo( C31T );
763 _C32.ResizeTo( C32 );
766 TMatrixD C32T( TMatrixD::kTransposed,
_C32 );
767 _C32T.ResizeTo( C32T );
789 TMatrixD C33T( TMatrixD::kTransposed,
_C33 );
790 _C33T.ResizeTo( C33T );
802 TMatrixD deltaastar( 1, 1 );
805 deltaastar.ResizeTo(
_nParA, 1 );
806 for (
unsigned int indexParticle = 0; indexParticle <
_unmeasParticles.size(); indexParticle++) {
809 const TMatrixD* astar = particle->
getParCurr();
811 TMatrixD deltaastarpart(*astar);
812 deltaastarpart -= *
a;
814 for (
int indexParam = 0; indexParam < deltaastarpart.GetNrows(); indexParam++) {
815 deltaastar(indexParam+offsetParam, 0) = deltaastarpart(indexParam, 0);
817 offsetParam += deltaastarpart.GetNrows();
828 TMatrixD deltaystar(
_nParB, 1 );
830 for (
unsigned int indexParticle = 0; indexParticle <
_measParticles.size(); indexParticle++) {
833 const TMatrixD* ystar = particle->
getParCurr();
835 TMatrixD deltaystarpart(*ystar);
836 deltaystarpart -= *
y;
838 for (
int indexParam = 0; indexParam < deltaystarpart.GetNrows(); indexParam++) {
839 deltaystar(indexParam+offsetParam, 0) = deltaystarpart(indexParam, 0);
841 offsetParam += deltaystarpart.GetNrows();
845 for (
unsigned int iC = 0; iC <
_constraints.size(); iC++) {
849 if ( constraint->
getNPar() > 0 ) {
851 const TMatrixD* alphastar = constraint->
getParCurr();
854 TMatrixD deltaalphastarpart(*alphastar);
855 deltaalphastarpart -= *
alpha;
857 for (
int indexParam = 0; indexParam < deltaalphastarpart.GetNrows(); indexParam++) {
858 deltaystar(indexParam+offsetParam, 0) = deltaalphastarpart(indexParam, 0);
860 offsetParam += deltaalphastarpart.GetNrows();
871 for (
unsigned int indexConstr = 0; indexConstr <
_constraints.size(); indexConstr++) {
872 fstar( indexConstr, 0 ) =
_constraints[indexConstr]->getCurrentValue();
876 _c.ResizeTo( fstar );
936 TMatrixD lambdaT( TMatrixD::kTransposed,
_lambda );
959 Int_t nbRows =
_C11.GetNrows();
960 Int_t nbCols =
_C11.GetNcols();
962 nbRows +=
_C21.GetNrows();
963 nbCols +=
_C21T.GetNcols();
965 _yaVFit.ResizeTo( nbRows, nbCols );
967 for (
int iRow = 0; iRow < nbRows; iRow++) {
968 for (
int iCol = 0; iCol < nbCols; iCol++) {
970 if (iRow >=
_C11.GetNrows()) {
971 if (iCol >=
_C11.GetNcols()) {
977 if (iCol >=
_C11.GetNcols()) {
995 for (
unsigned int indexParticle = 0; indexParticle <
_measParticles.size(); indexParticle++) {
997 Int_t nbParams = particle->
getNPar();
998 TMatrixD vfit( nbParams, nbParams );
999 for (Int_t
c = 0;
c < nbParams;
c++) {
1000 for (Int_t
r = 0;
r < nbParams;
r++) {
1001 vfit(
r,
c) =
_yaVFit(
r + offsetParam,
c + offsetParam);
1005 offsetParam += nbParams;
1008 for (
unsigned int indexConstraint = 0; indexConstraint <
_constraints.size(); indexConstraint++) {
1010 Int_t nbParams = constraint->
getNPar();
1012 TMatrixD vfit( nbParams, nbParams );
1013 for (Int_t
c = 0;
c < nbParams;
c++) {
1014 for (Int_t
r = 0;
r < nbParams;
r++) {
1015 vfit(
r,
c) =
_yaVFit(
r + offsetParam,
c + offsetParam);
1019 offsetParam += nbParams;
1023 for (
unsigned int indexParticle = 0; indexParticle <
_unmeasParticles.size(); indexParticle++) {
1025 Int_t nbParams = particle->
getNPar();
1026 TMatrixD vfit( nbParams, nbParams );
1027 for (Int_t
c = 0;
c < nbParams;
c++) {
1028 for (Int_t
r = 0;
r < nbParams;
r++) {
1029 vfit(
r,
c) =
_yaVFit(
r + offsetParam,
c + offsetParam);
1033 offsetParam += nbParams;
1041 int offsetParam = 0;
1042 for (
unsigned int indexParticle = 0; indexParticle <
_unmeasParticles.size(); indexParticle++) {
1045 Int_t nbParams = particle->
getNPar();
1046 TMatrixD params( nbParams, 1 );
1051 offsetParam+=nbParams;
1062 int offsetParam = 0;
1063 for (
unsigned int indexParticle = 0; indexParticle <
_measParticles.size(); indexParticle++) {
1066 Int_t nbParams = particle->
getNPar();
1067 TMatrixD params( nbParams, 1 );
1072 offsetParam+=nbParams;
1076 for (
unsigned int indexConstraint = 0; indexConstraint <
_constraints.size(); indexConstraint++) {
1079 Int_t nbParams = constraint->
getNPar();
1080 if ( nbParams > 0 ) {
1081 TMatrixD params( nbParams, 1 );
1086 offsetParam+=nbParams;
1100 for (
unsigned int indexConstr = 0; indexConstr <
_constraints.size(); indexConstr++) {
1116 TMatrixD deltaYTVinv(
_deltaY, TMatrixD::kTransposeMult,
_Vinv);
1129 Bool_t isConverged =
false;
1132 isConverged = (F <
_maxF);
1135 Double_t deltaS = currS - prevS;
1144 TString statusstring =
"";
1149 statusstring =
"NO FIT PERFORMED";
1153 statusstring =
"RUNNING";
1157 statusstring =
"ABORTED";
1161 statusstring =
"CONVERGED";
1165 statusstring =
"NOT CONVERGED";
1170 return statusstring;
1183 log <<
"measured particles: \n";
1187 Int_t nParP = particle->
getNPar();
1188 const TMatrixD* par = particle->
getParCurr();
1190 log << std::setw(3) << setiosflags(std::ios::right) << iP;
1191 log << std::setw(15) << setiosflags(std::ios::right) << particle->GetName();
1192 log << std::setw(3) <<
" ";
1193 for (
int iPar = 0; iPar < nParP; iPar++) {
1195 log << setiosflags(std::ios::right) << std::setw(21) <<
" ";
1197 TString colstr =
"";
1200 log << std::setw(4) << colstr;
1201 log << std::setw(2) <<
" ";
1202 log << setiosflags(std::ios::left) << setiosflags(std::ios::scientific) << std::setprecision(3);
1203 log << std::setw(15) << (*par)(iPar, 0);
1205 log << std::setw(15) << TMath::Sqrt(
_yaVFit(iPar, iPar) );
1207 log << std::setw(15) <<
" ";
1209 log << std::setw(15) << TMath::Sqrt( (*covP)(iPar, iPar) );
1216 log <<
"unmeasured particles: \n";
1220 Int_t nParP = particle->
getNPar();
1221 const TMatrixD* par = particle->
getParCurr();
1222 log << std::setw(3) << setiosflags(std::ios::right) << iP;
1223 log << std::setw(15) << particle->GetName();
1224 log << std::setw(3) <<
" ";
1225 for (
int iPar = 0; iPar < nParP; iPar++) {
1227 log << setiosflags(std::ios::right) << std::setw(21) <<
" ";
1229 TString colstr =
"";
1232 log << std::setw(4) << colstr;
1233 log << std::setw(2) <<
" ";
1234 log << setiosflags(std::ios::left) << setiosflags(std::ios::scientific) << std::setprecision(3);
1235 log << std::setw(15) << (*par)(iPar, 0);
1239 log << std::setw(15) <<
" ";
1248 log <<
"constraints: \n";
1249 for (
unsigned int indexConstr = 0; indexConstr <
_constraints.size(); indexConstr++) {
1261 if (!matrix.IsValid()) {
1262 edm::LogWarning (
"InvalidMatrix") <<
"Matrix " << name <<
" is invalid.";
1268 const Int_t nCols = matrix.GetNcols();
1269 const Int_t nRows = matrix.GetNrows();
1270 const Int_t colsPerSheet = 5;
1272 Int_t nk = 6+13*
TMath::Min(colsPerSheet, nCols);
1273 for(Int_t
i = 0;
i < nk;
i++) topbar[
i] =
'-';
1276 Int_t sw = (70-name.Length())/2;
1278 log << std::setfill(
'=') << std::setw(sw) <<
"= " << name << std::setw(sw) << std::left <<
" =" <<
"\n" 1279 << std::setfill(
' ') << std::right <<
"\n";
1281 log << nRows <<
"x" << nCols <<
" matrix is as follows \n";
1283 for (Int_t iSheet = 0; iSheet < nCols; iSheet += colsPerSheet) {
1286 for (Int_t iCol = iSheet; iCol < nCols; iCol++) {
1287 if (iCol < iSheet+colsPerSheet) log << std::setw(8) << iCol <<
" |";}
1290 for(Int_t iRow = 0; iRow < nRows; iRow++) {
1291 log << std::setw(4) << iRow <<
" |";
1292 for (Int_t iCol = iSheet; iCol < nCols; iCol++) {
1293 if (iCol < iSheet+colsPerSheet ) log << std::setw(12) <<
matrix(iRow, iCol) <<
" "; }
virtual void applyDeltaAlpha(TMatrixD *corrMatrix)
Bool_t converged(Double_t F, Double_t prevS, Double_t currS)
std::vector< TAbsFitParticle * > _measParticles
virtual const TMatrixD * getCovMatrix() const
TString getStatusString()
void addMeasParticles(TAbsFitParticle *p1, TAbsFitParticle *p2=0, TAbsFitParticle *p3=0, TAbsFitParticle *p4=0, TAbsFitParticle *p5=0, TAbsFitParticle *p6=0, TAbsFitParticle *p7=0, TAbsFitParticle *p8=0, TAbsFitParticle *p9=0)
virtual TMatrixD * getDerivativeAlpha()
std::vector< TAbsFitParticle * > _unmeasParticles
void addUnmeasParticles(TAbsFitParticle *p1, TAbsFitParticle *p2=0, TAbsFitParticle *p3=0, TAbsFitParticle *p4=0, TAbsFitParticle *p5=0, TAbsFitParticle *p6=0, TAbsFitParticle *p7=0, TAbsFitParticle *p8=0, TAbsFitParticle *p9=0)
virtual void setCovMatrixFit(const TMatrixD *theCovMatrixFit)
virtual TMatrixD * getDerivative()=0
void addConstraint(TAbsFitConstraint *constraint)
void addUnmeasParticle(TAbsFitParticle *particle)
void addMeasParticle(TAbsFitParticle *particle)
virtual void applycorr(TMatrixD *corrMatrix)
void setCovMatrix(TMatrixD &V)
void setVerbosity(Int_t verbosity=1)
const TMatrixD * getParIni()
void printMatrix(const TMatrixD &matrix, const TString &name="")
double S(const TLorentzVector &, const TLorentzVector &)
const TMatrixD * getParIni()
std::vector< TAbsFitConstraint * > _constraints
virtual const TMatrixD * getCovMatrix() const
virtual void setCovMatrixFit(const TMatrixD *theCovMatrixFit)
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
const TMatrixD * getParCurr()
const TMatrixD * getParCurr()