ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VUserPhysicsList.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VUserPhysicsList.hh
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 // GEANT 4 class header file
31 // Class Description:
32 // This class is an abstract class for
33 // constructing particles and processes.
34 // User must implement following three virtual methods
35 // in his/her own concrete class derived from this class.
36 // G4VUserPhysicsList::ConstructParticle()
37 // Construct particles
38 // G4VUserPhysicsList::ConstructProcess()
39 // Construct procesess and register them to particles
40 //
41 // -------------------------------------------
42 // History
43 // first version 09 Jan. 1998 by H.Kurashige
44 // modified 24 Jan. 1998 by H.Kurashige
45 // rename DumpCutValues/DumpCutValuesTable
46 // change SetCuts method
47 // add SetCutsWithDefault method
48 // modified 06 June 1998 by H.Kurashige
49 // add AddProcessManager
50 // add BuildPhysicsTable
51 // modified 29 June 1998 by H.Kurashige
52 // add AddProcessManager
53 // modified 05 Dec. 1998 by H.Kurashige
54 // add ConstructAllParticles()
55 // modified 14, Apr 1999 by H.Kurashige
56 // change BuildPhysicsTable as public
57 // removed ConstructAllParticles() and related methods
58 // changed SetCuts method argument
59 // modified 08, Nov 2000 by H.Kurashige
60 // added Retrieve/StorePhysicsTable and related methods
61 // modified 08, Mar 2001 by H.Kurashige
62 // added binary mode for Retrieve/StorePhysicsTable
63 // added RetrieveCutValues and related
64 // added Set/ResetStoredInAscii() to switch on ascii mode
65 // for Retrieve/StorePhysicsTable
66 // modified for CUTS per REGION 10, Oct 2002 by H.Kurashige
67 // removed following methods
68 // void ReCalcCutValue()
69 // void SetCutValueForOthers()
70 // void SetCutValueForOtherThan()
71 // void ReCalcCutValueForOthers()
72 // virtual G4bool StoreMaterialInfo()
73 // virtual G4bool StoreCutValues()
74 // virtual G4bool RetrieveCutValues()
75 // virtual G4bool CheckForRetrievePhysicsTable()
76 // virtual G4bool CheckMaterialInfo()
77 // added void BuildPhysicsTable()
78 // Added PhysicsListHelper 29 Apr. 2011 H.Kurashige
79 // Added default impelmentation of SetCuts 10 June 2011 H.Kurashige
80 // SetCuts is not 'pure virtual' any more
81 // Trasnformations for multi-threading 26 Mar. 2013 A. Dotti
82 // Added destructions 21 Apr 2017 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 
156 {
157  public:
159  virtual ~G4VUserPhysicsList();
160 
161  // copy constructor and assignment operator
164 
165  public: // with description
166  // Each particle type will be instantiated
167  // This method is invoked by the RunManger
168  virtual void ConstructParticle() = 0;
169 
170  // By calling the "Construct" method,
171  // process manager and processes are created.
172  void Construct();
173 
174  // Each physics process will be instantiated and
175  // registered to the process manager of each particle type
176  // This method is invoked in Construct method
177  virtual void ConstructProcess() = 0;
178 
179  protected: // with description
180  // User must invoke this method in his ConstructProcess()
181  // implementation in order to insures particle transportation.
182  void AddTransportation();
183 
184  //Register a process to the particle type
185  // according to the ordering parameter table
186  // 'true' is returned if the process is registerd successfully
189 
190 
191  public:
192  void UseCoupledTransportation(G4bool vl=true);
193 
195  public: // with description
196  // "SetCuts" method sets a cut value for all particle types
197  // in the particle table
198  virtual void SetCuts();
199 
200  public: // with description
201  // set/get the default cut value
202  // Calling SetDefaultCutValue causes re-calcuration of cut values
203  // and physics tables just before the next event loop
204  void SetDefaultCutValue(G4double newCutValue);
206 
208  public: // with description
209  // Invoke BuildPhysicsTable for all processes for all particles
210  // In case of "Retrieve" flag is ON, PhysicsTable will be
211  // retrieved from files
212  void BuildPhysicsTable();
213 
214  // do PreparePhysicsTable for specified particle type
216 
217  // do BuildPhysicsTable for specified particle type
219 
220  // Store PhysicsTable together with both material and cut value
221  // information in files under the specified directory.
222  // (return true if files are sucessfully created)
223  G4bool StorePhysicsTable(const G4String& directory = ".");
224 
225  // Return true if "Retrieve" flag is ON.
226  // (i.e. PhysicsTable will be retrieved from files)
228  G4bool IsStoredInAscii() const;
229 
230  // Get directory path for physics table files.
231  const G4String& GetPhysicsTableDirectory() const;
232 
233  // Set "Retrieve" flag
234  // Directory path can be set together.
235  // Null string (default) means directory is not changed
236  // from the current value
237  void SetPhysicsTableRetrieved(const G4String& directory = "");
238  void SetStoredInAscii();
239 
240  // Reset "Retrieve" flag
242  void ResetStoredInAscii();
243 
245  public: // with description
246  // Print out the List of registered particles types
247  void DumpList() const;
248 
249  public: // with description
250  // Request to print out information of cut values
251  // Printing will be performed when all tables are made
252  void DumpCutValuesTable(G4int flag =1);
253 
254  // The following method actually trigger the print-out requested
255  // by the above method. This method must be invoked by RunManager
256  // at the proper moment.
258 
259  public: // with description
261  G4int GetVerboseLevel() const;
262  // set/get controle flag for output message
263  // 0: Silent
264  // 1: Warning message
265  // 2: More
266 
268  public: // with description
269  // "SetCutsWithDefault" method invokes default SetCuts method
270  // Note: Cut values will not be overwriten with this method
271  // Using default SetCuts method is recommended
272  // (i.e You do not need to implement SetCuts method)
273  void SetCutsWithDefault();
274 
275  // Following are utility methods for SetCuts
276 
277  // SetCutValue sets a cut value for a particle type for the default region
278  void SetCutValue(G4double aCut, const G4String& pname);
279 
280  // GetCutValue sets a cut value for a particle type for the default region
281  G4double GetCutValue(const G4String& pname) const;
282 
283  // SetCutValue sets a cut value for a particle type for a region
284  void SetCutValue(G4double aCut, const G4String& pname, const G4String& rname);
285 
286  // Invoke SetCuts for specified particle for a region
287  // If the pointer to the region is NULL, the default region is used
288  // In case of "Retrieve" flag is ON,
289  // Cut values will be retrieved from files
290  void SetParticleCuts(G4double cut,G4ParticleDefinition* particle,G4Region* region=0);
291  void SetParticleCuts( G4double cut, const G4String& particleName, G4Region* region=0);
292 
293  // Invoke SetCuts for all particles in a region
294  void SetCutsForRegion(G4double aCut, const G4String& rname);
295 
296  // Following are utility methods are obsolete
297  void ResetCuts();
298 
300  public:
301  // Get/SetApplyCuts gets/sets the flag for ApplyCuts
302  void SetApplyCuts(G4bool value, const G4String& name);
303  G4bool GetApplyCuts(const G4String& name) const;
304 
306  protected:
307  // do BuildPhysicsTable for make the integral schema
309 
310 
311  protected:
312  // Retrieve PhysicsTable from files for proccess belongng the particle.
313  // Normal BuildPhysics procedure of processes will be invoked,
314  // if it fails (in case of Process's RetrievePhysicsTable returns false)
316  const G4String& directory,
317  G4bool ascii = false);
318 
320  protected:
321  // adds new ProcessManager to all particles in the Particle Table
322  // this routine is used in Construct()
324 
325  public: // with description
326  // remove and delete ProcessManagers for all particles in tha Particle Table
327  // this routine is invoked from RunManager
328  void RemoveProcessManager();
329 
330  public: // with description
331  // add process manager for particles created on-the-fly
332  void AddProcessManager(G4ParticleDefinition* newParticle,
333  G4ProcessManager* newManager = 0 );
334 
336  public:
337  // check consistencies of list of particles
338 
339  void CheckParticleList();
340 
342 
344  protected:
345  // the particle table has the complete List of existing particle types
347  //G4ParticleTable::G4PTblDicIterator* theParticleIterator; //AND
348 
349  protected:
350  // pointer to G4UserPhysicsListMessenger
351  //G4UserPhysicsListMessenger* theMessenger;
352 
353  protected:
355 
356  protected:
357  // this is the default cut value for all particles
360 
361  protected:
362  // pointer to ProductionCutsTable
364 
365  // flag to determine physics table will be build from file or not
368 
371 
372  // directory name for physics table files
374 
375  // flag for displaying the range cuts & energy thresholds
376  //G4int fDisplayThreshold;
377 
378  // flag for Physics Table has been built
379  //G4bool fIsPhysicsTableBuilt;
380 
381  // flag for CheckParticleList
383 
384  // PhysicsListHelper
385  //G4PhysicsListHelper* thePLHelper;
386 
387  private:
389 
390  //Changes for MT
391  protected:
395  public:
396  inline G4int GetInstanceID() const;
397  static const G4VUPLManager& GetSubInstanceManager();
398  //Used by Worker threads on the shared instance of
399  // PL to initialize workers. Derived class re-implementing this method
400  // must also call this base class method
401  virtual void InitializeWorker();
402  //Destroy thread-local data. Note that derived classes
403  //implementing this method should still call this base class one
404  virtual void TerminateWorker();
405 };
406 
408 {
409 #ifdef G4VERBOSE
410  if (verboseLevel >1) G4cout << "G4VUserPhysicsList::Construct()" << G4endl;
411 #endif
412 
414 
415 #ifdef G4VERBOSE
416  if (verboseLevel >1) G4cout << "Construct processes " << G4endl;
417 #endif
419 
420 }
421 
423 {
424  return defaultCutValue;
425 }
426 
427 
429 {
430  return verboseLevel;
431 }
432 
433 inline
435 {
436  return fRetrievePhysicsTable;
437 }
438 
439 inline
441 {
442  return fStoredInAscii;
443 }
444 
445 inline
447 {
448  return directoryPhysicsTable;
449 }
450 
451 inline
453 {
454  fStoredInAscii = true;
455 }
456 
457 
458 inline
460 {
461  fRetrievePhysicsTable = false;
462  fIsRestoredCutValues = false;
464 }
465 
466 
467 inline
469 {
470  fStoredInAscii = false;
471 }
472 
473 inline
475 {
477 }
478 
479 inline
481 {
482  return g4vuplInstanceID;
483 }
484 
485 inline
487 {
488  return subInstanceManager;
489 }
490 #endif
491