ATLAS Offline Software
Loading...
Searching...
No Matches
MuonCombinedTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6// MuonCombinedTool
7// AlgTool performing MS hit reallocation for a likely spectrometer-indet
8// match which has given combined fit problems.
9// Extrapolates indet track to MS.
10// Returns a combined track with full track fit.
11//
13
14#include "MuonCombinedTool.h"
15
17#include "GaudiKernel/ConcurrencyFlags.h"
21namespace MuonCombined {
22
23 MuonCombinedTool::MuonCombinedTool(const std::string& type, const std::string& name, const IInterface* parent) :
24 AthAlgTool(type, name, parent) {
25 declareInterface<IMuonCombinedTool>(this);
26 }
28 const InDetCandidateCollection& inDetCandidates) const {
29 if (!m_runMuonCombinedDebugger) return;
31 debugger_tool->fillBranches(muonCandidates, inDetCandidates);
32 }
34 ATH_CHECK(m_printer.retrieve());
36 // debug tree, only for running with 1 thread
37 if (Gaudi::Concurrency::ConcurrencyFlags::numThreads() > 1) { m_runMuonCombinedDebugger = false; }
39 ATH_CHECK(m_muonCombDebugger.retrieve());
40 } else
41 m_muonCombDebugger.disable();
42
43 return StatusCode::SUCCESS;
44 }
45
46 void MuonCombinedTool::combine(const MuonCandidateCollection& muonCandidates, const InDetCandidateCollection& inDetCandidates,
47 std::vector<InDetCandidateToTagMap*> tagMaps, TrackCollection* combinedTracks, TrackCollection* METracks,
48 const EventContext& ctx) const {
49 // check that there are tracks in both systems
50 if (inDetCandidates.empty()) return;
51 if (muonCandidates.empty()) return;
52 if (tagMaps.size() != m_muonCombinedTagTools.size()) {
53 ATH_MSG_ERROR("Number of tag maps does not match number of tag tools");
54 return;
55 }
56
57 // debug tree
58 fill_debugging(muonCandidates, inDetCandidates);
59 // loop over muon track particles
60 for (const MuonCandidate* muonCandidate : muonCandidates) {
61 const Trk::Track& muonTrack =
62 muonCandidate->extrapolatedTrack() ? *muonCandidate->extrapolatedTrack() : muonCandidate->muonSpectrometerTrack();
63 ATH_MSG_DEBUG("MuonCandidate " << m_printer->print(muonTrack) << std::endl << m_printer->printStations(muonTrack));
64 // preselect ID candidates close to the muon
65 std::vector<const InDetCandidate*> associatedIdCandidates;
66 associate(*muonCandidate, inDetCandidates, associatedIdCandidates);
67 if (associatedIdCandidates.empty()) continue;
68 ATH_MSG_DEBUG("Associated ID candidates " << associatedIdCandidates.size());
69 // build combined muons
70 int count = 0;
71
72 for (const auto& tool : m_muonCombinedTagTools) {
73 tool->combine(*muonCandidate, associatedIdCandidates, *(tagMaps.at(count)), combinedTracks, METracks, ctx);
74 ++count;
75 }
76 }
77 }
78
79 void MuonCombinedTool::associate(const MuonCandidate& muonCandidate, const InDetCandidateCollection& inDetCandidates,
80 std::vector<const InDetCandidate*>& associatedIdCandidates) const {
81 associatedIdCandidates.clear();
82 for (const InDetCandidate* indetCand : inDetCandidates) {
83 if (!pass_prematching(muonCandidate, *indetCand)) continue;
84 associatedIdCandidates.push_back(indetCand);
85 }
86 }
87 bool MuonCombinedTool::pass_prematching(const MuonCandidate& muonCandidate, const InDetCandidate& idCandidate) const {
88 const bool hasExtr = muonCandidate.extrapolatedTrack() != nullptr;
89 const Trk::Track* ms_trk = &muonCandidate.muonSpectrometerTrack();
90 const Trk::Track* msoe_trk = muonCandidate.extrapolatedTrack();
91 const Trk::Track* id_trk = idCandidate.indetTrackParticle().track();
92 if (!ms_trk && !msoe_trk) {
93 ATH_MSG_WARNING("Muon candidate without any Trk::Track");
94 return false;
95 }
96
97 const Trk::TrackParameters* muonPars = (msoe_trk ? msoe_trk : ms_trk)->perigeeParameters();
98 if (!muonPars) {
99 ATH_MSG_WARNING("MuonCandidate without Perigee, skipping");
100 return false;
101 }
102
103 const Trk::TrackStateOnSurface *id_exit{nullptr}, *dummy{nullptr}, *ms_entrance{nullptr}, *msoe_entrance{nullptr};
105 const Trk::CaloExtension* calo_extension = idCandidate.getCaloExtension();
106 const Trk::TrackParameters* id_extension = calo_extension ? calo_extension->muonEntryLayerIntersection() : nullptr;
109 if (!m_alignUncertTool.empty()) {
110 if (id_trk && !id_extension) m_alignUncertTool->get_track_state_measures(id_trk, id_exit, dummy, dummy, dummy);
111 if (ms_trk) m_alignUncertTool->get_track_state_measures(ms_trk, dummy, dummy, dummy, ms_entrance);
112 if (msoe_trk) m_alignUncertTool->get_track_state_measures(msoe_trk, dummy, dummy, dummy, msoe_entrance);
113
114 if (!msoe_entrance) msoe_entrance = ms_entrance;
115 if (!ms_entrance) ms_entrance = msoe_entrance;
116 }
117
119 if ((!id_exit && !id_extension) || !ms_entrance) {
122 if (!id_trk) ATH_MSG_WARNING("Trk::Track not found for InDetTrack candidate!");
123 const Amg::Vector3D muon_p3 = hasExtr ? muonPars->momentum() : muonPars->position();
124 const Amg::Vector3D idtr_p3 = idCandidate.indetTrackParticle().perigeeParameters().momentum();
125
126 const double deltaPhi = std::abs(xAOD::P4Helpers::deltaPhi(muon_p3.phi(), idtr_p3.phi()));
127 if (deltaPhi > m_deltaPhiPreSelection) return false;
128
129 const double deltaEta = std::abs(muon_p3.eta() - idtr_p3.eta());
130 if (deltaEta > m_deltaEtaPreSelection) return false;
131
132 const double muonPt = muon_p3.perp();
133 const double indetPt = idtr_p3.perp();
134 const double ptBal = muonPt > 0. ? std::abs(muonPt - indetPt) / muonPt : 1.;
135 if (m_ptBalance > 0. && ptBal > m_ptBalance) return false;
136 } else {
138 const Amg::Vector3D id_ex_pos = (id_extension ? id_extension : id_exit->trackParameters())->position();
139 const Amg::Vector3D ms_en_pos = ms_entrance->trackParameters()->position();
140 const Amg::Vector3D msoe_en_pos = msoe_entrance->trackParameters()->position();
141
142 const double deltaPhi = std::abs(xAOD::P4Helpers::deltaPhi(id_ex_pos.phi(), ms_en_pos.phi()));
143 const double deltaEta = std::abs(id_ex_pos.eta() - ms_en_pos.eta());
144
145 const double deltaPhiMSOE = std::abs(xAOD::P4Helpers::deltaPhi(id_ex_pos.phi(), msoe_en_pos.phi()));
146 const double deltaEtaMSOE = std::abs(id_ex_pos.eta() - msoe_en_pos.eta());
147
152 (deltaPhiMSOE > m_deltaPhiPreSelection || deltaEtaMSOE > m_deltaEtaPreSelection)
153
154 )
155 return false;
156
157 const double muonPt = muonPars->momentum().perp();
158 const double indetPt = idCandidate.indetTrackParticle().pt();
159 const double ptBal = muonPt > 0. ? std::abs(muonPt - indetPt) / muonPt : 1.;
160 if (m_ptBalance > 0. && ptBal > m_ptBalance) return false;
161 }
162
163 return true;
164 }
165
166} // namespace MuonCombined
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#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.
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
#define ATLAS_THREAD_SAFE
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
bool empty() const noexcept
Returns true if the collection is empty.
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
void fillBranches(const MuonCandidateCollection &muonCandidates, const InDetCandidateCollection &inDetCandidates)
ToolHandle< MuonCombinedDebuggerTool > m_muonCombDebugger
PublicToolHandle< Muon::MuonEDMPrinterTool > m_printer
Gaudi::Property< bool > m_runMuonCombinedDebugger
virtual StatusCode initialize() override
Gaudi::Property< float > m_ptBalance
Gaudi::Property< float > m_deltaEtaPreSelection
virtual void combine(const MuonCandidateCollection &muonCandidates, const InDetCandidateCollection &inDetCandidates, std::vector< InDetCandidateToTagMap * > tagMaps, TrackCollection *combinedTracks, TrackCollection *METracks, const EventContext &ctx) const override
IMuonCombinedTool interface: build combined muons from ID and MS candidates.
ToolHandleArray< MuonCombined::IMuonCombinedTagTool > m_muonCombinedTagTools
void associate(const MuonCandidate &muonCandidate, const InDetCandidateCollection &inDetCandidates, std::vector< const InDetCandidate * > &associatedIdCandidates) const
bool pass_prematching(const MuonCandidate &muonCandidate, const InDetCandidate &idCandidate) const
Gaudi::Property< float > m_deltaPhiPreSelection
PublicToolHandle< Muon::IMuonAlignmentUncertTool > m_alignUncertTool
Use this tool to retrieve the last and first measurments of the ID and MS, respectively.
MuonCombinedTool(const std::string &type, const std::string &name, const IInterface *parent)
void fill_debugging(const MuonCandidateCollection &muonCandidates, const InDetCandidateCollection &inDetCandidates) const
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:146
Eigen::Matrix< double, 3, 1 > Vector3D
The MuonTagToSegMap is an auxillary construct that links the MuonSegments associated with a combined ...
ParametersBase< TrackParametersDim, Charged > TrackParameters
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[