ATLAS Offline Software
TauClusterFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef XAOD_ATHLYSIS
6 
7 #include "TauClusterFinder.h"
9 
12 #include "xAODTau/TauJet.h"
14 
15 
18 }
19 
20 
22  tau.clearClusterLinks();
23 
24  if (tau.jet() == nullptr) {
25  ATH_MSG_ERROR("Tau jet link is invalid.");
26  return StatusCode::FAILURE;
27  }
28 
29  const xAOD::Jet* jetSeed = tau.jet();
30 
31  // Find all the clusters in the JetConstituent
32  std::vector<const xAOD::CaloCluster*> clusterList = getClusterList(*jetSeed);
33 
34  for (const xAOD::CaloCluster* cluster : clusterList) {
35  if (cluster == nullptr) {
36  ATH_MSG_WARNING("Find cluster with nullptr, please check the configuration !");
37  continue;
38  }
39  if (inEleRM()){
40  static const SG::AuxElement::ConstAccessor<ElementLink<xAOD::CaloClusterContainer>> acc_originalObject("ERMOriginalCaloCluster");
41  auto original_cluster_link = acc_originalObject(*cluster);
42  if (!original_cluster_link.isValid()){
43  ATH_MSG_ERROR("Original ERM cluster link is not valid");
44  }
45  cluster = *original_cluster_link;
46  }
47 
48  // Clusters with negative energy will be thinned, and the elementlinks to these
49  // clusters will not be valid.
50  if (m_skipNegativeEnergy && cluster->rawE() <= 0.) continue;
51 
53  linkToCluster.toContainedElement(
54  *(static_cast<const xAOD::IParticleContainer*> (cluster->container())),
55  static_cast<const xAOD::IParticle*>(cluster));
56  tau.addClusterLink(linkToCluster);
57  }
58 
59  return StatusCode::SUCCESS;
60 }
61 
62 
63 
64 std::vector<const xAOD::CaloCluster*> TauClusterFinder::getClusterList(const xAOD::Jet& jet) const {
65  std::vector<const xAOD::CaloCluster*> clusterList;
66 
67  xAOD::JetConstituentVector constituents = jet.getConstituents();
68  for (const xAOD::JetConstituent* constituent : constituents) {
69  ATH_MSG_DEBUG("JetConstituent: ");
70  ATH_MSG_DEBUG("eta: " << constituent->eta() << " phi: " << constituent->phi() << " e: " << constituent->e());
71 
72  if( constituent->type() == xAOD::Type::CaloCluster ) {
73  const xAOD::CaloCluster* cluster = static_cast<const xAOD::CaloCluster*>(constituent->rawConstituent());
74  ATH_MSG_DEBUG("CaloCluster: ");
75  ATH_MSG_DEBUG("eta: " << cluster->eta() << " phi: " << cluster->phi() << " e: " << cluster->e());
76 
77  // If jet perfroms the vertex correction, then cluster in Topo jets is in a shallow copy of CaloCalTopoCluster.
78  // Since jets and the shallow copy may not be stored to AOD in R22, these clusters will be invalid with AOD as input.
79  // To fix this issue, we now retrieve the clusters in the original CaloCalTopoCluster.
80  const xAOD::IParticle* originalParticle = xAOD::getOriginalObject(*cluster);
81  if (m_useOrigCluster and originalParticle != nullptr) {
82  clusterList.push_back( static_cast<const xAOD::CaloCluster*>(originalParticle) );
83  }
84  else {
85  clusterList.push_back(cluster);
86  }
87  }
88  else if ( constituent->type() == xAOD::Type::FlowElement ) {
89  const xAOD::FlowElement* fe = static_cast<const xAOD::FlowElement*>( constituent->rawConstituent() );
90 
91  if (fe->isCharged()) continue;
92  if (fe->nOtherObjects()!=1){
93  ATH_MSG_WARNING("Neutral PFO has " << std::to_string(fe->nOtherObjects()) << " clusters, expected exactly 1!\n");
94  continue;
95  }
96 
97  clusterList.push_back( dynamic_cast<const xAOD::CaloCluster*>(fe->otherObject(0)) );
98  }
99  else {
100  ATH_MSG_WARNING("Seed jet constituent type not supported ! Skip");
101  continue;
102  }
103  }
104 
105  for (const xAOD::JetConstituent* constituent : constituents) {
106  // There is only one type in the constituents
107  if (constituent->type() != xAOD::Type::FlowElement) break;
108 
109  const xAOD::FlowElement* fe = static_cast<const xAOD::FlowElement*>( constituent->rawConstituent() );
110  if (! fe->isCharged()) continue;
111 
112  for (u_int index=0; index<fe->nOtherObjects(); index++){
113  const xAOD::CaloCluster* cluster = dynamic_cast<const xAOD::CaloCluster*>(fe->otherObject(index));
114  // Check it is not duplicate of one in neutral list
115  if ( std::find(clusterList.begin(), clusterList.end(), cluster) == clusterList.end() ) {
116  clusterList.push_back(cluster);
117  }
118  }
119  }
120 
121  return clusterList;
122 }
123 
124 #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
TauClusterFinder::m_skipNegativeEnergy
Gaudi::Property< bool > m_skipNegativeEnergy
Definition: TauClusterFinder.h:40
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:620
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
TauClusterFinder::TauClusterFinder
TauClusterFinder(const std::string &name)
Constructor.
Definition: TauClusterFinder.cxx:16
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
TauClusterFinder::getClusterList
std::vector< const xAOD::CaloCluster * > getClusterList(const xAOD::Jet &jet) const
Definition: TauClusterFinder.cxx:64
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
TauJetAuxContainer.h
xAOD::FlowElement_v1::isCharged
bool isCharged() const
Definition: FlowElement_v1.cxx:56
TauClusterFinder::m_useOrigCluster
Gaudi::Property< bool > m_useOrigCluster
Definition: TauClusterFinder.h:42
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
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
TauJetContainer.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::TauJet_v3::addClusterLink
void addClusterLink(const ElementLink< IParticleContainer > &tr)
add a cluster link to the tau
Definition: TauJet_v3.cxx:615
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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:21
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
TauJet.h
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