Belle II Software  release-05-01-25
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 (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 58 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 275 of file TimeExtractionUtils.cc.

277 {
278  const auto* kfs = dynamic_cast<const genfit::KalmanFitStatus*>(recoTrack.getTrackFitStatus());
279 
280  if (!kfs) {
281  B2ERROR("Track not fitted with a Kalman fitter.");
282  return false;
283  }
284 
285  if (!kfs->isFitConverged()) {
286  B2ERROR("Track fit didn't converge.");
287  return false;
288  }
289 
290  if (!kfs->isFittedWithReferenceTrack()) {
291  B2ERROR("No reference track.");
292  return false;
293  }
294 
295  const auto& hitPoints = recoTrack.getHitPointsWithMeasurement();
296  const unsigned int nPoints = hitPoints.size();
297  const genfit::AbsTrackRep* rep = recoTrack.getCardinalRepresentation();
298  const int nDim = rep->getDim();
299 
300  fullCovariance.ResizeTo(nPoints * nDim, nPoints * nDim);
301  std::vector<TMatrixD> vFitterGain;
302  vFitterGain.reserve(nPoints);
303  for (unsigned int i = 0; i < nPoints; ++i) {
304  const genfit::TrackPoint* tp = hitPoints[i];
306  if (!fi) {
307  B2DEBUG(50, "Missing KalmanFitterInfo - skipping track");
308  return false;
309  }
310 
311  // Diagonal part of the full covariance matrix are the covariances
312  // of the smoothed states.
313  const genfit::MeasuredStateOnPlane& mop = fi->getFittedState();
314  setSubOnDiagonal(fullCovariance, i * nDim, mop.getCov());
315 
316  // Build the corresponding smoother gain matrix.
317  if (i + 1 < nPoints) {
318  const genfit::TrackPoint* tpNext = hitPoints[i + 1];
319  const genfit::KalmanFitterInfo* fiNext = tpNext->getKalmanFitterInfo();
320  if (!fiNext) {
321  B2DEBUG(50, "Missing next KalmanFitterInfo - skipping track");
322  return false;
323  }
324 
325  // update at i
326  const genfit::MeasuredStateOnPlane* update = fi->getForwardUpdate();
327  // transport to i+1 prediction at i+1
328  const genfit::ReferenceStateOnPlane* rsop = fiNext->getReferenceState();
329  if (rsop) {
330  const genfit::MeasuredStateOnPlane* pred = fiNext->getForwardPrediction();
331 
332  // Evaluate (C^i_i+1)^-1 F_i
333  TDecompChol decomp(pred->getCov());
334  TMatrixD F = rsop->getForwardTransportMatrix();
335  decomp.MultiSolve(F);
336 
337  // Calculate gain matrix as
338  // C_i F_i^T (C^i_i+1)^-1 = C_i ((C^i_i+1)^-1 F_i)^T
339  // in the notation of 0810.2241
340  vFitterGain.emplace_back(TMatrixD(update->getCov(),
341  TMatrixD::kMultTranspose, F));
342  } else {
343  B2DEBUG(150, "No reference state, substituting empty fitter gain matrix.");
344  vFitterGain.emplace_back(TMatrixD(5, 5));
345  }
346  }
347 
348  // Build the off-diagonal elements.
349  TMatrixD offDiag = mop.getCov();
350  for (int j = i - 1; j >= 0; --j) {
351  offDiag = TMatrixD(vFitterGain[j], TMatrixD::kMult, offDiag);
352  setSubOffDiagonal(fullCovariance, j * nDim, i * nDim, offDiag);
353  }
354  }
355 
356  return true;
357 }

◆ 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 359 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 428 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 201 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 259 of file TimeExtractionUtils.cc.


The documentation for this class was generated from the following files:
genfit::TrackPoint
Object containing AbsMeasurement and AbsFitterInfo objects.
Definition: TrackPoint.h:46
Belle2::RecoTrack::getTrackFitStatus
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:537
Belle2::RecoTrack::getCardinalRepresentation
genfit::AbsTrackRep * getCardinalRepresentation() const
Get a pointer to the cardinal track representation. You are not allowed to modify or delete it!
Definition: RecoTrack.h:547
genfit::MeasuredStateOnPlane
#StateOnPlane with additional covariance matrix.
Definition: MeasuredStateOnPlane.h:39
genfit::KalmanFitStatus
FitStatus for use with AbsKalmanFitter implementations.
Definition: KalmanFitStatus.h:36
genfit::ReferenceStateOnPlane
#StateOnPlane with linearized transport to that #ReferenceStateOnPlane from previous and next #Refere...
Definition: ReferenceStateOnPlane.h:43
genfit::TrackPoint::getKalmanFitterInfo
KalmanFitterInfo * getKalmanFitterInfo(const AbsTrackRep *rep=nullptr) const
Helper to avoid casting.
Definition: TrackPoint.cc:180
genfit::AbsTrackRep
Abstract base class for a track representation.
Definition: AbsTrackRep.h:66
Belle2::RecoTrack::getHitPointsWithMeasurement
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:607
genfit::KalmanFitterInfo
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
Definition: KalmanFitterInfo.h:44
prepareAsicCrosstalkSimDB.fi
fi
open root file to store x-talk probability histogram
Definition: prepareAsicCrosstalkSimDB.py:88
genfit::AbsTrackRep::getDim
virtual unsigned int getDim() const =0
Get the dimension of the state vector used by the track representation.