HepMC event record
Print.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014-2015 The HepMC collaboration (see AUTHORS for details)
5 //
6 ///
7 /// @file Print.cc
8 /// @brief Implementation of static \b class Print
9 ///
10 /// @todo AB: Why a static class rather than some namespaced free functions?
11 ///
12 #include "HepMC/Print.h"
13 #include "HepMC/Attribute.h"
14 
15 using namespace std;
16 
17 namespace HepMC {
18 
19 
20 void Print::content( const GenEvent &event ) {
21  cout<<"--------------------------------"<<endl;
22  cout<<"--------- EVENT CONTENT --------"<<endl;
23  cout<<"--------------------------------"<<endl;
24  cout<<endl;
25 
26  cout<<"Weights (" << event.weights().size() <<"): "<<endl;
27  FOREACH( const double w, event.weights() ) {
28  cout << w << endl;
29  }
30 
31  cout<<"Attributes:"<<endl;
32 
33  typedef map< string, map<int, shared_ptr<Attribute> > >::value_type value_type1;
34  typedef map<int, shared_ptr<Attribute> >::value_type value_type2;
35 
36  FOREACH( const value_type1& vt1, event.attributes() ) {
37  FOREACH( const value_type2& vt2, vt1.second ) {
38  cout << vt2.first << ": " << vt1.first << endl;
39  }
40  }
41 
42  cout<<"GenParticlePtr ("<<event.particles().size()<<")"<<endl;
43 
44  FOREACH( const GenParticlePtr &p, event.particles() )
45  {
47  }
48 
49  cout<<"GenVertexPtr ("<<event.vertices().size()<<")"<<endl;
50  FOREACH( const GenVertexPtr &v, event.vertices() ) {
52  }
53 
54  cout<<"-----------------------------"<<endl;
55 }
56 
57 void Print::listing( const GenEvent &event, unsigned short precision ) {
58 
59  // Find the current stream state
60  ios_base::fmtflags orig = cout.flags();
61  streamsize prec = cout.precision();
62 
63  // Set precision
64  cout.precision( precision );
65 
66  cout << "________________________________________________________________________" << endl;
67  cout << "GenEvent: #" << event.event_number() << endl;
68  cout << " Momentum units: " << Units::name(event.momentum_unit())
69  << " Position units: " << Units::name(event.length_unit()) << endl;
70  cout << " Entries in this event: " << event.vertices().size() << " vertices, "
71  << event.particles().size() << " particles, "
72  << event.weights().size() << " weights." << endl;
73 
74  const FourVector &pos = event.event_pos();
75  cout << " Position offset: " << pos.x() << ", " << pos.y() << ", " << pos.z() << ", " << pos.t() << endl;
76 
77  // Print a legend to describe the particle info
78  cout << " GenParticle Legend" << endl;
79  cout << " ID PDG ID "
80  << "( px, py, pz, E )"
81  << " Stat ProdVtx" << endl;
82  cout << "________________________________________________________________________" << endl;
83 
84  // Print all vertices
85  FOREACH( const GenVertexPtr &v, event.vertices() ) {
87  }
88 
89  // Restore the stream state
90  cout.flags(orig);
91  cout.precision(prec);
92  cout << "________________________________________________________________________" << endl;
93 }
94 
95 void Print::listing( const GenVertexPtr &v ) {
96  cout << "Vtx: ";
97  cout.width(6);
98  cout << v->id() << " stat: ";
99  cout.width(3);
100  cout << v->status();
101 
102  const FourVector &pos = v->position();
103  if( !pos.is_zero() ) {
104  cout << " (X,cT): " << pos.x()<<" "<<pos.y()<<" "<<pos.z()<<" "<<pos.t();
105  }
106  else cout << " (X,cT): 0";
107 
108  cout << endl;
109 
110  bool printed_header = false;
111 
112  // Print out all the incoming particles
113  FOREACH( const GenParticlePtr &p, v->particles_in() ) {
114  if( !printed_header ) {
115  cout << " I: ";
116  printed_header = true;
117  }
118  else cout << " ";
119 
121  }
122 
123  printed_header = false;
124 
125  // Print out all the outgoing particles
126  FOREACH( const GenParticlePtr &p, v->particles_out() ) {
127  if( !printed_header ) {
128  cout << " O: ";
129  printed_header = true;
130  }
131  else cout << " ";
132 
134  }
135 }
136 
137 void Print::listing( const GenParticlePtr &p ) {
138  cout << " ";
139  cout.width(6);
140  cout << p->id();
141  cout.width(9);
142  cout << p->pid() << " ";
143  cout.width(9);
144  cout.setf(ios::scientific, ios::floatfield);
145  cout.setf(ios_base::showpos);
146 
147  const FourVector &momentum = p->momentum();
148 
149  cout.width(9);
150  cout << momentum.px() << ",";
151  cout.width(9);
152  cout << momentum.py() << ",";
153  cout.width(9);
154  cout << momentum.pz() << ",";
155  cout.width(9);
156  cout << momentum.e() << " ";
157  cout.setf(ios::fmtflags(0), ios::floatfield);
158  cout.unsetf(ios_base::showpos);
159  cout.width(3);
160  cout << p->status();
161 
162  const GenVertexPtr prod = p->production_vertex();
163 
164  if( prod ) {
165  cout.width(6);
166  cout << prod->id();
167  }
168 
169  cout << endl;
170 }
171 
172 void Print::line(const GenVertexPtr &v) {
173  cout << "GenVertex: " << v->id() << " stat: ";
174  cout.width(3);
175  cout << v->status();
176  cout << " in: " << v->particles_in().size();
177  cout.width(3);
178  cout << " out: " << v->particles_out().size();
179 
180  const FourVector &pos = v->position();
181  cout << " has_set_position: ";
182  if( v->has_set_position() ) cout << "true";
183  else cout << "false";
184 
185  cout << " (X,cT): " << pos.x()<<", "<<pos.y()<<", "<<pos.z()<<", "<<pos.t() << endl;
186 }
187 
188 void Print::line(const GenParticlePtr &p) {
189 
190  cout << "GenParticle: ";
191  cout.width(3);
192  cout << p->id() <<" PDGID: ";
193  cout.width(5);
194  cout << p->pid();
195 
196  // Find the current stream state
197  ios_base::fmtflags orig = cout.flags();
198 
199  cout.setf(ios::scientific, ios::floatfield);
200  cout.setf(ios_base::showpos);
201  streamsize prec = cout.precision();
202 
203  // Set precision
204  cout.precision( 2 );
205 
206  const FourVector &momentum = p->momentum();
207 
208  cout << " (P,E)=" << momentum.px()
209  << "," << momentum.py()
210  << "," << momentum.pz()
211  << "," << momentum.e();
212 
213  // Restore the stream state
214  cout.flags(orig);
215  cout.precision(prec);
216 
217  GenVertexPtr prod = p->production_vertex();
218  GenVertexPtr end = p->end_vertex();
219  int prod_vtx_id = (prod) ? prod->id() : 0;
220  int end_vtx_id = (end) ? end->id() : 0;
221 
222  cout << " Stat: " << p->status()
223  << " PV: " << prod_vtx_id
224  << " EV: " << end_vtx_id
225  << endl;
226 }
227 
228 void Print::line(shared_ptr<GenCrossSection> &cs) {
229  cout << " GenCrossSection: " << cs->cross_section
230  << " " << cs->cross_section_error
231  << " " << endl;
232 }
233 
234 void Print::line(shared_ptr<GenHeavyIon> &hi) {
235  cout << " GenHeavyIon: " << hi->Ncoll_hard
236  << " " << hi->Npart_proj
237  << " " << hi->Npart_targ
238  << " " << hi->Ncoll
239  << " " << hi->spectator_neutrons
240  << " " << hi->spectator_protons
241  << " " << hi->N_Nwounded_collisions
242  << " " << hi->Nwounded_N_collisions
243  << " " << hi->Nwounded_Nwounded_collisions
244  << " " << hi->impact_parameter
245  << " " << hi->event_plane_angle
246  << " " << hi->eccentricity
247  << " " << hi->sigma_inel_NN
248  << endl;
249 }
250 
251 void Print::line(shared_ptr<GenPdfInfo> &pi) {
252  cout << " GenPdfInfo: " << pi->parton_id[0]
253  << " " << pi->parton_id[1]
254  << " " << pi->x[0]
255  << " " << pi->x[1]
256  << " " << pi->scale
257  << " " << pi->xf[0]
258  << " " << pi->xf[1]
259  << " " << pi->pdf_id[0]
260  << " " << pi->pdf_id[1]
261  << " " << endl;
262 }
263 
264 } // namespace HepMC
const std::vector< GenParticlePtr > & particles() const
Get list of particles (const)
double px() const
x-component of momentum
double y() const
y-component of position/displacement
const Units::MomentumUnit & momentum_unit() const
Get momentum unit.
static void listing(const GenEvent &event, unsigned short precision=2)
Print event in listing (HepMC2) format.
Definition: Print.cc:57
STL namespace.
const std::map< string, std::map< int, shared_ptr< Attribute > > > & attributes() const
Get list of attributes.
static void line(const GenEvent &event)
Print one-line info.
bool is_zero() const
Check if the length of this vertex is zero.
double x() const
x-component of position/displacement
Stores event-related information.
double t() const
Time component of position/displacement.
double py() const
y-component of momentum
double e() const
Energy component of momentum.
const std::vector< GenVertexPtr > & vertices() const
Get list of vertices (const)
double pz() const
z-component of momentum
Definition of template class SmartPointer.
const Units::LengthUnit & length_unit() const
Get length unit.
double z() const
z-component of position/displacement
const std::vector< double > & weights() const
Get event weight values as a vector.