Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add estimateTrackParamCovariance to Core #3683

Merged
merged 11 commits into from
Oct 17, 2024
44 changes: 44 additions & 0 deletions Core/include/Acts/Seeding/EstimateTrackParamsFromSeed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,48 @@ std::optional<BoundVector> estimateTrackParamsFromSeed(
return params;
}

struct EstimateTrackParamCovarianceConfig {
BoundVector initialSigmas = {1. * UnitConstants::mm,
1. * UnitConstants::mm,
1. * UnitConstants::degree,
1. * UnitConstants::degree,
1. * UnitConstants::e / UnitConstants::GeV,
1. * UnitConstants::ns};

double initialSigmaPtRel = 0.1;

BoundVector initialVarInflation = {1., 1., 1., 1., 1., 1.};
};

BoundMatrix estimateTrackParamCovariance(
andiwand marked this conversation as resolved.
Show resolved Hide resolved
const BoundVector& params,
const EstimateTrackParamCovarianceConfig& config) {
BoundSquareMatrix result = BoundSquareMatrix::Zero();

for (std::size_t i = eBoundLoc0; i < eBoundSize; ++i) {
double sigma = config.initialSigmas[i];
double variance = sigma * sigma;

if (i == eBoundQOverP) {
// note that we rely on the fact that sigma theta is already computed
double varianceTheta = result(eBoundTheta, eBoundTheta);

// transverse momentum contribution
variance += std::pow(config.initialSigmaPtRel * params[eBoundQOverP], 2);

// theta contribution
variance +=
varianceTheta *
std::pow(params[eBoundQOverP] / std::tan(params[eBoundTheta]), 2);
}

// Inflate the initial covariance
variance *= config.initialVarInflation[i];

result(i, i) = variance;
}

return result;
}

} // namespace Acts
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,6 @@

namespace ActsExamples {

namespace {

Acts::BoundSquareMatrix makeInitialCovariance(
const TrackParamsEstimationAlgorithm::Config& config,
const Acts::BoundVector& params, const SimSpacePoint& sp) {
Acts::BoundSquareMatrix result = Acts::BoundSquareMatrix::Zero();

for (std::size_t i = Acts::eBoundLoc0; i < Acts::eBoundSize; ++i) {
double sigma = config.initialSigmas[i];
double variance = sigma * sigma;

if (i == Acts::eBoundQOverP) {
// note that we rely on the fact that sigma theta is already computed
double varianceTheta = result(Acts::eBoundTheta, Acts::eBoundTheta);

// transverse momentum contribution
variance +=
std::pow(config.initialSigmaPtRel * params[Acts::eBoundQOverP], 2);

// theta contribution
variance +=
varianceTheta * std::pow(params[Acts::eBoundQOverP] *
std::tan(params[Acts::eBoundTheta]),
2);
}

// Inflate the time uncertainty if no time measurement is available
if (i == Acts::eBoundTime && !sp.t().has_value()) {
variance *= config.noTimeVarInflation;
}

// Inflate the initial covariance
variance *= config.initialVarInflation[i];

result(i, i) = variance;
}

return result;
}

} // namespace

ActsExamples::TrackParamsEstimationAlgorithm::TrackParamsEstimationAlgorithm(
ActsExamples::TrackParamsEstimationAlgorithm::Config cfg,
Acts::Logging::Level lvl)
Expand Down Expand Up @@ -171,8 +129,19 @@ ActsExamples::ProcessCode ActsExamples::TrackParamsEstimationAlgorithm::execute(

const auto& params = optParams.value();

Acts::BoundSquareMatrix cov =
makeInitialCovariance(m_cfg, params, *bottomSP);
Acts::BoundSquareMatrix cov = Acts::estimateTrackParamCovariance(
params,
Acts::EstimateTrackParamCovarianceConfig{
.initialSigmas =
Eigen::Map<const Acts::BoundVector>{m_cfg.initialSigmas.data()},
.initialSigmaPtRel = m_cfg.initialSigmaPtRel,
.initialVarInflation = Eigen::Map<const Acts::BoundVector>{
m_cfg.initialVarInflation.data()}});

// Inflate the time uncertainty if no time measurement is available
if (!bottomSP->t().has_value()) {
cov(Acts::eBoundTime, Acts::eBoundTime) *= m_cfg.noTimeVarInflation;
}

trackParameters.emplace_back(surface->getSharedPtr(), params, cov,
m_cfg.particleHypothesis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/EventData/ParticleHypothesis.hpp"
#include "Acts/Seeding/EstimateTrackParamsFromSeed.hpp"
#include "Acts/Surfaces/PerigeeSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Helpers.hpp"
Expand Down Expand Up @@ -128,31 +129,16 @@ ActsExamples::ProcessCode ActsExamples::ParticleSmearing::execute(
Acts::BoundSquareMatrix cov = Acts::BoundSquareMatrix::Zero();
if (m_cfg.initialSigmas) {
// use the initial sigmas if set
for (std::size_t i = Acts::eBoundLoc0; i < Acts::eBoundSize; ++i) {
double sigma = (*m_cfg.initialSigmas)[i];
double variance = sigma * sigma;

if (i == Acts::eBoundQOverP) {
// note that we rely on the fact that sigma theta is already
// computed
double varianceTheta = cov(Acts::eBoundTheta, Acts::eBoundTheta);

// transverse momentum contribution
variance += std::pow(
m_cfg.initialSigmaPtRel * params[Acts::eBoundQOverP], 2);

// theta contribution
variance += varianceTheta *
std::pow(params[Acts::eBoundQOverP] *
std::tan(params[Acts::eBoundTheta]),
2);
}

// Inflate the initial covariance
variance *= m_cfg.initialVarInflation[i];

cov(i, i) = variance;
}
cov = Acts::estimateTrackParamCovariance(
params,
Acts::EstimateTrackParamCovarianceConfig{
.initialSigmas =
Eigen::Map<const Acts::BoundVector>{
m_cfg.initialSigmas->data()},
.initialSigmaPtRel = m_cfg.initialSigmaPtRel,
.initialVarInflation = Eigen::Map<const Acts::BoundVector>{
m_cfg.initialVarInflation.data()}});
} else {
// otherwise use the smearing sigmas

Expand Down
Loading