ATLAS Offline Software
TauClusterFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef XAOD_ATHLYSIS
6 
7 #include "TauClusterFinder.h"
9 
11 
12 
15 }
16 
17 
19  tau.clearClusterLinks();
20 
21  if (tau.jet() == nullptr) {
22  ATH_MSG_ERROR("Tau jet link is invalid.");
23  return StatusCode::FAILURE;
24  }
25 
26  const xAOD::Jet* jetSeed = tau.jet();
27 
28  // Find all the clusters in the JetConstituent
29  std::vector<const xAOD::CaloCluster*> clusterList = getClusterList(*jetSeed);
30 
31  for (const xAOD::CaloCluster* cluster : clusterList) {
32  if (cluster == nullptr) {
33  ATH_MSG_WARNING("Find cluster with nullptr, please check the configuration !");
34  continue;
35  }
36  if (inEleRM()){
37  static const SG::ConstAccessor<ElementLink<xAOD::CaloClusterContainer>> acc_originalObject("ERMOriginalCaloCluster");
38  auto original_cluster_link = acc_originalObject(*cluster);
39  if (!original_cluster_link.isValid()){
40  ATH_MSG_ERROR("Original ERM cluster link is not valid");
41  }
42  cluster = *original_cluster_link;
43  }
44 
45  // Clusters with negative energy will be thinned, and the elementlinks to these
46  // clusters will not be valid.
47  if (cluster->rawE() <= 0.) continue;
48 
50  linkToCluster.toContainedElement(
51  *(static_cast<const xAOD::IParticleContainer*> (cluster->container())),
52  static_cast<const xAOD::IParticle*>(cluster));
53  tau.addClusterLink(linkToCluster);
54  }
55 
56  return StatusCode::SUCCESS;
57 }
58 
59 
60 
61 std::vector<const xAOD::CaloCluster*> TauClusterFinder::getClusterList(const xAOD::Jet& jet) const {
62  std::vector<const xAOD::CaloCluster*> clusterList;
63 
64  xAOD::JetConstituentVector constituents = jet.getConstituents();
65  for (const xAOD::JetConstituent* constituent : constituents) {
66  ATH_MSG_DEBUG("JetConstituent: ");
67  ATH_MSG_DEBUG("eta: " << constituent->eta() << " phi: " << constituent->phi() << " e: " << constituent->e());
68 
69  if( constituent->type() == xAOD::Type::CaloCluster ) {
70  const xAOD::CaloCluster* cluster = static_cast<const xAOD::CaloCluster*>(constituent->rawConstituent());
71  ATH_MSG_DEBUG("CaloCluster: ");
72  ATH_MSG_DEBUG("eta: " << cluster->eta() << " phi: " << cluster->phi() << " e: " << cluster->e());
73 
74  // If jet perfroms the vertex correction, then cluster in Topo jets is in a shallow copy of CaloCalTopoCluster.
75  // Since jets and the shallow copy may not be stored to AOD in R22, these clusters will be invalid with AOD as input.
76  // To fix this issue, we now retrieve the clusters in the original CaloCalTopoCluster.
77  const xAOD::IParticle* originalParticle = xAOD::getOriginalObject(*cluster);
78  if (m_useOrigCluster and originalParticle != nullptr) {
79  clusterList.push_back( static_cast<const xAOD::CaloCluster*>(originalParticle) );
80  }
81  else {
82  clusterList.push_back(cluster);
83  }
84  }
85  else if ( constituent->type() == xAOD::Type::FlowElement ) {
86  const xAOD::FlowElement* fe = static_cast<const xAOD::FlowElement*>( constituent->rawConstituent() );
87 
88  if (fe->isCharged()) continue;
89  if (fe->nOtherObjects()!=1){
90  ATH_MSG_WARNING("Neutral PFO has " << std::to_string(fe->nOtherObjects()) << " clusters, expected exactly 1!\n");
91  continue;
92  }
93 
94  clusterList.push_back( dynamic_cast<const xAOD::CaloCluster*>(fe->otherObject(0)) );
95  }
96  else {
97  ATH_MSG_WARNING("Seed jet constituent type not supported ! Skip");
98  continue;
99  }
100  }
101 
102  for (const xAOD::JetConstituent* constituent : constituents) {
103  // There is only one type in the constituents
104  if (constituent->type() != xAOD::Type::FlowElement) break;
105 
106  const xAOD::FlowElement* fe = static_cast<const xAOD::FlowElement*>( constituent->rawConstituent() );
107  if (! fe->isCharged()) continue;
108 
109  for (u_int index=0; index<fe->nOtherObjects(); index++){
110  const xAOD::CaloCluster* cluster = dynamic_cast<const xAOD::CaloCluster*>(fe->otherObject(index));
111  // Check it is not duplicate of one in neutral list
112  if ( std::find(clusterList.begin(), clusterList.end(), cluster) == clusterList.end() ) {
113  clusterList.push_back(cluster);
114  }
115  }
116  }
117 
118  return clusterList;
119 }
120 
121 #endif
xAOD::CaloCluster_v1::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition: CaloCluster_v1.cxx:256
TauClusterFinder.h
xAOD::TauJet_v3::jet
const Jet * jet() const
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
index
Definition: index.py:1
xAOD::FlowElement_v1::nOtherObjects
std::size_t nOtherObjects() const
Definition: FlowElement_v1.cxx:192
TauRecToolBase
The base class for all tau tools.
Definition: TauRecToolBase.h:21
xAOD::TauJet_v3::clearClusterLinks
void clearClusterLinks()
Remove all clusters from the tau.
Definition: TauJet_v3.cxx:580
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
TauClusterFinder::TauClusterFinder
TauClusterFinder(const std::string &name)
Constructor.
Definition: TauClusterFinder.cxx:13
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
TauClusterFinder::getClusterList
std::vector< const xAOD::CaloCluster * > getClusterList(const xAOD::Jet &jet) const
Definition: TauClusterFinder.cxx:61
TauRecToolBase::inEleRM
bool inEleRM() const
Definition: TauRecToolBase.h:89
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
xAOD::FlowElement_v1::isCharged
bool isCharged() const
Definition: FlowElement_v1.cxx:56
TauClusterFinder::m_useOrigCluster
Gaudi::Property< bool > m_useOrigCluster
Definition: TauClusterFinder.h:40
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::CaloCluster_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: CaloCluster_v1.cxx:251
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
xAOD::FlowElement
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition: FlowElement.h:16
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
xAOD::TauJet_v3::addClusterLink
void addClusterLink(const ElementLink< IParticleContainer > &tr)
add a cluster link to the tau
Definition: TauJet_v3.cxx:575
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TauClusterFinder::execute
virtual StatusCode execute(xAOD::TauJet &tau) const override
Execution of this tool.
Definition: TauClusterFinder.cxx:18
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
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
HelperFunctions.h
xAOD::JetConstituent
4-vector of jet constituent at the scale used during jet finding.
Definition: JetConstituentVector.h:61
IParticleHelpers.h
xAOD::JetConstituentVector
A vector of jet constituents at the scale used during jet finding.
Definition: JetConstituentVector.h:117
xAOD::getOriginalObject
const IParticle * getOriginalObject(const IParticle &copy)
This function can be used to conveniently get a pointer back to the original object from which a copy...
Definition: IParticleHelpers.cxx:140
xAOD::CaloCluster_v1::e
virtual double e() const
The total energy of the particle.
Definition: CaloCluster_v1.cxx:265
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25