ATLAS Offline Software
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"
12 #include "xAODMuon/MuonSegment.h"
14 
15 using std::string;
16 using xAOD::IParticle;
17 using xAOD::MuonSegment;
18 
19 using IParticleVector = std::vector<const IParticle *>;
20 using 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 
49 constituents(const xAOD::Jet& jet, PseudoJetVector& constits,
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 //**********************************************************************
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
beamspotman.r
def r
Definition: beamspotman.py:676
jet::LabelIndex
Definition: LabelIndex.h:22
JetConstituentsRetriever::print
void print() const
Print the state of the tool.
Definition: JetConstituentsRetriever.cxx:201
JetConstituentsRetriever.h
IndexedTConstituentUserInfo.h
test_pyathena.px
px
Definition: test_pyathena.py:18
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
IParticleVector
std::vector< const IParticle * > IParticleVector
Definition: JetConstituentsRetriever.cxx:19
MuonSegment.h
test_pyathena.pt
pt
Definition: test_pyathena.py:11
JetConstituentsRetriever::m_usepj
bool m_usepj
Definition: JetConstituentsRetriever.h:50
jet::IConstituentUserInfo::particle
virtual const xAOD::IParticle * particle() const =0
ReadBchFromCool.gname
gname
Definition: ReadBchFromCool.py:415
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAOD::JetInput::typeName
const std::string & typeName(Type id)
Definition: JetContainerInfo.cxx:199
x
#define x
xAOD::MuonSegment
MuonSegment_v1 MuonSegment
Reference the current persistent version:
Definition: Event/xAOD/xAODMuon/xAODMuon/MuonSegment.h:13
IJetConstituentsRetriever::PseudoJetVector
std::vector< fastjet::PseudoJet > PseudoJetVector
Definition: IJetConstituentsRetriever.h:32
JetConstituentsRetriever::JetConstituentsRetriever
JetConstituentsRetriever(const std::string &name)
Definition: JetConstituentsRetriever.cxx:26
MuonSegmentContainer.h
jet::IndexedTConstituentUserInfo
Definition: IndexedTConstituentUserInfo.h:31
JetConstituentsRetriever::constituents
int constituents(const xAOD::Jet &jet, PseudoJetVector &cons, NameList *pghostlabs=nullptr) const
Append constituents to the supplied vector.
Definition: JetConstituentsRetriever.cxx:49
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
JetConstituentsRetriever::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetConstituentsRetriever.cxx:37
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IndexedConstituentUserInfo.h
z
#define z
jet::IConstituentUserInfo::isGhost
virtual bool isGhost() const
Returns true if this constituent is a ghost.
Definition: IConstituentUserInfo.cxx:26
jet::LabelIndex::addLabel
Index addLabel(const Label &lab)
Add a label and get its index.
Definition: LabelIndex.cxx:23
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Amg::pz
@ pz
Definition: GeoPrimitives.h:40
jet::IConstituentUserInfo::index
virtual Index index() const
Definition: IConstituentUserInfo.cxx:14
jet::IConstituentUserInfo::label
virtual Label label() const =0
JetConstituentsRetriever::m_gscale
double m_gscale
Definition: JetConstituentsRetriever.h:54
IJetConstituentsRetriever::NameList
std::vector< std::string > NameList
Definition: IJetConstituentsRetriever.h:33
xAOD::JetInput::Type
Type
Definition: JetContainerInfo.h:54
jet::IndexedConstituentUserInfo
Definition: IndexedConstituentUserInfo.h:28
Amg::py
@ py
Definition: GeoPrimitives.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
JetConstituentsRetriever::m_usejetcons
bool m_usejetcons
Definition: JetConstituentsRetriever.h:51
LabelIndex.h
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
PseudoJetVector
std::vector< fastjet::PseudoJet > PseudoJetVector
Definition: JetConstituentFiller.cxx:17
MuonSegmentVector
std::vector< const MuonSegment * > MuonSegmentVector
Definition: JetConstituentFiller.cxx:27
y
#define y
NameList
IJetConstituentsRetriever::NameList NameList
Definition: JetConstituentsRetriever.cxx:22
jet::IConstituentUserInfo
Definition: IConstituentUserInfo.h:26
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
JetConstituentsRetriever::m_glabs
NameList m_glabs
Definition: JetConstituentsRetriever.h:53
IParticle
Definition: Event/EventKernel/EventKernel/IParticle.h:43
JetConstituentsRetriever::m_hpjr
ToolHandle< IJetPseudojetRetriever > m_hpjr
Definition: JetConstituentsRetriever.h:52