702 if (not fitResult.ok())
705 std::unique_ptr<Trk::Track> newtrack =
nullptr;
707 const auto& acts_track = fitResult.value();
708 auto finalTrajectory = std::make_unique<Trk::TrackStates>();
710 int numberOfDeadPixel = 0;
711 int numberOfDeadSCT = 0;
713 std::vector<std::unique_ptr<const Acts::BoundTrackParameters>> actsSmoothedParam;
715 tracks.trackStateContainer().visitBackwards(acts_track.tipIndex(),
716 [&] (
const auto &state) ->
void
719 auto flag = state.typeFlags();
720 const auto* associatedDetEl = state.referenceSurface().associatedDetectorElement();
721 if (not associatedDetEl)
724 const auto* actsElement = dynamic_cast<const ActsDetectorElement*>(associatedDetEl);
728 const auto* upstreamDetEl = actsElement->upstreamDetectorElement();
729 if (not upstreamDetEl)
732 ATH_MSG_VERBOSE(
"Try casting to TRT for if");
733 if (dynamic_cast<const InDetDD::TRT_BaseElement*>(upstreamDetEl))
736 const auto* trkDetElem = dynamic_cast<const Trk::TrkDetElementBase*>(upstreamDetEl);
740 ATH_MSG_VERBOSE(
"trkDetElem type: " << static_cast<std::underlying_type_t<Trk::DetectorElemType>>(trkDetElem->detectorType()));
742 ATH_MSG_VERBOSE(
"Try casting to SiDetectorElement");
743 const auto* detElem = dynamic_cast<const InDetDD::SiDetectorElement*>(upstreamDetEl);
746 ATH_MSG_VERBOSE(
"detElem = " << detElem);
749 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
750 std::unique_ptr<Trk::TrackParameters> parm;
753 if (flag.test(Acts::TrackStateFlag::HoleFlag)){
754 ATH_MSG_VERBOSE(
"State is a hole (no associated measurement), use predicted parameters");
755 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
757 state.predictedCovariance(),
758 acts_track.particleHypothesis());
759 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
760 auto boundaryCheck = m_boundaryCheckTool->boundaryCheck(*parm);
763 ATH_MSG_VERBOSE(
"Check if this is a hole, a dead sensors or a state outside the sensor boundary");
764 if(boundaryCheck == Trk::BoundaryCheckResult::DeadElement){
765 if (detElem->isPixel()) {
768 else if (detElem->isSCT()) {
773 } else if (boundaryCheck != Trk::BoundaryCheckResult::Candidate){
777 typePattern.set(Trk::TrackStateOnSurface::Hole);
780 else if (
flag.test(Acts::TrackStateFlag::OutlierFlag) or !state.hasSmoothed()) {
781 ATH_MSG_VERBOSE(
"The state was tagged as an outlier or was missed in the reverse filtering, use filtered parameters");
782 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
784 state.filteredCovariance(),
785 acts_track.particleHypothesis());
786 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
787 typePattern.set(Trk::TrackStateOnSurface::Outlier);
791 ATH_MSG_VERBOSE(
"The state is a measurement state, use smoothed parameters");
793 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
795 state.smoothedCovariance(),
796 acts_track.particleHypothesis());
798 actsSmoothedParam.push_back(std::make_unique<const Acts::BoundTrackParameters>(Acts::BoundTrackParameters(actsParam)));
799 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
800 typePattern.set(Trk::TrackStateOnSurface::Measurement);
802 std::unique_ptr<Trk::MeasurementBase> measState;
803 if (state.hasUncalibratedSourceLink() && !SourceLinkType){
804 auto sl = state.getUncalibratedSourceLink().template get<ATLASSourceLink>();
806 measState = sl->uniqueClone();
808 else if (state.hasUncalibratedSourceLink() && SourceLinkType){
809 auto sl = state.getUncalibratedSourceLink().template get<PRDSourceLink>().prd;
812 const IdentifierHash idHash = sl->detectorElement()->identifyHash();
813 int dim = state.calibratedSize();
814 std::unique_ptr<Trk::RIO_OnTrack> rot;
816 const InDet::SCT_Cluster* sct_Cluster = dynamic_cast<const InDet::SCT_Cluster*>(sl);
818 ATH_MSG_ERROR(
"ERROR could not cast PRD to SCT_Cluster");
821 rot = std::make_unique<InDet::SCT_ClusterOnTrack>(sct_Cluster,Trk::LocalParameters(Trk::DefinedParameter(state.template calibrated<1>()[0], Trk::loc1)), state.template calibratedCovariance<1>(),idHash);
827 ATH_MSG_VERBOSE(
"Dimension is 2 but we need SCT_Cluster for this measurment");
832 rot = std::make_unique<InDet::PixelClusterOnTrack>(
pixelCluster,
Trk::LocalParameters(state.template calibrated<2>()),state.template calibratedCovariance<2>(),idHash);
836 throw std::domain_error(
"Cannot handle measurement dim>2");
838 measState = rot->uniqueClone();
840 double nDoF = state.calibratedSize();
845 ATH_MSG_VERBOSE(
"State succesfully creates, adding it to the trajectory");
846 finalTrajectory->insert(finalTrajectory->begin(), perState);
850 const Acts::BoundTrackParameters actsPer(acts_track.referenceSurface().getSharedPtr(),
851 acts_track.parameters(),
852 acts_track.covariance(),
853 acts_track.particleHypothesis());
854 std::unique_ptr<Trk::TrackParameters> per =
m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsPer, tgContext);
855 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
858 if (perState) finalTrajectory->insert(finalTrajectory->begin(), perState);
863 newtrack = std::make_unique<Trk::Track>(newInfo, std::move(finalTrajectory),
nullptr);