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