-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add derivative of track parameters to alignment parameters (#125)
* Add bone structure for KF-based alignment implementation * Add calculation of global covariance matrix in KF * Add option to calcuate global track params covariance * Add enum for alignment parameters * Add alignment derivatives engine * Add derivative of bound parameters w.r.t. reference frame rotation * Add enum for cartesian coordinate indices * Move rotation derivatives into separate function * Add layer and volume alignment to bound parameters derivative * Change alignment frame to local frame * Break alignment to bound derivative calculation into separate functions * Fix the alignmentToPathDerivative return * Move alignment derivative calculations to surface method * Add static check of alignment parameters defintion * Implement local3D to bound 2D derivative with separte method * Re-implement calculation of alignment to path derivative for LineSurface * Re-implement the local3D to bound local derivative for DiscSurface * Re-implement the local3D to bound local derivative for LineSurface * Re-implement the local3D to bound local derivative for CylinderSurface * Re-implement the local3D to bound local derivative for ConeSurface * Make the local3D to bound local derivative method pure virtual * Add unit test for alignment helper * Pass pointer for global covariance matrix to smoother * Not use inline for alignment-related derivatives * Move function definitions in AlignmentHelper.hpp to cpp * Add derivative test for plane surface * Add test for line surface derivative calculation * Add derivative test for DiscSurface * Add derivative test for CylinderSurface * Add derivative test for ConeSurface * Add more Surface tests * Implement function to calculate global track parameters covariance * Remove the option to consider only measurement states
- Loading branch information
1 parent
efcfdeb
commit 6220f45
Showing
31 changed files
with
979 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
Core/include/Acts/Fitter/detail/KalmanGlobalCovariance.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2020 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "Acts/EventData/MultiTrajectory.hpp" | ||
#include "Acts/EventData/TrackParameters.hpp" | ||
#include "Acts/Geometry/GeometryContext.hpp" | ||
#include "Acts/Surfaces/Surface.hpp" | ||
#include "Acts/Utilities/Definitions.hpp" | ||
#include "Acts/Utilities/ParameterDefinitions.hpp" | ||
|
||
#include <unordered_map> | ||
|
||
namespace Acts { | ||
namespace detail { | ||
/// Calculate the global track parameters covariance for a smoothed trajectory | ||
/// stored in MultiTrajecty based on formulas at Journal of Physics: Conference | ||
/// Series 219 (2010) 032028. | ||
/// | ||
/// @tparam source_link_t The source link type of the trajectory | ||
/// @tparam parameters_t The track parameters type | ||
/// | ||
/// @param multiTraj The MultiTrajectory containing the trajectory to be | ||
/// investigated | ||
/// @param entryIndex The trajectory entry index | ||
/// | ||
/// @return The global track parameters covariance matrix and the starting | ||
/// row/column for smoothed states | ||
template <typename source_link_t, typename parameters_t = BoundParameters> | ||
std::pair<ActsMatrixX<BoundParametersScalar>, | ||
std::unordered_map<size_t, size_t>> | ||
globalTrackParametersCovariance( | ||
const Acts::MultiTrajectory<source_link_t>& multiTraj, | ||
const size_t& entryIndex) { | ||
using CovMatrix = typename parameters_t::CovMatrix_t; | ||
using GainMatrix = CovMatrix; | ||
|
||
// The last smoothed state index | ||
size_t lastSmoothedIndex = SIZE_MAX; | ||
// The total number of smoothed states | ||
size_t nSmoothedStates = 0; | ||
// Visit all the states | ||
multiTraj.visitBackwards(entryIndex, [&](const auto& ts) { | ||
if (ts.hasSmoothed()) { | ||
if (lastSmoothedIndex == SIZE_MAX) { | ||
lastSmoothedIndex = ts.index(); | ||
} | ||
nSmoothedStates++; | ||
} | ||
}); | ||
|
||
// Set the size of global track parameters covariance for all smoothed states | ||
ActsMatrixX<BoundParametersScalar> fullGlobalTrackParamsCov = | ||
ActsMatrixX<BoundParametersScalar>::Zero( | ||
nSmoothedStates * eBoundParametersSize, | ||
nSmoothedStates * eBoundParametersSize); | ||
// The index of state within the trajectory and the starting row/column for | ||
// this state in the global covariance matrix | ||
std::unordered_map<size_t, size_t> stateRowIndices; | ||
// Visit the smoothed states to calculate the full global track parameters | ||
// covariance | ||
size_t nProcessed = 0; | ||
auto prev_ts = multiTraj.getTrackState(lastSmoothedIndex); | ||
multiTraj.visitBackwards(lastSmoothedIndex, [&](const auto& ts) { | ||
const size_t iRow = fullGlobalTrackParamsCov.rows() - | ||
eBoundParametersSize * (nProcessed + 1); | ||
// Fill the covariance of this state | ||
fullGlobalTrackParamsCov.block<eBoundParametersSize, eBoundParametersSize>( | ||
iRow, iRow) = ts.smoothedCovariance(); | ||
// Fill the correlation between this state (indexed by i-1) and | ||
// beforehand smoothed states (indexed by j): C^n_{i-1, j}= G_{i-1} * | ||
// C^n_{i, j} for i <= j | ||
if (nProcessed > 0) { | ||
// Calculate the gain matrix | ||
GainMatrix G = ts.filteredCovariance() * prev_ts.jacobian().transpose() * | ||
prev_ts.predictedCovariance().inverse(); | ||
// Loop over the beforehand smoothed states | ||
for (size_t iProcessed = 1; iProcessed <= nProcessed; iProcessed++) { | ||
const size_t iCol = iRow + eBoundParametersSize * iProcessed; | ||
CovMatrix prev_correlation = | ||
fullGlobalTrackParamsCov | ||
.block<eBoundParametersSize, eBoundParametersSize>( | ||
iRow + eBoundParametersSize, iCol); | ||
CovMatrix correlation = G * prev_correlation; | ||
fullGlobalTrackParamsCov | ||
.block<eBoundParametersSize, eBoundParametersSize>(iRow, iCol) = | ||
correlation; | ||
fullGlobalTrackParamsCov | ||
.block<eBoundParametersSize, eBoundParametersSize>(iCol, iRow) = | ||
correlation.transpose(); | ||
} | ||
} | ||
stateRowIndices.emplace(ts.index(), iRow); | ||
nProcessed++; | ||
prev_ts = ts; | ||
}); | ||
|
||
return std::make_pair(fullGlobalTrackParamsCov, stateRowIndices); | ||
} | ||
|
||
} // namespace detail | ||
} // namespace Acts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2020 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include <utility> | ||
#include <vector> | ||
#include "Acts/Utilities/Definitions.hpp" | ||
|
||
namespace Acts { | ||
|
||
namespace detail { | ||
|
||
// The container for derivative of local frame axis w.r.t. its | ||
// rotation parameters. The first element is for x axis, second for y axis and | ||
// last for z axis | ||
using RotationToAxes = | ||
std::tuple<RotationMatrix3D, RotationMatrix3D, RotationMatrix3D>; | ||
|
||
/// @brief Evaluate the derivative of local frame axes vector w.r.t. | ||
/// its rotation around global x/y/z axis | ||
/// @Todo: add parameter for rotation axis order | ||
/// | ||
/// @param rotation The rotation that help place the surface | ||
/// | ||
/// @return Derivative of local frame x/y/z axis vector w.r.t. its | ||
/// rotation angles (extrinsic Euler angles) around global x/y/z axis | ||
RotationToAxes rotationToLocalAxesDerivative(const RotationMatrix3D& rotation); | ||
|
||
} // namespace detail | ||
|
||
} // namespace Acts |
Oops, something went wrong.