ATLAS Offline Software
Loading...
Searching...
No Matches
MuonCombinedAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "MuonCombinedAlg.h"
6
8
9using namespace MuonCombined;
10
14 ATH_CHECK(m_combTagMaps.initialize());
15 ATH_CHECK(m_muidCombinedTracks.initialize());
16 ATH_CHECK(m_muidMETracks.initialize());
17 ATH_CHECK(m_printer.retrieve());
19 return StatusCode::SUCCESS;
20}
21
22StatusCode MuonCombinedAlg::execute(const EventContext& ctx) const {
23 const InDetCandidateCollection* inDetCandidates{nullptr};
24 ATH_CHECK(SG::get(inDetCandidates, m_indetCandidateCollectionName, ctx));
25
26 const MuonCandidateCollection* muonCandidates{nullptr};
27 ATH_CHECK(SG::get(muonCandidates, m_muonCandidateCollectionName, ctx));
28
29 std::vector<SG::WriteHandle<MuonCombined::InDetCandidateToTagMap> > tagMaps = m_combTagMaps.makeHandles(ctx);
30 std::vector<MuonCombined::InDetCandidateToTagMap*> maps;
31 for (auto& h : tagMaps) {
32 ATH_CHECK(h.record(std::make_unique<MuonCombined::InDetCandidateToTagMap>()));
33 maps.push_back(h.ptr());
34 }
35
36 SG::WriteHandle muidCombTracks(m_muidCombinedTracks, ctx);
37 ATH_CHECK(muidCombTracks.record(std::make_unique<TrackCollection>()));
38
39 SG::WriteHandle muidMETracks(m_muidMETracks, ctx);
40 ATH_CHECK(muidMETracks.record(std::make_unique<TrackCollection>()));
41
42 if (inDetCandidates->empty() || muonCandidates->empty()) {
43 ATH_MSG_DEBUG(__func__<<"() "<<__LINE__<<" - InDetCandidates "<<inDetCandidates->size()
44 <<", MuonCandidates: "<<muonCandidates->size()<<"... One of them is empty");
45 return StatusCode::SUCCESS;
46 }
47
48 for (const MuonCandidate* muonCandidate : *muonCandidates) {
49 const Trk::Track& muonTrack = muonCandidate->extrapolatedTrack() ?
50 *muonCandidate->extrapolatedTrack() :
51 muonCandidate->muonSpectrometerTrack();
52 ATH_MSG_DEBUG("MuonCandidate " << m_printer->print(muonTrack) << std::endl << m_printer->printStations(muonTrack));
53 // preselect ID candidates close to the muon
54 std::vector<const InDetCandidate*> associatedIdCandidates{};
55 associatedIdCandidates.reserve(inDetCandidates->size());
56 std::copy_if(inDetCandidates->begin(),inDetCandidates->end(), std::back_inserter(associatedIdCandidates),
57 [&](const InDetCandidate* assocMe) {
58 return pass_prematching(*muonCandidate, *assocMe);
59 });
60
61
62 if (associatedIdCandidates.empty()) {
63 continue;
64 }
65 ATH_MSG_DEBUG("Associated ID candidates " << associatedIdCandidates.size());
66 // build combined muons
67 unsigned count{0u};
68 for (const auto& tool : m_muonCombinedTagTools) {
69 tool->combine(*muonCandidate, associatedIdCandidates, *tagMaps.at(count), muidCombTracks.ptr(), muidMETracks.ptr(), ctx);
70 ++count;
71 }
72 }
73 return StatusCode::SUCCESS;
74}
75
76bool MuonCombinedAlg::pass_prematching(const MuonCandidate& muonCandidate, const InDetCandidate& idCandidate) const {
77 const bool hasExtr = muonCandidate.extrapolatedTrack() != nullptr;
78 const Trk::Track* ms_trk = &muonCandidate.muonSpectrometerTrack();
79 const Trk::Track* msoe_trk = muonCandidate.extrapolatedTrack();
80 const Trk::Track* id_trk = idCandidate.indetTrackParticle().track();
81 if (!ms_trk && !msoe_trk) {
82 ATH_MSG_WARNING("Muon candidate without any Trk::Track");
83 return false;
84 }
85
86 const Trk::TrackParameters* muonPars = (msoe_trk ? msoe_trk : ms_trk)->perigeeParameters();
87 if (!muonPars) {
88 ATH_MSG_WARNING("MuonCandidate without Perigee, skipping");
89 return false;
90 }
91
92 const Trk::TrackStateOnSurface *id_exit{nullptr}, *dummy{nullptr}, *ms_entrance{nullptr}, *msoe_entrance{nullptr};
94 const Trk::CaloExtension* calo_extension = idCandidate.getCaloExtension();
95 const Trk::TrackParameters* id_extension = calo_extension ? calo_extension->muonEntryLayerIntersection() : nullptr;
98 if (!m_alignUncertTool.empty()) {
99 if (id_trk && !id_extension) m_alignUncertTool->get_track_state_measures(id_trk, id_exit, dummy, dummy, dummy);
100 if (ms_trk) m_alignUncertTool->get_track_state_measures(ms_trk, dummy, dummy, dummy, ms_entrance);
101 if (msoe_trk) m_alignUncertTool->get_track_state_measures(msoe_trk, dummy, dummy, dummy, msoe_entrance);
102
103 if (!msoe_entrance) msoe_entrance = ms_entrance;
104 if (!ms_entrance) ms_entrance = msoe_entrance;
105 }
106
108 if ((!id_exit && !id_extension) || !ms_entrance) {
111 if (!id_trk) ATH_MSG_WARNING("Trk::Track not found for InDetTrack candidate!");
112 const Amg::Vector3D muon_p3 = hasExtr ? muonPars->momentum() : muonPars->position();
113 const Amg::Vector3D idtr_p3 = idCandidate.indetTrackParticle().perigeeParameters().momentum();
114
115 const double deltaPhi = std::abs(xAOD::P4Helpers::deltaPhi(muon_p3.phi(), idtr_p3.phi()));
116 if (deltaPhi > m_deltaPhiPreSelection) return false;
117
118 const double deltaEta = std::abs(muon_p3.eta() - idtr_p3.eta());
119 if (deltaEta > m_deltaEtaPreSelection) return false;
120
121 const double muonPt = muon_p3.perp();
122 const double indetPt = idtr_p3.perp();
123 const double ptBal = muonPt > 0. ? std::abs(muonPt - indetPt) / muonPt : 1.;
124 if (m_ptBalance > 0. && ptBal > m_ptBalance) return false;
125 } else {
127 const Amg::Vector3D id_ex_pos = (id_extension ? id_extension : id_exit->trackParameters())->position();
128 const Amg::Vector3D ms_en_pos = ms_entrance->trackParameters()->position();
129 const Amg::Vector3D msoe_en_pos = msoe_entrance->trackParameters()->position();
130
131 const double deltaPhi = std::abs(xAOD::P4Helpers::deltaPhi(id_ex_pos.phi(), ms_en_pos.phi()));
132 const double deltaEta = std::abs(id_ex_pos.eta() - ms_en_pos.eta());
133
134 const double deltaPhiMSOE = std::abs(xAOD::P4Helpers::deltaPhi(id_ex_pos.phi(), msoe_en_pos.phi()));
135 const double deltaEtaMSOE = std::abs(id_ex_pos.eta() - msoe_en_pos.eta());
136
141 (deltaPhiMSOE > m_deltaPhiPreSelection || deltaEtaMSOE > m_deltaEtaPreSelection)
142
143 )
144 return false;
145
146 const double muonPt = muonPars->momentum().perp();
147 const double indetPt = idCandidate.indetTrackParticle().pt();
148 const double ptBal = muonPt > 0. ? std::abs(muonPt - indetPt) / muonPt : 1.;
149 if (m_ptBalance > 0. && ptBal > m_ptBalance) return false;
150 }
151
152 return true;
153}
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
DataVector< MuonCombined::InDetCandidate > InDetCandidateCollection
This typedef represents a collection of InDetCandidate objects.
DataVector< MuonCombined::MuonCandidate > MuonCandidateCollection
This typedef represents a collection of MuonCandidate objects.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
PublicToolHandle< Muon::MuonEDMPrinterTool > m_printer
PublicToolHandle< Muon::IMuonAlignmentUncertTool > m_alignUncertTool
Use this tool to retrieve the last and first measurments of the ID and MS, respectively.
SG::ReadHandleKey< MuonCandidateCollection > m_muonCandidateCollectionName
SG::WriteHandleKey< TrackCollection > m_muidMETracks
StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< InDetCandidateCollection > m_indetCandidateCollectionName
Gaudi::Property< float > m_deltaPhiPreSelection
SG::WriteHandleKey< TrackCollection > m_muidCombinedTracks
SG::WriteHandleKeyArray< MuonCombined::InDetCandidateToTagMap > m_combTagMaps
bool pass_prematching(const MuonCombined::MuonCandidate &muonCandidate, const MuonCombined::InDetCandidate &idCandidate) const
Checks whether the Id & the muon candidate are compatible to attempt a combination of the two as a si...
Gaudi::Property< float > m_ptBalance
StatusCode initialize() override
ToolHandleArray< MuonCombined::IMuonCombinedTagTool > m_muonCombinedTagTools
Gaudi::Property< float > m_deltaEtaPreSelection
const Trk::CaloExtension * getCaloExtension() const
const xAOD::TrackParticle & indetTrackParticle() const
access TrackParticle
const Trk::Track & muonSpectrometerTrack() const
access spectrometer track, always there
const Trk::Track * extrapolatedTrack() const
access extrapolated track, can be zero if back extrapolation failed
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
Tracking class to hold the extrapolation through calorimeter Layers Both the caloEntryLayerIntersecti...
const TrackParameters * muonEntryLayerIntersection() const
access to intersection with the muon entry layer return nullptr if the intersection failed
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
represents the track state (measurement, material, fit parameters and quality) at a surface.
const TrackParameters * trackParameters() const
return ptr to trackparameters const overload
const Trk::Perigee & perigeeParameters() const
Returns the Trk::MeasuredPerigee track parameters.
const Trk::Track * track() const
Returns a pointer (which can be NULL) to the Trk::Track which was used to make this TrackParticle.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
Eigen::Matrix< double, 3, 1 > Vector3D
The MuonTagToSegMap is an auxillary construct that links the MuonSegments associated with a combined ...
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
ParametersBase< TrackParametersDim, Charged > TrackParameters
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[