HepMC3 event record library
WriterHEPEVT.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 WriterHEPEVT.cc
8  * @brief Implementation of \b class WriterHEPEVT
9  *
10  */
11 #include <sstream>
12 #include <cstdio> // sprintf
13 #include "HepMC3/WriterHEPEVT.h"
14 #include "HepMC3/HEPEVT_Wrapper.h"
15 #include "HepMC3/Print.h"
16 namespace HepMC3
17 {
18 
19 WriterHEPEVT::WriterHEPEVT(const std::string &filename): m_events_count(0)
20 {
21  m_file=fopen(filename.c_str(),"w");
22  hepevtbuffer=(char*)(new struct HEPEVT());
24 }
25 
26 void WriterHEPEVT::write_hepevt_particle( int index, bool iflong )
27 {
28  fprintf(m_file,"% 8i% 8i",HEPEVT_Wrapper::status(index), HEPEVT_Wrapper::id(index));
29  if (iflong)
30  {
31  fprintf(m_file,"% 8i% 8i",HEPEVT_Wrapper::first_parent(index),HEPEVT_Wrapper::last_parent(index));
32  fprintf(m_file,"% 8i% 8i",HEPEVT_Wrapper::first_child(index),HEPEVT_Wrapper::last_child(index));
33  fprintf(m_file,"% 19.8E% 19.8E% 19.8E% 19.8E% 19.8E\n",HEPEVT_Wrapper::px(index),HEPEVT_Wrapper::py(index),HEPEVT_Wrapper::pz(index),HEPEVT_Wrapper::e(index),HEPEVT_Wrapper::m(index));
34  fprintf(m_file, "%-48s% 19.8E% 19.8E% 19.8E% 19.8E\n"," ",HEPEVT_Wrapper::x(index),HEPEVT_Wrapper::y(index),HEPEVT_Wrapper::z(index),HEPEVT_Wrapper::t(index));
35  }
36  else
37  {
38  fprintf(m_file,"% 8i% 8i",HEPEVT_Wrapper::first_child(index),HEPEVT_Wrapper::last_child(index));
39  fprintf(m_file,"% 19.8E% 19.8E% 19.8E% 19.8E\n",HEPEVT_Wrapper::px(index),HEPEVT_Wrapper::py(index),HEPEVT_Wrapper::pz(index),HEPEVT_Wrapper::m(index));
40  }
41 }
42 
44 {
46 }
47 
49 {
53  for( int i=1; i<=HEPEVT_Wrapper::number_entries(); ++i ) write_hepevt_particle(i);
55 }
56 
58 {
59  fclose(m_file);
60 }
61 
63 {
64  return false;
65 }
66 
67 } // namespace HepMC3
static double m(const int &index)
Get generated mass.
Definition of class WriterHEPEVT.
static int last_child(const int &index)
Get index of last daughter.
static double z(const int &index)
Get Z Production vertex.
char * hepevtbuffer
Pointer to HEPEVT Fortran common block/C struct.
Definition: WriterHEPEVT.h:70
static double y(const int &index)
Get Y Production vertex.
static double t(const int &index)
Get production time.
int m_events_count
Events count. Needed to generate unique object name.
Definition: WriterHEPEVT.h:71
static int status(const int &index)
Get status code.
static int event_number()
Get event number.
static double x(const int &index)
Get X Production vertex.
static double pz(const int &index)
Get Z momentum.
virtual void write_hepevt_particle(int index, bool iflong=true)
Write particle to file.
Definition: WriterHEPEVT.cc:26
static double e(const int &index)
Get Energy.
WriterHEPEVT(const std::string &filename)
Default constructor.
Definition: WriterHEPEVT.cc:19
static void set_hepevt_address(char *c)
Set Fortran block address.
void write_event(const GenEvent &evt)
Write event to file.
Definition: WriterHEPEVT.cc:48
FILE * m_file
File to write. Need to be public to be accessible by children.
Definition: WriterHEPEVT.h:67
bool failed()
Get stream error state flag.
Definition: WriterHEPEVT.cc:62
virtual void write_hepevt_event_header()
Write event header to file.
Definition: WriterHEPEVT.cc:43
void close()
Close file stream.
Definition: WriterHEPEVT.cc:57
static bool fix_daughters()
Tries to fix list of daughters.
Stores event-related information.
Definition: GenEvent.h:42
static double py(const int &index)
Get Y momentum.
Fortran common block HEPEVT.
static int first_child(const int &index)
Get index of 1st daughter.
static int id(const int &index)
Get PDG particle id.
static bool GenEvent_to_HEPEVT(const GenEvent *evt)
Convert GenEvent to HEPEVT.
static int first_parent(const int &index)
Get index of 1st mother.
static double px(const int &index)
Get X momentum.
static int last_parent(const int &index)
Get index of last mother.
Definition of class HEPEVT_Wrapper.
static int number_entries()
Get number of entries.