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