9 #include <boost/math/distributions/chi_squared.hpp>
10 #include <boost/test/unit_test.hpp>
43 using namespace Acts::UnitLiterals;
53 using TrackState = TrackState<SourceLink, BoundParameters>;
61 std::normal_distribution<double>
gauss(0., 1.);
92 std::vector<FittableMeasurement<SourceLink>>
outliers;
104 template <
typename propagator_state_t,
typename stepper_t>
105 void operator()(propagator_state_t& state,
const stepper_t&
stepper,
108 auto surface = state.navigation.currentSurface;
111 auto volumeID = geoID.volume();
112 auto layerID = geoID.layer();
114 auto vResolution = detectorResolution.find(volumeID);
115 if (vResolution != detectorResolution.end()) {
117 auto lResolution = vResolution->second.find(layerID);
118 if (lResolution != vResolution->second.end()) {
121 surface->globalToLocal(state.geoContext,
122 stepper.position(state.stepping),
123 stepper.direction(state.stepping), lPos);
124 if (lResolution->second.size() == 1) {
125 double sp = lResolution->second[0].second;
128 if (lResolution->second[0].first ==
eLOC_0) {
136 result.
outliers.push_back(std::move(o0));
145 result.
outliers.push_back(std::move(o1));
147 }
else if (lResolution->second.size() == 2) {
149 double sx = lResolution->second[
eLOC_0].second;
150 double sy = lResolution->second[
eLOC_1].second;
151 cov2D << sx * sx, 0., 0., sy * sy;
163 result.
outliers.push_back(std::move(o01));
191 template <
typename propagator_state_t,
typename stepper_t>
194 if (state.navigation.currentSurface &&
195 state.navigation.currentSurface->surfaceMaterial() &&
196 state.stepping.cov != Covariance::Zero()) {
198 std::normal_distribution<double> scatterAngle(
203 state.stepping.cov(
ePHI,
ePHI) += dPhi * dPhi;
207 auto direction = stepper.direction(state.stepping);
208 double theta = std::acos(direction.z());
209 double phi = std::atan2(direction.y(), direction.x());
211 state.stepping.update(
212 stepper.position(state.stepping),
213 {std::sin(theta + dTheta) * std::cos(phi + dPhi),
214 std::sin(theta + dTheta) * std::sin(phi + dPhi),
215 std::cos(theta + dTheta)},
216 std::max(stepper.momentum(state.stepping) -
225 double measurementSignificanceCutoff = 0;
227 double chi2Tolerance = 10
e-5;
236 template <
typename track_state_t>
238 double chi2 = trackState.chi2();
239 if (
std::abs(chi2) < chi2Tolerance) {
243 size_t ndf = trackState.calibratedSize();
245 boost::math::chi_squared chiDist(ndf);
247 double pValue = 1 - boost::math::cdf(chiDist, chi2);
249 return pValue > measurementSignificanceCutoff ?
false :
true;
274 MeasurementPropagator mPropagator(mStepper, mNavigator);
293 pixelVolumeRes[2] = pixelElementRes;
294 pixelVolumeRes[4] = pixelElementRes;
297 stripVolumeRes[2] = stripElementResI;
298 stripVolumeRes[4] = stripElementResO;
299 stripVolumeRes[6] = stripElementResI;
300 stripVolumeRes[8] = stripElementResO;
303 detRes[2] = pixelVolumeRes;
304 detRes[3] = stripVolumeRes;
314 auto mResult = mPropagator.propagate(mStart, mOptions).value();
316 const auto debugString =
317 mResult.template get<DebugOutput::result_type>().debugString;
318 std::cout <<
">>>> Measurement creation: " << std::endl;
319 std::cout << debugString;
324 std::vector<FittableMeasurement<SourceLink>> measurements = std::move(
325 mResult.template get<MeasurementCreator::result_type>().measurements);
326 BOOST_CHECK_EQUAL(measurements.size(), 6
u);
329 std::vector<SourceLink> sourcelinks;
331 std::back_inserter(sourcelinks),
337 rNavigator.resolvePassive =
false;
338 rNavigator.resolveMaterial =
true;
339 rNavigator.resolveSensitive =
true;
344 RecoStepper rStepper(bField);
346 RecoPropagator rPropagator(rStepper, rNavigator);
350 cov << 1000
_um, 0., 0., 0., 0., 0., 0., 1000
_um, 0., 0., 0., 0., 0., 0., 0.05,
351 0., 0., 0., 0., 0., 0., 0.05, 0., 0., 0., 0., 0., 0., 0.01, 0., 0., 0.,
378 auto fitRes = kFitter.
fit(sourcelinks, rStart, kfOptions);
379 BOOST_CHECK(fitRes.ok());
380 auto& fittedTrack = *fitRes;
381 auto fittedParameters = fittedTrack.fittedParameters.value();
384 fitRes = kFitter.
fit(sourcelinks, rStart, kfOptions);
385 BOOST_CHECK(fitRes.ok());
386 auto& fittedAgainTrack = *fitRes;
387 auto fittedAgainParameters = fittedAgainTrack.fittedParameters.value();
390 fittedAgainParameters.parameters().template head<5>(), 1
e-5);
392 fittedAgainParameters.parameters().template tail<1>(), 1
e-5);
395 std::vector<SourceLink> shuffledMeasurements = {
396 sourcelinks[3], sourcelinks[2], sourcelinks[1],
397 sourcelinks[4], sourcelinks[5], sourcelinks[0]};
400 fitRes = kFitter.
fit(shuffledMeasurements, rStart, kfOptions);
401 BOOST_CHECK(fitRes.ok());
402 auto& fittedShuffledTrack = *fitRes;
403 auto fittedShuffledParameters = fittedShuffledTrack.fittedParameters.value();
406 fittedShuffledParameters.parameters().template head<5>(),
409 fittedShuffledParameters.parameters().template tail<1>(),
413 std::vector<SourceLink> measurementsWithHole = {
414 sourcelinks[0], sourcelinks[1], sourcelinks[2], sourcelinks[4],
418 fitRes = kFitter.
fit(measurementsWithHole, rStart, kfOptions);
419 BOOST_CHECK(fitRes.ok());
420 auto& fittedWithHoleTrack = *fitRes;
421 auto fittedWithHoleParameters = fittedWithHoleTrack.fittedParameters.value();
424 BOOST_CHECK_EQUAL(fittedWithHoleTrack.missedActiveSurfaces.size(), 1
u);
431 fittedWithHoleParameters.parameters(),
437 fitRes = kFitter.
fit(sourcelinks, rStart, kfOptions);
438 BOOST_CHECK(fitRes.ok());
439 auto fittedWithBwdFiltering = *fitRes;
441 BOOST_CHECK(fittedWithBwdFiltering.forwardFiltered);
442 BOOST_CHECK(not fittedWithBwdFiltering.smoothed);
445 auto trackTip = fittedWithBwdFiltering.trackTip;
446 auto mj = fittedWithBwdFiltering.fittedStates;
447 size_t nSmoothed = 0;
448 mj.visitBackwards(trackTip, [&](
const auto& state) {
449 if (state.hasSmoothed())
452 BOOST_CHECK_EQUAL(nSmoothed, 6
u);
456 std::vector<FittableMeasurement<SourceLink>> outliers = std::move(
457 mResult.template get<MeasurementCreator::result_type>().outliers);
460 std::vector<SourceLink> measurementsWithOneOutlier = {
461 sourcelinks[0], sourcelinks[1], sourcelinks[2],
462 SourceLink{&outliers[3]}, sourcelinks[4], sourcelinks[5]};
465 fitRes = kFitter.
fit(measurementsWithOneOutlier, rStart, kfOptions);
466 BOOST_CHECK(fitRes.ok());
467 auto& fittedWithOneOutlier = *fitRes;
470 trackTip = fittedWithOneOutlier.trackTip;
471 mj = fittedWithOneOutlier.fittedStates;
472 size_t nOutliers = 0;
473 mj.visitBackwards(trackTip, [&](
const auto& state) {
474 auto typeFlags = state.typeFlags();
479 BOOST_CHECK_EQUAL(nOutliers, 1
u);