ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
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. More...
 

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. More...
 
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 
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);
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()) {
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) {
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  }

◆ 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()}));
32  ATH_CHECK(m_ambiguityProcessor.retrieve());
33  ATH_CHECK(m_trackSummaryTool.retrieve());
34  ATH_CHECK(m_idHelperSvc.retrieve());
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  }

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.

◆ 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.

◆ 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.

◆ m_extrapolationStrategy

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

Definition at line 54 of file MuonCandidateTool.h.

◆ m_idHelperSvc

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

Definition at line 45 of file MuonCandidateTool.h.

◆ m_printer

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

Definition at line 37 of file MuonCandidateTool.h.

◆ 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.

◆ m_trackBuilder

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

Definition at line 38 of file MuonCandidateTool.h.

◆ m_trackExtrapolationTool

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

Definition at line 39 of file MuonCandidateTool.h.

◆ 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.

◆ m_trackSummaryTool

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

Definition at line 43 of file MuonCandidateTool.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
MuonCombined::MuonCandidateTool::m_commissioning
Gaudi::Property< bool > m_commissioning
Definition: MuonCandidateTool.h:56
Trk::Track::fitQuality
const FitQuality * fitQuality() const
return a pointer to the fit quality const-overload
MuonCombined::MuonCandidateTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonCandidateTool.h:45
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
Muon::MuonStationIndex
Definition: MuonStationIndex.h:13
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
index
Definition: index.py:1
Trk::Track::info
const TrackInfo & info() const
Returns a const ref to info of a const tracks.
MuonCombined::MuonCandidateTool::m_trackBuilder
ToolHandle< Rec::ICombinedMuonTrackBuilder > m_trackBuilder
Definition: MuonCandidateTool.h:38
Trk::TrackInfo::MuidStandAlone
@ MuidStandAlone
MuidStandalone.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:165
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
Trk::MuonTrackSummary::chamberHitSummary
const std::vector< ChamberHitSummary > & chamberHitSummary() const
access to the vector of chamber hit summaries on the track
Definition: MuonTrackSummary.h:148
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Ringer::EM
@ EM
Definition: CaloRingsDefs.h:19
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::MuonTrackSummary
Detailed track summary for the muon system Give access to hit counts per chamber.
Definition: MuonTrackSummary.h:26
Trk::muon
@ muon
Definition: ParticleHypothesis.h:31
DataVector< Trk::Segment >
postInclude.outputCollection
outputCollection
Definition: postInclude.SortInput.py:27
Trk::Track::perigeeParameters
const Perigee * perigeeParameters() const
return Perigee.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:163
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
MuonCombined::MuonCandidateTool::m_trackSegmentAssociationTool
PublicToolHandle< MuonCombined::IMuonTrackToSegmentAssociationTool > m_trackSegmentAssociationTool
Definition: MuonCandidateTool.h:51
MuonCombined::MuonCandidateTool::m_extrapolationStrategy
Gaudi::Property< unsigned int > m_extrapolationStrategy
Definition: MuonCandidateTool.h:54
DeMoScan.index
string index
Definition: DeMoScan.py:362
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::Track::trackSummary
const Trk::TrackSummary * trackSummary() const
Returns a pointer to the const Trk::TrackSummary owned by this const track (could be nullptr)
MuonCombined::MuonCandidateTool::m_trackExtrapolationTool
ToolHandle< Muon::IMuonTrackExtrapolationTool > m_trackExtrapolationTool
Definition: MuonCandidateTool.h:39
Trk::TrackInfo::setParticleHypothesis
void setParticleHypothesis(const ParticleHypothesis &hypothesis)
Method re-setting the ParticleHypothesis.
Trk::FitQuality::chiSquared
double chiSquared() const
returns the of the overall track fit
Definition: FitQuality.h:56
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
Trk::TrackInfo::setPatternRecognitionInfo
void setPatternRecognitionInfo(const TrackPatternRecoInfo &patternReco)
Method setting the pattern recognition algorithm.
Trk::TrackSummary::muonTrackSummary
const MuonTrackSummary * muonTrackSummary() const
returns a pointer to the MuonTrackSummary if available
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
MuonCombined::MuonCandidateTool::m_segmentKey
SG::ReadHandleKey< Trk::SegmentCollection > m_segmentKey
Retrieve the segment container to perform the segment association offline.
Definition: MuonCandidateTool.h:50
MuonCombined::MuonCandidateTool::m_printer
PublicToolHandle< Muon::MuonEDMPrinterTool > m_printer
Definition: MuonCandidateTool.h:37
MuonCombined::MuonCandidateTool::m_beamSpotKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition: MuonCandidateTool.h:47
MuonCombined::MuonCandidateTool::m_ambiguityProcessor
ToolHandle< Trk::ITrackAmbiguityProcessorTool > m_ambiguityProcessor
Definition: MuonCandidateTool.h:41
Trk::FitQuality::doubleNumberDoF
double doubleNumberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as double
Definition: FitQuality.h:68
MuonCombined::MuonCandidateTool::m_trackSummaryTool
ToolHandle< Trk::IExtendedTrackSummaryTool > m_trackSummaryTool
Definition: MuonCandidateTool.h:43