ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
Jet
JetMomentTools
Root
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
5
#include "
JetMomentTools/JetClusterMomentsTool.h
"
6
#include "
AsgDataHandles/WriteDecorHandle.h
"
7
8
JetClusterMomentsTool::JetClusterMomentsTool
(
const
std::string& name)
9
:
asg
::
AsgTool
(name)
10
{
11
}
12
13
StatusCode
JetClusterMomentsTool::initialize
(){
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();
20
if
(!
m_clsSecondLambdaKey
.empty())
m_clsSecondLambdaKey
=
m_jetContainerName
+
"."
+
m_clsSecondLambdaKey
.key();
21
if
(!
m_clsCenterLambdaKey
.empty())
m_clsCenterLambdaKey
=
m_jetContainerName
+
"."
+
m_clsCenterLambdaKey
.key();
22
if
(!
m_clsSecondRKey
.empty())
m_clsSecondRKey
=
m_jetContainerName
+
"."
+
m_clsSecondRKey
.key();
23
24
ATH_CHECK
(
m_clsPtKey
.initialize(
SG::AllowEmpty
));
25
ATH_CHECK
(
m_clsSecondLambdaKey
.initialize(
SG::AllowEmpty
));
26
ATH_CHECK
(
m_clsCenterLambdaKey
.initialize(
SG::AllowEmpty
));
27
ATH_CHECK
(
m_clsSecondRKey
.initialize(
SG::AllowEmpty
));
28
29
return
StatusCode::SUCCESS;
30
}
31
32
StatusCode
JetClusterMomentsTool::decorate
(
const
xAOD::JetContainer
& jets)
const
{
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
62
const
xAOD::CaloCluster
*
JetClusterMomentsTool::findLeadingCluster
(
const
xAOD::Jet
&
jet
)
const
{
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() ) {
71
case
xAOD::Type::CaloCluster
: {
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
95
float
JetClusterMomentsTool::getMoment
(
const
xAOD::CaloCluster
* cluster,
const
xAOD::CaloCluster::MomentType
& momentType)
const
{
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
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
WriteDecorHandle.h
Handle class for adding a decoration to an object.
JetClusterMomentsTool.h
JetClusterMomentsTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition
JetClusterMomentsTool.cxx:13
JetClusterMomentsTool::findLeadingCluster
const xAOD::CaloCluster * findLeadingCluster(const xAOD::Jet &jet) const
Definition
JetClusterMomentsTool.cxx:62
JetClusterMomentsTool::m_clsPtKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_clsPtKey
Definition
JetClusterMomentsTool.h:48
JetClusterMomentsTool::m_clsCenterLambdaKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_clsCenterLambdaKey
Definition
JetClusterMomentsTool.h:50
JetClusterMomentsTool::getMoment
float getMoment(const xAOD::CaloCluster *cluster, const xAOD::CaloCluster::MomentType &momentType) const
Definition
JetClusterMomentsTool.cxx:95
JetClusterMomentsTool::m_jetContainerName
Gaudi::Property< std::string > m_jetContainerName
Definition
JetClusterMomentsTool.h:44
JetClusterMomentsTool::decorate
virtual StatusCode decorate(const xAOD::JetContainer &jets) const override
Decorate a jet collection without otherwise modifying it.
Definition
JetClusterMomentsTool.cxx:32
JetClusterMomentsTool::m_clsSecondRKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_clsSecondRKey
Definition
JetClusterMomentsTool.h:51
JetClusterMomentsTool::m_clsSecondLambdaKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_clsSecondLambdaKey
Definition
JetClusterMomentsTool.h:49
JetClusterMomentsTool::JetClusterMomentsTool
JetClusterMomentsTool(const std::string &name)
Definition
JetClusterMomentsTool.cxx:8
asg::AsgTool::AsgTool
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition
AsgTool.cxx:58
xAOD::CaloCluster_v1::retrieveMoment
bool retrieveMoment(MomentType type, double &value) const
Retrieve individual moment.
Definition
CaloCluster_v1.cxx:662
xAOD::CaloCluster_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle (negative for negative-energy clusters).
Definition
CaloCluster_v1.cxx:247
xAOD::CaloCluster_v1::MomentType
MomentType
Enums to identify different moments.
Definition
CaloCluster_v1.h:123
xAOD::CaloCluster_v1::SECOND_LAMBDA
@ SECOND_LAMBDA
Second Moment in .
Definition
CaloCluster_v1.h:127
xAOD::CaloCluster_v1::SECOND_R
@ SECOND_R
Second Moment in .
Definition
CaloCluster_v1.h:126
xAOD::CaloCluster_v1::CENTER_LAMBDA
@ CENTER_LAMBDA
Shower depth at Cluster Centroid.
Definition
CaloCluster_v1.h:139
SG::AllowEmpty
@ AllowEmpty
Definition
StoreGate/StoreGate/VarHandleKey.h:27
asg
Definition
DataHandleTestTool.h:28
jet
Definition
JetCalibTools_PlotJESFactors.cxx:23
xAODType::Jet
@ Jet
The object is a jet.
Definition
ObjectType.h:40
xAODType::CaloCluster
@ CaloCluster
The object is a calorimeter cluster.
Definition
ObjectType.h:39
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition
Event/xAOD/xAODJet/xAODJet/Jet.h:17
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition
Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
xAOD::JetContainer
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Definition
JetContainer.h:17
Generated on
for ATLAS Offline Software by
1.17.0