Geant4_10
G4VUserPhysicsList.hh
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 //
27 // $Id: G4VUserPhysicsList.hh 73123 2013-08-19 07:52:00Z gcosmo $
28 //
29 //
30 // ------------------------------------------------------------
31 // GEANT 4 class header file
32 // Class Description:
33 // This class is an abstract class for
34 // constructing particles and processes.
35 // User must implement following three virtual methods
36 // in his/her own concrete class derived from this class.
37 // G4VUserPhysicsList::ConstructParticle()
38 // Construct particles
39 // G4VUserPhysicsList::ConstructProcess()
40 // Construct procesess and register them to particles
41 //
42 // -------------------------------------------
43 // History
44 // first version 09 Jan. 1998 by H.Kurashige
45 // modified 24 Jan. 1998 by H.Kurashige
46 // rename DumpCutValues/DumpCutValuesTable
47 // change SetCuts method
48 // add SetCutsWithDefault method
49 // modified 06 June 1998 by H.Kurashige
50 // add AddProcessManager
51 // add BuildPhysicsTable
52 // modified 29 June 1998 by H.Kurashige
53 // add AddProcessManager
54 // modified 05 Dec. 1998 by H.Kurashige
55 // add ConstructAllParticles()
56 // modified 14, Apr 1999 by H.Kurashige
57 // change BuildPhysicsTable as public
58 // removed ConstructAllParticles() and related methods
59 // changed SetCuts method argument
60 // modified 08, Nov 2000 by H.Kurashige
61 // added Retrieve/StorePhysicsTable and related methods
62 // modified 08, Mar 2001 by H.Kurashige
63 // added binary mode for Retrieve/StorePhysicsTable
64 // added RetrieveCutValues and related
65 // added Set/ResetStoredInAscii() to switch on ascii mode
66 // for Retrieve/StorePhysicsTable
67 // modified for CUTS per REGION 10, Oct 2002 by H.Kurashige
68 // removed following methods
69 // void ReCalcCutValue()
70 // void SetCutValueForOthers()
71 // void SetCutValueForOtherThan()
72 // void ReCalcCutValueForOthers()
73 // virtual G4bool StoreMaterialInfo()
74 // virtual G4bool StoreCutValues()
75 // virtual G4bool RetrieveCutValues()
76 // virtual G4bool CheckForRetrievePhysicsTable()
77 // virtual G4bool CheckMaterialInfo()
78 // added void BuildPhysicsTable()
79 // Added PhysicsListHelper 29 Apr. 2011 H.Kurashige
80 // Added default impelmentation of SetCuts 10 June 2011 H.Kurashige
81 // SetCuts is not 'pure virtual' any more
82 // Trasnformations for multi-threading 26 Mar. 2013 A. Dotti
83 // ------------------------------------------------------------
84 #ifndef G4VUserPhysicsList_h
85 #define G4VUserPhysicsList_h 1
86 
87 #include "globals.hh"
88 #include "tls.hh"
89 #include "rundefs.hh"
90 #include "G4ios.hh"
91 
92 #include "G4ParticleTable.hh"
93 #include "G4ParticleDefinition.hh"
94 #include "G4ProductionCutsTable.hh"
95 #include "G4VUPLSplitter.hh"
96 
97 #include "G4Threading.hh"
98 
100 class G4PhysicsListHelper;
101 class G4VProcess;
102 
104 {
105  //Encapsulate the fields of class G4VUserPhysicsList
106  //that are per-thread.
107 public:
108  void initialize();
114 };
115 // The type G4VUPLManager is introduced to encapsulate the methods used by
116 // both the master thread and worker threads to allocate memory space for
117 // the fields encapsulated by the class G4VUPLData. When each thread
118 // changes the value for these fields, it refers to them using a macro
119 // definition defined below. For every G4VUserPhysicsList instance,
120 // there is a corresponding G4VUPLData instance. All G4VUPLData instances
121 // are organized by the class G4VUPLManager as an array.
122 // The field "int g4vuplInstanceID" is added to the class G4VUserPhysicsList.
123 // The value of this field in each G4VUserPhysicsList instance is the
124 // subscript of the corresponding G44VUPLData instance.
125 // In order to use the class G44VUPLManager, we add a static member in the class
126 // G4VUserPhysicsList as follows: "static G4VUPLManager subInstanceManager".
127 // Both the master thread and worker threads change the length of the array
128 // for G44VUPLData instances mutually along with G4VUserPhysicsList
129 // instances are created. For each worker thread, it dynamically creates ions.
130 // Consider any thread A, if there is any other thread which creates an ion.
131 // This ion is shared by the thread A. So the thread A leaves an empty space
132 // in the array of G4PDefData instances for the ion.
133 //
134 // Important Note: you may wonder why we are introducing this mechanism
135 // since there is only one PL for each application.
136 // This is true, in the sense that only one PL is allowed
137 // to be associated to a G4RunManager, however user can instantiate
138 // as many PLs are needed and at run-time select one of the PLs to be used
139 // we thus need this mechanism to guarantee that the system works without
140 // problems in case of this (unusual) case. This may be reviewed in the future
143 
144 // This macros change the references to fields that are now encapsulated
145 // in the class G4VUPLData.
146 //
147 // Note1: the use of this-> this is needed to avoid compilation errors
148 // when using templated class with T=G4VUserPhysicsList. Don't know why.
149 // Note2: the name of the first #define is different, because otherwise
150 // we need to change its use in all classes that inherits from
151 // this base class (all examples). However one should note comment
152 // on JIRA task: http://jira-geant4.kek.jp/browse/DEV-27
153 #define theParticleIterator ((this->subInstanceManager.offset[this->g4vuplInstanceID])._theParticleIterator)
154 #define G4MT_theMessenger ((this->subInstanceManager.offset[this->g4vuplInstanceID])._theMessenger)
155 #define G4MT_thePLHelper ((this->subInstanceManager.offset[this->g4vuplInstanceID])._thePLHelper)
156 #define fIsPhysicsTableBuilt ((this->subInstanceManager.offset[this->g4vuplInstanceID])._fIsPhysicsTableBuilt)
157 #define fDisplayThreshold ((this->subInstanceManager.offset[this->g4vuplInstanceID])._fDisplayThreshold)
158 
160 {
161  public:
163  virtual ~G4VUserPhysicsList();
164 
165  // copy constructor and assignment operator
168 
169  public: // with description
170  // Each particle type will be instantiated
171  // This method is invoked by the RunManger
172  virtual void ConstructParticle() = 0;
173 
174  // By calling the "Construct" method,
175  // process manager and processes are created.
176  void Construct();
177 
178  // Each physics process will be instantiated and
179  // registered to the process manager of each particle type
180  // This method is invoked in Construct method
181  virtual void ConstructProcess() = 0;
182 
183  protected: // with description
184  // User must invoke this method in his ConstructProcess()
185  // implementation in order to insures particle transportation.
186  void AddTransportation();
187 
188  //Register a process to the particle type
189  // according to the ordering parameter table
190  // 'true' is returned if the process is registerd successfully
192  G4ParticleDefinition* particle);
193 
194  public:
195  void UseCoupledTransportation(G4bool vl=true);
196 
198  public: // with description
199  // "SetCuts" method sets a cut value for all particle types
200  // in the particle table
201  virtual void SetCuts();
202 
203  public: // with description
204  // set/get the default cut value
205  // Calling SetDefaultCutValue causes re-calcuration of cut values
206  // and physics tables just before the next event loop
207  void SetDefaultCutValue(G4double newCutValue);
209 
211  public: // with description
212  // Invoke BuildPhysicsTable for all processes for all particles
213  // In case of "Retrieve" flag is ON, PhysicsTable will be
214  // retrieved from files
215  void BuildPhysicsTable();
216 
217  // do PreparePhysicsTable for specified particle type
219 
220  // do BuildPhysicsTable for specified particle type
222 
223  // Store PhysicsTable together with both material and cut value
224  // information in files under the specified directory.
225  // (return true if files are sucessfully created)
226  G4bool StorePhysicsTable(const G4String& directory = ".");
227 
228  // Return true if "Retrieve" flag is ON.
229  // (i.e. PhysicsTable will be retrieved from files)
231  G4bool IsStoredInAscii() const;
232 
233  // Get directory path for physics table files.
234  const G4String& GetPhysicsTableDirectory() const;
235 
236  // Set "Retrieve" flag
237  // Directory path can be set together.
238  // Null string (default) means directory is not changed
239  // from the current value
240  void SetPhysicsTableRetrieved(const G4String& directory = "");
241  void SetStoredInAscii();
242 
243  // Reset "Retrieve" flag
245  void ResetStoredInAscii();
246 
248  public: // with description
249  // Print out the List of registered particles types
250  void DumpList() const;
251 
252  public: // with description
253  // Request to print out information of cut values
254  // Printing will be performed when all tables are made
255  void DumpCutValuesTable(G4int flag =1);
256 
257  // The following method actually trigger the print-out requested
258  // by the above method. This method must be invoked by RunManager
259  // at the proper moment.
261 
262  public: // with description
264  G4int GetVerboseLevel() const;
265  // set/get controle flag for output message
266  // 0: Silent
267  // 1: Warning message
268  // 2: More
269 
271  public: // with description
272  // "SetCutsWithDefault" method invokes default SetCuts method
273  // Note: Cut values will not be overwriten with this method
274  // Using default SetCuts method is recommended
275  // (i.e You do not need to implement SetCuts method)
276  void SetCutsWithDefault();
277 
278  // Following are utility methods for SetCuts
279 
280  // SetCutValue sets a cut value for a particle type for the default region
281  void SetCutValue(G4double aCut, const G4String& pname);
282 
283  // GetCutValue sets a cut value for a particle type for the default region
284  G4double GetCutValue(const G4String& pname) const;
285 
286  // SetCutValue sets a cut value for a particle type for a region
287  void SetCutValue(G4double aCut, const G4String& pname, const G4String& rname);
288 
289  // Invoke SetCuts for specified particle for a region
290  // If the pointer to the region is NULL, the default region is used
291  // In case of "Retrieve" flag is ON,
292  // Cut values will be retrieved from files
293  void SetParticleCuts(G4double cut,G4ParticleDefinition* particle,G4Region* region=0);
294  void SetParticleCuts( G4double cut, const G4String& particleName, G4Region* region=0);
295 
296  // Invoke SetCuts for all particles in a region
297  void SetCutsForRegion(G4double aCut, const G4String& rname);
298 
299  // Following are utility methods are obsolete
300  void ResetCuts();
301 
303  public:
304  // Get/SetApplyCuts gets/sets the flag for ApplyCuts
305  void SetApplyCuts(G4bool value, const G4String& name);
306  G4bool GetApplyCuts(const G4String& name) const;
307 
309  protected:
310  // do BuildPhysicsTable for make the integral schema
312 
313 
314  protected:
315  // Retrieve PhysicsTable from files for proccess belongng the particle.
316  // Normal BuildPhysics procedure of processes will be invoked,
317  // if it fails (in case of Process's RetrievePhysicsTable returns false)
319  const G4String& directory,
320  G4bool ascii = false);
321 
323  protected:
324  // adds new ProcessManager to all particles in the Particle Table
325  // this routine is used in Construct()
327 
328  public: // with description
329  // remove and delete ProcessManagers for all particles in tha Particle Table
330  // this routine is invoked from RunManager
331  void RemoveProcessManager();
332 
333  public: // with description
334  // add process manager for particles created on-the-fly
335  void AddProcessManager(G4ParticleDefinition* newParticle,
336  G4ProcessManager* newManager = 0 );
337 
339  public:
340  // check consistencies of list of particles
341 
342  void CheckParticleList();
343 
345 
347  protected:
348  // the particle table has the complete List of existing particle types
350  //G4ParticleTable::G4PTblDicIterator* theParticleIterator; //AND
351 
352  protected:
353  // pointer to G4UserPhysicsListMessenger
354  //G4UserPhysicsListMessenger* theMessenger;
355 
356  protected:
358 
359  protected:
360  // this is the default cut value for all particles
363 
364  protected:
365  // pointer to ProductionCutsTable
367 
368  // flag to determine physics table will be build from file or not
371 
374 
375  // directory name for physics table files
377 
378  // flag for displaying the range cuts & energy thresholds
379  //G4int fDisplayThreshold;
380 
381  // flag for Physics Table has been built
382  //G4bool fIsPhysicsTableBuilt;
383 
384  // flag for CheckParticleList
386 
387  // PhysicsListHelper
388  //G4PhysicsListHelper* thePLHelper;
389 
390  private:
391  enum { FixedStringLengthForStore = 32 };
392 
393  //Changes for MT
394  protected:
397  public:
398  inline G4int GetInstanceID() const;
399  static const G4VUPLManager& GetSubInstanceManager();
400  //Used by Worker threads on the shared instance of
401  // PL to initialize workers
402  void InitializeWorker();
403 };
404 
406 {
407 #ifdef G4VERBOSE
408  if (verboseLevel >1) G4cout << "G4VUserPhysicsList::Construct()" << G4endl;
409 #endif
410 
412 
413 #ifdef G4VERBOSE
414  if (verboseLevel >1) G4cout << "Construct processes " << G4endl;
415 #endif
417 
418 }
419 
421 {
422  return defaultCutValue;
423 }
424 
425 
427 {
428  return verboseLevel;
429 }
430 
431 inline
433 {
434  return fRetrievePhysicsTable;
435 }
436 
437 inline
439 {
440  return fStoredInAscii;
441 }
442 
443 inline
445 {
446  return directoryPhysicsTable;
447 }
448 
449 inline
451 {
452  fStoredInAscii = true;
453 }
454 
455 
456 inline
458 {
459  fRetrievePhysicsTable = false;
460  fIsRestoredCutValues = false;
462 }
463 
464 
465 inline
467 {
468  fStoredInAscii = false;
469 }
470 
471 inline
473 {
475 }
476 
477 inline
479 {
480  return g4vuplInstanceID;
481 }
482 
483 inline
485 {
486  return subInstanceManager;
487 }
488 #endif
489 
G4double GetCutValue(const G4String &pname) const
void SetDefaultCutValue(G4double newCutValue)
void BuildIntegralPhysicsTable(G4VProcess *, G4ParticleDefinition *)
void SetApplyCuts(G4bool value, const G4String &name)
G4PhysicsListHelper * _thePLHelper
void SetCutValue(G4double aCut, const G4String &pname)
void PreparePhysicsTable(G4ParticleDefinition *)
G4bool RegisterProcess(G4VProcess *process, G4ParticleDefinition *particle)
G4ProductionCutsTable * fCutsTable
const G4String & GetPhysicsTableDirectory() const
G4VUPLSplitter< G4VUPLData > G4VUPLManager
G4bool fIsCheckedForRetrievePhysicsTable
const XML_Char * name
Definition: expat.h:151
G4bool GetApplyCuts(const G4String &name) const
void SetCutsForRegion(G4double aCut, const G4String &rname)
#define G4RUN_DLL
Definition: rundefs.hh:48
G4ParticleTable * theParticleTable
G4UserPhysicsListMessenger * _theMessenger
int G4int
Definition: G4Types.hh:78
G4int GetVerboseLevel() const
G4bool _fIsPhysicsTableBuilt
void SetPhysicsTableRetrieved(const G4String &directory="")
void SetParticleCuts(G4double cut, G4ParticleDefinition *particle, G4Region *region=0)
void DumpCutValuesTable(G4int flag=1)
void AddProcessManager(G4ParticleDefinition *newParticle, G4ProcessManager *newManager=0)
G4double GetDefaultCutValue() const
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
G4int GetInstanceID() const
void SetVerboseLevel(G4int value)
G4bool IsPhysicsTableRetrieved() const
G4ParticleTable::G4PTblDicIterator * _theParticleIterator
G4VUserPhysicsList & operator=(const G4VUserPhysicsList &)
string pname
Definition: eplot.py:33
G4bool StorePhysicsTable(const G4String &directory=".")
void UseCoupledTransportation(G4bool vl=true)
static G4RUN_DLL G4VUPLManager subInstanceManager
G4bool IsStoredInAscii() const
static const G4VUPLManager & GetSubInstanceManager()
const XML_Char int const XML_Char * value
Definition: expat.h:331
void ResetCuts()
obsolete methods
#define G4endl
Definition: G4ios.hh:61
G4VUPLManager G4VUserPhysicsListSubInstanceManager
virtual void ConstructParticle()=0
double G4double
Definition: G4Types.hh:76
virtual void RetrievePhysicsTable(G4ParticleDefinition *, const G4String &directory, G4bool ascii=false)
virtual void ConstructProcess()=0