Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JetScapeWriterRootHepMC.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JetScapeWriterRootHepMC.h
1 /*******************************************************************************
2  * Copyright (c) The JETSCAPE Collaboration, 2018
3  *
4  * Modular, task-based framework for simulating all aspects of heavy-ion collisions
5  *
6  * For the list of contributors see AUTHORS.
7  *
8  * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
9  *
10  * or via email to bugs.jetscape@gmail.com
11  *
12  * Distributed under the GNU General Public License 3.0 (GPLv3 or later).
13  * See COPYING for details.
14  ******************************************************************************/
15 
16 #ifndef JETSCAPEWRITERROOTHEPMC_H
17 #define JETSCAPEWRITERROOTHEPMC_H
18 
19 #include <fstream>
20 #include <string>
21 
22 #include "JetScapeWriter.h"
23 #include "PartonShower.h"
24 
25 #include "HepMC3/GenEvent.h"
26 #include "HepMC3/ReaderAscii.h"
27 #include "HepMC3/WriterRootTree.h"
28 #include "HepMC3/Print.h"
29 
30 // using namespace HepMC;
31 using HepMC3::GenEvent;
32 using HepMC3::GenVertex;
33 using HepMC3::GenParticle;
34 using HepMC3::GenVertexPtr;
35 using HepMC3::GenParticlePtr;
36 
37 namespace Jetscape {
38 
39 class JetScapeWriterRootHepMC : public JetScapeWriter, public HepMC3::WriterRootTree {
40 
41 public:
42  JetScapeWriterRootHepMC() : HepMC3::WriterRootTree("") { SetId("HepMC ROOT writer"); };
43  JetScapeWriterRootHepMC(string m_file_name_out)
44  : JetScapeWriter(m_file_name_out), HepMC3::WriterRootTree(m_file_name_out) {
45  SetId("HepMC ROOT writer");
46  };
47  virtual ~JetScapeWriterRootHepMC();
48 
49  void Init();
50  void Exec();
51 
52  bool GetStatus() { return failed(); }
53  void Close() { close(); }
54 
55  // // NEVER use this!
56  // // Can work with only one writer, but with a second one it gets called twice
57  // void WriteTask(weak_ptr<JetScapeWriter> w);
58 
59  // overload write functions
60  void WriteEvent();
61 
62  // At parton level, we should never accept anything other than a full shower
63  // void Write(weak_ptr<Vertex> v);
64  void Write(weak_ptr<PartonShower> ps);
65  void Write(weak_ptr<Hadron> h);
66  void WriteHeaderToFile();
67 
68 private:
69  HepMC3::GenEvent evt;
70  vector<HepMC3::GenVertexPtr> vertices;
71  HepMC3::GenVertexPtr hadronizationvertex;
72 
74  bool hashadrons=false;
75 
76  inline HepMC3::GenVertexPtr
77  castVtxToHepMC(const shared_ptr<Vertex> vtx) const {
78  double x = vtx->x_in().x();
79  double y = vtx->x_in().y();
80  double z = vtx->x_in().z();
81  double t = vtx->x_in().t();
82  HepMC3::FourVector vtxPosition(x, y, z, t);
83  // if ( t< 1e-6 ) t = 1e-6; // could do this. Exact 0 is bit quirky but works for hepmc
84  return make_shared<GenVertex>(vtxPosition);
85  }
86 
87  inline HepMC3::GenParticlePtr
88  castPartonToHepMC(const shared_ptr<Parton> pparticle) const {
89  return castPartonToHepMC(*pparticle);
90  }
91 
92  inline HepMC3::GenParticlePtr
94  HepMC3::FourVector pmom(particle.px(), particle.py(), particle.pz(),
95  particle.e());
96  return make_shared<GenParticle>(pmom, particle.pid(), particle.pstat());
97  }
98 
99  inline HepMC3::GenParticlePtr
100  castHadronToHepMC(const shared_ptr<Hadron> pparticle) const {
101  return castHadronToHepMC(*pparticle);
102  }
103 
104  inline HepMC3::GenParticlePtr
106  HepMC3::FourVector pmom(particle.px(), particle.py(), particle.pz(),
107  particle.e());
108  return make_shared<GenParticle>(pmom, particle.pid(), particle.pstat());
109  }
110 
111  //int m_precision; //!< Output precision
112 };
113 
114 } // end namespace Jetscape
115 
116 #endif