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