Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMXParticleSourceMessenger.cc
Go to the documentation of this file.
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 <fstream>
48 #include <iomanip>
49 
51 #include "DMXParticleSource.hh"
52 
53 #include "G4SystemOfUnits.hh"
54 #include "G4Geantino.hh"
55 #include "G4ThreeVector.hh"
56 #include "G4ParticleTable.hh"
57 #include "G4UIdirectory.hh"
59 #include "G4UIcmdWithAString.hh"
61 #include "G4UIcmdWith3Vector.hh"
63 #include "G4UIcmdWithAnInteger.hh"
64 #include "G4UIcmdWithADouble.hh"
65 #include "G4UIcmdWithABool.hh"
66 #include "G4ios.hh"
67 #include "G4Tokenizer.hh"
68 
69 ///////////////////////////////////////////////////////////////////////////////
71 (DMXParticleSource *fPtclGun) : fParticleGun(fPtclGun),fShootIon(false) {
72 
73  particleTable = G4ParticleTable::GetParticleTable();
74 
75  // create directory
76  gunDirectory = new G4UIdirectory("/dmx/gun/");
77  gunDirectory->SetGuidance("Particle Source control commands.");
78 
79  // list available particles
80  listCmd = new G4UIcmdWithoutParameter("/dmx/gun/List",this);
81  listCmd->SetGuidance("List available particles.");
82  listCmd->SetGuidance(" Invoke G4ParticleTable.");
83 
84  // set particle
85  particleCmd = new G4UIcmdWithAString("/dmx/gun/particle",this);
86  particleCmd->SetGuidance("Set particle to be generated.");
87  particleCmd->SetGuidance(" (geantino is default)");
88  particleCmd->SetGuidance(" (ion can be specified for shooting ions)");
89  particleCmd->SetParameterName("particleName",true);
90  particleCmd->SetDefaultValue("geantino");
91  G4String candidateList;
92  G4int nPtcl = particleTable->entries();
93  for(G4int i=0;i<nPtcl;i++)
94  {
95  candidateList += particleTable->GetParticleName(i);
96  candidateList += " ";
97  }
98  candidateList += "ion ";
99  particleCmd->SetCandidates(candidateList);
100 
101 
102  // particle direction
103  directionCmd = new G4UIcmdWith3Vector("/dmx/gun/direction",this);
104  directionCmd->SetGuidance("Set momentum direction.");
105  directionCmd->SetGuidance("Direction needs not to be a unit vector.");
106  directionCmd->SetParameterName("Px","Py","Pz",true,true);
107  directionCmd->SetRange("Px != 0 || Py != 0 || Pz != 0");
108 
109  // particle energy
110  energyCmd = new G4UIcmdWithADoubleAndUnit("/dmx/gun/energy",this);
111  energyCmd->SetGuidance("Set kinetic energy.");
112  energyCmd->SetParameterName("Energy",true,true);
113  energyCmd->SetDefaultUnit("GeV");
114  //energyCmd->SetUnitCategory("Energy");
115  //energyCmd->SetUnitCandidates("eV keV MeV GeV TeV");
116 
117  positionCmd = new G4UIcmdWith3VectorAndUnit("/dmx/gun/position",this);
118  positionCmd->SetGuidance("Set starting position of the particle.");
119  positionCmd->SetParameterName("X","Y","Z",true,true);
120  positionCmd->SetDefaultUnit("cm");
121  //positionCmd->SetUnitCategory("Length");
122  //positionCmd->SetUnitCandidates("microm mm cm m km");
123 
124 
125  // ion
126  ionCmd = new G4UIcommand("/dmx/gun/ion",this);
127  ionCmd->SetGuidance("Set properties of ion to be generated.");
128  ionCmd->SetGuidance("[usage] /gun/ion Z A Q E");
129  ionCmd->SetGuidance(" Z:(int) AtomicNumber");
130  ionCmd->SetGuidance(" A:(int) AtomicMass");
131  ionCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)");
132  ionCmd->SetGuidance(" E:(double) Excitation energy (in keV)");
133 
134  G4UIparameter* param;
135  param = new G4UIparameter("Z",'i',false);
136  param->SetDefaultValue("1");
137  ionCmd->SetParameter(param);
138  param = new G4UIparameter("A",'i',false);
139  param->SetDefaultValue("1");
140  ionCmd->SetParameter(param);
141  param = new G4UIparameter("Q",'i',true);
142  param->SetDefaultValue("0");
143  ionCmd->SetParameter(param);
144  param = new G4UIparameter("E",'d',true);
145  param->SetDefaultValue("0.0");
146  ionCmd->SetParameter(param);
147 
148 
149  // source distribution type
150  typeCmd = new G4UIcmdWithAString("/dmx/gun/type",this);
151  typeCmd->SetGuidance("Sets source distribution type.");
152  typeCmd->SetGuidance("Either Point or Volume");
153  typeCmd->SetParameterName("DisType",true,true);
154  typeCmd->SetDefaultValue("Point");
155  typeCmd->SetCandidates("Point Volume");
156 
157  // source shape
158  shapeCmd = new G4UIcmdWithAString("/dmx/gun/shape",this);
159  shapeCmd->SetGuidance("Sets source shape type.");
160  shapeCmd->SetParameterName("Shape",true,true);
161  shapeCmd->SetDefaultValue("NULL");
162  shapeCmd->SetCandidates("Sphere Cylinder");
163 
164  // centre coordinates
165  centreCmd = new G4UIcmdWith3VectorAndUnit("/dmx/gun/centre",this);
166  centreCmd->SetGuidance("Set centre coordinates of source.");
167  centreCmd->SetParameterName("X","Y","Z",true,true);
168  centreCmd->SetDefaultUnit("cm");
169  centreCmd->SetUnitCandidates("nm um mm cm m km");
170 
171  // half height of source
172  halfzCmd = new G4UIcmdWithADoubleAndUnit("/dmx/gun/halfz",this);
173  halfzCmd->SetGuidance("Set z half length of source.");
174  halfzCmd->SetParameterName("Halfz",true,true);
175  halfzCmd->SetDefaultUnit("cm");
176  halfzCmd->SetUnitCandidates("nm um mm cm m km");
177 
178  // radius of source
179  radiusCmd = new G4UIcmdWithADoubleAndUnit("/dmx/gun/radius",this);
180  radiusCmd->SetGuidance("Set radius of source.");
181  radiusCmd->SetParameterName("Radius",true,true);
182  radiusCmd->SetDefaultUnit("cm");
183  radiusCmd->SetUnitCandidates("nm um mm cm m km");
184 
185  // confine to volume
186  confineCmd = new G4UIcmdWithAString("/dmx/gun/confine",this);
187  confineCmd->SetGuidance("Confine source to volume (NULL to unset).");
188  confineCmd->SetGuidance("usage: confine VolName");
189  confineCmd->SetParameterName("VolName",true,true);
190  confineCmd->SetDefaultValue("NULL");
191 
192  // angular distribution
193  angtypeCmd = new G4UIcmdWithAString("/dmx/gun/angtype",this);
194  angtypeCmd->SetGuidance("Sets angular source distribution type");
195  angtypeCmd->SetGuidance("Possible variables are: iso direction");
196  angtypeCmd->SetParameterName("AngDis",true,true);
197  angtypeCmd->SetDefaultValue("iso");
198  angtypeCmd->SetCandidates("iso direction");
199 
200  // energy distribution
201  energytypeCmd = new G4UIcmdWithAString("/dmx/gun/energytype",this);
202  energytypeCmd->SetGuidance("Sets energy distribution type");
203  energytypeCmd->SetGuidance("Possible variables are: Mono");
204  energytypeCmd->SetParameterName("EnergyDis",true,true);
205  energytypeCmd->SetDefaultValue("Mono");
206  energytypeCmd->SetCandidates("Mono");
207 
208  // verbosity
209  verbosityCmd = new G4UIcmdWithAnInteger("/dmx/gun/verbose",this);
210  verbosityCmd->SetGuidance("Set Verbose level for gun");
211  verbosityCmd->SetGuidance(" 0 : Silent");
212  verbosityCmd->SetGuidance(" 1 : Limited information");
213  verbosityCmd->SetGuidance(" 2 : Detailed information");
214  verbosityCmd->SetParameterName("level",false);
215  verbosityCmd->SetRange("level>=0 && level <=2");
216 
217 }
218 
219 
221 
222  delete typeCmd;
223  delete shapeCmd;
224  delete centreCmd;
225  delete halfzCmd;
226  delete radiusCmd;
227  delete confineCmd;
228  delete angtypeCmd;
229  delete energytypeCmd;
230  delete verbosityCmd;
231  delete ionCmd;
232  delete particleCmd;
233  delete positionCmd;
234  delete directionCmd;
235  delete energyCmd;
236  delete listCmd;
237 
238  delete gunDirectory;
239 }
240 
242  (G4UIcommand *command, G4String newValues) {
243 
244  if(command == typeCmd)
245  fParticleGun->SetPosDisType(newValues);
246 
247  else if(command == shapeCmd)
248  fParticleGun->SetPosDisShape(newValues);
249 
250  else if(command == centreCmd)
251  fParticleGun->SetCentreCoords(centreCmd->GetNew3VectorValue(newValues));
252 
253  else if(command == halfzCmd)
254  fParticleGun->SetHalfZ(halfzCmd->GetNewDoubleValue(newValues));
255 
256  else if(command == radiusCmd)
257  fParticleGun->SetRadius(radiusCmd->GetNewDoubleValue(newValues));
258 
259  else if(command == angtypeCmd)
260  fParticleGun->SetAngDistType(newValues);
261 
262  else if(command == confineCmd)
263  fParticleGun->ConfineSourceToVolume(newValues);
264 
265  else if(command == energytypeCmd)
266  fParticleGun->SetEnergyDisType(newValues);
267 
268  else if(command == verbosityCmd)
269  fParticleGun->SetVerbosity(verbosityCmd->GetNewIntValue(newValues));
270 
271  else if( command==particleCmd ) {
272  if (newValues =="ion") {
273  fShootIon = true;
274  } else {
275  fShootIon = false;
276  G4ParticleDefinition* pd = particleTable->FindParticle(newValues);
277  if(pd != NULL)
278  { fParticleGun->SetParticleDefinition( pd ); }
279  }
280  }
281 
282  else if( command==ionCmd ) {
283  if (fShootIon) {
284  G4Tokenizer next( newValues );
285  // check argument
286  fAtomicNumber = StoI(next());
287  fAtomicMass = StoI(next());
288  G4String sQ = next();
289  if (sQ.isNull()) {
290  fIonCharge = fAtomicNumber;
291  } else {
292  fIonCharge = StoI(sQ);
293  sQ = next();
294  if (sQ.isNull()) {
295  fIonExciteEnergy = 0.0;
296  } else {
297  fIonExciteEnergy = StoD(sQ) * keV;
298  }
299  }
300 
302  ion = particleTable->GetIon(fAtomicNumber,fAtomicMass,fIonExciteEnergy);
303  if (ion==0) {
304  G4cout << "Ion with Z=" << fAtomicNumber;
305  G4cout << " A=" << fAtomicMass << "is not be defined" << G4endl;
306  } else {
307  fParticleGun->SetParticleDefinition(ion);
308  fParticleGun->SetParticleCharge(fIonCharge*eplus);
309  }
310  } else {
311  G4cout<<"Set /dmx/gun/particle to ion before using /dmx/gun/ion command";
312  G4cout<<G4endl;
313  }
314  }
315 
316  else if( command==listCmd )
317  particleTable->DumpTable();
318 
319  else if( command==directionCmd ) {
320  fParticleGun->SetAngDistType("direction");
321  fParticleGun->SetParticleMomentumDirection
322  (directionCmd->GetNew3VectorValue(newValues));
323  }
324 
325  else if( command==energyCmd ) {
326  fParticleGun->SetEnergyDisType("Mono");
327  fParticleGun->SetMonoEnergy(energyCmd->GetNewDoubleValue(newValues));
328  }
329 
330  else if( command==positionCmd ) {
331  fParticleGun->SetPosDisType("Point");
332  fParticleGun->SetCentreCoords(positionCmd->GetNew3VectorValue(newValues));
333  }
334  else
335  G4cout << "Error entering command" << G4endl;
336 }
337 
338 
339 
340 
void SetDefaultValue(const char *theDefaultValue)
int G4int
Definition: G4Types.hh:78
void SetNewValue(G4UIcommand *command, G4String newValues)
DMXParticleSourceMessenger(DMXParticleSource *fPtclGun)
G4GLOB_DLL std::ostream G4cout
static G4ParticleTable * GetParticleTable()
#define G4endl
Definition: G4ios.hh:61
G4bool isNull() const