File: Print.cc

package info (click to toggle)
hepmc3 3.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 14,116 kB
  • sloc: fortran: 66,849; cpp: 13,604; ansic: 1,374; xml: 109; sh: 72; makefile: 33
file content (340 lines) | stat: -rw-r--r-- 10,116 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
// -*- C++ -*-
//
// This file is part of HepMC
// Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
//
///
/// @file Print.cc
/// @brief Implementation of static \b class Print
///
///
#include "HepMC3/Print.h"
#include "HepMC3/Attribute.h"


namespace HepMC3 {
using namespace std;

void Print::content( std::ostream& os, const GenEvent &event ) {
    os<<"--------------------------------"<<endl;
    os<<"--------- EVENT CONTENT --------"<<endl;
    os<<"--------------------------------"<<endl;
    os<<endl;

    os<<"Weights (" << event.weights().size() <<"): "<<endl;
    for (std::vector<double>::const_iterator w=event.weights().begin(); w!=event.weights().end(); ++w )
        os <<" "<<*w;


    os<<"Attributes:"<<endl;

    for( auto vt1: event.attributes() ) {
        for( auto vt2: vt1.second ) {
            os << vt2.first << ": " << vt1.first << endl;
        }
    }

    os<<"GenParticlePtr ("<<event.particles().size()<<")"<<endl;

    for( ConstGenParticlePtr p: event.particles()) {
        Print::line(p,true);
    }

    os<<"GenVertexPtr ("<<event.vertices().size()<<")"<<endl;
    for( ConstGenVertexPtr v: event.vertices() ) {
        Print::line(v);
    }

    os<<"-----------------------------"<<endl;
}

void Print::listing( std::ostream& os, const GenEvent &event, unsigned short precision ) {

    // Find the current stream state
    ios_base::fmtflags orig = os.flags();
    streamsize         prec = os.precision();

    // Set precision
    os.precision( precision );

    os << "________________________________________________________________________" << endl;
    os << "GenEvent: #" << event.event_number() << endl;
    os << " Momentum units: " << Units::name(event.momentum_unit())
       << " Position units: " << Units::name(event.length_unit()) << endl;
    os << " Entries in this event: " << event.vertices().size() << " vertices, "
       << event.particles().size() << " particles, "
       << event.weights().size()   << " weights." << endl;

    const FourVector &pos = event.event_pos();
    os << " Position offset: " << pos.x() << ", " << pos.y() << ", " << pos.z() << ", " << pos.t() << endl;

    // Print a legend to describe the particle info
    os << "                                    GenParticle Legend" << endl;
    os << "         ID    PDG ID   "
       << "( px,       py,       pz,     E )"
       << "   Stat ProdVtx" << endl;
    os << "________________________________________________________________________" << endl;

    // Print all vertices
    for(ConstGenVertexPtr v: event.vertices() ) {
        Print::listing(os,v);
    }

    // Restore the stream state
    os.flags(orig);
    os.precision(prec);
    os << "________________________________________________________________________" << endl;
}

void Print::listing(std::ostream& os, const GenRunInfo &ri, unsigned short precision) {

    // Find the current stream state
    ios_base::fmtflags orig = os.flags();
    streamsize         prec = os.precision();

    // Set precision
    os.precision( precision );

    os << "________________________________________________________________________" << endl;
    os << "GenRunInfo:" << endl;

    vector<string> names = ri.weight_names();
    os << " Names: ( ";
    for (auto n: names) os<<n;
    os<<" )"<< endl;

    os << " Tools: "<< endl;

    for(auto t: ri.tools()) {
        Print::line(os,t);
    }
    os<<"Attributes:"<<endl;
    for ( auto att: ri.attributes() ) {
        string st;
        if ( ! att.second->to_string(st) ) {
            WARNING ("Print::listing: problem serializing attribute: "<< att.first )
        }
        else { os<<att.first<<" "<<att.second->to_string(st);}
        os<<endl;
    }

    // Restore the stream state
    os.flags(orig);
    os.precision(prec);
    os << "________________________________________________________________________" << endl;
}

void Print::listing( std::ostream& os, ConstGenVertexPtr v ) {
    os << "Vtx: ";
    os.width(6);
    os << v->id() << " stat: ";
    os.width(3);
    os << v->status();

    const FourVector &pos = v->position();
    if( !pos.is_zero() ) {
        os << " (X,cT): " << pos.x()<<" "<<pos.y()<<" "<<pos.z()<<" "<<pos.t();
    }
    else os << " (X,cT): 0";

    os << endl;

    bool printed_header = false;

    // Print out all the incoming particles
    for(ConstGenParticlePtr p: v->particles_in() ) {
        if( !printed_header ) {
            os << " I: ";
            printed_header = true;
        }
        else os << "    ";

        Print::listing(os, p);
    }

    printed_header = false;

    // Print out all the outgoing particles
    for(ConstGenParticlePtr p: v->particles_out() ) {
        if( !printed_header ) {
            os << " O: ";
            printed_header = true;
        }
        else os << "    ";

        Print::listing(os, p);
    }
}

void Print::listing( std::ostream& os, ConstGenParticlePtr p ) {
    os << " ";
    os.width(6);
    os << p->id();
    os.width(9);
    os << p->pid() << " ";
    os.width(9);
    os.setf(ios::scientific, ios::floatfield);
    os.setf(ios_base::showpos);

    const FourVector &momentum = p->momentum();

    os.width(9);
    os << momentum.px() << ",";
    os.width(9);
    os << momentum.py() << ",";
    os.width(9);
    os << momentum.pz() << ",";
    os.width(9);
    os << momentum.e() << " ";
    os.setf(ios::fmtflags(0), ios::floatfield);
    os.unsetf(ios_base::showpos);
    os.width(3);
    os << p->status();

    ConstGenVertexPtr prod = p->production_vertex();

    if( prod ) {
        os.width(6);
        os << prod->id();
    }

    os << endl;
}
void Print::line(std::ostream& os, const GenEvent &event, bool attributes) {
    os <<"GenEvent: #" << event.event_number();
    if(attributes) for (std::vector<std::string>::const_iterator s=event.attribute_names().begin(); s!=event.attribute_names().end(); ++s)
            os<<" "<<*s<<"="<<event.attribute_as_string(*s);
}

void Print::line(std::ostream& os, const GenRunInfo &RunInfo, bool attributes) {
    os <<"GenRunInfo: Number of tools:" << RunInfo.tools().size();
    if(attributes) for (std::vector<std::string>::const_iterator s=RunInfo.attribute_names().begin(); s!=RunInfo.attribute_names().end(); ++s)
            os<<" "<<*s<<"="<<RunInfo.attribute_as_string(*s);
}

void Print::line(std::ostream& os, const GenRunInfo::ToolInfo& t) {
    os<<"GenRunInfo::ToolInfo "<<t.name<<" "<<t.version<<" "<<t.description;
}

void Print::line(std::ostream& os, ConstGenVertexPtr v, bool attributes) {
    os << "GenVertex:  " << v->id() << " stat: ";
    os.width(3);
    os << v->status();
    os << " in: "  << v->particles_in().size();
    os.width(3);
    os << " out: " << v->particles_out().size();

    const FourVector &pos = v->position();
    os << " has_set_position: ";
    if( v->has_set_position() ) os << "true";
    else                        os << "false";

    os << " (X,cT): " << pos.x()<<", "<<pos.y()<<", "<<pos.z()<<", "<<pos.t();
    if(attributes)for (std::vector<std::string>::const_iterator s= v->attribute_names().begin(); s!= v->attribute_names().end(); ++s)
            os<<" "<<*s<<"="<<v->attribute_as_string(*s);

}

void Print::line(std::ostream& os, const FourVector& p) {

    os << "FourVector: ";
    // Find the current stream state
    ios_base::fmtflags orig = os.flags();
    os.setf(ios::scientific, ios::floatfield);
    os.setf(ios_base::showpos);
    streamsize prec = os.precision();
    // Set precision
    os.precision( 2 );
    os << " (P,E)=" << p.x()
       << "," << p.y()
       << "," << p.z()
       << "," << p.e();

    // Restore the stream state
    os.flags(orig);
    os.precision(prec);
}

void Print::line(std::ostream& os, ConstGenParticlePtr p, bool attributes) {

    os << "GenParticle: ";
    os.width(3);
    os << p->id() <<" PDGID: ";
    os.width(5);
    os << p->pid();

    // Find the current stream state
    ios_base::fmtflags orig = os.flags();

    os.setf(ios::scientific, ios::floatfield);
    os.setf(ios_base::showpos);
    streamsize prec = os.precision();

    // Set precision
    os.precision( 2 );

    const FourVector &momentum = p->momentum();

    os << " (P,E)=" << momentum.px()
       << "," << momentum.py()
       << "," << momentum.pz()
       << "," << momentum.e();

    // Restore the stream state
    os.flags(orig);
    os.precision(prec);

    ConstGenVertexPtr prod = p->production_vertex();
    ConstGenVertexPtr end  = p->end_vertex();
    int prod_vtx_id   = (prod) ? prod->id() : 0;
    int end_vtx_id    = (end)  ? end->id()  : 0;

    os << " Stat: " << p->status()
       << " PV: " << prod_vtx_id
       << " EV: " << end_vtx_id
       << " Attr: " << (*p).attribute_names().size();

    if(attributes)
    {
        std::vector<std::string> names     =p->attribute_names();
        for (auto ss: names)
            os<<" "<<ss<<"="<<(*p).attribute_as_string(ss);
    }
}

void Print::line(std::ostream& os, shared_ptr<GenCrossSection> &cs) {
    os << " GenCrossSection: " << cs->xsec(0)
       << " " << cs->xsec_err(0)
       << " " << cs->get_accepted_events()
       << " " << cs->get_attempted_events();
}

void Print::line(std::ostream& os, shared_ptr<GenHeavyIon> &hi) {
    os << " GenHeavyIon: " << hi->Ncoll_hard
       << " " << hi->Npart_proj
       << " " << hi->Npart_targ
       << " " << hi->Ncoll
       << " " << hi->spectator_neutrons
       << " " << hi->spectator_protons
       << " " << hi->N_Nwounded_collisions
       << " " << hi->Nwounded_N_collisions
       << " " << hi->Nwounded_Nwounded_collisions
       << " " << hi->impact_parameter
       << " " << hi->event_plane_angle
       << " " << hi->eccentricity
       << " " << hi->sigma_inel_NN;
}

void Print::line(std::ostream& os, shared_ptr<GenPdfInfo> &pi) {
    os << " GenPdfInfo: " << pi->parton_id[0]
       << " " << pi->parton_id[1]
       << " " << pi->x[0]
       << " " << pi->x[1]
       << " " << pi->scale
       << " " << pi->xf[0]
       << " " << pi->xf[1]
       << " " << pi->pdf_id[0]
       << " " << pi->pdf_id[1];
}

} // namespace HepMC3