ATLAS Offline Software
Loading...
Searching...
No Matches
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
13TauClusterFinder::TauClusterFinder(const std::string& name) :
14 TauRecToolBase(name) {
15}
16
17
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
61std::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
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helper class to provide constant type-safe access to aux data.
virtual StatusCode execute(xAOD::TauJet &tau) const override
Execution of this tool.
Gaudi::Property< bool > m_useOrigCluster
TauClusterFinder(const std::string &name)
Constructor.
std::vector< const xAOD::CaloCluster * > getClusterList(const xAOD::Jet &jet) const
TauRecToolBase(const std::string &name)
bool inEleRM() const
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double e() const
The total energy of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
std::size_t nOtherObjects() const
const xAOD::IParticle * otherObject(std::size_t i) const
Class providing the definition of the 4-vector interface.
A vector of jet constituents at the scale used during jet finding.
4-vector of jet constituent at the scale used during jet finding.
void clearClusterLinks()
Remove all clusters from the tau.
const Jet * jet() const
void addClusterLink(const ElementLink< IParticleContainer > &tr)
add a cluster link to the tau
Definition index.py:1
@ FlowElement
The object is a track-calo-cluster.
Definition ObjectType.h:52
@ CaloCluster
The object is a calorimeter cluster.
Definition ObjectType.h:39
Jet_v1 Jet
Definition of the current "jet version".
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition FlowElement.h:16
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...
TauJet_v3 TauJet
Definition of the current "tau version".
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.