Skip to content

Commit

Permalink
step 2
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger committed Oct 31, 2024
1 parent d849ca5 commit 2370d22
Showing 1 changed file with 28 additions and 40 deletions.
68 changes: 28 additions & 40 deletions Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ void addMeasurementToGx2fSums(Eigen::MatrixXd& aMatrixExtended,

ACTS_VERBOSE(
"Contributions in addMeasurementToGx2fSums:\n"
<< " kMeasDim: " << kMeasDim << "\n"
<< " predicted" << predicted.transpose() << "\n"
<< " kMeasDim: " << kMeasDim << "\n"
<< " predicted: " << predicted.transpose() << "\n"
<< " measurement: " << measurement.transpose() << "\n"
<< " covarianceMeasurement:\n"
<< covarianceMeasurement << "\n"
Expand All @@ -393,7 +393,7 @@ void addMeasurementToGx2fSums(Eigen::MatrixXd& aMatrixExtended,
<< " bVector contribution: "
<< (residual.transpose() * (*safeInvCovMeasurement) * projJacobian).eval()
<< "\n"
<< " chi2sumMeas: "
<< " chi2sum contribution: "
<< (residual.transpose() * (*safeInvCovMeasurement) * residual)(0, 0)
<< "\n"
<< " safeInvCovMeasurement:\n"
Expand Down Expand Up @@ -460,8 +460,8 @@ void addMaterialToGx2fSums(

ACTS_VERBOSE(
"Contributions in addMaterialToGx2fSums:\n"
<< " invCov: " << invCov << "\n"
<< " sinThetaLoc: " << sinThetaLoc << "\n"
<< " invCov: " << invCov << "\n"
<< " sinThetaLoc: " << sinThetaLoc << "\n"
<< " deltaPosition: " << deltaPosition << "\n"
<< " Phi:\n"
<< " scattering angle: " << scatteringAngles[eBoundPhi] << "\n"
Expand Down Expand Up @@ -825,9 +825,10 @@ class Gx2Fitter {
if (doMaterial) {
ACTS_DEBUG(" Update parameters with scattering angles.");
const auto scatteringMapId = scatteringMap->find(geoId);
ACTS_VERBOSE(" scatteringAngles:\n"
<< scatteringMapId->second.scatteringAngles()
<< "\n boundParams before the update: "
ACTS_VERBOSE(
" scatteringAngles: "
<< scatteringMapId->second.scatteringAngles().transpose());
ACTS_VERBOSE(" boundParams before the update: "
<< boundParams.parameters().transpose());
boundParams.parameters() +=
scatteringMapId->second.scatteringAngles();
Expand Down Expand Up @@ -928,9 +929,10 @@ class Gx2Fitter {
// multipleScattering and have material
ACTS_DEBUG(" Update parameters with scattering angles.");
const auto scatteringMapId = scatteringMap->find(geoId);
ACTS_VERBOSE(" scatteringAngles:\n"
<< scatteringMapId->second.scatteringAngles()
<< "\n boundParams before the update: "
ACTS_VERBOSE(
" scatteringAngles: "
<< scatteringMapId->second.scatteringAngles().transpose());
ACTS_VERBOSE(" boundParams before the update: "
<< boundParams.parameters().transpose());
boundParams.parameters() +=
scatteringMapId->second.scatteringAngles();
Expand Down Expand Up @@ -988,17 +990,6 @@ class Gx2Fitter {
"and/or material.");
}

// We only create track states here if there is already a measurement
// detected (no holes before the first measurement) or if we encounter
// material
const bool precedingMeasurementExists = (result.measurementStates > 0);
if (!precedingMeasurementExists && !surfaceHasMaterial) {
ACTS_DEBUG(
" Ignoring hole, because there are no preceding "
"measurements.");
return;
}

auto& fittedStates = *result.fittedStates;

// Add a <trackStateMask> TrackState entry multi trajectory. This
Expand Down Expand Up @@ -1098,7 +1089,7 @@ class Gx2Fitter {
requires(!isDirectNavigator)
{
// Preprocess Measurements (SourceLinks -> map)
// To be able to find measurements later, we put them into a map
// To be able to find measurements later, we put them into a map.
// We need to copy input SourceLinks anyway, so the map can own them.
ACTS_VERBOSE("Preparing " << std::distance(it, end)
<< " input measurements");
Expand All @@ -1109,7 +1100,6 @@ class Gx2Fitter {
auto geoId = gx2fOptions.extensions.surfaceAccessor(sl)->geometryId();
inputMeasurements.emplace(geoId, std::move(sl));
}
ACTS_VERBOSE("inputMeasurements.size() = " << inputMeasurements.size());

// Store, if we want to do multiple scattering. We still need to pass this
// option to the Actor.
Expand Down Expand Up @@ -1156,21 +1146,21 @@ class Gx2Fitter {
// track parameters.
BoundMatrix fullCovariancePredicted = BoundMatrix::Identity();

ACTS_VERBOSE("params:\n" << params);
ACTS_VERBOSE("Initial parameters: " << params.parameters().transpose());

/// Actual Fitting /////////////////////////////////////////////////////////
ACTS_DEBUG("Start to iterate");

// Iterate the fit and improve result. Abort after n steps or after
// convergence
// nUpdate is initialized outside to save its state for the track
// convergence.
// nUpdate is initialized outside to save its state for the track.
std::size_t nUpdate = 0;
for (nUpdate = 0; nUpdate < gx2fOptions.nUpdateMax; nUpdate++) {
ACTS_DEBUG("nUpdate = " << nUpdate + 1 << "/" << gx2fOptions.nUpdateMax);

// update params
params.parameters() += deltaParams;
ACTS_VERBOSE("updated params:\n" << params);
ACTS_VERBOSE("Updated parameters: " << params.parameters().transpose());

// set up propagator and co
Acts::GeometryContext geoCtx = gx2fOptions.geoContext;
Expand Down Expand Up @@ -1230,9 +1220,8 @@ class Gx2Fitter {
tipIndex = gx2fResult.lastMeasurementIndex;

// It could happen, that no measurements were found. Then the track would
// be empty and the following operations would be invalid.
// Usually, this only happens during the first iteration, due to bad
// initial parameters.
// be empty and the following operations would be invalid. Usually, this
// only happens during the first iteration, due to bad initial parameters.
if (tipIndex == Acts::MultiTrajectoryTraits::kInvalid) {
ACTS_INFO("Did not find any measurements in nUpdate "
<< nUpdate + 1 << "/" << gx2fOptions.nUpdateMax);
Expand Down Expand Up @@ -1309,12 +1298,11 @@ class Gx2Fitter {
}

// This check takes into account the evaluated dimensions of the
// measurements. To fit, we need at least NDF+1 measurements. However,
// we count n-dimensional measurements for n measurements, reducing the
// effective number of needed measurements.
// We might encounter the case, where we cannot use some (parts of a)
// measurements, maybe if we do not support that kind of measurement. This
// is also taken into account here.
// measurements. To fit, we need at least NDF+1 measurements. However, we
// count n-dimensional measurements for n measurements, reducing the
// effective number of needed measurements. We might encounter the case,
// where we cannot use some (parts of a) measurements, maybe if we do not
// support that kind of measurement. This is also taken into account here.
// We skip the check during the first iteration, since we cannot guarantee
// to hit all/enough measurement surfaces with the initial parameter
// guess.
Expand Down Expand Up @@ -1401,7 +1389,7 @@ class Gx2Fitter {
oldChi2sum = chi2sum;
}
ACTS_DEBUG("Finished to iterate");
ACTS_VERBOSE("final params:\n" << params);
ACTS_VERBOSE("Final parameters: " << params.parameters().transpose());
/// Finish Fitting /////////////////////////////////////////////////////////

ACTS_VERBOSE("Final scattering angles:");
Expand All @@ -1414,15 +1402,15 @@ class Gx2Fitter {
<< " )");
}

ACTS_VERBOSE("final covariance:\n" << fullCovariancePredicted);
ACTS_VERBOSE("Final covariance:\n" << fullCovariancePredicted);

// Propagate again with the final covariance matrix. This is necessary to
// obtain the propagated covariance for each state.
// We also need to recheck the result and find the tipIndex, because at this
// step, we will not ignore the boundary checks for measurement surfaces. We
// want to create trackstates only on surfaces, that we actually hit.
if (gx2fOptions.nUpdateMax > 0) {
ACTS_VERBOSE("final deltaParams:\n" << deltaParams);
ACTS_VERBOSE("Final delta parameters: " << deltaParams.transpose());
ACTS_VERBOSE("Propagate with the final covariance.");
// update covariance
params.covariance() = fullCovariancePredicted;
Expand Down

0 comments on commit 2370d22

Please sign in to comment.