ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHHepMCGenEvent.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHHepMCGenEvent.cc
1 #include "PHHepMCGenEvent.h"
2 
3 #include <HepMC/GenEvent.h>
4 #include <HepMC/SimpleVector.h> // for FourVector
5 
6 #include <CLHEP/Vector/Boost.h>
10 
11 #include <sstream>
12 #include <utility> // for swap
13 
14 using namespace std;
15 
17  : _embedding_id(0)
18  , _isSimulated(false)
19  , _collisionVertex(0, 0, 0, 0)
20  , _theEvt(nullptr)
21 {
22 }
23 
25  : _embedding_id(event.get_embedding_id())
26  , _isSimulated(event.is_simulated())
27  , _collisionVertex(event.get_collision_vertex())
28  , _theEvt(nullptr)
29 {
30  if (event.getEvent())
31  _theEvt = new HepMC::GenEvent(*event.getEvent());
32  return;
33 }
34 
36 {
37  if (&event == this) return *this;
38 
39  Reset();
40 
41  _embedding_id = event.get_embedding_id();
42  _isSimulated = event.is_simulated();
43  _theEvt = new HepMC::GenEvent(*event.getEvent());
44 
45  return *this;
46 }
47 
49 {
50  delete _theEvt;
51 }
52 
54 {
55  _embedding_id = 0;
56  _isSimulated = false;
57  _collisionVertex.set(0, 0, 0, 0);
58  delete _theEvt;
59  _theEvt = nullptr;
60 }
61 
62 HepMC::GenEvent* PHHepMCGenEvent::getEvent()
63 {
64  return _theEvt;
65 }
66 
67 const HepMC::GenEvent* PHHepMCGenEvent::getEvent() const
68 {
69  return _theEvt;
70 }
71 
72 bool PHHepMCGenEvent::addEvent(HepMC::GenEvent* evt)
73 {
74  // clean up old event if it exists,
75  // no check needed, one can delete null pointers
76  delete _theEvt;
77 
78  _theEvt = evt;
79  if (!_theEvt) return false;
80  return true;
81 }
82 
83 bool PHHepMCGenEvent::swapEvent(HepMC::GenEvent*& evt)
84 {
85  swap(_theEvt, evt);
86 
87  if (!_theEvt) return false;
88  return true;
89 }
90 
91 bool PHHepMCGenEvent::addEvent(HepMC::GenEvent& evt)
92 {
93  return addEvent(new HepMC::GenEvent(evt));
94 }
95 
97 {
98  if (_theEvt) _theEvt->clear();
99 }
100 
101 void PHHepMCGenEvent::moveVertex(double x, double y, double z, double t)
102 {
103  _collisionVertex.setX(_collisionVertex.x() + x);
104  _collisionVertex.setY(_collisionVertex.y() + y);
105  _collisionVertex.setZ(_collisionVertex.z() + z);
106  _collisionVertex.setT(_collisionVertex.t() + t);
107 }
108 
109 int PHHepMCGenEvent::size(void) const
110 {
111  if (_theEvt)
112  return _theEvt->particles_size();
113  else
114  return 0;
115 }
116 
118 {
119  if (_theEvt)
120  return _theEvt->vertices_size();
121  else
122  return 0;
123 }
124 
125 //_____________________________________________________________________________
126 void PHHepMCGenEvent::identify(std::ostream& os) const
127 {
128  os << "identify yourself: PHHepMCGenEvent Object";
129  os << ", No of Particles: " << size();
130  os << ", No of Vertices: " << vertexSize() << endl;
131  os << " embedding_id = " << _embedding_id << endl;
132  os << " isSimulated = " << _isSimulated << endl;
133  os << " collisionVertex = (" << _collisionVertex.x() << "," << _collisionVertex.y() << "," << _collisionVertex.z() << ") cm, " << _collisionVertex.t() << " ns" << endl;
134 
135  return;
136 }
137 
138 void PHHepMCGenEvent::print(std::ostream& out) const
139 {
140  identify(out);
141 }
142 
144 {
145  _theEvt->print();
146 }