source: trunk/source/particles/management/src/G4PrimaryParticle.cc@ 1305

Last change on this file since 1305 was 1196, checked in by garnier, 16 years ago

update CVS release candidate geant4.9.3.01

File size: 6.8 KB
Line 
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// $Id: G4PrimaryParticle.cc,v 1.5 2007/10/06 06:49:29 kurasige Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30
31#include "G4PrimaryParticle.hh"
32#include "G4ParticleDefinition.hh"
33#include "G4ParticleTable.hh"
34#include "G4ios.hh"
35#include "G4VUserPrimaryParticleInformation.hh"
36
37G4Allocator<G4PrimaryParticle> aPrimaryParticleAllocator;
38
39G4PrimaryParticle::G4PrimaryParticle()
40:PDGcode(0),G4code(0),Px(0.),Py(0.),Pz(0.),
41 nextParticle(0),daughterParticle(0),trackID(-1),
42 mass(-1.),charge(DBL_MAX),polX(0.),polY(0.),polZ(0.),
43 Weight0(1.0),properTime(0.0),userInfo(0)
44{;}
45
46G4PrimaryParticle::G4PrimaryParticle(G4int Pcode)
47:PDGcode(Pcode),Px(0.),Py(0.),Pz(0.),
48 nextParticle(0),daughterParticle(0),trackID(-1),
49 mass(-1.),charge(DBL_MAX),polX(0.),polY(0.),polZ(0.),
50 Weight0(1.0),properTime(0.0),userInfo(0)
51{ G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode); }
52
53G4PrimaryParticle::G4PrimaryParticle(G4int Pcode,
54 G4double px,G4double py,G4double pz)
55:PDGcode(Pcode),Px(px),Py(py),Pz(pz),
56 nextParticle(0),daughterParticle(0),trackID(-1),
57 mass(-1.),charge(DBL_MAX),polX(0.),polY(0.),polZ(0.),
58 Weight0(1.0),properTime(0.0),userInfo(0)
59{ G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode); }
60
61G4PrimaryParticle::G4PrimaryParticle(G4int Pcode,
62 G4double px,G4double py,G4double pz,G4double E)
63:PDGcode(Pcode),Px(px),Py(py),Pz(pz),
64 nextParticle(0),daughterParticle(0),trackID(-1),
65 charge(DBL_MAX),polX(0.),polY(0.),polZ(0.),
66 Weight0(1.0),properTime(0.0),userInfo(0)
67{
68 G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode);
69 G4double mas2 = E*E - px*px - py*py - pz*pz;
70 if(mas2>=0.)
71 { mass = std::sqrt(mas2); }
72 else
73 { mass = -1.0; }
74}
75
76G4PrimaryParticle::G4PrimaryParticle(G4ParticleDefinition* Gcode)
77:G4code(Gcode),Px(0.),Py(0.),Pz(0.),
78 nextParticle(0),daughterParticle(0),trackID(-1),
79 mass(-1.),charge(DBL_MAX),polX(0.),polY(0.),polZ(0.),
80 Weight0(1.0),properTime(0.0),userInfo(0)
81{ PDGcode = Gcode->GetPDGEncoding(); }
82
83G4PrimaryParticle::G4PrimaryParticle(G4ParticleDefinition* Gcode,
84 G4double px,G4double py,G4double pz)
85:G4code(Gcode),Px(px),Py(py),Pz(pz),
86 nextParticle(0),daughterParticle(0),trackID(-1),
87 mass(-1.),charge(DBL_MAX),polX(0.),polY(0.),polZ(0.),
88 Weight0(1.0),properTime(0.0),userInfo(0)
89{ PDGcode = Gcode->GetPDGEncoding(); }
90
91G4PrimaryParticle::G4PrimaryParticle(G4ParticleDefinition* Gcode,
92 G4double px,G4double py,G4double pz,G4double E)
93:G4code(Gcode),Px(px),Py(py),Pz(pz),
94 nextParticle(0),daughterParticle(0),trackID(-1),
95 charge(DBL_MAX),polX(0.),polY(0.),polZ(0.),
96 Weight0(1.0),properTime(0.0),userInfo(0)
97{
98 PDGcode = Gcode->GetPDGEncoding();
99 G4double mas2 = E*E - px*px - py*py - pz*pz;
100 if(mas2>=0.)
101 { mass = std::sqrt(mas2); }
102 else
103 { mass = -1.0; }
104}
105
106G4PrimaryParticle::~G4PrimaryParticle()
107{
108 if(nextParticle != 0)
109 { delete nextParticle; }
110 if(daughterParticle != 0)
111 { delete daughterParticle; }
112 if(userInfo!=0)
113 { delete userInfo; }
114}
115
116void G4PrimaryParticle::SetPDGcode(G4int Pcode)
117{
118 PDGcode = Pcode;
119 G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode);
120}
121
122void G4PrimaryParticle::SetG4code(G4ParticleDefinition* Gcode)
123{
124 G4code = Gcode;
125 PDGcode = Gcode->GetPDGEncoding();
126}
127
128G4double G4PrimaryParticle::GetMass() const
129{
130 if (mass <0.0 ) {
131 if (G4code != 0) {
132 // return PDG mass if dynamical mass has not be specified
133 return G4code->GetPDGMass();
134 }
135 }
136 return mass;
137}
138
139G4double G4PrimaryParticle::GetCharge() const
140{
141 if ( charge <DBL_MAX ) {
142 return charge;
143 } else {
144 if (G4code != 0) {
145 // return PDG charge if dynamical mass has not be specified
146 return G4code->GetPDGCharge();
147 }
148 }
149 return charge;
150}
151
152const G4PrimaryParticle &
153G4PrimaryParticle::operator=(const G4PrimaryParticle &)
154{ return *this; }
155G4int G4PrimaryParticle::operator==(const G4PrimaryParticle &right) const
156{ return (this==&right); }
157G4int G4PrimaryParticle::operator!=(const G4PrimaryParticle &right) const
158{ return (this!=&right); }
159
160void G4PrimaryParticle::Print() const
161{
162 G4cout << "==== PDGcode " << PDGcode << " Particle name ";
163 if(G4code != 0)
164 { G4cout << G4code->GetParticleName() << G4endl; }
165 else
166 { G4cout << " is not defined in G4." << G4endl; }
167 if(charge<DBL_MAX)
168 { G4cout << " Assigned charge : " << charge/eplus << G4endl; }
169 else
170 { G4cout << " Charge will be taken from PDG charge." << G4endl; }
171 G4cout << " Momentum ( "
172 << Px/GeV << "[GeV/c], "
173 << Py/GeV << "[GeV/c], "
174 << Pz/GeV << "[GeV/c] )" << G4endl;
175 if(mass>=0.)
176 { G4cout << " Mass : " << mass/GeV << " [GeV]" << G4endl; }
177 else
178 { G4cout << " Nominal mass will be taken from particle definition." << G4endl; }
179 G4cout << " Polarization ( "
180 << polX << ", "
181 << polY << ", "
182 << polZ << " )"
183 << G4endl;
184 G4cout << " Weight : " << Weight0 << G4endl;
185 if(properTime>0.0)
186 { G4cout << " PreAssigned proper decay time : " << properTime/ns << " [ns] " << G4endl; }
187 if(userInfo != 0) userInfo->Print();
188 if(daughterParticle != 0)
189 {
190 G4cout << ">>>> Daughters" << G4endl;
191 daughterParticle->Print();
192 }
193 if(nextParticle != 0)
194 { nextParticle->Print(); }
195 else
196 { G4cout << "<<<< End of link" << G4endl; }
197}
198
199
200
201
Note: See TracBrowser for help on using the repository browser.