16 const IInterface*
parent) :
18 declareInterface<IMuonCandidateTrackBuilderTool>(
this);
26 return StatusCode::SUCCESS;
34 std::stable_sort(layerIntersections.begin(), layerIntersections.end(),
36 auto getDistance = [](const MuonLayerIntersection& layerIntersection) {
37 if (layerIntersection.intersection.trackParameters.get() == nullptr) return 1e9;
38 return layerIntersection.intersection.trackParameters->position().mag();
44 std::vector<const Trk::MeasurementBase*> measurements;
46 bool isEndcap{
false},
isBarrel{
false}, isSmall{
false}, isLarge{
false};
47 for (
const MuonLayerIntersection& layerIntersection : layerIntersections) {
50 << layerIntersection.intersection.trackParameters->position().perp() <<
" z "
51 << layerIntersection.intersection.trackParameters->position().z() <<
" distance to IP "
52 << layerIntersection.intersection.trackParameters->position().mag());
53 ATH_MSG_VERBOSE(
" segment surface center perp " << layerIntersection.segment->associatedSurface().center().perp() <<
" z "
54 << layerIntersection.segment->associatedSurface().center().z() <<
" nr of msts "
55 << layerIntersection.segment->containedMeasurements().size());
62 std::vector<const Trk::MeasurementBase*> containedMeasurements = layerIntersection.segment->containedMeasurements();
77 if (!
id.is_valid())
continue;
79 if (!m_idHelperSvc->isMuon(
id))
continue;
81 if (m_idHelperSvc->isEndcap(
id)) {
86 if (m_idHelperSvc->isTrigger(
id))
continue;
88 if (m_idHelperSvc->isSmallChamber(
id)) {
95 if (m_reOrderMeasurements) {
98 SortMeas(&*m_edmHelperSvc, &*m_idHelperSvc, isEndcap));
101 measurements.insert(measurements.end(), containedMeasurements.begin(), containedMeasurements.end());
106 if (candidate.layerIntersections.size() == 2 && isSmall && isLarge) {
107 if (m_idHelperSvc->stationIndex(m_edmHelperSvc->chamberId(*candidate.layerIntersections.at(0).segment)) ==
108 m_idHelperSvc->stationIndex(m_edmHelperSvc->chamberId(*candidate.layerIntersections.at(1).segment))) {
109 const Muon::MuonSegment* seg1 = candidate.layerIntersections.at(0).segment.get();
110 const Muon::MuonSegment* seg2 = candidate.layerIntersections.at(1).segment.get();
112 seg2 = candidate.layerIntersections.at(0).segment.get();
113 seg1 = candidate.layerIntersections.at(1).segment.get();
119 if (m_edmHelperSvc->getIdentifier(*meas1) == m_edmHelperSvc->getIdentifier(*meas2)) {
128 ATH_MSG_DEBUG(
"S/L overlap where one segment contains the other, don't use");
129 return std::unique_ptr<Trk::Track>();
136 bool reorderAllMeasurements =
false;
137 if (isSmall && isLarge) reorderAllMeasurements =
true;
138 if (isEndcap &&
isBarrel) reorderAllMeasurements =
false;
140 if (m_reOrderMeasurements && reorderAllMeasurements) {
142 ATH_MSG_VERBOSE(
" reorder all measurements before " << std::endl << m_printer->print(measurements));
143 std::stable_sort(measurements.begin(), measurements.end(), SortMeas(&*m_edmHelperSvc, &*m_idHelperSvc, isEndcap));
146 ATH_MSG_VERBOSE(
"final measurement list: " << std::endl << m_printer->print(measurements));
148 ATH_MSG_DEBUG(
"Extracted hits from candidate: " << measurements.size());
149 std::unique_ptr<Trk::Track> refittedTrack{m_trackFitter->indetExtension(ctx, idTrack, measurements)};
151 ATH_MSG_DEBUG(
"got Track: " << m_printer->print(*refittedTrack) << std::endl << m_printer->printStations(*refittedTrack));
153 return refittedTrack;