HepMC3 event record library
ReaderAsciiHepMC2.cc
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
5//
6/**
7 * @file ReaderAsciiHepMC2.cc
8 * @brief Implementation of \b class ReaderAsciiHepMC2
9 *
10 */
12
13#include "HepMC3/GenEvent.h"
14#include "HepMC3/GenVertex.h"
15#include "HepMC3/GenParticle.h"
16#include "HepMC3/GenHeavyIon.h"
17#include "HepMC3/GenPdfInfo.h"
18#include "HepMC3/Setup.h"
19
20#include <cstring>
21#include <cstdlib>
22
23namespace HepMC3 {
24
25ReaderAsciiHepMC2::ReaderAsciiHepMC2(const std::string& filename):
26 m_file(filename), m_stream(0), m_isstream(false) {
27 if( !m_file.is_open() ) {
28 ERROR( "ReaderAsciiHepMC2: could not open input file: "<<filename )
29 }
30 set_run_info(make_shared<GenRunInfo>());
32}
33// Ctor for reading from stdin
35 : m_stream(&stream), m_isstream(true)
36{
37 if( !m_stream->good() ) {
38 ERROR( "ReaderAsciiHepMC2: could not open input stream " )
39 }
40 set_run_info(make_shared<GenRunInfo>());
42}
43
45
46
48 if ( (!m_file.is_open()) && (!m_isstream) ) return false;
49
50 char peek;
51 const size_t max_buffer_size=512*512;
52 const size_t max_weights_size=256;
53 char buf[max_buffer_size];
54 bool parsed_event_header = false;
55 bool is_parsing_successful = true;
56 int parsing_result = 0;
57 unsigned int vertices_count = 0;
58 unsigned int current_vertex_particles_count = 0;
59 unsigned int current_vertex_particles_parsed= 0;
60
61 evt.clear();
63
64 // Empty cache
65 m_vertex_cache.clear();
66 m_vertex_barcodes.clear();
67
68 m_particle_cache.clear();
71 //
72 // Parse event, vertex and particle information
73 //
74 while(!failed()) {
75 m_isstream ? m_stream->getline(buf,max_buffer_size) : m_file.getline(buf,max_buffer_size);
76 if( strlen(buf) == 0 ) continue;
77 // Check for IO_GenEvent header/footer
78 if( strncmp(buf,"HepMC",5) == 0 ) {
79 if( strncmp(buf,"HepMC::Version",14) != 0 && strncmp(buf,"HepMC::IO_GenEvent",18)!=0 )
80 {
81 WARNING( "ReaderAsciiHepMC2: found unsupported expression in header. Will close the input." )
82 std::cout<<buf<<std::endl;
83 m_isstream ? m_stream->clear(ios::eofbit) : m_file.clear(ios::eofbit);
84 }
85 if(parsed_event_header) {
86 is_parsing_successful = true;
87 break;
88 }
89 continue;
90 }
91 switch(buf[0]) {
92 case 'E':
93 parsing_result = parse_event_information(evt,buf);
94 if(parsing_result<0) {
95 is_parsing_successful = false;
96 ERROR( "ReaderAsciiHepMC2: error parsing event information" )
97 }
98 else {
99 vertices_count = parsing_result;
100 m_vertex_cache.reserve(vertices_count);
101 m_particle_cache.reserve(vertices_count*3);
102 m_vertex_barcodes.reserve(vertices_count);
103 m_end_vertex_barcodes.reserve(vertices_count*3);
104 is_parsing_successful = true;
105 }
106 parsed_event_header = true;
107 break;
108 case 'V':
109 // If starting new vertex: verify if previous was fully parsed
110
111 /** @bug HepMC2 files produced with Pythia8 are known to have wrong
112 information about number of particles in vertex. Hence '<' sign */
113 if(current_vertex_particles_parsed < current_vertex_particles_count) {
114 is_parsing_successful = false;
115 break;
116 }
117 current_vertex_particles_parsed = 0;
118
119 parsing_result = parse_vertex_information(buf);
120
121 if(parsing_result<0) {
122 is_parsing_successful = false;
123 ERROR( "ReaderAsciiHepMC2: error parsing vertex information" )
124 }
125 else {
126 current_vertex_particles_count = parsing_result;
127 is_parsing_successful = true;
128 }
129 break;
130 case 'P':
131
132 parsing_result = parse_particle_information(buf);
133
134 if(parsing_result<0) {
135 is_parsing_successful = false;
136 ERROR( "ReaderAsciiHepMC2: error parsing particle information" )
137 }
138 else {
139 ++current_vertex_particles_parsed;
140 is_parsing_successful = true;
141 }
142 break;
143 case 'U':
144 is_parsing_successful = parse_units(evt,buf);
145 break;
146 case 'F':
147 is_parsing_successful = parse_pdf_info(evt,buf);
148 break;
149 case 'H':
150 is_parsing_successful = parse_heavy_ion(evt,buf);
151 break;
152 case 'N':
153 is_parsing_successful = parse_weight_names(buf);
154 break;
155 case 'C':
156 is_parsing_successful = parse_xs_info(evt,buf);
157 break;
158 default:
159 WARNING( "ReaderAsciiHepMC2: skipping unrecognised prefix: " << buf[0] )
160 is_parsing_successful = true;
161 break;
162 }
163
164 if( !is_parsing_successful ) break;
165
166 // Check for next event
167 m_isstream ? peek = m_stream->peek() : peek = m_file.peek();
168 if( parsed_event_header && peek=='E' ) break;
169 }
170
171 // Check if all particles in last vertex were parsed
172 /** @bug HepMC2 files produced with Pythia8 are known to have wrong
173 information about number of particles in vertex. Hence '<' sign */
174 if( is_parsing_successful && current_vertex_particles_parsed < current_vertex_particles_count ) {
175 ERROR( "ReaderAsciiHepMC2: not all particles parsed" )
176 is_parsing_successful = false;
177 }
178 // Check if all vertices were parsed
179 else if( is_parsing_successful && m_vertex_cache.size() != vertices_count ) {
180 ERROR( "ReaderAsciiHepMC2: not all vertices parsed" )
181 is_parsing_successful = false;
182 }
183
184 if( !is_parsing_successful ) {
185 ERROR( "ReaderAsciiHepMC2: event parsing failed. Returning empty event" )
186 DEBUG( 1, "Parsing failed at line:" << std::endl << buf )
187 evt.clear();
188 m_isstream ? m_stream->clear(ios::badbit) : m_file.clear(ios::badbit);
189 return 0;
190 }
191
192 // Restore production vertex pointers
193 for(unsigned int i=0; i<m_particle_cache.size(); ++i) {
194 if( !m_end_vertex_barcodes[i] ) continue;
195
196 for(unsigned int j=0; j<m_vertex_cache.size(); ++j) {
198 m_vertex_cache[j]->add_particle_in(m_particle_cache[i]);
199 break;
200 }
201 }
202 }
203
204 // Remove vertices with no incoming particles or no outgoing particles
205 for(unsigned int i=0; i<m_vertex_cache.size(); ++i) {
206 if( m_vertex_cache[i]->particles_in().size() == 0 ) {
207 m_vertex_cache[i] = nullptr;
208 }
209 else if( m_vertex_cache[i]->particles_out().size() == 0 ) {
210 m_vertex_cache[i] = nullptr;
211 }
212 }
213
214 // Reserve memory for the event
215 evt.reserve( m_particle_cache.size(), m_vertex_cache.size() );
216
217 // Add whole event tree in topological order
219
220 for(unsigned int i=0; i<m_particle_cache.size(); ++i) {
221 if(m_particle_cache_ghost[i]->attribute_names().size())
222 {
223 shared_ptr<DoubleAttribute> phi = m_particle_cache_ghost[i]->attribute<DoubleAttribute>("phi");
224 if (phi) m_particle_cache[i]->add_attribute("phi",phi);
225 shared_ptr<DoubleAttribute> theta = m_particle_cache_ghost[i]->attribute<DoubleAttribute>("theta");
226 if (theta) m_particle_cache[i]->add_attribute("theta",theta);
227 shared_ptr<IntAttribute> flow1 = m_particle_cache_ghost[i]->attribute<IntAttribute>("flow1");
228 if (flow1) m_particle_cache[i]->add_attribute("flow1",flow1);
229 shared_ptr<IntAttribute> flow2 = m_particle_cache_ghost[i]->attribute<IntAttribute>("flow2");
230 if (flow2) m_particle_cache[i]->add_attribute("flow2",flow2);
231 }
232 }
233
234 for(unsigned int i=0; i<m_vertex_cache.size(); ++i)
235 if(m_vertex_cache_ghost[i]->attribute_names().size())
236 {
237 for (size_t ii=0; ii<max_weights_size; ii++)
238 {
239 shared_ptr<DoubleAttribute> rs=m_vertex_cache_ghost[i]->attribute<DoubleAttribute>("weight"+to_string((long long unsigned int)ii));
240 if (!rs) break;
241 m_vertex_cache[i]->add_attribute("weight"+to_string((long long unsigned int)ii),rs);
242 }
243 }
245 m_vertex_cache_ghost.clear();
247 return 1;
248}
249
251 const char *cursor = buf;
252 int event_no = 0;
253 int vertices_count = 0;
254 int random_states_size = 0;
255 int weights_size = 0;
256 std::vector<long> random_states(0);
257 std::vector<double> weights(0);
258
259 // event number
260 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
261 event_no = atoi(cursor);
262 evt.set_event_number(event_no);
263
264 //mpi
265 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
266 shared_ptr<IntAttribute> mpi = make_shared<IntAttribute>(atoi(cursor));
267 evt.add_attribute("mpi",mpi);
268
269 //event scale
270 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
271 shared_ptr<DoubleAttribute> event_scale = make_shared<DoubleAttribute>(atof(cursor));
272 evt.add_attribute("event_scale",event_scale);
273
274 //alpha_qcd
275 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
276 shared_ptr<DoubleAttribute> alphaQCD = make_shared<DoubleAttribute>(atof(cursor));
277 evt.add_attribute("alphaQCD",alphaQCD);
278
279 //alpha_qed
280 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
281 shared_ptr<DoubleAttribute> alphaQED = make_shared<DoubleAttribute>(atof(cursor));
282 evt.add_attribute("alphaQED",alphaQED);
283
284 //signal_process_id
285 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
286 shared_ptr<IntAttribute> signal_process_id = make_shared<IntAttribute>(atoi(cursor));
287 evt.add_attribute("signal_process_id",signal_process_id);
288
289 //signal_process_vertex
290 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
291 shared_ptr<IntAttribute> signal_process_vertex = make_shared<IntAttribute>(atoi(cursor));
292 evt.add_attribute("signal_process_vertex",signal_process_vertex);
293
294 // num_vertices
295 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
296 vertices_count = atoi(cursor);
297
298 // SKIPPED: beam 1
299 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
300
301 // SKIPPED: beam 2
302 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
303
304 //random states
305 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
306 random_states_size = atoi(cursor);
307 random_states.resize(random_states_size);
308
309 for ( int i = 0; i < random_states_size; ++i ) {
310 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
311 random_states[i] = atoi(cursor);
312 }
313
314 for ( int i = 0; i < random_states_size; ++i )
315 evt.add_attribute("random_states"+to_string((long long unsigned int)i),make_shared<IntAttribute>(random_states[i])); //gcc-4.4.7 workaround
316
317 // weights
318 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
319 weights_size = atoi(cursor);
320 weights.resize(weights_size);
321
322 for ( int i = 0; i < weights_size; ++i ) {
323 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
324 weights[i] = atof(cursor);
325 }
326
327 evt.weights() = weights;
328
329 DEBUG( 10, "ReaderAsciiHepMC2: E: "<<event_no<<" ("<<vertices_count<<"V, "<<weights_size<<"W, "<<random_states_size<<"RS)" )
330
331 return vertices_count;
332}
333
334bool ReaderAsciiHepMC2::parse_units(GenEvent &evt, const char *buf) {
335 const char *cursor = buf;
336
337 // momentum
338 if( !(cursor = strchr(cursor+1,' ')) ) return false;
339 ++cursor;
340 Units::MomentumUnit momentum_unit = Units::momentum_unit(cursor);
341
342 // length
343 if( !(cursor = strchr(cursor+1,' ')) ) return false;
344 ++cursor;
345 Units::LengthUnit length_unit = Units::length_unit(cursor);
346
347 evt.set_units(momentum_unit,length_unit);
348
349 DEBUG( 10, "ReaderAsciiHepMC2: U: " << Units::name(evt.momentum_unit()) << " " << Units::name(evt.length_unit()) )
350
351 return true;
352}
353
355 GenVertexPtr data = make_shared<GenVertex>();
356 GenVertexPtr data_ghost = make_shared<GenVertex>();
357 FourVector position;
358 const char *cursor = buf;
359 int barcode = 0;
360 int num_particles_out = 0;
361 int weights_size = 0;
362 std::vector<double> weights(0);
363 // barcode
364 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
365 barcode = atoi(cursor);
366
367 // status
368 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
369 data->set_status( atoi(cursor) );
370
371 // x
372 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
373 position.setX(atof(cursor));
374
375 // y
376 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
377 position.setY(atof(cursor));
378
379 // z
380 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
381 position.setZ(atof(cursor));
382
383 // t
384 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
385 position.setT(atof(cursor));
386 data->set_position( position );
387
388 // SKIPPED: num_orphans_in
389 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
390
391 // num_particles_out
392 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
393 num_particles_out = atoi(cursor);
394
395 // weights
396
397 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
398 weights_size = atoi(cursor);
399 weights.resize(weights_size);
400
401 for ( int i = 0; i < weights_size; ++i ) {
402 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
403 weights[i] = atof(cursor);
404 }
405
406
407
408 // Add original vertex barcode to the cache
409 m_vertex_cache.push_back( data );
410 m_vertex_barcodes.push_back( barcode );
411
412 m_event_ghost->add_vertex(data_ghost);
413 for ( int i = 0; i < weights_size; ++i )
414 data_ghost->add_attribute("weight"+to_string((long long unsigned int)i),make_shared<DoubleAttribute>(weights[i])); //gcc-4.4.7 workaround
415 m_vertex_cache_ghost.push_back( data_ghost );
416
417 DEBUG( 10, "ReaderAsciiHepMC2: V: "<<-(int)m_vertex_cache.size()<<" (old barcode"<<barcode<<") "<<num_particles_out<<" particles)" )
418
419 return num_particles_out;
420}
421
423 GenParticlePtr data = make_shared<GenParticle>();
424 GenParticlePtr data_ghost = make_shared<GenParticle>();
425 m_event_ghost->add_particle(data_ghost);
426 FourVector momentum;
427 const char *cursor = buf;
428 int end_vtx = 0;
429
430 /// @note barcode is ignored
431 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
432
433 // id
434 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
435 data->set_pid( atoi(cursor) );
436
437 // px
438 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
439 momentum.setPx(atof(cursor));
440
441 // py
442 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
443 momentum.setPy(atof(cursor));
444
445 // pz
446 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
447 momentum.setPz(atof(cursor));
448
449 // pe
450 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
451 momentum.setE(atof(cursor));
452 data->set_momentum(momentum);
453
454 // m
455 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
456 data->set_generated_mass( atof(cursor) );
457
458 // status
459 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
460 data->set_status( atoi(cursor) );
461
462 //theta
463 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
464 shared_ptr<DoubleAttribute> theta = make_shared<DoubleAttribute>(atof(cursor));
465 if (theta->value()!=0.0) data_ghost->add_attribute("theta",theta);
466
467 //phi
468 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
469 shared_ptr<DoubleAttribute> phi = make_shared<DoubleAttribute>(atof(cursor));
470 if (phi->value()!=0.0) data_ghost->add_attribute("phi",phi);
471
472 // end_vtx_code
473 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
474 end_vtx = atoi(cursor);
475
476 //flow
477 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
478 int flowsize=atoi(cursor);
479
480 for (int i=0; i<flowsize; i++)
481 {
482 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
483 int flowindex=atoi(cursor);
484 if( !(cursor = strchr(cursor+1,' ')) ) return -1;
485 int flowvalue=atoi(cursor);
486 data_ghost->add_attribute("flow"+to_string((long long int)flowindex),make_shared<IntAttribute>(flowvalue));//gcc-4.4.7 workaround
487 }
488
489 // Set prod_vtx link
490 if( end_vtx == m_vertex_barcodes.back() ) {
491 m_vertex_cache.back()->add_particle_in(data);
492 end_vtx = 0;
493 }
494 else {
495 m_vertex_cache.back()->add_particle_out(data);
496 }
497
498 m_particle_cache.push_back( data );
499 m_particle_cache_ghost.push_back( data_ghost );
500 m_end_vertex_barcodes.push_back( end_vtx );
501
502 DEBUG( 10, "ReaderAsciiHepMC2: P: "<<m_particle_cache.size()<<" ( pid: "<<data->pid()<<") end vertex: "<<end_vtx )
503
504 return 0;
505}
506
507bool ReaderAsciiHepMC2::parse_xs_info(GenEvent &evt, const char *buf) {
508 const char *cursor = buf;
509 shared_ptr<GenCrossSection> xs = make_shared<GenCrossSection>();
510
511 if( !(cursor = strchr(cursor+1,' ')) ) return false;
512 double xs_val = atof(cursor);
513
514 if( !(cursor = strchr(cursor+1,' ')) ) return false;
515 double xs_err = atof(cursor);
516
517 xs->set_cross_section( xs_val , xs_err);
518 evt.add_attribute("GenCrossSection",xs);
519
520 return true;
521}
522
524 const char *cursor = buf;
525 const char *cursor2 = buf;
526 int w_count = 0;
527 vector<string> w_names;
528
529 // Ignore weight names if no GenRunInfo object
530 if( !run_info() ) return true;
531
532 if( !(cursor = strchr(cursor+1,' ')) ) return false;
533 w_count = atoi(cursor);
534
535 if( w_count <= 0 ) return false;
536
537 w_names.resize(w_count);
538
539 for( int i=0; i < w_count; ++i ) {
540 // Find pair of '"' characters
541 if( !(cursor = strchr(cursor+1,'"')) ) return false;
542 if( !(cursor2 = strchr(cursor+1,'"')) ) return false;
543
544 // Strip cursor of leading '"' character
545 ++cursor;
546
547 w_names[i].assign(cursor, cursor2-cursor);
548
549 cursor = cursor2;
550 }
551
552 run_info()->set_weight_names(w_names);
553
554 return true;
555}
556
557bool ReaderAsciiHepMC2::parse_heavy_ion(GenEvent &evt, const char *buf) {
558 shared_ptr<GenHeavyIon> hi = make_shared<GenHeavyIon>();
559 const char *cursor = buf;
560
561 if( !(cursor = strchr(cursor+1,' ')) ) return false;
562 hi->Ncoll_hard = atoi(cursor);
563
564 if( !(cursor = strchr(cursor+1,' ')) ) return false;
565 hi->Npart_proj = atoi(cursor);
566
567 if( !(cursor = strchr(cursor+1,' ')) ) return false;
568 hi->Npart_targ = atoi(cursor);
569
570 if( !(cursor = strchr(cursor+1,' ')) ) return false;
571 hi->Ncoll = atoi(cursor);
572
573 if( !(cursor = strchr(cursor+1,' ')) ) return false;
574 hi->spectator_neutrons = atoi(cursor);
575
576 if( !(cursor = strchr(cursor+1,' ')) ) return false;
577 hi->spectator_protons = atoi(cursor);
578
579 if( !(cursor = strchr(cursor+1,' ')) ) return false;
580 hi->N_Nwounded_collisions = atoi(cursor);
581
582 if( !(cursor = strchr(cursor+1,' ')) ) return false;
583 hi->Nwounded_N_collisions = atoi(cursor);
584
585 if( !(cursor = strchr(cursor+1,' ')) ) return false;
586 hi->Nwounded_Nwounded_collisions = atoi(cursor);
587
588 if( !(cursor = strchr(cursor+1,' ')) ) return false;
589 hi->impact_parameter = atof(cursor);
590
591 if( !(cursor = strchr(cursor+1,' ')) ) return false;
592 hi->event_plane_angle = atof(cursor);
593
594 if( !(cursor = strchr(cursor+1,' ')) ) return false;
595 hi->eccentricity = atof(cursor);
596
597 if( !(cursor = strchr(cursor+1,' ')) ) return false;
598 hi->sigma_inel_NN = atof(cursor);
599
600 // Not in HepMC2:
601 hi->centrality = 0.0;
602
603 evt.add_attribute("GenHeavyIon",hi);
604
605 return true;
606}
607
608bool ReaderAsciiHepMC2::parse_pdf_info(GenEvent &evt, const char *buf) {
609 shared_ptr<GenPdfInfo> pi = make_shared<GenPdfInfo>();
610 const char *cursor = buf;
611
612 if( !(cursor = strchr(cursor+1,' ')) ) return false;
613 pi->parton_id[0] = atoi(cursor);
614
615 if( !(cursor = strchr(cursor+1,' ')) ) return false;
616 pi->parton_id[1] = atoi(cursor);
617
618 if( !(cursor = strchr(cursor+1,' ')) ) return false;
619 pi->x[0] = atof(cursor);
620
621 if( !(cursor = strchr(cursor+1,' ')) ) return false;
622 pi->x[1] = atof(cursor);
623
624 if( !(cursor = strchr(cursor+1,' ')) ) return false;
625 pi->scale = atof(cursor);
626
627 if( !(cursor = strchr(cursor+1,' ')) ) return false;
628 pi->xf[0] = atof(cursor);
629
630 if( !(cursor = strchr(cursor+1,' ')) ) return false;
631 pi->xf[1] = atof(cursor);
632
633 //For compatibility with original HepMC2
634 bool pdfids=true;
635 if( !(cursor = strchr(cursor+1,' ')) ) pdfids=false;
636 if(pdfids) pi->pdf_id[0] = atoi(cursor);
637 else pi->pdf_id[0] =0;
638
639 if(pdfids) if( !(cursor = strchr(cursor+1,' ')) ) pdfids=false;
640 if(pdfids) pi->pdf_id[1] = atoi(cursor);
641 else pi->pdf_id[1] =0;
642
643 evt.add_attribute("GenPdfInfo",pi);
644
645 return true;
646}
647bool ReaderAsciiHepMC2::failed() { return m_isstream ? (bool)m_stream->rdstate() :(bool)m_file.rdstate(); }
648
650 if (m_event_ghost) { m_event_ghost->clear(); delete m_event_ghost; m_event_ghost=nullptr;}
651 if( !m_file.is_open() ) return;
652 m_file.close();
653}
654
655} // namespace HepMC3
#define WARNING(MESSAGE)
Macro for printing warning messages.
Definition Errors.h:26
#define DEBUG(LEVEL, MESSAGE)
Macro for printing debug messages with appropriate debug level.
Definition Errors.h:32
#define ERROR(MESSAGE)
Macro for printing error messages.
Definition Errors.h:23
Definition of class GenEvent.
Definition of attribute class GenHeavyIon.
Definition of class GenParticle.
Definition of event attribute class GenPdfInfo.
Definition of class GenVertex.
Definition of class ReaderAsciiHepMC2.
Definition of class Setup.
Attribute that holds a real number as a double.
Definition Attribute.h:242
Generic 4-vector.
Definition FourVector.h:35
void setE(double ee)
Definition FourVector.h:116
void setT(double tt)
Definition FourVector.h:87
void setPz(double pzz)
Definition FourVector.h:109
void setY(double yy)
Definition FourVector.h:73
void setPy(double pyy)
Definition FourVector.h:102
void setX(double xx)
Definition FourVector.h:66
void setPx(double pxx)
Definition FourVector.h:95
void setZ(double zz)
Definition FourVector.h:80
Stores event-related information.
Definition GenEvent.h:42
void add_tree(const std::vector< GenParticlePtr > &particles)
Add whole tree in topological order.
Definition GenEvent.cc:268
void add_vertex(GenVertexPtr v)
Add vertex.
Definition GenEvent.cc:98
void add_particle(GenParticlePtr p)
Add particle.
Definition GenEvent.cc:50
void set_units(Units::MomentumUnit new_momentum_unit, Units::LengthUnit new_length_unit)
Change event units Converts event from current units to new ones.
Definition GenEvent.cc:396
void add_attribute(const string &name, const shared_ptr< Attribute > &att, const int &id=0)
Add event attribute to event.
Definition GenEvent.h:209
void set_event_number(const int &num)
Set event number.
Definition GenEvent.h:138
void set_run_info(shared_ptr< GenRunInfo > run)
Set the GenRunInfo object by smart pointer.
Definition GenEvent.h:129
const Units::MomentumUnit & momentum_unit() const
Get momentum unit.
Definition GenEvent.h:141
const Units::LengthUnit & length_unit() const
Get length unit.
Definition GenEvent.h:143
const std::vector< double > & weights() const
Get event weight values as a vector.
Definition GenEvent.h:87
void clear()
Remove contents of this event.
Definition GenEvent.cc:610
void reserve(const size_t &particles, const size_t &vertices=0)
Reserve memory for particles and vertices.
Definition GenEvent.cc:390
Attribute that holds an Integer implemented as an int.
Definition Attribute.h:158
bool m_isstream
toggles usage of m_file or m_stream
vector< int > m_vertex_barcodes
Old vertex barcodes.
bool read_event(GenEvent &evt)
Implementation of Reader::read_event.
int parse_event_information(GenEvent &evt, const char *buf)
Parse event.
vector< int > m_end_vertex_barcodes
Old end vertex barcodes.
bool parse_pdf_info(GenEvent &evt, const char *buf)
Parse pdf information.
std::ifstream m_file
Input file.
bool parse_units(GenEvent &evt, const char *buf)
Parse units.
int parse_particle_information(const char *buf)
Parse particle.
void close()
Close file stream.
ReaderAsciiHepMC2(const std::string &filename)
Default constructor.
vector< GenParticlePtr > m_particle_cache
Particle cache.
bool parse_weight_names(const char *buf)
Parse weight names.
bool failed()
Return status of the stream.
bool parse_xs_info(GenEvent &evt, const char *buf)
Parse pdf information.
vector< GenVertexPtr > m_vertex_cache
Vertex cache.
std::istream * m_stream
For ctor when reading from stdin.
vector< GenParticlePtr > m_particle_cache_ghost
Particle cache for attributes.
vector< GenVertexPtr > m_vertex_cache_ghost
Vertex cache for attributes.
int parse_vertex_information(const char *buf)
Parse vertex.
bool parse_heavy_ion(GenEvent &evt, const char *buf)
Parse heavy ion information.
GenEvent * m_event_ghost
To save particle and verstex attributes.
void set_run_info(shared_ptr< GenRunInfo > run)
Set the global GenRunInfo object.
Definition Reader.h:46
shared_ptr< GenRunInfo > run_info() const
Get the global GenRunInfo object.
Definition Reader.h:39
static LengthUnit length_unit(const std::string &name)
Get length unit based on its name.
Definition Units.h:46
LengthUnit
Position units.
Definition Units.h:32
static std::string name(MomentumUnit u)
Get name of momentum unit.
Definition Units.h:56
MomentumUnit
Momentum units.
Definition Units.h:29
static MomentumUnit momentum_unit(const std::string &name)
Get momentum unit based on its name.
Definition Units.h:36
HepMC3 main namespace.
Definition ReaderGZ.h:28