ATLAS Offline Software
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"
21 namespace MuonCombined {
22 
23  MuonCombinedTool::MuonCombinedTool(const std::string& type, const std::string& name, const IInterface* 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
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
xAOD::TrackParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TrackParticle_v1.cxx:73
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
Trk::CaloExtension
Tracking class to hold the extrapolation from a particle from the ID to the muon system (or the other...
Definition: CaloExtension.h:18
MuonCombined::MuonCombinedTool::pass_prematching
bool pass_prematching(const MuonCandidate &muonCandidate, const InDetCandidate &idCandidate) const
Definition: MuonCombinedTool.cxx:87
Trk::ParametersBase::position
const Amg::Vector3D & position() const
Access method for the position.
xAODP4Helpers.h
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
CaloExtension.h
MuonCombined::MuonCombinedTool::combine
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.
Definition: MuonCombinedTool.cxx:46
MuonCombined::InDetCandidate
Definition: InDetCandidate.h:18
xAOD::P4Helpers::deltaPhi
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition: xAODP4Helpers.h:69
MuonCombined::MuonCombinedTool::fill_debugging
void fill_debugging(const MuonCandidateCollection &muonCandidates, const InDetCandidateCollection &inDetCandidates) const
Definition: MuonCombinedTool.cxx:27
MuonCombined::MuonCombinedTool::MuonCombinedTool
MuonCombinedTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: MuonCombinedTool.cxx:23
MuonCombined::MuonCombinedTool::initialize
virtual StatusCode initialize() override
Definition: MuonCombinedTool.cxx:33
Trk::CaloExtension::muonEntryLayerIntersection
const TrackParameters * muonEntryLayerIntersection() const
access to intersection with the muon entry layer return NULL if the intersection failed
Definition: CaloExtension.h:70
MuonCombined::MuonCombinedTool::m_deltaPhiPreSelection
Gaudi::Property< float > m_deltaPhiPreSelection
Definition: MuonCombinedTool.h:52
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
MuonCombined::MuonCombinedTool::m_muonCombDebugger
ToolHandle< MuonCombinedDebuggerTool > m_muonCombDebugger
Definition: MuonCombinedTool.h:45
MuonCombined::MuonCombinedTool::m_muonCombinedTagTools
ToolHandleArray< MuonCombined::IMuonCombinedTagTool > m_muonCombinedTagTools
Definition: MuonCombinedTool.h:44
xAOD::TrackParticle_v1::perigeeParameters
const Trk::Perigee & perigeeParameters() const
Returns the Trk::MeasuredPerigee track parameters.
Definition: TrackParticle_v1.cxx:485
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MuonCombined::MuonCandidate
Definition: Reconstruction/MuonIdentification/MuonCombinedEvent/MuonCombinedEvent/MuonCandidate.h:25
P4Helpers::deltaEta
double deltaEta(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition: P4Helpers.h:53
MuonCombined::MuonCombinedDebuggerTool::fillBranches
void fillBranches(const MuonCandidateCollection &muonCandidates, const InDetCandidateCollection &inDetCandidates)
Definition: MuonCombinedDebuggerTool.cxx:139
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
python.xAODType.dummy
dummy
Definition: xAODType.py:4
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::ParametersBase
Definition: ParametersBase.h:55
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
MuonCombinedTool.h
InDetCandidate.h
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
Trk::perigeeParameters
@ perigeeParameters
Definition: MeasurementType.h:19
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
MuonCandidate.h
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonCombined::InDetCandidate::getCaloExtension
const Trk::CaloExtension * getCaloExtension() const
Definition: InDetCandidate.cxx:47
MuonCombined::MuonCandidate::extrapolatedTrack
const Trk::Track * extrapolatedTrack() const
access extrapolated track, can be zero if back extrapolation failed
Definition: Reconstruction/MuonIdentification/MuonCombinedEvent/src/MuonCandidate.cxx:50
Trk::ParametersBase::momentum
const Amg::Vector3D & momentum() const
Access method for the momentum.
MuonCombined::MuonCombinedTool::m_ptBalance
Gaudi::Property< float > m_ptBalance
Definition: MuonCombinedTool.h:53
MuonCombined::InDetCandidate::indetTrackParticle
const xAOD::TrackParticle & indetTrackParticle() const
access TrackParticle
Definition: InDetCandidate.cxx:27
MuonCombined::MuonCombinedTool::associate
void associate(const MuonCandidate &muonCandidate, const InDetCandidateCollection &inDetCandidates, std::vector< const InDetCandidate * > &associatedIdCandidates) const
Definition: MuonCombinedTool.cxx:79
python.BackTrackingConfig.numThreads
int numThreads
Definition: BackTrackingConfig.py:61
MuonCombined::MuonCombinedDebuggerTool
Definition: MuonCombinedDebuggerTool.h:25
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MuonCombined::MuonCombinedTool::m_printer
ToolHandle< Muon::MuonEDMPrinterTool > m_printer
Definition: MuonCombinedTool.h:43
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
MuonCombined
The MuonTagToSegMap is an auxillary construct that links the MuonSegments associated with a combined ...
Definition: IMuonSystemExtensionTool.h:23
MuonCombined::MuonCombinedTool::m_alignUncertTool
PublicToolHandle< Muon::IMuonAlignmentUncertTool > m_alignUncertTool
Use this tool to retrieve the last and first measurments of the ID and MS, respectively.
Definition: MuonCombinedTool.h:49
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
MuonCombined::MuonCombinedTool::m_deltaEtaPreSelection
Gaudi::Property< float > m_deltaEtaPreSelection
Definition: MuonCombinedTool.h:51
xAOD::TrackParticle_v1::track
const Trk::Track * track() const
Returns a pointer (which can be NULL) to the Trk::Track which was used to make this TrackParticle.
Definition: TrackParticle_v1.cxx:805
MuonCombined::MuonCandidate::muonSpectrometerTrack
const Trk::Track & muonSpectrometerTrack() const
access spectrometer track, always there
Definition: Reconstruction/MuonIdentification/MuonCombinedEvent/src/MuonCandidate.cxx:45
MuonCombined::MuonCombinedTool::m_runMuonCombinedDebugger
Gaudi::Property< bool > m_runMuonCombinedDebugger
Definition: MuonCombinedTool.h:55
AthAlgTool
Definition: AthAlgTool.h:26
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.