50 declareInterface<IMuonHoleRecoveryTool>(
this);
86 return StatusCode::SUCCESS;
91 std::vector<std::unique_ptr<const Trk::TrackStateOnSurface>>&
states)
const {
109 ATH_MSG_DEBUG(
" MuonChamberHoleRecoveryTool failed to create a new track "
110 <<
" Returning input (unrecovered) track ");
111 return std::make_unique<Trk::Track>(
track);
114 <<
m_printer->printStations(*chRecTrack));
149 std::unique_ptr<Trk::Track> triggerRecTrack =
addMissingChambers(ctx, *chRecTrack, muonData,
false);
150 if (triggerRecTrack) chRecTrack.swap(triggerRecTrack);
152 std::unique_ptr<Trk::Track> mdtRecTrack =
addMissingChambers(ctx, *chRecTrack, muonData,
true);
153 if (mdtRecTrack) chRecTrack.swap(mdtRecTrack);
155 std::unique_ptr<Trk::Track> mdtRecTrackWithHoles =
findHoles(ctx, *chRecTrack, muonData);
156 if (mdtRecTrackWithHoles) chRecTrack.swap(mdtRecTrackWithHoles);
166 const std::set<IdentifierHash>& exclusion)
const {
170 std::vector<IdentifierHash> crossed;
180 if (!exclusion.count(*
it) && !
hashes.count(*
it)) {
229 std::set<MuonStationIndex::StIndex> stations;
230 double etamin{1e9}, etamax{-1e9}, phimin{1e9}, phimax{-1e9};
235 for (; tsit != tsit_end; ++tsit) {
239 double rpos =
pars->position().perp();
240 double zpos = std::abs(
pars->position().z());
241 if (rpos < 2500 && zpos < 4000)
continue;
242 double eta =
pars->position().eta();
243 double phi =
pars->position().phi();
245 msg() <<
"All State parameters: eta: " << eta <<
" ,phi: " << phi <<
" pos r " << rpos <<
" z " << zpos;
255 bool pseudo = !
id.is_valid();
257 if (pseudo || !
m_idHelperSvc->mdtIdHelper().is_muon(
id))
continue;
259 if (eta > etamax) etamax = eta;
261 if (phi > phimax) phimax = phi;
262 if (phi < phimin) phimin = phi;
264 msg() <<
"Selected State parameters: eta: " << eta <<
" ,phi: " << phi <<
" pos r " << rpos <<
" z " << zpos;
270 if (stations.count(stIndex))
continue;
271 stations.insert(stIndex);
280 ATH_MSG_DEBUG(
"Eta range: " <<
etamin <<
" " << etamax <<
" Phi range " << phimin <<
" " << phimax);
282 ATH_MSG_DEBUG(
"no hits selected, nothing further will be done");
297 for (; hsit != hsit_end; ++hsit) {
302 data.mdtPerStation[chIndex].insert(*hsit);
305 hsit =
data.csc.begin();
306 hsit_end =
data.csc.end();
307 for (; hsit != hsit_end; ++hsit) {
327 std::set<MuonStationIndex::StIndex> stations;
332 for (; tsit != tsit_end; ++tsit) {
382 if (
mm && !
data.mmTrack.count(
mm->collectionHash())) {
383 data.mmTrack.insert(
mm->collectionHash());
394 ATH_MSG_WARNING(
" track without states, cannot perform mdt hole search ");
399 if (!InterSectSvc.isValid()) {
400 ATH_MSG_ERROR(
"Failed to retrieve chamber intersection service");
405 std::vector<std::unique_ptr<const Trk::TrackStateOnSurface>>
states;
406 unsigned int nholes = 0;
407 std::set<Identifier> chambersInSearch;
410 if (
data.mdtTrack.count(ith)) {
419 if (chambersInSearch.count(chId)) {
428 std::unique_ptr<const Trk::TrackParameters> exPars{
reachableDetEl(ctx,
track, *detEl,
true)};
439 for (
unsigned int ii = 0; ii <
intersect.tubeIntersects().
size(); ++ii) {
448 chambersInSearch.insert(
ch);
451 std::unique_ptr<Trk::TrackParameters> tubePars{
460 double distEdge = std::abs(tubePars->parameters()[
Trk::locZ]) - 0.5 * tubeLen;
464 std::optional<Amg::Vector2D> locPos = surf.Trk::Surface::globalToLocal(tubePars->position());
466 bool inBounds =
false;
473 <<
" outside bounds ");
477 <<
" dist tube edge " << distEdge <<
" pullEdge " << pullEdge);
480 states.emplace_back(std::move(tsos));
487 if (
data.cscTrack.count(ith)) {
502 std::unique_ptr<const Trk::TrackParameters> exPars{
reachableDetEl(ctx,
track, *detEl,
true)};
508 std::set<Identifier> layIds;
509 std::vector<std::unique_ptr<const Trk::TrackStateOnSurface>> cscstates;
513 for (std::unique_ptr<const Trk::TrackStateOnSurface>& cscit : cscstates) {
515 states.emplace_back(std::move(cscit));
520 if (
data.tgcTrack.count(ith)) {
535 std::unique_ptr<const Trk::TrackParameters> exPars{
reachableDetEl(ctx,
track, *detEl,
true)};
541 std::set<Identifier> layIds;
542 std::vector<std::unique_ptr<const Trk::TrackStateOnSurface>> tgcstates;
546 for (std::unique_ptr<const Trk::TrackStateOnSurface>& tgcit : tgcstates) {
548 states.emplace_back(std::move(tgcit));
554 if (
data.rpcTrack.count(ith)) {
569 std::unique_ptr<const Trk::TrackParameters> exPars{
reachableDetEl(ctx,
track, *detEl,
true)};
575 std::set<Identifier> layIds;
576 std::vector<std::unique_ptr<const Trk::TrackStateOnSurface>> rpcstates;
580 for (std::unique_ptr<const Trk::TrackStateOnSurface>& rpcit : rpcstates) {
582 states.emplace_back(std::move(rpcit));
590 if (
data.stgcTrack.count(ith)) {
611 std::unique_ptr<const Trk::TrackParameters> exPars{
reachableDetEl(ctx,
track, *detEl,
true)};
617 std::set<Identifier> layIds;
618 std::vector<std::unique_ptr<const Trk::TrackStateOnSurface>> stgcstates;
622 for (std::unique_ptr<const Trk::TrackStateOnSurface>& stgcit : stgcstates) {
624 states.push_back(std::move(stgcit));
631 if (
data.mmTrack.count(ith)) {
652 std::unique_ptr<const Trk::TrackParameters> exPars{
reachableDetEl(ctx,
track, *detEl,
true)};
658 std::set<Identifier> layIds;
659 std::vector<std::unique_ptr<const Trk::TrackStateOnSurface>> mmstates;
663 for (std::unique_ptr<const Trk::TrackStateOnSurface>& mmit : mmstates) {
665 states.emplace_back(std::move(mmit));
670 auto trackStateOnSurfaces = std::make_unique<Trk::TrackStates>();
671 trackStateOnSurfaces->reserve(oldStates->
size() +
states.size());
673 std::vector<std::unique_ptr<const Trk::TrackStateOnSurface>> toBeSorted;
674 toBeSorted.reserve(oldStates->
size() +
states.size());
678 for (std::unique_ptr<const Trk::TrackStateOnSurface>& stit :
states) toBeSorted.emplace_back(std::move(stit));
682 for (std::unique_ptr<const Trk::TrackStateOnSurface>&
sorted : toBeSorted) { trackStateOnSurfaces->push_back(
sorted.release()); }
683 std::unique_ptr<Trk::Track> trackWithHoles = std::make_unique<Trk::Track>(
684 track.info(), std::move(trackStateOnSurfaces),
track.fitQuality() ?
track.fitQuality()->uniqueClone() :
nullptr);
688 <<
m_printer->printStations(*trackWithHoles));
689 return trackWithHoles;
697 std::vector<std::unique_ptr<const Trk::TrackStateOnSurface>>
states;
698 std::set<IdentifierHash> newMdtHashes;
699 std::set<IdentifierHash> newRpcHashes;
700 std::set<IdentifierHash> newTgcHashes;
701 std::set<IdentifierHash> newCscHashes;
703 std::set<IdentifierHash> newMMHashes;
704 std::set<IdentifierHash> newsTgcHashes;
706 ATH_MSG_DEBUG(
"Adding Missing MDT chambers: regions " <<
data.mdtPerStation.size());
707 std::vector<const MdtPrepDataCollection*> newmcols;
708 for (
const auto& chit :
data.mdtPerStation) {
710 std::vector<const MdtPrepDataCollection*>
cols;
712 std::map<int, std::vector<const MdtPrepData*>> mdtPrds;
713 std::unique_ptr<const Trk::TrackParameters> exParsFirst;
715 std::unique_ptr<const Trk::TrackParameters> exPars{
reachableDetEl(ctx,
track, *mit->front()->detectorElement())};
719 <<
" sector " << sector);
720 newmcols.emplace_back(mit);
721 std::vector<const MdtPrepData*>&
col = mdtPrds[sector];
722 col.insert(
col.end(), mit->begin(), mit->end());
723 if (!exParsFirst) exParsFirst.swap(exPars);
727 << mit->identifyHash());
730 std::vector<const MdtPrepData*>* prds =
nullptr;
731 std::map<int, std::vector<const MdtPrepData*>>
::iterator sectorIt = mdtPrds.begin();
732 if (mdtPrds.empty()) {
734 }
else if (mdtPrds.size() == 1) {
735 prds = §orIt->second;
740 if (
pos != mdtPrds.end())
746 if (prds && exParsFirst) {
747 std::unique_ptr<Trk::SegmentCollection> segments =
m_seededSegmentFinder->find(ctx, *exParsFirst, *prds);
752 std::unique_ptr<const Trk::TrackParameters> bestSegmentPars;
764 std::unique_ptr<const Trk::TrackParameters> segPars{
m_extrapolator->extrapolateDirectly(
772 if (std::abs(dangleYZ) < 0.05) {
774 bestSegmentPars.swap(segPars);
782 std::unique_ptr<Trk::TrackParameters> hitPars{
m_extrapolator->extrapolateDirectly(
785 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
789 states.emplace_back(tsos);
800 data.mdtCols = std::move(newmcols);
802 unsigned int nstates =
states.size();
805 std::vector<const RpcPrepDataCollection*> newtcols;
807 std::unique_ptr<const Trk::TrackParameters> exPars{
reachableDetEl(ctx,
track, *(rit)->front()->detectorElement())};
809 newtcols.emplace_back(rit);
811 std::set<Identifier> layIds;
813 if (
states.size() != nstates) {
819 data.rpcCols = std::move(newtcols);
823 std::vector<const TgcPrepDataCollection*> newtcols;
825 std::unique_ptr<const Trk::TrackParameters> exPars{
reachableDetEl(ctx,
track, *(tgcit)->front()->detectorElement())};
827 newtcols.emplace_back(tgcit);
829 std::set<Identifier> layIds;
831 if (
states.size() != nstates) {
837 data.tgcCols = std::move(newtcols);
841 std::vector<const CscPrepDataCollection*> newccols;
843 std::unique_ptr<const Trk::TrackParameters> exPars{
reachableDetEl(ctx,
track, *(cit)->front()->detectorElement())};
845 newccols.push_back(cit);
847 std::set<Identifier> layIds;
849 if (
states.size() != nstates) {
855 data.cscCols = std::move(newccols);
860 std::vector<const sTgcPrepDataCollection*> newstcols;
861 ATH_MSG_DEBUG(
" extractsTgcPrdCols data.stgcCols.size() " <<
data.stgcCols.size());
863 std::unique_ptr<const Trk::TrackParameters> exPars{
reachableDetEl(ctx,
track, *(stgcit)->front()->detectorElement())};
865 newstcols.push_back(stgcit);
867 std::set<Identifier> layIds;
870 if (
states.size() != nstates) {
876 data.stgcCols = std::move(newstcols);
882 std::vector<const MMPrepDataCollection*> newmcols;
886 newmcols.push_back(mit);
888 std::set<Identifier> layIds;
891 if (
states.size() != nstates) {
897 data.mmCols = std::move(newmcols);
914 auto trackStateOnSurfaces = std::make_unique<Trk::TrackStates>();
915 trackStateOnSurfaces->reserve(
states.size());
916 for (std::unique_ptr<const Trk::TrackStateOnSurface>&
sorted :
states) { trackStateOnSurfaces->push_back(
sorted.release()); }
918 std::unique_ptr<Trk::Track> newTrack = std::make_unique<Trk::Track>(
track.info(), std::move(trackStateOnSurfaces),
919 track.fitQuality() ?
track.fitQuality()->uniqueClone() :
nullptr);
920 std::unique_ptr<Trk::Track> refittedTrack;
929 data.mdtTrack.insert(newMdtHashes.begin(), newMdtHashes.end());
930 data.rpcTrack.insert(newRpcHashes.begin(), newRpcHashes.end());
931 data.tgcTrack.insert(newTgcHashes.begin(), newTgcHashes.end());
932 data.cscTrack.insert(newCscHashes.begin(), newCscHashes.end());
934 data.stgcTrack.insert(newsTgcHashes.begin(), newsTgcHashes.end());
935 data.mmTrack.insert(newMMHashes.begin(), newMMHashes.end());
937 return refittedTrack;
945 bool smallerBounds)
const {
947 std::unique_ptr<const Trk::TrackParameters> exPars;
971 if (covx > 0.0 && covy > 0.0) {
980 if (tolx > 10.) tolx = 10.;
981 if (toly > 10.) toly = 10.;
988 std::ostringstream parsType;
991 parsType <<
" tolerance=(" << tolx <<
"," << toly <<
")";
993 parsType <<
" => inbounds";
995 parsType <<
" => outbounds";
998 if (!inbounds) {
return nullptr; }