00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "G4PrimaryParticle.hh"
00031 #include "G4SystemOfUnits.hh"
00032 #include "G4ParticleDefinition.hh"
00033 #include "G4ParticleTable.hh"
00034 #include "G4ios.hh"
00035 #include "G4VUserPrimaryParticleInformation.hh"
00036
00037 G4Allocator<G4PrimaryParticle> aPrimaryParticleAllocator;
00038
00039 G4PrimaryParticle::G4PrimaryParticle()
00040 :PDGcode(0),G4code(0),
00041 direction(0.,0.,1.),kinE(0.),
00042 nextParticle(0),daughterParticle(0),trackID(-1),
00043 mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
00044 Weight0(1.0),properTime(0.0),userInfo(0)
00045 {;}
00046
00047 G4PrimaryParticle::G4PrimaryParticle(G4int Pcode)
00048 :PDGcode(Pcode),
00049 direction(0.,0.,1.),kinE(0.),
00050 nextParticle(0),daughterParticle(0),trackID(-1),
00051 mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
00052 Weight0(1.0),properTime(0.0),userInfo(0)
00053 {
00054 G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode);
00055 if (G4code !=0) {
00056 mass = G4code->GetPDGMass();
00057 charge = G4code->GetPDGCharge();
00058 }
00059 }
00060
00061 G4PrimaryParticle::G4PrimaryParticle(G4int Pcode,
00062 G4double px,G4double py,G4double pz)
00063 :PDGcode(Pcode),
00064 direction(0.,0.,1.),kinE(0.),
00065 nextParticle(0),daughterParticle(0),trackID(-1),
00066 mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
00067 Weight0(1.0),properTime(0.0),userInfo(0)
00068 {
00069 G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode);
00070 if (G4code !=0) {
00071 mass = G4code->GetPDGMass();
00072 charge = G4code->GetPDGCharge();
00073 }
00074 SetMomentum( px, py, pz);
00075 }
00076
00077 G4PrimaryParticle::G4PrimaryParticle(G4int Pcode,
00078 G4double px,G4double py,G4double pz,G4double E)
00079 :PDGcode(Pcode),
00080 direction(0.,0.,1.),kinE(0.),
00081 nextParticle(0),daughterParticle(0),trackID(-1),
00082 charge(0.),polX(0.),polY(0.),polZ(0.),
00083 Weight0(1.0),properTime(0.0),userInfo(0)
00084 {
00085 G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode);
00086 if (G4code !=0) {
00087 mass = G4code->GetPDGMass();
00088 charge = G4code->GetPDGCharge();
00089 }
00090 Set4Momentum( px, py, pz, E);
00091 }
00092
00093 G4PrimaryParticle::G4PrimaryParticle(const G4ParticleDefinition* Gcode)
00094 :PDGcode(0),G4code(Gcode),
00095 direction(0.,0.,1.),kinE(0.),
00096 nextParticle(0),daughterParticle(0),trackID(-1),
00097 mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
00098 Weight0(1.0),properTime(0.0),userInfo(0)
00099 {
00100 if (G4code !=0) {
00101 PDGcode = Gcode->GetPDGEncoding();
00102 mass = G4code->GetPDGMass();
00103 charge = G4code->GetPDGCharge();
00104 }
00105 }
00106
00107 G4PrimaryParticle::G4PrimaryParticle(const G4ParticleDefinition* Gcode,
00108 G4double px,G4double py,G4double pz)
00109 :PDGcode(0),G4code(Gcode),
00110 direction(0.,0.,1.),kinE(0.),
00111 nextParticle(0),daughterParticle(0),trackID(-1),
00112 mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
00113 Weight0(1.0),properTime(0.0),userInfo(0)
00114 {
00115 if (G4code !=0) {
00116 PDGcode = Gcode->GetPDGEncoding();
00117 mass = G4code->GetPDGMass();
00118 charge = G4code->GetPDGCharge();
00119 }
00120 SetMomentum( px, py, pz);
00121 }
00122
00123 G4PrimaryParticle::G4PrimaryParticle(const G4ParticleDefinition* Gcode,
00124 G4double px,G4double py,G4double pz,G4double E)
00125 :PDGcode(0),G4code(Gcode),
00126 direction(0.,0.,1.),kinE(0.),
00127 nextParticle(0),daughterParticle(0),trackID(-1),
00128 charge(0.),polX(0.),polY(0.),polZ(0.),
00129 Weight0(1.0),properTime(0.0),userInfo(0)
00130 {
00131 if (G4code !=0) {
00132 PDGcode = Gcode->GetPDGEncoding();
00133 mass = G4code->GetPDGMass();
00134 charge = G4code->GetPDGCharge();
00135 }
00136 Set4Momentum( px, py, pz, E);
00137 }
00138
00139 G4PrimaryParticle::G4PrimaryParticle(const G4PrimaryParticle& right)
00140 :PDGcode(0),G4code(0),
00141 direction(0.,0.,1.),kinE(0.),
00142 nextParticle(0),daughterParticle(0),trackID(-1),
00143 mass(-1.),charge(0.),polX(0.),polY(0.),polZ(0.),
00144 Weight0(1.0),properTime(0.0),userInfo(0)
00145 {
00146 *this = right;
00147 }
00148
00149 G4PrimaryParticle & G4PrimaryParticle::operator=(const G4PrimaryParticle & right)
00150 {
00151 if (this != &right) {
00152 PDGcode = right.PDGcode;
00153 G4code = right.G4code;
00154 direction = right.direction;
00155 kinE = right.kinE;
00156 if (nextParticle !=0) delete nextParticle;
00157 if ( right.nextParticle ==0 ){
00158 nextParticle = 0;
00159 } else {
00160 nextParticle = new G4PrimaryParticle(*right.nextParticle);
00161 }
00162 if (daughterParticle !=0) delete daughterParticle;
00163 if ( right.daughterParticle ==0 ){
00164 daughterParticle = 0;
00165 } else {
00166 daughterParticle = new G4PrimaryParticle(*right.daughterParticle);
00167 }
00168 trackID = right.trackID;
00169 mass = right.mass;
00170 charge = right.charge;
00171 polX = right.polX;
00172 polY = right.polY;
00173 polZ = right.polZ;
00174 Weight0 = right.Weight0;
00175 properTime = right.properTime;
00176
00177
00178 userInfo = 0;
00179 }
00180
00181 return *this;
00182 }
00183
00184 G4int G4PrimaryParticle::operator==(const G4PrimaryParticle &right) const
00185 { return (this==&right); }
00186
00187 G4int G4PrimaryParticle::operator!=(const G4PrimaryParticle &right) const
00188 { return (this!=&right); }
00189
00190 G4PrimaryParticle::~G4PrimaryParticle()
00191 {
00192 if(nextParticle != 0){
00193 delete nextParticle;
00194 nextParticle = 0;
00195 }
00196 if(daughterParticle != 0){
00197 delete daughterParticle;
00198 daughterParticle =0;
00199 }
00200 if(userInfo!=0) {
00201 delete userInfo;
00202 userInfo=0;
00203 }
00204 }
00205
00206 void G4PrimaryParticle::SetMomentum(G4double px, G4double py, G4double pz)
00207 {
00208 if ((mass<0.)&&(G4code!=0)){
00209 mass = G4code->GetPDGMass();
00210 }
00211 G4double pmom = std::sqrt(px*px+py*py+pz*pz);
00212 if (pmom>0.0) {
00213 direction.setX(px/pmom);
00214 direction.setY(py/pmom);
00215 direction.setZ(pz/pmom);
00216 }
00217 kinE = std::sqrt(px*px+py*py+pz*pz+mass*mass)-mass;
00218 }
00219
00220 void G4PrimaryParticle::Set4Momentum(G4double px, G4double py, G4double pz, G4double E)
00221 {
00222 G4double pmom = std::sqrt(px*px+py*py+pz*pz);
00223 if (pmom>0.0) {
00224 direction.setX(px/pmom);
00225 direction.setY(py/pmom);
00226 direction.setZ(pz/pmom);
00227 }
00228 G4double mas2 = E*E - pmom*pmom;
00229 if(mas2>=0.){
00230 mass = std::sqrt(mas2);
00231 } else {
00232 if (G4code!=0){
00233 mass = G4code->GetPDGMass();
00234 }
00235 E = std::sqrt(pmom*pmom+mass*mass);
00236 }
00237 kinE = E - mass;
00238 }
00239
00240 void G4PrimaryParticle::SetPDGcode(G4int Pcode)
00241 {
00242 PDGcode = Pcode;
00243 G4code = G4ParticleTable::GetParticleTable()->FindParticle(Pcode);
00244 if (G4code!=0){
00245 mass = G4code->GetPDGMass();
00246 charge = G4code->GetPDGCharge();
00247 }
00248 }
00249
00250 void G4PrimaryParticle::SetParticleDefinition(const G4ParticleDefinition* Gcode)
00251 {
00252 G4code = Gcode;
00253 if (G4code!=0){
00254 PDGcode = Gcode->GetPDGEncoding();
00255 mass = G4code->GetPDGMass();
00256 charge = G4code->GetPDGCharge();
00257 }
00258 }
00259
00260 void G4PrimaryParticle::Print() const
00261 {
00262 G4cout << "==== PDGcode " << PDGcode << " Particle name ";
00263 if(G4code != 0)
00264 { G4cout << G4code->GetParticleName() << G4endl; }
00265 else
00266 { G4cout << " is not defined in G4." << G4endl; }
00267 G4cout << " Assigned charge : " << charge/eplus << G4endl;
00268 G4cout << " Momentum ( "
00269 << GetTotalMomentum()*direction.x()/GeV << "[GeV/c], "
00270 << GetTotalMomentum()*direction.y()/GeV << "[GeV/c], "
00271 << GetTotalMomentum()*direction.z()/GeV << "[GeV/c] )" << G4endl;
00272 G4cout << " kinetic Energy : " << kinE/GeV << " [GeV]" << G4endl;
00273 if(mass>=0.){
00274 G4cout << " Mass : " << mass/GeV << " [GeV]" << G4endl;
00275 } else {
00276 G4cout << " Mass is not assigned " << G4endl;
00277 }
00278 G4cout << " Polarization ( "
00279 << polX << ", "
00280 << polY << ", "
00281 << polZ << " )"
00282 << G4endl;
00283 G4cout << " Weight : " << Weight0 << G4endl;
00284 if(properTime>0.0) {
00285 G4cout << " PreAssigned proper decay time : " << properTime/ns << " [ns] " << G4endl;
00286 }
00287 if(userInfo != 0) { userInfo->Print(); }
00288 if(daughterParticle != 0) {
00289 G4cout << ">>>> Daughters" << G4endl;
00290 daughterParticle->Print();
00291 }
00292 if(nextParticle != 0) {
00293 nextParticle->Print();
00294 } else {
00295 G4cout << "<<<< End of link" << G4endl;
00296 }
00297 }
00298
00299
00300
00301