Smaller changes
[u/mrichter/AliRoot.git] / AliGeant4 / AliGunParticle.cxx
1 // $Id$
2 // Category: event
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class AliGunParticle
7 // --------------------
8 // See the class description in the header file.
9
10 #include "AliGunParticle.h"
11
12 #include <G4ParticleDefinition.hh>
13
14 //_____________________________________________________________________________
15 AliGunParticle::AliGunParticle()
16   : fParticleDefinition(0),
17     fParticleMomentum(G4ThreeVector(0., 0., 1.)),
18     fPosition(G4ThreeVector()),
19     fTime(0),
20     fPolarization(G4ThreeVector())
21 {
22 //
23 }
24
25 //_____________________________________________________________________________
26 AliGunParticle::AliGunParticle(G4ParticleDefinition* particleDef,
27                                G4ParticleMomentum momentum, 
28                                G4ThreeVector position, 
29                                G4double time, 
30                                G4ThreeVector polarization )
31   : fParticleDefinition(particleDef),
32     fParticleMomentum(momentum),
33     fPosition(position),
34     fTime(time),
35     fPolarization(polarization)
36 {
37 //
38 }
39
40 //_____________________________________________________________________________
41 AliGunParticle::AliGunParticle(G4ParticleDefinition* particleDef, 
42                                G4ParticleMomentum momentumDir,
43                                G4double kinEnergy,
44                                G4ThreeVector position,
45                                G4double time, 
46                                G4ThreeVector polarization )
47   : fParticleDefinition(particleDef),
48     fPosition(position),
49     fTime(time),
50     fPolarization(polarization)
51 {
52 //   
53   G4double mass = fParticleDefinition->GetPDGMass();
54   G4double energy = kinEnergy + mass;
55   G4double pmag = sqrt(energy*energy - mass*mass);
56   fParticleMomentum = pmag*momentumDir;
57 }
58
59 //_____________________________________________________________________________
60 AliGunParticle::AliGunParticle(const AliGunParticle& right) {
61 //
62   // copy stuff
63   *this = right;
64 }
65
66 //_____________________________________________________________________________
67 AliGunParticle::~AliGunParticle() {
68 //
69 }
70
71 // operators
72
73 //_____________________________________________________________________________
74 AliGunParticle& AliGunParticle::operator=(const AliGunParticle& right)
75 {    
76   // check assignement to self
77   if (this == &right) return *this;
78
79   fParticleDefinition = right.fParticleDefinition;
80   fParticleMomentum = right.fParticleMomentum;
81   fPosition = right.fPosition; 
82   fTime = right.fTime;
83   fPolarization = right.fPolarization; 
84   
85   return *this;
86 }
87
88 //_____________________________________________________________________________
89 G4int AliGunParticle::operator==(const AliGunParticle& right) const 
90 {
91 //    
92   G4int returnValue = 0;
93   if (fParticleDefinition == right.fParticleDefinition 
94       && fParticleMomentum == right.fParticleMomentum 
95       && fPosition == right.fPosition 
96       && fTime == right.fTime 
97       && fPolarization == right.fPolarization)  returnValue = 1; 
98
99   return returnValue;  
100 }
101
102 //_____________________________________________________________________________
103 G4int AliGunParticle::operator!=(const AliGunParticle& right) const
104 {
105 //    
106   G4int returnValue = 1;
107   if (*this == right) returnValue = 0; 
108   
109   return returnValue;
110 }
111
112 // public methods
113
114 //_____________________________________________________________________________
115 void AliGunParticle::Print() const
116 {
117 // Prints particle properties.
118 // ---
119
120   G4cout << "    particle name: ";
121   G4cout << fParticleDefinition->GetParticleName() << G4endl;
122   G4cout << "    particle momentum: ";
123   G4cout << fParticleMomentum << G4endl;
124   G4cout << "    particle position: ";
125   G4cout << fPosition << " mm" << G4endl;
126   G4cout << "    particle time: ";
127   G4cout << fTime     << " s" << G4endl;
128   G4cout << "    particle polarization: ";
129   G4cout << fPolarization << G4endl;
130 }  
131
132 //_____________________________________________________________________________
133 void AliGunParticle::SetKineticEnergy(G4double kinEnergy)
134 {
135 // Sets kinetic energy.
136 // ---
137
138   G4double mass = fParticleDefinition->GetPDGMass();
139   G4double energy = kinEnergy + mass;
140   G4double pmag = sqrt(energy*energy - mass*mass);
141   fParticleMomentum.setMag(pmag); 
142 }
143
144 //_____________________________________________________________________________
145 G4double AliGunParticle::GetKineticEnergy() const
146 {
147 // Gets kinetic energy.
148 // ---
149
150   G4double mass = fParticleDefinition->GetPDGMass();
151   G4double energy 
152    = sqrt(fParticleMomentum.mag()*fParticleMomentum.mag() + mass*mass);
153   return energy - mass;
154 }