1 #include "HepMC3Particle.h"
2 #include "HepMC3Event.h"
3 #include <iostream>
4 
5 #ifdef _USE_ROOT_
ClassImp(HepMC3Particle)6 ClassImp(HepMC3Particle)
7 #endif
8 
9 HepMC3Particle::HepMC3Particle() {}
10 
HepMC3Particle(HepMC3::GenParticle & particle,HEPEvent * e,int Id)11 HepMC3Particle::HepMC3Particle(HepMC3::GenParticle & particle, HEPEvent * e, int Id) {
12 
13     part = &particle;
14     SetEvent(e);
15     SetId(Id);
16 }
17 
~HepMC3Particle()18 HepMC3Particle::~HepMC3Particle() {
19 }
20 
operator =(HEPParticle & p)21 const HepMC3Particle HepMC3Particle::operator=(HEPParticle &p)
22 {
23     if (this == &p)
24         return *this;
25 
26     // SetId(p.GetId());
27 
28     SetPDGId(p.GetPDGId());
29     SetStatus(p.GetStatus());
30     SetMother(p.GetMother());
31     SetMother2(p.GetMother2());
32     SetFirstDaughter(p.GetFirstDaughter());
33     SetLastDaughter(p.GetLastDaughter());
34     SetE(p.GetE());
35     SetPx(p.GetPx());
36     SetPy(p.GetPy());
37     SetPz(p.GetPz());
38     SetM(p.GetM());
39     SetVx(p.GetVx());
40     SetVy(p.GetVy());
41     SetVz(p.GetVz());
42     SetTau(p.GetTau());
43 
44     return *this;
45 
46 }
47 
GetEvent()48 HEPEvent* HepMC3Particle::GetEvent() {
49     return event;
50 }
51 
GetId()52 int const HepMC3Particle::GetId() {
53     return id;
54 }
55 
56 //GetMother and Daughter methods not implemented here
57 //GetDaughterList() and GetMotherList() should be used
58 //instead. Still to do: some errors should be thrown.
GetMother()59 int const HepMC3Particle::GetMother() {
60     return 0;
61 }
62 
GetMother2()63 int const HepMC3Particle::GetMother2() {
64     return 0;
65 }
66 
GetFirstDaughter()67 int const HepMC3Particle::GetFirstDaughter() {
68     return 0;
69 }
70 
GetLastDaughter()71 int const HepMC3Particle::GetLastDaughter() {
72     return 0;
73 }
74 
GetE()75 double const HepMC3Particle::GetE() {
76     return part->momentum().e();
77 }
78 
GetPx()79 double const HepMC3Particle::GetPx() {
80     return part->momentum().px();
81 }
82 
GetPy()83 double const HepMC3Particle::GetPy() {
84     return part->momentum().py();
85 }
86 
GetPz()87 double const HepMC3Particle::GetPz() {
88     return part->momentum().pz();
89 }
90 
GetM()91 double const HepMC3Particle::GetM() {
92     return part->momentum().m();
93 }
94 
GetPDGId()95 int const HepMC3Particle::GetPDGId() {
96     return part->pid();
97 }
98 
GetStatus()99 int const HepMC3Particle::GetStatus() {
100     return part->status();
101 }
102 
IsStable()103 int const HepMC3Particle::IsStable() {
104     return (GetStatus() == 1 || !part->end_vertex());
105 }
106 
Decays()107 int const HepMC3Particle::Decays() {
108     return (!IsHistoryEntry() && !IsStable());
109 }
110 
IsHistoryEntry()111 int const HepMC3Particle::IsHistoryEntry() {
112     return (GetStatus() == 3);
113 }
114 
GetVx()115 double const HepMC3Particle::GetVx() {
116     if(part->production_vertex()) return part->production_vertex()->position().x();
117     return 0.;
118 }
119 
GetVy()120 double const HepMC3Particle::GetVy() {
121     if(part->production_vertex()) return part->production_vertex()->position().y();
122     return 0.;
123 }
124 
GetVz()125 double const HepMC3Particle::GetVz() {
126     if(part->production_vertex()) return part->production_vertex()->position().z();
127     return 0.;
128 }
129 
GetTau()130 double const HepMC3Particle::GetTau() {
131     //Not implemented
132     if(part->end_vertex()&&part->production_vertex())
133         return (part->end_vertex()->position().t()-part->production_vertex()->position().t()); //not correct, but will see if it's empty
134     else
135         return 0;
136 }
137 
138 //methods not implemented. Not done for HepMC.
139 /**void HepMC3Particle::SetP4(MC4Vector &v){ }
140 void HepMC3Particle::SetP3(MC3Vector &v){ }
141 void HepMC3Particle::SetV3(MC3Vector &v){ }
142 **/
143 
SetEvent(HEPEvent * event)144 void HepMC3Particle::SetEvent(HEPEvent * event) {
145     this->event=(HepMC3Event*)event;
146 }
147 
SetId(int id)148 void HepMC3Particle::SetId(int id) {
149     this->id = id;
150 }
151 
152 //Can not use these methods for HepMC
SetMother(int)153 void HepMC3Particle::SetMother(int /*mother*/) {}
SetMother2(int)154 void HepMC3Particle::SetMother2(int /*mother*/) {}
SetFirstDaughter(int)155 void HepMC3Particle::SetFirstDaughter(int /*daughter*/) {}
SetLastDaughter(int)156 void HepMC3Particle::SetLastDaughter (int /*daughter*/) {}
157 
SetE(double E)158 void HepMC3Particle::SetE(double E) {
159     HepMC3::FourVector temp_mom(part->momentum());
160     temp_mom.setE(E);
161     part->set_momentum(temp_mom);
162 }
163 
SetPx(double px)164 void HepMC3Particle::SetPx(double px) {
165     HepMC3::FourVector temp_mom(part->momentum());
166     temp_mom.setPx(px);
167     part->set_momentum(temp_mom);
168 }
169 
SetPy(double py)170 void HepMC3Particle::SetPy( double py ) {
171     HepMC3::FourVector temp_mom(part->momentum());
172     temp_mom.setPy(py);
173     part->set_momentum(temp_mom);
174 }
175 
SetPz(double pz)176 void HepMC3Particle::SetPz( double pz ) {
177     HepMC3::FourVector temp_mom(part->momentum());
178     temp_mom.setPz(pz);
179     part->set_momentum(temp_mom);
180 }
181 
SetM(double)182 void HepMC3Particle::SetM(double /*m*/) {
183     //Can not set in GenEvent
184     std::cout << "Can not set mass in HepMC3Particle. Set e, px, py, pz instead" <<std::endl;
185 }
186 
SetPDGId(int pdg)187 void HepMC3Particle::SetPDGId ( int pdg ) {
188     part->set_pid( pdg );
189 }
190 
SetStatus(int st)191 void HepMC3Particle::SetStatus( int st) {
192     part->set_status( st );
193 }
194 
SetVx(double)195 void HepMC3Particle::SetVx (double /*vx*/) {
196     //Not implemented
197 }
198 
SetVy(double)199 void HepMC3Particle::SetVy (double /*vy*/) {
200     //Not implemented
201 }
202 
SetVz(double)203 void HepMC3Particle::SetVz (double /*vz*/) {
204     //Not implemented
205 }
206 
SetTau(double)207 void HepMC3Particle::SetTau(double /*tau*/) {
208     //Not implemented
209 }
210 
211 
GetDaughterList(HEPParticleList * list)212 HEPParticleList* HepMC3Particle::GetDaughterList(HEPParticleList *list)
213 {
214     // if list is not provided, it is created.
215     if (!list) list=new HEPParticleList();
216 
217     if(!part->end_vertex()) //no daughters
218         return list;
219 
220     HepMC3::GenVertexPtr end = part->end_vertex();
221 
222     //iterate over daughters
223     for(unsigned int i=0; i<end->particles_out().size(); ++i) {
224         HepMC3Particle * daughter = event->GetParticleWithId((end->particles_out()[i])->id());
225         if(!list->contains(daughter->GetId())) {
226             if(!daughter->IsHistoryEntry())
227                 list->push_back(daughter);
228         }
229     }
230     return list;
231 }
232 
GetMotherList(HEPParticleList * list)233 HEPParticleList* HepMC3Particle::GetMotherList(HEPParticleList *list)
234 {
235     // if list is not provided, it is created.
236     if (!list) list=new HEPParticleList();
237 
238     if(!part->production_vertex()) //no mothers
239         return list;
240 
241     HepMC3::GenVertexPtr prod = part->production_vertex();
242 
243     //iterate over daughters
244     for(unsigned int i=0; i<prod->particles_in().size(); ++i) {
245         list->push_back(event->GetParticleWithId((prod->particles_in()[i])->id()));
246     }
247 
248     return list;
249 }
250 
251 
252 #ifdef _USE_ROOT_
Streamer(TBuffer &)253 void HepMC3Particle::Streamer(TBuffer &)
254 {
255     // streamer class for ROOT compatibility
256 }
257 
258 
259 #endif
260