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