ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
Jet
JetMomentTools
Root
JetPtAssociationTool.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
// JetPtAssociationTool.cxx
6
7
#include "
JetMomentTools/JetPtAssociationTool.h
"
8
9
#include "
AsgDataHandles/ReadHandle.h
"
10
#include "
AsgDataHandles/WriteDecorHandle.h
"
11
12
using
std::string;
13
using
xAOD::IParticle
;
14
using
xAOD::Jet
;
15
using
xAOD::JetContainer
;
16
using
xAOD::JetConstituent
;
17
using
xAOD::JetConstituentVector
;
18
19
//**********************************************************************
20
21
JetPtAssociationTool::JetPtAssociationTool
(
const
std::string& myname)
22
:
asg
::
AsgTool
(myname) {
23
24
}
25
26
//**********************************************************************
27
28
StatusCode
JetPtAssociationTool::initialize
() {
29
30
if
(
m_jetContainerName
.empty()) {
31
ATH_MSG_ERROR
(
"JetPtAssociationTool needs to have its input jet container configured!"
);
32
return
StatusCode::FAILURE;
33
}
34
m_assocFracKey
=
m_jetContainerName
+
"."
+
m_aname
+
m_assocFracKey
.key();
35
m_assocLinkKey
=
m_jetContainerName
+
"."
+
m_aname
+
m_assocLinkKey
.key();
36
37
ATH_CHECK
(
m_assocFracKey
.initialize());
38
ATH_CHECK
(
m_assocLinkKey
.initialize());
39
40
ATH_CHECK
(
m_matchingContainerName
.initialize());
41
42
return
StatusCode::SUCCESS;
43
44
}
45
46
//**********************************************************************
47
48
StatusCode
JetPtAssociationTool::decorate
(
const
xAOD::JetContainer
& jets)
const
{
49
50
SG::WriteDecorHandle<xAOD::JetContainer, float>
assocFracHandle(
m_assocFracKey
);
51
SG::WriteDecorHandle<xAOD::JetContainer, ElementLink<JetContainer>
> assocLinkHandle(
m_assocLinkKey
);
52
53
for
(
const
xAOD::Jet
*
jet
: jets) {
54
ATH_MSG_DEBUG
(
"Processing jet "
<<
jet
->index());
55
APVector
apins;
56
57
// Retrieve the association vector.
58
if
( !
jet
->getAssociatedObjects(
m_aname
, apins) ) {
59
ATH_MSG_WARNING
(
"Jet does not have association vector "
<<
m_aname
);
60
return
StatusCode::FAILURE;
61
}
62
63
// Retrieve the container of jets to be matched.
64
SG::ReadHandle<xAOD::JetContainer>
handle (
m_matchingContainerName
);
65
if
(!handle.isValid()){
66
ATH_MSG_WARNING
(
"Matching jet container not found: "
67
<<
m_matchingContainerName
);
68
return
StatusCode::FAILURE;
69
}
70
71
const
auto
*pjets = handle.cptr();
72
73
// Match associated particle to jets.
74
FloatVector
ptfs;
75
if
(
ptfrac
(apins, *pjets, ptfs) ) {
76
ATH_MSG_WARNING
(
"Match of association vector to jets failed"
);
77
return
StatusCode::FAILURE;
78
}
79
// Find the best match.
80
float
frac = 0.0;
81
unsigned
int
ijet_matched = ptfs.size();
82
for
(
unsigned
int
ijet=0; ijet<ptfs.size(); ++ijet ) {
83
ATH_MSG_VERBOSE
(
" Pt fraction["
<< ijet <<
"]: "
<< ptfs[ijet]);
84
if
( ptfs[ijet] > frac ) {
85
frac = ptfs[ijet];
86
ijet_matched = ijet;
87
}
88
}
89
ElementLink<JetContainer>
el;
90
if
( ijet_matched < ptfs.size() ) {
91
el =
ElementLink<JetContainer>
(*pjets, ijet_matched);
92
}
93
string
sfrac =
m_aname
+
"AssociationFraction"
;
94
string
slink =
m_aname
+
"AssociationLink"
;
95
ATH_MSG_DEBUG
(
" Setting "
<< sfrac <<
" = "
<< frac);
96
assocFracHandle(*
jet
) = frac;
97
ATH_MSG_DEBUG
(
" Setting "
<< slink <<
" = "
98
<< el.dataID() <<
"["
<< el.index() <<
"]"
);
99
assocLinkHandle(*
jet
) = el;
100
}
101
return
StatusCode::SUCCESS;
102
}
103
104
//**********************************************************************
105
106
int
JetPtAssociationTool::
107
ptfrac
(
const
APVector
& apins,
const
xAOD::JetContainer
& jets,
FloatVector
& ptfs)
const
{
108
ptfs.clear();
109
ptfs.resize(jets.size(), 0.0);
110
ATH_MSG_DEBUG
(
"Match jet count: "
<< jets.size());
111
for
(
unsigned
int
ijet=0; ijet<jets.size(); ++ijet ) {
112
const
Jet
* pjet = jets[ijet];
113
if
( pjet ==
nullptr
)
return
-3;
114
APVector
apouts;
115
double
ptsum_target = 0.;
116
match
(apins, *pjet, apouts, ptsum_target);
117
double
ptsum = 0.0;
118
for
(
const
IParticle
* ppar : apouts ) {
119
if
( ppar ==
nullptr
)
return
-4;
120
ptsum += ppar->pt();
121
}
122
ptfs[ijet] = ptsum/ptsum_target;
123
}
124
return
0;
125
}
126
127
//**********************************************************************
128
129
int
JetPtAssociationTool::
130
match
(
const
APVector
& aps,
const
xAOD::Jet
&
jet
,
APVector
& apvs,
double
& ptsum_constituents)
const
{
131
ptsum_constituents = 0.;
132
apvs.clear();
133
const
JetConstituentVector
cons =
jet
.getConstituents();
134
for
(
const
JetConstituent
* pcon : cons ) {
135
const
IParticle
* pparcon = pcon->rawConstituent();
136
ptsum_constituents+=pparcon->
pt
();
137
for
(
const
IParticle
* pparap : aps ) {
138
if
( pparap == pparcon ) {
139
apvs.push_back(pparcon);
140
break
;
141
}
142
}
143
}
144
return
0;
145
}
146
147
//**********************************************************************
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ElementLink
ElementLink()
Default constructor.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
ReadHandle.h
Handle class for reading from StoreGate.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
JetPtAssociationTool.h
ElementLink
ElementLink implementation for ROOT usage.
Definition
A/AthLinks/ElementLink.h:40
I4Momentum::pt
virtual double pt() const =0
transverse momentum
IParticle
Definition
Event/EventKernel/EventKernel/IParticle.h:43
JetPtAssociationTool::JetPtAssociationTool
JetPtAssociationTool(const std::string &myname)
Constructor from tool name.
Definition
JetPtAssociationTool.cxx:21
JetPtAssociationTool::m_assocLinkKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_assocLinkKey
Definition
JetPtAssociationTool.h:72
JetPtAssociationTool::FloatVector
std::vector< float > FloatVector
Definition
JetPtAssociationTool.h:34
JetPtAssociationTool::match
int match(const APVector &aps, const xAOD::Jet &jet, APVector &apvs, double &ptsum_constituents) const
Return the vector of AP's that appear as constituents of the given jet.
Definition
JetPtAssociationTool.cxx:130
JetPtAssociationTool::decorate
virtual StatusCode decorate(const xAOD::JetContainer &jets) const override
Inherited method to modify a jet.
Definition
JetPtAssociationTool.cxx:48
JetPtAssociationTool::initialize
virtual StatusCode initialize() override
Initialization.
Definition
JetPtAssociationTool.cxx:28
JetPtAssociationTool::m_aname
Gaudi::Property< std::string > m_aname
Properties.
Definition
JetPtAssociationTool.h:67
JetPtAssociationTool::m_jetContainerName
Gaudi::Property< std::string > m_jetContainerName
Definition
JetPtAssociationTool.h:68
JetPtAssociationTool::m_assocFracKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_assocFracKey
Definition
JetPtAssociationTool.h:71
JetPtAssociationTool::APVector
std::vector< const xAOD::IParticle * > APVector
Definition
JetPtAssociationTool.h:32
JetPtAssociationTool::ptfrac
int ptfrac(const APVector &aps, const xAOD::JetContainer &jets, FloatVector &ptsums) const
Return the matched pT sum for each jet in a collection.
Definition
JetPtAssociationTool.cxx:107
JetPtAssociationTool::m_matchingContainerName
SG::ReadHandleKey< xAOD::JetContainer > m_matchingContainerName
Definition
JetPtAssociationTool.h:69
Jet
Definition
Reconstruction/Jet/JetEvent/JetEvent/Jet.h:47
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
asg::AsgTool::AsgTool
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition
AsgTool.cxx:58
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAOD::JetConstituentVector
A vector of jet constituents at the scale used during jet finding.
Definition
JetConstituentVector.h:117
xAOD::JetConstituent
4-vector of jet constituent at the scale used during jet finding.
Definition
JetConstituentVector.h:61
asg
Definition
DataHandleTestTool.h:28
jet
Definition
JetCalibTools_PlotJESFactors.cxx:23
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition
Event/xAOD/xAODJet/xAODJet/Jet.h:17
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