Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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// G4VUserPhysicsList
27//
28// Class description:
29//
30// This class is an abstract class for constructing particles and processes.
31// User must implement the following two pure virtual methods in the concrete
32// class derived from this class:
33// - G4VUserPhysicsList::ConstructParticle()
34// Construct particles
35// - G4VUserPhysicsList::ConstructProcess()
36// Construct procesess and register them to particles.
37
38// Original author: H.Kurashige (Kobe University), 9 January 1998
39// --------------------------------------------------------------------
40#ifndef G4VUserPhysicsList_hh
41#define G4VUserPhysicsList_hh 1
42
44#include "G4ParticleTable.hh"
47#include "G4Threading.hh"
48#include "G4VUPLSplitter.hh"
49#include "G4ios.hh"
50#include "globals.hh"
51
52#include "rundefs.hh"
53#include "tls.hh"
54
57class G4VProcess;
58
59// Encapsulate the fields of class G4VUserPhysicsList that are per-thread.
71
72// The type G4VUPLManager is introduced to encapsulate the methods used by
73// both the master thread and worker threads to allocate memory space for
74// the fields encapsulated by the class G4VUPLData. When each thread
75// changes the value for these fields, it refers to them using a macro
76// definition defined below. For every G4VUserPhysicsList instance,
77// there is a corresponding G4VUPLData instance. All G4VUPLData instances
78// are organized by the class G4VUPLManager as an array.
79// The field "int g4vuplInstanceID" is added to the class G4VUserPhysicsList.
80// The value of this field in each G4VUserPhysicsList instance is the
81// subscript of the corresponding G44VUPLData instance.
82// In order to use the class G44VUPLManager, we add a static member in the class
83// G4VUserPhysicsList as follows: "static G4VUPLManager subInstanceManager".
84// Both the master thread and worker threads change the length of the array
85// for G44VUPLData instances mutually along with G4VUserPhysicsList
86// instances are created. For each worker thread, it dynamically creates ions.
87// Consider any thread A, if there is any other thread which creates an ion.
88// This ion is shared by the thread A. So the thread A leaves an empty space
89// in the array of G4PDefData instances for the ion.
90//
91// Important Note: you may wonder why we are introducing this mechanism
92// since there is only one PL for each application.
93// This is true, in the sense that only one PL is allowed
94// to be associated to a G4RunManager, however user can
95// instantiate as many PLs are needed and at run-time select one
96// of the PLs to be used we thus need this mechanism to
97// guarantee that the system works without problems in case of
98// this (unusual) case. This may be reviewed in the future
99//
102
104{
105 public:
107 virtual ~G4VUserPhysicsList();
110
111 // Each particle type will be instantiated.
112 // This method is invoked by the RunManger.
113 virtual void ConstructParticle() = 0;
114
115 // By calling the "Construct" method,
116 // process manager and processes are created.
117 void Construct();
118
119 // Each physics process will be instantiated and
120 // registered to the process manager of each particle type.
121 // Invoked in the Construct() method.
122 virtual void ConstructProcess() = 0;
123
124 // Sets a cut value for all particle types in the particle table.
125 virtual void SetCuts();
126
127 // Set/get the default cut value. Calling SetDefaultCutValue() causes
128 // re-calcuration of cut values and physics tables just before the
129 // next event loop.
130 void SetDefaultCutValue(G4double newCutValue);
132
133 // Invoke BuildPhysicsTable for all processes for all particles.
134 // In case of "Retrieve" flag is ON, PhysicsTable will be
135 // retrieved from files.
136 void BuildPhysicsTable();
137
138 // Prepare the PhysicsTable for specified particle type.
140
141 // Build the PhysicsTable for specified particle type.
143
144 // Store PhysicsTable together with both material and cut value
145 // information in files under the specified directory.
146 // Returns "true" if files are successfully created.
147 G4bool StorePhysicsTable(const G4String& directory = ".");
148
149 // Return true if "Retrieve" flag is ON.
150 // (i.e. PhysicsTable will be retrieved from files).
152 G4bool IsStoredInAscii() const;
153
154 // Get directory path for physics table files.
155 const G4String& GetPhysicsTableDirectory() const;
156
157 // Set "Retrieve" flag. Directory path can be set together.
158 // Null string (default) means directory is not changed
159 // from the current value.
160 void SetPhysicsTableRetrieved(const G4String& directory = "");
161 void SetStoredInAscii();
162
163 // Reset "Retrieve" flag.
165 void ResetStoredInAscii();
166
167 // Print out the List of registered particles types.
168 void DumpList() const;
169
170 // Request to print out information of cut values.
171 // Printing will be performed when all tables are made.
172 void DumpCutValuesTable(G4int flag = 1);
173
174 // Triggers the print-out requested by the above method.
175 // This method must be invoked by RunManager at the proper moment.
177
178 // Set/get control flag for output message
179 // 0: Silent
180 // 1: Warning message
181 // 2: More
182 void SetVerboseLevel(G4int value);
183 G4int GetVerboseLevel() const;
184
185 void UseCoupledTransportation(G4bool vl = true);
186
187 // Invokes default SetCuts() method.
188 // Note: cut values will not be overwritten.
189 // Use of default SetCuts() method is recommended.
190 void SetCutsWithDefault();
191
192 // Sets a cut value for a particle type for the default region.
193 void SetCutValue(G4double aCut, const G4String& pname);
194
195 // Gets a cut value for a particle type for the default region.
196 G4double GetCutValue(const G4String& pname) const;
197
198 // Sets a cut value for a particle type for a region.
199 void SetCutValue(G4double aCut, const G4String& pname, const G4String& rname);
200
201 // Invoke SetCuts for specified particle for a region.
202 // If the pointer to the region is NULL, the default region is used
203 // In case of "Retrieve" flag is ON, cut values will be retrieved
204 // from files.
205 void SetParticleCuts(G4double cut, G4ParticleDefinition* particle, G4Region* region = nullptr);
206 void SetParticleCuts(G4double cut, const G4String& particleName, G4Region* region = nullptr);
207
208 // Invoke SetCuts() for all particles in a region.
209 void SetCutsForRegion(G4double aCut, const G4String& rname);
210
211 // Gets/sets the flag for ApplyCuts().
212 void SetApplyCuts(G4bool value, const G4String& name);
213 G4bool GetApplyCuts(const G4String& name) const;
214
215 // Remove and delete ProcessManagers for all particles in the
216 // Particle Table.
218
219 // Remove and delete TrackingManagers for all particles in the
220 // Particle Table.
222
223 // Add process manager for particles created on-the-fly.
224 void AddProcessManager(G4ParticleDefinition* newParticle,
225 G4ProcessManager* newManager = nullptr);
226
227 // Check consistencies of list of particles.
228 void CheckParticleList();
229
231
232 inline G4int GetInstanceID() const;
233 static const G4VUPLManager& GetSubInstanceManager();
234
235 // Used by Worker threads on the shared instance of physics-list
236 // to initialise workers. Derived class re-implementing this method
237 // must also call this base class method.
238 virtual void InitializeWorker();
239
240 // Destroy thread-local data. Note that derived classes
241 // implementing this method should still call this base class one.
242 virtual void TerminateWorker();
243
244 protected:
245 // User must invoke this method in his ConstructProcess()
246 // implementation in order to enable particle transportation.
247 void AddTransportation();
248
249 // Register a process to the particle type
250 // according to the ordering parameter table.
251 // 'true' is returned if the process is registerd successfully.
253
254 // Build PhysicsTable for making the integral schema.
256
257 // Retrieve PhysicsTable from files for process belonging to the particle.
258 // Normal BuildPhysics procedure of processes will be invoked, if it
259 // fails (in case of process's RetrievePhysicsTable() returns false).
260 virtual void RetrievePhysicsTable(G4ParticleDefinition*, const G4String& directory,
261 G4bool ascii = false);
262
263 // Adds new ProcessManager to all particles in the Particle Table.
264 // This function is used in Construct().
266
268
269 protected:
270 // The particle table has the complete List of existing particle types.
272
274
275 // Default cut value for all particles
278
279 // Pointer to ProductionCutsTable.
281
282 // Flag to determine if physics table will be build from file or not.
285
288
289 // Directory name for physics table files.
291
292 // Flag for CheckParticleList().
294
295 // MT data
298};
299
300// Inline methods implementations
301
303{
304#ifdef G4VERBOSE
305 if (verboseLevel > 1) G4cout << "G4VUserPhysicsList::Construct()" << G4endl;
306#endif
307
309
311
312#ifdef G4VERBOSE
313 if (verboseLevel > 1) G4cout << "Construct processes " << G4endl;
314#endif
316}
317
322
324{
325 return verboseLevel;
326}
327
332
334{
335 return fStoredInAscii;
336}
337
342
344{
345 fStoredInAscii = true;
346}
347
354
356{
357 fStoredInAscii = false;
358}
359
364
366{
367 return g4vuplInstanceID;
368}
369
374
375#endif
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4VUPLSplitter< G4VUPLData > G4VUPLManager
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4bool _fIsPhysicsTableBuilt
G4ParticleTable::G4PTblDicIterator * _theParticleIterator
G4PhysicsListHelper * _thePLHelper
G4UserPhysicsListMessenger * _theMessenger
G4double GetCutValue(const G4String &pname) const
void SetDefaultCutValue(G4double newCutValue)
void SetPhysicsTableRetrieved(const G4String &directory="")
virtual void ConstructProcess()=0
G4VUserPhysicsList & operator=(const G4VUserPhysicsList &)
void PreparePhysicsTable(G4ParticleDefinition *)
virtual void TerminateWorker()
void SetCutValue(G4double aCut, const G4String &pname)
G4bool RegisterProcess(G4VProcess *process, G4ParticleDefinition *particle)
void UseCoupledTransportation(G4bool vl=true)
G4bool IsStoredInAscii() const
void SetCutsForRegion(G4double aCut, const G4String &rname)
G4ProductionCutsTable * fCutsTable
void AddProcessManager(G4ParticleDefinition *newParticle, G4ProcessManager *newManager=nullptr)
virtual void ConstructParticle()=0
G4bool StorePhysicsTable(const G4String &directory=".")
G4ParticleTable::G4PTblDicIterator * GetParticleIterator() const
G4ParticleTable * theParticleTable
void SetVerboseLevel(G4int value)
G4int GetVerboseLevel() const
void SetApplyCuts(G4bool value, const G4String &name)
const G4String & GetPhysicsTableDirectory() const
G4bool IsPhysicsTableRetrieved() const
virtual void RetrievePhysicsTable(G4ParticleDefinition *, const G4String &directory, G4bool ascii=false)
void SetParticleCuts(G4double cut, G4ParticleDefinition *particle, G4Region *region=nullptr)
void DumpCutValuesTable(G4int flag=1)
G4bool GetApplyCuts(const G4String &name) const
static G4RUN_DLL G4VUPLManager subInstanceManager
void BuildIntegralPhysicsTable(G4VProcess *, G4ParticleDefinition *)
virtual void InitializeWorker()
G4double GetDefaultCutValue() const
static const G4VUPLManager & GetSubInstanceManager()
G4bool IsMasterThread()
#define G4RUN_DLL
Definition rundefs.hh:45