]>
Commit | Line | Data |
---|---|---|
676fb573 | 1 | // $Id$ |
2 | // Category: event | |
3 | // | |
7005154f | 4 | // Author: I. Hrivnacova |
5 | // | |
6 | // Class AliParticleGunMessenger | |
7 | // ----------------------------- | |
676fb573 | 8 | // See the class description in the header file. |
9 | ||
10 | #include "AliParticleGunMessenger.h" | |
11 | #include "AliParticleGun.h" | |
12 | #include "AliGunParticle.h" | |
13 | #include "AliGlobals.h" | |
14 | ||
15 | #include <G4Geantino.hh> | |
16 | #include <G4ThreeVector.hh> | |
17 | #include <G4ParticleTable.hh> | |
18 | #include <G4UIdirectory.hh> | |
19 | #include <G4UIcmdWithoutParameter.hh> | |
20 | #include <G4UIcmdWithAString.hh> | |
21 | #include <G4UIcmdWithADoubleAndUnit.hh> | |
22 | #include <G4UIcmdWithAnInteger.hh> | |
23 | #include <G4UIcmdWith3Vector.hh> | |
24 | #include <G4UIcmdWith3VectorAndUnit.hh> | |
25 | ||
78ca1e9c | 26 | //_____________________________________________________________________________ |
676fb573 | 27 | AliParticleGunMessenger::AliParticleGunMessenger(AliParticleGun* gun) |
28 | :fGun(gun) | |
29 | { | |
30 | // | |
31 | fParticleTable = G4ParticleTable::GetParticleTable(); | |
32 | ||
33 | fGunDirectory = new G4UIdirectory("/aliGun/"); | |
34 | fGunDirectory->SetGuidance("AliParticleGun control commands."); | |
35 | ||
36 | fListAvailableCmd | |
37 | = new G4UIcmdWithoutParameter("/aliGun/listAvailable", this); | |
38 | fListAvailableCmd->SetGuidance("List available particles."); | |
39 | fListAvailableCmd->SetGuidance(" Invoke G4ParticleTable."); | |
40 | fListAvailableCmd->AvailableForStates(PreInit,Idle); | |
41 | ||
42 | fListCurrentCmd | |
43 | = new G4UIcmdWithoutParameter("/aliGun/listCurrent", this); | |
44 | fListCurrentCmd->SetGuidance("List current particle properties."); | |
45 | fListCurrentCmd | |
46 | ->SetGuidance("(Use addParticle to add this particle to the gun."); | |
47 | fListCurrentCmd->AvailableForStates(PreInit,Idle); | |
48 | ||
49 | fParticleCmd | |
50 | = new G4UIcmdWithAString("/aliGun/particle", this); | |
51 | fParticleCmd->SetGuidance("Set particle to be generated."); | |
52 | fParticleCmd->SetGuidance(" (geantino is default)"); | |
53 | fParticleCmd->SetParameterName("particleName", true); | |
54 | fParticleCmd->SetDefaultValue("geantino"); | |
55 | G4String candidateList; | |
56 | G4int nofPTEntries = fParticleTable->entries(); | |
57 | for (G4int i=0; i<nofPTEntries; i++) | |
58 | { | |
59 | candidateList += fParticleTable->GetParticleName(i); | |
60 | candidateList += " "; | |
61 | } | |
62 | fParticleCmd->SetCandidates(candidateList); | |
63 | fParticleCmd->AvailableForStates(PreInit,Idle); | |
64 | ||
65 | fMomentumCmd | |
66 | = new G4UIcmdWith3VectorAndUnit("/aliGun/momentum", this); | |
67 | fMomentumCmd->SetGuidance("Set momentum."); | |
68 | fMomentumCmd->SetParameterName("Px","Py","Pz", true, true); | |
69 | fMomentumCmd->SetDefaultUnit("MeV"); | |
70 | fMomentumCmd->SetUnitCategory("Energy"); | |
71 | fMomentumCmd->SetRange("Px != 0 || Py != 0 || Pz != 0"); | |
72 | fMomentumCmd->AvailableForStates(PreInit,Idle); | |
73 | ||
74 | fPositionCmd | |
75 | = new G4UIcmdWith3VectorAndUnit("/aliGun/position", this); | |
76 | fPositionCmd->SetGuidance("Set starting position of the particle."); | |
77 | fPositionCmd->SetParameterName("X","Y","Z", true, true); | |
78 | fPositionCmd->SetDefaultUnit("cm"); | |
79 | fPositionCmd->SetUnitCategory("Length"); | |
80 | fPositionCmd->AvailableForStates(PreInit,Idle); | |
81 | ||
82 | fTimeCmd | |
83 | = new G4UIcmdWithADoubleAndUnit("/aliGun/time", this); | |
84 | fTimeCmd->SetGuidance("Set initial time of the particle."); | |
85 | fTimeCmd->SetParameterName("t0", true, true); | |
86 | fTimeCmd->SetDefaultUnit("ns"); | |
87 | fTimeCmd->SetUnitCategory("Time"); | |
88 | fTimeCmd->AvailableForStates(PreInit,Idle); | |
89 | ||
90 | fPolarizationCmd | |
91 | = new G4UIcmdWith3Vector("/aliGun/polarization", this); | |
92 | fPolarizationCmd->SetGuidance("Set polarization."); | |
93 | fPolarizationCmd->SetParameterName("Px","Py","Pz", true, true); | |
94 | fPolarizationCmd | |
95 | ->SetRange("Px>=-1. && Px<=1. && Py>=-1. && Py<=1. && Pz>=-1. && Pz<=1."); | |
96 | fPolarizationCmd->AvailableForStates(PreInit,Idle); | |
97 | ||
98 | fDirectionCmd | |
99 | = new G4UIcmdWith3Vector("/aliGun/direction", this); | |
100 | fDirectionCmd->SetGuidance("Set momentum direction."); | |
101 | fDirectionCmd->SetGuidance("Direction needs not to be a unit vector."); | |
102 | fDirectionCmd->SetParameterName("Dx","Dy","Dz", true, true); | |
103 | fDirectionCmd->SetRange("Dx != 0 || Dy != 0 || Dz != 0"); | |
104 | fDirectionCmd->AvailableForStates(PreInit,Idle); | |
105 | ||
106 | fKinEnergyCmd | |
107 | = new G4UIcmdWithADoubleAndUnit("/aliGun/kinEnergy", this); | |
108 | fKinEnergyCmd->SetGuidance("Set kinetic energy."); | |
109 | fKinEnergyCmd->SetParameterName("KineticEnergy", true, true); | |
110 | fKinEnergyCmd->SetDefaultUnit("GeV"); | |
111 | fKinEnergyCmd->SetUnitCategory("Energy"); | |
112 | fKinEnergyCmd->AvailableForStates(PreInit,Idle); | |
113 | ||
114 | fListCmd | |
115 | = new G4UIcmdWithoutParameter("/aliGun/list",this); | |
116 | fListCmd->SetGuidance("List the Alice gun particles."); | |
117 | fListCmd->AvailableForStates(PreInit,Idle); | |
118 | ||
119 | fAddParticleCmd | |
120 | = new G4UIcmdWithoutParameter("/aliGun/addParticle", this); | |
121 | fAddParticleCmd->SetGuidance("Add the particle to the Alice particle gun."); | |
122 | fAddParticleCmd->AvailableForStates(PreInit,Idle); | |
123 | ||
124 | fRemoveParticleCmd | |
125 | = new G4UIcmdWithAnInteger("/aliGun/removeParticle", this); | |
126 | fRemoveParticleCmd | |
127 | ->SetGuidance("Remove the i-th particle friom the Alice particle gun."); | |
128 | fRemoveParticleCmd->SetParameterName("iParticle", false); | |
129 | fRemoveParticleCmd->SetRange("iParticle>=0"); | |
130 | fRemoveParticleCmd->AvailableForStates(PreInit,Idle); | |
131 | ||
132 | fResetCmd | |
133 | = new G4UIcmdWithoutParameter("/aliGun/reset", this); | |
134 | fResetCmd->SetGuidance("ReSet the Alice particle gun."); | |
135 | fResetCmd->AvailableForStates(PreInit,Idle); | |
136 | ||
137 | // Set initial value to AliGunParticle | |
138 | fParticle = new AliGunParticle(); | |
139 | ||
140 | fParticle->SetParticleDefinition(G4Geantino::Geantino()); | |
141 | fParticle->SetMomentumDirection(G4ThreeVector(1.0,0.0,0.0)); | |
142 | fParticle->SetKineticEnergy(1.0*GeV); | |
143 | fParticle->SetPosition(G4ThreeVector(0.0*cm, 0.0*cm, 0.0*cm)); | |
144 | fParticle->SetTime(0.0*ns); | |
145 | fParticle->SetPolarization(G4ThreeVector(0.0*cm, 0.0*cm, 0.0*cm)); | |
146 | } | |
147 | ||
78ca1e9c | 148 | //_____________________________________________________________________________ |
676fb573 | 149 | AliParticleGunMessenger::AliParticleGunMessenger() { |
150 | // | |
151 | } | |
152 | ||
78ca1e9c | 153 | //_____________________________________________________________________________ |
676fb573 | 154 | AliParticleGunMessenger::AliParticleGunMessenger( |
155 | const AliParticleGunMessenger& right) { | |
156 | // | |
157 | AliGlobals::Exception("AliParticleGunMessenger is protected from copying."); | |
158 | } | |
159 | ||
78ca1e9c | 160 | //_____________________________________________________________________________ |
676fb573 | 161 | AliParticleGunMessenger::~AliParticleGunMessenger() { |
162 | // | |
163 | delete fListAvailableCmd; | |
164 | delete fParticleCmd; | |
165 | delete fMomentumCmd; | |
166 | delete fPositionCmd; | |
167 | delete fTimeCmd; | |
168 | delete fPolarizationCmd; | |
169 | delete fDirectionCmd; | |
170 | delete fKinEnergyCmd; | |
171 | delete fListCmd; | |
172 | delete fAddParticleCmd; | |
173 | delete fRemoveParticleCmd; | |
174 | delete fResetCmd; | |
175 | delete fGunDirectory; | |
176 | delete fParticle; | |
177 | } | |
178 | ||
179 | // operators | |
180 | ||
181 | AliParticleGunMessenger& | |
182 | AliParticleGunMessenger::operator=(const AliParticleGunMessenger &right) | |
183 | { | |
184 | // check assignement to self | |
185 | if (this == &right) return *this; | |
186 | ||
187 | AliGlobals::Exception("AliParticleGunMessenger is protected from assigning."); | |
188 | ||
189 | return *this; | |
190 | } | |
191 | ||
192 | // public methods | |
193 | ||
78ca1e9c | 194 | //_____________________________________________________________________________ |
676fb573 | 195 | void AliParticleGunMessenger::SetNewValue(G4UIcommand * command, |
196 | G4String newValues) | |
197 | { | |
198 | // Applies command to the associated object. | |
199 | // --- | |
200 | ||
201 | // Alice gun particle set commands | |
202 | if (command==fListAvailableCmd) | |
203 | { | |
204 | fParticleTable->DumpTable(); | |
205 | } | |
206 | else if (command == fParticleCmd) | |
207 | { | |
208 | G4ParticleDefinition* particleDef | |
209 | = fParticleTable->FindParticle(newValues); | |
210 | if (particleDef != 0) | |
211 | { fParticle->SetParticleDefinition(particleDef); } | |
212 | } | |
213 | else if (command == fListCurrentCmd) | |
214 | { | |
215 | fParticle->Print(); | |
216 | } | |
217 | else if (command == fMomentumCmd) | |
218 | { | |
219 | fParticle->SetMomentum(fMomentumCmd->GetNew3VectorValue(newValues)); | |
220 | } | |
221 | else if (command == fPositionCmd) | |
222 | { | |
223 | fParticle->SetPosition(fDirectionCmd->GetNew3VectorValue(newValues)); | |
224 | } | |
225 | else if (command == fTimeCmd) | |
226 | { | |
227 | fParticle->SetTime(fTimeCmd->GetNewDoubleValue(newValues)); | |
228 | } | |
229 | else if (command == fPolarizationCmd) | |
230 | { | |
231 | fParticle | |
232 | ->SetPolarization(fPolarizationCmd->GetNew3VectorValue(newValues)); | |
233 | } | |
234 | else if (command == fDirectionCmd) | |
235 | { | |
236 | fParticle | |
237 | ->SetMomentumDirection(fDirectionCmd->GetNew3VectorValue(newValues)); | |
238 | } | |
239 | else if (command == fKinEnergyCmd) | |
240 | { | |
241 | fParticle->SetKineticEnergy(fKinEnergyCmd->GetNewDoubleValue(newValues)); | |
242 | } | |
243 | ||
244 | // Alice particle gun commands | |
245 | else if (command == fListCmd) | |
246 | { | |
247 | fGun->List(); | |
248 | } | |
249 | else if (command == fAddParticleCmd) | |
250 | { | |
251 | fGun->AddParticle(fParticle); | |
252 | fParticle = new AliGunParticle(*fParticle); | |
253 | } | |
254 | else if (command == fRemoveParticleCmd) | |
255 | { | |
256 | fGun->RemoveParticle(fRemoveParticleCmd->GetNewIntValue(newValues)); | |
257 | } | |
258 | else if (command == fResetCmd) | |
259 | { | |
260 | fGun->Reset(); | |
261 | } | |
262 | } | |
263 | ||
78ca1e9c | 264 | //_____________________________________________________________________________ |
676fb573 | 265 | G4String AliParticleGunMessenger::GetCurrentValue(G4UIcommand * command) |
266 | { | |
267 | // Returns current command parameters as string. | |
268 | // --- | |
269 | ||
270 | G4String curValue; | |
271 | ||
272 | if( command==fDirectionCmd ) | |
273 | { | |
274 | curValue | |
275 | = fDirectionCmd->ConvertToString(fParticle->GetMomentumDirection()); | |
276 | } | |
277 | else if( command==fKinEnergyCmd ) | |
278 | { | |
279 | curValue | |
280 | = fKinEnergyCmd->ConvertToString(fParticle->GetKineticEnergy(),"GeV"); | |
281 | } | |
282 | else if( command==fPositionCmd ) | |
283 | { | |
284 | curValue = fPositionCmd->ConvertToString(fParticle->GetPosition(),"cm"); | |
285 | } | |
286 | else if( command==fTimeCmd ) | |
287 | { | |
288 | curValue = fTimeCmd->ConvertToString(fParticle->GetTime(),"ns"); | |
289 | } | |
290 | else if( command==fPolarizationCmd ) | |
291 | { | |
292 | curValue = fPolarizationCmd->ConvertToString(fParticle->GetPolarization()); | |
293 | } | |
294 | ||
295 | return curValue; | |
296 | } | |
297 |