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