ATLAS Offline Software
Loading...
Searching...
No Matches
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"
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 if ( pjet == nullptr ) return empty;
52 return empty;
53}
54
55template<>
57 (const Jet*) {
58 return {};
59}
60
61//**********************************************************************
62
63int JetDumper::execute() const {
64 ATH_MSG_DEBUG("Looping over collection types...");
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");
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");
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 }
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
98void 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
109string 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
122int 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
143int 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
164void 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
171void 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
179void 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
187void 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
194getAssociatedParticles(const xAOD::Jet* pobj, const std::string& name, APVector& val) const {
195 pobj->getAssociatedObjects(name, val);
196}
197
198//**********************************************************************
199
201getAssociatedLinks(const xAOD::Jet* pobj, const std::string& name, APELVector& val) const {
202 pobj->getAttribute(name, val);
203}
204
205//**********************************************************************
206
208getAssociatedParticles(const xAOD::Jet* pobj, const std::string& name, MSVector& val) const {
209 pobj->getAssociatedObjects(name, val);
210}
211
212//**********************************************************************
213
215getAssociatedLinks(const xAOD::Jet* pobj, const std::string& name, MSELVector& val) const {
216 pobj->getAttribute(name, val);
217}
218
219//**********************************************************************
220
221std::string
222JetDumper::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
252void 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
275void 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//**********************************************************************
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:57
JetDumper::Name Name
Definition JetDumper.cxx:19
JetDumper::NameList get_moment_keys< Jet, float >(const Jet *pjet)
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:63
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:98
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
const SG::AuxVectorData * container() const
Return the container holding this element.
size_t index() const
Return the index of this element within its container.
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:153
JetConstituentVector getConstituents() const
Return a vector of consituents. The object behaves like vector<const IParticle*>. See JetConstituentV...
Definition Jet_v1.cxx:147
const fastjet::PseudoJet * getPseudoJet() const
Definition Jet_v1.cxx:236
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:114
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