Skip to content

Commit

Permalink
requested changes review benjaminhuth
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger committed Aug 23, 2023
1 parent 2ee6be7 commit 35e9ddf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 66 deletions.
77 changes: 25 additions & 52 deletions Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ struct Gx2FitterOptions {
FreeToBoundCorrection freeToBoundCorrection;

/// Max number of iterations during the fit
const size_t nUpdateMax = 5;
size_t nUpdateMax = 5;
};

template <typename traj_t>
Expand Down Expand Up @@ -299,7 +299,7 @@ class Gx2Fitter {
void operator()(propagator_state_t& state, const stepper_t& stepper,
const navigator_t& navigator, result_type& result,
const Logger& /*logger*/) const {
// assert(result.fittedStates && "No MultiTrajectory set");
assert(result.fittedStates && "No MultiTrajectory set");

if (result.finished) {
return;
Expand All @@ -323,8 +323,9 @@ class Gx2Fitter {
// std::string direction = state.stepping.navDir.toString();
if (surface != nullptr) {
++result.surfaceCount;
std::cout << "Measurement surface " << surface->geometryId()
<< " detected." << std::endl;
ACTS_VERBOSE("Measurement surface " << surface->geometryId()
<< " detected.");

// check if measurement surface
auto sourcelink_it = inputMeasurements->find(surface->geometryId());

Expand All @@ -349,8 +350,6 @@ class Gx2Fitter {

// now get track state proxy back
auto trackStateProxy = fittedStates.getTrackState(newTrackIndex);
// auto trackStateProxy =
// fittedStates.getTrackState(result.lastTrackIndex);
trackStateProxy.setReferenceSurface(surface->getSharedPtr());
// assign the source link to the track state
trackStateProxy.setUncalibratedSourceLink(sourcelink_it->second);
Expand All @@ -372,12 +371,10 @@ class Gx2Fitter {
.template calibratedCovariance<measdimPlaceholder>();
// calculate residuals and return with covariances and jacobians
ActsVector<2> residual;
// std::vector<ActsScalar> covDiagonal;
for (long i = 0; i < measurement.size(); i++) {
residual[i] = measurement[i] - predicted[i];
// covDiagonal.push_back(measurement[i] - predicted[i]);
}
std::cout << "dbgMeasurement: " << measurement << std::endl;
ACTS_VERBOSE("Measurement in Actor:\n" << measurement);
result.collectorResiduals.push_back(residual);
result.collectorCovariance.push_back(covarianceMeasurement);

Expand All @@ -394,8 +391,7 @@ class Gx2Fitter {
}

if (result.surfaceCount > 11) {
std::cout << "dbgActor: finish due to limit. Result might be garbage."
<< std::endl;
ACTS_WARNING("Actor: finish due to limit. Result might be garbage.");
result.finished = true;
}
}
Expand Down Expand Up @@ -462,12 +458,7 @@ class Gx2Fitter {
auto geoId = sl.geometryId();
inputMeasurements.emplace(geoId, std::move(sl));
}
std::cout << "inputMeasurements.size() = " << inputMeasurements.size()
<< std::endl;
// for (const auto &p : inputMeasurements) {
// std::cout << "inputMeasurements.map-loop = " <<
// p.second.geometryId() << std::endl;
// }
ACTS_VERBOSE("inputMeasurements.size() = " << inputMeasurements.size());

/// Fully understand Aborter, Actor, Result later
// Create the ActionList and AbortList
Expand All @@ -487,21 +478,20 @@ class Gx2Fitter {
BoundMatrix aMatrix = BoundMatrix::Zero();
BoundVector bVector = BoundVector::Zero();

std::cout << "params:\n" << params << std::endl;
ACTS_VERBOSE("params:\n" << params);

/// Actual Fitting /////////////////////////////////////////////////////////
std::cout << "\nStart to iterate" << std::endl;
ACTS_DEBUG("Start to iterate");

// Iterate the fit and improve result. Abort after n steps or after
// convergence
for (size_t nUpdate = 0; nUpdate < gx2fOptions.nUpdateMax; nUpdate++) {
std::cout << "\nnUpdate = " << nUpdate + 1 << "/"
<< gx2fOptions.nUpdateMax << "\n"
<< std::endl;
ACTS_VERBOSE("nUpdate = " << nUpdate + 1 << "/"
<< gx2fOptions.nUpdateMax);

// update params
params.parameters() += deltaParams;
std::cout << "updated params:\n" << params << std::endl;
ACTS_VERBOSE("updated params:\n" << params);

// set up propagator and co
Acts::GeometryContext geoCtx = gx2fOptions.geoContext;
Expand All @@ -511,6 +501,7 @@ class Gx2Fitter {
auto& gx2fActor = propagatorOptions.actionList.template get<GX2FActor>();
gx2fActor.inputMeasurements = &inputMeasurements;
gx2fActor.extensions = gx2fOptions.extensions;
gx2fActor.actorLogger = m_actorLogger.get();

typename propagator_t::template action_list_t_result_t<
CurvilinearTrackParameters, Actors>
Expand All @@ -528,29 +519,12 @@ class Gx2Fitter {
auto& propRes = *result;
auto gx2fResult = std::move(propRes.template get<GX2FResult>());

// std::cout << "gx2fResult.collectorResiduals.size() = "
// << gx2fResult.collectorResiduals.size() << std::endl;
// for (auto vec : gx2fResult.collectorResiduals) {
// for (auto s : vec) {
// std::cout << s << ", ";
// }
// }
// std::cout << std::endl;

// std::cout << "gx2fResult.collectorCovariance.size() = "
// << gx2fResult.collectorCovariance.size() << std::endl;
// for (auto s : gx2fResult.collectorCovariance) {
// std::cout << s(0, 0) << ", " << s(0, 1) << ", " << s(1, 0) << ",
// "
// << s(1, 1) << "\n";
// }
// std::cout << std::endl;

// std::cout << "gx2fResult.collectorJacobians.size() = " <<
// gx2fResult.collectorJacobians.size() << std::endl;
// for (auto s : gx2fResult.collectorJacobians){
// std::cout << s << "\n" << std::endl;
// }
ACTS_VERBOSE("gx2fResult.collectorResiduals.size() = "
<< gx2fResult.collectorResiduals.size());
ACTS_VERBOSE("gx2fResult.collectorCovariance.size() = "
<< gx2fResult.collectorCovariance.size());
ACTS_VERBOSE("gx2fResult.collectorJacobians.size() = "
<< gx2fResult.collectorJacobians.size());

chi2sum = 0;
aMatrix = BoundMatrix::Zero();
Expand Down Expand Up @@ -597,19 +571,18 @@ class Gx2Fitter {
deltaParams(idp, 0) = deltaParamsReduced(idp, 0);
}

// TODO use Acts logging for this
std::cout << "chi2sum = " << chi2sum << std::endl;
std::cout << "aMatrix:\n" << aMatrix << std::endl;
std::cout << "bVector:\n" << bVector << std::endl;
std::cout << "deltaParams:\n" << deltaParams << std::endl;
ACTS_VERBOSE("chi2sum = " << chi2sum);
ACTS_VERBOSE("aMatrix:\n" << aMatrix);
ACTS_VERBOSE("bVector:\n" << bVector);
ACTS_VERBOSE("deltaParams:\n" << deltaParams);

// TODO check delta params and abort
// similar to:
// if (sum(delta_params) < 1e-3) {
// break;
// }
}
std::cout << "Finished to iterate" << std::endl;
ACTS_DEBUG("Finished to iterate");
/// Finish Fitting /////////////////////////////////////////////////////////

// Calculate covariance of the fitted parameters with inverse of [a]
Expand Down
31 changes: 17 additions & 14 deletions Tests/UnitTests/Core/TrackFitting/Gx2fTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@
#include "Acts/Tests/CommonHelpers/PredefinedMaterials.hpp"
#include "Acts/TrackFitting/GainMatrixUpdater.hpp"
#include "Acts/TrackFitting/GlobalChiSquareFitter.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <vector>

#include "FitterTestsCommon.hpp"

using namespace Acts::UnitLiterals;

Acts::Logging::Level logLevel = Acts::Logging::VERBOSE;
const auto gx2fLogger = Acts::getDefaultLogger("Gx2f", logLevel);

namespace Acts {
namespace Test {

Expand Down Expand Up @@ -183,7 +187,8 @@ BOOST_AUTO_TEST_SUITE(Gx2fTest)
// This test checks if the call to the fitter works and no errors occur in the
// framework, without fitting and updating any parameters
BOOST_AUTO_TEST_CASE(NoFit) {
std::cout << "\n\n##### Start test case NoFit #####" << std::endl;
ACTS_LOCAL_LOGGER(Acts::getDefaultLogger("Gx2fTests", logLevel));
ACTS_INFO("*** Test: NoFit -- Start");

// Context objects
Acts::GeometryContext geoCtx;
Expand Down Expand Up @@ -213,7 +218,7 @@ BOOST_AUTO_TEST_CASE(NoFit) {

using Gx2Fitter =
Experimental::Gx2Fitter<SimPropagator, VectorMultiTrajectory>;
Gx2Fitter Fitter(simPropagator);
Gx2Fitter Fitter(simPropagator, gx2fLogger->clone());

const Surface* rSurface = &parametersMeasurements.referenceSurface();

Expand Down Expand Up @@ -242,11 +247,12 @@ BOOST_AUTO_TEST_CASE(NoFit) {
BOOST_CHECK_EQUAL(track.parameters(), startParametersFit.parameters());
BOOST_CHECK_EQUAL(track.covariance(), BoundMatrix::Identity());

std::cout << "##### Finished test case NoFit #####" << std::endl;
ACTS_INFO("*** Test: NoFit -- Finish");
}

BOOST_AUTO_TEST_CASE(Fit5Iterations) {
std::cout << "\n\n##### Start test case Fit5Iterations #####" << std::endl;
ACTS_LOCAL_LOGGER(Acts::getDefaultLogger("Gx2fTests", logLevel));
ACTS_INFO("*** Test: Fit5Iterations -- Start");

// Create a test context
GeometryContext tgContext = GeometryContext();
Expand All @@ -255,7 +261,7 @@ BOOST_AUTO_TEST_CASE(Fit5Iterations) {
const size_t nSurfaces = 5;
detector.geometry = makeToyDetector(tgContext, nSurfaces);

std::cout << "\n*** Go to propagator ***\n" << std::endl;
ACTS_DEBUG("Go to propagator");

auto parametersMeasurements = makeParameters();
auto startParametersFit = makeParameters(10_mm, 10_mm, 10_mm, 42_ns,
Expand All @@ -280,16 +286,14 @@ BOOST_AUTO_TEST_CASE(Fit5Iterations) {
auto measurements = createMeasurements(
simPropagator, geoCtx, magCtx, parametersMeasurements, resolutions, rng);
auto sourceLinks = prepareSourceLinks(measurements.sourceLinks);
std::cout << "sourceLinks.size() = " << sourceLinks.size() << std::endl;
ACTS_VERBOSE("sourceLinks.size() = " << sourceLinks.size());

BOOST_REQUIRE_EQUAL(sourceLinks.size(), nSurfaces);

std::cout << "\n*** Start fitting ***\n" << std::endl;
ACTS_DEBUG("Start fitting");
ACTS_VERBOSE("startParameter unsmeared:\n" << parametersMeasurements);
ACTS_VERBOSE("startParameter fit:\n" << startParametersFit);

std::cout << "\n*** startParameter unsmeared: ***\n"
<< parametersMeasurements << std::endl;
std::cout << "\n*** startParameter fit: ***\n"
<< startParametersFit << std::endl;
const Surface* rSurface = &parametersMeasurements.referenceSurface();

Navigator::Config cfg{detector.geometry};
Expand All @@ -306,8 +310,7 @@ BOOST_AUTO_TEST_CASE(Fit5Iterations) {

using Gx2Fitter =
Experimental::Gx2Fitter<RecoPropagator, VectorMultiTrajectory>;

Gx2Fitter Fitter(rPropagator);
Gx2Fitter Fitter(rPropagator, gx2fLogger->clone());

Experimental::Gx2FitterExtensions<VectorMultiTrajectory> extensions;
extensions.calibrator
Expand Down Expand Up @@ -344,7 +347,7 @@ BOOST_AUTO_TEST_CASE(Fit5Iterations) {
BOOST_CHECK_CLOSE(track.parameters()[eBoundTime], 12591.2832360000, 1e-6);
BOOST_CHECK_CLOSE(track.covariance().determinant(), 1e-27, 4e0);

std::cout << "##### Finished test case Fit5Iterations #####" << std::endl;
ACTS_INFO("*** Test: Fit5Iterations -- Finish");
}

BOOST_AUTO_TEST_SUITE_END()
Expand Down

0 comments on commit 35e9ddf

Please sign in to comment.