Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UserPhysicsListMessenger.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//
29//---------------------------------------------------------------
30//
31// G4UserPhysicsListMessenger.cc
32// ------------------------------------------------------------
33// History
34// first version 09 Jan. 1998 by H.Kurashige
35// add buildPhysicsTable command 13 Apr. 1999 by H.Kurashige
36// add setStoredInAscii command 12 Mar. 2001 by H.Kurashige
37// add dumpOrderingParam command 3 May. 2011 by H.Kurashige
38// ------------------------------------------------------------
39
40#include <sstream>
41
43
44#include "G4ParticleTable.hh"
46#include "G4SystemOfUnits.hh"
47#include "G4Tokenizer.hh"
49#include "G4UIcmdWithAString.hh"
52#include "G4UIdirectory.hh"
53#include "G4UIparameter.hh"
54#include "G4VUserPhysicsList.hh"
55#include "G4ios.hh"
56
57G4UserPhysicsListMessenger::G4UserPhysicsListMessenger(
58 G4VUserPhysicsList* pParticleList)
59 : thePhysicsList(pParticleList)
60{
61 G4UIparameter* param = 0;
62 // /run/particle directory
63 theDirectory = new G4UIdirectory("/run/particle/");
64 theDirectory->SetGuidance("Commands for G4VUserPhysicsList.");
65
66 // /run/particle/Verbose command
67 verboseCmd = new G4UIcmdWithAnInteger("/run/particle/verbose", this);
68 verboseCmd->SetGuidance("Set the Verbose level of G4VUserPhysicsList.");
69 verboseCmd->SetGuidance(" 0 : Silent (default)");
70 verboseCmd->SetGuidance(" 1 : Display warning messages");
71 verboseCmd->SetGuidance(" 2 : Display more");
72 verboseCmd->SetParameterName("level", true);
73 verboseCmd->SetDefaultValue(0);
74 verboseCmd->SetRange("level >=0 && level <=3");
75
76 // /run/setCut command
77 setCutCmd = new G4UIcmdWithADoubleAndUnit("/run/setCut", this);
78 setCutCmd->SetGuidance("Set default cut value ");
79 setCutCmd->SetParameterName("cut", false);
80 setCutCmd->SetDefaultValue(1.0);
81 setCutCmd->SetRange("cut >=0.0");
82 setCutCmd->SetDefaultUnit("mm");
84
85 // /run/setCutForAGivenParticle command
86 setCutForAGivenParticleCmd =
87 new G4UIcommand("/run/setCutForAGivenParticle", this);
88 setCutForAGivenParticleCmd->SetGuidance(
89 "Set a cut value to a specific particle ");
90 setCutForAGivenParticleCmd->SetGuidance(
91 "Usage: /run/setCutForAGivenParticle gamma 1. mm");
92 param = new G4UIparameter("particleName", 's', false);
93 param->SetParameterCandidates("e- e+ gamma proton");
94 setCutForAGivenParticleCmd->SetParameter(param);
95 param = new G4UIparameter("cut", 'd', false);
96 param->SetDefaultValue("1.");
97 param->SetParameterRange("cut>=0.0");
98 setCutForAGivenParticleCmd->SetParameter(param);
99 param = new G4UIparameter("unit", 's', false);
100 param->SetDefaultUnit("mm");
101 setCutForAGivenParticleCmd->SetParameter(param);
102 setCutForAGivenParticleCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
103
104 // /run/getCutForAGivenParticle command
105 getCutForAGivenParticleCmd =
106 new G4UIcmdWithAString("/run/getCutForAGivenParticle", this);
107 getCutForAGivenParticleCmd->SetGuidance(
108 "Get a cut value to a specific particle ");
109 getCutForAGivenParticleCmd->SetGuidance(
110 "Usage: /run/getCutForAGivenParticle gamma ");
111 getCutForAGivenParticleCmd->SetParameterName("particleName", false, false);
112 getCutForAGivenParticleCmd->SetCandidates("e- e+ gamma proton");
113 getCutForAGivenParticleCmd->AvailableForStates(
115
116 // /run/setCutForRegion command
117 setCutRCmd = new G4UIcommand("/run/setCutForRegion", this);
118 setCutRCmd->SetGuidance("Set cut value for a region");
119 param = new G4UIparameter("Region", 's', false);
120 setCutRCmd->SetParameter(param);
121 param = new G4UIparameter("cut", 'd', false);
122 param->SetParameterRange("cut >=0.0");
123 setCutRCmd->SetParameter(param);
124 param = new G4UIparameter("Unit", 's', true);
125 param->SetDefaultValue("mm");
127 setCutRCmd->UnitsList(setCutRCmd->CategoryOf("mm")));
128 setCutRCmd->SetParameter(param);
129 setCutRCmd->AvailableForStates(G4State_Idle);
130
131 // /run/particle/DumpList command
132 dumpListCmd = new G4UIcmdWithoutParameter("/run/particle/dumpList", this);
133 dumpListCmd->SetGuidance("Dump List of particles in G4VUserPhysicsList. ");
134
135 // /run/particle/addProcManager command
136 addProcManCmd = new G4UIcmdWithAString("/run/particle/addProcManager", this);
137 addProcManCmd->SetToBeBroadcasted(false);
138 addProcManCmd->SetGuidance("add process manager to specified particle type");
139 addProcManCmd->SetParameterName("particleType", true);
140 addProcManCmd->SetDefaultValue("");
143
144 // /run/particle/buildPhysicsTable command
145 buildPTCmd = new G4UIcmdWithAString("/run/particle/buildPhysicsTable", this);
146 buildPTCmd->SetGuidance("build physics table of specified particle type");
147 buildPTCmd->SetParameterName("particleType", true);
148 buildPTCmd->SetDefaultValue("");
151
152 // /run/particle/storePhysicsTable command
153 storeCmd = new G4UIcmdWithAString("/run/particle/storePhysicsTable", this);
154 storeCmd->SetGuidance("Store Physics Table");
155 storeCmd->SetGuidance(" Enter directory name");
156 storeCmd->SetParameterName("dirName", true);
157 storeCmd->SetDefaultValue("");
159
160 // /run/particle/retrievePhysicsTable command
161 retrieveCmd =
162 new G4UIcmdWithAString("/run/particle/retrievePhysicsTable", this);
163 retrieveCmd->SetGuidance("Retrieve Physics Table");
164 retrieveCmd->SetGuidance(" Enter directory name or OFF to switch off");
165 retrieveCmd->SetParameterName("dirName", true);
166 retrieveCmd->SetDefaultValue("");
168
169 // /run/particle/setStoredInAscii command
170 asciiCmd = new G4UIcmdWithAnInteger("/run/particle/setStoredInAscii", this);
171 asciiCmd->SetGuidance(
172 "Switch on/off ascii mode in store/retrieve Physics Table");
173 asciiCmd->SetGuidance(" Enter 0(binary) or 1(ascii)");
174 asciiCmd->SetParameterName("ascii", true);
175 asciiCmd->SetDefaultValue(0);
177 asciiCmd->SetRange("ascii ==0 || ascii ==1");
178
179 // Commnad /run/particle/applyCuts command
180 applyCutsCmd = new G4UIcommand("/run/particle/applyCuts", this);
181 applyCutsCmd->SetGuidance("Set applyCuts flag for a particle.");
182 applyCutsCmd->SetGuidance(
183 " Some EM processes which do not have infrared divergence");
184 applyCutsCmd->SetGuidance(
185 "may generate gamma, e- and/or e+ with kinetic energies");
186 applyCutsCmd->SetGuidance(
187 "below the production threshold. By setting this flag,");
188 applyCutsCmd->SetGuidance(
189 "such secondaries below threshold are eliminated and");
190 applyCutsCmd->SetGuidance(
191 "kinetic energies of such secondaries are accumulated");
192 applyCutsCmd->SetGuidance("to the energy deposition of their mother.");
193 applyCutsCmd->SetGuidance(
194 " Note that 'applyCuts' makes sense only for gamma,");
195 applyCutsCmd->SetGuidance(
196 "e- and e+. If this command is issued for other particle,");
197 applyCutsCmd->SetGuidance(
198 "a warning message is displayed and the command is");
199 applyCutsCmd->SetGuidance("ignored.");
200 applyCutsCmd->SetGuidance(
201 " If particle name is 'all', this command affects on");
202 applyCutsCmd->SetGuidance("gamma, e- and e+.");
203 param = new G4UIparameter("Flag", 's', true);
204 param->SetDefaultValue("true");
205 applyCutsCmd->SetParameter(param);
206 param = new G4UIparameter("Particle", 's', true);
207 param->SetDefaultValue("all");
208 applyCutsCmd->SetParameter(param);
210
211 // /run/particle/dumpCutValues command
212 dumpCutValuesCmd =
213 new G4UIcmdWithAString("/run/particle/dumpCutValues", this);
214 dumpCutValuesCmd->SetGuidance(
215 "Dump a list of production threshold values in range and energy");
216 dumpCutValuesCmd->SetGuidance("for all registered material-cuts-couples.");
217 dumpCutValuesCmd->SetGuidance(
218 "Dumping a list takes place when you issue 'beamOn' and");
219 dumpCutValuesCmd->SetGuidance(
220 "actual conversion tables from range to energy are available.");
221 dumpCutValuesCmd->SetGuidance(
222 "If you want a list 'immediately', use '/run/dumpRegion' for threshold");
223 dumpCutValuesCmd->SetGuidance(
224 "list given in range only. Also, '/run/dumpCouples' gives you the");
225 dumpCutValuesCmd->SetGuidance(
226 "current list if you have already issued 'run/beamOn' at least once.");
227 dumpCutValuesCmd->SetParameterName("particle", true);
228 dumpCutValuesCmd->SetDefaultValue("all");
229 dumpCutValuesCmd->AvailableForStates(G4State_Idle);
230
231 // /run/particle/dumpCutValues command
232 dumpOrdParamCmd =
233 new G4UIcmdWithAnInteger("/run/particle/dumpOrderingParam", this);
234 dumpOrdParamCmd->SetGuidance("Dump a list of ordering parameter ");
235 dumpOrdParamCmd->SetParameterName("subtype", true);
236 dumpOrdParamCmd->SetDefaultValue(-1);
239}
240
242{
243 delete setCutCmd;
244 delete setCutRCmd;
245 delete setCutForAGivenParticleCmd;
246 delete getCutForAGivenParticleCmd;
247 delete verboseCmd;
248 delete dumpListCmd;
249 delete addProcManCmd;
250 delete buildPTCmd;
251 delete storeCmd;
252 delete retrieveCmd;
253 delete asciiCmd;
254 delete applyCutsCmd;
255 delete dumpCutValuesCmd;
256 delete dumpOrdParamCmd;
257 delete theDirectory;
258}
259
261 G4String newValue)
262{
264 if(command == setCutCmd)
265 {
266 G4double newCut = setCutCmd->GetNewDoubleValue(newValue);
269 }
270 else if(command == setCutForAGivenParticleCmd)
271 {
272 G4String particleName, unit;
273 G4double cut;
274 std::istringstream str(newValue);
275 str >> particleName >> cut >> unit;
276 thePhysicsList->SetCutValue(cut * G4UIcommand::ValueOf(unit), particleName);
277 }
278 else if(command == getCutForAGivenParticleCmd)
279 {
280 G4cout << thePhysicsList->GetCutValue(newValue) / mm << "[mm]" << G4endl;
281 }
282 else if(command == setCutRCmd)
283 {
284 std::istringstream is(newValue);
285 G4String regName;
286 G4String uniName;
287 G4double cVal = -1.0;
288 is >> regName >> cVal >> uniName;
289 if(is.fail())
290 {
291 ed << "illegal arguments : " << newValue;
292 command->CommandFailed(ed);
293 return;
294 }
295 thePhysicsList->SetCutsForRegion(cVal * (setCutRCmd->ValueOf(uniName)),
296 regName);
297 }
298 else if(command == verboseCmd)
299 {
300 thePhysicsList->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue));
301 }
302 else if(command == dumpListCmd)
303 {
305 }
306 else if(command == dumpOrdParamCmd)
307 {
308 G4int stype = dumpOrdParamCmd->GetNewIntValue(newValue);
310 stype);
311 }
312 else if(command == addProcManCmd)
313 {
314 G4ParticleDefinition* particle =
315 (G4ParticleTable::GetParticleTable())->FindParticle(newValue);
316 if(particle == 0)
317 {
318 ed << " Particle is not found : " << newValue;
319 command->CommandFailed(ed);
320 return;
321 }
322 else if(particle->GetProcessManager() != 0)
323 {
324 ed << " Particle is not initialized : " << newValue;
325 command->CommandFailed(ed);
326 return;
327 }
329 }
330 else if(command == buildPTCmd)
331 {
332 G4ParticleDefinition* particle =
333 (G4ParticleTable::GetParticleTable())->FindParticle(newValue);
334 if(particle == 0)
335 {
336 ed << " Particle is not found : " << newValue;
337 command->CommandFailed(ed);
338 return;
339 }
342 }
343 else if(command == storeCmd)
344 {
346 }
347 else if(command == retrieveCmd)
348 {
349 if((newValue == "OFF") || (newValue == "off"))
350 {
352 }
353 else
354 {
356 }
357 }
358 else if(command == asciiCmd)
359 {
360 if(asciiCmd->GetNewIntValue(newValue) == 0)
361 {
363 }
364 else
365 {
367 }
368 }
369 else if(command == applyCutsCmd)
370 {
371 G4Tokenizer next(newValue);
372
373 // check 1st argument
374 G4String temp = G4String(next());
375 G4bool flag = (temp == "true" || temp == "TRUE");
376
377 // check 2nd argument
378 G4String name = G4String(next());
379
380 thePhysicsList->SetApplyCuts(flag, name);
381 }
382 else if(command == dumpCutValuesCmd)
383 {
385 }
386}
387
389{
390 G4String cv;
391 G4String candidates("none");
393 (G4ParticleTable::GetParticleTable())->GetIterator();
394
395 if(command == setCutCmd)
396 {
397 cv = setCutCmd->ConvertToString(thePhysicsList->GetDefaultCutValue(), "mm");
398 }
399 else if(command == verboseCmd)
400 {
402 }
403 else if(command == addProcManCmd)
404 {
405 // set candidate list
406 piter->reset();
407 while((*piter)())
408 {
409 G4ParticleDefinition* particle = piter->value();
410 candidates += " " + particle->GetParticleName();
411 }
412 addProcManCmd->SetCandidates(candidates);
413 cv = "";
414 }
415 else if(command == buildPTCmd)
416 {
417 // set candidate list
418 piter->reset();
419 while((*piter)())
420 {
421 G4ParticleDefinition* particle = piter->value();
422 candidates += " " + particle->GetParticleName();
423 }
424 addProcManCmd->SetCandidates(candidates);
425 cv = "";
426 }
427 else if(command == storeCmd)
428 {
430 }
431 else if(command == retrieveCmd)
432 {
434 {
436 }
437 else
438 {
439 cv = "OFF";
440 }
441 }
442 else if(command == asciiCmd)
443 {
445 {
446 cv = "1";
447 }
448 else
449 {
450 cv = "0";
451 }
452
453 // } else if( command == applyCutsCmd ) {
454 // if (thePhysicsList->GetApplyCuts("gamma")){
455 // cv = "true";
456 // } else {
457 // cv = "false";
458 // }
459 }
460
461 return cv;
462}
@ G4State_EventProc
@ G4State_Init
@ G4State_Idle
@ G4State_GeomClosed
@ G4State_PreInit
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4ProcessManager * GetProcessManager() const
const G4String & GetParticleName() const
void reset(G4bool ifSkipIon=true)
static G4ParticleTable * GetParticleTable()
static G4PhysicsListHelper * GetPhysicsListHelper()
void DumpOrdingParameterTable(G4int subType=-1) const
void SetDefaultUnit(const char *defUnit)
static G4double GetNewDoubleValue(const char *paramString)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetCandidates(const char *candidateList)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(const char *defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetDefaultValue(G4int defVal)
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:172
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:356
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:348
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:430
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:146
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:179
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:362
void SetRange(const char *rs)
Definition: G4UIcommand.hh:120
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:273
void SetDefaultValue(const char *theDefaultValue)
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)
void SetDefaultUnit(const char *theDefaultUnit)
virtual G4String GetCurrentValue(G4UIcommand *command)
virtual void SetNewValue(G4UIcommand *command, G4String newValues)
G4double GetCutValue(const G4String &pname) const
void SetDefaultCutValue(G4double newCutValue)
void SetPhysicsTableRetrieved(const G4String &directory="")
void PreparePhysicsTable(G4ParticleDefinition *)
void SetCutValue(G4double aCut, const G4String &pname)
G4bool IsStoredInAscii() const
void SetCutsForRegion(G4double aCut, const G4String &rname)
G4bool StorePhysicsTable(const G4String &directory=".")
void SetVerboseLevel(G4int value)
G4int GetVerboseLevel() const
void SetApplyCuts(G4bool value, const G4String &name)
const G4String & GetPhysicsTableDirectory() const
G4bool IsPhysicsTableRetrieved() const
void DumpCutValuesTable(G4int flag=1)
void AddProcessManager(G4ParticleDefinition *newParticle, G4ProcessManager *newManager=0)
G4double GetDefaultCutValue() const