ATLAS Offline Software
PFTauFlowElementAssoc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "xAODTau/TauTrack.h"
10 
13 
15  ISvcLocator* pSvcLocator): AthReentrantAlgorithm(name, pSvcLocator)
16 {}
17 
19 
21 
22  ATH_MSG_DEBUG("Initializing" << name() << "...");
23 
28 
29  ATH_CHECK(m_tauJetReadHandleKey.initialize());
30  ATH_CHECK(m_neutralFEReadHandleKey.initialize());
31  ATH_CHECK(m_chargedFEReadHandleKey.initialize());
32 
33  if (!m_jetReadHandleKey.empty()) ATH_CHECK(m_jetReadHandleKey.initialize());
34 
35  ATH_MSG_DEBUG("Initialization completed successfully");
36 
37  return StatusCode::SUCCESS;
38 }
39 
50 StatusCode PFTauFlowElementAssoc::execute(const EventContext &ctx) const {
51 
52  // Write decoration handles for linking the TauJet container with the FlowElement container and vice versa
57  // Read handles for the TauJet container and the FlowElement container
61 
62  // Initialize flow element link containers
63  std::vector<std::vector<FELink_t>> tauNeutralFEVec(tauJetReadHandle->size());
64  std::vector<std::vector<FELink_t>> tauChargedFEVec(tauJetReadHandle->size());
65 
66  static const SG::AuxElement::ConstAccessor<char> acc_passThinning("passThinning");
67 
69  // Loop over the neutral flow elements
71  for (const xAOD::FlowElement* FE : *neutralFETauWriteDecorHandle) {
72  // Check that the flow element cluster exists and is not null
73  if (FE->otherObjects().empty()) continue;
74  if (FE->otherObjects().at(0) == nullptr) continue;
75  // Get the index of the flow element cluster
76  size_t FEClusterIndex = FE->otherObjects().at(0)->index();
77 
78  std::vector<TauJetLink_t> FETauJetLinks;
79 
80  // Loop over the taus
81  for (const xAOD::TauJet* tau : *tauNeutralFEWriteDecorHandle) {
82  // Skip taus that won't be written to AOD - first check the variable exists
83  // because older ESD and any AOD used as input do not have this variable.
84  if(acc_passThinning.isAvailable(*tau) && !acc_passThinning(*tau)) continue;
85  // Get tau vertex
86  const xAOD::Vertex* tauVertex = tau->vertex();
87  // Get the clusters associated to the tau
88  std::vector<const xAOD::IParticle*> tauClusters = tau->clusters();
89  for (const auto *cluster : tauClusters) {
90  const xAOD::CaloCluster* clus = static_cast<const xAOD::CaloCluster*>(cluster);
91  TLorentzVector clusterp4 = clus->p4();
92  // Correct cluster to tau vertex if it exists
93  if (tauVertex != nullptr) {
94  xAOD::CaloVertexedTopoCluster vertexedClus(*clus, tauVertex->position());
95  clusterp4 = vertexedClus.p4();
96  }
97  // Check if the cluster is within R = 0.2 of tau axis
98  if (clusterp4.DeltaR(tau->p4(xAOD::TauJetParameters::IntermediateAxis)) > 0.2) continue;
99  // Get the index of the cluster associated to the tau
100  size_t tauClusterIndex = clus->index();
101 
102  // Link the tau and the neutral FE if the cluster indices match
103  if (tauClusterIndex == FEClusterIndex) {
104  FETauJetLinks.emplace_back(*tauJetReadHandle,tau->index() );
105  tauNeutralFEVec.at(tau->index()).emplace_back(*neutralFEReadHandle, FE->index() );
106  }
107 
108  } // end tau cluster loop
109  } // end tau loop
110 
111  // Add vector of elements links to the tau jets as a decoration to the FE container
112  neutralFETauWriteDecorHandle (*FE) = FETauJetLinks;
113 
114  } // end neutral FE loop
115 
117  // Loop over the charged flow elements
119  for (const xAOD::FlowElement* FE : *chargedFETauWriteDecorHandle) {
120  // Check that the flow element track exists and is not null
121  if (FE->chargedObjects().empty()) continue;
122  if (FE->chargedObjects().at(0) == nullptr) continue;
123 
124  // Get the index of the flow element track
125  size_t FETrackIndex = FE->chargedObjects().at(0)->index();
126 
127  std::vector<TauJetLink_t> FETauJetLinks;
128 
129  // Loop over the taus
130  for (const xAOD::TauJet* tau : *tauChargedFEWriteDecorHandle) {
131  // Skip taus that won't be written to AOD - first check the variable exists
132  // because older ESD and any AOD used as input do not have this variable.
133  if(acc_passThinning.isAvailable(*tau) && !acc_passThinning(*tau)) continue;
134  // Get tau tracks associated to the tau
135  std::vector<const xAOD::TauTrack*> tauTracks = tau->tracks();
136  for (const auto *tauTrack : tauTracks) {
137  // Get track associated to the tau track to use for matching
138  const xAOD::TrackParticle* tauIDTrack = tauTrack->track();
139  // Get the index of the track associated to the tau
140  size_t tauIDTrackIndex = tauIDTrack->index();
141 
142  // Link the tau and the charged FE if the track indices match
143  if (tauIDTrackIndex == FETrackIndex) {
144  FETauJetLinks.emplace_back(*tauJetReadHandle,tau->index() );
145  tauChargedFEVec.at(tau->index()).emplace_back(*chargedFEReadHandle, FE->index() );
146  }
147  } // end tau track loop
148  } // end tau loop
149 
150  // Add vector of elements links to the tau jets as a decoration to the FE container
151  chargedFETauWriteDecorHandle (*FE) = FETauJetLinks;
152 
153  } // end charged FE loop
154 
156  // Write decorations to TauJet container
158  // Add vectors of Flow Element (FE) Links as decorations to the TauJet container
159  for (const xAOD::TauJet* tau : *tauNeutralFEWriteDecorHandle) {
160  tauNeutralFEWriteDecorHandle (*tau) = tauNeutralFEVec.at(tau->index());
161  tauChargedFEWriteDecorHandle (*tau) = tauChargedFEVec.at(tau->index());
162  }
163 
164  ATH_MSG_DEBUG("Execute completed successfully");
165 
166  return StatusCode::SUCCESS;
167 }
PFTauFlowElementAssoc::~PFTauFlowElementAssoc
virtual ~PFTauFlowElementAssoc()
xAOD::CaloVertexedClusterBase::p4
virtual FourMom_t p4() const final
The full 4-momentum of the particle.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloVertexedClusterBase.h:88
FlowElementContainer.h
xAOD::TauJetParameters::IntermediateAxis
@ IntermediateAxis
Definition: TauDefs.h:338
PFTauFlowElementAssoc.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
PFTauFlowElementAssoc::PFTauFlowElementAssoc
PFTauFlowElementAssoc(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PFTauFlowElementAssoc.cxx:14
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
PFTauFlowElementAssoc::initialize
virtual StatusCode initialize()
Definition: PFTauFlowElementAssoc.cxx:20
PFTauFlowElementAssoc::m_jetReadHandleKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetReadHandleKey
Definition: PFTauFlowElementAssoc.h:65
PFTauFlowElementAssoc::m_neutralFEReadHandleKey
SG::ReadHandleKey< xAOD::FlowElementContainer > m_neutralFEReadHandleKey
Definition: PFTauFlowElementAssoc.h:53
PFTauFlowElementAssoc::m_tauNeutralFEWriteDecorKey
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_tauNeutralFEWriteDecorKey
The write key for adding Neutral Flow Element links to the taus.
Definition: PFTauFlowElementAssoc.h:57
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
FlowElement.h
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
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
PFTauFlowElementAssoc::m_chargedFEReadHandleKey
SG::ReadHandleKey< xAOD::FlowElementContainer > m_chargedFEReadHandleKey
Definition: PFTauFlowElementAssoc.h:54
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PFTauFlowElementAssoc::m_tauChargedFEWriteDecorKey
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_tauChargedFEWriteDecorKey
The write key for adding Charged Flow Element links to the taus.
Definition: PFTauFlowElementAssoc.h:59
TauJetContainer.h
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
xAOD::CaloCluster_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: CaloCluster_v1.cxx:465
PFTauFlowElementAssoc::m_neutralFETauWriteDecorKey
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_neutralFETauWriteDecorKey
The write key for adding tau element links to the Neutral Flow Elements.
Definition: PFTauFlowElementAssoc.h:61
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
PFTauFlowElementAssoc::m_chargedFETauWriteDecorKey
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_chargedFETauWriteDecorKey
The write key for adding tau element links to the Charged Flow Elements.
Definition: PFTauFlowElementAssoc.h:63
TauTrack.h
PFTauFlowElementAssoc::m_tauJetReadHandleKey
SG::ReadHandleKey< xAOD::TauJetContainer > m_tauJetReadHandleKey
Definition: PFTauFlowElementAssoc.h:51
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
PFTauFlowElementAssoc::execute
virtual StatusCode execute(const EventContext &ctx) const
This algorithm: 1) Accesses the relevant FlowElement and TauJet containers 2) Loops over the neutral ...
Definition: PFTauFlowElementAssoc.cxx:50
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
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::CaloVertexedTopoCluster
Evaluate cluster kinematics with a different vertex / signal state.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloVertexedTopoCluster.h:38
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25