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

Last change on this file since 1149 was 1058, checked in by garnier, 17 years ago

file release beta

File size: 13.7 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.28 2007/05/30 10:34:54 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
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/particle/setCut command
72 setPCutCmd = new G4UIcmdWithADoubleAndUnit("/run/particle/setCut",this);
73 setPCutCmd->SetGuidance("Set default cut value ");
74 setPCutCmd->SetGuidance("This command is equivallent to /run/setCut command.");
75 setPCutCmd->SetGuidance("This command is kept for backward compatibility.");
76 setPCutCmd->SetParameterName("cut",false);
77 setPCutCmd->SetDefaultValue(1.0);
78 setPCutCmd->SetRange("cut >0.0");
79 setPCutCmd->SetDefaultUnit("mm");
80 setPCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
81
82 // /run/setCut command
83 setCutCmd = new G4UIcmdWithADoubleAndUnit("/run/setCut",this);
84 setCutCmd->SetGuidance("Set default cut value ");
85 setCutCmd->SetParameterName("cut",false);
86 setCutCmd->SetDefaultValue(1.0);
87 setCutCmd->SetRange("cut >0.0");
88 setCutCmd->SetDefaultUnit("mm");
89 setCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
90
91 // /run/setCutForRegion command
92 setCutRCmd = new G4UIcommand("/run/setCutForRegion",this);
93 setCutRCmd->SetGuidance("Set cut value for a region");
94 param = new G4UIparameter("Region",'s',false);
95 setCutRCmd->SetParameter(param);
96 param = new G4UIparameter("cut",'d',false);
97 param->SetParameterRange("cut >0.0");
98 setCutRCmd->SetParameter(param);
99 param = new G4UIparameter("Unit",'s',true);
100 param->SetDefaultValue("mm");
101 param->SetParameterCandidates(setCutRCmd->UnitsList(setCutRCmd->CategoryOf("mm")));
102 setCutRCmd->SetParameter(param);
103 setCutRCmd->AvailableForStates(G4State_Idle);
104
105 // /run/particle/DumpList command
106 dumpListCmd = new G4UIcmdWithoutParameter("/run/particle/dumpList",this);
107 dumpListCmd->SetGuidance("Dump List of particles in G4VUserPhysicsList. ");
108
109 // /run/particle/addProcManager command
110 addProcManCmd = new G4UIcmdWithAString("/run/particle/addProcManager", this);
111 addProcManCmd->SetGuidance("add process manager to specified particle type");
112 addProcManCmd->SetParameterName("particleType", true);
113 addProcManCmd->SetDefaultValue("");
114 addProcManCmd->AvailableForStates(G4State_Init,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
115
116 // /run/particle/buildPhysicsTable command
117 buildPTCmd = new G4UIcmdWithAString("/run/particle/buildPhysicsTable", this);
118 buildPTCmd->SetGuidance("build physics table of specified particle type");
119 buildPTCmd->SetParameterName("particleType", true);
120 buildPTCmd->SetDefaultValue("");
121 buildPTCmd->AvailableForStates(G4State_Init,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
122
123 // /run/particle/storePhysicsTable command
124 storeCmd = new G4UIcmdWithAString("/run/particle/storePhysicsTable",this);
125 storeCmd->SetGuidance("Store Physics Table");
126 storeCmd->SetGuidance(" Enter directory name");
127 storeCmd->SetParameterName("dirName",true);
128 storeCmd->SetDefaultValue("");
129 storeCmd->AvailableForStates(G4State_Idle);
130
131 // /run/particle/retrievePhysicsTable command
132 retrieveCmd = new G4UIcmdWithAString("/run/particle/retrievePhysicsTable",this);
133 retrieveCmd->SetGuidance("Retrieve Physics Table");
134 retrieveCmd->SetGuidance(" Enter directory name or OFF to switch off");
135 retrieveCmd->SetParameterName("dirName",true);
136 retrieveCmd->SetDefaultValue("");
137 retrieveCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
138
139 // /run/particle/setStoredInAscii command
140 asciiCmd = new G4UIcmdWithAnInteger("/run/particle/setStoredInAscii",this);
141 asciiCmd->SetGuidance("Switch on/off ascii mode in store/retreive Physics Table");
142 asciiCmd->SetGuidance(" Enter 0(binary) or 1(ascii)");
143 asciiCmd->SetParameterName("ascii",true);
144 asciiCmd->SetDefaultValue(0);
145 asciiCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
146 asciiCmd->SetRange("ascii ==0 || ascii ==1");
147
148 //Commnad /run/particle/applyCuts command
149 applyCutsCmd = new G4UIcommand("/run/particle/applyCuts",this);
150 applyCutsCmd->SetGuidance("Set applyCuts flag for a particle.");
151 applyCutsCmd->SetGuidance(" Some EM processes which do not have infrared divergence");
152 applyCutsCmd->SetGuidance("may generate gamma, e- and/or e+ with kinetic energies");
153 applyCutsCmd->SetGuidance("below the production threshold. By setting this flag,");
154 applyCutsCmd->SetGuidance("such secondaries below threshold are eliminated and");
155 applyCutsCmd->SetGuidance("kinetic energies of such secondaries are accumulated");
156 applyCutsCmd->SetGuidance("to the energy deposition of their mother.");
157 applyCutsCmd->SetGuidance(" Note that 'applyCuts' makes sense only for gamma,");
158 applyCutsCmd->SetGuidance("e- and e+. If this command is issued for other particle,");
159 applyCutsCmd->SetGuidance("a warning message is displayed and the command is");
160 applyCutsCmd->SetGuidance("ignored.");
161 applyCutsCmd->SetGuidance(" If particle name is 'all', this command affects on");
162 applyCutsCmd->SetGuidance("gamma, e- and e+.");
163 param = new G4UIparameter("Flag",'s',true);
164 param->SetDefaultValue("true");
165 applyCutsCmd->SetParameter(param);
166 param = new G4UIparameter("Particle",'s',true);
167 param->SetDefaultValue("all");
168 applyCutsCmd->SetParameter(param);
169 applyCutsCmd->AvailableForStates(G4State_PreInit,G4State_Init,G4State_Idle);
170
171 // /run/particle/dumpCutValues command
172 dumpCutValuesCmd = new G4UIcmdWithAString("/run/particle/dumpCutValues",this);
173 dumpCutValuesCmd->SetGuidance("Dump a list of production threshold values in range and energy");
174 dumpCutValuesCmd->SetGuidance("for all registered material-cuts-couples.");
175 dumpCutValuesCmd->SetGuidance("Dumping a list takes place when you issue 'beamOn' and");
176 dumpCutValuesCmd->SetGuidance("actual conversion tables from range to energy are available.");
177 dumpCutValuesCmd->SetGuidance("If you want a list 'immediately', use '/run/dumpRegion' for threshold");
178 dumpCutValuesCmd->SetGuidance("list given in gange only. Also, '/run/dumpCouples' gives you the");
179 dumpCutValuesCmd->SetGuidance("current list if you have already issued 'run/beamOn' at least once.");
180 dumpCutValuesCmd->SetParameterName("particle",true);
181 dumpCutValuesCmd->SetDefaultValue("all");
182 dumpCutValuesCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
183}
184
185G4UserPhysicsListMessenger::~G4UserPhysicsListMessenger()
186{
187 delete setPCutCmd;
188 delete setCutCmd;
189 delete setCutRCmd;
190 delete verboseCmd;
191 delete dumpListCmd;
192 delete addProcManCmd;
193 delete buildPTCmd;
194 delete storeCmd;
195 delete retrieveCmd;
196 delete asciiCmd;
197 delete applyCutsCmd;
198 delete dumpCutValuesCmd;
199 delete theDirectory;
200}
201
202void G4UserPhysicsListMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
203{
204 if( command==setCutCmd || command==setPCutCmd ){
205 G4double newCut = setCutCmd->GetNewDoubleValue(newValue);
206 thePhysicsList->SetDefaultCutValue(newCut);
207 thePhysicsList->SetCutsWithDefault();
208
209 } else if( command==setCutRCmd ){
210 //G4Tokenizer next( newValue );
211 //G4String rName = G4String(next());
212 //G4String cValue = G4String(next())+" "+G4String(next());
213 //G4double newCut = setCutCmd->GetNewDoubleValue(cValue);
214 //thePhysicsList->SetCutsForRegion(newCut,rName);
215 std::istringstream is(newValue);
216 char regName[50];
217 G4double cVal;
218 char uniName[10];
219 is >> regName >> cVal >> uniName;
220 G4String regN = regName;
221 G4String uniN = uniName;
222 thePhysicsList->SetCutsForRegion(cVal*(setCutRCmd->ValueOf(uniN)),regN);
223
224 } else if( command==verboseCmd ) {
225 thePhysicsList->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue));
226
227 } else if( command==dumpListCmd ){
228 thePhysicsList->DumpList();
229
230 } else if( command == addProcManCmd ){
231 G4ParticleDefinition* particle = (G4ParticleTable::GetParticleTable())->FindParticle(newValue);
232 if (particle == 0) return;
233 if (particle->GetProcessManager() != 0) return;
234 thePhysicsList->AddProcessManager(particle);
235
236 } else if( command == buildPTCmd ){
237 G4ParticleDefinition* particle = (G4ParticleTable::GetParticleTable())->FindParticle(newValue);
238 if (particle == 0) return;
239 thePhysicsList->PreparePhysicsTable(particle);
240 thePhysicsList->BuildPhysicsTable(particle);
241
242 } else if ( command == storeCmd ){
243 thePhysicsList->StorePhysicsTable(newValue);
244
245 } else if( command == retrieveCmd ) {
246 if ((newValue == "OFF") || (newValue == "off") ){
247 thePhysicsList->ResetPhysicsTableRetrieved();
248 } else {
249 thePhysicsList->SetPhysicsTableRetrieved(newValue);
250 }
251
252 } else if( command == asciiCmd ) {
253 if (asciiCmd->GetNewIntValue(newValue) == 0) {
254 thePhysicsList->ResetStoredInAscii();
255 } else {
256 thePhysicsList->SetStoredInAscii();
257 }
258
259 } else if( command == applyCutsCmd ) {
260 G4Tokenizer next( newValue );
261
262 // check 1st argument
263 G4String temp = G4String(next());
264 G4bool flag = (temp =="true" || temp=="TRUE");
265
266 // check 2nd argument
267 G4String name = G4String(next());
268
269 thePhysicsList->SetApplyCuts(flag, name);
270
271 } else if( command == dumpCutValuesCmd ) {
272 thePhysicsList->DumpCutValuesTable(1);
273
274 }
275}
276
277G4String G4UserPhysicsListMessenger::GetCurrentValue(G4UIcommand * command)
278{
279 G4String cv;
280 G4String candidates("none");
281 G4ParticleTable::G4PTblDicIterator *piter = (G4ParticleTable::GetParticleTable())->GetIterator();
282
283 if( command==setCutCmd || command==setPCutCmd ){
284 cv = setCutCmd->ConvertToString( thePhysicsList->GetDefaultCutValue(), "mm" );
285
286 } else if( command==verboseCmd ){
287 cv = verboseCmd->ConvertToString(thePhysicsList->GetVerboseLevel());
288
289 } else if( command== addProcManCmd ){
290 // set candidate list
291 piter -> reset();
292 while( (*piter)() ){
293 G4ParticleDefinition *particle = piter->value();
294 candidates += " " + particle->GetParticleName();
295 }
296 addProcManCmd->SetCandidates(candidates);
297 cv = "";
298
299 } else if( command== buildPTCmd ){
300 // set candidate list
301 piter -> reset();
302 while( (*piter)() ){
303 G4ParticleDefinition *particle = piter->value();
304 candidates += " " + particle->GetParticleName();
305 }
306 addProcManCmd->SetCandidates(candidates);
307 cv = "";
308
309 } else if ( command == storeCmd ){
310 cv = thePhysicsList->GetPhysicsTableDirectory();
311
312 }else if( command == retrieveCmd ) {
313 if (thePhysicsList->IsPhysicsTableRetrieved()) {
314 cv = thePhysicsList->GetPhysicsTableDirectory();
315 } else {
316 cv = "OFF";
317 }
318
319 } else if( command==asciiCmd ){
320 if (thePhysicsList->IsStoredInAscii()){
321 cv = "1";
322 } else {
323 cv = "0";
324 }
325
326// } else if( command == applyCutsCmd ) {
327// if (thePhysicsList->GetApplyCuts("gamma")){
328// cv = "true";
329// } else {
330// cv = "false";
331// }
332 }
333
334 return cv;
335}
Note: See TracBrowser for help on using the repository browser.