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

Last change on this file since 1355 was 1340, checked in by garnier, 14 years ago

update ti head

File size: 7.0 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.7 2010/08/11 17:14:02 kurasige Exp $
28// GEANT4 tag $Name: particles-V09-03-15 $
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(const 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(const 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(const 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(const G4ParticleDefinition* Gcode)
123{
124  SetParticleDefinition(Gcode);
125}
126
127void G4PrimaryParticle::SetParticleDefinition(const G4ParticleDefinition* Gcode)
128{
129  G4code = Gcode;
130  PDGcode = Gcode->GetPDGEncoding();
131}
132
133G4double G4PrimaryParticle::GetMass() const
134{
135  if (mass <0.0 ) {
136    if (G4code != 0) {
137      // return PDG mass if dynamical mass has not be specified
138      return G4code->GetPDGMass();
139    }
140  }
141  return mass; 
142}
143
144G4double G4PrimaryParticle::GetCharge() const
145{
146  if ( charge <DBL_MAX ) {
147    return charge;
148  } else {
149    if (G4code != 0) {
150      // return PDG charge if dynamical mass has not be specified
151      return G4code->GetPDGCharge();
152    }
153  }
154  return charge; 
155}
156
157const G4PrimaryParticle & 
158G4PrimaryParticle::operator=(const G4PrimaryParticle &)
159{ return *this; }
160G4int G4PrimaryParticle::operator==(const G4PrimaryParticle &right) const
161{ return (this==&right); }
162G4int G4PrimaryParticle::operator!=(const G4PrimaryParticle &right) const
163{ return (this!=&right); }
164
165void G4PrimaryParticle::Print() const
166{
167  G4cout << "==== PDGcode " << PDGcode << "  Particle name ";
168  if(G4code != 0)
169  { G4cout << G4code->GetParticleName() << G4endl; }
170  else
171  { G4cout << " is not defined in G4." << G4endl; }
172  if(charge<DBL_MAX)
173  { G4cout << " Assigned charge : " << charge/eplus  << G4endl; }
174  else
175  { G4cout << " Charge will be taken from PDG charge." << G4endl; }
176  G4cout << "     Momentum ( " 
177         << Px/GeV << "[GeV/c], " 
178         << Py/GeV << "[GeV/c], " 
179         << Pz/GeV << "[GeV/c] )" << G4endl;
180  if(mass>=0.)
181    { G4cout << "     Mass : " << mass/GeV << " [GeV]" << G4endl; }
182  else
183    { G4cout << "     Nominal mass will be taken from particle definition." << G4endl; }
184  G4cout << "     Polarization ( " 
185         << polX << ", " 
186         << polY << ", "
187         << polZ << " )" 
188         << G4endl;
189  G4cout << "     Weight : " << Weight0 << G4endl;
190  if(properTime>0.0)
191  { G4cout << "     PreAssigned proper decay time : " << properTime/ns << " [ns] " << G4endl; }
192  if(userInfo != 0) userInfo->Print();
193  if(daughterParticle != 0)
194  {
195    G4cout << ">>>> Daughters" << G4endl;
196    daughterParticle->Print();
197  }
198  if(nextParticle != 0)
199  { nextParticle->Print(); }
200  else
201  { G4cout << "<<<< End of link" << G4endl; }
202}
203
204
205
206
Note: See TracBrowser for help on using the repository browser.