149 using namespace Eigen;
163 GblTrajectory::GblTrajectory(
const std::vector<GblPoint> &aPointList,
164 bool flagCurv,
bool flagU1dir,
bool flagU2dir) :
165 numAllPoints(aPointList.size()), numPoints(), numOffsets(0), numInnerTransformations(
166 0), numInnerTransOffsets(0), numCurvature(flagCurv ? 1 : 0), numParameters(
167 0), numLocals(0), numMeasurements(0), externalPoint(0), skippedMeasLabel(
168 0), maxNumGlobals(0), theDimension(0), thePoints(), theData(), measDataIndex(), scatDataIndex(), externalSeed(), innerTransformations(), externalDerivatives(), externalMeasurements(), externalPrecisions() {
175 thePoints.emplace_back(std::move(aPointList));
186 const std::vector<std::pair<std::vector<GblPoint>, Eigen::MatrixXd> >& aPointsAndTransList) :
187 numAllPoints(), numPoints(), numOffsets(0), numInnerTransformations(
188 aPointsAndTransList.size()), numParameters(0), numLocals(0), numMeasurements(
189 0), externalPoint(0), skippedMeasLabel(0), maxNumGlobals(0), theDimension(
190 0), thePoints(), theData(), measDataIndex(), scatDataIndex(), externalSeed(), innerTransformations(), externalDerivatives(), externalMeasurements(), externalPrecisions() {
192 for (
unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
193 thePoints.push_back(aPointsAndTransList[iTraj].first);
209 #ifdef GBL_EIGEN_SUPPORT_ROOT
223 unsigned int aLabel,
const TMatrixDSym &aSeed,
bool flagCurv,
224 bool flagU1dir,
bool flagU2dir) :
225 numAllPoints(aPointList.size()), numPoints(), numOffsets(0),
226 numInnerTransformations(0), numInnerTransOffsets(0), numCurvature(flagCurv ? 1 : 0), numParameters(0),
227 numLocals(0), numMeasurements(0), externalPoint(aLabel), skippedMeasLabel(0),
228 maxNumGlobals(0), theDimension(0), thePoints(), theData(), measDataIndex(),
229 scatDataIndex(), externalSeed(), innerTransformations(), externalDerivatives(),
230 externalMeasurements(), externalPrecisions() {
237 unsigned int nParSeed = aSeed.GetNrows();
239 for (
unsigned int i = 0; i < nParSeed; ++i) {
240 for (
unsigned int j = 0; j < nParSeed; ++j) {
245 thePoints.emplace_back(std::move(aPointList));
256 numAllPoints(), numPoints(), numOffsets(0), numInnerTransformations(aPointsAndTransList.size()),
257 numParameters(0), numLocals(0), numMeasurements(0), externalPoint(0),
258 skippedMeasLabel(0), maxNumGlobals(0), theDimension(0), thePoints(), theData(),
259 measDataIndex(), scatDataIndex(), externalSeed(), innerTransformations(),
260 externalDerivatives(), externalMeasurements(), externalPrecisions() {
262 for (
unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
263 thePoints.emplace_back(std::move(aPointsAndTransList[iTraj].first));
267 unsigned int nRowTrans = aPointsAndTransList[iTraj].second.GetNrows();
268 unsigned int nColTrans = aPointsAndTransList[iTraj].second.GetNcols();
269 MatrixXd aTrans(nRowTrans, nColTrans);
270 for (
unsigned int i = 0; i < nRowTrans; ++i) {
271 for (
unsigned int j = 0; j < nColTrans; ++j) {
272 aTrans(i, j) = aPointsAndTransList[iTraj].second(i, j);
297 const TMatrixD &extDerivatives,
const TVectorD &extMeasurements,
298 const TVectorD &extPrecisions) :
299 numAllPoints(), numPoints(), numOffsets(0), numInnerTransformations(aPointsAndTransList.size()),
300 numParameters(0), numLocals(0), numMeasurements(0), externalPoint(0),
301 skippedMeasLabel(0), maxNumGlobals(0), theDimension(0), thePoints(), theData(),
302 measDataIndex(), scatDataIndex(), externalSeed(), innerTransformations(),
303 externalDerivatives(), externalMeasurements(), externalPrecisions() {
306 unsigned int nExtMeas = extDerivatives.GetNrows();
307 unsigned int nExtPar = extDerivatives.GetNcols();
311 for (
unsigned int i = 0; i < nExtMeas; ++i) {
314 for (
unsigned int j = 0; j < nExtPar; ++j) {
318 for (
unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
319 thePoints.emplace_back(std::move(aPointsAndTransList[iTraj].first));
323 unsigned int nRowTrans = aPointsAndTransList[iTraj].second.GetNrows();
324 unsigned int nColTrans = aPointsAndTransList[iTraj].second.GetNcols();
325 MatrixXd aTrans(nRowTrans, nColTrans);
326 for (
unsigned int i = 0; i < nRowTrans; ++i) {
327 for (
unsigned int j = 0; j < nColTrans; ++j) {
328 aTrans(i, j) = aPointsAndTransList[iTraj].second(i, j);
353 const TMatrixD &extDerivatives,
const TVectorD &extMeasurements,
354 const TMatrixDSym &extPrecisions) :
355 numAllPoints(), numPoints(), numOffsets(0), numInnerTransformations(aPointsAndTransList.size()),
356 numParameters(0), numLocals(0), numMeasurements(0), externalPoint(0),
357 skippedMeasLabel(0), maxNumGlobals(0), theDimension(0), thePoints(), theData(),
358 measDataIndex(), scatDataIndex(), externalSeed(), innerTransformations() {
361 TMatrixDSymEigen extEigen(extPrecisions);
362 TMatrixD extTransformation = extEigen.GetEigenVectors();
363 extTransformation.T();
364 TMatrixD aDerivatives = extTransformation * extDerivatives;
365 TVectorD aMeasurements = extTransformation * extMeasurements;
366 TVectorD aPrecisions = extEigen.GetEigenValues();
368 unsigned int nExtMeas = aDerivatives.GetNrows();
369 unsigned int nExtPar = aDerivatives.GetNcols();
373 for (
unsigned int i = 0; i < nExtMeas; ++i) {
376 for (
unsigned int j = 0; j < nExtPar; ++j) {
380 for (
unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
381 thePoints.emplace_back(std::move(aPointsAndTransList[iTraj].first));
385 unsigned int nRowTrans = aPointsAndTransList[iTraj].second.GetNrows();
386 unsigned int nColTrans = aPointsAndTransList[iTraj].second.GetNcols();
387 MatrixXd aTrans(nRowTrans, nColTrans);
388 for (
unsigned int i = 0; i < nRowTrans; ++i) {
389 for (
unsigned int j = 0; j < nColTrans; ++j) {
390 aTrans(i, j) = aPointsAndTransList[iTraj].second(i, j);
428 unsigned int aLabel = 0;
430 std::cout <<
" GblTrajectory construction failed: too few GblPoints "
438 std::vector<GblPoint>::iterator itPoint;
440 itPoint <
thePoints[iTraj].end(); ++itPoint) {
443 itPoint->setLabel(++aLabel);
450 }
catch (std::overflow_error &e) {
451 std::cout <<
" GblTrajectory construction failed: " << e.what()
455 std::cout <<
" GblTrajectory construction failed with exception " << i
479 std::vector<GblPoint>::iterator itPoint;
480 for (itPoint =
thePoints[iTraj].begin() + 1;
481 itPoint <
thePoints[iTraj].end() - 1; ++itPoint) {
482 if (itPoint->hasScatterer()) {
501 unsigned int numStep = 0;
502 std::vector<GblPoint>::iterator itPoint;
503 for (itPoint =
thePoints[iTraj].begin() + 1;
504 itPoint <
thePoints[iTraj].end(); ++itPoint) {
506 scatJacobian = itPoint->getP2pJacobian();
508 scatJacobian = itPoint->getP2pJacobian() * scatJacobian;
511 itPoint->addPrevJacobian(scatJacobian);
512 if (itPoint->getOffset() >= 0) {
515 previousPoint = &(*itPoint);
519 for (itPoint =
thePoints[iTraj].end() - 1;
520 itPoint >
thePoints[iTraj].begin(); --itPoint) {
521 if (itPoint->getOffset() >= 0) {
525 itPoint->addNextJacobian(scatJacobian);
526 scatJacobian = scatJacobian * itPoint->getP2pJacobian();
541 int aSignedLabel)
const {
547 unsigned int aLabel = abs(aSignedLabel);
548 unsigned int firstLabel = 1;
549 unsigned int lastLabel = 0;
550 unsigned int aTrajectory = 0;
555 if (aLabel <= lastLabel)
562 if (aSignedLabel > 0) {
564 if (aLabel >= lastLabel) {
570 if (aLabel <= firstLabel) {
577 std::array<unsigned int, 5> labDer;
581 unsigned int nBand = 0;
585 for (
unsigned int i = 0; i < 5; ++i)
586 if (labDer[i] > lastExt)
592 unsigned int nBorder = nCurv + nLocals;
593 unsigned int nParBRL = nBorder + nBand;
594 unsigned int nParLoc = nLocals + 5;
595 std::vector<unsigned int> anIndex;
596 anIndex.reserve(nParBRL);
597 MatrixXd aJacobian(nParLoc, nParBRL);
601 for (
unsigned int i = 0; i < nLocals; ++i) {
602 aJacobian(i + 5, i) = 1.0;
603 anIndex.push_back(i + 1);
606 unsigned int iCol = nLocals;
610 unsigned int nSimple = nCurv + nBand;
611 MatrixXd aTrans(5, nSimple);
614 aTrans.block(0, 0, 1, nCurv) =
innerTransDer[aTrajectory].block(0, 0, 1,
616 for (
unsigned int i = 0; i < nCurv; ++i)
617 anIndex.push_back(++iCol);
621 aTrans.block(1, 0, 4 - nBand, nCurv) =
625 for (
unsigned int i = 5 - nBand; i < 5; ++i) {
626 aTrans(i, iCol++) = 1.;
631 aJacobian.block(0, nLocals, 5, nSimple) = matDer * aTrans;
634 for (
unsigned int i = 0; i < 5; ++i) {
636 anIndex.push_back(labDer[i]);
637 for (
unsigned int j = 0; j < 5; ++j) {
638 aJacobian(j, iCol) = matDer(j, i);
644 return std::make_pair(anIndex, aJacobian);
659 unsigned int nJacobian)
const {
671 Matrix2d prevW, prevWJ, nextW, nextWJ, matN;
672 Vector2d prevWd, nextWd;
675 const Matrix2d sumWJ(prevWJ + nextWJ);
676 matN = sumWJ.inverse();
678 const Matrix2d prevNW(matN * prevW);
679 const Matrix2d nextNW(matN * nextW);
680 const Vector2d prevNd(matN * prevWd);
681 const Vector2d nextNd(matN * nextWd);
683 unsigned int iOff = nDim * (-nOffset - 1) + nLocals + nCurv + 1;
687 aJacobian.block<2, 1>(3, 0) = -prevNd - nextNd;
688 anIndex[0] = nLocals + 1;
690 aJacobian.block<2, 2>(3, 1) = prevNW;
691 aJacobian.block<2, 2>(3, 3) = nextNW;
692 for (
unsigned int i = 0; i < nDim; ++i) {
700 const Matrix2d prevWPN(nextWJ * prevNW);
701 const Matrix2d nextWPN(prevWJ * nextNW);
702 const Vector2d prevWNd(nextWJ * prevNd);
703 const Vector2d nextWNd(prevWJ * nextNd);
705 aJacobian(0, 0) = 1.0;
706 aJacobian.block<2, 1>(1, 0) = prevWNd - nextWNd;
708 aJacobian.block<2, 2>(1, 1) = -prevWPN;
709 aJacobian.block<2, 2>(1, 3) = nextWPN;
715 unsigned int iOff1 = nDim * nOffset + nCurv + nLocals + 1;
716 unsigned int index1 = 3 - 2 * nJacobian;
717 unsigned int iOff2 = iOff1 + nDim * (nJacobian * 2 - 1);
718 unsigned int index2 = 1 + 2 * nJacobian;
720 aJacobian(3, index1) = 1.0;
721 aJacobian(4, index1 + 1) = 1.0;
722 for (
unsigned int i = 0; i < nDim; ++i) {
728 Matrix2d matW, matWJ;
731 double sign = (nJacobian > 0) ? 1. : -1.;
733 aJacobian(0, 0) = 1.0;
734 aJacobian.block<2, 1>(1, 0) = -sign * vecWd;
735 anIndex[0] = nLocals + 1;
737 aJacobian.block<2, 2>(1, index1) = -sign * matWJ;
738 aJacobian.block<2, 2>(1, index2) = sign * matW;
739 for (
unsigned int i = 0; i < nDim; ++i) {
765 Matrix2d prevW, prevWJ, nextW, nextWJ;
766 Vector2d prevWd, nextWd;
769 const Matrix2d sumWJ(prevWJ + nextWJ);
770 const Vector2d sumWd(prevWd + nextWd);
772 unsigned int iOff = (nOffset - 1) * nDim + nCurv + nLocals + 1;
776 aJacobian.block<2, 1>(0, 0) = -sumWd;
777 anIndex[0] = nLocals + 1;
779 aJacobian.block<2, 2>(0, 1) = prevW;
780 aJacobian.block<2, 2>(0, 3) = -sumWJ;
781 aJacobian.block<2, 2>(0, 5) = nextW;
782 for (
unsigned int i = 0; i < nDim; ++i) {
805 Eigen::VectorXd &localPar, Eigen::MatrixXd &localCov)
const {
808 std::pair<std::vector<unsigned int>, MatrixXd> indexAndJacobian =
810 unsigned int nParBrl = indexAndJacobian.first.size();
811 VectorXd aVec(nParBrl);
812 for (
unsigned int i = 0; i < nParBrl; ++i) {
813 aVec[i] =
theVector(indexAndJacobian.first[i] - 1);
816 localPar = indexAndJacobian.second * aVec;
817 localCov = indexAndJacobian.second * aMat
818 * indexAndJacobian.second.adjoint();
836 unsigned int &numData, Eigen::VectorXd &aResiduals,
837 Eigen::VectorXd &aMeasErrors, Eigen::VectorXd &aResErrors,
838 Eigen::VectorXd &aDownWeights) {
845 for (
unsigned int i = 0; i < numData; ++i) {
847 aMeasErrors(i), aResErrors(i), aDownWeights(i));
866 unsigned int &numData, Eigen::VectorXd &aResiduals,
867 Eigen::VectorXd &aMeasErrors, Eigen::VectorXd &aResErrors,
868 Eigen::VectorXd &aDownWeights) {
875 for (
unsigned int i = 0; i < numData; ++i) {
876 getResAndErr(firstData + i,
true, aResiduals(i), aMeasErrors(i),
877 aResErrors(i), aDownWeights(i));
882 #ifdef GBL_EIGEN_SUPPORT_ROOT
899 TMatrixDSym &localCov)
const {
902 std::pair<std::vector<unsigned int>, MatrixXd> indexAndJacobian =
904 unsigned int nParBrl = indexAndJacobian.first.size();
905 VectorXd aVec(nParBrl);
906 for (
unsigned int i = 0; i < nParBrl; ++i) {
907 aVec[i] =
theVector(indexAndJacobian.first[i] - 1);
910 VectorXd aLocalPar = indexAndJacobian.second * aVec;
911 MatrixXd aLocalCov = indexAndJacobian.second * aMat
912 * indexAndJacobian.second.adjoint();
914 unsigned int nParOut = localPar.GetNrows();
915 for (
unsigned int i = 0; i < nParOut; ++i) {
916 localPar[i] = aLocalPar(i);
917 for (
unsigned int j = 0; j < nParOut; ++j) {
918 localCov(i, j) = aLocalCov(i, j);
938 unsigned int &numData, TVectorD &aResiduals, TVectorD &aMeasErrors,
939 TVectorD &aResErrors, TVectorD &aDownWeights) {
946 for (
unsigned int i = 0; i < numData; ++i) {
948 aMeasErrors[i], aResErrors[i], aDownWeights[i]);
967 unsigned int &numData, TVectorD &aResiduals, TVectorD &aMeasErrors,
968 TVectorD &aResErrors, TVectorD &aDownWeights) {
975 for (
unsigned int i = 0; i < numData; ++i) {
976 getResAndErr(firstData + i,
true, aResiduals[i], aMeasErrors[i],
977 aResErrors[i], aDownWeights[i]);
990 std::vector<unsigned int> &aLabelList)
const {
994 unsigned int aLabel = 0;
995 unsigned int nPoint =
thePoints[0].size();
996 aLabelList.resize(nPoint);
997 for (
unsigned i = 0; i < nPoint; ++i) {
998 aLabelList[i] = ++aLabel;
1009 std::vector<std::vector<unsigned int> > &aLabelList)
const {
1013 unsigned int aLabel = 0;
1016 unsigned int nPoint =
thePoints[iTraj].size();
1017 aLabelList[iTraj].resize(nPoint);
1018 for (
unsigned i = 0; i < nPoint; ++i) {
1019 aLabelList[iTraj][i] = ++aLabel;
1037 double &aResidual,
double &aMeasError,
double &aResError,
1038 double &aDownWeight) {
1041 unsigned int numLocal;
1042 unsigned int* indLocal;
1044 theData[aData].getResidual(aResidual, aMeasVar, aDownWeight, numLocal,
1045 indLocal, derLocal);
1046 VectorXd aVec(numLocal);
1047 for (
unsigned int j = 0; j < numLocal; ++j) {
1048 aVec[j] = derLocal[j];
1051 double aFitVar = aVec.transpose() * aMat * aVec;
1052 aFitVar *= aDownWeight;
1053 aMeasError = sqrt(aMeasVar);
1055 aResError = (aFitVar < aMeasVar ? sqrt(aMeasVar - aFitVar) : 0.);
1057 aResError = sqrt(aMeasVar + aFitVar);
1065 double aValue, aWeight;
1066 unsigned int* indLocal;
1068 unsigned int numLocal;
1070 std::vector<GblData>::iterator itData;
1071 for (itData =
theData.begin(); itData <
theData.end(); ++itData) {
1077 itData->getLocalData(aValue, aWeight, numLocal, indLocal, derLocal);
1078 for (
unsigned int j = 0; j < numLocal; ++j) {
1079 theVector(indLocal[j] - 1) += derLocal[j] * aWeight * aValue;
1101 unsigned int nData = 0;
1108 if (nInnerTransRows != 5 and nInnerTransRows != 2) {
1110 <<
" GblTrajectory::prepare composed trajectory with bad inner transformation matrix("
1111 << nInnerTransRows <<
"," << nInnerTransCols
1112 <<
"): invalid number of rows" << std::endl;
1115 if (nInnerTransRows > nInnerTransCols) {
1117 <<
" GblTrajectory::prepare composed trajectory with bad inner transformation matrix("
1118 << nInnerTransRows <<
"," << nInnerTransCols
1119 <<
"): too few columns" << std::endl;
1127 <<
" GblTrajectory::prepare composed trajectory with bad inner transformation matrix["
1128 << iTraj <<
"]: different size as [0]" << std::endl;
1134 std::array<unsigned int, 5> firstLabels;
1137 if (nInnerTransRows == 5) {
1140 Matrix5d matLocalToFit = matFitToLocal.inverse();
1147 matInnerToFit.setZero();
1148 matInnerToFit(0, nInnerTransCols + iTraj) = 1.;
1149 matInnerToFit.block(1, 0, 2, nInnerTransCols) =
1158 std::vector<GblPoint>::iterator itPoint;
1162 Eigen::Matrix<double, Eigen::Dynamic, 5, Eigen::ColMajor ,
1166 for (itPoint =
thePoints[iTraj].begin();
1167 itPoint <
thePoints[iTraj].end(); ++itPoint) {
1169 unsigned int nLabel = itPoint->getLabel();
1170 unsigned int measDim = itPoint->hasMeasurement();
1172 const MatrixXd localDer = itPoint->getLocalDerivatives();
1174 itPoint->getNumGlobals());
1176 itPoint->getMeasurement(matP, aMeas, aPrec);
1177 double minPrecision = itPoint->getMeasPrecMin();
1178 unsigned int iOff = 5 - measDim;
1179 std::array<unsigned int, 5> labDer;
1181 unsigned int nJacobian =
1182 (itPoint <
thePoints[iTraj].end() - 1) ? 1 : 0;
1186 matPDer = matP * matDer;
1189 matPDer.block<2, 5>(3, 0) = matP.block<2, 2>(3, 3)
1190 * matDer.block<2, 5>(3, 0);
1195 proDer.resize(measDim, Eigen::NoChange);
1198 unsigned int ifirst = 0;
1200 unsigned int ilabel = 0;
1201 unsigned int numRelated = 0;
1202 while (ilabel < 5) {
1203 if (labDer[ilabel] > 0) {
1205 != labDer[ilabel] and ifirst <= ilast) {
1208 if (ifirst > ilast) {
1210 * nDim * (iTraj + 1);
1215 for (
unsigned int k = iOff; k < 5; ++k) {
1216 proDer(k - iOff, ifirst) = matPDer(k,
1223 if (numRelated > 0) {
1228 for (
unsigned int i = iOff; i < 5; ++i) {
1229 if (aPrec(i) > minPrecision) {
1235 theData.emplace_back(std::move(aData));
1250 Eigen::Matrix<double, Eigen::Dynamic, 5, Eigen::ColMajor ,
1256 for (itPoint =
thePoints[iTraj].begin() + 1;
1257 itPoint <
thePoints[iTraj].end() - 1; ++itPoint) {
1258 Vector2d aMeas, aPrec;
1259 unsigned int nLabel = itPoint->getLabel();
1260 if (itPoint->hasScatterer()) {
1261 itPoint->getScatterer(matT, aMeas, aPrec);
1263 std::array<unsigned int, 7> labDer;
1266 matTDer = matT * matDer;
1269 proDer.resize(nDim, Eigen::NoChange);
1272 unsigned int ifirst = 0;
1274 unsigned int ilabel = 0;
1275 unsigned int numRelated = 0;
1276 while (ilabel < 7) {
1277 if (labDer[ilabel] > 0) {
1279 != labDer[ilabel] and ifirst <= ilast) {
1282 if (ifirst > ilast) {
1284 * nDim * (iTraj + 1);
1289 for (
unsigned int k = 0; k < nDim; ++k) {
1290 proDer(k, ifirst) = matTDer(k, ilabel);
1296 if (numRelated > 0) {
1301 for (
unsigned int i = 0; i < nDim; ++i) {
1303 if (aPrec(iDim) > 0.) {
1309 theData.emplace_back(std::move(aData));
1322 std::pair<std::vector<unsigned int>, MatrixXd> indexAndJacobian =
1324 std::vector<unsigned int> externalSeedIndex = indexAndJacobian.first;
1325 std::vector<double> externalSeedDerivatives(externalSeedIndex.size());
1326 SelfAdjointEigenSolver<MatrixXd> externalSeedEigen(
externalSeed);
1327 VectorXd valEigen = externalSeedEigen.eigenvalues();
1328 MatrixXd vecEigen = externalSeedEigen.eigenvectors();
1329 vecEigen = vecEigen.transpose() * indexAndJacobian.second;
1331 if (valEigen(i) > 0.) {
1333 externalSeedDerivatives[j] = vecEigen(i, j);
1337 externalSeedDerivatives);
1338 theData.emplace_back(std::move(aData));
1349 for (
unsigned int iExt = 0; iExt < nExt; ++iExt) {
1350 for (
unsigned int iCol = 0; iCol <
numCurvature; ++iCol) {
1357 theData.emplace_back(std::move(aData));
1366 std::vector<GblData>::iterator itData;
1367 for (itData =
theData.begin(); itData <
theData.end(); ++itData) {
1378 std::vector<GblData>::iterator itData;
1379 for (itData =
theData.begin(); itData <
theData.end(); ++itData) {
1380 aLoss += (1. - itData->setDownWeighting(aMethod));
1399 const std::string& optionList,
unsigned int aLabel) {
1400 const double normChi2[4] = { 1.0, 0.8737, 0.9326, 0.8228 };
1401 const std::string methodList =
"TtHhCc";
1409 unsigned int aMethod = 0;
1414 unsigned int ierr = 0;
1420 for (
unsigned int i = 0; i < optionList.size(); ++i)
1422 size_t aPosition = methodList.find(optionList[i]);
1423 if (aPosition != std::string::npos) {
1424 aMethod = aPosition / 2 + 1;
1433 for (
unsigned int i = 0; i <
theData.size(); ++i) {
1441 Chi2 /= normChi2[aMethod];
1445 std::cout <<
" GblTrajectory::fit exception " << e << std::endl;
1459 unsigned int aPoint;
1461 unsigned int numLocal;
1462 unsigned int* labLocal;
1464 std::vector<int> labGlobal;
1465 std::vector<double> derGlobal;
1473 std::vector<GblData>::iterator itData;
1474 for (itData =
theData.begin(); itData !=
theData.end(); ++itData) {
1475 itData->getAllData(aValue, aErr, numLocal, labLocal, derLocal, aTraj,
1478 thePoints[aTraj][aPoint].getGlobalLabelsAndDerivatives(aRow,
1479 labGlobal, derGlobal);
1481 labGlobal.resize(0);
1482 aMille.
addData(aValue, aErr, numLocal, labLocal, derLocal, labGlobal,
1498 std::cout <<
"Simple GblTrajectory" << std::endl;
1501 std::cout <<
" 2D-trajectory" << std::endl;
1505 std::cout <<
" Number of points with offsets: " <<
numOffsets << std::endl;
1506 std::cout <<
" Number of fit parameters : " <<
numParameters
1511 std::cout <<
" Number of ext. measurements : "
1515 std::cout <<
" Label of point with ext. seed: " <<
externalPoint
1519 std::cout <<
" Constructed OK " << std::endl;
1522 std::cout <<
" Fitted OK " << std::endl;
1525 IOFormat CleanFmt(4, 0,
", ",
"\n",
"[",
"]");
1527 std::cout <<
" Inner transformations" << std::endl;
1534 std::cout <<
" External measurements" << std::endl;
1535 std::cout <<
" Measurements:" << std::endl;
1537 std::cout <<
" Precisions:" << std::endl;
1539 std::cout <<
" Derivatives:" << std::endl;
1543 std::cout <<
" External seed:" << std::endl;
1544 std::cout <<
externalSeed.format(CleanFmt) << std::endl;
1547 std::cout <<
" Fit results" << std::endl;
1548 std::cout <<
" Parameters:" << std::endl;
1550 std::cout <<
" Covariance matrix (bordered band part):"
1562 std::cout <<
"GblPoints " << std::endl;
1564 std::vector<GblPoint>::const_iterator itPoint;
1565 for (itPoint =
thePoints[iTraj].begin();
1566 itPoint <
thePoints[iTraj].end(); ++itPoint) {
1567 itPoint->printPoint(level);
1574 std::cout <<
"GblData blocks " << std::endl;
1575 std::vector<GblData>::const_iterator itData;
1576 for (itData =
theData.begin(); itData <
theData.end(); ++itData) {
1577 itData->printData();
void printMatrix() const
Print bordered band matrix.
Eigen::MatrixXd getBlockMatrix(const std::vector< unsigned int > anIndex) const
Retrieve symmetric block matrix.
void resize(unsigned int nSize, unsigned int nBorder=1, unsigned int nBand=5)
Resize bordered band matrix.
void solveAndInvertBorderedBand(const VVector &aRightHandSide, VVector &aSolution)
Solve linear equation system, partially calculate inverse.
void addBlockMatrix(double aWeight, const std::vector< unsigned int > *anIndex, const std::vector< double > *aVector)
Add symmetric block matrix.
Data (block) for independent scalar measurement.
void addDerivatives(unsigned int iRow, const std::array< unsigned int, 5 > &labDer, const Matrix5d &matDer, unsigned int iOff, const Eigen::MatrixBase< LocalDerivative > &derLocal, unsigned int extOff, const Eigen::MatrixBase< ExtDerivative > &extDer)
Add derivatives from measurement.
void getDerivatives(int aDirection, Eigen::Matrix2d &matW, Eigen::Matrix2d &matWJ, Eigen::Vector2d &vecWd) const
Retrieve derivatives of local track model.
void addNextJacobian(const Matrix5d &aJac)
Define jacobian to next scatterer (by GBLTrajectory constructor)
const Matrix5d & getP2pJacobian() const
Retrieve point-to-(previous)point jacobian.
int getOffset() const
Retrieve offset for point.
std::vector< unsigned int > numPoints
Number of points on (sub)trajectory.
std::vector< unsigned int > scatDataIndex
mapping points to data blocks from scatterers
BorderedBandMatrix theMatrix
(Bordered band) matrix of linear equation system
std::vector< std::vector< GblPoint > > thePoints
(list of) List of points on trajectory
void printPoints(unsigned int level=0) const
Print GblPoints on trajectory.
unsigned int skippedMeasLabel
Label of point with measurements skipped in fit (for unbiased residuals) (or 0)
unsigned int numTrajectories
Number of trajectories (in composed trajectory)
void construct()
Construct trajectory from list of points.
unsigned int externalPoint
Label of external point (or 0)
Eigen::MatrixXd externalSeed
Precision (inverse covariance matrix) of external seed.
unsigned int getMeasResults(unsigned int aLabel, unsigned int &numData, Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors, Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights)
Get residuals from fit at point for measurement.
unsigned int numAllPoints
Number of all points on trajectory.
double downWeight(unsigned int aMethod)
Down-weight all points.
VVector theVector
Vector of linear equation system.
void calcJacobians()
Calculate Jacobians to previous/next scatterer from point to point ones.
unsigned int numCurvature
Number of curvature parameters (0 or 1) or external parameters.
Eigen::VectorXd externalPrecisions
Precisions for external measurements of composed trajectory.
std::vector< std::array< unsigned int, 5 > > innerTransLab
Labels at innermost points of composed trajectory.
Eigen::VectorXd externalMeasurements
Residuals for external measurements of composed trajectory.
void printTrajectory(unsigned int level=0) const
Print GblTrajectory.
void predict()
Calculate predictions for all points.
void defineOffsets()
Define offsets from list of points.
std::vector< Eigen::MatrixXd > innerTransformations
Transformations at innermost points of composed trajectory (from common external parameters)
unsigned int numLocals
Total number of (additional) local parameters.
void getResAndErr(unsigned int aData, bool used, double &aResidual, double &aMeadsError, double &aResError, double &aDownWeight)
Get residual and errors from data block.
void milleOut(MilleBinary &aMille)
Write valid trajectory to Millepede-II binary file.
void getFitToLocalJacobian(std::array< unsigned int, 5 > &anIndex, Matrix5d &aJacobian, const GblPoint &aPoint, unsigned int measDim, unsigned int nJacobian=1) const
Get (part of) jacobian for transformation from (trajectory) fit to track parameters at point.
unsigned int numInnerTransformations
Number of inner transformations to external parameters.
unsigned int maxNumGlobals
Max. number of global labels/derivatives per point.
bool isValid() const
Retrieve validity of trajectory.
GblTrajectory(const std::vector< GblPoint > &aPointList, bool flagCurv=true, bool flagU1dir=true, bool flagU2dir=true)
Create new (simple) trajectory from list of points.
void prepare()
Prepare fit for simple or composed trajectory.
unsigned int getResults(int aSignedLabel, Eigen::VectorXd &localPar, Eigen::MatrixXd &localCov) const
Get fit results at point.
Eigen::MatrixXd externalDerivatives
Derivatives for external measurements of composed trajectory.
unsigned int fit(double &Chi2, int &Ndf, double &lostWeight, const std::string &optionList="", unsigned int aLabel=0)
Perform fit of (valid) trajectory.
unsigned int getScatResults(unsigned int aLabel, unsigned int &numData, Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors, Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights)
Get (kink) residuals from fit at point for scatterer.
std::vector< GblData > theData
List of data blocks.
bool constructOK
Trajectory has been successfully constructed (ready for fit/output)
unsigned int numInnerTransOffsets
Number of (points with) offsets affected by inner transformations to external parameters.
std::vector< unsigned int > measDataIndex
mapping points to data blocks from measurements
void getFitToKinkJacobian(std::array< unsigned int, 7 > &anIndex, Matrix27d &aJacobian, const GblPoint &aPoint) const
Get jacobian for transformation from (trajectory) fit to kink parameters at point.
void buildLinearEquationSystem()
Build linear equation system from data (blocks).
void printData() const
Print GblData blocks for trajectory.
unsigned int getLabels(std::vector< unsigned int > &aLabelList) const
Get (list of) labels of points on (simple) valid trajectory.
unsigned int numParameters
Number of fit parameters.
unsigned int numMeasurements
Total number of measurements.
std::vector< Eigen::MatrixXd > innerTransDer
Derivatives at innermost points of composed trajectory.
std::pair< std::vector< unsigned int >, Eigen::MatrixXd > getJacobian(int aSignedLabel) const
Get jacobian for transformation from fit to track parameters at point.
bool fitOK
Trajectory has been successfully fitted (results are valid)
unsigned int numOffsets
Number of (points with) offsets on trajectory.
std::vector< unsigned int > theDimension
List of active dimensions (0=u1, 1=u2) in fit.
unsigned int getNumPoints() const
Retrieve number of point from trajectory.
Millepede-II (binary) record.
void writeRecord()
Write record to file.
void addData(double aMeas, double aErr, unsigned int numLocal, unsigned int *indLocal, double *derLocal, const std::vector< int > &labGlobal, const std::vector< double > &derGlobal)
Add data block to (end of) record.
void resize(const unsigned int nRows)
Resize vector.
void print() const
Print vector.
Namespace for the general broken lines package.
Eigen::Matrix< double, 5, 1 > Vector5d
Eigen::Matrix< double, 2, 7 > Matrix27d
Eigen::Matrix< double, 5, 5 > Matrix5d