ATLAS Offline Software
JetDumper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // JetDumper.cxx
6 
7 #include "JetRec/JetDumper.h"
9 #include "xAODJet/JetContainer.h"
12 #include <iostream>
13 
14 using std::string;
15 using xAOD::Jet;
18 
21 
22 //**********************************************************************
23 
24 JetDumper::JetDumper(const std::string& myname)
25 : AsgTool(myname) {
26  ATH_MSG_INFO("JetDumper::ctor: Declaring properties.");
27  declareProperty("ContainerName", m_cname ="");
28  declareProperty("Detail", m_detail =1);
29  declareProperty("LineDetail", m_linedetail =1);
30  declareProperty("Prefix", m_prefix =1);
31  declareProperty("MaxObject", m_maxobj =10);
32  declareProperty("FloatMax", m_floatmax = 0.999e6);
33  declareProperty("FloatMoments", m_fmoms);
34  declareProperty("IntMoments", m_imoms);
35  declareProperty("BoolMoments", m_bmoms);
36  declareProperty("CBoolMoments", m_cbmoms);
37  declareProperty("StringMoments", m_smoms);
38  declareProperty("FourVectorMoments", m_fvmoms);
39  declareProperty("ElementLinkMoments", m_elmoms);
40  declareProperty("IntVectorMoments", m_vimoms);
41  declareProperty("FloatVectorMoments", m_vfmoms);
42  declareProperty("AssociatedParticleVectors", m_apmoms);
43  ATH_MSG_DEBUG("JetDumper::ctor: Done.");
44 }
45 
46 //**********************************************************************
47 
48 template<>
50  static const NameList empty;
51  if ( pjet == nullptr ) return empty;
52  return empty;
53 }
54 
55 template<>
57  (const Jet*) {
58  return {};
59 }
60 
61 //**********************************************************************
62 
63 int JetDumper::execute() const {
64  ATH_MSG_DEBUG("Looping over collection types...");
65  if ( evtStore()->contains<PseudoJetVector>(m_cname) ) {
66  ATH_MSG_DEBUG("Collection is pseudojets.");
67  const PseudoJetVector* pobjs = nullptr;
68  StatusCode sc = evtStore()->retrieve(pobjs, m_cname);
69  if ( !sc.isFailure() && pobjs != nullptr ) return dump_collection(pobjs, "Pseudojet");
70  } else if ( evtStore()->contains<xAOD::CaloClusterContainer>(m_cname) ) {
71  ATH_MSG_DEBUG("Collection is xAOD clusters.");
72  const xAOD::CaloClusterContainer* pclus = nullptr;
73  pclus = evtStore()->retrieve<const xAOD::CaloClusterContainer>(m_cname);
74  //StatusCode sc = evtStore()->retrieve(pclus, m_cname);
75  if ( pclus != nullptr ) return dump_collection(pclus, "Cluster");
76  } else if ( evtStore()->contains<xAOD::JetContainer>(m_cname) ) {
77  ATH_MSG_DEBUG("Collection is xAOD jets.");
78  const xAOD::JetContainer* pobjs = nullptr;
79  pobjs = evtStore()->retrieve<const xAOD::JetContainer>(m_cname);
80  if ( pobjs != nullptr ) {
81  return dump_collection(pobjs, "Jet");
82  ATH_MSG_DEBUG("Retrieved xAOD jets.");
83  } else {
84  ATH_MSG_ERROR("xAOD jet retrieval failed.");
85  }
86  } else if ( evtStore()->contains<xAOD::MuonSegmentContainer>(m_cname) ) {
87  ATH_MSG_DEBUG("Collection is xAOD muon segments.");
88  const xAOD::MuonSegmentContainer* psegs = nullptr;
89  psegs = evtStore()->retrieve<const xAOD::MuonSegmentContainer>(m_cname);
90  if ( psegs != nullptr ) return dump_collection(psegs, "Muon segment");
91  }
92  ATH_MSG_ERROR("Unable to retrieve input collection: " << m_cname);
93  return 2;
94 }
95 
96 //**********************************************************************
97 
98 void JetDumper::print() const {
99  std::string myname = "JetDumper::print: ";
100  ATH_MSG_INFO("Properties for JetDumper " << name());
101  ATH_MSG_INFO(" Container: " << m_cname);
102  ATH_MSG_INFO(" Detail: " << m_detail);
103  ATH_MSG_INFO(" LineDetail: " << m_linedetail);
104  ATH_MSG_INFO(" Max # objects: " << m_maxobj);
105 }
106 
107 //**********************************************************************
108 
109 string JetDumper::object_label(const fastjet::PseudoJet& jet, const string& label) const {
110  string sout;
111  if ( jet.has_user_info<IConstituentUserInfo>() ) {
112  const IConstituentUserInfo& cui = jet.user_info<IConstituentUserInfo>();
113  return cui.label() + " pseudojet";
114  } else {
115  return "No-CUI pseudojet";
116  }
117  return label;
118 }
119 
120 //**********************************************************************
121 
122 int JetDumper::dump_object_after_prefix(const fastjet::PseudoJet& jet, const std::string& /*objtypename*/) const {
123  const double mevtogev = 0.001;
124  // One line summary.
125  std::ostringstream ssjetline;
126  double px = mevtogev*jet.px();
127  double py = mevtogev*jet.py();
128  double pt = sqrt(px*px+py*py);
129  if ( m_linedetail > 0 ) {
130  ssjetline << "pT =" << std::setw(6) << std::fixed << std::setprecision(1) << pt << " GeV";
131  ssjetline << ", m =" << std::setw(6) << std::fixed << std::setprecision(1)
132  << mevtogev*jet.m() << " GeV";
133  ssjetline << ", eta =" << std::setw(5) << std::fixed << std::setprecision(2) << jet.eta();
134  ssjetline << ", phi =" << std::setw(5) << std::fixed << std::setprecision(2) << jet.phi();
135  }
136  if ( m_linedetail > 1 ) extra_info(&jet, ssjetline, m_linedetail);
137  msg() << ssjetline.str() << endmsg;
138  return 0;
139 }
140 
141 //**********************************************************************
142 
143 int JetDumper::dump_object_after_prefix(const xAOD::MuonSegment* pseg, const std::string& /*objtypename*/) const {
144  if ( pseg == nullptr ) return 1;
145  const xAOD::MuonSegment& seg = *pseg;
146  const double mmtom = 0.001;
147  // One line summary.
148  std::ostringstream ssline;
149  double x = mmtom*seg.x();
150  double y = mmtom*seg.y();
151  double z = mmtom*seg.z();
152  double r = sqrt(x*x+y*y);
153  double phi = atan2(y,x);
154  ssline << "r =" << std::setw(7) << std::fixed << std::setprecision(2) << r << " m";
155  ssline << ", z =" << std::setw(7) << std::fixed << std::setprecision(2) << z << " m";
156  ssline << ", phi =" << std::setw(7) << std::fixed << std::setprecision(2) << phi;
157  //if ( m_linedetail > 1 ) extra_info(&seg, ssline, m_linedetail);
158  msg() << ssline.str() << endmsg;
159  return 0;
160 }
161 
162 //**********************************************************************
163 
164 void JetDumper::get_moment(const xAOD::Jet* pjet, const std::string& name, FourVector& val) const {
165  if ( name.empty() || name == "jetP4()" ) val = pjet->jetP4();
166  else val = pjet->getAttribute<FourVector>(name);
167 }
168 
169 //**********************************************************************
170 
171 void JetDumper::get_moment(const xAOD::Jet* pjet, const std::string& name,
172  std::vector<int>& vals) const {
173  typedef std::vector<int> T;
174  vals = pjet->getAttribute<T>(name);
175 }
176 
177 //**********************************************************************
178 
179 void JetDumper::get_moment(const xAOD::Jet* pjet, const std::string& name,
180  std::vector<float>& vals) const {
181  typedef std::vector<float> T;
182  vals = pjet->getAttribute<T>(name);
183 }
184 
185 //**********************************************************************
186 
187 void JetDumper::get_moment(const xAOD::Jet* pjet, const std::string& name, std::string& val) const {
188  val = pjet->getAttribute<std::string>(name);
189 }
190 
191 //**********************************************************************
192 
194 getAssociatedParticles(const xAOD::Jet* pobj, const std::string& name, APVector& val) const {
195  pobj->getAssociatedObjects(name, val);
196 }
197 
198 //**********************************************************************
199 
201 getAssociatedLinks(const xAOD::Jet* pobj, const std::string& name, APELVector& val) const {
202  pobj->getAttribute(name, val);
203 }
204 
205 //**********************************************************************
206 
207 void JetDumper::
208 getAssociatedParticles(const xAOD::Jet* pobj, const std::string& name, MSVector& val) const {
209  pobj->getAssociatedObjects(name, val);
210 }
211 
212 //**********************************************************************
213 
215 getAssociatedLinks(const xAOD::Jet* pobj, const std::string& name, MSELVector& val) const {
216  pobj->getAttribute(name, val);
217 }
218 
219 //**********************************************************************
220 
221 std::string
222 JetDumper::get_moment_as_string(const xAOD::Jet* pjet, const std::string& name) const {
223  std::ostringstream sout;
224  // May want to try other types here.
225  // Or find some way to access the base information of the element link.
226  try {
228  if ( pjet->getAttribute(name, eljet) ) {
229  sout << "Jet " << eljet.dataID() << "[" << eljet.index() << "]";
230  return sout.str();
231  }
232  } catch (...) { }
233  try {
235  if ( pjet->getAttribute(name, elvtx) ) {
236  sout << "Vertex " << elvtx.dataID() << "[" << elvtx.index() << "]";
237  return sout.str();
238  }
239  } catch (...) { }
240  try {
242  if ( pjet->getAttribute(name, elobj) ) {
243  sout << "IParticle " << elobj.dataID() << "[" << elobj.index() << "]";
244  return sout.str();
245  }
246  } catch (...) { }
247  return "Not a known element link.";
248 }
249 
250 //**********************************************************************
251 
252 void JetDumper::extra_info(const xAOD::Jet* pjet, std::ostream& out, int iopt) const {
253  if ( iopt == 2 ) {
254  int ncon = pjet->numConstituents();
255  out << ", ncon = " << ncon;
256  }
257  if ( iopt > 2 ) {
258  int ncon = pjet->numConstituents();
259  int scon = pjet->getConstituents().size();
260  string lab = ", size/ncon=";
261  out << lab << scon << "/" << ncon;
262  }
263  if ( iopt > 3 ) {
264  const fastjet::PseudoJet* ppj = pjet->getPseudoJet();
265  if ( ppj == nullptr ) {
266  out << ", No pseudojet";
267  } else {
268  out << ", npjcon=" << ppj->constituents().size();
269  }
270  }
271 }
272 
273 //**********************************************************************
274 
275 void JetDumper::extra_info(const fastjet::PseudoJet* ppsj, std::ostream& out, int linedetail) const {
276  if ( ppsj == nullptr ) {
277  out << ", Null pseudojet";
278  return;
279  }
280  const fastjet::PseudoJet& psj = *ppsj;
281  if ( psj.has_user_info() ) {
282  const jet::IConstituentUserInfo& cui = psj.user_info<jet::IConstituentUserInfo>();
283  if ( linedetail > 1 ) {
284  out << ", ilab=" << cui.index();
285  if ( linedetail > 2 ) {
286  const xAOD::IParticle* pip = cui.particle();
287  if ( pip == nullptr ) {
288  out << ", Associated particle is null";
289  } else {
290  out << " [" << pip->container() << "/" << pip->index() << "]";
291  if ( linedetail > 3 ) out << ", IParticle @ " << pip;
292  }
293  }
294  if ( cui.isGhost() ) out << ", ghost";
295  }
296  } else {
297  out << ", No user info";
298  }
299 }
300 
301 //**********************************************************************
beamspotman.r
def r
Definition: beamspotman.py:676
xAOD::Jet_v1::getPseudoJet
const fastjet::PseudoJet * getPseudoJet() const
Definition: Jet_v1.cxx:236
JetDumper::m_floatmax
float m_floatmax
Definition: JetDumper.h:153
JetDumper::NameList
std::vector< Name > NameList
Definition: JetDumper.h:61
xAOD::MuonSegment_v1::x
float x() const
test_pyathena.px
px
Definition: test_pyathena.py:18
JetDumper::m_apmoms
NameList m_apmoms
Vector<float> moments.
Definition: JetDumper.h:163
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
JetDumper::m_maxobj
int m_maxobj
Definition: JetDumper.h:152
Jet
Basic data class defines behavior for all Jet objects The Jet class is the principal data class for...
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:47
JetDumper::getAssociatedLinks
void getAssociatedLinks(TObj *pobj, std::string name, APELVector &val) const
Definition: JetDumper.h:452
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
JetDumper::MSELVector
std::vector< MSEL > MSELVector
Definition: JetDumper.h:68
get_moment_keys< Jet, int >
JetDumper::NameList get_moment_keys< Jet, int >(const Jet *)
Definition: JetDumper.cxx:57
JetDumper::Name
std::string Name
Definition: JetDumper.h:60
test_pyathena.pt
pt
Definition: test_pyathena.py:11
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
xAOD::MuonSegment_v1
Class describing a MuonSegment.
Definition: MuonSegment_v1.h:33
JetDumper::object_label
std::string object_label(const T *pjet, const std::string &label) const
Definition: JetDumper.h:356
JetDumper.h
xAOD::JetConstituentVector::size
size_t size() const
number of constituents
Definition: JetConstituentVector.cxx:102
JetDumper::m_vfmoms
NameList m_vfmoms
Vector<int> moments.
Definition: JetDumper.h:162
xAOD::Jet_v1::jetP4
JetFourMom_t jetP4() const
The full 4-momentum of the particle : internal jet type.
Definition: Jet_v1.cxx:76
JetDumper::m_cname
std::string m_cname
Definition: JetDumper.h:148
jet::IConstituentUserInfo::particle
virtual const xAOD::IParticle * particle() const =0
JetDumper::execute
int execute() const
Method to be called for each event.
Definition: JetDumper.cxx:63
JetDumper::m_detail
int m_detail
Definition: JetDumper.h:149
xAOD::Jet_v1::getConstituents
JetConstituentVector getConstituents() const
Return a vector of consituents. The object behaves like vector<const IParticle*>. See JetConstituentV...
Definition: Jet_v1.cxx:147
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
x
#define x
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
xAOD::Jet_v1::getAttribute
bool getAttribute(AttributeID type, T &value) const
Retrieve attribute moment by enum.
JetDumper::m_prefix
int m_prefix
Definition: JetDumper.h:151
JetDumper::m_cbmoms
NameList m_cbmoms
Bool moments.
Definition: JetDumper.h:157
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MuonSegmentContainer.h
JetDumper::get_moment
void get_moment(TObj *pobj, std::string name, TMom &val) const
Definition: JetDumper.h:417
JetDumper::m_vimoms
NameList m_vimoms
Element link moments.
Definition: JetDumper.h:161
xAOD::Jet_v1::getAssociatedObjects
std::vector< const T * > getAssociatedObjects(const std::string &name) const
get associated objects as a vector<object> this compact form throws an exception if the object is not...
jet::PseudoJetVector
std::vector< fastjet::PseudoJet > PseudoJetVector
Definition: PseudoJetVector.h:21
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
JetDumper::m_bmoms
NameList m_bmoms
Int moments.
Definition: JetDumper.h:156
JetDumper::get_moment_as_string
std::string get_moment_as_string(const TObj &obj, std::string name) const
Definition: JetDumper.h:462
JetDumper::JetDumper
JetDumper(const std::string &myname)
Definition: JetDumper.cxx:24
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
z
#define z
jet::IConstituentUserInfo::isGhost
virtual bool isGhost() const
Returns true if this constituent is a ghost.
Definition: IConstituentUserInfo.cxx:26
JetDumper::m_smoms
NameList m_smoms
Bool stored as char moments.
Definition: JetDumper.h:158
JetDumper::extra_info
void extra_info(const T *, std::ostream &out, int) const
Definition: JetDumper.h:476
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
get_moment_keys< Jet, float >
JetDumper::NameList get_moment_keys< Jet, float >(const Jet *pjet)
Definition: JetDumper.cxx:49
jet::IConstituentUserInfo::index
virtual Index index() const
Definition: IConstituentUserInfo.cxx:14
jet::IConstituentUserInfo::label
virtual Label label() const =0
JetDumper::m_elmoms
NameList m_elmoms
Four-vector moments.
Definition: JetDumper.h:160
JetDumper::m_linedetail
int m_linedetail
Definition: JetDumper.h:150
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Amg::py
@ py
Definition: GeoPrimitives.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
JetDumper::APVector
std::vector< const xAOD::IParticle * > APVector
Definition: JetDumper.h:63
JetDumper::dump_collection
int dump_collection(const TList *pjets, const std::string &objtypename="Unknown") const
Definition: JetDumper.h:369
JetDumper::m_fmoms
NameList m_fmoms
Definition: JetDumper.h:154
xAOD::MuonSegment_v1::z
float z() const
Returns the y position.
JetDumper::FourVector
xAOD::JetFourMom_t FourVector
Definition: JetDumper.h:62
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
PseudoJetVector
std::vector< fastjet::PseudoJet > PseudoJetVector
Definition: JetConstituentFiller.cxx:17
Name
JetDumper::Name Name
Definition: JetDumper.cxx:19
VertexContainer.h
y
#define y
JetContainer.h
xAOD::MuonSegment_v1::y
float y() const
Returns the x position.
NameList
IJetConstituentsRetriever::NameList NameList
Definition: JetConstituentsRetriever.cxx:22
jet::IConstituentUserInfo
Definition: IConstituentUserInfo.h:26
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
JetDumper::getAssociatedParticles
void getAssociatedParticles(TObj *pobj, std::string name, APVector &val) const
Definition: JetDumper.h:449
JetDumper::APELVector
std::vector< APEL > APELVector
Definition: JetDumper.h:65
CaloClusterContainer.h
JetDumper::m_imoms
NameList m_imoms
Float moments.
Definition: JetDumper.h:155
JetDumper::dump_object_after_prefix
int dump_object_after_prefix(const T *pjet, const std::string &objtypename) const
Definition: JetDumper.h:183
SG::AuxElement::container
const SG::AuxVectorData * container() const
Return the container holding this element.
xAOD::Jet_v1::numConstituents
size_t numConstituents() const
Number of constituents in this jets (this is valid even when reading a file where the constituents ha...
Definition: Jet_v1.cxx:153
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition: Event/xAOD/xAODJet/xAODJet/Jet.h:17
JetDumper::print
void print() const
Print the state of the tool.
Definition: JetDumper.cxx:98
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
PlotCalibFromCool.vals
vals
Definition: PlotCalibFromCool.py:474
JetDumper::m_fvmoms
NameList m_fvmoms
String moments.
Definition: JetDumper.h:159