CMS 3D CMS Logo

GblTrajectory.cc
Go to the documentation of this file.
1 /*
2  * GblTrajectory.cpp
3  *
4  * Created on: Aug 18, 2011
5  * Author: kleinwrt
6  */
7 
139 using namespace Eigen;
140 
142 namespace gbl {
143 
145 
153  GblTrajectory::GblTrajectory(const std::vector<GblPoint> &aPointList,
154  bool flagCurv, bool flagU1dir, bool flagU2dir) :
155  numAllPoints(aPointList.size()), numPoints(), numOffsets(0),
156  numInnerTrans(0), numCurvature(flagCurv ? 1 : 0), numParameters(0),
157  numLocals(0), numMeasurements(0), externalPoint(0), skippedMeasLabel(0),
158  maxNumGlobals(0), theDimension(0), thePoints(), theData(), measDataIndex(),
159  scatDataIndex(), externalSeed(), innerTransformations(),
160  externalDerivatives(), externalMeasurements(), externalPrecisions()
161  {
162 
163  if (flagU1dir)
164  theDimension.push_back(0);
165  if (flagU2dir)
166  theDimension.push_back(1);
167  // simple (single) trajectory
168  thePoints.emplace_back(std::move(aPointList));
169  numPoints.push_back(numAllPoints);
170  construct(); // construct trajectory
171  }
172 
174 
178  GblTrajectory::GblTrajectory(const std::vector<std::pair<std::vector<GblPoint>, MatrixXd> > &aPointsAndTransList) :
180  numInnerTrans(aPointsAndTransList.size()), numParameters(0), numLocals(0),
185  {
186 
187  for (unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
188  thePoints.push_back(aPointsAndTransList[iTraj].first);
189  numPoints.push_back(thePoints.back().size());
190  numAllPoints += numPoints.back();
191  innerTransformations.push_back(aPointsAndTransList[iTraj].second);
192  }
193  theDimension.push_back(0);
194  theDimension.push_back(1);
196  construct(); // construct (composed) trajectory
197  }
198 
199 #ifdef GBL_EIGEN_SUPPORT_ROOT
200 
212  GblTrajectory::GblTrajectory(const std::vector<GblPoint> &aPointList,
213  unsigned int aLabel, const TMatrixDSym &aSeed,
214  bool flagCurv, bool flagU1dir, bool flagU2dir) :
215  numAllPoints(aPointList.size()), numPoints(), numOffsets(0),
216  numInnerTrans(0), numCurvature(flagCurv ? 1 : 0), numParameters(0),
217  numLocals(0), numMeasurements(0), externalPoint(aLabel),
222  {
223 
224  if (flagU1dir)
225  theDimension.push_back(0);
226  if (flagU2dir)
227  theDimension.push_back(1);
228  // convert from ROOT
229  unsigned int nParSeed = aSeed.GetNrows();
230  externalSeed.resize(nParSeed, nParSeed);
231  for (unsigned int i = 0; i < nParSeed; ++i) {
232  for (unsigned int j = 0; j < nParSeed; ++j) {
233  externalSeed(i, j) = aSeed(i, j);
234  }
235  }
236  // simple (single) trajectory
237  thePoints.emplace_back(std::move(aPointList));
238  numPoints.push_back(numAllPoints);
239  construct(); // construct trajectory
240  }
241 
243 
247  GblTrajectory::GblTrajectory(const std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > &aPointsAndTransList) :
249  numInnerTrans(aPointsAndTransList.size()), numParameters(0), numLocals(0),
254  {
255 
256  for (unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
257  thePoints.emplace_back(std::move(aPointsAndTransList[iTraj].first));
258  numPoints.push_back(thePoints.back().size());
259  numAllPoints += numPoints.back();
260  // convert from ROOT
261  unsigned int nRowTrans = aPointsAndTransList[iTraj].second.GetNrows();
262  unsigned int nColTrans = aPointsAndTransList[iTraj].second.GetNcols();
263  MatrixXd aTrans(nRowTrans, nColTrans);
264  for (unsigned int i = 0; i < nRowTrans; ++i) {
265  for (unsigned int j = 0; j < nColTrans; ++j) {
266  aTrans(i, j) = aPointsAndTransList[iTraj].second(i, j);
267  }
268  }
269  innerTransformations.emplace_back(std::move(aTrans));
270  }
271  theDimension.push_back(0);
272  theDimension.push_back(1);
274  construct(); // construct (composed) trajectory
275  }
276 
278 
285  GblTrajectory::GblTrajectory(const std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > &aPointsAndTransList,
286  const TMatrixD &extDerivatives,
287  const TVectorD &extMeasurements,
288  const TVectorD &extPrecisions) :
290  numInnerTrans(aPointsAndTransList.size()), numParameters(0), numLocals(0),
295  {
296 
297  // convert from ROOT
298  unsigned int nExtMeas = extDerivatives.GetNrows();
299  unsigned int nExtPar = extDerivatives.GetNcols();
300  externalDerivatives.resize(nExtMeas, nExtPar);
301  externalMeasurements.resize(nExtMeas);
302  externalPrecisions.resize(nExtMeas);
303  for (unsigned int i = 0; i < nExtMeas; ++i) {
304  externalMeasurements(i) = extMeasurements[i];
305  externalPrecisions(i) = extPrecisions[i];
306  for (unsigned int j = 0; j < nExtPar; ++j) {
307  externalDerivatives(i, j) = extDerivatives(i, j);
308  }
309  }
310  for (unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
311  thePoints.emplace_back(std::move(aPointsAndTransList[iTraj].first));
312  numPoints.push_back(thePoints.back().size());
313  numAllPoints += numPoints.back();
314  // convert from ROOT
315  unsigned int nRowTrans = aPointsAndTransList[iTraj].second.GetNrows();
316  unsigned int nColTrans = aPointsAndTransList[iTraj].second.GetNcols();
317  MatrixXd aTrans(nRowTrans, nColTrans);
318  for (unsigned int i = 0; i < nRowTrans; ++i) {
319  for (unsigned int j = 0; j < nColTrans; ++j) {
320  aTrans(i, j) = aPointsAndTransList[iTraj].second(i, j);
321  }
322  }
323  innerTransformations.emplace_back(std::move(aTrans));
324  }
325  theDimension.push_back(0);
326  theDimension.push_back(1);
328  construct(); // construct (composed) trajectory
329  }
330 
332 
339  GblTrajectory::GblTrajectory(const std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > &aPointsAndTransList,
340  const TMatrixD &extDerivatives,
341  const TVectorD &extMeasurements,
342  const TMatrixDSym &extPrecisions) :
344  numInnerTrans(aPointsAndTransList.size()), numParameters(0), numLocals(0),
348  {
349 
350  // diagonalize external measurement
351  TMatrixDSymEigen extEigen(extPrecisions);
352  TMatrixD extTransformation = extEigen.GetEigenVectors();
353  extTransformation.T();
354  TMatrixD aDerivatives = extTransformation * extDerivatives;
355  TVectorD aMeasurements = extTransformation * extMeasurements;
356  TVectorD aPrecisions = extEigen.GetEigenValues();
357  // convert from ROOT
358  unsigned int nExtMeas = aDerivatives.GetNrows();
359  unsigned int nExtPar = aDerivatives.GetNcols();
360  externalDerivatives.resize(nExtMeas, nExtPar);
361  externalMeasurements.resize(nExtMeas);
362  externalPrecisions.resize(nExtMeas);
363  for (unsigned int i = 0; i < nExtMeas; ++i) {
364  externalMeasurements(i) = aMeasurements[i];
365  externalPrecisions(i) = aPrecisions[i];
366  for (unsigned int j = 0; j < nExtPar; ++j) {
367  externalDerivatives(i, j) = aDerivatives(i, j);
368  }
369  }
370  for (unsigned int iTraj = 0; iTraj < aPointsAndTransList.size(); ++iTraj) {
371  thePoints.push_back(aPointsAndTransList[iTraj].first);
372  numPoints.push_back(thePoints.back().size());
373  numAllPoints += numPoints.back();
374  // convert from ROOT
375  unsigned int nRowTrans = aPointsAndTransList[iTraj].second.GetNrows();
376  unsigned int nColTrans = aPointsAndTransList[iTraj].second.GetNcols();
377  MatrixXd aTrans(nRowTrans, nColTrans);
378  for (unsigned int i = 0; i < nRowTrans; ++i) {
379  for (unsigned int j = 0; j < nColTrans; ++j) {
380  aTrans(i, j) = aPointsAndTransList[iTraj].second(i, j);
381  }
382  }
383  innerTransformations.push_back(aTrans);
384  }
385  theDimension.push_back(0);
386  theDimension.push_back(1);
388  construct(); // construct (composed) trajectory
389  }
390 #endif
391 
393  }
394 
396  bool GblTrajectory::isValid() const {
397  return constructOK;
398  }
399 
401  unsigned int GblTrajectory::getNumPoints() const {
402  return numAllPoints;
403  }
404 
406 
410 
411  constructOK = false;
412  fitOK = false;
413  unsigned int aLabel = 0;
414  if (numAllPoints < 2) {
415  std::cout << " GblTrajectory construction failed: too few GblPoints "
416  << std::endl;
417  return;
418  }
419  // loop over trajectories
420  numTrajectories = thePoints.size();
421  //std::cout << " numTrajectories: " << numTrajectories << ", " << innerTransformations.size() << std::endl;
422  for (unsigned int iTraj = 0; iTraj < numTrajectories; ++iTraj) {
423  std::vector<GblPoint>::iterator itPoint;
424  for (itPoint = thePoints[iTraj].begin();
425  itPoint < thePoints[iTraj].end(); ++itPoint) {
426  numLocals = std::max(numLocals, itPoint->getNumLocals());
427  numMeasurements += itPoint->hasMeasurement();
428  itPoint->setLabel(++aLabel);
429  }
430  }
431  defineOffsets();
432  calcJacobians();
433  try {
434  prepare();
435  } catch (std::overflow_error &e) {
436  std::cout << " GblTrajectory construction failed: " << e.what()
437  << std::endl;
438  return;
439  }
440 
441  constructOK = true;
442  // number of fit parameters
445  }
446 
448 
453 
454  // loop over trajectories
455  for (unsigned int iTraj = 0; iTraj < numTrajectories; ++iTraj) {
456  // first point is offset
457  thePoints[iTraj].front().setOffset(numOffsets++);
458  // intermediate scatterers are offsets
459  std::vector<GblPoint>::iterator itPoint;
460  for (itPoint = thePoints[iTraj].begin() + 1;
461  itPoint < thePoints[iTraj].end() - 1; ++itPoint) {
462  if (itPoint->hasScatterer()) {
463  itPoint->setOffset(numOffsets++);
464  } else {
465  itPoint->setOffset(-numOffsets);
466  }
467  }
468  // last point is offset
469  thePoints[iTraj].back().setOffset(numOffsets++);
470  }
471  }
472 
475 
476  Matrix5d scatJacobian;
477  // loop over trajectories
478  for (unsigned int iTraj = 0; iTraj < numTrajectories; ++iTraj) {
479  // forward propagation (all)
480  GblPoint* previousPoint = &thePoints[iTraj].front();
481  unsigned int numStep = 0;
482  std::vector<GblPoint>::iterator itPoint;
483  for (itPoint = thePoints[iTraj].begin() + 1;
484  itPoint < thePoints[iTraj].end(); ++itPoint) {
485  if (numStep == 0) {
486  scatJacobian = itPoint->getP2pJacobian();
487  } else {
488  scatJacobian = itPoint->getP2pJacobian() * scatJacobian;
489  }
490  numStep++;
491  itPoint->addPrevJacobian(scatJacobian); // iPoint -> previous scatterer
492  if (itPoint->getOffset() >= 0) {
493  previousPoint->addNextJacobian(scatJacobian); // lastPoint -> next scatterer
494  numStep = 0;
495  previousPoint = &(*itPoint);
496  }
497  }
498  // backward propagation (without scatterers)
499  for (itPoint = thePoints[iTraj].end() - 1;
500  itPoint > thePoints[iTraj].begin(); --itPoint) {
501  if (itPoint->getOffset() >= 0) {
502  scatJacobian = itPoint->getP2pJacobian();
503  continue; // skip offsets
504  }
505  itPoint->addNextJacobian(scatJacobian); // iPoint -> next scatterer
506  scatJacobian = scatJacobian * itPoint->getP2pJacobian();
507  }
508  }
509  }
510 
512 
520  std::pair<std::vector<unsigned int>, MatrixXd> GblTrajectory::getJacobian(
521  int aSignedLabel) const {
522 
523  unsigned int nDim = theDimension.size();
524  unsigned int nCurv = numCurvature;
525  unsigned int nLocals = numLocals;
526  unsigned int nBorder = nCurv + nLocals;
527  unsigned int nParBRL = nBorder + 2 * nDim;
528  unsigned int nParLoc = nLocals + 5;
529  std::vector<unsigned int> anIndex;
530  anIndex.reserve(nParBRL);
531  MatrixXd aJacobian(nParLoc, nParBRL);
532  aJacobian.setZero();
533 
534  unsigned int aLabel = abs(aSignedLabel);
535  unsigned int firstLabel = 1;
536  unsigned int lastLabel = 0;
537  unsigned int aTrajectory = 0;
538  // loop over trajectories
539  for (unsigned int iTraj = 0; iTraj < numTrajectories; ++iTraj) {
540  aTrajectory = iTraj;
541  lastLabel += numPoints[iTraj];
542  if (aLabel <= lastLabel)
543  break;
544  if (iTraj < numTrajectories - 1)
545  firstLabel += numPoints[iTraj];
546  }
547  int nJacobian; // 0: prev, 1: next
548  // check consistency of (index, direction)
549  if (aSignedLabel > 0) {
550  nJacobian = 1;
551  if (aLabel >= lastLabel) {
552  aLabel = lastLabel;
553  nJacobian = 0;
554  }
555  } else {
556  nJacobian = 0;
557  if (aLabel <= firstLabel) {
558  aLabel = firstLabel;
559  nJacobian = 1;
560  }
561  }
562  const GblPoint aPoint = thePoints[aTrajectory][aLabel - firstLabel];
563  std::array<unsigned int, 5> labDer;
564  Matrix5d matDer;
565  getFitToLocalJacobian(labDer, matDer, aPoint, 5, nJacobian);
566 
567  // from local parameters
568  for (unsigned int i = 0; i < nLocals; ++i) {
569  aJacobian(i + 5, i) = 1.0;
570  anIndex.push_back(i + 1);
571  }
572  // from trajectory parameters
573  unsigned int iCol = nLocals;
574  for (unsigned int i = 0; i < 5; ++i) {
575  if (labDer[i] > 0) {
576  anIndex.push_back(labDer[i]);
577  for (unsigned int j = 0; j < 5; ++j) {
578  aJacobian(j, iCol) = matDer(j, i);
579  }
580  ++iCol;
581  }
582  }
583  return std::make_pair(anIndex, aJacobian);
584  }
585 
587 
596  void GblTrajectory::getFitToLocalJacobian(std::array<unsigned int, 5>& anIndex,
597  Matrix5d &aJacobian, const GblPoint &aPoint, unsigned int measDim,
598  unsigned int nJacobian) const {
599 
600  unsigned int nDim = theDimension.size();
601  unsigned int nCurv = numCurvature;
602  unsigned int nLocals = numLocals;
603 
604  int nOffset = aPoint.getOffset();
605 
606  anIndex = {};
607  aJacobian.setZero();
608  if (nOffset < 0) // need interpolation
609  {
610  Matrix2d prevW, prevWJ, nextW, nextWJ, matN;
611  Vector2d prevWd, nextWd;
612  aPoint.getDerivatives(0, prevW, prevWJ, prevWd); // W-, W- * J-, W- * d-
613  aPoint.getDerivatives(1, nextW, nextWJ, nextWd); // W+, W+ * J+, W+ * d+
614  const Matrix2d sumWJ(prevWJ + nextWJ);
615  matN = sumWJ.inverse(); // N = (W- * J- + W+ * J+)^-1
616  // derivatives for u_int
617  const Matrix2d prevNW(matN * prevW); // N * W-
618  const Matrix2d nextNW(matN * nextW); // N * W+
619  const Vector2d prevNd(matN * prevWd); // N * W- * d-
620  const Vector2d nextNd(matN * nextWd); // N * W+ * d+
621 
622  unsigned int iOff = nDim * (-nOffset - 1) + nLocals + nCurv + 1; // first offset ('i' in u_i)
623 
624  // local offset
625  if (nCurv > 0) {
626  aJacobian.block<2, 1>(3, 0) = -prevNd - nextNd; // from curvature
627  anIndex[0] = nLocals + 1;
628  }
629  aJacobian.block<2, 2>(3, 1) = prevNW; // from 1st Offset
630  aJacobian.block<2, 2>(3, 3) = nextNW; // from 2nd Offset
631  for (unsigned int i = 0; i < nDim; ++i) {
632  anIndex[1 + theDimension[i]] = iOff + i;
633  anIndex[3 + theDimension[i]] = iOff + nDim + i;
634  }
635 
636  // local slope and curvature
637  if (measDim > 2) {
638  // derivatives for u'_int
639  const Matrix2d prevWPN(nextWJ * prevNW); // W+ * J+ * N * W-
640  const Matrix2d nextWPN(prevWJ * nextNW); // W- * J- * N * W+
641  const Vector2d prevWNd(nextWJ * prevNd); // W+ * J+ * N * W- * d-
642  const Vector2d nextWNd(prevWJ * nextNd); // W- * J- * N * W+ * d+
643  if (nCurv > 0) {
644  aJacobian(0, 0) = 1.0;
645  aJacobian.block<2, 1>(1, 0) = prevWNd - nextWNd; // from curvature
646  }
647  aJacobian.block<2, 2>(1, 1) = -prevWPN; // from 1st Offset
648  aJacobian.block<2, 2>(1, 3) = nextWPN; // from 2nd Offset
649  }
650  } else { // at point
651  // anIndex must be sorted
652  // forward : iOff2 = iOff1 + nDim, index1 = 1, index2 = 3
653  // backward: iOff2 = iOff1 - nDim, index1 = 3, index2 = 1
654  unsigned int iOff1 = nDim * nOffset + nCurv + nLocals + 1; // first offset ('i' in u_i)
655  unsigned int index1 = 3 - 2 * nJacobian; // index of first offset
656  unsigned int iOff2 = iOff1 + nDim * (nJacobian * 2 - 1); // second offset ('i' in u_i)
657  unsigned int index2 = 1 + 2 * nJacobian; // index of second offset
658  // local offset
659  aJacobian(3, index1) = 1.0; // from 1st Offset
660  aJacobian(4, index1 + 1) = 1.0;
661  for (unsigned int i = 0; i < nDim; ++i) {
662  anIndex[index1 + theDimension[i]] = iOff1 + i;
663  }
664 
665  // local slope and curvature
666  if (measDim > 2) {
667  Matrix2d matW, matWJ;
668  Vector2d vecWd;
669  aPoint.getDerivatives(nJacobian, matW, matWJ, vecWd); // W, W * J, W * d
670  double sign = (nJacobian > 0) ? 1. : -1.;
671  if (nCurv > 0) {
672  aJacobian(0, 0) = 1.0;
673  aJacobian.block<2, 1>(1, 0) = -sign * vecWd; // from curvature
674  anIndex[0] = nLocals + 1;
675  }
676  aJacobian.block<2, 2>(1, index1) = -sign * matWJ; // from 1st Offset
677  aJacobian.block<2, 2>(1, index2) = sign * matW; // from 2nd Offset
678  for (unsigned int i = 0; i < nDim; ++i) {
679  anIndex[index2 + theDimension[i]] = iOff2 + i;
680  }
681  }
682  }
683  }
684 
686 
692  void GblTrajectory::getFitToKinkJacobian(std::array<unsigned int, 7>& anIndex,
693  Matrix27d &aJacobian, const GblPoint &aPoint) const {
694 
695  unsigned int nDim = theDimension.size();
696  unsigned int nCurv = numCurvature;
697  unsigned int nLocals = numLocals;
698 
699  int nOffset = aPoint.getOffset();
700 
701  anIndex = {};
702  aJacobian.setZero();
703 
704  Matrix2d prevW, prevWJ, nextW, nextWJ;
705  Vector2d prevWd, nextWd;
706  aPoint.getDerivatives(0, prevW, prevWJ, prevWd); // W-, W- * J-, W- * d-
707  aPoint.getDerivatives(1, nextW, nextWJ, nextWd); // W-, W- * J-, W- * d-
708  const Matrix2d sumWJ(prevWJ + nextWJ); // W- * J- + W+ * J+
709  const Vector2d sumWd(prevWd + nextWd); // W+ * d+ + W- * d-
710 
711  unsigned int iOff = (nOffset - 1) * nDim + nCurv + nLocals + 1; // first offset ('i' in u_i)
712 
713  // local offset
714  if (nCurv > 0) {
715  aJacobian.block<2, 1>(0, 0) = -sumWd; // from curvature
716  anIndex[0] = nLocals + 1;
717  }
718  aJacobian.block<2, 2>(0, 1) = prevW; // from 1st Offset
719  aJacobian.block<2, 2>(0, 3) = -sumWJ; // from 2nd Offset
720  aJacobian.block<2, 2>(0, 5) = nextW; // from 1st Offset
721  for (unsigned int i = 0; i < nDim; ++i) {
722  anIndex[1 + theDimension[i]] = iOff + i;
723  anIndex[3 + theDimension[i]] = iOff + nDim + i;
724  anIndex[5 + theDimension[i]] = iOff + nDim * 2 + i;
725  }
726  }
727 
729 
743  unsigned int GblTrajectory::getResults(int aSignedLabel, VectorXd &localPar,
744  MatrixXd &localCov) const {
745  if (not fitOK)
746  return 1;
747  std::pair<std::vector<unsigned int>, MatrixXd> indexAndJacobian =
748  getJacobian(aSignedLabel);
749  unsigned int nParBrl = indexAndJacobian.first.size();
750  VectorXd aVec(nParBrl); // compressed vector
751  for (unsigned int i = 0; i < nParBrl; ++i) {
752  aVec[i] = theVector(indexAndJacobian.first[i] - 1);
753  }
754  MatrixXd aMat = theMatrix.getBlockMatrix(indexAndJacobian.first); // compressed matrix
755  localPar = indexAndJacobian.second * aVec;
756  localCov = indexAndJacobian.second * aMat
757  * indexAndJacobian.second.adjoint();
758  return 0;
759  }
760 
762 
774  unsigned int GblTrajectory::getMeasResults(unsigned int aLabel,
775  unsigned int &numData, VectorXd &aResiduals, VectorXd &aMeasErrors,
776  VectorXd &aResErrors, VectorXd &aDownWeights) {
777  numData = 0;
778  if (not fitOK)
779  return 1;
780 
781  unsigned int firstData = measDataIndex[aLabel - 1]; // first data block with measurement
782  numData = measDataIndex[aLabel] - firstData; // number of data blocks
783  for (unsigned int i = 0; i < numData; ++i) {
784  getResAndErr(firstData + i, (aLabel != skippedMeasLabel), aResiduals(i),
785  aMeasErrors(i), aResErrors(i), aDownWeights(i));
786  }
787  return 0;
788  }
789 
791 
803  unsigned int GblTrajectory::getScatResults(unsigned int aLabel,
804  unsigned int &numData, VectorXd &aResiduals, VectorXd &aMeasErrors,
805  VectorXd &aResErrors, VectorXd &aDownWeights) {
806  numData = 0;
807  if (not fitOK)
808  return 1;
809 
810  unsigned int firstData = scatDataIndex[aLabel - 1]; // first data block with scatterer
811  numData = scatDataIndex[aLabel] - firstData; // number of data blocks
812  for (unsigned int i = 0; i < numData; ++i) {
813  getResAndErr(firstData + i, true, aResiduals(i), aMeasErrors(i),
814  aResErrors(i), aDownWeights(i));
815  }
816  return 0;
817  }
818 
819 #ifdef GBL_EIGEN_SUPPORT_ROOT
820 
835  unsigned int GblTrajectory::getResults(int aSignedLabel, TVectorD &localPar,
836  TMatrixDSym &localCov) const {
837  if (not fitOK)
838  return 1;
839  std::pair<std::vector<unsigned int>, MatrixXd> indexAndJacobian =
840  getJacobian(aSignedLabel);
841  unsigned int nParBrl = indexAndJacobian.first.size();
842  VectorXd aVec(nParBrl); // compressed vector
843  for (unsigned int i = 0; i < nParBrl; ++i) {
844  aVec[i] = theVector(indexAndJacobian.first[i] - 1);
845  }
846  MatrixXd aMat = theMatrix.getBlockMatrix(indexAndJacobian.first); // compressed matrix
847  VectorXd aLocalPar = indexAndJacobian.second * aVec;
848  MatrixXd aLocalCov = indexAndJacobian.second * aMat
849  * indexAndJacobian.second.adjoint();
850  // convert to ROOT
851  unsigned int nParOut = localPar.GetNrows();
852  for (unsigned int i = 0; i < nParOut; ++i) {
853  localPar[i] = aLocalPar(i);
854  for (unsigned int j = 0; j < nParOut; ++j) {
855  localCov(i, j) = aLocalCov(i, j);
856  }
857  }
858  return 0;
859  }
860 
862 
874  unsigned int GblTrajectory::getMeasResults(unsigned int aLabel,
875  unsigned int &numData, TVectorD &aResiduals, TVectorD &aMeasErrors,
876  TVectorD &aResErrors, TVectorD &aDownWeights) {
877  numData = 0;
878  if (not fitOK)
879  return 1;
880 
881  unsigned int firstData = measDataIndex[aLabel - 1]; // first data block with measurement
882  numData = measDataIndex[aLabel] - firstData; // number of data blocks
883  for (unsigned int i = 0; i < numData; ++i) {
884  getResAndErr(firstData + i, (aLabel != skippedMeasLabel), aResiduals[i],
885  aMeasErrors[i], aResErrors[i], aDownWeights[i]);
886  }
887  return 0;
888  }
889 
891 
903  unsigned int GblTrajectory::getScatResults(unsigned int aLabel,
904  unsigned int &numData, TVectorD &aResiduals, TVectorD &aMeasErrors,
905  TVectorD &aResErrors, TVectorD &aDownWeights) {
906  numData = 0;
907  if (not fitOK)
908  return 1;
909 
910  unsigned int firstData = scatDataIndex[aLabel - 1]; // first data block with scatterer
911  numData = scatDataIndex[aLabel] - firstData; // number of data blocks
912  for (unsigned int i = 0; i < numData; ++i) {
913  getResAndErr(firstData + i, true, aResiduals[i], aMeasErrors[i],
914  aResErrors[i], aDownWeights[i]);
915  }
916  return 0;
917  }
918 
919 #endif
920 
922 
926  unsigned int GblTrajectory::getLabels(std::vector<unsigned int> &aLabelList) {
927  if (not constructOK)
928  return 1;
929 
930  unsigned int aLabel = 0;
931  unsigned int nPoint = thePoints[0].size();
932  aLabelList.resize(nPoint);
933  for (unsigned i = 0; i < nPoint; ++i) {
934  aLabelList[i] = ++aLabel;
935  }
936  return 0;
937  }
938 
940 
945  std::vector<std::vector<unsigned int> > &aLabelList) {
946  if (not constructOK)
947  return 1;
948 
949  unsigned int aLabel = 0;
950  aLabelList.resize(numTrajectories);
951  for (unsigned int iTraj = 0; iTraj < numTrajectories; ++iTraj) {
952  unsigned int nPoint = thePoints[iTraj].size();
953  aLabelList[iTraj].resize(nPoint);
954  for (unsigned i = 0; i < nPoint; ++i) {
955  aLabelList[iTraj][i] = ++aLabel;
956  }
957  }
958  return 0;
959  }
960 
962 
972  void GblTrajectory::getResAndErr(unsigned int aData, bool used,
973  double &aResidual, double &aMeasError, double &aResError,
974  double &aDownWeight) {
975 
976  double aMeasVar;
977  unsigned int numLocal;
978  unsigned int* indLocal;
979  double* derLocal;
980  theData[aData].getResidual(aResidual, aMeasVar, aDownWeight, numLocal,
981  indLocal, derLocal);
982  VectorXd aVec(numLocal); // compressed vector of derivatives
983  for (unsigned int j = 0; j < numLocal; ++j) {
984  aVec[j] = derLocal[j];
985  }
986  MatrixXd aMat = theMatrix.getBlockMatrix(numLocal, indLocal); // compressed (covariance) matrix
987  double aFitVar = aVec.transpose() * aMat * aVec; // variance from track fit
988  aMeasError = sqrt(aMeasVar); // error of measurement
989  if (used)
990  aResError = (aFitVar < aMeasVar ? sqrt(aMeasVar - aFitVar) : 0.); // error of (biased) residual
991  else
992  aResError = sqrt(aMeasVar + aFitVar); // error of (unbiased) residual
993  }
994 
997  unsigned int nBorder = numCurvature + numLocals;
999  theMatrix.resize(numParameters, nBorder);
1000  double aValue, aWeight;
1001  unsigned int* indLocal;
1002  double* derLocal;
1003  unsigned int numLocal;
1004 
1005  std::vector<GblData>::iterator itData;
1006  for (itData = theData.begin(); itData < theData.end(); ++itData) {
1007  // skipped (internal) measurement ?
1008  if (itData->getLabel() == skippedMeasLabel
1009  && itData->getType() == InternalMeasurement)
1010  continue;
1011  itData->getLocalData(aValue, aWeight, numLocal, indLocal, derLocal);
1012  for (unsigned int j = 0; j < numLocal; ++j) {
1013  theVector(indLocal[j] - 1) += derLocal[j] * aWeight * aValue;
1014  }
1015  theMatrix.addBlockMatrix(aWeight, numLocal, indLocal, derLocal);
1016  }
1017  }
1018 
1020 
1024  unsigned int nDim = theDimension.size();
1025  // upper limit
1026  unsigned int maxData = numMeasurements + nDim * (numOffsets - 2)
1027  + externalSeed.rows();
1028  theData.reserve(maxData);
1029  measDataIndex.resize(numAllPoints + 3); // include external seed and measurements
1030  scatDataIndex.resize(numAllPoints + 1);
1031  unsigned int nData = 0;
1032  std::vector<MatrixXd> innerTransDer;
1033  std::vector<std::array<unsigned int, 5> > innerTransLab;
1034  // composed trajectory ?
1035  if (numInnerTrans > 0) {
1036  //std::cout << "composed trajectory" << std::endl;
1037  for (unsigned int iTraj = 0; iTraj < numTrajectories; ++iTraj) {
1038  // innermost point
1039  GblPoint* innerPoint = &thePoints[iTraj].front();
1040  // transformation fit to local track parameters
1041  std::array<unsigned int, 5> firstLabels;
1042  Matrix5d matFitToLocal, matLocalToFit;
1043  getFitToLocalJacobian(firstLabels, matFitToLocal, *innerPoint, 5);
1044  // transformation local track to fit parameters
1045  matLocalToFit = matFitToLocal.inverse();
1046  // transformation external to fit parameters at inner (first) point
1047  innerTransDer.emplace_back(matLocalToFit * innerTransformations[iTraj]);
1048  innerTransLab.push_back(firstLabels);
1049  }
1050  }
1051  Matrix5d matP; // measurements
1052  std::vector<GblPoint>::iterator itPoint;
1053  // limit the scope of proDer:
1054  {
1055  // transform for external parameters
1056  Eigen::Matrix<double, Eigen::Dynamic, 5,
1057  Eigen::ColMajor /* default */, 5, 5> proDer;
1058  // loop over trajectories
1059  for (unsigned int iTraj = 0; iTraj < numTrajectories; ++iTraj) {
1060  for (itPoint = thePoints[iTraj].begin();
1061  itPoint < thePoints[iTraj].end(); ++itPoint) {
1062  Vector5d aMeas, aPrec;
1063  unsigned int nLabel = itPoint->getLabel();
1064  unsigned int measDim = itPoint->hasMeasurement();
1065  if (measDim) {
1066  const MatrixXd localDer = itPoint->getLocalDerivatives();
1068  itPoint->getNumGlobals());
1069  MatrixXd transDer;
1070  itPoint->getMeasurement(matP, aMeas, aPrec);
1071  double minPrecision = itPoint->getMeasPrecMin();
1072  unsigned int iOff = 5 - measDim; // first active component
1073  std::array<unsigned int, 5> labDer;
1074  Matrix5d matDer, matPDer;
1075  unsigned int nJacobian =
1076  (itPoint < thePoints[iTraj].end() - 1) ? 1 : 0; // last point needs backward propagation
1077  getFitToLocalJacobian(labDer, matDer, *itPoint, measDim,
1078  nJacobian);
1079  if (measDim > 2) {
1080  matPDer = matP * matDer;
1081  } else { // 'shortcut' for position measurements
1082  matPDer.setZero();
1083  matPDer.block<2, 5>(3, 0) = matP.block<2, 2>(3, 3)
1084  * matDer.block<2, 5>(3, 0);
1085  }
1086 
1087  if (numInnerTrans > 0) {
1088  // transform for external parameters
1089  proDer.resize(measDim, Eigen::NoChange);
1090  proDer.setZero();
1091  // match parameters
1092  unsigned int ifirst = 0;
1093  unsigned int ilabel = 0;
1094  while (ilabel < 5) {
1095  if (labDer[ilabel] > 0) {
1096  while (innerTransLab[iTraj][ifirst]
1097  != labDer[ilabel] and ifirst < 5) {
1098  ++ifirst;
1099  }
1100  if (ifirst >= 5) {
1101  labDer[ilabel] -= 2 * nDim * (iTraj + 1); // adjust label
1102  } else {
1103  // match
1104  labDer[ilabel] = 0; // mark as related to external parameters
1105  for (unsigned int k = iOff; k < 5; ++k) {
1106  proDer(k - iOff, ifirst) = matPDer(k,
1107  ilabel);
1108  }
1109  }
1110  }
1111  ++ilabel;
1112  }
1113  transDer.resize(measDim, numCurvature);
1114  transDer = proDer * innerTransDer[iTraj];
1115  }
1116  for (unsigned int i = iOff; i < 5; ++i) {
1117  if (aPrec(i) > minPrecision) {
1118  GblData aData(nLabel, InternalMeasurement, aMeas(i),
1119  aPrec(i), iTraj,
1120  itPoint - thePoints[iTraj].begin());
1121  aData.addDerivatives(i, labDer, matPDer, iOff, localDer,
1122  numLocals, transDer);
1123  theData.emplace_back(aData);
1124  nData++;
1125  }
1126  }
1127 
1128  }
1129  measDataIndex[nLabel] = nData;
1130  }
1131  }
1132  } // end of scope for proDer
1133 
1134  Matrix2d matT; // measurements
1135  // limit the scope of proDer:
1136  {
1137  // transform for external parameters
1138  Eigen::Matrix<double, Eigen::Dynamic, 5,
1139  Eigen::ColMajor /* default */, 5, 5> proDer;
1140  scatDataIndex[0] = nData;
1141  scatDataIndex[1] = nData;
1142  // loop over trajectories
1143  for (unsigned int iTraj = 0; iTraj < numTrajectories; ++iTraj) {
1144  for (itPoint = thePoints[iTraj].begin() + 1;
1145  itPoint < thePoints[iTraj].end() - 1; ++itPoint) {
1146  Vector2d aMeas, aPrec;
1147  unsigned int nLabel = itPoint->getLabel();
1148  if (itPoint->hasScatterer()) {
1149  itPoint->getScatterer(matT, aMeas, aPrec);
1150  MatrixXd transDer;
1151  std::array<unsigned int, 7> labDer;
1152  Matrix27d matDer, matTDer;
1153  getFitToKinkJacobian(labDer, matDer, *itPoint);
1154  matTDer = matT * matDer;
1155  if (numInnerTrans > 0) {
1156  // transform for external parameters
1157  proDer.resize(nDim, Eigen::NoChange);
1158  proDer.setZero();
1159  // match parameters
1160  unsigned int ifirst = 0;
1161  unsigned int ilabel = 0;
1162  while (ilabel < 7) {
1163  if (labDer[ilabel] > 0) {
1164  while (innerTransLab[iTraj][ifirst]
1165  != labDer[ilabel] and ifirst < 5) {
1166  ++ifirst;
1167  }
1168  if (ifirst >= 5) {
1169  labDer[ilabel] -= 2 * nDim * (iTraj + 1); // adjust label
1170  } else {
1171  // match
1172  labDer[ilabel] = 0; // mark as related to external parameters
1173  for (unsigned int k = 0; k < nDim; ++k) {
1174  proDer(k, ifirst) = matTDer(k, ilabel);
1175  }
1176  }
1177  }
1178  ++ilabel;
1179  }
1180  transDer.resize(nDim, numCurvature);
1181  transDer = proDer * innerTransDer[iTraj];
1182  }
1183  for (unsigned int i = 0; i < nDim; ++i) {
1184  unsigned int iDim = theDimension[i];
1185  if (aPrec(iDim) > 0.) {
1186  GblData aData(nLabel, InternalKink, aMeas(iDim),
1187  aPrec(iDim), iTraj,
1188  itPoint - thePoints[iTraj].begin());
1189  aData.addDerivatives(iDim, labDer, matTDer, numLocals,
1190  transDer);
1191  theData.emplace_back(aData);
1192  nData++;
1193  }
1194  }
1195  }
1196  scatDataIndex[nLabel] = nData;
1197  }
1198  scatDataIndex[thePoints[iTraj].back().getLabel()] = nData;
1199  }
1200  }
1201 
1202  // external seed
1203  if (externalPoint > 0) {
1204  std::pair<std::vector<unsigned int>, MatrixXd> indexAndJacobian =
1206  std::vector<unsigned int> externalSeedIndex = indexAndJacobian.first;
1207  std::vector<double> externalSeedDerivatives(externalSeedIndex.size());
1208  SelfAdjointEigenSolver<MatrixXd> externalSeedEigen(externalSeed);
1209  VectorXd valEigen = externalSeedEigen.eigenvalues();
1210  MatrixXd vecEigen = externalSeedEigen.eigenvectors();
1211  vecEigen = vecEigen.transpose() * indexAndJacobian.second;
1212  for (int i = 0; i < externalSeed.rows(); ++i) {
1213  if (valEigen(i) > 0.) {
1214  for (int j = 0; j < externalSeed.cols(); ++j) {
1215  externalSeedDerivatives[j] = vecEigen(i, j);
1216  }
1217  GblData aData(externalPoint, ExternalSeed, 0., valEigen(i));
1218  aData.addDerivatives(externalSeedIndex,
1219  externalSeedDerivatives);
1220  theData.emplace_back(std::move(aData));
1221  nData++;
1222  }
1223  }
1224  }
1225  measDataIndex[numAllPoints + 1] = nData;
1226  // external measurements
1227  unsigned int nExt = externalMeasurements.rows();
1228  if (nExt > 0) {
1229  std::vector<unsigned int> index(numCurvature);
1230  std::vector<double> derivatives(numCurvature);
1231  for (unsigned int iExt = 0; iExt < nExt; ++iExt) {
1232  for (unsigned int iCol = 0; iCol < numCurvature; ++iCol) {
1233  index[iCol] = iCol + 1;
1234  derivatives[iCol] = externalDerivatives(iExt, iCol);
1235  }
1237  externalPrecisions(iExt));
1238  aData.addDerivatives(index, derivatives);
1239  theData.emplace_back(std::move(aData));
1240  nData++;
1241  }
1242  }
1243  measDataIndex[numAllPoints + 2] = nData;
1244  }
1245 
1248  std::vector<GblData>::iterator itData;
1249  for (itData = theData.begin(); itData < theData.end(); ++itData) {
1250  itData->setPrediction(theVector);
1251  }
1252  }
1253 
1255 
1258  double GblTrajectory::downWeight(unsigned int aMethod) {
1259  double aLoss = 0.;
1260  std::vector<GblData>::iterator itData;
1261  for (itData = theData.begin(); itData < theData.end(); ++itData) {
1262  aLoss += (1. - itData->setDownWeighting(aMethod));
1263  }
1264  return aLoss;
1265  }
1266 
1268 
1280  unsigned int GblTrajectory::fit(double &Chi2, int &Ndf, double &lostWeight,
1281  const std::string& optionList, unsigned int aLabel) {
1282  const double normChi2[4] = { 1.0, 0.8737, 0.9326, 0.8228 };
1283  const std::string methodList = "TtHhCc";
1284 
1285  Chi2 = 0.;
1286  Ndf = -1;
1287  lostWeight = 0.;
1288  if (not constructOK)
1289  return 10;
1290 
1291  unsigned int aMethod = 0;
1292  skippedMeasLabel = aLabel;
1293 
1295  lostWeight = 0.;
1296  unsigned int ierr = 0;
1297  try {
1298 
1300  predict();
1301 
1302  for (unsigned int i = 0; i < optionList.size(); ++i) // down weighting iterations
1303  {
1304  size_t aPosition = methodList.find(optionList[i]);
1305  if (aPosition != std::string::npos) {
1306  aMethod = aPosition / 2 + 1;
1307  lostWeight = downWeight(aMethod);
1310  predict();
1311  }
1312  }
1313  Ndf = -numParameters;
1314  Chi2 = 0.;
1315  for (unsigned int i = 0; i < theData.size(); ++i) {
1316  // skipped (internal) measurement ?
1317  if (theData[i].getLabel() == skippedMeasLabel
1318  && theData[i].getType() == InternalMeasurement)
1319  continue;
1320  Chi2 += theData[i].getChi2();
1321  Ndf++;
1322  }
1323  Chi2 /= normChi2[aMethod];
1324  fitOK = true;
1325 
1326  } catch (int e) {
1327  std::cout << " GblTrajectory::fit exception " << e << std::endl;
1328  ierr = e;
1329  }
1330  return ierr;
1331  }
1332 
1335  double aValue;
1336  double aErr;
1337  unsigned int aTraj;
1338  unsigned int aPoint;
1339  unsigned int aRow;
1340  unsigned int numLocal;
1341  unsigned int* labLocal;
1342  double* derLocal;
1343  std::vector<int> labGlobal;
1344  std::vector<double> derGlobal;
1345 
1346  if (not constructOK)
1347  return;
1348 
1349  // data: measurements, kinks and external seed
1350  labGlobal.reserve(maxNumGlobals);
1351  derGlobal.reserve(maxNumGlobals);
1352  std::vector<GblData>::iterator itData;
1353  for (itData = theData.begin(); itData != theData.end(); ++itData) {
1354  itData->getAllData(aValue, aErr, numLocal, labLocal, derLocal, aTraj,
1355  aPoint, aRow);
1356  if (itData->getType() == InternalMeasurement)
1357  thePoints[aTraj][aPoint].getGlobalLabelsAndDerivatives(aRow,
1358  labGlobal, derGlobal);
1359  else
1360  labGlobal.resize(0);
1361  aMille.addData(aValue, aErr, numLocal, labLocal, derLocal, labGlobal,
1362  derGlobal);
1363  }
1364  aMille.writeRecord();
1365  }
1366 
1368 
1372  if (numInnerTrans) {
1373  std::cout << "Composed GblTrajectory, " << numInnerTrans
1374  << " subtrajectories" << std::endl;
1375  } else {
1376  std::cout << "Simple GblTrajectory" << std::endl;
1377  }
1378  if (theDimension.size() < 2) {
1379  std::cout << " 2D-trajectory" << std::endl;
1380  }
1381  std::cout << " Number of GblPoints : " << numAllPoints
1382  << std::endl;
1383  std::cout << " Number of points with offsets: " << numOffsets << std::endl;
1384  std::cout << " Number of fit parameters : " << numParameters
1385  << std::endl;
1386  std::cout << " Number of measurements : " << numMeasurements
1387  << std::endl;
1388  if (externalMeasurements.rows()) {
1389  std::cout << " Number of ext. measurements : "
1390  << externalMeasurements.rows() << std::endl;
1391  }
1392  if (externalPoint) {
1393  std::cout << " Label of point with ext. seed: " << externalPoint
1394  << std::endl;
1395  }
1396  if (constructOK) {
1397  std::cout << " Constructed OK " << std::endl;
1398  }
1399  if (fitOK) {
1400  std::cout << " Fitted OK " << std::endl;
1401  }
1402  if (level > 0) {
1403  IOFormat CleanFmt(4, 0, ", ", "\n", "[", "]");
1404  if (numInnerTrans) {
1405  std::cout << " Inner transformations" << std::endl;
1406  for (unsigned int i = 0; i < numInnerTrans; ++i) {
1407  std::cout << innerTransformations[i].format(CleanFmt)
1408  << std::endl;
1409  }
1410  }
1411  if (externalMeasurements.rows()) {
1412  std::cout << " External measurements" << std::endl;
1413  std::cout << " Measurements:" << std::endl;
1414  std::cout << externalMeasurements.format(CleanFmt) << std::endl;
1415  std::cout << " Precisions:" << std::endl;
1416  std::cout << externalPrecisions.format(CleanFmt) << std::endl;
1417  std::cout << " Derivatives:" << std::endl;
1418  std::cout << externalDerivatives.format(CleanFmt) << std::endl;
1419  }
1420  if (externalPoint) {
1421  std::cout << " External seed:" << std::endl;
1422  std::cout << externalSeed.format(CleanFmt) << std::endl;
1423  }
1424  if (fitOK) {
1425  std::cout << " Fit results" << std::endl;
1426  std::cout << " Parameters:" << std::endl;
1427  theVector.print();
1428  std::cout << " Covariance matrix (bordered band part):"
1429  << std::endl;
1431  }
1432  }
1433  }
1434 
1436 
1439  void GblTrajectory::printPoints(unsigned int level) {
1440  std::cout << "GblPoints " << std::endl;
1441  for (unsigned int iTraj = 0; iTraj < numTrajectories; ++iTraj) {
1442  std::vector<GblPoint>::iterator itPoint;
1443  for (itPoint = thePoints[iTraj].begin();
1444  itPoint < thePoints[iTraj].end(); ++itPoint) {
1445  itPoint->printPoint(level);
1446  }
1447  }
1448  }
1449 
1452  std::cout << "GblData blocks " << std::endl;
1453  std::vector<GblData>::iterator itData;
1454  for (itData = theData.begin(); itData < theData.end(); ++itData) {
1455  itData->printData();
1456  }
1457  }
1458 
1459 }
void printMatrix() const
Print bordered band matrix.
size
Write out results.
std::vector< unsigned int > scatDataIndex
mapping points to data blocks from scatterers
void addBlockMatrix(double aWeight, const std::vector< unsigned int > *anIndex, const std::vector< double > *aVector)
Add symmetric block matrix.
void construct()
Construct trajectory from list of points.
void addNextJacobian(const Matrix5d &aJac)
Define jacobian to next scatterer (by GBLTrajectory constructor)
Definition: GblPoint.cc:487
Data (block) for independent scalar measurement.
Definition: GblData.h:55
void buildLinearEquationSystem()
Build linear equation system from data (blocks).
void printTrajectory(unsigned int level=0)
Print GblTrajectory.
unsigned int numParameters
Number of fit parameters.
void writeRecord()
Write record to file.
Definition: MilleBinary.cc:113
bool constructOK
Trajectory has been successfully constructed (ready for fit/output)
std::vector< unsigned int > measDataIndex
mapping points to data blocks from measurements
Eigen::MatrixXd getBlockMatrix(const std::vector< unsigned int > anIndex) const
Retrieve symmetric block matrix.
bool fitOK
Trajectory has been successfully fitted (results are valid)
std::vector< unsigned int > theDimension
List of active dimensions (0=u1, 1=u2) in fit.
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 nLocal, const Eigen::MatrixBase< TrafoDerivative > &derTrans)
Add derivatives from measurement.
Definition: GblData.h:126
unsigned int getLabels(std::vector< unsigned int > &aLabelList)
Get (list of) labels of points on (simple) valid trajectory.
void print() const
Print vector.
Definition: VMatrix.cc:298
void predict()
Calculate predictions for all points.
int getOffset() const
Retrieve offset for point.
Definition: GblPoint.cc:459
unsigned int numOffsets
Number of (points with) offsets on trajectory.
Eigen::VectorXd externalMeasurements
CLHEP::HepMatrix Matrix
Definition: matutil.h:65
bool isValid() const
Retrieve validity of trajectory.
unsigned int getResults(int aSignedLabel, Eigen::VectorXd &localPar, Eigen::MatrixXd &localCov) const
Get fit results at point.
U second(std::pair< T, U > const &p)
unsigned int fit(double &Chi2, int &Ndf, double &lostWeight, const std::string &optionList="", unsigned int aLabel=0)
Perform fit of (valid) trajectory.
unsigned int externalPoint
Label of external point (or 0)
unsigned int numInnerTrans
Number of inner transformations to external parameters.
void calcJacobians()
Calculate Jacobians to previous/next scatterer from point to point ones.
unsigned int numMeasurements
Total number of 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.
T sqrt(T t)
Definition: SSEVec.h:18
void resize(const unsigned int nRows)
Resize vector.
Definition: VMatrix.cc:262
Eigen::MatrixXd externalSeed
Precision (inverse covariance matrix) of external seed.
void defineOffsets()
Define offsets from list of points.
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.
Definition: MilleBinary.cc:72
void prepare()
Prepare fit for simple or composed trajectory.
unsigned int getScatResults(unsigned int aLabel, unsigned int &numRes, Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors, Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights)
Get (kink) residuals from fit at point for scatterer.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void printData()
Print GblData blocks for trajectory.
Namespace for the general broken lines package.
double downWeight(unsigned int aMethod)
Down-weight all points.
#define end
Definition: vmac.h:37
std::vector< unsigned int > numPoints
Number of points on (sub)trajectory.
int k[5][pyjets_maxn]
std::pair< std::vector< unsigned int >, Eigen::MatrixXd > getJacobian(int aSignedLabel) const
Get jacobian for transformation from fit to track parameters at point.
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...
void milleOut(MilleBinary &aMille)
Write valid trajectory to Millepede-II binary file.
std::vector< GblData > theData
List of data blocks.
Eigen::Matrix< double, 5, 1 > Vector5d
Definition: GblPoint.h:47
Eigen::Matrix< double, 2, 7 > Matrix27d
Definition: GblData.h:44
unsigned int maxNumGlobals
Max. number of global labels/derivatives per point.
void resize(unsigned int nSize, unsigned int nBorder=1, unsigned int nBand=5)
Resize bordered band matrix.
std::vector< Eigen::MatrixXd > innerTransformations
Transformations at innermost points of.
Eigen::MatrixXd externalDerivatives
void getDerivatives(int aDirection, Eigen::Matrix2d &matW, Eigen::Matrix2d &matWJ, Eigen::Vector2d &vecWd) const
Retrieve derivatives of local track model.
Definition: GblPoint.cc:501
std::vector< std::vector< GblPoint > > thePoints
(list of) List of points on trajectory
BorderedBandMatrix theMatrix
(Bordered band) matrix of linear equation system
VVector theVector
Vector of linear equation system.
unsigned int numTrajectories
Number of trajectories (in composed trajectory)
unsigned int getMeasResults(unsigned int aLabel, unsigned int &numRes, Eigen::VectorXd &aResiduals, Eigen::VectorXd &aMeasErrors, Eigen::VectorXd &aResErrors, Eigen::VectorXd &aDownWeights)
Get residuals from fit at point for measurement.
#define begin
Definition: vmac.h:30
GblTrajectory(const std::vector< GblPoint > &aPointList, bool flagCurv=true, bool flagU1dir=true, bool flagU2dir=true)
Create new (simple) trajectory from list of points.
unsigned int numLocals
Total number of (additional) local parameters.
virtual ~GblTrajectory()
Millepede-II (binary) record.
Definition: MilleBinary.h:68
unsigned int getNumPoints() const
Retrieve number of point from trajectory.
unsigned int numAllPoints
Number of all points on trajectory.
void getResAndErr(unsigned int aData, bool used, double &aResidual, double &aMeadsError, double &aResError, double &aDownWeight)
Get residual and errors from data block.
void printPoints(unsigned int level=0)
Print GblPoints on trajectory.
void solveAndInvertBorderedBand(const VVector &aRightHandSide, VVector &aSolution)
Solve linear equation system, partially calculate inverse.
Definition: Chi2.h:17
unsigned int numCurvature
Number of curvature parameters (0 or 1) or external parameters.
def move(src, dest)
Definition: eostools.py:510
unsigned int skippedMeasLabel
Label of point with measurements skipped in fit (for unbiased residuals) (or 0)
const Matrix5d & getP2pJacobian() const
Retrieve point-to-(previous)point jacobian.
Definition: GblPoint.cc:464
Eigen::VectorXd externalPrecisions
Point on trajectory.
Definition: GblPoint.h:66
Eigen::Matrix< double, 5, 5 > Matrix5d
Definition: GblData.h:43