File indexing completed on 2025-08-03 08:19:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef JETSCAPEWRITERHEPMC_H
0017 #define JETSCAPEWRITERHEPMC_H
0018
0019 #include <fstream>
0020 #include <string>
0021
0022 #include "JetScapeWriter.h"
0023 #include "PartonShower.h"
0024
0025 #include "HepMC3/GenEvent.h"
0026 #include "HepMC3/ReaderAscii.h"
0027 #include "HepMC3/WriterAscii.h"
0028 #include "HepMC3/Print.h"
0029
0030
0031 using HepMC3::GenEvent;
0032 using HepMC3::GenVertex;
0033 using HepMC3::GenParticle;
0034 using HepMC3::GenVertexPtr;
0035 using HepMC3::GenParticlePtr;
0036
0037 namespace Jetscape {
0038
0039 class JetScapeWriterHepMC : public JetScapeWriter, public HepMC3::WriterAscii {
0040
0041 public:
0042 JetScapeWriterHepMC() : HepMC3::WriterAscii("") { SetId("HepMC writer"); };
0043 JetScapeWriterHepMC(string m_file_name_out)
0044 : JetScapeWriter(m_file_name_out), HepMC3::WriterAscii(m_file_name_out) {
0045 SetId("HepMC writer");
0046 };
0047 virtual ~JetScapeWriterHepMC();
0048
0049 void Init();
0050 void Exec();
0051
0052 bool GetStatus() { return failed(); }
0053 void Close() { close(); }
0054
0055
0056
0057
0058
0059
0060 void WriteEvent();
0061
0062
0063
0064 void Write(weak_ptr<PartonShower> ps);
0065 void Write(weak_ptr<Hadron> h);
0066 void WriteHeaderToFile();
0067
0068 private:
0069 HepMC3::GenEvent evt;
0070 vector<HepMC3::GenVertexPtr> vertices;
0071 HepMC3::GenVertexPtr hadronizationvertex;
0072
0073
0074 bool hashadrons=false;
0075
0076 inline HepMC3::GenVertexPtr
0077 castVtxToHepMC(const shared_ptr<Vertex> vtx) const {
0078 double x = vtx->x_in().x();
0079 double y = vtx->x_in().y();
0080 double z = vtx->x_in().z();
0081 double t = vtx->x_in().t();
0082 HepMC3::FourVector vtxPosition(x, y, z, t);
0083
0084 return make_shared<GenVertex>(vtxPosition);
0085 }
0086
0087 inline HepMC3::GenParticlePtr
0088 castPartonToHepMC(const shared_ptr<Parton> pparticle) const {
0089 return castPartonToHepMC(*pparticle);
0090 }
0091
0092 inline HepMC3::GenParticlePtr
0093 castPartonToHepMC(const Parton &particle) const {
0094 HepMC3::FourVector pmom(particle.px(), particle.py(), particle.pz(),
0095 particle.e());
0096 return make_shared<GenParticle>(pmom, particle.pid(), particle.pstat());
0097 }
0098
0099 inline HepMC3::GenParticlePtr
0100 castHadronToHepMC(const shared_ptr<Hadron> pparticle) const {
0101 return castHadronToHepMC(*pparticle);
0102 }
0103
0104 inline HepMC3::GenParticlePtr
0105 castHadronToHepMC(const Hadron &particle) const {
0106 HepMC3::FourVector pmom(particle.px(), particle.py(), particle.pz(),
0107 particle.e());
0108 return make_shared<GenParticle>(pmom, particle.pid(), particle.pstat());
0109 }
0110
0111
0112 };
0113
0114 }
0115
0116 #endif