ATLAS Offline Software
METTauAssociator.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 // METTauAssociator.cxx
8 // Implementation file for class METTauAssociator
9 //
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
11 //
12 // Author: P Loch, S Resconi, TJ Khoo, AS Mete
14 
15 // METReconstruction includes
17 
18 // MET EDM
20 
21 // Tau EDM
23 #include "xAODTau/TauTrack.h"
24 #include "xAODTau/TauxAODHelpers.h"
25 
26 // Tracking EDM
27 #include "xAODTracking/Vertex.h"
28 
29 // DeltaR calculation
31 
35 
36 
39 
40 namespace met {
41 
42  using namespace xAOD;
43 
44  // Constructors
47  AsgTool(name),
49  {
50  }
51 
52  // Athena algtool's Hooks
55  {
57 
58  ATH_MSG_VERBOSE ("Initializing " << name() << "...");
59  ATH_CHECK( m_tauContKey.initialize());
60 
61  if (m_useFELinks) {
64  ATH_CHECK( m_neutralFEReadDecorKey.initialize());
65  ATH_CHECK( m_chargedFEReadDecorKey.initialize());
66  }
67 
68  return StatusCode::SUCCESS;
69  }
70 
71  // executeTool
74  {
75  ATH_MSG_VERBOSE ("In execute: " << name() << "...");
76 
78  if (!tauCont.isValid()) {
79  ATH_MSG_WARNING("Unable to retrieve input tau container " << m_tauContKey.key());
80  return StatusCode::FAILURE;
81  }
82 
83  ATH_MSG_DEBUG("Successfully retrieved tau collection");
84  if (fillAssocMap(metMap,tauCont.cptr()).isFailure()) {
85  ATH_MSG_WARNING("Unable to fill map with tau container " << m_tauContKey.key());
86  return StatusCode::FAILURE;
87  }
88  return StatusCode::SUCCESS;
89  }
90 
91 
92  //*********************************************************************************************************
93  // Get tau constituents
95  std::vector<const xAOD::IParticle*>& tclist,
96  const met::METAssociator::ConstitHolder& /*tcCont*/) const
97  {
98  const TauJet* tau = static_cast<const TauJet*>(obj);
99  TLorentzVector tauAxis = tauRecTools::getTauAxis(*tau);
100  const xAOD::Vertex* tauVertex = tau->vertex();
101 
102  auto clusterList = tau->clusters();
103  for (const xAOD::IParticle* particle : clusterList) {
104  const xAOD::CaloCluster* cluster = static_cast<const xAOD::CaloCluster*>(particle);
105 
106  TLorentzVector clusterP4 = cluster->p4();
107 
108  // Correct the four momentum to point at the tau vertex
109  if (tauVertex) {
110  xAOD::CaloVertexedTopoCluster vertexedCluster(*cluster, tauVertex->position());
111  clusterP4 = vertexedCluster.p4();
112  }
113 
114  if (clusterP4.DeltaR(tauAxis) > 0.2) continue;
115 
116  tclist.push_back(particle);
117  }
118 
119  return StatusCode::SUCCESS;
120  }
121 
122 
124  std::vector<const xAOD::IParticle*>& constlist,
125  const met::METAssociator::ConstitHolder& constits) const
126  {
127  const TauJet* tau = static_cast<const TauJet*>(obj);
128  for( const xAOD::TauTrack* tauTrk : tau->tracks(xAOD::TauJetParameters::coreTrack) ){//all tracks dR<0.2 regardless of quality
129  if(tauTrk->trackLinks().empty() || !tauTrk->trackLinks().at(0).isValid()){
130  ATH_MSG_DEBUG("Skipping absent tau track, probably thinned");
131  continue;
132  }
133  const TrackParticle* trk = tauTrk->track();
134  if(acceptTrack(trk,constits.pv) && isGoodEoverP(trk) ){
135  ATH_MSG_VERBOSE("Accept tau track " << trk << " px, py = " << trk->p4().Px() << ", " << trk->p4().Py());
136  constlist.push_back(trk);
137  }
138  }
139 
140  return StatusCode::SUCCESS;
141  }
142  //*********************************************************************************************************
143  // Get tau constituents
145  std::vector<const xAOD::IParticle*>& pfolist,
146  const met::METAssociator::ConstitHolder& constits,
147  std::map<const IParticle*,MissingETBase::Types::constvec_t> &/*momenta*/) const
148  {
149  const TauJet* tau = static_cast<const TauJet*>(obj);
150  const Jet* seedjet = *tau->jetLink();
151  TLorentzVector momentum;
152  for(const auto *const pfo : *constits.pfoCont) {
153  bool match = false;
154  if (!pfo->isCharged()) {
155  if(xAOD::P4Helpers::isInDeltaR(*seedjet,*pfo,0.2,m_useRapidity) && pfo->eEM()>0) {
156  ATH_MSG_VERBOSE("Found nPFO with dR " << seedjet->p4().DeltaR(pfo->p4EM()));
157  match = true;
158  }
159  }
160  else {
161  const TrackParticle* pfotrk = pfo->track(0);
162  for( const xAOD::TauTrack* ttrk : tau->tracks(xAOD::TauJetParameters::coreTrack) ){//all tracks <0.2, no quality
163  if(ttrk->trackLinks().empty() || !ttrk->trackLinks().at(0).isValid()){
164  ATH_MSG_DEBUG("Skipping absent tau track, probably thinned");
165  continue;
166  }
167  const TrackParticle* tautrk = ttrk->track();
168  if(tautrk==pfotrk) {
169  ATH_MSG_VERBOSE("Found cPFO with dR " << seedjet->p4().DeltaR(ttrk->p4()));
170  // We set a small -ve pt for cPFOs that were rejected
171  // by the ChargedHadronSubtractionTool
172  const static SG::AuxElement::ConstAccessor<char> PVMatchedAcc("matchedToPV");
173  if(PVMatchedAcc(*pfo) && ( !m_cleanChargedPFO || isGoodEoverP(pfotrk) )) match = true;
174  }
175  }
176  }
177  if(match) {
178  pfolist.push_back(pfo);
179  }
180  }
181  return StatusCode::SUCCESS;
182  }
183 
185  std::vector<const xAOD::IParticle*>& felist,
186  const met::METAssociator::ConstitHolder& constits,
187  std::map<const IParticle*,MissingETBase::Types::constvec_t> &/*momenta*/) const
188  {
189  const TauJet* tau = static_cast<const TauJet*>(obj);
190  if (m_useFELinks)
191  ATH_CHECK( extractFEsFromLinks(tau, felist,constits) );
192  else
193  ATH_CHECK( extractFEs(tau, felist, constits) );
194 
195  return StatusCode::SUCCESS;
196  }
197 
198 
200  std::vector<const xAOD::IParticle*>& felist,
201  const met::METAssociator::ConstitHolder& constits) const
202  {
203 
204  ATH_MSG_DEBUG("Extract FEs From Links for " << tau->type() << " with pT " << tau->pt());
205 
206  std::vector<FELink_t> nFELinks;
207  std::vector<FELink_t> cFELinks;
208 
211  nFELinks=neutralFEReadDecorHandle(*tau);
212  cFELinks=chargedFEReadDecorHandle(*tau);
213 
214  // Charged FEs
215  for (const FELink_t& feLink : cFELinks) {
216  if (!feLink.isValid()) continue;
217  const xAOD::FlowElement* fe_init = *feLink;
218  for (const auto *const fe : *constits.feCont){
219  if (fe->index() == fe_init->index() && fe->isCharged()){ //index-based match between JetETmiss and CHSFlowElements collections
220  const static SG::AuxElement::ConstAccessor<char> PVMatchedAcc("matchedToPV");
221  if( fe->isCharged() && PVMatchedAcc(*fe)&& ( !m_cleanChargedPFO || isGoodEoverP(static_cast<const xAOD::TrackParticle*>(fe->chargedObject(0))) ) ) {
222  ATH_MSG_DEBUG("Accept cFE with pt " << fe->pt() << ", e " << fe->e() << ", eta " << fe->eta() << ", phi " << fe->phi() );
223  felist.push_back(fe);
224  }
225  }
226  }
227  } // end cFE loop
228 
229  // Neutral FEs
230  for (const FELink_t& feLink : nFELinks) {
231  if (!feLink.isValid()) continue;
232  const xAOD::FlowElement* fe_init = *feLink;
233  for (const auto *const fe : *constits.feCont){
234  if (fe->index() == fe_init->index() && !fe->isCharged()){ //index-based match between JetETmiss and CHSFlowElements collections
235  if( ( !fe->isCharged()&& fe->e() > FLT_MIN ) ){
236  ATH_MSG_DEBUG("Accept nFE with pt " << fe->pt() << ", e " << fe->e() << ", eta " << fe->eta() << ", phi " << fe->phi() << " in sum.");
237  felist.push_back(fe);
238  }
239  }
240  }
241  } // end nFE links loop
242 
243 
244  return StatusCode::SUCCESS;
245 
246  }
247 
248 
250  std::vector<const xAOD::IParticle*>& felist,
251  const met::METAssociator::ConstitHolder& constits) const
252  {
253  //const TauJet* tau = static_cast<const TauJet*>(obj);
254  if(!tau->jetLink().isValid()){
255  ATH_MSG_ERROR("Tau seed jet link is invalid. Cannot extract FlowElements.");
256  return StatusCode::FAILURE;
257  }
258  const Jet* seedjet = *tau->jetLink();
259  TLorentzVector momentum;
260  for(const xAOD::FlowElement* pfo : *constits.feCont) {
261  bool match = false;
262  if (!pfo->isCharged()) {
263  if(xAOD::P4Helpers::isInDeltaR(*seedjet,*pfo,0.2,m_useRapidity) && pfo->e()>0) {
264  ATH_MSG_VERBOSE("Found nPFO with dR " << seedjet->p4().DeltaR(pfo->p4()));
265  match = true;
266  }
267  }
268  else {
269  const TrackParticle* pfotrk = static_cast<const xAOD::TrackParticle*>(pfo->chargedObject(0));
270  for( const xAOD::TauTrack* ttrk : tau->tracks(xAOD::TauJetParameters::coreTrack) ){//all tracks <0.2, no quality
271  if(ttrk->trackLinks().empty() || !ttrk->trackLinks().at(0).isValid()){
272  ATH_MSG_DEBUG("Skipping absent tau track, probably thinned");
273  continue;
274  }
275  const TrackParticle* tautrk = ttrk->track();
276  if(tautrk==pfotrk) {
277  ATH_MSG_VERBOSE("Found cPFO with dR " << seedjet->p4().DeltaR(ttrk->p4()));
278  // We set a small -ve pt for cPFOs that were rejected
279  // by the ChargedHadronSubtractionTool
280  const static SG::AuxElement::ConstAccessor<char> PVMatchedAcc("matchedToPV");
281  if(PVMatchedAcc(*pfo) && ( !m_cleanChargedPFO || isGoodEoverP(pfotrk) )) match = true;
282  }
283  }
284  }
285  if(match) {
286  felist.push_back(pfo);
287  }
288  }
289  return StatusCode::SUCCESS;
290  }
291 
292 
293 }
xAOD::CaloVertexedClusterBase::p4
virtual FourMom_t p4() const final
The full 4-momentum of the particle.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloVertexedClusterBase.h:88
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
met::METTauAssociator::extractTopoClusters
StatusCode extractTopoClusters(const xAOD::IParticle *obj, std::vector< const xAOD::IParticle * > &tclist, const met::METAssociator::ConstitHolder &constits) const final
Definition: METTauAssociator.cxx:94
met::METTauAssociator::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: METTauAssociator.cxx:54
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
xAODP4Helpers.h
tauRecTools::getTauAxis
TLorentzVector getTauAxis(const xAOD::TauJet &tau, bool doVertexCorrection=true)
Return the four momentum of the tau axis The tau axis is widely used to select clusters and cells in ...
Definition: Reconstruction/tauRecTools/Root/HelperFunctions.cxx:33
met::METTauAssociator::m_chargedFEReadDecorKey
SG::ReadDecorHandleKey< xAOD::TauJetContainer > m_chargedFEReadDecorKey
Definition: METTauAssociator.h:83
xAOD::TauJet_v3::type
virtual Type::ObjectType type() const
The type of the object as a simple enumeration.
Definition: TauJet_v3.cxx:232
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::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
IWeightPFOTool.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
met::METTauAssociator::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: METTauAssociator.cxx:144
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
met::METAssociator::m_useRapidity
bool m_useRapidity
Definition: METAssociator.h:105
xAOD::MissingETAssociationMap_v1
Definition: MissingETAssociationMap_v1.h:29
xAOD::TauJet_v3::clusters
std::vector< const IParticle * > clusters() const
Definition: TauJet_v3.cxx:585
met::METAssociator::ConstitHolder::pv
const xAOD::Vertex * pv
Definition: METAssociator.h:68
met::METTauAssociator::extractFEs
StatusCode extractFEs(const xAOD::TauJet *tau, std::vector< const xAOD::IParticle * > &felist, const met::METAssociator::ConstitHolder &constits) const
Definition: METTauAssociator.cxx:249
xAOD::TauJet_v3::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
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::METTauAssociator::m_neutralFEReadDecorKey
SG::ReadDecorHandleKey< xAOD::TauJetContainer > m_neutralFEReadDecorKey
Definition: METTauAssociator.h:82
met
Definition: IMETSignificance.h:24
met::METAssociator::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: METAssociator.cxx:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
met::METTauAssociator::executeTool
StatusCode executeTool(xAOD::MissingETContainer *metCont, xAOD::MissingETAssociationMap *metMap) const final
Definition: METTauAssociator.cxx:73
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
met::METTauAssociator::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: METTauAssociator.cxx:184
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TauxAODHelpers.h
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
xAOD::TauJet_v3::jetLink
const JetLink_t & jetLink() const
met::METAssociator::m_neutralFELinksKey
std::string m_neutralFELinksKey
Definition: METAssociator.h:89
met::METAssociator::m_chargedFELinksKey
std::string m_chargedFELinksKey
Definition: METAssociator.h:90
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::TauJetParameters::coreTrack
@ coreTrack
Definition: TauDefs.h:403
TauJetContainer.h
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
Vertex.h
met::METTauAssociator::METTauAssociator
METTauAssociator()
Default constructor:
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::CaloCluster_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: CaloCluster_v1.cxx:465
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:221
xAOD::FlowElement_v1::e
virtual double e() const override
The total energy of the particle.
Definition: FlowElement_v1.cxx:25
met::METAssociator::isGoodEoverP
bool isGoodEoverP(const xAOD::TrackParticle *trk) const
Definition: METAssociator.cxx:367
TauTrack.h
CaloVertexedTopoCluster.h
Evaluate cluster kinematics with a different vertex / signal state.
met::METAssociator::acceptTrack
bool acceptTrack(const xAOD::TrackParticle *trk, const xAOD::Vertex *pv) const
Definition: METAssociator.cxx:359
met::METTauAssociator::extractFEsFromLinks
StatusCode extractFEsFromLinks(const xAOD::TauJet *tau, std::vector< const xAOD::IParticle * > &felist, const met::METAssociator::ConstitHolder &constits) const
Definition: METTauAssociator.cxx:199
met::METAssociator::fillAssocMap
virtual StatusCode fillAssocMap(xAOD::MissingETAssociationMap *metMap, const xAOD::IParticleContainer *hardObjs) const
Definition: METAssociator.cxx:295
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
met::METTauAssociator::m_tauContKey
SG::ReadHandleKey< xAOD::TauJetContainer > m_tauContKey
Definition: METTauAssociator.h:81
xAOD::Jet_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: Jet_v1.cxx:71
xAOD::FlowElement_v1::p4
virtual FourMom_t p4() const override
The full 4-momentum of the particle.
Definition: FlowElement_v1.cxx:33
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
xAOD::TauJet_v3::vertex
const Vertex * vertex() const
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::TauTrack_v1
Definition: TauTrack_v1.h:27
met::METTauAssociator::extractTracks
StatusCode extractTracks(const xAOD::IParticle *obj, std::vector< const xAOD::IParticle * > &constlist, const met::METAssociator::ConstitHolder &constits) const final
Definition: METTauAssociator.cxx:123
HelperFunctions.h
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
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
xAOD::P4Helpers::isInDeltaR
bool isInDeltaR(const xAOD::IParticle &p1, const xAOD::IParticle &p2, double dR, bool useRapidity=true)
Check if 2 xAOD::IParticle are in a cone.
Definition: xAODP4Helpers.h:174
xAOD::CaloVertexedTopoCluster
Evaluate cluster kinematics with a different vertex / signal state.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloVertexedTopoCluster.h:38
python.PyAthena.obj
obj
Definition: PyAthena.py:132
met::METAssociator::m_cleanChargedPFO
bool m_cleanChargedPFO
Definition: METAssociator.h:109
METTauAssociator.h
xAOD::TauJet_v3::tracks
std::vector< const TauTrack * > tracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Get the v<const pointer> to a given tauTrack collection associated with this tau.
Definition: TauJet_v3.cxx:493
MissingETComposition.h
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
met::METAssociator::ConstitHolder
Definition: METAssociator.h:62
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25