00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <sstream>
00042
00043 #include "G4UserPhysicsListMessenger.hh"
00044
00045 #include "G4SystemOfUnits.hh"
00046 #include "G4VUserPhysicsList.hh"
00047 #include "G4PhysicsListHelper.hh"
00048 #include "G4UIdirectory.hh"
00049 #include "G4UIcmdWithoutParameter.hh"
00050 #include "G4UIcmdWithAnInteger.hh"
00051 #include "G4UIcmdWithADoubleAndUnit.hh"
00052 #include "G4UIcmdWithAString.hh"
00053 #include "G4ParticleTable.hh"
00054 #include "G4ios.hh"
00055 #include "G4Tokenizer.hh"
00056
00057 G4UserPhysicsListMessenger::G4UserPhysicsListMessenger(G4VUserPhysicsList* pParticleList):thePhysicsList(pParticleList)
00058 {
00059 G4UIparameter* param = 0;
00060
00061 theDirectory = new G4UIdirectory("/run/particle/");
00062 theDirectory->SetGuidance("Commands for G4VUserPhysicsList.");
00063
00064
00065 verboseCmd = new G4UIcmdWithAnInteger("/run/particle/verbose",this);
00066 verboseCmd->SetGuidance("Set the Verbose level of G4VUserPhysicsList.");
00067 verboseCmd->SetGuidance(" 0 : Silent (default)");
00068 verboseCmd->SetGuidance(" 1 : Display warning messages");
00069 verboseCmd->SetGuidance(" 2 : Display more");
00070 verboseCmd->SetParameterName("level",true);
00071 verboseCmd->SetDefaultValue(0);
00072 verboseCmd->SetRange("level >=0 && level <=3");
00073
00074
00075 setCutCmd = new G4UIcmdWithADoubleAndUnit("/run/setCut",this);
00076 setCutCmd->SetGuidance("Set default cut value ");
00077 setCutCmd->SetParameterName("cut",false);
00078 setCutCmd->SetDefaultValue(1.0);
00079 setCutCmd->SetRange("cut >=0.0");
00080 setCutCmd->SetDefaultUnit("mm");
00081 setCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
00082
00083
00084 setCutForAGivenParticleCmd = new G4UIcommand("/run/setCutForAGivenParticle",this) ;
00085 setCutForAGivenParticleCmd->SetGuidance("Set a cut value to a specific particle ") ;
00086 setCutForAGivenParticleCmd->SetGuidance("Usage: /run/setCutForAGivenParticle gamma 1. mm") ;
00087 param = new G4UIparameter("particleName",'s',false) ;
00088 param->SetParameterCandidates("e- e+ gamma proton");
00089 setCutForAGivenParticleCmd->SetParameter(param) ;
00090 param = new G4UIparameter("cut",'d',false) ;
00091 param->SetDefaultValue("1.") ;
00092 param->SetParameterRange("cut>=0.0") ;
00093 setCutForAGivenParticleCmd->SetParameter(param) ;
00094 param = new G4UIparameter("unit",'s',false) ;
00095 param->SetDefaultValue("mm") ;
00096 setCutForAGivenParticleCmd->SetParameter(param) ;
00097 setCutForAGivenParticleCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
00098
00099
00100 getCutForAGivenParticleCmd = new G4UIcmdWithAString("/run/getCutForAGivenParticle",this) ;
00101 getCutForAGivenParticleCmd->SetGuidance("Get a cut value to a specific particle ") ;
00102 getCutForAGivenParticleCmd->SetGuidance("Usage: /run/getCutForAGivenParticle gamma ") ;
00103 getCutForAGivenParticleCmd->SetParameterName("particleName",false,false) ;
00104 getCutForAGivenParticleCmd->SetCandidates("e- e+ gamma proton");
00105 getCutForAGivenParticleCmd->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00106
00107
00108 setCutRCmd = new G4UIcommand("/run/setCutForRegion",this);
00109 setCutRCmd->SetGuidance("Set cut value for a region");
00110 param = new G4UIparameter("Region",'s',false);
00111 setCutRCmd->SetParameter(param);
00112 param = new G4UIparameter("cut",'d',false);
00113 param->SetParameterRange("cut >=0.0");
00114 setCutRCmd->SetParameter(param);
00115 param = new G4UIparameter("Unit",'s',true);
00116 param->SetDefaultValue("mm");
00117 param->SetParameterCandidates(setCutRCmd->UnitsList(setCutRCmd->CategoryOf("mm")));
00118 setCutRCmd->SetParameter(param);
00119 setCutRCmd->AvailableForStates(G4State_Idle);
00120
00121
00122 dumpListCmd = new G4UIcmdWithoutParameter("/run/particle/dumpList",this);
00123 dumpListCmd->SetGuidance("Dump List of particles in G4VUserPhysicsList. ");
00124
00125
00126 addProcManCmd = new G4UIcmdWithAString("/run/particle/addProcManager", this);
00127 addProcManCmd->SetGuidance("add process manager to specified particle type");
00128 addProcManCmd->SetParameterName("particleType", true);
00129 addProcManCmd->SetDefaultValue("");
00130 addProcManCmd->AvailableForStates(G4State_Init,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00131
00132
00133 buildPTCmd = new G4UIcmdWithAString("/run/particle/buildPhysicsTable", this);
00134 buildPTCmd->SetGuidance("build physics table of specified particle type");
00135 buildPTCmd->SetParameterName("particleType", true);
00136 buildPTCmd->SetDefaultValue("");
00137 buildPTCmd->AvailableForStates(G4State_Init,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00138
00139
00140 storeCmd = new G4UIcmdWithAString("/run/particle/storePhysicsTable",this);
00141 storeCmd->SetGuidance("Store Physics Table");
00142 storeCmd->SetGuidance(" Enter directory name");
00143 storeCmd->SetParameterName("dirName",true);
00144 storeCmd->SetDefaultValue("");
00145 storeCmd->AvailableForStates(G4State_Idle);
00146
00147
00148 retrieveCmd = new G4UIcmdWithAString("/run/particle/retrievePhysicsTable",this);
00149 retrieveCmd->SetGuidance("Retrieve Physics Table");
00150 retrieveCmd->SetGuidance(" Enter directory name or OFF to switch off");
00151 retrieveCmd->SetParameterName("dirName",true);
00152 retrieveCmd->SetDefaultValue("");
00153 retrieveCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
00154
00155
00156 asciiCmd = new G4UIcmdWithAnInteger("/run/particle/setStoredInAscii",this);
00157 asciiCmd->SetGuidance("Switch on/off ascii mode in store/retreive Physics Table");
00158 asciiCmd->SetGuidance(" Enter 0(binary) or 1(ascii)");
00159 asciiCmd->SetParameterName("ascii",true);
00160 asciiCmd->SetDefaultValue(0);
00161 asciiCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
00162 asciiCmd->SetRange("ascii ==0 || ascii ==1");
00163
00164
00165 applyCutsCmd = new G4UIcommand("/run/particle/applyCuts",this);
00166 applyCutsCmd->SetGuidance("Set applyCuts flag for a particle.");
00167 applyCutsCmd->SetGuidance(" Some EM processes which do not have infrared divergence");
00168 applyCutsCmd->SetGuidance("may generate gamma, e- and/or e+ with kinetic energies");
00169 applyCutsCmd->SetGuidance("below the production threshold. By setting this flag,");
00170 applyCutsCmd->SetGuidance("such secondaries below threshold are eliminated and");
00171 applyCutsCmd->SetGuidance("kinetic energies of such secondaries are accumulated");
00172 applyCutsCmd->SetGuidance("to the energy deposition of their mother.");
00173 applyCutsCmd->SetGuidance(" Note that 'applyCuts' makes sense only for gamma,");
00174 applyCutsCmd->SetGuidance("e- and e+. If this command is issued for other particle,");
00175 applyCutsCmd->SetGuidance("a warning message is displayed and the command is");
00176 applyCutsCmd->SetGuidance("ignored.");
00177 applyCutsCmd->SetGuidance(" If particle name is 'all', this command affects on");
00178 applyCutsCmd->SetGuidance("gamma, e- and e+.");
00179 param = new G4UIparameter("Flag",'s',true);
00180 param->SetDefaultValue("true");
00181 applyCutsCmd->SetParameter(param);
00182 param = new G4UIparameter("Particle",'s',true);
00183 param->SetDefaultValue("all");
00184 applyCutsCmd->SetParameter(param);
00185 applyCutsCmd->AvailableForStates(G4State_PreInit,G4State_Init,G4State_Idle);
00186
00187
00188 dumpCutValuesCmd = new G4UIcmdWithAString("/run/particle/dumpCutValues",this);
00189 dumpCutValuesCmd->SetGuidance("Dump a list of production threshold values in range and energy");
00190 dumpCutValuesCmd->SetGuidance("for all registered material-cuts-couples.");
00191 dumpCutValuesCmd->SetGuidance("Dumping a list takes place when you issue 'beamOn' and");
00192 dumpCutValuesCmd->SetGuidance("actual conversion tables from range to energy are available.");
00193 dumpCutValuesCmd->SetGuidance("If you want a list 'immediately', use '/run/dumpRegion' for threshold");
00194 dumpCutValuesCmd->SetGuidance("list given in gange only. Also, '/run/dumpCouples' gives you the");
00195 dumpCutValuesCmd->SetGuidance("current list if you have already issued 'run/beamOn' at least once.");
00196 dumpCutValuesCmd->SetParameterName("particle",true);
00197 dumpCutValuesCmd->SetDefaultValue("all");
00198 dumpCutValuesCmd->AvailableForStates(G4State_Idle);
00199
00200
00201 dumpOrdParamCmd = new G4UIcmdWithAnInteger("/run/particle/dumpOrderingParam",this);
00202 dumpOrdParamCmd->SetGuidance("Dump a list of ordering parameter ");
00203 dumpOrdParamCmd->SetParameterName("subtype",true);
00204 dumpOrdParamCmd->SetDefaultValue(-1);
00205 dumpOrdParamCmd->AvailableForStates(G4State_PreInit,G4State_Init,G4State_Idle);
00206 }
00207
00208 G4UserPhysicsListMessenger::~G4UserPhysicsListMessenger()
00209 {
00210 delete setCutCmd;
00211 delete setCutRCmd;
00212 delete setCutForAGivenParticleCmd;
00213 delete getCutForAGivenParticleCmd;
00214 delete verboseCmd;
00215 delete dumpListCmd;
00216 delete addProcManCmd;
00217 delete buildPTCmd;
00218 delete storeCmd;
00219 delete retrieveCmd;
00220 delete asciiCmd;
00221 delete applyCutsCmd;
00222 delete dumpCutValuesCmd;
00223 delete dumpOrdParamCmd;
00224 delete theDirectory;
00225 }
00226
00227 void G4UserPhysicsListMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
00228 {
00229 if( command==setCutCmd ){
00230 G4double newCut = setCutCmd->GetNewDoubleValue(newValue);
00231 thePhysicsList->SetDefaultCutValue(newCut);
00232 thePhysicsList->SetCuts();
00233
00234 } else if( command==setCutForAGivenParticleCmd ){
00235 G4String particleName, unit ; G4double cut ;
00236 std::istringstream str (newValue) ;
00237 str >> particleName >> cut >> unit ;
00238 thePhysicsList->SetCutValue(cut*G4UIcommand::ValueOf(unit), particleName) ;
00239
00240 } else if( command==getCutForAGivenParticleCmd ){
00241 G4cout << thePhysicsList->GetCutValue(newValue)/mm <<"[mm]" << G4endl ;
00242
00243 } else if( command==setCutRCmd ){
00244 std::istringstream is(newValue);
00245 G4String regName;
00246 G4String uniName;
00247 G4double cVal = -1.0;
00248 is >> regName >> cVal >> uniName;
00249 if (is.fail()) {
00250 G4cout << "illegal arguments : try again " << G4endl;
00251 return;
00252 }
00253 thePhysicsList->SetCutsForRegion(cVal*(setCutRCmd->ValueOf(uniName)),regName);
00254
00255 } else if( command==verboseCmd ) {
00256 thePhysicsList->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue));
00257
00258 } else if( command==dumpListCmd ){
00259 thePhysicsList->DumpList();
00260
00261 } else if( command==dumpOrdParamCmd ){
00262 G4int stype = dumpOrdParamCmd->GetNewIntValue(newValue);
00263 G4PhysicsListHelper::GetPhysicsListHelper()->DumpOrdingParameterTable(stype);
00264
00265 } else if( command == addProcManCmd ){
00266 G4ParticleDefinition* particle = (G4ParticleTable::GetParticleTable())->FindParticle(newValue);
00267 if (particle == 0) return;
00268 if (particle->GetProcessManager() != 0) return;
00269 thePhysicsList->AddProcessManager(particle);
00270
00271 } else if( command == buildPTCmd ){
00272 G4ParticleDefinition* particle = (G4ParticleTable::GetParticleTable())->FindParticle(newValue);
00273 if (particle == 0) return;
00274 thePhysicsList->PreparePhysicsTable(particle);
00275 thePhysicsList->BuildPhysicsTable(particle);
00276
00277 } else if ( command == storeCmd ){
00278 thePhysicsList->StorePhysicsTable(newValue);
00279
00280 } else if( command == retrieveCmd ) {
00281 if ((newValue == "OFF") || (newValue == "off") ){
00282 thePhysicsList->ResetPhysicsTableRetrieved();
00283 } else {
00284 thePhysicsList->SetPhysicsTableRetrieved(newValue);
00285 }
00286
00287 } else if( command == asciiCmd ) {
00288 if (asciiCmd->GetNewIntValue(newValue) == 0) {
00289 thePhysicsList->ResetStoredInAscii();
00290 } else {
00291 thePhysicsList->SetStoredInAscii();
00292 }
00293
00294 } else if( command == applyCutsCmd ) {
00295 G4Tokenizer next( newValue );
00296
00297
00298 G4String temp = G4String(next());
00299 G4bool flag = (temp =="true" || temp=="TRUE");
00300
00301
00302 G4String name = G4String(next());
00303
00304 thePhysicsList->SetApplyCuts(flag, name);
00305
00306 } else if( command == dumpCutValuesCmd ) {
00307 thePhysicsList->DumpCutValuesTable(1);
00308
00309 }
00310 }
00311
00312 G4String G4UserPhysicsListMessenger::GetCurrentValue(G4UIcommand * command)
00313 {
00314 G4String cv;
00315 G4String candidates("none");
00316 G4ParticleTable::G4PTblDicIterator *piter = (G4ParticleTable::GetParticleTable())->GetIterator();
00317
00318 if( command==setCutCmd ) {
00319 cv = setCutCmd->ConvertToString( thePhysicsList->GetDefaultCutValue(), "mm" );
00320
00321 } else if( command==verboseCmd ){
00322 cv = verboseCmd->ConvertToString(thePhysicsList->GetVerboseLevel());
00323
00324 } else if( command== addProcManCmd ){
00325
00326 piter -> reset();
00327 while( (*piter)() ){
00328 G4ParticleDefinition *particle = piter->value();
00329 candidates += " " + particle->GetParticleName();
00330 }
00331 addProcManCmd->SetCandidates(candidates);
00332 cv = "";
00333
00334 } else if( command== buildPTCmd ){
00335
00336 piter -> reset();
00337 while( (*piter)() ){
00338 G4ParticleDefinition *particle = piter->value();
00339 candidates += " " + particle->GetParticleName();
00340 }
00341 addProcManCmd->SetCandidates(candidates);
00342 cv = "";
00343
00344 } else if ( command == storeCmd ){
00345 cv = thePhysicsList->GetPhysicsTableDirectory();
00346
00347 }else if( command == retrieveCmd ) {
00348 if (thePhysicsList->IsPhysicsTableRetrieved()) {
00349 cv = thePhysicsList->GetPhysicsTableDirectory();
00350 } else {
00351 cv = "OFF";
00352 }
00353
00354 } else if( command==asciiCmd ){
00355 if (thePhysicsList->IsStoredInAscii()){
00356 cv = "1";
00357 } else {
00358 cv = "0";
00359 }
00360
00361
00362
00363
00364
00365
00366
00367 }
00368
00369 return cv;
00370 }