source: trunk/examples/advanced/underground_physics/src/DMXParticleSourceMessenger.cc@ 1266

Last change on this file since 1266 was 807, checked in by garnier, 17 years ago

update

File size: 12.0 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// --------------------------------------------------------------
28// GEANT 4 - Underground Dark Matter Detector Advanced Example
29//
30// For information related to this code contact: Alex Howard
31// e-mail: alexander.howard@cern.ch
32// --------------------------------------------------------------
33// Comments
34//
35// Underground Advanced
36// by A. Howard and H. Araujo
37// (27th November 2001)
38//
39// ParticleSourceMessenger program
40// --------------------------------------------------------------
41//////////////////////////////////////////////////////////////////////////////
42// This particle source is a shortened version of G4GeneralParticleSource by
43// C Ferguson, F Lei & P Truscott (University of Southampton / DERA), with
44// some minor modifications.
45//////////////////////////////////////////////////////////////////////////////
46
47#include "DMXParticleSourceMessenger.hh"
48#include "DMXParticleSource.hh"
49
50#include "G4Geantino.hh"
51#include "G4ThreeVector.hh"
52#include "G4ParticleTable.hh"
53#include "G4UIdirectory.hh"
54#include "G4UIcmdWithoutParameter.hh"
55#include "G4UIcmdWithAString.hh"
56#include "G4UIcmdWithADoubleAndUnit.hh"
57#include "G4UIcmdWith3Vector.hh"
58#include "G4UIcmdWith3VectorAndUnit.hh"
59#include "G4UIcmdWithAnInteger.hh"
60#include "G4UIcmdWithADouble.hh"
61#include "G4UIcmdWithABool.hh"
62#include "G4ios.hh"
63#include <fstream>
64#include <iomanip>
65#include "G4Tokenizer.hh"
66
67///////////////////////////////////////////////////////////////////////////////
68DMXParticleSourceMessenger::DMXParticleSourceMessenger
69(DMXParticleSource *fPtclGun) : fParticleGun(fPtclGun),fShootIon(false) {
70
71 particleTable = G4ParticleTable::GetParticleTable();
72
73 // create directory
74 gunDirectory = new G4UIdirectory("/dmx/gun/");
75 gunDirectory->SetGuidance("Particle Source control commands.");
76
77 // list available particles
78 listCmd = new G4UIcmdWithoutParameter("/dmx/gun/List",this);
79 listCmd->SetGuidance("List available particles.");
80 listCmd->SetGuidance(" Invoke G4ParticleTable.");
81
82 // set particle
83 particleCmd = new G4UIcmdWithAString("/dmx/gun/particle",this);
84 particleCmd->SetGuidance("Set particle to be generated.");
85 particleCmd->SetGuidance(" (geantino is default)");
86 particleCmd->SetGuidance(" (ion can be specified for shooting ions)");
87 particleCmd->SetParameterName("particleName",true);
88 particleCmd->SetDefaultValue("geantino");
89 G4String candidateList;
90 G4int nPtcl = particleTable->entries();
91 for(G4int i=0;i<nPtcl;i++)
92 {
93 candidateList += particleTable->GetParticleName(i);
94 candidateList += " ";
95 }
96 candidateList += "ion ";
97 particleCmd->SetCandidates(candidateList);
98
99
100 // particle direction
101 directionCmd = new G4UIcmdWith3Vector("/dmx/gun/direction",this);
102 directionCmd->SetGuidance("Set momentum direction.");
103 directionCmd->SetGuidance("Direction needs not to be a unit vector.");
104 directionCmd->SetParameterName("Px","Py","Pz",true,true);
105 directionCmd->SetRange("Px != 0 || Py != 0 || Pz != 0");
106
107 // particle energy
108 energyCmd = new G4UIcmdWithADoubleAndUnit("/dmx/gun/energy",this);
109 energyCmd->SetGuidance("Set kinetic energy.");
110 energyCmd->SetParameterName("Energy",true,true);
111 energyCmd->SetDefaultUnit("GeV");
112 //energyCmd->SetUnitCategory("Energy");
113 //energyCmd->SetUnitCandidates("eV keV MeV GeV TeV");
114
115 positionCmd = new G4UIcmdWith3VectorAndUnit("/dmx/gun/position",this);
116 positionCmd->SetGuidance("Set starting position of the particle.");
117 positionCmd->SetParameterName("X","Y","Z",true,true);
118 positionCmd->SetDefaultUnit("cm");
119 //positionCmd->SetUnitCategory("Length");
120 //positionCmd->SetUnitCandidates("microm mm cm m km");
121
122
123 // ion
124 ionCmd = new G4UIcommand("/dmx/gun/ion",this);
125 ionCmd->SetGuidance("Set properties of ion to be generated.");
126 ionCmd->SetGuidance("[usage] /gun/ion Z A Q E");
127 ionCmd->SetGuidance(" Z:(int) AtomicNumber");
128 ionCmd->SetGuidance(" A:(int) AtomicMass");
129 ionCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)");
130 ionCmd->SetGuidance(" E:(double) Excitation energy (in keV)");
131
132 G4UIparameter* param;
133 param = new G4UIparameter("Z",'i',false);
134 param->SetDefaultValue("1");
135 ionCmd->SetParameter(param);
136 param = new G4UIparameter("A",'i',false);
137 param->SetDefaultValue("1");
138 ionCmd->SetParameter(param);
139 param = new G4UIparameter("Q",'i',true);
140 param->SetDefaultValue("0");
141 ionCmd->SetParameter(param);
142 param = new G4UIparameter("E",'d',true);
143 param->SetDefaultValue("0.0");
144 ionCmd->SetParameter(param);
145
146
147 // source distribution type
148 typeCmd = new G4UIcmdWithAString("/dmx/gun/type",this);
149 typeCmd->SetGuidance("Sets source distribution type.");
150 typeCmd->SetGuidance("Either Point or Volume");
151 typeCmd->SetParameterName("DisType",true,true);
152 typeCmd->SetDefaultValue("Point");
153 typeCmd->SetCandidates("Point Volume");
154
155 // source shape
156 shapeCmd = new G4UIcmdWithAString("/dmx/gun/shape",this);
157 shapeCmd->SetGuidance("Sets source shape type.");
158 shapeCmd->SetParameterName("Shape",true,true);
159 shapeCmd->SetDefaultValue("NULL");
160 shapeCmd->SetCandidates("Sphere Cylinder");
161
162 // centre coordinates
163 centreCmd = new G4UIcmdWith3VectorAndUnit("/dmx/gun/centre",this);
164 centreCmd->SetGuidance("Set centre coordinates of source.");
165 centreCmd->SetParameterName("X","Y","Z",true,true);
166 centreCmd->SetDefaultUnit("cm");
167 centreCmd->SetUnitCandidates("nm um mm cm m km");
168
169 // half height of source
170 halfzCmd = new G4UIcmdWithADoubleAndUnit("/dmx/gun/halfz",this);
171 halfzCmd->SetGuidance("Set z half length of source.");
172 halfzCmd->SetParameterName("Halfz",true,true);
173 halfzCmd->SetDefaultUnit("cm");
174 halfzCmd->SetUnitCandidates("nm um mm cm m km");
175
176 // radius of source
177 radiusCmd = new G4UIcmdWithADoubleAndUnit("/dmx/gun/radius",this);
178 radiusCmd->SetGuidance("Set radius of source.");
179 radiusCmd->SetParameterName("Radius",true,true);
180 radiusCmd->SetDefaultUnit("cm");
181 radiusCmd->SetUnitCandidates("nm um mm cm m km");
182
183 // confine to volume
184 confineCmd = new G4UIcmdWithAString("/dmx/gun/confine",this);
185 confineCmd->SetGuidance("Confine source to volume (NULL to unset).");
186 confineCmd->SetGuidance("usage: confine VolName");
187 confineCmd->SetParameterName("VolName",true,true);
188 confineCmd->SetDefaultValue("NULL");
189
190 // angular distribution
191 angtypeCmd = new G4UIcmdWithAString("/dmx/gun/angtype",this);
192 angtypeCmd->SetGuidance("Sets angular source distribution type");
193 angtypeCmd->SetGuidance("Possible variables are: iso direction");
194 angtypeCmd->SetParameterName("AngDis",true,true);
195 angtypeCmd->SetDefaultValue("iso");
196 angtypeCmd->SetCandidates("iso direction");
197
198 // energy distribution
199 energytypeCmd = new G4UIcmdWithAString("/dmx/gun/energytype",this);
200 energytypeCmd->SetGuidance("Sets energy distribution type");
201 energytypeCmd->SetGuidance("Possible variables are: Mono");
202 energytypeCmd->SetParameterName("EnergyDis",true,true);
203 energytypeCmd->SetDefaultValue("Mono");
204 energytypeCmd->SetCandidates("Mono");
205
206 // verbosity
207 verbosityCmd = new G4UIcmdWithAnInteger("/dmx/gun/verbose",this);
208 verbosityCmd->SetGuidance("Set Verbose level for gun");
209 verbosityCmd->SetGuidance(" 0 : Silent");
210 verbosityCmd->SetGuidance(" 1 : Limited information");
211 verbosityCmd->SetGuidance(" 2 : Detailed information");
212 verbosityCmd->SetParameterName("level",false);
213 verbosityCmd->SetRange("level>=0 && level <=2");
214
215}
216
217
218DMXParticleSourceMessenger::~DMXParticleSourceMessenger() {
219
220 delete typeCmd;
221 delete shapeCmd;
222 delete centreCmd;
223 delete halfzCmd;
224 delete radiusCmd;
225 delete confineCmd;
226 delete angtypeCmd;
227 delete energytypeCmd;
228 delete verbosityCmd;
229 delete ionCmd;
230 delete particleCmd;
231 delete positionCmd;
232 delete directionCmd;
233 delete energyCmd;
234 delete listCmd;
235
236 delete gunDirectory;
237}
238
239void DMXParticleSourceMessenger::SetNewValue
240 (G4UIcommand *command, G4String newValues) {
241
242 if(command == typeCmd)
243 fParticleGun->SetPosDisType(newValues);
244
245 else if(command == shapeCmd)
246 fParticleGun->SetPosDisShape(newValues);
247
248 else if(command == centreCmd)
249 fParticleGun->SetCentreCoords(centreCmd->GetNew3VectorValue(newValues));
250
251 else if(command == halfzCmd)
252 fParticleGun->SetHalfZ(halfzCmd->GetNewDoubleValue(newValues));
253
254 else if(command == radiusCmd)
255 fParticleGun->SetRadius(radiusCmd->GetNewDoubleValue(newValues));
256
257 else if(command == angtypeCmd)
258 fParticleGun->SetAngDistType(newValues);
259
260 else if(command == confineCmd)
261 fParticleGun->ConfineSourceToVolume(newValues);
262
263 else if(command == energytypeCmd)
264 fParticleGun->SetEnergyDisType(newValues);
265
266 else if(command == verbosityCmd)
267 fParticleGun->SetVerbosity(verbosityCmd->GetNewIntValue(newValues));
268
269 else if( command==particleCmd ) {
270 if (newValues =="ion") {
271 fShootIon = true;
272 } else {
273 fShootIon = false;
274 G4ParticleDefinition* pd = particleTable->FindParticle(newValues);
275 if(pd != NULL)
276 { fParticleGun->SetParticleDefinition( pd ); }
277 }
278 }
279
280 else if( command==ionCmd ) {
281 if (fShootIon) {
282 G4Tokenizer next( newValues );
283 // check argument
284 fAtomicNumber = StoI(next());
285 fAtomicMass = StoI(next());
286 G4String sQ = next();
287 if (sQ.isNull()) {
288 fIonCharge = fAtomicNumber;
289 } else {
290 fIonCharge = StoI(sQ);
291 sQ = next();
292 if (sQ.isNull()) {
293 fIonExciteEnergy = 0.0;
294 } else {
295 fIonExciteEnergy = StoD(sQ) * keV;
296 }
297 }
298
299 G4ParticleDefinition* ion;
300 ion = particleTable->GetIon(fAtomicNumber,fAtomicMass,fIonExciteEnergy);
301 if (ion==0) {
302 G4cout << "Ion with Z=" << fAtomicNumber;
303 G4cout << " A=" << fAtomicMass << "is not be defined" << G4endl;
304 } else {
305 fParticleGun->SetParticleDefinition(ion);
306 fParticleGun->SetParticleCharge(fIonCharge*eplus);
307 }
308 } else {
309 G4cout<<"Set /dmx/gun/particle to ion before using /dmx/gun/ion command";
310 G4cout<<G4endl;
311 }
312 }
313
314 else if( command==listCmd )
315 particleTable->DumpTable();
316
317 else if( command==directionCmd ) {
318 fParticleGun->SetAngDistType("direction");
319 fParticleGun->SetParticleMomentumDirection
320 (directionCmd->GetNew3VectorValue(newValues));
321 }
322
323 else if( command==energyCmd ) {
324 fParticleGun->SetEnergyDisType("Mono");
325 fParticleGun->SetMonoEnergy(energyCmd->GetNewDoubleValue(newValues));
326 }
327
328 else if( command==positionCmd ) {
329 fParticleGun->SetPosDisType("Point");
330 fParticleGun->SetCentreCoords(positionCmd->GetNew3VectorValue(newValues));
331 }
332 else
333 G4cout << "Error entering command" << G4endl;
334}
335
336
337
338
Note: See TracBrowser for help on using the repository browser.