ATLAS Offline Software
Loading...
Searching...
No Matches
JetClusterMomentsTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7
9 : asg::AsgTool(name)
10{
11}
12
14 if(m_jetContainerName.empty()){
15 ATH_MSG_ERROR("JetClusterMomentsTool needs to have its input jet container name configured!");
16 return StatusCode::FAILURE;
17 }
18
19 if(!m_clsPtKey.empty()) m_clsPtKey = m_jetContainerName + "." + m_clsPtKey.key();
23
28
29 return StatusCode::SUCCESS;
30}
31
33
34 // Use pointers here so we can create only the ones we're configured for
35 std::unique_ptr<SG::WriteDecorHandle<xAOD::JetContainer, float> > handlePt;
36 std::unique_ptr<SG::WriteDecorHandle<xAOD::JetContainer, float> > handleSecondLambda;
37 std::unique_ptr<SG::WriteDecorHandle<xAOD::JetContainer, float> > handleCenterLambda;
38 std::unique_ptr<SG::WriteDecorHandle<xAOD::JetContainer, float> > handleSecondR;
39
40 if(!m_clsPtKey.empty()) handlePt = std::make_unique<SG::WriteDecorHandle<xAOD::JetContainer, float> >(m_clsPtKey);
41 if(!m_clsSecondLambdaKey.empty()) handleSecondLambda = std::make_unique<SG::WriteDecorHandle<xAOD::JetContainer, float> >(m_clsSecondLambdaKey);
42 if(!m_clsCenterLambdaKey.empty()) handleCenterLambda = std::make_unique<SG::WriteDecorHandle<xAOD::JetContainer, float> >(m_clsCenterLambdaKey);
43 if(!m_clsSecondRKey.empty()) handleSecondR = std::make_unique<SG::WriteDecorHandle<xAOD::JetContainer, float> >(m_clsSecondRKey);
44
45 for(const xAOD::Jet* jet : jets){
46 // Find leading constituent cluster
47 const xAOD::CaloCluster* leadingCluster = findLeadingCluster(*jet);
48 ATH_MSG_DEBUG("Leading cluster retrieving finished.");
49 if(!leadingCluster){
50 ATH_MSG_WARNING("Jet has no CaloCluster constituents, leading cluster not found");
51 return StatusCode::FAILURE;
52 }
53 // Set info
54 if(handlePt.get() != nullptr) (*handlePt)(*jet) = leadingCluster->pt();
55 if(handleSecondLambda.get() != nullptr) (*handleSecondLambda)(*jet) = getMoment(leadingCluster, xAOD::CaloCluster::SECOND_LAMBDA);
56 if(handleCenterLambda.get() != nullptr) (*handleCenterLambda)(*jet) = getMoment(leadingCluster, xAOD::CaloCluster::CENTER_LAMBDA);
57 if(handleSecondR.get() != nullptr) (*handleSecondR)(*jet) = getMoment(leadingCluster, xAOD::CaloCluster::SECOND_R);
58 }
59 return StatusCode::SUCCESS;
60}
61
63
64 // Retrieve the associated clusters.
65
66 if ( jet.numConstituents() == 0 ) return nullptr;
67 const xAOD::CaloCluster * cl_leading = nullptr;
68
69
70 switch( jet.rawConstituent(0)->type() ) {
72 for (size_t i_cl = 0; i_cl < jet.numConstituents(); i_cl++){ // loop all constituents
73 const xAOD::CaloCluster * cl_current = dynamic_cast<const xAOD::CaloCluster*> (jet.rawConstituent(i_cl));
74 if (!cl_current) continue;
75 if (!cl_leading || cl_leading->pt() < cl_current->pt() ) cl_leading = cl_current;
76 }
77
78 } break;
79
80 case xAOD::Type::Jet: {
81 for (size_t i_cl = 0; i_cl < jet.numConstituents(); i_cl++){ // loop all constituents
82 const xAOD::Jet * jet_constit = dynamic_cast<const xAOD::Jet*> (jet.rawConstituent(i_cl));
83 if (!jet_constit) continue;
84 const xAOD::CaloCluster * cl_current = findLeadingCluster( *jet_constit ) ;
85 if(cl_current) if (!cl_leading || cl_leading->pt() < cl_current->pt() ) cl_leading = cl_current;
86 }
87
88 } break;
89 default:
90 break;
91 } // end switch
92 return cl_leading;
93}
94
96 if (cluster){ // if we have a pointer than read the moment
97 double moment = 0.0;
98 bool isRetrieved = cluster->retrieveMoment(momentType, moment);
99 if (isRetrieved) return (float) moment;
100 }
101 ATH_MSG_WARNING("Can not retrieved moment from cluster");
102 return 0.0;
103}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for adding a decoration to an object.
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
const xAOD::CaloCluster * findLeadingCluster(const xAOD::Jet &jet) const
SG::WriteDecorHandleKey< xAOD::JetContainer > m_clsPtKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_clsCenterLambdaKey
float getMoment(const xAOD::CaloCluster *cluster, const xAOD::CaloCluster::MomentType &momentType) const
Gaudi::Property< std::string > m_jetContainerName
virtual StatusCode decorate(const xAOD::JetContainer &jets) const override
Decorate a jet collection without otherwise modifying it.
SG::WriteDecorHandleKey< xAOD::JetContainer > m_clsSecondRKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_clsSecondLambdaKey
JetClusterMomentsTool(const std::string &name)
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
bool retrieveMoment(MomentType type, double &value) const
Retrieve individual moment.
virtual double pt() const
The transverse momentum ( ) of the particle (negative for negative-energy clusters)
MomentType
Enums to identify different moments.
@ SECOND_LAMBDA
Second Moment in .
@ SECOND_R
Second Moment in .
@ CENTER_LAMBDA
Shower depth at Cluster Centroid.
@ Jet
The object is a jet.
Definition ObjectType.h:40
@ 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.
JetContainer_v1 JetContainer
Definition of the current "jet container version".