Belle II Software  release-08-01-10
TimeExtractionUtils Class Reference

Helper class to perform all kind of track extrapolations using the methods from arXiv:0810.2241. More...

#include <TimeExtractionUtils.h>

Static Public Member Functions

static std::pair< double, double > getChi2WithFit (const std::vector< RecoTrack * > &recoTracks, bool setDirtyFlag)
 Fit the tracks and extract the reduced chi2.
 
static std::pair< double, double > getExtractedTimeAndUncertaintyWithFit (const std::vector< RecoTrack * > &recoTracks, bool setDirtyFlag)
 Fit the tracks and extract the chi2 derivatives.
 
static void addEventT0WithQuality (const std::vector< RecoTrack * > &recoTracks, StoreObjPtr< EventT0 > &eventT0, std::vector< EventT0::EventT0Component > &eventT0WithQualityIndex)
 Append an event-t0 value with quality information.
 
static double extractReducedChi2 (const RecoTrack &recoTrack)
 Small helper function to extract the reduced chi^2 (chi^2/ndf). Returns NaN if ndf is 0.
 
static std::pair< double, double > getChi2Derivatives (const RecoTrack &recoTrack)
 Extract the derivatives d chi^2 / d alpha and d^2 chi^2 / (d alpha)^2 from the reco track by calculating the full residual covariance matrix, where alpha is the global event time. More...
 

Static Private Member Functions

static std::vector< int > getMeasurementDimensions (const RecoTrack &recoTrack)
 Get a list of dimensions for each measurement in the reco track. More...
 
static bool buildFullCovarianceMatrix (const RecoTrack &recoTrack, TMatrixDSym &fullCovariance)
 Build the full covariance matrix of the given reco track and fills it into the given TMatrixDSym. More...
 
static bool buildFullResidualCovarianceMatrix (const RecoTrack &recoTrack, const std::vector< int > &vDimMeas, const TMatrixDSym &fullCovariance, TMatrixDSym &fullResidualCovariance, TMatrixDSym &inverseFullMeasurementCovariance)
 Build the full covariance matrix of the residuals of the measurements out of the full covariance matrix of the track states. More...
 
static void buildResidualsAndTimeDerivative (const RecoTrack &recoTrack, const std::vector< int > &vDimMeas, TVectorD &residuals, TVectorD &residualTimeDerivative)
 Calculate the weighted residuals (weighted with the DAF weight) of each hit and the time derivative of the residuals by calling the timeDerivativesMeasurementsOnPlane method of the CDCRecoHits. More...
 

Detailed Description

Helper class to perform all kind of track extrapolations using the methods from arXiv:0810.2241.

The event time is calculated as one would calculate an alignment parameter. We follow the prescription in arXiv:0810.2241 [physics.ins-det] to build the full covariance matrix for the Kalman-fitted track (DAF counts as Kalman). We then evaluate the change in event time that minimizes the sum of chi^2s of the tracks following the same procedure that is decribed in loc.cit.

Unlike the case of alignment, we only have one free parameter (time), and therefore there are no large matrices to invert. The necessary timeshift is calculated from the estimated derivatives of chi2^2 in the linear approximation as dchi^2 /d^2chi^2 delta t = - -----— / -----— . dt / dt^2 Here division replaces a matrix inverse (this is loc.cit. Eq. (8)).

Time-dependence of the fit result comes from the CDC hits, where a later time of particle passage corresponds to a greater drift circle.

Definition at line 48 of file TimeExtractionUtils.h.

Member Function Documentation

◆ buildFullCovarianceMatrix()

bool buildFullCovarianceMatrix ( const RecoTrack recoTrack,
TMatrixDSym &  fullCovariance 
)
staticprivate

Build the full covariance matrix of the given reco track and fills it into the given TMatrixDSym.

Needed for the derivatives.

The full covariance contains the covariances of the different states of the reco track at different hits, this means is connects the calculates state at one measurement to one at another measurement. This is why it has the dimension number of hits * dimensionality of the track state. The diagonal blocks are filled with the covariance matrices at a single measurement whereas the off diagonal elements connect different measurements.

The off-diagnal elements are calculated, by either using one prediction step forward (because the two hits are neighbors), by using the fact that if thei are not neighbors they can be connected by a finite number of forward predictions which breaks this down to the first case and some multiplications again or by using symmetry aspects (e.g. no background prediction is needed).

The notation follows 0810.2241.

Returns false if something strange happened, otherwise true.

Definition at line 272 of file TimeExtractionUtils.cc.

274 {
275  const auto* kfs = dynamic_cast<const genfit::KalmanFitStatus*>(recoTrack.getTrackFitStatus());
276 
277  if (!kfs) {
278  B2ERROR("Track not fitted with a Kalman fitter.");
279  return false;
280  }
281 
282  if (!kfs->isFitConverged()) {
283  B2ERROR("Track fit didn't converge.");
284  return false;
285  }
286 
287  if (!kfs->isFittedWithReferenceTrack()) {
288  B2ERROR("No reference track.");
289  return false;
290  }
291 
292  const auto& hitPoints = recoTrack.getHitPointsWithMeasurement();
293  const unsigned int nPoints = hitPoints.size();
294  const genfit::AbsTrackRep* rep = recoTrack.getCardinalRepresentation();
295  const int nDim = rep->getDim();
296 
297  fullCovariance.ResizeTo(nPoints * nDim, nPoints * nDim);
298  std::vector<TMatrixD> vFitterGain;
299  vFitterGain.reserve(nPoints);
300  for (unsigned int i = 0; i < nPoints; ++i) {
301  const genfit::TrackPoint* tp = hitPoints[i];
303  if (!fi) {
304  B2DEBUG(25, "Missing KalmanFitterInfo - skipping track");
305  return false;
306  }
307 
308  // Diagonal part of the full covariance matrix are the covariances
309  // of the smoothed states.
310  const genfit::MeasuredStateOnPlane& mop = fi->getFittedState();
311  setSubOnDiagonal(fullCovariance, i * nDim, mop.getCov());
312 
313  // Build the corresponding smoother gain matrix.
314  if (i + 1 < nPoints) {
315  const genfit::TrackPoint* tpNext = hitPoints[i + 1];
316  const genfit::KalmanFitterInfo* fiNext = tpNext->getKalmanFitterInfo();
317  if (!fiNext) {
318  B2DEBUG(25, "Missing next KalmanFitterInfo - skipping track");
319  return false;
320  }
321 
322  // update at i
323  const genfit::MeasuredStateOnPlane* update = fi->getForwardUpdate();
324  // transport to i+1 prediction at i+1
325  const genfit::ReferenceStateOnPlane* rsop = fiNext->getReferenceState();
326  if (rsop) {
327  const genfit::MeasuredStateOnPlane* pred = fiNext->getForwardPrediction();
328 
329  // Evaluate (C^i_i+1)^-1 F_i
330  TDecompChol decomp(pred->getCov());
331  TMatrixD F = rsop->getForwardTransportMatrix();
332  decomp.MultiSolve(F);
333 
334  // Calculate gain matrix as
335  // C_i F_i^T (C^i_i+1)^-1 = C_i ((C^i_i+1)^-1 F_i)^T
336  // in the notation of 0810.2241
337  vFitterGain.emplace_back(TMatrixD(update->getCov(),
338  TMatrixD::kMultTranspose, F));
339  } else {
340  B2DEBUG(150, "No reference state, substituting empty fitter gain matrix.");
341  vFitterGain.emplace_back(TMatrixD(5, 5));
342  }
343  }
344 
345  // Build the off-diagonal elements.
346  TMatrixD offDiag = mop.getCov();
347  for (int j = i - 1; j >= 0; --j) {
348  offDiag = TMatrixD(vFitterGain[j], TMatrixD::kMult, offDiag);
349  setSubOffDiagonal(fullCovariance, j * nDim, i * nDim, offDiag);
350  }
351  }
352 
353  return true;
354 }
const genfit::FitStatus * getTrackFitStatus(const genfit::AbsTrackRep *representation=nullptr) const
Return the track fit status for the given representation or for the cardinal one. You are not allowed...
Definition: RecoTrack.h:621
const std::vector< genfit::TrackPoint * > & getHitPointsWithMeasurement() const
Return a list of measurements and track points, which can be used e.g. to extrapolate....
Definition: RecoTrack.h:708
genfit::AbsTrackRep * getCardinalRepresentation() const
Get a pointer to the cardinal track representation. You are not allowed to modify or delete it!
Definition: RecoTrack.h:631
Abstract base class for a track representation.
Definition: AbsTrackRep.h:66
virtual unsigned int getDim() const =0
Get the dimension of the state vector used by the track representation.
FitStatus for use with AbsKalmanFitter implementations.
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
#StateOnPlane with additional covariance matrix.
#StateOnPlane with linearized transport to that #ReferenceStateOnPlane from previous and next #Refere...
Object containing AbsMeasurement and AbsFitterInfo objects.
Definition: TrackPoint.h:46
KalmanFitterInfo * getKalmanFitterInfo(const AbsTrackRep *rep=nullptr) const
Helper to avoid casting.
Definition: TrackPoint.cc:180

◆ buildFullResidualCovarianceMatrix()

bool buildFullResidualCovarianceMatrix ( const RecoTrack recoTrack,
const std::vector< int > &  vDimMeas,
const TMatrixDSym &  fullCovariance,
TMatrixDSym &  fullResidualCovariance,
TMatrixDSym &  inverseFullMeasurementCovariance 
)
staticprivate

Build the full covariance matrix of the residuals of the measurements out of the full covariance matrix of the track states.

The returned matrix has the dimensionality of the number of measurements * their dimensionality and relates the residuals of each measurements to each other residuals of an (other) measurement.

This can easily be done using the full covariance matrix of the states, which is calculated using the buildFullCovarianceMatrix method. The ful covariance matrix of the residuals and their inverse is returned.

The fullResidualCovariance is eq. (17) in 0810.2241.

Definition at line 356 of file TimeExtractionUtils.cc.

◆ buildResidualsAndTimeDerivative()

void buildResidualsAndTimeDerivative ( const RecoTrack recoTrack,
const std::vector< int > &  vDimMeas,
TVectorD &  residuals,
TVectorD &  residualTimeDerivative 
)
staticprivate

Calculate the weighted residuals (weighted with the DAF weight) of each hit and the time derivative of the residuals by calling the timeDerivativesMeasurementsOnPlane method of the CDCRecoHits.

The residuals as well as the residualTimeDerivative are returned by reference to a vector as large as there are measurements in the reco track (exactly: number of measurements * dimensionality of each measurement).

Definition at line 425 of file TimeExtractionUtils.cc.

◆ getChi2Derivatives()

std::pair< double, double > getChi2Derivatives ( const RecoTrack recoTrack)
static

Extract the derivatives d chi^2 / d alpha and d^2 chi^2 / (d alpha)^2 from the reco track by calculating the full residual covariance matrix, where alpha is the global event time.

The two derivatives are returned as a pair.

Definition at line 199 of file TimeExtractionUtils.cc.

◆ getMeasurementDimensions()

std::vector< int > getMeasurementDimensions ( const RecoTrack recoTrack)
staticprivate

Get a list of dimensions for each measurement in the reco track.

Needed for the derivatives. E.g. the residuals vector is as large as the sum of the returned vector here.

Parameters
recoTrackThe reco track from which the measurements should be taken.
Returns
An std::vector with the number of dimensions for each measurement. Has as many entries as there are measurements in the reco track.

Definition at line 257 of file TimeExtractionUtils.cc.


The documentation for this class was generated from the following files: