ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4PrimaryParticle.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4PrimaryParticle.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 
29 #include "G4PrimaryParticle.hh"
30 #include "G4SystemOfUnits.hh"
31 #include "G4ParticleDefinition.hh"
32 #include "G4ParticleTable.hh"
33 #include "G4ios.hh"
35 
37 {
39  return _instance;
40 }
41 
43 :PDGcode(0),G4code(0),
44  direction(0.,0.,1.),kinE(0.),
45  nextParticle(0),daughterParticle(0),trackID(-1),
46  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
47  Weight0(1.0),properTime(-1.0),userInfo(0)
48 {;}
49 
51 :PDGcode(Pcode),
52  direction(0.,0.,1.),kinE(0.),
53  nextParticle(0),daughterParticle(0),trackID(-1),
54  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
55  Weight0(1.0),properTime(-1.0),userInfo(0)
56 {
58  if (G4code !=0) {
59  mass = G4code->GetPDGMass();
61  }
62 }
63 
65  G4double px,G4double py,G4double pz)
66 :PDGcode(Pcode),
67  direction(0.,0.,1.),kinE(0.),
68  nextParticle(0),daughterParticle(0),trackID(-1),
69  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
70  Weight0(1.0),properTime(-1.0),userInfo(0)
71 {
73  if (G4code !=0) {
74  mass = G4code->GetPDGMass();
76  }
77  SetMomentum( px, py, pz);
78 }
79 
82 :PDGcode(Pcode),
83  direction(0.,0.,1.),kinE(0.),
84  nextParticle(0),daughterParticle(0),trackID(-1),
85  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
86  Weight0(1.0),properTime(-1.0),userInfo(0)
87 {
89  if (G4code !=0) {
90  mass = G4code->GetPDGMass();
92  }
93  Set4Momentum( px, py, pz, E);
94 }
95 
97 :PDGcode(0),G4code(Gcode),
98  direction(0.,0.,1.),kinE(0.),
99  nextParticle(0),daughterParticle(0),trackID(-1),
100  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
101  Weight0(1.0),properTime(-1.0),userInfo(0)
102 {
103  if (G4code !=0) {
104  PDGcode = Gcode->GetPDGEncoding();
105  mass = G4code->GetPDGMass();
107  }
108 }
109 
111  G4double px,G4double py,G4double pz)
112 :PDGcode(0),G4code(Gcode),
113  direction(0.,0.,1.),kinE(0.),
114  nextParticle(0),daughterParticle(0),trackID(-1),
115  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
116  Weight0(1.0),properTime(-1.0),userInfo(0)
117 {
118  if (G4code !=0) {
119  PDGcode = Gcode->GetPDGEncoding();
120  mass = G4code->GetPDGMass();
122  }
123  SetMomentum( px, py, pz);
124 }
125 
128 :PDGcode(0),G4code(Gcode),
129  direction(0.,0.,1.),kinE(0.),
130  nextParticle(0),daughterParticle(0),trackID(-1),
131  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
132  Weight0(1.0),properTime(-1.0),userInfo(0)
133 {
134  if (G4code !=0) {
135  PDGcode = Gcode->GetPDGEncoding();
136  mass = G4code->GetPDGMass();
138  }
139  Set4Momentum( px, py, pz, E);
140 }
141 
143 :PDGcode(0),G4code(0),
144  direction(0.,0.,1.),kinE(0.),
145  nextParticle(0),daughterParticle(0),trackID(-1),
146  mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
147  Weight0(1.0),properTime(-1.0),userInfo(0)
148 {
149  *this = right;
150 }
151 
153 {
154  if (this != &right) {
155  PDGcode = right.PDGcode;
156  G4code = right.G4code;
157  direction = right.direction;
158  kinE = right.kinE;
159  if (nextParticle !=0) delete nextParticle;
160  if ( right.nextParticle ==0 ){
161  nextParticle = 0;
162  } else {
164  }
165  if (daughterParticle !=0) delete daughterParticle;
166  if ( right.daughterParticle ==0 ){
167  daughterParticle = 0;
168  } else {
170  }
171  trackID = right.trackID;
172  mass = right.mass;
173  charge = right.charge;
174  polX = right.polX;
175  polY = right.polY;
176  polZ = right.polZ;
177  Weight0 = right.Weight0;
178  properTime = right.properTime;
179 
180  // userInfo can not be copied
181  userInfo = 0;
182  }
183 
184  return *this;
185 }
186 
188 { return (this==&right); }
189 
191 { return (this!=&right); }
192 
194 {
195  if(nextParticle != 0){
196  delete nextParticle;
197  nextParticle = 0;
198  }
199  if(daughterParticle != 0){
200  delete daughterParticle;
201  daughterParticle =0;
202  }
203  if(userInfo!=0) {
204  delete userInfo;
205  userInfo=0;
206  }
207 }
208 
210 {
211  if ((mass<0.)&&(G4code!=0)){
212  mass = G4code->GetPDGMass();
213  }
214  G4double pmom = std::sqrt(px*px+py*py+pz*pz);
215  if (pmom>0.0) {
216  direction.setX(px/pmom);
217  direction.setY(py/pmom);
218  direction.setZ(pz/pmom);
219  }
220  kinE = std::sqrt(px*px+py*py+pz*pz+mass*mass)-mass;
221 }
222 
224 {
225  G4double pmom = std::sqrt(px*px+py*py+pz*pz);
226  if (pmom>0.0) {
227  direction.setX(px/pmom);
228  direction.setY(py/pmom);
229  direction.setZ(pz/pmom);
230  }
231  G4double mas2 = E*E - pmom*pmom;
232  if(mas2>=0.){
233  mass = std::sqrt(mas2);
234  } else {
235  if (G4code!=0){
236  mass = G4code->GetPDGMass();
237  }
238  E = std::sqrt(pmom*pmom+mass*mass);
239  }
240  kinE = E - mass;
241 }
242 
244 {
245  PDGcode = Pcode;
247  if (G4code!=0){
248  mass = G4code->GetPDGMass();
250  }
251 }
252 
254 {
255  G4code = Gcode;
256  if (G4code!=0){
257  PDGcode = Gcode->GetPDGEncoding();
258  mass = G4code->GetPDGMass();
260  }
261 }
262 
264 {
265  G4cout << "==== PDGcode " << PDGcode << " Particle name ";
266  if(G4code != 0)
267  { G4cout << G4code->GetParticleName() << G4endl; }
268  else
269  { G4cout << " is not defined in G4." << G4endl; }
270  G4cout << " Assigned charge : " << charge/eplus << G4endl;
271  G4cout << " Momentum ( "
272  << GetTotalMomentum()*direction.x()/GeV << "[GeV/c], "
273  << GetTotalMomentum()*direction.y()/GeV << "[GeV/c], "
274  << GetTotalMomentum()*direction.z()/GeV << "[GeV/c] )" << G4endl;
275  G4cout << " kinetic Energy : " << kinE/GeV << " [GeV]" << G4endl;
276  if(mass>=0.){
277  G4cout << " Mass : " << mass/GeV << " [GeV]" << G4endl;
278  } else {
279  G4cout << " Mass is not assigned " << G4endl;
280  }
281  G4cout << " Polarization ( "
282  << polX << ", "
283  << polY << ", "
284  << polZ << " )"
285  << G4endl;
286  G4cout << " Weight : " << Weight0 << G4endl;
287  if(properTime>=0.0) {
288  G4cout << " PreAssigned proper decay time : " << properTime/ns << " [ns] " << G4endl;
289  }
290  if(userInfo != 0) { userInfo->Print(); }
291  if(daughterParticle != 0) {
292  G4cout << ">>>> Daughters" << G4endl;
294  }
295  if(nextParticle != 0) {
296  nextParticle->Print();
297  } else {
298  G4cout << "<<<< End of link" << G4endl;
299  }
300 }