ATLAS Offline Software
MuonCombinedStacoTagTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // MuonCombinedStacoTagTool
7 // AlgTool performing statistical combination of ID and MS tracks (STACO)
8 // A StacoTag is added to the InDetCandidate object.
9 //
11 
13 
20 namespace MuonCombined {
21 
22  MuonCombinedStacoTagTool::MuonCombinedStacoTagTool(const std::string& type, const std::string& name, const IInterface* parent) :
24  declareInterface<IMuonCombinedTagTool>(this);
25  }
26 
28  ATH_MSG_INFO("Initializing MuonCombinedStacoTagTool");
29  ATH_CHECK(m_printer.retrieve());
30  ATH_CHECK(m_tagTool.retrieve());
31  ATH_CHECK(m_extrapolator.retrieve());
32  return StatusCode::SUCCESS;
33  }
34 
35  void MuonCombinedStacoTagTool::combine(const MuonCandidate& muonCandidate, const std::vector<const InDetCandidate*>& indetCandidates,
37  const EventContext& ctx) const {
38  if (!combTracks) {
39  ATH_MSG_WARNING("No TrackCollection passed");
40  return;
41  }
42  // only combine if the back extrapolation was successfull
43  if (!muonCandidate.extrapolatedTrack() || !muonCandidate.extrapolatedTrack()->perigeeParameters() ||
44  !muonCandidate.extrapolatedTrack()->perigeeParameters()->covariance())
45  return;
46 
47  std::unique_ptr<const Trk::Perigee> bestPerigee;
48  const InDetCandidate* bestCandidate = nullptr;
49  double bestChi2{FLT_MAX};
50 
51  // loop over ID candidates
52  for (const MuonCombined::InDetCandidate* const idTP : indetCandidates) {
53  // skip tracklets
54  if (idTP->isSiliconAssociated()) continue;
55 
56  // ensure that also the id has a perigee with covariance
57  if (!idTP->indetTrackParticle().perigeeParameters().covariance()) continue;
58 
59  // ensure that id tp can be extrapolated to something
60  const Trk::CaloExtension* caloExtension = idTP->getCaloExtension();
61  if (!caloExtension || caloExtension->caloLayerIntersections().empty()) continue;
62 
63  const Trk::Perigee* idPer = &idTP->indetTrackParticle().perigeeParameters();
64  const Trk::Perigee* msPer = muonCandidate.extrapolatedTrack()->perigeeParameters();
65  std::unique_ptr<const Trk::TrackParameters> exPars;
66  // check that the to perigee surfaces are the same
67  if (idPer->associatedSurface() != msPer->associatedSurface()) {
68  // extrapolate to id surface
69  exPars = m_extrapolator->extrapolateTrack(ctx, *muonCandidate.extrapolatedTrack(), idPer->associatedSurface());
70  if (!exPars) {
71  ATH_MSG_DEBUG("The ID and MS candidates are not expressed at the same surface: id r "
72  << idTP->indetTrackParticle().perigeeParameters().associatedSurface().center().perp() << " z "
73  << idTP->indetTrackParticle().perigeeParameters().associatedSurface().center().z() << " ms r "
74  << muonCandidate.extrapolatedTrack()->perigeeParameters()->associatedSurface().center().perp() << " z "
75  << muonCandidate.extrapolatedTrack()->perigeeParameters()->associatedSurface().center().z()
76  << " and extrapolation failed");
77  continue;
78  }
79  msPer = dynamic_cast<const Trk::Perigee*>(exPars.get());
80  if (!msPer) {
81  ATH_MSG_WARNING("Extrapolation did not return a perigee!");
82  continue;
83  }
84  }
85  double chi2 = 0;
86  std::unique_ptr<const Trk::Perigee> perigee = theCombIdMu(*idPer, *msPer, chi2);
87  if (!perigee || !perigee->covariance() || !Amg::hasPositiveDiagElems(*perigee->covariance())) {
88  ATH_MSG_DEBUG("Combination failed");
89  continue;
90  }
91  if (chi2 < bestChi2) {
92  bestChi2 = chi2;
93  bestPerigee = std::move(perigee);
94  bestCandidate = idTP;
95  }
96  }
97  if (bestCandidate) {
98  const double outerMatchChi2 =
99  m_tagTool->chi2(*bestCandidate->indetTrackParticle().track(), *muonCandidate.extrapolatedTrack(), ctx);
100  ATH_MSG_DEBUG("Combined Muon with ID " << m_printer->print(*bestPerigee) << " match chi2 " << bestChi2 << " outer match "
101  << outerMatchChi2);
102  StacoTag* tag = new StacoTag(muonCandidate, bestPerigee, bestChi2);
103  tagMap.addEntry(bestCandidate, tag);
104  }
105  }
106 
107  std::unique_ptr<Trk::Perigee> MuonCombinedStacoTagTool::theCombIdMu(const Trk::Perigee& indetPerigee, const Trk::Perigee& extrPerigee,
108  double& chi2) const {
109  chi2 = 1e20;
110  if (!indetPerigee.covariance() || !extrPerigee.covariance()) {
111  ATH_MSG_WARNING("Perigee parameters without covariance");
112  return nullptr;
113  }
114 
115  const AmgSymMatrix(5)& covID = *indetPerigee.covariance();
116  const AmgSymMatrix(5) weightID = covID.inverse();
117  if (weightID.determinant() == 0.) {
118  ATH_MSG_DEBUG(" ID weight matrix computation failed ");
119  return nullptr;
120  }
121 
122  const AmgSymMatrix(5)& covMS = *extrPerigee.covariance();
123  const AmgSymMatrix(5) weightMS = covMS.inverse();
124  if (weightMS.determinant() == 0.) {
125  ATH_MSG_DEBUG("weightMS computation failed ");
126  return nullptr;
127  }
128 
129  AmgSymMatrix(5) weightCB = weightID + weightMS;
130 
131  if (weightCB.determinant() == 0) {
132  ATH_MSG_DEBUG(" Inversion of weightCB failed ");
133  return nullptr;
134  }
135  AmgSymMatrix(5) covCB = AmgSymMatrix(5)(weightCB.inverse());
136  if (covCB.determinant() == 0) {
137  ATH_MSG_DEBUG(" Inversion of weightCB failed ");
138  return nullptr;
139  }
140 
141  AmgSymMatrix(5) covSum = covID + covMS;
142  AmgSymMatrix(5) invCovSum = covSum.inverse();
143 
144  if (invCovSum.determinant() == 0) {
145  ATH_MSG_DEBUG(" Inversion of covSum failed ");
146  return nullptr;
147  }
148 
149  AmgVector(5) parsMS(extrPerigee.parameters());
150 
151  AmgVector(5) diffPars = indetPerigee.parameters() - parsMS;
152  chi2 = (diffPars.transpose() * invCovSum * diffPars);
153  chi2 /= 5.;
154 
155  AmgVector(5) parsCB = (covCB) * (weightID * indetPerigee.parameters() + weightMS * parsMS);
156 
157  parsCB[Trk::phi] = xAOD::P4Helpers::deltaPhi(parsCB[Trk::phi], 0.);
158  return indetPerigee.associatedSurface().createUniqueParameters<5, Trk::Charged>(
159  parsCB[Trk::locX], parsCB[Trk::locY], parsCB[Trk::phi], parsCB[Trk::theta], parsCB[Trk::qOverP], covCB);
160  }
161 
162 } // namespace MuonCombined
Amg::hasPositiveDiagElems
bool hasPositiveDiagElems(const AmgSymMatrix(N) &mat)
Returns true if all diagonal elements of the covariance matrix are finite aka sane in the above defin...
Definition: EventPrimitivesCovarianceHelpers.h:96
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::locX
@ locX
Definition: ParamDefs.h:43
Trk::locY
@ locY
local cartesian
Definition: ParamDefs.h:44
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::InDetCandidateToTagMap
Definition: InDetCandidateToTagMap.h:15
xAODP4Helpers.h
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
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::StacoTag
TagBase implementation for a combined fit.
Definition: StacoTag.h:22
MuonCombined::MuonCombinedStacoTagTool::theCombIdMu
std::unique_ptr< Trk::Perigee > theCombIdMu(const Trk::Perigee &indetPerigee, const Trk::Perigee &extrPerigee, double &chi2) const
Definition: MuonCombinedStacoTagTool.cxx:107
AmgSymMatrix
#define AmgSymMatrix(dim)
Definition: EventPrimitives.h:52
Trk::Charged
Definition: Charged.h:27
MuonCombined::MuonCombinedStacoTagTool::m_printer
ToolHandle< Muon::MuonEDMPrinterTool > m_printer
Definition: MuonCombinedStacoTagTool.h:42
Trk::ParametersT::associatedSurface
virtual const S & associatedSurface() const override final
Access to the Surface method.
MuonCombined::InDetCandidateToTagMap::addEntry
void addEntry(const InDetCandidate *idcand, TagBase *tag)
Definition: InDetCandidateToTagMap.cxx:8
MuonCombined::MuonCandidate
Definition: Reconstruction/MuonIdentification/MuonCombinedEvent/MuonCombinedEvent/MuonCandidate.h:25
Trk::theta
@ theta
Definition: ParamDefs.h:72
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
AmgVector
AmgVector(4) T2BSTrackFilterTool
Definition: T2BSTrackFilterTool.cxx:114
MuonCombined::MuonCombinedStacoTagTool::m_extrapolator
ToolHandle< Trk::IExtrapolator > m_extrapolator
Definition: MuonCombinedStacoTagTool.h:44
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector< Trk::Track >
InDetCandidate.h
InDetCandidateToTagMap.h
Trk::Track::perigeeParameters
const Perigee * perigeeParameters() const
return Perigee.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:163
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
MuonCombined::MuonCombinedStacoTagTool::initialize
virtual StatusCode initialize() override
Definition: MuonCombinedStacoTagTool.cxx:27
MuonCandidate.h
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
EventPrimitivesCovarianceHelpers.h
MuonCombined::InDetCandidate::indetTrackParticle
const xAOD::TrackParticle & indetTrackParticle() const
access TrackParticle
Definition: InDetCandidate.cxx:27
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MuonCombined::MuonCombinedStacoTagTool::combine
virtual void combine(const MuonCandidate &muonCandidate, const std::vector< const InDetCandidate * > &indetCandidates, InDetCandidateToTagMap &tagMap, TrackCollection *combTracks, TrackCollection *METracks, const EventContext &ctx) const override
IMuonCombinedTagTool interface: build combined muons from a muon and a vector of indet candidates.
Definition: MuonCombinedStacoTagTool.cxx:35
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
Trk::qOverP
@ qOverP
perigee
Definition: ParamDefs.h:73
Trk::phi
@ phi
Definition: ParamDefs.h:81
StacoTag.h
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
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
Trk::CaloExtension::caloLayerIntersections
const std::vector< CurvilinearParameters > & caloLayerIntersections() const
access to the intersections with the calorimeter layers.
Definition: CaloExtension.h:76
AthAlgTool
Definition: AthAlgTool.h:26
MuonCombined::MuonCombinedStacoTagTool::MuonCombinedStacoTagTool
MuonCombinedStacoTagTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: MuonCombinedStacoTagTool.cxx:22
MuonCombined::MuonCombinedStacoTagTool::m_tagTool
ToolHandle< MuonCombined::IMuonTrackTagTool > m_tagTool
Definition: MuonCombinedStacoTagTool.h:43
MuonCombinedStacoTagTool.h