source: trunk/source/run/src/G4UserPhysicsListMessenger.cc@ 1291

Last change on this file since 1291 was 1196, checked in by garnier, 16 years ago

update CVS release candidate geant4.9.3.01

File size: 14.8 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// $Id: G4UserPhysicsListMessenger.cc,v 1.30 2009/10/20 07:07:51 kurasige Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30//
31//---------------------------------------------------------------
32//
33// G4UserPhysicsListMessenger.cc
34// ------------------------------------------------------------
35// History
36// first version 09 Jan. 1998 by H.Kurashige
37// add buildPhysicsTable command 13 Apr. 1999 by H.Kurashige
38// add setStoredInAscii command 12 Mar. 2001 by H.Kurashige
39// ------------------------------------------------------------
40
41#include "G4UserPhysicsListMessenger.hh"
42#include "G4VUserPhysicsList.hh"
43#include "G4UIdirectory.hh"
44#include "G4UIcmdWithoutParameter.hh"
45#include "G4UIcmdWithAnInteger.hh"
46#include "G4UIcmdWithADoubleAndUnit.hh"
47#include "G4UIcmdWithAString.hh"
48#include "G4ParticleTable.hh"
49#include "G4ios.hh"
50#include "G4Tokenizer.hh"
51
52#include <sstream>
53
54G4UserPhysicsListMessenger::G4UserPhysicsListMessenger(G4VUserPhysicsList* pParticleList):thePhysicsList(pParticleList)
55{
56 G4UIparameter* param = 0;
57 // /run/particle directory
58 theDirectory = new G4UIdirectory("/run/particle/");
59 theDirectory->SetGuidance("Commands for G4VUserPhysicsList.");
60
61 // /run/particle/Verbose command
62 verboseCmd = new G4UIcmdWithAnInteger("/run/particle/verbose",this);
63 verboseCmd->SetGuidance("Set the Verbose level of G4VUserPhysicsList.");
64 verboseCmd->SetGuidance(" 0 : Silent (default)");
65 verboseCmd->SetGuidance(" 1 : Display warning messages");
66 verboseCmd->SetGuidance(" 2 : Display more");
67 verboseCmd->SetParameterName("level",true);
68 verboseCmd->SetDefaultValue(0);
69 verboseCmd->SetRange("level >=0 && level <=3");
70
71 // /run/setCut command
72 setCutCmd = new G4UIcmdWithADoubleAndUnit("/run/setCut",this);
73 setCutCmd->SetGuidance("Set default cut value ");
74 setCutCmd->SetParameterName("cut",false);
75 setCutCmd->SetDefaultValue(1.0);
76 setCutCmd->SetRange("cut >0.0");
77 setCutCmd->SetDefaultUnit("mm");
78 setCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
79
80 // /run/particle/setCut command
81 setPCutCmd = new G4UIcmdWithADoubleAndUnit("/run/particle/setCut",this);
82 setPCutCmd->SetGuidance("Set default cut value ");
83 setPCutCmd->SetGuidance("This command is equivallent to /run/setCut command.");
84 setPCutCmd->SetGuidance("This command is kept for backward compatibility.");
85 setPCutCmd->SetParameterName("cut",false);
86 setPCutCmd->SetDefaultValue(1.0);
87 setPCutCmd->SetRange("cut >0.0");
88 setPCutCmd->SetDefaultUnit("mm");
89 setPCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
90
91 // /run/setCutForAGivenParticle command
92 setCutForAGivenParticleCmd = new G4UIcommand("/run/setCutForAGivenParticle",this) ;
93 setCutForAGivenParticleCmd->SetGuidance("Set a cut value to a specific particle") ;
94 setCutForAGivenParticleCmd->SetGuidance("Usage: /run/setCutForAGivenParticle gamma 1. mm") ;
95 param = new G4UIparameter("particleName",'s',false) ;
96 param->SetParameterCandidates("e- e+ gamma proton");
97 setCutForAGivenParticleCmd->SetParameter(param) ;
98 param = new G4UIparameter("cut",'d',false) ;
99 param->SetDefaultValue("1.") ;
100 param->SetParameterRange("cut>0.0") ;
101 setCutForAGivenParticleCmd->SetParameter(param) ;
102 param = new G4UIparameter("unit",'s',false) ;
103 param->SetDefaultValue("mm") ;
104 setCutForAGivenParticleCmd->SetParameter(param) ;
105 setCutForAGivenParticleCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
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");
117 param->SetParameterCandidates(setCutRCmd->UnitsList(setCutRCmd->CategoryOf("mm")));
118 setCutRCmd->SetParameter(param);
119 setCutRCmd->AvailableForStates(G4State_Idle);
120
121 // /run/particle/DumpList command
122 dumpListCmd = new G4UIcmdWithoutParameter("/run/particle/dumpList",this);
123 dumpListCmd->SetGuidance("Dump List of particles in G4VUserPhysicsList. ");
124
125 // /run/particle/addProcManager command
126 addProcManCmd = new G4UIcmdWithAString("/run/particle/addProcManager", this);
127 addProcManCmd->SetGuidance("add process manager to specified particle type");
128 addProcManCmd->SetParameterName("particleType", true);
129 addProcManCmd->SetDefaultValue("");
130 addProcManCmd->AvailableForStates(G4State_Init,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
131
132 // /run/particle/buildPhysicsTable command
133 buildPTCmd = new G4UIcmdWithAString("/run/particle/buildPhysicsTable", this);
134 buildPTCmd->SetGuidance("build physics table of specified particle type");
135 buildPTCmd->SetParameterName("particleType", true);
136 buildPTCmd->SetDefaultValue("");
137 buildPTCmd->AvailableForStates(G4State_Init,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
138
139 // /run/particle/storePhysicsTable command
140 storeCmd = new G4UIcmdWithAString("/run/particle/storePhysicsTable",this);
141 storeCmd->SetGuidance("Store Physics Table");
142 storeCmd->SetGuidance(" Enter directory name");
143 storeCmd->SetParameterName("dirName",true);
144 storeCmd->SetDefaultValue("");
145 storeCmd->AvailableForStates(G4State_Idle);
146
147 // /run/particle/retrievePhysicsTable command
148 retrieveCmd = new G4UIcmdWithAString("/run/particle/retrievePhysicsTable",this);
149 retrieveCmd->SetGuidance("Retrieve Physics Table");
150 retrieveCmd->SetGuidance(" Enter directory name or OFF to switch off");
151 retrieveCmd->SetParameterName("dirName",true);
152 retrieveCmd->SetDefaultValue("");
153 retrieveCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
154
155 // /run/particle/setStoredInAscii command
156 asciiCmd = new G4UIcmdWithAnInteger("/run/particle/setStoredInAscii",this);
157 asciiCmd->SetGuidance("Switch on/off ascii mode in store/retreive Physics Table");
158 asciiCmd->SetGuidance(" Enter 0(binary) or 1(ascii)");
159 asciiCmd->SetParameterName("ascii",true);
160 asciiCmd->SetDefaultValue(0);
161 asciiCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
162 asciiCmd->SetRange("ascii ==0 || ascii ==1");
163
164 //Commnad /run/particle/applyCuts command
165 applyCutsCmd = new G4UIcommand("/run/particle/applyCuts",this);
166 applyCutsCmd->SetGuidance("Set applyCuts flag for a particle.");
167 applyCutsCmd->SetGuidance(" Some EM processes which do not have infrared divergence");
168 applyCutsCmd->SetGuidance("may generate gamma, e- and/or e+ with kinetic energies");
169 applyCutsCmd->SetGuidance("below the production threshold. By setting this flag,");
170 applyCutsCmd->SetGuidance("such secondaries below threshold are eliminated and");
171 applyCutsCmd->SetGuidance("kinetic energies of such secondaries are accumulated");
172 applyCutsCmd->SetGuidance("to the energy deposition of their mother.");
173 applyCutsCmd->SetGuidance(" Note that 'applyCuts' makes sense only for gamma,");
174 applyCutsCmd->SetGuidance("e- and e+. If this command is issued for other particle,");
175 applyCutsCmd->SetGuidance("a warning message is displayed and the command is");
176 applyCutsCmd->SetGuidance("ignored.");
177 applyCutsCmd->SetGuidance(" If particle name is 'all', this command affects on");
178 applyCutsCmd->SetGuidance("gamma, e- and e+.");
179 param = new G4UIparameter("Flag",'s',true);
180 param->SetDefaultValue("true");
181 applyCutsCmd->SetParameter(param);
182 param = new G4UIparameter("Particle",'s',true);
183 param->SetDefaultValue("all");
184 applyCutsCmd->SetParameter(param);
185 applyCutsCmd->AvailableForStates(G4State_PreInit,G4State_Init,G4State_Idle);
186
187 // /run/particle/dumpCutValues command
188 dumpCutValuesCmd = new G4UIcmdWithAString("/run/particle/dumpCutValues",this);
189 dumpCutValuesCmd->SetGuidance("Dump a list of production threshold values in range and energy");
190 dumpCutValuesCmd->SetGuidance("for all registered material-cuts-couples.");
191 dumpCutValuesCmd->SetGuidance("Dumping a list takes place when you issue 'beamOn' and");
192 dumpCutValuesCmd->SetGuidance("actual conversion tables from range to energy are available.");
193 dumpCutValuesCmd->SetGuidance("If you want a list 'immediately', use '/run/dumpRegion' for threshold");
194 dumpCutValuesCmd->SetGuidance("list given in gange only. Also, '/run/dumpCouples' gives you the");
195 dumpCutValuesCmd->SetGuidance("current list if you have already issued 'run/beamOn' at least once.");
196 dumpCutValuesCmd->SetParameterName("particle",true);
197 dumpCutValuesCmd->SetDefaultValue("all");
198 dumpCutValuesCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
199}
200
201G4UserPhysicsListMessenger::~G4UserPhysicsListMessenger()
202{
203 delete setPCutCmd;
204 delete setCutCmd;
205 delete setCutRCmd;
206 delete setCutForAGivenParticleCmd;
207 delete verboseCmd;
208 delete dumpListCmd;
209 delete addProcManCmd;
210 delete buildPTCmd;
211 delete storeCmd;
212 delete retrieveCmd;
213 delete asciiCmd;
214 delete applyCutsCmd;
215 delete dumpCutValuesCmd;
216 delete theDirectory;
217}
218
219void G4UserPhysicsListMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
220{
221 if( command==setCutCmd ){
222 G4double newCut = setCutCmd->GetNewDoubleValue(newValue);
223 thePhysicsList->SetDefaultCutValue(newCut);
224 thePhysicsList->SetCutsWithDefault();
225
226 } else if( command==setPCutCmd ){
227 G4cout << "Please use /run/setCut command instead. This command will be removed" << G4endl;
228 G4double newCut = setCutCmd->GetNewDoubleValue(newValue);
229 thePhysicsList->SetDefaultCutValue(newCut);
230 thePhysicsList->SetCutsWithDefault();
231
232 } else if( command==setCutForAGivenParticleCmd ){
233 G4String particleName, unit ; G4double cut ;
234 std::istringstream str (newValue) ;
235 str >> particleName >> cut >> unit ;
236 thePhysicsList->SetCutValue(cut*G4UIcommand::ValueOf(unit), particleName) ;
237
238 } else if( command==setCutRCmd ){
239 std::istringstream is(newValue);
240 char regName[50];
241 G4double cVal;
242 char uniName[10];
243 is >> regName >> cVal >> uniName;
244 G4String regN = regName;
245 G4String uniN = uniName;
246 thePhysicsList->SetCutsForRegion(cVal*(setCutRCmd->ValueOf(uniN)),regN);
247
248 } else if( command==verboseCmd ) {
249 thePhysicsList->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue));
250
251 } else if( command==dumpListCmd ){
252 thePhysicsList->DumpList();
253
254 } else if( command == addProcManCmd ){
255 G4ParticleDefinition* particle = (G4ParticleTable::GetParticleTable())->FindParticle(newValue);
256 if (particle == 0) return;
257 if (particle->GetProcessManager() != 0) return;
258 thePhysicsList->AddProcessManager(particle);
259
260 } else if( command == buildPTCmd ){
261 G4ParticleDefinition* particle = (G4ParticleTable::GetParticleTable())->FindParticle(newValue);
262 if (particle == 0) return;
263 thePhysicsList->PreparePhysicsTable(particle);
264 thePhysicsList->BuildPhysicsTable(particle);
265
266 } else if ( command == storeCmd ){
267 thePhysicsList->StorePhysicsTable(newValue);
268
269 } else if( command == retrieveCmd ) {
270 if ((newValue == "OFF") || (newValue == "off") ){
271 thePhysicsList->ResetPhysicsTableRetrieved();
272 } else {
273 thePhysicsList->SetPhysicsTableRetrieved(newValue);
274 }
275
276 } else if( command == asciiCmd ) {
277 if (asciiCmd->GetNewIntValue(newValue) == 0) {
278 thePhysicsList->ResetStoredInAscii();
279 } else {
280 thePhysicsList->SetStoredInAscii();
281 }
282
283 } else if( command == applyCutsCmd ) {
284 G4Tokenizer next( newValue );
285
286 // check 1st argument
287 G4String temp = G4String(next());
288 G4bool flag = (temp =="true" || temp=="TRUE");
289
290 // check 2nd argument
291 G4String name = G4String(next());
292
293 thePhysicsList->SetApplyCuts(flag, name);
294
295 } else if( command == dumpCutValuesCmd ) {
296 thePhysicsList->DumpCutValuesTable(1);
297
298 }
299}
300
301G4String G4UserPhysicsListMessenger::GetCurrentValue(G4UIcommand * command)
302{
303 G4String cv;
304 G4String candidates("none");
305 G4ParticleTable::G4PTblDicIterator *piter = (G4ParticleTable::GetParticleTable())->GetIterator();
306
307 if( command==setCutCmd ) {
308 cv = setCutCmd->ConvertToString( thePhysicsList->GetDefaultCutValue(), "mm" );
309
310 } else if( command==verboseCmd ){
311 cv = verboseCmd->ConvertToString(thePhysicsList->GetVerboseLevel());
312
313 } else if( command== addProcManCmd ){
314 // set candidate list
315 piter -> reset();
316 while( (*piter)() ){
317 G4ParticleDefinition *particle = piter->value();
318 candidates += " " + particle->GetParticleName();
319 }
320 addProcManCmd->SetCandidates(candidates);
321 cv = "";
322
323 } else if( command== buildPTCmd ){
324 // set candidate list
325 piter -> reset();
326 while( (*piter)() ){
327 G4ParticleDefinition *particle = piter->value();
328 candidates += " " + particle->GetParticleName();
329 }
330 addProcManCmd->SetCandidates(candidates);
331 cv = "";
332
333 } else if ( command == storeCmd ){
334 cv = thePhysicsList->GetPhysicsTableDirectory();
335
336 }else if( command == retrieveCmd ) {
337 if (thePhysicsList->IsPhysicsTableRetrieved()) {
338 cv = thePhysicsList->GetPhysicsTableDirectory();
339 } else {
340 cv = "OFF";
341 }
342
343 } else if( command==asciiCmd ){
344 if (thePhysicsList->IsStoredInAscii()){
345 cv = "1";
346 } else {
347 cv = "0";
348 }
349
350// } else if( command == applyCutsCmd ) {
351// if (thePhysicsList->GetApplyCuts("gamma")){
352// cv = "true";
353// } else {
354// cv = "false";
355// }
356 }
357
358 return cv;
359}
Note: See TracBrowser for help on using the repository browser.