30 std::string
print(
const std::vector<MuPatSegment*>& segVec) {
42 std::string
print(
const std::vector<std::unique_ptr<MuPatTrack> >& tracks) {
44 for (
const std::unique_ptr<MuPatTrack>&
tit : tracks)
s << std::endl <<
print(*
tit);
52 declareInterface<IMuonTrackFinder>(
this);
82 return StatusCode::SUCCESS;
89 std::unique_ptr<TrackCollection>
result = std::make_unique<TrackCollection>();
93 ChSet chambersWithSegments;
94 StSet stationsWithSegments;
96 if (
extractSegments(ctx, coll, chamberSegments, stationSegments, chambersWithSegments, stationsWithSegments, trash_bin)) {
105 if (coll.empty())
return false;
117 if (chIndex < 0 || stIndex < 0) {
121 chambersWithSegments.insert(chIndex);
122 stationsWithSegments.insert(stIndex);
124 std::vector<MuPatSegment*>& segments = chamberSegments[chIndex];
125 segments.push_back(aSeg.get());
127 std::vector<MuPatSegment*>& segments2 = stationSegments[stIndex];
128 segments2.push_back(aSeg.get());
135 stationsWithSegments, trash_bin);
137 stationsWithSegments, trash_bin);
139 stationsWithSegments, trash_bin);
141 stationsWithSegments, trash_bin);
143 stationsWithSegments, trash_bin);
145 stationsWithSegments, trash_bin);
147 stationsWithSegments, trash_bin);
149 stationsWithSegments, trash_bin);
151 if (!segments.empty()) {
155 segs.insert(segs.end(), segments.begin(), segments.end());
167 if (ch1.empty() && ch2.empty())
return;
172 SegCol& stationVec = stationSegments[stIndex];
175 std::vector<bool> wasMatched2(ch2.size(),
false);
180 int qualityLevel1 = ch1.size() > 5 ? 1 : 2;
181 if (sit1->quality < qualityLevel1) {
182 ATH_MSG_VERBOSE(
"resolveSLOverlaps::bad segment1 q: " << sit1->quality <<
" cut " << qualityLevel1 << std::endl
184 stationVec.push_back(sit1);
188 bool wasMatched1 =
false;
191 int qualityLevel2 = ch2.size() > 5 ? 1 : 2;
198 if (sit2->quality < qualityLevel2) {
199 ATH_MSG_VERBOSE(
"resolveSLOverlaps::bad segment2: q " << sit2->quality <<
" cut " << qualityLevel2 << std::endl
203 if (sit1->quality < 2 && sit2->quality < 2) {
204 ATH_MSG_VERBOSE(
"resolveSLOverlaps:: combination of insufficient quality " << std::endl
205 <<
" q1 " << sit1->quality <<
" q2 "
211 <<
m_printer->print(*sit1->segment) << std::endl
215 ATH_MSG_VERBOSE(
" overlap combination rejected based on matching" << std::endl <<
m_printer->print(*sit2->segment));
221 std::unique_ptr<MuonSegment> newseg{
m_mooBTool->combineToSegment(ctx, *sit1, *sit2, emptyPhiHits)};
235 std::unique_ptr<MuPatSegment> segInfo =
m_candidateTool->createSegInfo(ctx, *newseg);
237 if (segInfo->quality < 2 || (segInfo->quality < sit1->quality || segInfo->quality < sit2->quality)) {
241 int shared_eta = 0, shared_phi = 0;
247 if (hit_ch1->info().id == hit_ch2->info().id) {
248 if (hit_ch1->info().measuresPhi)
256 if (sit1->etaHits().size() + sit2->etaHits().size() - shared_eta - segInfo->etaHits().size() > 1) {
257 ATH_MSG_VERBOSE(
"resolveSLOverlaps::more than one eta measurement removed, dropping track "
263 int phiHitDiff = sit1->phiHits().size() + sit2->phiHits().size() - shared_phi - segInfo->phiHits().size();
264 if (phiHitDiff > 1 || (sit1->phiHits().size() + sit2->phiHits().size() > 0 && segInfo->phiHits().empty())) {
265 ATH_MSG_VERBOSE(
"resolveSLOverlaps::more than one phi measurement removed, dropping track "
272 double cosPointingAngle = (newseg->globalPosition().x() * newseg->globalDirection().x() +
273 newseg->globalPosition().y() * newseg->globalDirection().y()) /
274 (newseg->globalPosition().perp() * newseg->globalDirection().perp());
275 if (cosPointingAngle < 0.995) {
276 ATH_MSG_VERBOSE(
"resolveSLOverlaps: rejected due to too large pointing angle " << std::endl
280 ATH_MSG_VERBOSE(
"created SL overlap segment: cos pointing " << cosPointingAngle << std::endl
285 wasMatched2[idx_ch2] =
true;
288 stationVec.push_back(segInfo.get());
295 if (!wasMatched1) { stationVec.push_back(sit1); }
299 for (
unsigned int i = 0;
i < wasMatched2.size(); ++
i) {
300 if (!wasMatched2[
i]) { stationVec.push_back(ch2[
i]); }
304 if (!stationVec.empty()) { stationsWithSegments.insert(stIndex); }
317 std::vector<std::unique_ptr<MuPatTrack> > resultAll;
325 std::vector<std::unique_ptr<MuPatTrack> >
result;
332 std::set<MuonStationIndex::StIndex> stations;
334 for (
unsigned int lit = 0; lit <
strategy.getAll().
size(); ++lit) {
335 std::vector<MuonStationIndex::ChIndex> chambers =
strategy.getCh(lit);
340 for (
unsigned int chin = 0; chin < chambers.size(); ++chin) {
345 if (stations.count(stIndex))
continue;
346 SegCol& segments = stationSegments[stIndex];
352 for (
unsigned int iseg = 0; iseg < segments.size(); iseg++) {
353 double thetaSeg = std::abs((*segments[iseg]).
segment->globalPosition().theta());
356 if ((0.74159 > thetaSeg && thetaSeg > 0.51159) || (2.63 > thetaSeg && thetaSeg > 2.40))
357 mySegColVec[lit].push_back(segments[iseg]);
360 mySegColVec[lit].insert(mySegColVec[lit].
end(), segments.begin(), segments.end());
363 stations.insert(stIndex);
368 for (
unsigned int chin = 0; chin < chambers.size(); ++chin) {
369 SegCol& segments = chamberSegments[chambers[chin]];
371 mySegColVec[lit].insert(mySegColVec[lit].
end(), segments.begin(), segments.end());
378 for (
unsigned int lit = 0; lit < mySegColVec.size(); ++lit) {
383 bool hasSegments =
false;
384 for (
unsigned int lit = 0; lit < mySegColVec.size(); ++lit) {
385 if (!mySegColVec[lit].
empty()) {
392 for (
unsigned int lit = 0; lit < mySegColVec.size(); ++lit)
393 for (
unsigned int sit = 0; sit < mySegColVec[lit].size(); ++sit)
404 std::vector<unsigned int> seeds;
409 std::vector<std::pair<int, unsigned int> > occupancy;
410 for (
unsigned int lit = 0; lit < mySegColVec.size(); ++lit) {
411 occupancy.emplace_back(mySegColVec[lit].
size(), lit);
413 std::stable_sort(occupancy.begin(), occupancy.end());
414 for (
unsigned int lit = 0; lit < occupancy.size(); ++lit) { seeds.push_back(occupancy[lit].
second); }
418 for (
unsigned int j = 0; j < mySegColVec.size(); ++j) seeds.push_back(j);
425 for (
unsigned int lin = 0; lin < seeds.size(); ++lin) {
427 ATH_MSG_VERBOSE(
"New seed layer " << lin <<
" segments in layer " << mySegColVec[lin].
size());
429 for (
unsigned int sin = 0;
sin < mySegColVec[lin].size();
sin++) {
430 seedSeg = mySegColVec[lin].operator[](
sin);
431 if (!seedSeg)
continue;
434 if (cutSeeds && seedSeg->
usedInFit)
continue;
445 for (
unsigned int sin2 = 0; sin2 < mySegColVec[lin].size(); sin2++) {
446 if (
sin == sin2)
continue;
456 double deltaEta = std::abs(etaSeed - etaSeg);
459 if (
deltaR < 0.35) segsInCone++;
465 std::vector<std::unique_ptr<MuPatTrack> >
found =
469 if (!
found.empty()) {
470 result.insert(
result.end(), std::make_move_iterator(
found.begin()), std::make_move_iterator(
found.end()));
487 resultAll.insert(resultAll.end(), std::make_move_iterator(
result.begin()), std::make_move_iterator(
result.end()));
496 if (!emSegments.empty()) {
499 if (!sit->tracks().empty())
continue;
502 if (sit->quality < 2)
continue;
505 std::unique_ptr<Trk::Track> segmentTrack(
m_segmentFitter->fit(*sit->segment));
509 if (recoveredTrack) segmentTrack.swap(recoveredTrack);
516 std::unique_ptr<MuPatTrack>
can =
m_candidateTool->createCandidate(*sit, segmentTrack);
518 resultAll.push_back(std::move(
can));
527 if (!resultAll.empty()) {
533 std::unique_ptr<TrackCollection> finalTrack =
nullptr;
534 if (!resultAll.empty()) { finalTrack =
selectTracks(resultAll); }
543 std::vector<std::unique_ptr<MuPatTrack> >
result;
545 const unsigned int endLayer = strat.
getAll().size();
547 for (
unsigned int ilayer = 0; ilayer < strat.
getAll().
size(); ++ilayer) {
548 if (ilayer ==
layer)
continue;
550 if (segs[ilayer].
empty())
continue;
552 std::vector<MuPatSegment*> matchedSegs;
553 bool tightCuts =
false;
556 double phiSeed = (seedSeg.
segment)->globalPosition().phi();
557 double etaSeed = (seedSeg.
segment)->globalPosition().eta();
560 for (
unsigned int j = 0; j < segs[ilayer].size(); j++) {
561 double phiSeg = (*segs[ilayer][j]).
segment->globalPosition().phi();
562 double etaSeg = (*segs[ilayer][j]).
segment->globalPosition().eta();
565 double deltaEta = std::abs(etaSeed - etaSeg);
568 if (
deltaR < 0.35) segsInCone++;
572 for (
unsigned int j = 0; j < segs[ilayer].size(); ++j) {
575 if (
isMatched) matchedSegs.push_back(segs[ilayer][j]);
577 if (matchedSegs.empty())
continue;
582 std::vector<std::unique_ptr<MuPatTrack> > tracks;
587 tracks =
m_trackBTool->find(ctx, seedSeg, segs[ilayer]);
588 if (!tracks.empty()) {
590 if (ilayer + 1 == strat.
getAll().size()) {
591 result.insert(
result.end(), std::make_move_iterator(tracks.begin()), std::make_move_iterator(tracks.end()));
596 for (std::unique_ptr<MuPatTrack>& cit : tracks) {
597 unsigned int nextLayer = ilayer + 1;
598 if (nextLayer < strat.
getAll().size()) {
599 int cutLevel = tightCuts ? 1 : 0;
600 std::vector<std::unique_ptr<MuPatTrack> > nextTracks =
602 if (!nextTracks.empty()) {
603 result.insert(
result.end(), std::make_move_iterator(nextTracks.begin()),
604 std::make_move_iterator(nextTracks.end()));
606 result.push_back(std::move(cit));
618 unsigned int nextlayer,
const unsigned int endlayer,
619 int cutLevel)
const {
620 std::vector<std::unique_ptr<MuPatTrack> >
result;
621 if (nextlayer < endlayer) {
622 for (; nextlayer != endlayer; nextlayer++) {
623 if (segs[nextlayer].
empty())
continue;
625 std::vector<std::unique_ptr<MuPatTrack> > nextTracks =
m_trackBTool->find(ctx, candidate, segs[nextlayer]);
626 if (!nextTracks.empty()) {
627 for (std::unique_ptr<MuPatTrack>& cit : nextTracks) {
628 std::vector<std::unique_ptr<MuPatTrack> > nextTracks2 =
630 if (!nextTracks2.empty()) {
631 result.insert(
result.end(), std::make_move_iterator(nextTracks2.begin()),
632 std::make_move_iterator(nextTracks2.end()));
634 result.push_back(std::move(cit));
646 std::unique_ptr<TrackCollection>
result = takeOwnership ?std::make_unique<TrackCollection>() : std::make_unique<TrackCollection>(
SG::VIEW_ELEMENTS);
648 for (std::unique_ptr<MuPatTrack>& cit :
candidates) {
649 auto & thisTrack = cit->track();
674 std::unique_ptr<TrackCollection> trkColl(
selectTracks(tracks,
false));
675 if (!trkColl || trkColl->
empty()) {
return; }
677 std::unique_ptr<const TrackCollection> resolvedTracks(
m_ambiTool->process(trkColl.get()));
678 if (!resolvedTracks) {
return; }
680 ATH_MSG_DEBUG(
" resolved track candidates: old size " << trkColl->
size() <<
" new size " << resolvedTracks->
size());
682 std::vector<std::unique_ptr<MuPatTrack> >
::iterator pat = tracks.begin();
683 for (;
pat != tracks.end();) {
685 for (
const Trk::Track* rtrk : *resolvedTracks) {
686 if (&(*pat)->track() == rtrk) {
703 for (
unsigned int i = 0;
i <
strategy.size(); ++
i) {
714 return StatusCode::SUCCESS;
720 const std::string delims(
" \t[],;");
727 std::vector<std::string>
options;
731 typedef std::vector<std::string> ChamberGroup;
732 std::vector<ChamberGroup> sequence;
735 bool success =
false;
736 std::unique_ptr<const MuonTrackSteeringStrategy>
result;
741 std::string::size_type begIdx, endIdx;
742 begIdx =
strategy.find_first_not_of(delims);
743 if (std::string::npos != begIdx) {
744 endIdx =
strategy.find(
':', begIdx);
745 if (std::string::npos != endIdx) {
747 std::string nameopt =
strategy.substr(begIdx, endIdx - begIdx);
748 std::string::size_type bi = nameopt.find(
'[');
749 if (std::string::npos != bi) {
750 name = nameopt.substr(0, bi);
753 std::string::size_type ei = nameopt.find(
']', bi);
754 if (std::string::npos == ei) { ei = nameopt.length(); }
755 std::string inputOpt = nameopt.substr(bi + 1, ei - bi - 1);
763 ATH_MSG_DEBUG(
"From strat: " <<
strategy <<
" with success " << success <<
" end " << endIdx <<
" beg " << begIdx
764 <<
" Name: " <<
name <<
" options: ");
772 endIdx =
strategy.find(
';', begIdx);
773 std::string::size_type lstIdx = endIdx;
774 if (std::string::npos == endIdx) { lstIdx =
strategy.length(); }
775 std::string grpString =
strategy.substr(begIdx, lstIdx - begIdx);
778 sequence.push_back(
group);
780 }
while (std::string::npos != endIdx && success);
784 std::vector<std::vector<MuonStationIndex::ChIndex> >
path;
785 for (
unsigned int i = 0;
i < sequence.size(); ++
i) {
786 std::vector<MuonStationIndex::ChIndex> idxGrp;
787 for (
unsigned int j = 0; j < sequence[
i].size(); ++j) {
790 if (sequence[
i][j] !=
"all" && sequence[
i][j] !=
"ALL" && sequence[
i][j] !=
"All") {
799 idxGrp.push_back(
idx);
802 path.push_back(idxGrp);
814 std::string::size_type begIdx = 0;
815 std::string::size_type endIdx = 0;
817 endIdx =
input.find(
',', begIdx);
818 std::string::size_type lstIdx = endIdx;
819 if (std::string::npos == endIdx) { lstIdx =
input.length(); }
820 std::string
item =
input.substr(begIdx, lstIdx - begIdx);
823 }
while (std::string::npos != endIdx);