700 if (not fitResult.ok())
703 std::unique_ptr<Trk::Track> newtrack =
nullptr;
705 const auto& acts_track = fitResult.value();
706 auto finalTrajectory = std::make_unique<Trk::TrackStates>();
708 int numberOfDeadPixel = 0;
709 int numberOfDeadSCT = 0;
711 std::vector<std::unique_ptr<const Acts::BoundTrackParameters>> actsSmoothedParam;
713 tracks.trackStateContainer().visitBackwards(acts_track.tipIndex(),
714 [&] (
const auto &state) ->
void
717 auto flag = state.typeFlags();
718 const auto* associatedDetEl = state.referenceSurface().associatedDetectorElement();
719 if (not associatedDetEl)
722 const auto* actsElement = dynamic_cast<const ActsDetectorElement*>(associatedDetEl);
726 const auto* upstreamDetEl = actsElement->upstreamDetectorElement();
727 if (not upstreamDetEl)
730 ATH_MSG_VERBOSE(
"Try casting to TRT for if");
731 if (dynamic_cast<const InDetDD::TRT_BaseElement*>(upstreamDetEl))
734 const auto* trkDetElem = dynamic_cast<const Trk::TrkDetElementBase*>(upstreamDetEl);
738 ATH_MSG_VERBOSE(
"trkDetElem type: " << static_cast<std::underlying_type_t<Trk::DetectorElemType>>(trkDetElem->detectorType()));
740 ATH_MSG_VERBOSE(
"Try casting to SiDetectorElement");
741 const auto* detElem = dynamic_cast<const InDetDD::SiDetectorElement*>(upstreamDetEl);
744 ATH_MSG_VERBOSE(
"detElem = " << detElem);
747 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
748 std::unique_ptr<Trk::TrackParameters> parm;
751 if (flag.test(Acts::TrackStateFlag::HoleFlag)){
752 ATH_MSG_VERBOSE(
"State is a hole (no associated measurement), use predicted parameters");
753 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
755 state.predictedCovariance(),
756 acts_track.particleHypothesis());
757 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
758 auto boundaryCheck = m_boundaryCheckTool->boundaryCheck(*parm);
761 ATH_MSG_VERBOSE(
"Check if this is a hole, a dead sensors or a state outside the sensor boundary");
762 if(boundaryCheck == Trk::BoundaryCheckResult::DeadElement){
763 if (detElem->isPixel()) {
766 else if (detElem->isSCT()) {
771 } else if (boundaryCheck != Trk::BoundaryCheckResult::Candidate){
775 typePattern.set(Trk::TrackStateOnSurface::Hole);
778 else if (
flag.test(Acts::TrackStateFlag::OutlierFlag) or !state.hasSmoothed()) {
779 ATH_MSG_VERBOSE(
"The state was tagged as an outlier or was missed in the reverse filtering, use filtered parameters");
780 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
782 state.filteredCovariance(),
783 acts_track.particleHypothesis());
784 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
785 typePattern.set(Trk::TrackStateOnSurface::Outlier);
789 ATH_MSG_VERBOSE(
"The state is a measurement state, use smoothed parameters");
791 const Acts::BoundTrackParameters actsParam(state.referenceSurface().getSharedPtr(),
793 state.smoothedCovariance(),
794 acts_track.particleHypothesis());
796 actsSmoothedParam.push_back(std::make_unique<const Acts::BoundTrackParameters>(Acts::BoundTrackParameters(actsParam)));
797 parm = m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsParam, tgContext);
798 typePattern.set(Trk::TrackStateOnSurface::Measurement);
800 std::unique_ptr<Trk::MeasurementBase> measState;
801 if (state.hasUncalibratedSourceLink() && !SourceLinkType){
802 auto sl = state.getUncalibratedSourceLink().template get<ATLASSourceLink>();
804 measState = sl->uniqueClone();
806 else if (state.hasUncalibratedSourceLink() && SourceLinkType){
807 auto sl = state.getUncalibratedSourceLink().template get<PRDSourceLink>().prd;
810 const IdentifierHash idHash = sl->detectorElement()->identifyHash();
811 int dim = state.calibratedSize();
812 std::unique_ptr<Trk::RIO_OnTrack> rot;
814 const InDet::SCT_Cluster* sct_Cluster = dynamic_cast<const InDet::SCT_Cluster*>(sl);
816 ATH_MSG_ERROR(
"ERROR could not cast PRD to SCT_Cluster");
819 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);
825 ATH_MSG_VERBOSE(
"Dimension is 2 but we need SCT_Cluster for this measurment");
830 rot = std::make_unique<InDet::PixelClusterOnTrack>(
pixelCluster,
Trk::LocalParameters(state.template calibrated<2>()),state.template calibratedCovariance<2>(),idHash);
834 throw std::domain_error(
"Cannot handle measurement dim>2");
836 measState = rot->uniqueClone();
838 double nDoF = state.calibratedSize();
843 ATH_MSG_VERBOSE(
"State succesfully creates, adding it to the trajectory");
844 finalTrajectory->insert(finalTrajectory->begin(), perState);
848 const Acts::BoundTrackParameters actsPer(acts_track.referenceSurface().getSharedPtr(),
849 acts_track.parameters(),
850 acts_track.covariance(),
851 acts_track.particleHypothesis());
852 std::unique_ptr<Trk::TrackParameters> per =
m_ATLASConverterTool->actsTrackParametersToTrkParameters(actsPer, tgContext);
853 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
856 if (perState) finalTrajectory->insert(finalTrajectory->begin(), perState);
861 newtrack = std::make_unique<Trk::Track>(newInfo, std::move(finalTrajectory),
nullptr);