ATLAS Offline Software
Loading...
Searching...
No Matches
JetDumper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// JetDumper.cxx
6
7#include "JetRec/JetDumper.h"
12#include <iostream>
13
14using std::string;
15using xAOD::Jet;
18
21
22//**********************************************************************
23
24JetDumper::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
48template<>
50 static const NameList empty;
51 return empty;
52}
53
54template<>
56 (const Jet*) {
57 return {};
58}
59
60//**********************************************************************
61
62int JetDumper::execute() const {
63 ATH_MSG_DEBUG("Looping over collection types...");
65 ATH_MSG_DEBUG("Collection is pseudojets.");
66 const PseudoJetVector* pobjs = nullptr;
67 StatusCode sc = evtStore()->retrieve(pobjs, m_cname);
68 if ( !sc.isFailure() && pobjs != nullptr ) return dump_collection(pobjs, "Pseudojet");
70 ATH_MSG_DEBUG("Collection is xAOD clusters.");
71 const xAOD::CaloClusterContainer* pclus = nullptr;
72 pclus = evtStore()->retrieve<const xAOD::CaloClusterContainer>(m_cname);
73 //StatusCode sc = evtStore()->retrieve(pclus, m_cname);
74 if ( pclus != nullptr ) return dump_collection(pclus, "Cluster");
76 ATH_MSG_DEBUG("Collection is xAOD jets.");
77 const xAOD::JetContainer* pobjs = nullptr;
78 pobjs = evtStore()->retrieve<const xAOD::JetContainer>(m_cname);
79 if ( pobjs != nullptr ) {
80 return dump_collection(pobjs, "Jet");
81 ATH_MSG_DEBUG("Retrieved xAOD jets.");
82 } else {
83 ATH_MSG_ERROR("xAOD jet retrieval failed.");
84 }
86 ATH_MSG_DEBUG("Collection is xAOD muon segments.");
87 const xAOD::MuonSegmentContainer* psegs = nullptr;
88 psegs = evtStore()->retrieve<const xAOD::MuonSegmentContainer>(m_cname);
89 if ( psegs != nullptr ) return dump_collection(psegs, "Muon segment");
90 }
91 ATH_MSG_ERROR("Unable to retrieve input collection: " << m_cname);
92 return 2;
93}
94
95//**********************************************************************
96
97void JetDumper::print() const {
98 std::string myname = "JetDumper::print: ";
99 ATH_MSG_INFO("Properties for JetDumper " << name());
100 ATH_MSG_INFO(" Container: " << m_cname);
101 ATH_MSG_INFO(" Detail: " << m_detail);
102 ATH_MSG_INFO(" LineDetail: " << m_linedetail);
103 ATH_MSG_INFO(" Max # objects: " << m_maxobj);
104}
105
106//**********************************************************************
107
108string JetDumper::object_label(const fastjet::PseudoJet& jet, const string& label) const {
109 string sout;
110 if ( jet.has_user_info<IConstituentUserInfo>() ) {
111 const IConstituentUserInfo& cui = jet.user_info<IConstituentUserInfo>();
112 return cui.label() + " pseudojet";
113 } else {
114 return "No-CUI pseudojet";
115 }
116 return label;
117}
118
119//**********************************************************************
120
121int JetDumper::dump_object_after_prefix(const fastjet::PseudoJet& jet, const std::string& /*objtypename*/) const {
122 const double mevtogev = 0.001;
123 // One line summary.
124 std::ostringstream ssjetline;
125 double px = mevtogev*jet.px();
126 double py = mevtogev*jet.py();
127 double pt = sqrt(px*px+py*py);
128 if ( m_linedetail > 0 ) {
129 ssjetline << "pT =" << std::setw(6) << std::fixed << std::setprecision(1) << pt << " GeV";
130 ssjetline << ", m =" << std::setw(6) << std::fixed << std::setprecision(1)
131 << mevtogev*jet.m() << " GeV";
132 ssjetline << ", eta =" << std::setw(5) << std::fixed << std::setprecision(2) << jet.eta();
133 ssjetline << ", phi =" << std::setw(5) << std::fixed << std::setprecision(2) << jet.phi();
134 }
135 if ( m_linedetail > 1 ) extra_info(&jet, ssjetline, m_linedetail);
136 msg() << ssjetline.str() << endmsg;
137 return 0;
138}
139
140//**********************************************************************
141
142int JetDumper::dump_object_after_prefix(const xAOD::MuonSegment* pseg, const std::string& /*objtypename*/) const {
143 if ( pseg == nullptr ) return 1;
144 const xAOD::MuonSegment& seg = *pseg;
145 const double mmtom = 0.001;
146 // One line summary.
147 std::ostringstream ssline;
148 double x = mmtom*seg.x();
149 double y = mmtom*seg.y();
150 double z = mmtom*seg.z();
151 double r = sqrt(x*x+y*y);
152 double phi = atan2(y,x);
153 ssline << "r =" << std::setw(7) << std::fixed << std::setprecision(2) << r << " m";
154 ssline << ", z =" << std::setw(7) << std::fixed << std::setprecision(2) << z << " m";
155 ssline << ", phi =" << std::setw(7) << std::fixed << std::setprecision(2) << phi;
156 //if ( m_linedetail > 1 ) extra_info(&seg, ssline, m_linedetail);
157 msg() << ssline.str() << endmsg;
158 return 0;
159}
160
161//**********************************************************************
162
163void JetDumper::get_moment(const xAOD::Jet* pjet, const std::string& name, FourVector& val) const {
164 if ( name.empty() || name == "jetP4()" ) val = pjet->jetP4();
165 else val = pjet->getAttribute<FourVector>(name);
166}
167
168//**********************************************************************
169
170void JetDumper::get_moment(const xAOD::Jet* pjet, const std::string& name,
171 std::vector<int>& vals) const {
172 typedef std::vector<int> T;
173 vals = pjet->getAttribute<T>(name);
174}
175
176//**********************************************************************
177
178void JetDumper::get_moment(const xAOD::Jet* pjet, const std::string& name,
179 std::vector<float>& vals) const {
180 typedef std::vector<float> T;
181 vals = pjet->getAttribute<T>(name);
182}
183
184//**********************************************************************
185
186void JetDumper::get_moment(const xAOD::Jet* pjet, const std::string& name, std::string& val) const {
187 val = pjet->getAttribute<std::string>(name);
188}
189
190//**********************************************************************
191
193getAssociatedParticles(const xAOD::Jet* pobj, const std::string& name, APVector& val) const {
194 bool ok [[maybe_unused]] = pobj->getAssociatedObjects(name, val);
195}
196
197//**********************************************************************
198
200getAssociatedLinks(const xAOD::Jet* pobj, const std::string& name, APELVector& val) const {
201 pobj->getAttribute(name, val);
202}
203
204//**********************************************************************
205
207getAssociatedParticles(const xAOD::Jet* pobj, const std::string& name, MSVector& val) const {
208 bool ok [[maybe_unused]] = pobj->getAssociatedObjects(name, val);
209}
210
211//**********************************************************************
212
214getAssociatedLinks(const xAOD::Jet* pobj, const std::string& name, MSELVector& val) const {
215 pobj->getAttribute(name, val);
216}
217
218//**********************************************************************
219
220std::string
221JetDumper::get_moment_as_string(const xAOD::Jet* pjet, const std::string& name) const {
222 std::ostringstream sout;
223 // May want to try other types here.
224 // Or find some way to access the base information of the element link.
225 try {
227 if ( pjet->getAttribute(name, eljet) ) {
228 sout << "Jet " << eljet.dataID() << "[" << eljet.index() << "]";
229 return sout.str();
230 }
231 } catch (...) { }
232 try {
234 if ( pjet->getAttribute(name, elvtx) ) {
235 sout << "Vertex " << elvtx.dataID() << "[" << elvtx.index() << "]";
236 return sout.str();
237 }
238 } catch (...) { }
239 try {
241 if ( pjet->getAttribute(name, elobj) ) {
242 sout << "IParticle " << elobj.dataID() << "[" << elobj.index() << "]";
243 return sout.str();
244 }
245 } catch (...) { }
246 return "Not a known element link.";
247}
248
249//**********************************************************************
250
251void JetDumper::extra_info(const xAOD::Jet* pjet, std::ostream& out, int iopt) const {
252 if ( iopt == 2 ) {
253 int ncon = pjet->numConstituents();
254 out << ", ncon = " << ncon;
255 }
256 if ( iopt > 2 ) {
257 int ncon = pjet->numConstituents();
258 int scon = pjet->getConstituents().size();
259 string lab = ", size/ncon=";
260 out << lab << scon << "/" << ncon;
261 }
262 if ( iopt > 3 ) {
263 const fastjet::PseudoJet* ppj = pjet->getPseudoJet();
264 if ( ppj == nullptr ) {
265 out << ", No pseudojet";
266 } else {
267 out << ", npjcon=" << ppj->constituents().size();
268 }
269 }
270}
271
272//**********************************************************************
273
274void JetDumper::extra_info(const fastjet::PseudoJet* ppsj, std::ostream& out, int linedetail) const {
275 if ( ppsj == nullptr ) {
276 out << ", Null pseudojet";
277 return;
278 }
279 const fastjet::PseudoJet& psj = *ppsj;
280 if ( psj.has_user_info() ) {
281 const jet::IConstituentUserInfo& cui = psj.user_info<jet::IConstituentUserInfo>();
282 if ( linedetail > 1 ) {
283 out << ", ilab=" << cui.index();
284 if ( linedetail > 2 ) {
285 const xAOD::IParticle* pip = cui.particle();
286 if ( pip == nullptr ) {
287 out << ", Associated particle is null";
288 } else {
289 out << " [" << pip->container() << "/" << pip->index() << "]";
290 if ( linedetail > 3 ) out << ", IParticle @ " << pip;
291 }
292 }
293 if ( cui.isGhost() ) out << ", ghost";
294 }
295 } else {
296 out << ", No user info";
297 }
298}
299
300//**********************************************************************
Scalar phi() const
phi method
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
IJetConstituentsRetriever::NameList NameList
JetDumper::NameList get_moment_keys< Jet, int >(const Jet *)
Definition JetDumper.cxx:56
JetDumper::Name Name
Definition JetDumper.cxx:19
JetDumper::NameList get_moment_keys< Jet, float >(const Jet *)
Definition JetDumper.cxx:49
static Double_t sc
#define y
#define x
#define z
static const Attributes_t empty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
JetDumper(const std::string &myname)
Definition JetDumper.cxx:24
void getAssociatedLinks(TObj *pobj, std::string name, APELVector &val) const
Definition JetDumper.h:452
NameList m_bmoms
Int moments.
Definition JetDumper.h:156
NameList m_fvmoms
String moments.
Definition JetDumper.h:159
NameList m_imoms
Float moments.
Definition JetDumper.h:155
std::string m_cname
Definition JetDumper.h:148
std::vector< MSEL > MSELVector
Definition JetDumper.h:68
void getAssociatedParticles(TObj *pobj, std::string name, APVector &val) const
Definition JetDumper.h:449
int m_detail
Definition JetDumper.h:149
std::vector< APEL > APELVector
Definition JetDumper.h:65
void get_moment(TObj *pobj, std::string name, TMom &val) const
Definition JetDumper.h:417
std::vector< const xAOD::MuonSegment * > MSVector
Definition JetDumper.h:66
std::string get_moment_as_string(const TObj &obj, std::string name) const
Definition JetDumper.h:462
float m_floatmax
Definition JetDumper.h:153
NameList m_smoms
Bool stored as char moments.
Definition JetDumper.h:158
NameList m_fmoms
Definition JetDumper.h:154
NameList m_cbmoms
Bool moments.
Definition JetDumper.h:157
NameList m_vfmoms
Vector<int> moments.
Definition JetDumper.h:162
NameList m_vimoms
Element link moments.
Definition JetDumper.h:161
int dump_object_after_prefix(const T *pjet, const std::string &objtypename) const
Definition JetDumper.h:183
void extra_info(const T *, std::ostream &out, int) const
Definition JetDumper.h:476
int m_maxobj
Definition JetDumper.h:152
int m_prefix
Definition JetDumper.h:151
std::string Name
Definition JetDumper.h:60
NameList m_elmoms
Four-vector moments.
Definition JetDumper.h:160
std::vector< const xAOD::IParticle * > APVector
Definition JetDumper.h:63
std::string object_label(const T *pjet, const std::string &label) const
Definition JetDumper.h:356
int m_linedetail
Definition JetDumper.h:150
int execute() const
Method to be called for each event.
Definition JetDumper.cxx:62
int dump_collection(const TList *pjets, const std::string &objtypename="Unknown") const
Definition JetDumper.h:369
void print() const
Print the state of the tool.
Definition JetDumper.cxx:97
xAOD::JetFourMom_t FourVector
Definition JetDumper.h:62
std::vector< Name > NameList
Definition JetDumper.h:61
NameList m_apmoms
Vector<float> moments.
Definition JetDumper.h:163
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
Class providing the definition of the 4-vector interface.
size_t size() const
number of constituents
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:155
JetConstituentVector getConstituents() const
Return a vector of consituents. The object behaves like vector<const IParticle*>. See JetConstituentV...
Definition Jet_v1.cxx:149
const fastjet::PseudoJet * getPseudoJet() const
Definition Jet_v1.cxx:247
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...
bool getAttribute(AttributeID type, T &value) const
Retrieve attribute moment by enum.
JetFourMom_t jetP4() const
The full 4-momentum of the particle : internal jet type.
Definition Jet_v1.cxx:76
float y() const
Returns the x position.
float z() const
Returns the y position.
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:116
std::string label(const std::string &format, int i)
Definition label.h:19
std::vector< fastjet::PseudoJet > PseudoJetVector
Jet_v1 Jet
Definition of the current "jet version".
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
MuonSegment_v1 MuonSegment
Reference the current persistent version:
MsgStream & msg
Definition testRead.cxx:32