ATLAS Offline Software
Loading...
Searching...
No Matches
MuonCombined::MuonCandidateTool Class Reference

#include <MuonCandidateTool.h>

Inheritance diagram for MuonCombined::MuonCandidateTool:
Collaboration diagram for MuonCombined::MuonCandidateTool:

Public Member Functions

virtual ~MuonCandidateTool ()=default
virtual StatusCode initialize () override
virtual void create (const xAOD::TrackParticleContainer &tracks, MuonCandidateCollection &outputCollection, TrackCollection &outputTracks, const EventContext &ctx) const override
 IMuonCandidateTool interface: build a MuonCandidateCollection from a TrackCollection of spectrometer tracks.

Private Attributes

PublicToolHandle< Muon::MuonEDMPrinterToolm_printer {this, "Printer", "Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"}
ToolHandle< Rec::ICombinedMuonTrackBuilderm_trackBuilder {this, "TrackBuilder", "", ""}
ToolHandle< Muon::IMuonTrackExtrapolationToolm_trackExtrapolationTool
ToolHandle< Trk::ITrackAmbiguityProcessorToolm_ambiguityProcessor
ToolHandle< Trk::IExtendedTrackSummaryToolm_trackSummaryTool {this, "TrackSummaryTool", "MuonTrackSummaryTool"}
ServiceHandle< Muon::IMuonIdHelperSvcm_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}
SG::ReadCondHandleKey< InDet::BeamSpotDatam_beamSpotKey {this, "BeamSpotKey", "BeamSpotData", "SG key for beam spot"}
SG::ReadHandleKey< Trk::SegmentCollectionm_segmentKey {this, "SegmentContainer", ""}
 Retrieve the segment container to perform the segment association offline.
PublicToolHandle< MuonCombined::IMuonTrackToSegmentAssociationToolm_trackSegmentAssociationTool
Gaudi::Property< unsigned int > m_extrapolationStrategy {this, "ExtrapolationStrategy", 0}
Gaudi::Property< bool > m_commissioning

Detailed Description

Definition at line 25 of file MuonCandidateTool.h.

Constructor & Destructor Documentation

◆ ~MuonCandidateTool()

virtual MuonCombined::MuonCandidateTool::~MuonCandidateTool ( )
virtualdefault

Member Function Documentation

◆ create()

void MuonCombined::MuonCandidateTool::create ( const xAOD::TrackParticleContainer & tracks,
MuonCandidateCollection & outputCollection,
TrackCollection & outputTracks,
const EventContext & ctx ) const
overridevirtual

IMuonCandidateTool interface: build a MuonCandidateCollection from a TrackCollection of spectrometer tracks.

Last but not least set the segments

Definition at line 41 of file MuonCandidateTool.cxx.

42 {
43 ATH_MSG_DEBUG("Producing MuonCandidates for " << tracks.size());
44 unsigned int ntracks = 0;
45
46 SG::ReadCondHandle<InDet::BeamSpotData> beamSpotHandle{m_beamSpotKey, ctx};
47 if (!beamSpotHandle.isValid()) {
48 ATH_MSG_ERROR("Could not retrieve the BeamSpot data from key " << m_beamSpotKey.objKey());
49 return;
50 }
51
52 ATH_MSG_DEBUG("Beamspot position bs_x=" << beamSpotHandle->beamPos());
53
54 std::vector<track_link> trackLinks;
55
56 unsigned int index = -1;
57 // Loop over MS tracks
58 for (const auto* track : tracks) {
59 ++index;
60
61 if (!track->trackLink().isValid() || !track->track()) {
62 ATH_MSG_WARNING("MuonStandalone track particle without Trk::Track");
63 continue;
64 }
65 const Trk::Track& msTrack = *track->track();
66
67 ATH_MSG_VERBOSE("Re-Fitting track " << std::endl
68 << m_printer->print(msTrack) << std::endl
69 << m_printer->printStations(msTrack));
70 std::unique_ptr<Trk::Track> standaloneTrack;
71 if (m_extrapolationStrategy == 0u) {
72 standaloneTrack = m_trackBuilder->standaloneFit(ctx, msTrack, beamSpotHandle->beamPos(), nullptr);
73 } else {
74 standaloneTrack = m_trackExtrapolationTool->extrapolate(msTrack, ctx);
75 }
76 if (standaloneTrack) {
77 // Reject the track if its fit quality is much (much much) worse than that of the non-extrapolated track
78 if (standaloneTrack->fitQuality()->doubleNumberDoF() == 0) {
79 standaloneTrack.reset();
80 ATH_MSG_DEBUG("extrapolated track has no DOF, don't use it");
81 } else {
82 double mschi2 = 2.5; // a default we should hopefully never have to use (taken from CombinedMuonTrackBuilder)
83 if (msTrack.fitQuality()->doubleNumberDoF() > 0)
84 mschi2 = msTrack.fitQuality()->chiSquared() / msTrack.fitQuality()->doubleNumberDoF();
85 // choice of 1000 is slightly arbitrary, the point is that the fit should be really be terrible
86 if (standaloneTrack->fitQuality()->chiSquared() / standaloneTrack->fitQuality()->doubleNumberDoF() > 1000 * mschi2) {
87 standaloneTrack.reset();
88 ATH_MSG_DEBUG("extrapolated track has a degraded fit, don't use it");
89 }
90 }
91 }
92 if (standaloneTrack) {
93 standaloneTrack->info().setParticleHypothesis(Trk::muon);
94 standaloneTrack->info().setPatternRecognitionInfo(Trk::TrackInfo::MuidStandAlone);
95 ATH_MSG_VERBOSE("Extrapolated track " << std::endl
96 << m_printer->print(*standaloneTrack) << std::endl
97 << m_printer->printStations(*standaloneTrack));
98 ++ntracks;
99 if (!standaloneTrack->perigeeParameters())
100 ATH_MSG_WARNING(" Track without perigee " << (*standaloneTrack));
101 else if (!standaloneTrack->perigeeParameters()->covariance())
102 ATH_MSG_WARNING(" Track with perigee without covariance " << (*standaloneTrack));
103 trackLinks.emplace_back(std::move(standaloneTrack), index, true);
104 } else {
105 // We can create tracks from EM segments+TGC hits
106 // If these are not successfully extrapolated, they are too low quality to be useful
107 // So only make candidates from un-extrapolated tracks if they are not EM-only
108 bool skipTrack = true;
109 const Trk::MuonTrackSummary* msMuonTrackSummary = nullptr;
110 std::unique_ptr<Trk::TrackSummary> msTrackSummary;
111 // If reading from an ESD, the track will not have a track summary yet
112 if (!msTrack.trackSummary()) {
113 msTrackSummary = m_trackSummaryTool->summary(msTrack);
114 msMuonTrackSummary = msTrackSummary->muonTrackSummary();
115 } else
116 msMuonTrackSummary = msTrack.trackSummary()->muonTrackSummary();
117 for (const auto& chs : msMuonTrackSummary->chamberHitSummary()) {
118 using namespace Muon::MuonStationIndex;
119 if ((chs.isMdt() && m_idHelperSvc->stationIndex(chs.chamberId()) != StIndex::EM) ||
120 m_idHelperSvc->isCsc(chs.chamberId())) {
121 skipTrack = false;
122 break;
123 }
124 }
125 if (!skipTrack) { trackLinks.emplace_back(std::make_unique<Trk::Track>(msTrack), index, false); }
126 }
127 }
129 std::unique_ptr<TrackCollection> extrapTracks = std::make_unique<TrackCollection>(SG::VIEW_ELEMENTS);
130 extrapTracks->reserve(trackLinks.size());
131 for (const track_link& link : trackLinks) extrapTracks->push_back(link.track.get());
132 ATH_MSG_DEBUG("Finished back-tracking, total number of successfull fits " << ntracks);
133
134 // Resolve ambiguity between extrapolated tracks (where available)
135 std::unique_ptr<const TrackCollection> resolvedTracks(m_ambiguityProcessor->process(extrapTracks.get()));
136
137 ATH_MSG_DEBUG("Finished ambiguity solving: " << extrapTracks->size() << " track(s) in -> " << resolvedTracks->size()
138 << " track(s) out");
139
140 const Trk::SegmentCollection* segments{nullptr};
141 if (!m_segmentKey.empty()) {
142 SG::ReadHandle<Trk::SegmentCollection> readHandle{m_segmentKey, ctx};
143 if (!readHandle.isValid()) {
144 ATH_MSG_WARNING("Failed to retrieve the segment container " << m_segmentKey.fullKey());
145 } else
146 segments = readHandle.cptr();
147 }
148
149 // Loop over resolved tracks and build MuonCondidate collection
150 for (const Trk::Track* track : *resolvedTracks) {
151 std::vector<track_link>::iterator tLink =
152 std::find_if(trackLinks.begin(), trackLinks.end(), [&track](const track_link& link) { return link.track.get() == track; });
153
154 if (tLink == trackLinks.end()) {
155 ATH_MSG_WARNING("Unable to find internal link between MS and SA tracks!");
156 continue;
157 }
158
159 std::unique_ptr<MuonCandidate> muon_candidate;
160 ElementLink<xAOD::TrackParticleContainer> MS_TrkLink{tracks, tLink->container_index, ctx};
161 if (tLink->extp_succeed) {
162 outputTracks.push_back(std::move(tLink->track));
163 ElementLink<TrackCollection> saLink(outputTracks, outputTracks.size() - 1, ctx);
164 muon_candidate = std::make_unique<MuonCandidate>(MS_TrkLink, saLink, outputTracks.size() - 1);
165 // remove track from set so it is not deleted
166 } else {
167 // in this case the extrapolation failed
168 muon_candidate = std::make_unique<MuonCandidate>(MS_TrkLink);
169 }
170 muon_candidate->setCommissioning(m_commissioning);
172 if (segments) {
173 std::vector<const Muon::MuonSegment*> assoc_segs;
174 m_trackSegmentAssociationTool->associatedSegments(*muon_candidate->primaryTrack(), segments, assoc_segs);
175 muon_candidate->setSegments(std::move(assoc_segs));
176 }
177
178 outputCollection.push_back(std::move(muon_candidate));
179 }
180 }
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
ToolHandle< Trk::ITrackAmbiguityProcessorTool > m_ambiguityProcessor
ToolHandle< Trk::IExtendedTrackSummaryTool > m_trackSummaryTool
ToolHandle< Muon::IMuonTrackExtrapolationTool > m_trackExtrapolationTool
PublicToolHandle< MuonCombined::IMuonTrackToSegmentAssociationTool > m_trackSegmentAssociationTool
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
PublicToolHandle< Muon::MuonEDMPrinterTool > m_printer
SG::ReadHandleKey< Trk::SegmentCollection > m_segmentKey
Retrieve the segment container to perform the segment association offline.
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
ToolHandle< Rec::ICombinedMuonTrackBuilder > m_trackBuilder
Gaudi::Property< unsigned int > m_extrapolationStrategy
Gaudi::Property< bool > m_commissioning
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
double chiSquared() const
returns the of the overall track fit
Definition FitQuality.h:56
double doubleNumberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as double
Definition FitQuality.h:68
const std::vector< ChamberHitSummary > & chamberHitSummary() const
access to the vector of chamber hit summaries on the track
const MuonTrackSummary * muonTrackSummary() const
returns a pointer to the MuonTrackSummary if available
const Trk::TrackSummary * trackSummary() const
Returns a pointer to the const Trk::TrackSummary owned by this const track (could be nullptr)
const FitQuality * fitQuality() const
return a pointer to the fit quality const-overload
str index
Definition DeMoScan.py:362
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
DataVector< Trk::Segment > SegmentCollection

◆ initialize()

StatusCode MuonCombined::MuonCandidateTool::initialize ( )
overridevirtual

Definition at line 28 of file MuonCandidateTool.cxx.

28 {
29 ATH_CHECK(m_printer.retrieve());
30 ATH_CHECK(m_trackBuilder.retrieve(EnableTool{!m_trackBuilder.empty()}));
31 ATH_CHECK(m_trackExtrapolationTool.retrieve(EnableTool{!m_trackExtrapolationTool.empty()}));
33 ATH_CHECK(m_trackSummaryTool.retrieve());
34 ATH_CHECK(m_idHelperSvc.retrieve());
35 ATH_CHECK(m_beamSpotKey.initialize());
36
37 ATH_CHECK(m_segmentKey.initialize(!m_segmentKey.empty()));
38 ATH_CHECK(m_trackSegmentAssociationTool.retrieve(EnableTool{!m_segmentKey.empty()}));
39 return StatusCode::SUCCESS;
40 }
#define ATH_CHECK
Evaluate an expression and check for errors.

Member Data Documentation

◆ m_ambiguityProcessor

ToolHandle<Trk::ITrackAmbiguityProcessorTool> MuonCombined::MuonCandidateTool::m_ambiguityProcessor
private
Initial value:
{this, "AmbiguityProcessor",
"Trk::TrackSelectionProcessorTool/MuonAmbiProcessor"}

Definition at line 41 of file MuonCandidateTool.h.

41 {this, "AmbiguityProcessor",
42 "Trk::TrackSelectionProcessorTool/MuonAmbiProcessor"};

◆ m_beamSpotKey

SG::ReadCondHandleKey<InDet::BeamSpotData> MuonCombined::MuonCandidateTool::m_beamSpotKey {this, "BeamSpotKey", "BeamSpotData", "SG key for beam spot"}
private

Definition at line 47 of file MuonCandidateTool.h.

47{this, "BeamSpotKey", "BeamSpotData", "SG key for beam spot"};

◆ m_commissioning

Gaudi::Property<bool> MuonCombined::MuonCandidateTool::m_commissioning
private
Initial value:
{this, "Commissioning", false,
"Flag deciding whether the candidate belongs to the comissioning."}

Definition at line 56 of file MuonCandidateTool.h.

56 {this, "Commissioning", false,
57 "Flag deciding whether the candidate belongs to the comissioning."};

◆ m_extrapolationStrategy

Gaudi::Property<unsigned int> MuonCombined::MuonCandidateTool::m_extrapolationStrategy {this, "ExtrapolationStrategy", 0}
private

Definition at line 54 of file MuonCandidateTool.h.

54{this, "ExtrapolationStrategy", 0};

◆ m_idHelperSvc

ServiceHandle<Muon::IMuonIdHelperSvc> MuonCombined::MuonCandidateTool::m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}
private

Definition at line 45 of file MuonCandidateTool.h.

45{this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};

◆ m_printer

PublicToolHandle<Muon::MuonEDMPrinterTool> MuonCombined::MuonCandidateTool::m_printer {this, "Printer", "Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"}
private

Definition at line 37 of file MuonCandidateTool.h.

37{this, "Printer", "Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"};

◆ m_segmentKey

SG::ReadHandleKey<Trk::SegmentCollection> MuonCombined::MuonCandidateTool::m_segmentKey {this, "SegmentContainer", ""}
private

Retrieve the segment container to perform the segment association offline.

Definition at line 50 of file MuonCandidateTool.h.

50{this, "SegmentContainer", ""};

◆ m_trackBuilder

ToolHandle<Rec::ICombinedMuonTrackBuilder> MuonCombined::MuonCandidateTool::m_trackBuilder {this, "TrackBuilder", "", ""}
private

Definition at line 38 of file MuonCandidateTool.h.

38{this, "TrackBuilder", "", ""};

◆ m_trackExtrapolationTool

ToolHandle<Muon::IMuonTrackExtrapolationTool> MuonCombined::MuonCandidateTool::m_trackExtrapolationTool
private
Initial value:
{this, "TrackExtrapolationTool",
"ExtrapolateMuonToIPTool/ExtrapolateMuonToIPTool"}

Definition at line 39 of file MuonCandidateTool.h.

39 {this, "TrackExtrapolationTool",
40 "ExtrapolateMuonToIPTool/ExtrapolateMuonToIPTool"};

◆ m_trackSegmentAssociationTool

PublicToolHandle<MuonCombined::IMuonTrackToSegmentAssociationTool> MuonCombined::MuonCandidateTool::m_trackSegmentAssociationTool
private
Initial value:
{
this, "TrackSegmentAssociationTool", "MuonCombined::TrackSegmentAssociationTool/TrackSegmentAssociationTool"}

Definition at line 51 of file MuonCandidateTool.h.

51 {
52 this, "TrackSegmentAssociationTool", "MuonCombined::TrackSegmentAssociationTool/TrackSegmentAssociationTool"};

◆ m_trackSummaryTool

ToolHandle<Trk::IExtendedTrackSummaryTool> MuonCombined::MuonCandidateTool::m_trackSummaryTool {this, "TrackSummaryTool", "MuonTrackSummaryTool"}
private

Definition at line 43 of file MuonCandidateTool.h.

43{this, "TrackSummaryTool", "MuonTrackSummaryTool"};

The documentation for this class was generated from the following files: