491 if (not fitResult.ok())
494 std::unique_ptr<Trk::Track> newtrack =
nullptr;
496 const auto& acts_track = fitResult.value();
497 auto finalTrajectory = std::make_unique<Trk::TrackStates>();
499 int numberOfDeadPixel = 0;
500 int numberOfDeadSCT = 0;
502 std::vector<std::unique_ptr<const Acts::BoundTrackParameters>> actsSmoothedParam;
504 tracks.trackStateContainer().visitBackwards(acts_track.tipIndex(),
505 [&] (
const auto &state) ->
void
508 auto flag = state.typeFlags();
509 const auto* associatedDetEl = state.referenceSurface().associatedDetectorElement();
510 if (not associatedDetEl)
513 const auto* actsElement = dynamic_cast<const ActsDetectorElement*>(associatedDetEl);
517 const auto* upstreamDetEl = actsElement->upstreamDetectorElement();
518 if (not upstreamDetEl)
521 ATH_MSG_VERBOSE(
"Try casting to TRT for if");
522 if (dynamic_cast<const InDetDD::TRT_BaseElement*>(upstreamDetEl))
525 const auto* trkDetElem = dynamic_cast<const Trk::TrkDetElementBase*>(upstreamDetEl);
529 ATH_MSG_VERBOSE(
"trkDetElem type: " << static_cast<std::underlying_type_t<Trk::DetectorElemType>>(trkDetElem->detectorType()));
531 ATH_MSG_VERBOSE(
"Try casting to SiDetectorElement");
532 const auto* detElem = dynamic_cast<const InDetDD::SiDetectorElement*>(upstreamDetEl);
535 ATH_MSG_VERBOSE(
"detElem = " << detElem);
538 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
539 std::unique_ptr<Trk::TrackParameters> parm;
542 if (flag.test(Acts::TrackStateFlag::HoleFlag)){
543 ATH_MSG_VERBOSE(
"State is a hole (no associated measurement), use predicted parameters");
544 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
546 state.predictedCovariance(),
547 acts_track.particleHypothesis());
548 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
549 auto boundaryCheck = m_boundaryCheckTool->boundaryCheck(*parm);
551 ATH_MSG_VERBOSE(
"Check if this is a hole, a dead sensors or a state outside the sensor boundary");
552 if(boundaryCheck == Trk::BoundaryCheckResult::DeadElement){
553 if (detElem->isPixel()) {
556 else if (detElem->isSCT()) {
561 } else if (boundaryCheck != Trk::BoundaryCheckResult::Candidate){
565 typePattern.set(Trk::TrackStateOnSurface::Hole);
568 else if (
flag.test(Acts::TrackStateFlag::OutlierFlag) or not state.hasSmoothed()) {
569 ATH_MSG_VERBOSE(
"The state was tagged as an outlier or was missed in the reverse filtering, use filtered parameters");
570 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
572 state.filteredCovariance(),
573 acts_track.particleHypothesis());
574 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
575 typePattern.set(Trk::TrackStateOnSurface::Outlier);
579 ATH_MSG_VERBOSE(
"The state is a measurement state, use smoothed parameters");
581 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
583 state.smoothedCovariance(),
584 acts_track.particleHypothesis());
586 actsSmoothedParam.push_back(std::make_unique<const Acts::BoundTrackParameters>(Acts::BoundTrackParameters(actsParam)));
587 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
588 typePattern.set(Trk::TrackStateOnSurface::Measurement);
591 std::unique_ptr<Trk::MeasurementBase> measState;
592 if (state.hasUncalibratedSourceLink()){
593 auto sl = state.getUncalibratedSourceLink().template get<ATLASSourceLink>();
595 measState = sl->uniqueClone();
597 double nDoF = state.calibratedSize();
602 ATH_MSG_VERBOSE(
"State succesfully creates, adding it to the trajectory");
603 finalTrajectory->insert(finalTrajectory->begin(), perState);
608 const Acts::BoundTrackParameters actsPer(acts_track.referenceSurface().getSharedPtr(),
609 acts_track.parameters(),
610 acts_track.covariance(),
611 acts_track.particleHypothesis());
612 std::unique_ptr<Trk::TrackParameters> per =
m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsPer, tgContext);
613 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
616 if (perState) finalTrajectory->insert(finalTrajectory->begin(), perState);
621 newtrack = std::make_unique<Trk::Track>(newInfo, std::move(finalTrajectory),
nullptr);