ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UserPhysicsListMessenger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4UserPhysicsListMessenger.cc
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 "G4SystemOfUnits.hh"
45 #include "G4VUserPhysicsList.hh"
46 #include "G4PhysicsListHelper.hh"
47 #include "G4UIdirectory.hh"
49 #include "G4UIcmdWithAnInteger.hh"
51 #include "G4UIcmdWithAString.hh"
52 #include "G4UIparameter.hh"
53 #include "G4ParticleTable.hh"
54 #include "G4ios.hh"
55 #include "G4Tokenizer.hh"
56 
58 {
59  G4UIparameter* param = 0;
60  // /run/particle directory
61  theDirectory = new G4UIdirectory("/run/particle/");
62  theDirectory->SetGuidance("Commands for G4VUserPhysicsList.");
63 
64  // /run/particle/Verbose command
65  verboseCmd = new G4UIcmdWithAnInteger("/run/particle/verbose",this);
66  verboseCmd->SetGuidance("Set the Verbose level of G4VUserPhysicsList.");
67  verboseCmd->SetGuidance(" 0 : Silent (default)");
68  verboseCmd->SetGuidance(" 1 : Display warning messages");
69  verboseCmd->SetGuidance(" 2 : Display more");
70  verboseCmd->SetParameterName("level",true);
72  verboseCmd->SetRange("level >=0 && level <=3");
73 
74  // /run/setCut command
75  setCutCmd = new G4UIcmdWithADoubleAndUnit("/run/setCut",this);
76  setCutCmd->SetGuidance("Set default cut value ");
77  setCutCmd->SetParameterName("cut",false);
79  setCutCmd->SetRange("cut >=0.0");
82 
83  // /run/setCutForAGivenParticle command
84  setCutForAGivenParticleCmd = new G4UIcommand("/run/setCutForAGivenParticle",this) ;
85  setCutForAGivenParticleCmd->SetGuidance("Set a cut value to a specific particle ") ;
86  setCutForAGivenParticleCmd->SetGuidance("Usage: /run/setCutForAGivenParticle gamma 1. mm") ;
87  param = new G4UIparameter("particleName",'s',false) ;
88  param->SetParameterCandidates("e- e+ gamma proton");
90  param = new G4UIparameter("cut",'d',false) ;
91  param->SetDefaultValue("1.") ;
92  param->SetParameterRange("cut>=0.0") ;
94  param = new G4UIparameter("unit",'s',false) ;
95  param->SetDefaultUnit("mm");
98 
99  // /run/getCutForAGivenParticle command
100  getCutForAGivenParticleCmd = new G4UIcmdWithAString("/run/getCutForAGivenParticle",this) ;
101  getCutForAGivenParticleCmd->SetGuidance("Get a cut value to a specific particle ") ;
102  getCutForAGivenParticleCmd->SetGuidance("Usage: /run/getCutForAGivenParticle gamma ") ;
103  getCutForAGivenParticleCmd->SetParameterName("particleName",false,false) ;
104  getCutForAGivenParticleCmd->SetCandidates("e- e+ gamma proton");
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->SetParameter(param);
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);
128  addProcManCmd->SetGuidance("add process manager to specified particle type");
129  addProcManCmd->SetParameterName("particleType", true);
132 
133  // /run/particle/buildPhysicsTable command
134  buildPTCmd = new G4UIcmdWithAString("/run/particle/buildPhysicsTable", this);
135  buildPTCmd->SetGuidance("build physics table of specified particle type");
136  buildPTCmd->SetParameterName("particleType", true);
139 
140  // /run/particle/storePhysicsTable command
141  storeCmd = new G4UIcmdWithAString("/run/particle/storePhysicsTable",this);
142  storeCmd->SetGuidance("Store Physics Table");
143  storeCmd->SetGuidance(" Enter directory name");
144  storeCmd->SetParameterName("dirName",true);
147 
148  // /run/particle/retrievePhysicsTable command
149  retrieveCmd = new G4UIcmdWithAString("/run/particle/retrievePhysicsTable",this);
150  retrieveCmd->SetGuidance("Retrieve Physics Table");
151  retrieveCmd->SetGuidance(" Enter directory name or OFF to switch off");
152  retrieveCmd->SetParameterName("dirName",true);
155 
156  // /run/particle/setStoredInAscii command
157  asciiCmd = new G4UIcmdWithAnInteger("/run/particle/setStoredInAscii",this);
158  asciiCmd->SetGuidance("Switch on/off ascii mode in store/retrieve Physics Table");
159  asciiCmd->SetGuidance(" Enter 0(binary) or 1(ascii)");
160  asciiCmd->SetParameterName("ascii",true);
163  asciiCmd->SetRange("ascii ==0 || ascii ==1");
164 
165  //Commnad /run/particle/applyCuts command
166  applyCutsCmd = new G4UIcommand("/run/particle/applyCuts",this);
167  applyCutsCmd->SetGuidance("Set applyCuts flag for a particle.");
168  applyCutsCmd->SetGuidance(" Some EM processes which do not have infrared divergence");
169  applyCutsCmd->SetGuidance("may generate gamma, e- and/or e+ with kinetic energies");
170  applyCutsCmd->SetGuidance("below the production threshold. By setting this flag,");
171  applyCutsCmd->SetGuidance("such secondaries below threshold are eliminated and");
172  applyCutsCmd->SetGuidance("kinetic energies of such secondaries are accumulated");
173  applyCutsCmd->SetGuidance("to the energy deposition of their mother.");
174  applyCutsCmd->SetGuidance(" Note that 'applyCuts' makes sense only for gamma,");
175  applyCutsCmd->SetGuidance("e- and e+. If this command is issued for other particle,");
176  applyCutsCmd->SetGuidance("a warning message is displayed and the command is");
177  applyCutsCmd->SetGuidance("ignored.");
178  applyCutsCmd->SetGuidance(" If particle name is 'all', this command affects on");
179  applyCutsCmd->SetGuidance("gamma, e- and e+.");
180  param = new G4UIparameter("Flag",'s',true);
181  param->SetDefaultValue("true");
182  applyCutsCmd->SetParameter(param);
183  param = new G4UIparameter("Particle",'s',true);
184  param->SetDefaultValue("all");
185  applyCutsCmd->SetParameter(param);
187 
188  // /run/particle/dumpCutValues command
189  dumpCutValuesCmd = new G4UIcmdWithAString("/run/particle/dumpCutValues",this);
190  dumpCutValuesCmd->SetGuidance("Dump a list of production threshold values in range and energy");
191  dumpCutValuesCmd->SetGuidance("for all registered material-cuts-couples.");
192  dumpCutValuesCmd->SetGuidance("Dumping a list takes place when you issue 'beamOn' and");
193  dumpCutValuesCmd->SetGuidance("actual conversion tables from range to energy are available.");
194  dumpCutValuesCmd->SetGuidance("If you want a list 'immediately', use '/run/dumpRegion' for threshold");
195  dumpCutValuesCmd->SetGuidance("list given in range only. Also, '/run/dumpCouples' gives you the");
196  dumpCutValuesCmd->SetGuidance("current list if you have already issued 'run/beamOn' at least once.");
197  dumpCutValuesCmd->SetParameterName("particle",true);
200 
201  // /run/particle/dumpCutValues command
202  dumpOrdParamCmd = new G4UIcmdWithAnInteger("/run/particle/dumpOrderingParam",this);
203  dumpOrdParamCmd->SetGuidance("Dump a list of ordering parameter ");
204  dumpOrdParamCmd->SetParameterName("subtype",true);
207 }
208 
210 {
211  delete setCutCmd;
212  delete setCutRCmd;
215  delete verboseCmd;
216  delete dumpListCmd;
217  delete addProcManCmd;
218  delete buildPTCmd;
219  delete storeCmd;
220  delete retrieveCmd;
221  delete asciiCmd;
222  delete applyCutsCmd;
223  delete dumpCutValuesCmd;
224  delete dumpOrdParamCmd;
225  delete theDirectory;
226 }
227 
229 {
231  if( command==setCutCmd ){
232  G4double newCut = setCutCmd->GetNewDoubleValue(newValue);
235 
236  } else if( command==setCutForAGivenParticleCmd ){
237  G4String particleName, unit ; G4double cut ;
238  std::istringstream str (newValue) ;
239  str >> particleName >> cut >> unit ;
240  thePhysicsList->SetCutValue(cut*G4UIcommand::ValueOf(unit), particleName) ;
241 
242  } else if( command==getCutForAGivenParticleCmd ){
243  G4cout << thePhysicsList->GetCutValue(newValue)/mm <<"[mm]" << G4endl ;
244 
245  } else if( command==setCutRCmd ){
246  std::istringstream is(newValue);
247  G4String regName;
248  G4String uniName;
249  G4double cVal = -1.0;
250  is >> regName >> cVal >> uniName;
251  if (is.fail()) {
252  ed << "illegal arguments : " << newValue;
253  command->CommandFailed(ed);
254  return;
255  }
256  thePhysicsList->SetCutsForRegion(cVal*(setCutRCmd->ValueOf(uniName)),regName);
257 
258  } else if( command==verboseCmd ) {
260 
261  } else if( command==dumpListCmd ){
263 
264  } else if( command==dumpOrdParamCmd ){
265  G4int stype = dumpOrdParamCmd->GetNewIntValue(newValue);
267 
268  } else if( command == addProcManCmd ){
269  G4ParticleDefinition* particle = (G4ParticleTable::GetParticleTable())->FindParticle(newValue);
270  if (particle == 0)
271  {
272  ed << " Particle is not found : " << newValue;
273  command->CommandFailed(ed);
274  return;
275  }
276  else if (particle->GetProcessManager() != 0)
277  {
278  ed << " Particle is not initialized : " << newValue;
279  command->CommandFailed(ed);
280  return;
281  }
283 
284  } else if( command == buildPTCmd ){
285  G4ParticleDefinition* particle = (G4ParticleTable::GetParticleTable())->FindParticle(newValue);
286  if (particle == 0)
287  {
288  ed << " Particle is not found : " << newValue;
289  command->CommandFailed(ed);
290  return;
291  }
294 
295  } else if ( command == storeCmd ){
297 
298  } else if( command == retrieveCmd ) {
299  if ((newValue == "OFF") || (newValue == "off") ){
301  } else {
303  }
304 
305  } else if( command == asciiCmd ) {
306  if (asciiCmd->GetNewIntValue(newValue) == 0) {
308  } else {
310  }
311 
312  } else if( command == applyCutsCmd ) {
313  G4Tokenizer next( newValue );
314 
315  // check 1st argument
316  G4String temp = G4String(next());
317  G4bool flag = (temp =="true" || temp=="TRUE");
318 
319  // check 2nd argument
320  G4String name = G4String(next());
321 
322  thePhysicsList->SetApplyCuts(flag, name);
323 
324  } else if( command == dumpCutValuesCmd ) {
326 
327  }
328 }
329 
331 {
332  G4String cv;
333  G4String candidates("none");
335 
336  if( command==setCutCmd ) {
338 
339  } else if( command==verboseCmd ){
341 
342  } else if( command== addProcManCmd ){
343  // set candidate list
344  piter -> reset();
345  while( (*piter)() ){
346  G4ParticleDefinition *particle = piter->value();
347  candidates += " " + particle->GetParticleName();
348  }
349  addProcManCmd->SetCandidates(candidates);
350  cv = "";
351 
352  } else if( command== buildPTCmd ){
353  // set candidate list
354  piter -> reset();
355  while( (*piter)() ){
356  G4ParticleDefinition *particle = piter->value();
357  candidates += " " + particle->GetParticleName();
358  }
359  addProcManCmd->SetCandidates(candidates);
360  cv = "";
361 
362  } else if ( command == storeCmd ){
364 
365  }else if( command == retrieveCmd ) {
368  } else {
369  cv = "OFF";
370  }
371 
372  } else if( command==asciiCmd ){
374  cv = "1";
375  } else {
376  cv = "0";
377  }
378 
379 // } else if( command == applyCutsCmd ) {
380 // if (thePhysicsList->GetApplyCuts("gamma")){
381 // cv = "true";
382 // } else {
383 // cv = "false";
384 // }
385  }
386 
387  return cv;
388 }