33 #include <boost/container/flat_set.hpp>
34 #include <boost/container/small_vector.hpp>
37 constexpr
bool useBoundaryMaterialUpdate(
true);
85 double prePositionR =
pars.begin()->params->position().perp();
86 return (prePositionR > (
pars.begin()->params->position() +
87 static_cast<int>(
dir) * 0.5 * prePositionR *
88 pars.begin()->params->momentum().unit())
98 radialDirectionCheck(
const EventContext& ctx,
107 const Amg::Vector3D& startPosition = startParm.begin()->params->position();
108 const Amg::Vector3D& onLayerPosition = parsOnLayer.begin()->params->position();
111 double distToLayer = (startPosition - onLayerPosition).
mag();
115 if (boundarySurfaces.size() == 4) {
121 auto parsOnInsideSurface =
123 *(startParm.begin()->params),
129 double distToInsideSurface =
131 ? (startPosition - (parsOnInsideSurface->position())).mag()
135 return distToLayer < distToInsideSurface;
146 const std::string&
name,
151 declareInterface<IMultiStateExtrapolator>(
this);
165 m_fieldProperties = m_fastField
169 return StatusCode::SUCCESS;
182 const EventContext& ctx,
190 if (multiComponentState.empty()) {
193 return extrapolateImpl(ctx,
207 const EventContext& ctx,
214 if (multiComponentState.empty()) {
219 if (!currentVolume) {
221 "Current tracking volume could not be determined... returning {}");
224 return extrapolateDirectlyImpl(ctx,
244 const EventContext& ctx,
256 return extrapolateDirectlyImpl(ctx,
267 std::unique_ptr<Trk::TrackParameters> referenceParameters =
nullptr;
269 initialiseNavigation(ctx,
281 return extrapolateDirectlyImpl(ctx,
290 multiComponentState.begin()->params.get();
304 double initialDistance = globalSeparation.mag();
306 combinedState =
nullptr;
315 bool foundFinalBoundary(
true);
316 int fallbackOscillationCounter(0);
320 while (currentVolume && currentVolume != destinationVolume) {
322 extrapolateToVolumeBoundary(ctx,
337 if (!nextVolume || nextVolume == currentVolume) {
338 foundFinalBoundary =
false;
342 if (previousVolume == nextVolume) {
343 ++fallbackOscillationCounter;
345 if (fallbackOscillationCounter > 10) {
346 foundFinalBoundary =
false;
351 combinedState = currentState->begin()->params.get();
353 auto parametersAtDestination =
354 m_propagator->propagateParameters(ctx,
362 if (parametersAtDestination) {
363 newDestination = parametersAtDestination->
position();
366 newDestination = surface.
center();
369 double revisedDistance =
372 double distanceChange = std::abs(revisedDistance - initialDistance);
374 if (revisedDistance > initialDistance && distanceChange > 0.01) {
375 foundFinalBoundary =
false;
379 combinedState =
nullptr;
381 previousVolume = currentVolume;
384 currentVolume = nextVolume;
387 associatedLayer =
nullptr;
391 if (!currentState || (currentVolume != destinationVolume)) {
392 currentState = &multiComponentState;
393 foundFinalBoundary =
false;
396 if (!foundFinalBoundary) {
398 m_propagator->multiStatePropagate(ctx,
406 emptyRecycleBins(cache);
416 extrapolateInsideVolume(ctx,
430 if (!destinationState.empty() &&
431 &((*(destinationState.begin())).params->associatedSurface()) != &surface) {
432 destinationState.clear();
435 if (destinationState.empty()) {
436 destinationState = m_propagator->multiStatePropagate(ctx,
444 emptyRecycleBins(cache);
445 return destinationState;
453 const EventContext& ctx,
460 return m_propagator->multiStatePropagate(ctx,
474 const EventContext& ctx,
493 if (!associatedLayer) {
497 associatedLayer = associatedLayer
501 direction * combinedState->
momentum().unit(),
514 if (!updatedState.empty()) {
515 addMultiComponentToCache(cache,std::move(updatedState));
522 if (associatedLayer) {
533 if (!nextState.empty()) {
534 addMultiComponentToCache(cache,std::move(nextState));
552 nextNavigationCell = m_navigator->nextTrackingVolume(
553 ctx, *m_propagator, *navigationParameters, direction, trackingVolume);
557 std::unique_ptr<Trk::TrackParameters> nextNavigationParameters =
562 resetRecallInformation(cache);
565 if (useBoundaryMaterialUpdate) {
578 if (nextVolume && layerAtBoundary) {
580 matUpdatedState = m_materialUpdator->postUpdate(
591 if (!matUpdatedState.empty()) {
592 addMultiComponentToCache(cache, std::move(matUpdatedState));
593 nextNavigationParameters =
607 const EventContext& ctx,
625 if (!destinationLayer) {
635 currentState->begin()->params.get();
640 if (!associatedLayer) {
648 direction * combinedState->
momentum().unit(),
652 else if (associatedLayer != destinationLayer &&
662 if (!updatedState.empty()) {
664 currentState = &updatedState;
669 combinedState =
nullptr;
671 if (destinationLayer) {
674 if (associatedLayer && associatedLayer != destinationLayer) {
675 nextState = extrapolateFromLayerToLayer(ctx,
685 if (!nextState.empty()) {
687 currentState = &nextState;
692 extrapolateToDestinationLayer(ctx,
702 setRecallInformation(cache, surface, *destinationLayer, trackingVolume);
709 m_propagator->multiStatePropagate(ctx,
719 resetRecallInformation(cache);
729 const EventContext& ctx,
733 const Layer* startLayer,
734 const Layer* destinationLayer,
743 multiComponentState.begin()->params.get();
749 currentLayer->
nextLayer(currentPosition, currentDirection);
753 std::less<const Trk::Layer*>,
754 boost::container::small_vector<const Trk::Layer*, 8>>;
757 layersHit.insert(currentLayer);
760 while (nextLayer && nextLayer != destinationLayer) {
761 layersHit.insert(nextLayer);
765 currentState = extrapolateToIntermediateLayer(
768 !currentState.empty() ? currentState : multiComponentState,
775 if (!currentState.empty()) {
776 combinedState = currentState.begin()->params.get();
777 currentPosition = combinedState->
position();
778 currentDirection = direction * combinedState->
momentum().unit();
782 currentLayer = nextLayer;
783 nextLayer = currentLayer->
nextLayer(currentPosition, currentDirection);
784 if (layersHit.find(nextLayer) != layersHit.end()) {
789 if (destinationLayer && nextLayer != destinationLayer &&
790 !currentState.empty()) {
791 currentState.clear();
802 const EventContext& ctx,
809 bool doPerpCheck)
const
815 m_propagator->multiStatePropagate(ctx,
817 layer.surfaceRepresentation(),
823 if (destinationState.empty()) {
831 int rDirection = radialDirection(multiComponentState, direction);
832 int newrDirection = radialDirection(destinationState, direction);
833 if (newrDirection != rDirection && doPerpCheck) {
838 if (!radialDirectionCheck(ctx,
845 particleHypothesis)) {
861 if (updatedState.empty()) {
862 return destinationState;
873 const EventContext& ctx,
889 m_propagator->multiStatePropagate(ctx,
900 if (destinationState.empty()) {
901 combinedState = initialState->begin()->params.get();
904 destinationState = m_propagator->multiStatePropagate(ctx,
912 combinedState =
nullptr;
913 if (destinationState.empty()) {
923 if (startLayer != &
layer) {
931 if (updatedState.empty()) {
932 return destinationState;
943 const EventContext& ctx,
950 std::unique_ptr<Trk::TrackParameters>& referenceParameters,
955 emptyRecycleBins(cache);
957 multiComponentState.begin()->params.get();
965 associatedSurface ? associatedSurface->
associatedLayer() : currentLayer;
977 else if (!currentVolume) {
979 resetRecallInformation(cache);
980 currentVolume = m_navigator->volume(ctx, combinedState->
position());
981 currentLayer = (currentVolume)
989 referenceParameters =
991 ? m_propagator->propagateParameters(
992 ctx, *combinedState, surface, direction,
false, m_fieldProperties)
996 if (referenceParameters) {
999 direction = (surfaceDirection.dot(combinedState->
momentum()) > 0.)
1018 if (!referenceParameters) {
1019 referenceParameters =
1021 ? m_propagator->propagateParameters(
1022 ctx, *combinedState, surface, direction,
false, m_fieldProperties)
1028 if (!referenceParameters) {
1029 referenceParameters =
1031 ? m_propagator->propagateParameters(
1032 ctx, *combinedState, surface, direction,
false, m_fieldProperties)
1036 destinationVolume = m_navigator->volume(
1037 ctx, referenceParameters ? referenceParameters->
position()