ATLAS Offline Software
Loading...
Searching...
No Matches
JetConstituentsRetriever.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// JetConstituentsRetriever.cxx
6
8#include "fastjet/PseudoJet.hh"
9#include "JetEDM/LabelIndex.h"
14
15using std::string;
16using xAOD::IParticle;
18
19using IParticleVector = std::vector<const IParticle *>;
20using MuonSegmentVector = std::vector<const MuonSegment *>;
23
24//**********************************************************************
25
27 : AsgTool(name), m_hpjr("",this) {
28 declareProperty("UsePseudojet", m_usepj =true);
29 declareProperty("UseJetConstituents", m_usejetcons =true);
30 declareProperty("PseudojetRetriever", m_hpjr);
31 declareProperty("GhostLabels", m_glabs);
32 declareProperty("GhostScale", m_gscale);
33}
34
35//**********************************************************************
36
38 if ( m_usepj ) {
39 if ( m_hpjr.empty() ) {
40 ATH_MSG_ERROR(" PseudojetRetriever is missing.");
41 }
42 }
43 return StatusCode::SUCCESS;
44}
45
46//**********************************************************************
47
50 NameList* pghostlabs) const {
51 // If flag is set, try to retrieve constituents from jet pseudojet.
52 if ( m_usepj ) {
53 ATH_MSG_VERBOSE("Using pseudojet to search for constituents.");
54 if ( m_hpjr.empty() ) {
55 ATH_MSG_WARNING("Pseudojet retriever not found.");
56 } else {
57 const fastjet::PseudoJet* ppj = m_hpjr->pseudojet(jet);
58 if ( ppj == nullptr ) {
59 ATH_MSG_VERBOSE("Pseudojet not found.");
60 } else {
61 if ( ! ppj->has_constituents() ) {
62 ATH_MSG_WARNING("Jet pseudojet does not have constituents.");
63 } else {
64 PseudoJetVector pjcons = ppj->constituents();
65 constits.insert(constits.end(), pjcons.begin(), pjcons.end());
66 return 0;
67 }
68 }
69 }
70 }
71 // Remainder requires access to the label index map;
72 jet::LabelIndex* pli = nullptr;
73 const string liname = "PseudoJetLabelMap";
74 if ( evtStore()->contains<jet::LabelIndex>(liname) ) {
75 ATH_MSG_DEBUG("Fetching existing pseudojet label map.");
76 pli = evtStore()->retrieve<jet::LabelIndex>(liname);
77 if ( pli == nullptr ) {
78 ATH_MSG_ERROR("Unable to fetch pseudojet label map.");
79 return 1;
80 }
81 } else {
82 ATH_MSG_DEBUG("Creating new pseudojet label map.");
83 pli = new jet::LabelIndex(liname);
84 if ( evtStore()->record(pli, liname).isFailure() ) {
85 ATH_MSG_ERROR("Unable to store pseudojet label map.");
86 return 2;
87 }
88 }
89 // Add ATLAS jet constituents.
90 if ( m_usejetcons ) {
91 xAOD::JetInput::Type intype = jet.getInputType();
92 string lab = xAOD::JetInput::typeName(intype);
93 int labidx = pli->addLabel(lab);
94 ATH_MSG_DEBUG("Jet input type is " << lab);
95 ATH_MSG_VERBOSE("Looping over " << jet.getConstituents().size()
96 << " real constituents.");
97 for ( const auto *const pjetcon : jet.getConstituents() ) {
98 if ( pjetcon == nullptr ) {
99 ATH_MSG_WARNING("Jet has null constituent");
100 } else {
101 //fastjet::PseudoJet psj(*pjetcon);
102 fastjet::PseudoJet psj(pjetcon->px(), pjetcon->py(), pjetcon->pz(), pjetcon->e());
103 const xAOD::IParticle* ppar = pjetcon->rawConstituent();
105 new jet::IndexedConstituentUserInfo(*ppar, labidx, pli);
106 psj.set_user_info(pcui);
107 constits.push_back(psj);
108 ATH_MSG_VERBOSE(" Real user info: particle=" << pcui->particle()
109 << ", index=" << pcui->index()
110 << ", label=" << pcui->label()
111 << ", isGhost=" << pcui->isGhost());
112 }
113 }
114 }
115 // Add ghosts.
116 NameList glabs;
117 ATH_MSG_VERBOSE("Looping over " << m_glabs.size() << " ghost labels.");
118 for ( const std::string& glab : m_glabs ) {
119 string gname = "Ghost" + glab;
120 double fac = m_gscale;
121 if ( glab == "MuonSegment" ) {
122 MuonSegmentVector psegs;
123 if ( jet.getAssociatedObjects(gname, psegs) ) {
124 ATH_MSG_VERBOSE(" Found Muon segment vector " << gname << " with "
125 << psegs.size() << " entries.");
126 int labidx = pli->addLabel(glab);
127 glabs.push_back(glab);
128 unsigned int iseg = 0;
129 for ( const MuonSegment* pseg : psegs ) {
130 if ( pseg == nullptr ) {
131 ATH_MSG_DEBUG("Muon segment not found: " << gname << "[" << iseg << "]");
132 } else {
133 // Cut and paste from MuonSegmentPseudoJetGetter.
134 double pt = 1.0e-20; // Should be property?
135 double x = pseg->x();
136 double y = pseg->y();
137 double z = pseg->z();
138 double xy = sqrt(x*x + y*y);
139 double r = xy*xy + z*z;
140 double pfac = pt/xy;
141 double px = pfac*x;
142 double py = pfac*y;
143 double pz = pfac*z;
144 double e = pfac*r;
145 fastjet::PseudoJet psj(px, py, pz, e);
147 new jet::IndexedTConstituentUserInfo<MuonSegment>(*pseg, -labidx, pli);
148 psj.set_user_info(pcui);
149 constits.push_back(psj);
150 ATH_MSG_VERBOSE(" Muon ghost user info: particle=" << pcui->particle()
151 << ", index=" << pcui->index()
152 << ", label=" << pcui->label()
153 << ", isGhost=" << pcui->isGhost());
154 ATH_MSG_VERBOSE(" Adding " << gname << "[" << iseg << "]");
155 }
156 ++iseg;
157 }
158 } else {
159 ATH_MSG_VERBOSE(" Muon segment vector " << gname << " is not found on jet.");
160 }
161
162 } else {
163 IParticleVector ppars;
164 if ( jet.getAssociatedObjects(gname, ppars) ) {
165 ATH_MSG_VERBOSE(" Found IParticle vector " << gname << " with "
166 << ppars.size() << " entries.");
167 int labidx = pli->addLabel(glab);
168 glabs.push_back(glab);
169 unsigned int ipar = 0;
170 for ( const IParticle* ppar : ppars ) {
171 if ( ppar == nullptr ) {
172 ATH_MSG_DEBUG("IParticle not found: " << gname << "[" << ipar << "]");
173 } else {
174 auto p4 = ppar->p4();
175 fastjet::PseudoJet psj(fac*p4.Px(), fac*p4.Py(), fac*p4.Pz(), fac*p4.E());
177 new jet::IndexedConstituentUserInfo(*ppar, -labidx, pli);
178 psj.set_user_info(pcui);
179 constits.push_back(psj);
180 ATH_MSG_VERBOSE(" Ghost user info: particle=" << pcui->particle()
181 << ", index=" << pcui->index()
182 << ", label=" << pcui->label()
183 << ", isGhost=" << pcui->isGhost());
184 ATH_MSG_VERBOSE(" Adding " << gname << "[" << ipar << "]");
185 }
186 ++ipar;
187 }
188 } else {
189 ATH_MSG_VERBOSE(" IParticle vector " << gname << " is not found on jet.");
190 }
191 }
192 }
193 if ( pghostlabs != nullptr ) {
194 pghostlabs->insert(pghostlabs->end(), glabs.begin(), glabs.end());
195 }
196 return 1;
197}
198
199//**********************************************************************
200
202 ATH_MSG_INFO("JetConstituentsRetriever");
203 ATH_MSG_INFO(" UsePseudojet: " << m_usepj);
204 if ( m_usepj ) {
205 if ( m_hpjr.empty() ) {
206 ATH_MSG_INFO(" PseudojetRetriever is missing.");
207 } else {
208 ATH_MSG_INFO(" PseudojetRetriever: " << m_hpjr->name());
209 }
210 }
211 ATH_MSG_INFO(" UsePseudojet: " << m_usepj);
212 if ( m_glabs.empty() ) {
213 ATH_MSG_INFO(" GhostLabels:");
214 for ( const std::string& glab : m_glabs ) {
215 ATH_MSG_INFO(" " << glab);
216 }
217 }
218 ATH_MSG_INFO(" GhostScale: " << m_gscale);
219}
220
221//**********************************************************************
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::vector< const MuonSegment * > MuonSegmentVector
std::vector< fastjet::PseudoJet > PseudoJetVector
std::vector< const IParticle * > IParticleVector
IJetConstituentsRetriever::NameList NameList
#define y
#define x
#define z
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
std::vector< std::string > NameList
std::vector< fastjet::PseudoJet > PseudoJetVector
ToolHandle< IJetPseudojetRetriever > m_hpjr
int constituents(const xAOD::Jet &jet, PseudoJetVector &cons, NameList *pghostlabs=nullptr) const
Append constituents to the supplied vector.
JetConstituentsRetriever(const std::string &name)
StatusCode initialize()
Dummy implementation of the initialisation function.
void print() const
Print the state of the tool.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
virtual Label label() const =0
virtual bool isGhost() const
Returns true if this constituent is a ghost.
virtual const xAOD::IParticle * particle() const =0
Index addLabel(const Label &lab)
Add a label and get its index.
Class providing the definition of the 4-vector interface.
int r
Definition globals.cxx:22
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
const std::string & typeName(Type id)
Jet_v1 Jet
Definition of the current "jet version".
MuonSegment_v1 MuonSegment
Reference the current persistent version: