ATLAS Offline Software
Loading...
Searching...
No Matches
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
8
11
12using std::string;
13using xAOD::IParticle;
14using xAOD::Jet;
18
19//**********************************************************************
20
22 : asg::AsgTool(myname) {
23
24}
25
26//**********************************************************************
27
29
30 if(m_jetContainerName.empty()) {
31 ATH_MSG_ERROR("JetPtAssociationTool needs to have its input jet container configured!");
32 return StatusCode::FAILURE;
33 }
36
37 ATH_CHECK(m_assocFracKey.initialize());
38 ATH_CHECK(m_assocLinkKey.initialize());
39
41
42 return StatusCode::SUCCESS;
43
44}
45
46//**********************************************************************
47
49
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.
65 if (!handle.isValid()){
66 ATH_MSG_WARNING("Matching jet container not found: "
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 }
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
107ptfrac(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
130match(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//**********************************************************************
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
virtual double pt() const =0
transverse momentum
JetPtAssociationTool(const std::string &myname)
Constructor from tool name.
SG::WriteDecorHandleKey< xAOD::JetContainer > m_assocLinkKey
std::vector< float > FloatVector
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.
virtual StatusCode decorate(const xAOD::JetContainer &jets) const override
Inherited method to modify a jet.
virtual StatusCode initialize() override
Initialization.
Gaudi::Property< std::string > m_aname
Properties.
Gaudi::Property< std::string > m_jetContainerName
SG::WriteDecorHandleKey< xAOD::JetContainer > m_assocFracKey
std::vector< const xAOD::IParticle * > APVector
int ptfrac(const APVector &aps, const xAOD::JetContainer &jets, FloatVector &ptsums) const
Return the matched pT sum for each jet in a collection.
SG::ReadHandleKey< xAOD::JetContainer > m_matchingContainerName
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Handle class for adding a decoration to an object.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
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.
Jet_v1 Jet
Definition of the current "jet version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".