470 if (not fitResult.ok())
473 std::unique_ptr<Trk::Track> newtrack =
nullptr;
475 const auto& acts_track = fitResult.value();
476 auto finalTrajectory = std::make_unique<Trk::TrackStates>();
478 int numberOfDeadPixel = 0;
479 int numberOfDeadSCT = 0;
481 std::vector<std::unique_ptr<const Acts::BoundTrackParameters>> actsSmoothedParam;
483 tracks.trackStateContainer().visitBackwards(acts_track.tipIndex(),
484 [&] (
const auto &state) ->
void
487 auto flag = state.typeFlags();
488 const auto* associatedDetEl = state.referenceSurface().associatedDetectorElement();
489 if (not associatedDetEl)
492 const auto* actsElement = dynamic_cast<const ActsDetectorElement*>(associatedDetEl);
496 const auto* upstreamDetEl = actsElement->upstreamDetectorElement();
497 if (not upstreamDetEl)
500 ATH_MSG_VERBOSE(
"Try casting to TRT for if");
501 if (dynamic_cast<const InDetDD::TRT_BaseElement*>(upstreamDetEl))
504 const auto* trkDetElem = dynamic_cast<const Trk::TrkDetElementBase*>(upstreamDetEl);
508 ATH_MSG_VERBOSE(
"trkDetElem type: " << static_cast<std::underlying_type_t<Trk::DetectorElemType>>(trkDetElem->detectorType()));
510 ATH_MSG_VERBOSE(
"Try casting to SiDetectorElement");
511 const auto* detElem = dynamic_cast<const InDetDD::SiDetectorElement*>(upstreamDetEl);
514 ATH_MSG_VERBOSE(
"detElem = " << detElem);
517 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
518 std::unique_ptr<Trk::TrackParameters> parm;
521 if (flag.test(Acts::TrackStateFlag::HoleFlag)){
522 ATH_MSG_VERBOSE(
"State is a hole (no associated measurement), use predicted parameters");
523 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
525 state.predictedCovariance(),
526 acts_track.particleHypothesis());
527 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
528 auto boundaryCheck = m_boundaryCheckTool->boundaryCheck(*parm);
530 ATH_MSG_VERBOSE(
"Check if this is a hole, a dead sensors or a state outside the sensor boundary");
531 if(boundaryCheck == Trk::BoundaryCheckResult::DeadElement){
532 if (detElem->isPixel()) {
535 else if (detElem->isSCT()) {
540 } else if (boundaryCheck != Trk::BoundaryCheckResult::Candidate){
544 typePattern.set(Trk::TrackStateOnSurface::Hole);
547 else if (
flag.test(Acts::TrackStateFlag::OutlierFlag) or not state.hasSmoothed()) {
548 ATH_MSG_VERBOSE(
"The state was tagged as an outlier or was missed in the reverse filtering, use filtered parameters");
549 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
551 state.filteredCovariance(),
552 acts_track.particleHypothesis());
553 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
554 typePattern.set(Trk::TrackStateOnSurface::Outlier);
558 ATH_MSG_VERBOSE(
"The state is a measurement state, use smoothed parameters");
560 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
562 state.smoothedCovariance(),
563 acts_track.particleHypothesis());
565 actsSmoothedParam.push_back(std::make_unique<const Acts::BoundTrackParameters>(Acts::BoundTrackParameters(actsParam)));
566 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
567 typePattern.set(Trk::TrackStateOnSurface::Measurement);
570 std::unique_ptr<Trk::MeasurementBase> measState;
571 if (state.hasUncalibratedSourceLink()){
572 auto sl = state.getUncalibratedSourceLink().template get<ATLASSourceLink>();
574 measState = sl->uniqueClone();
576 double nDoF = state.calibratedSize();
581 ATH_MSG_VERBOSE(
"State succesfully creates, adding it to the trajectory");
582 finalTrajectory->insert(finalTrajectory->begin(), perState);
587 const Acts::BoundTrackParameters actsPer(acts_track.referenceSurface().getSharedPtr(),
588 acts_track.parameters(),
589 acts_track.covariance(),
590 acts_track.particleHypothesis());
591 std::unique_ptr<Trk::TrackParameters> per =
m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsPer, tgContext);
592 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
595 if (perState) finalTrajectory->insert(finalTrajectory->begin(), perState);
600 newtrack = std::make_unique<Trk::Track>(newInfo, std::move(finalTrajectory),
nullptr);