]>
Commit | Line | Data |
---|---|---|
676fb573 | 1 | // $Id$ |
2 | // Category: event | |
3 | // | |
4 | // See the class description in the header file. | |
5 | ||
6 | #include "AliParticleGun.h" | |
7 | #include "AliParticleGunMessenger.h" | |
c97337f9 | 8 | #include "AliGunParticle.h" |
676fb573 | 9 | #include "AliGlobals.h" |
10 | ||
c97337f9 | 11 | #include <G4ParticleDefinition.hh> |
676fb573 | 12 | #include <G4PrimaryParticle.hh> |
c97337f9 | 13 | #include <G4PrimaryVertex.hh> |
676fb573 | 14 | #include <G4Event.hh> |
676fb573 | 15 | |
16 | AliParticleGun::AliParticleGun() { | |
17 | // | |
18 | fMessenger = new AliParticleGunMessenger(this); | |
19 | } | |
20 | ||
21 | AliParticleGun::AliParticleGun(const AliParticleGun& right) | |
22 | { | |
23 | // particles vector | |
24 | fGunParticlesVector.clearAndDestroy(); | |
25 | for (G4int i=0; i<right.fGunParticlesVector.entries(); i++) { | |
26 | AliGunParticle* rhsParticle = right.fGunParticlesVector[i]; | |
27 | AliGunParticle* newParticle = new AliGunParticle(*rhsParticle); | |
28 | fGunParticlesVector.insert(newParticle); | |
29 | } | |
30 | ||
31 | fMessenger = new AliParticleGunMessenger(this); | |
32 | } | |
33 | ||
34 | AliParticleGun::~AliParticleGun() { | |
35 | // | |
36 | fGunParticlesVector.clearAndDestroy(); | |
37 | delete fMessenger; | |
38 | } | |
39 | ||
40 | // operators | |
41 | ||
42 | AliParticleGun& AliParticleGun::operator=(const AliParticleGun& right) | |
43 | { | |
44 | // check assignement to self | |
45 | if (this == &right) return *this; | |
46 | ||
47 | // particles vector | |
48 | fGunParticlesVector.clearAndDestroy(); | |
49 | for (G4int i=0; i<right.fGunParticlesVector.entries(); i++) { | |
50 | AliGunParticle* rhsParticle = right.fGunParticlesVector[i]; | |
51 | AliGunParticle* newParticle = new AliGunParticle(*rhsParticle); | |
52 | fGunParticlesVector.insert(newParticle); | |
53 | } | |
54 | ||
55 | return *this; | |
56 | } | |
57 | ||
58 | // public methods | |
59 | ||
60 | void AliParticleGun::AddParticle(AliGunParticle* particle) | |
61 | { | |
62 | // Adds particle. | |
63 | // --- | |
64 | ||
65 | fGunParticlesVector.insert(particle); | |
66 | } | |
67 | ||
68 | void AliParticleGun::RemoveParticle(G4int iParticle) | |
69 | { | |
70 | // Removes particle. | |
71 | // --- | |
72 | ||
73 | AliGunParticle* particle = fGunParticlesVector[iParticle]; | |
74 | fGunParticlesVector.remove(particle); | |
75 | delete particle; | |
76 | } | |
77 | ||
78 | void AliParticleGun::GeneratePrimaryVertex(G4Event* event) | |
79 | { | |
80 | // Generates primary vertices. | |
81 | // --- | |
82 | ||
83 | G4PrimaryVertex* previousVertex = 0; | |
84 | G4ThreeVector previousPosition = G4ThreeVector(); | |
85 | G4double previousTime = 0.; | |
86 | ||
87 | G4int nofGunParticles = fGunParticlesVector.entries(); | |
88 | for( G4int i=0; i<nofGunParticles; i++ ) | |
89 | { | |
90 | AliGunParticle* particle = fGunParticlesVector[i]; | |
91 | ||
92 | G4ParticleDefinition* particleDefinition | |
93 | = particle->GetParticleDefinition(); | |
94 | if (particleDefinition==0) { | |
95 | AliGlobals::Exception( | |
96 | "AliParticleGun::GeneratePrimaryVertex: Unknown particle definition."); | |
97 | } | |
98 | ||
99 | G4ThreeVector position = particle->GetPosition(); | |
100 | G4double time = particle->GetTime(); | |
101 | G4PrimaryVertex* vertex; | |
102 | if ( i==0 || position != previousPosition || time != previousTime ) { | |
103 | // create a new vertex | |
104 | // in case position and time of gun particle are different from | |
105 | // previous values | |
106 | // (vertex objects are destroyed in G4EventManager::ProcessOneEvent() | |
107 | // when event is deleted) | |
108 | vertex = new G4PrimaryVertex(position, time); | |
109 | event->AddPrimaryVertex(vertex); | |
110 | ||
111 | previousVertex = vertex; | |
112 | previousPosition = position; | |
113 | previousTime = time; | |
114 | } | |
115 | else | |
116 | vertex = previousVertex; | |
117 | ||
118 | // create a primary particle and add it to the vertex | |
119 | // (primaryParticle objects are destroyed in G4EventManager::ProcessOneEvent() | |
120 | // when event and then vertex is deleted) | |
121 | G4double px = particle->GetMomentum().x(); | |
122 | G4double py = particle->GetMomentum().y(); | |
123 | G4double pz = particle->GetMomentum().z(); | |
124 | G4PrimaryParticle* primaryParticle | |
125 | = new G4PrimaryParticle(particleDefinition, px, py, pz); | |
126 | ||
127 | G4double mass = particleDefinition->GetPDGMass(); | |
128 | primaryParticle->SetMass(mass); | |
129 | primaryParticle->SetPolarization(particle->GetPolarization().x(), | |
130 | particle->GetPolarization().y(), | |
131 | particle->GetPolarization().z()); | |
132 | ||
133 | vertex->SetPrimary(primaryParticle); | |
134 | } | |
135 | ||
136 | // delete gun particles | |
137 | fGunParticlesVector.clearAndDestroy(); | |
138 | ||
139 | // add verbose | |
5f1d09c5 | 140 | G4cout << "AliParticleGun::GeneratePrimaryVertex:" << G4endl; |
676fb573 | 141 | G4cout << " " |
142 | << event->GetNumberOfPrimaryVertex() << " of primary vertices," | |
5f1d09c5 | 143 | << " " << nofGunParticles << " of primary particles " << G4endl; |
676fb573 | 144 | } |
145 | ||
146 | void AliParticleGun::Reset() | |
147 | { | |
148 | // Resets the particle gun. | |
149 | // --- | |
150 | ||
151 | fGunParticlesVector.clearAndDestroy(); | |
152 | } | |
153 | ||
154 | void AliParticleGun::List() | |
155 | { | |
156 | // Lists the particle gun. | |
157 | // --- | |
158 | ||
159 | G4int nofGunParticles = fGunParticlesVector.entries(); | |
160 | ||
5f1d09c5 | 161 | G4cout << "Particle Gun: " << G4endl; |
676fb573 | 162 | |
163 | if (nofGunParticles==0) | |
5f1d09c5 | 164 | { G4cout << " No particles are defined." << G4endl; } |
676fb573 | 165 | else |
166 | { | |
167 | for (G4int i=0; i<nofGunParticles; i++) | |
168 | { | |
5f1d09c5 | 169 | G4cout << i << " th particle properties: " << G4endl; |
170 | G4cout << "============================" << G4endl; | |
676fb573 | 171 | fGunParticlesVector[i]->Print(); |
172 | } | |
173 | } | |
174 | } | |
175 |