ATLAS Offline Software
METMuonAssociator.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // METMuonAssociator.cxx
8 // Implementation file for class METMuonAssociator
9 //
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
11 //
12 // Author: P Loch, S Resconi, TJ Khoo, AS Mete
14 
15 // METReconstruction includes
18 
19 // Muon EDM
20 #include "xAODMuon/MuonContainer.h"
21 
22 // Tracking EDM
23 #include "xAODTracking/Vertex.h"
24 
25 
28 
29 namespace met {
30 
31  using namespace xAOD;
32 
33  // Constructors
36  AsgTool(name),
38  {
39  }
40 
41  // Athena algtool's Hooks
44  {
46  ATH_MSG_VERBOSE ("Initializing " << name() << "...");
47  ATH_CHECK( m_muContKey.initialize());
48  if (m_useFELinks) {
51  ATH_CHECK( m_neutralFEReadDecorKey.initialize());
52  ATH_CHECK( m_chargedFEReadDecorKey.initialize());
53  }
54 
56 
57  return StatusCode::SUCCESS;
58  }
59 
60  // executeTool
63  {
64  ATH_MSG_VERBOSE ("In execute: " << name() << "...");
65 
67  if (!muonCont.isValid()) {
68  ATH_MSG_WARNING("Unable to retrieve input muon container " << m_muContKey.key());
69  return StatusCode::FAILURE;
70  }
71 
72  ATH_MSG_DEBUG("Successfully retrieved muon collection");
73  if (fillAssocMap(metMap,muonCont.cptr()).isFailure()) {
74  ATH_MSG_WARNING("Unable to fill map with muon container " << m_muContKey.key());
75  return StatusCode::FAILURE;
76  }
77  return StatusCode::SUCCESS;
78  }
79 
80  //*********************************************************************************************************
81  // Get constituents
83  std::vector<const xAOD::IParticle*>& tclist,
84  const met::METAssociator::ConstitHolder& /*constits*/) const
85  {
86  const xAOD::Muon *mu = static_cast<const xAOD::Muon*>(obj);
87  const CaloCluster* muclus = mu->cluster();
88  if(muclus && m_doMuonClusterMatch) {
89  ATH_MSG_VERBOSE("Muon " << mu->index() << " with pt " << mu->pt()
90  << ", eta " << mu->eta()
91  << ", phi " << mu->phi()
92  << " has cluster with "
93  << "eta " << muclus->calEta()
94  << ", phi " << muclus->calPhi()
95  << ", E " << muclus->calE()
96  << " formed of " << muclus->size() << " cells.");
97  ATH_MSG_VERBOSE("Muon Eloss type: " << mu->energyLossType()
98  << " Eloss: " << mu->floatParameter(xAOD::Muon::EnergyLoss)
99  << " MeasuredEloss: " << mu->floatParameter(xAOD::Muon::MeasEnergyLoss)
100  << " FSR E: " << mu->floatParameter(xAOD::Muon::FSR_CandidateEnergy) );
101 
103  for(const auto& matchel : tcLinkAcc(*muclus)) {
104  if(!matchel.isValid()) {continue;} // In case of thinned cluster collection
105  ATH_MSG_VERBOSE("Tool found cluster " << (*matchel)->index() << " with pt " << (*matchel)->pt() );
106  if((*matchel)->e()>1e-9) { // +ve E
107  tclist.push_back(*matchel);
108  }
109  }
110  } // muon has linked cluster
111 
112  return StatusCode::SUCCESS;
113  }
114 
116  std::vector<const xAOD::IParticle*>& constlist,
117  const met::METAssociator::ConstitHolder& constits) const
118  {
119  const xAOD::Muon *mu = static_cast<const xAOD::Muon*>(obj);
120  const TrackParticle* idtrack = mu->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
121  if(idtrack && acceptTrack(idtrack,constits.pv) && isGoodEoverP(idtrack)) {
122  // if(idtrack && acceptTrack(idtrack,pv)) {
123  ATH_MSG_VERBOSE("Accept muon track " << idtrack << " px, py = " << idtrack->p4().Px() << ", " << idtrack->p4().Py());
124  ATH_MSG_VERBOSE("Muon ID track ptr: " << idtrack);
125  constlist.push_back(idtrack);
126  // if(mu->pt()>10e3 && (mu->muonType()==xAOD::Muon::Combined || mu->muonType()==xAOD::Muon::SegmentTagged)) {
127  // mutracks.push_back(idtrack);
128  // }
129  }
130  return StatusCode::SUCCESS;
131  }
132 
133  //*********************************************************************************************************
134  // Get constituents
136  std::vector<const xAOD::IParticle*>& pfolist,
137  const met::METAssociator::ConstitHolder& constits,
138  std::map<const IParticle*,MissingETBase::Types::constvec_t>& /*momenta*/) const
139  {
140  const xAOD::Muon *mu = static_cast<const xAOD::Muon*>(obj);
141  const TrackParticle* idtrack = mu->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
142  const CaloCluster* muclus = mu->cluster();
143 
144  ATH_MSG_VERBOSE("Muon " << mu->index() << " with pt " << mu->pt()
145  << ", eta " << mu->eta()
146  << ", phi " << mu->phi());
147  if(muclus) {
148  ATH_MSG_VERBOSE(" has cluster with "
149  << "eta " << muclus->calEta()
150  << ", phi " << muclus->calPhi()
151  << ", E " << muclus->calE()
152  << " formed of " << muclus->size() << " cells.");
153  }
154  ATH_MSG_VERBOSE("Muon Eloss type: " << mu->energyLossType()
155  << " Eloss: " << mu->floatParameter(xAOD::Muon::EnergyLoss)
156  << " MeasuredEloss: " << mu->floatParameter(xAOD::Muon::MeasEnergyLoss)
157  << " FSR E: " << mu->floatParameter(xAOD::Muon::FSR_CandidateEnergy) );
158 
159  // One loop over PFOs
160  for(const auto *const pfo : *constits.pfoCont) {
161  if(pfo->isCharged()) {
162  // get charged PFOs by matching the muon ID track
163  // We set a small -ve pt for cPFOs that were rejected
164  // by the ChargedHadronSubtractionTool
165  const static SG::AuxElement::ConstAccessor<char> PVMatchedAcc("matchedToPV");
166  if(idtrack && pfo->track(0) == idtrack && PVMatchedAcc(*pfo) &&
167  ( !m_cleanChargedPFO || isGoodEoverP(pfo->track(0)) )
168  ) {
169  ATH_MSG_VERBOSE("Accept muon PFO " << pfo << " px, py = " << pfo->p4().Px() << ", " << pfo->p4().Py());
170  ATH_MSG_VERBOSE("Muon PFO index: " << pfo->index() << ", pt: " << pfo->pt() << ", eta: " << pfo->eta() << ", phi: " << pfo->phi() );
171  ATH_MSG_VERBOSE("Muon ID Track index: " << idtrack->index() << ", pt: " << idtrack->pt() << ", eta: " << idtrack->eta() << ", phi: " << idtrack->phi() );
172  pfolist.push_back(pfo);
173  break;
174  } // track match
175  } else {
176  // get neutral PFOs by matching the muon cluster
177  if(muclus && m_doMuonClusterMatch) {
178 
180  for(const auto& matchel : tcLinkAcc(*muclus)) {
181  if(!matchel.isValid()) {
182  ATH_MSG_DEBUG("Invalid muon-cluster elementLink");
183  } else {
184  if((*matchel)->e()>FLT_MIN && pfo->cluster(0) == *matchel) { // +ve E && matches cluster
185  ATH_MSG_VERBOSE("Tool found cluster " << (*matchel)->index() << " with pt " << (*matchel)->pt() );
186  pfolist.push_back(pfo);
187  }
188  }
189  }
190  } // muon has linked cluster
191  }
192  } // end of cluster loop
193 
194  return StatusCode::SUCCESS;
195  }
196 
198  std::vector<const xAOD::IParticle*>& felist,
199  const met::METAssociator::ConstitHolder& constits,
200  std::map<const IParticle*,MissingETBase::Types::constvec_t> &/*momenta*/) const
201  {
202  const xAOD::Muon *mu = static_cast<const xAOD::Muon*>(obj);
203 
204  if (m_useFELinks)
205  ATH_CHECK( extractFEsFromLinks(mu, felist,constits) );
206  else
207  ATH_CHECK( extractFEs(mu, felist, constits) );
208 
209  return StatusCode::SUCCESS;
210  }
211 
213  std::vector<const xAOD::IParticle*>& felist,
214  const met::METAssociator::ConstitHolder& constits) const
215  {
216  ATH_MSG_DEBUG("Extract FEs From Links for " << mu->type() << " with pT " << mu->pt());
217 
218  std::vector<FELink_t> nFELinks;
219  std::vector<FELink_t> cFELinks;
220 
223  nFELinks=neutralFEReadDecorHandle(*mu);
224  cFELinks=chargedFEReadDecorHandle(*mu);
225 
226  // Charged FEs
227  for (const FELink_t& feLink : cFELinks) {
228  if (!feLink.isValid()) continue;
229  const xAOD::FlowElement* fe_init = *feLink;
230  for (const auto *const fe : *constits.feCont){
231  if (fe->index() == fe_init->index() && fe->isCharged()){ //index-based match between JetETmiss and CHSFlowElements collections
232  const static SG::AuxElement::ConstAccessor<char> PVMatchedAcc("matchedToPV");
233  if( fe->isCharged() && PVMatchedAcc(*fe)&& ( !m_cleanChargedPFO || isGoodEoverP(static_cast<const xAOD::TrackParticle*>(fe->chargedObject(0))) ) ) {
234  ATH_MSG_DEBUG("Accept cFE with pt " << fe->pt() << ", e " << fe->e() << ", eta " << fe->eta() << ", phi " << fe->phi() );
235  felist.push_back(fe);
236  }
237  }
238  }
239  } // end cFE loop
240 
241  // Neutral FEs
242  for (const FELink_t& feLink : nFELinks) {
243  if (!feLink.isValid()) continue;
244  const xAOD::FlowElement* fe_init = *feLink;
245  for (const auto *const fe : *constits.feCont){
246  if (fe->index() == fe_init->index() && !fe->isCharged()){ //index-based match between JetETmiss and CHSFlowElements collections
247  if( ( !fe->isCharged()&& fe->e() > FLT_MIN ) ){
248  ATH_MSG_DEBUG("Accept nFE with pt " << fe->pt() << ", e " << fe->e() << ", eta " << fe->eta() << ", phi " << fe->phi() << " in sum.");
249  felist.push_back(fe);
250  }
251  }
252  }
253  } // end nFE links loop
254 
255 
256  return StatusCode::SUCCESS;
257  }
258 
260  std::vector<const xAOD::IParticle*>& felist,
261  const met::METAssociator::ConstitHolder& constits) const
262  {
263  const TrackParticle* idtrack = mu->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
264  const CaloCluster* muclus = mu->cluster();
265  ATH_MSG_VERBOSE("Muon " << mu->index() << " with pt " << mu->pt()
266  << ", eta " << mu->eta()
267  << ", phi " << mu->phi());
268  if(muclus) {
269  ATH_MSG_VERBOSE(" has cluster with "
270  << "eta " << muclus->calEta()
271  << ", phi " << muclus->calPhi()
272  << ", E " << muclus->calE()
273  << " formed of " << muclus->size() << " cells.");
274  }
275  ATH_MSG_VERBOSE("Muon Eloss type: " << mu->energyLossType()
276  << " Eloss: " << mu->floatParameter(xAOD::Muon::EnergyLoss)
277  << " MeasuredEloss: " << mu->floatParameter(xAOD::Muon::MeasEnergyLoss)
278  << " FSR E: " << mu->floatParameter(xAOD::Muon::FSR_CandidateEnergy) );
279 
280  // One loop over PFOs
281  for(const xAOD::FlowElement* fe : *constits.feCont) {
282  if(fe->isCharged()) {
283  // get charged FEs by matching the muon ID track
284  // We set a small -ve pt for cPFOs that were rejected
285  // by the ChargedHadronSubtractionTool
286  const static SG::AuxElement::ConstAccessor<char> PVMatchedAcc("matchedToPV");
287  if(idtrack && fe->chargedObject(0) == idtrack && PVMatchedAcc(*fe) &&
288  ( !m_cleanChargedPFO || isGoodEoverP(static_cast<const xAOD::TrackParticle*>(fe->chargedObject(0))) )
289  ) {
290  ATH_MSG_VERBOSE("Accept muon PFO (FE) " << fe << " px, py = " << fe->p4().Px() << ", " << fe->p4().Py());
291  ATH_MSG_VERBOSE("Muon PFO index: " << fe->index() << ", pt: " << fe->pt() << ", eta: " << fe->eta() << ", phi: " << fe->phi() );
292  ATH_MSG_VERBOSE("Muon ID Track index: " << idtrack->index() << ", pt: " << idtrack->pt() << ", eta: " << idtrack->eta() << ", phi: " << idtrack->phi() );
293  felist.push_back(fe);
294  break;
295  } // track match
296  } else {
297  // get neutral PFOs by matching the muon cluster
298  if(muclus && m_doMuonClusterMatch) {
299 
301  for(const auto& matchel : tcLinkAcc(*muclus)) {
302  if(!matchel.isValid()) {
303  ATH_MSG_DEBUG("Invalid muon-cluster elementLink");
304  } else {
305  if((*matchel)->e()>FLT_MIN && fe->otherObject(0) == *matchel) { // +ve E && matches cluster
306  ATH_MSG_VERBOSE("Tool found cluster " << (*matchel)->index() << " with pt " << (*matchel)->pt() );
307  felist.push_back(fe);
308  }
309  }
310  }
311  } // muon has linked cluster
312  }
313  } // end of cluster loop
314 
315  return StatusCode::SUCCESS;
316  }
317 
318 }
xAOD::TrackParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TrackParticle_v1.cxx:73
met::METMuonAssociator::m_neutralFEReadDecorKey
SG::ReadDecorHandleKey< xAOD::MuonContainer > m_neutralFEReadDecorKey
Definition: METMuonAssociator.h:85
met::METMuonAssociator::executeTool
StatusCode executeTool(xAOD::MissingETContainer *metCont, xAOD::MissingETAssociationMap *metMap) const final
Definition: METMuonAssociator.cxx:62
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
met::METAssociator::m_useFELinks
bool m_useFELinks
Definition: METAssociator.h:94
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::TrackParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TrackParticle_v1.cxx:77
xAOD::CaloCluster_v1::calE
flt_t calE() const
Geet Energy in signal state CALIBRATED.
xAOD::CaloCluster_v1::calEta
flt_t calEta() const
Get in signal state CALIBRATED.
met::METAssociator::ConstitHolder::pfoCont
const xAOD::PFOContainer * pfoCont
Definition: METAssociator.h:66
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
met::METAssociator::ConstitHolder::feCont
const xAOD::FlowElementContainer * feCont
Definition: METAssociator.h:67
xAOD::FlowElement_v1::phi
virtual double phi() const override
The azimuthal angle ( ) of the particle.
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
xAOD::FlowElement_v1::pt
virtual double pt() const override
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
xAOD::MissingETAssociationMap_v1
Definition: MissingETAssociationMap_v1.h:29
met::METAssociator::ConstitHolder::pv
const xAOD::Vertex * pv
Definition: METAssociator.h:68
xAOD::FlowElement_v1::isCharged
bool isCharged() const
Definition: FlowElement_v1.cxx:56
xAOD::TrackParticle_v1::p4
virtual FourMom_t p4() const override final
The full 4-momentum of the particle.
Definition: TrackParticle_v1.cxx:129
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
met::METMuonAssociator::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: METMuonAssociator.cxx:43
met
Definition: IMETSignificance.h:24
met::METAssociator::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: METAssociator.cxx:85
met::METMuonAssociator::m_doMuonClusterMatch
Gaudi::Property< bool > m_doMuonClusterMatch
Definition: METMuonAssociator.h:74
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
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
met::METAssociator::m_neutralFELinksKey
std::string m_neutralFELinksKey
Definition: METAssociator.h:89
xAOD::CaloCluster_v1::size
size_t size() const
size method (forwarded from CaloClusterCellLink obj)
Definition: CaloCluster_v1.cxx:996
met::METAssociator::m_chargedFELinksKey
std::string m_chargedFELinksKey
Definition: METAssociator.h:90
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::CaloCluster_v1::calPhi
flt_t calPhi() const
Get in signal state CALIBRATED.
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
met::METMuonAssociator::METMuonAssociator
METMuonAssociator()
Default constructor:
Vertex.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
met::METAssociator
Definition: METAssociator.h:55
xAOD::FlowElement_v1::chargedObject
const xAOD::IParticle * chargedObject(std::size_t i) const
Definition: FlowElement_v1.cxx:127
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
met::METMuonAssociator::extractTracks
StatusCode extractTracks(const xAOD::IParticle *obj, std::vector< const xAOD::IParticle * > &constlist, const met::METAssociator::ConstitHolder &constits) const final
Definition: METMuonAssociator.cxx:115
met::METAssociator::isGoodEoverP
bool isGoodEoverP(const xAOD::TrackParticle *trk) const
Definition: METAssociator.cxx:367
METMuonAssociator.h
met::METMuonAssociator::extractPFO
StatusCode extractPFO(const xAOD::IParticle *obj, std::vector< const xAOD::IParticle * > &pfolist, const met::METAssociator::ConstitHolder &constits, std::map< const xAOD::IParticle *, MissingETBase::Types::constvec_t > &momenta) const final
Definition: METMuonAssociator.cxx:135
met::METAssociator::acceptTrack
bool acceptTrack(const xAOD::TrackParticle *trk, const xAOD::Vertex *pv) const
Definition: METAssociator.cxx:359
met::METMuonAssociator::extractFEs
StatusCode extractFEs(const xAOD::Muon *mu, std::vector< const xAOD::IParticle * > &felist, const met::METAssociator::ConstitHolder &constits) const
Definition: METMuonAssociator.cxx:259
MuonContainer.h
met::METAssociator::fillAssocMap
virtual StatusCode fillAssocMap(xAOD::MissingETAssociationMap *metMap, const xAOD::IParticleContainer *hardObjs) const
Definition: METAssociator.cxx:295
xAOD::FlowElement_v1::eta
virtual double eta() const override
The pseudorapidity ( ) of the particle.
xAOD::FlowElement_v1::p4
virtual FourMom_t p4() const override
The full 4-momentum of the particle.
Definition: FlowElement_v1.cxx:33
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
met::METMuonAssociator::m_chargedFEReadDecorKey
SG::ReadDecorHandleKey< xAOD::MuonContainer > m_chargedFEReadDecorKey
Definition: METMuonAssociator.h:91
met::METMuonAssociator::m_elementLinkName
SG::ReadDecorHandleKey< xAOD::CaloClusterContainer > m_elementLinkName
Definition: METMuonAssociator.h:97
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::FlowElement_v1::otherObject
const xAOD::IParticle * otherObject(std::size_t i) const
Definition: FlowElement_v1.cxx:196
ReadDecorHandle.h
Handle class for reading a decoration on an object.
met::METMuonAssociator::extractFEsFromLinks
StatusCode extractFEsFromLinks(const xAOD::Muon *mu, std::vector< const xAOD::IParticle * > &felist, const met::METAssociator::ConstitHolder &constits) const
Definition: METMuonAssociator.cxx:212
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
met::METMuonAssociator::extractFE
StatusCode extractFE(const xAOD::IParticle *obj, std::vector< const xAOD::IParticle * > &felist, const met::METAssociator::ConstitHolder &constits, std::map< const xAOD::IParticle *, MissingETBase::Types::constvec_t > &momenta) const final
Definition: METMuonAssociator.cxx:197
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
python.PyAthena.obj
obj
Definition: PyAthena.py:135
met::METAssociator::m_cleanChargedPFO
bool m_cleanChargedPFO
Definition: METAssociator.h:109
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
met::METMuonAssociator::m_muContKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muContKey
Definition: METMuonAssociator.h:79
met::METMuonAssociator::extractTopoClusters
StatusCode extractTopoClusters(const xAOD::IParticle *obj, std::vector< const xAOD::IParticle * > &tclist, const met::METAssociator::ConstitHolder &constits) const final
Definition: METMuonAssociator.cxx:82
met::METAssociator::ConstitHolder
Definition: METAssociator.h:62
xAOD::TrackParticle_v1::phi
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .)
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25