Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
43#include "G4ios.hh"
44#include "globals.hh"
45#include "rundefs.hh"
46#include "tls.hh"
47
49#include "G4ParticleTable.hh"
51#include "G4VUPLSplitter.hh"
52
53#include "G4Threading.hh"
55
58class G4VProcess;
59
61{
62 // Encapsulate the fields of class G4VUserPhysicsList that are per-thread.
63
64 public:
65
66 void initialize();
67
73};
74
75// The type G4VUPLManager is introduced to encapsulate the methods used by
76// both the master thread and worker threads to allocate memory space for
77// the fields encapsulated by the class G4VUPLData. When each thread
78// changes the value for these fields, it refers to them using a macro
79// definition defined below. For every G4VUserPhysicsList instance,
80// there is a corresponding G4VUPLData instance. All G4VUPLData instances
81// are organized by the class G4VUPLManager as an array.
82// The field "int g4vuplInstanceID" is added to the class G4VUserPhysicsList.
83// The value of this field in each G4VUserPhysicsList instance is the
84// subscript of the corresponding G44VUPLData instance.
85// In order to use the class G44VUPLManager, we add a static member in the class
86// G4VUserPhysicsList as follows: "static G4VUPLManager subInstanceManager".
87// Both the master thread and worker threads change the length of the array
88// for G44VUPLData instances mutually along with G4VUserPhysicsList
89// instances are created. For each worker thread, it dynamically creates ions.
90// Consider any thread A, if there is any other thread which creates an ion.
91// This ion is shared by the thread A. So the thread A leaves an empty space
92// in the array of G4PDefData instances for the ion.
93//
94// Important Note: you may wonder why we are introducing this mechanism
95// since there is only one PL for each application.
96// This is true, in the sense that only one PL is allowed
97// to be associated to a G4RunManager, however user can
98// instantiate as many PLs are needed and at run-time select one
99// of the PLs to be used we thus need this mechanism to
100// guarantee that the system works without problems in case of
101// this (unusual) case. This may be reviewed in the future
102//
105
107{
108 public:
109
111 virtual ~G4VUserPhysicsList();
112
115 // Copy constructor and assignment operator.
116
117 virtual void ConstructParticle() = 0;
118 // Each particle type will be instantiated.
119 // This method is invoked by the RunManger.
120
121 void Construct();
122 // By calling the "Construct" method,
123 // process manager and processes are created.
124
125 virtual void ConstructProcess() = 0;
126 // Each physics process will be instantiated and
127 // registered to the process manager of each particle type.
128 // Invoked in the Construct() method.
129
130 virtual void SetCuts();
131 // Sets a cut value for all particle types in the particle table.
132
133 void SetDefaultCutValue(G4double newCutValue);
135 // Set/get the default cut value. Calling SetDefaultCutValue() causes
136 // re-calcuration of cut values and physics tables just before the
137 // next event loop.
138
139 void BuildPhysicsTable();
140 // Invoke BuildPhysicsTable for all processes for all particles.
141 // In case of "Retrieve" flag is ON, PhysicsTable will be
142 // retrieved from files.
143
145 // Prepare the PhysicsTable for specified particle type.
146
148 // Build the PhysicsTable for specified particle type.
149
150 G4bool StorePhysicsTable(const G4String& directory = ".");
151 // Store PhysicsTable together with both material and cut value
152 // information in files under the specified directory.
153 // Returns "true" if files are successfully created.
154
156 G4bool IsStoredInAscii() const;
157 // Return true if "Retrieve" flag is ON.
158 // (i.e. PhysicsTable will be retrieved from files).
159
160 const G4String& GetPhysicsTableDirectory() const;
161 // Get directory path for physics table files.
162
163 void SetPhysicsTableRetrieved(const G4String& directory = "");
164 void SetStoredInAscii();
165 // Set "Retrieve" flag. Directory path can be set together.
166 // Null string (default) means directory is not changed
167 // from the current value.
168
170 void ResetStoredInAscii();
171 // Reset "Retrieve" flag.
172
173 void DumpList() const;
174 // Print out the List of registered particles types.
175
176 void DumpCutValuesTable(G4int flag = 1);
177 // Request to print out information of cut values.
178 // Printing will be performed when all tables are made.
179
181 // Triggers the print-out requested by the above method.
182 // This method must be invoked by RunManager at the proper moment.
183
184 void SetVerboseLevel(G4int value);
185 G4int GetVerboseLevel() const;
186 // Set/get control flag for output message
187 // 0: Silent
188 // 1: Warning message
189 // 2: More
190
191 void UseCoupledTransportation(G4bool vl = true);
192
193 void SetCutsWithDefault();
194 // Invokes default SetCuts() method.
195 // Note: cut values will not be overwritten.
196 // Use of default SetCuts() method is recommended.
197
198 void SetCutValue(G4double aCut, const G4String& pname);
199 // Sets a cut value for a particle type for the default region.
200
201 G4double GetCutValue(const G4String& pname) const;
202 // Gets a cut value for a particle type for the default region.
203
204 void SetCutValue(G4double aCut, const G4String& pname,
205 const G4String& rname);
206 // Sets a cut value for a particle type for a region.
207
209 G4Region* region = nullptr);
210 void SetParticleCuts(G4double cut, const G4String& particleName,
211 G4Region* region = nullptr);
212 // Invoke SetCuts for specified particle for a region.
213 // If the pointer to the region is NULL, the default region is used
214 // In case of "Retrieve" flag is ON, cut values will be retrieved
215 // from files.
216
217 void SetCutsForRegion(G4double aCut, const G4String& rname);
218 // Invoke SetCuts() for all particles in a region.
219
220 void SetApplyCuts(G4bool value, const G4String& name);
221 G4bool GetApplyCuts(const G4String& name) const;
222 // Gets/sets the flag for ApplyCuts().
223
225 // Remove and delete ProcessManagers for all particles in the
226 // Particle Table.
227
229 // Remove and delete TrackingManagers for all particles in the
230 // Particle Table.
231
232 void AddProcessManager(G4ParticleDefinition* newParticle,
233 G4ProcessManager* newManager = nullptr);
234 // Add process manager for particles created on-the-fly.
235
236 void CheckParticleList();
237 // Check consistencies of list of particles.
238
240
241 inline G4int GetInstanceID() const;
242 static const G4VUPLManager& GetSubInstanceManager();
243 // Used by Worker threads on the shared instance of physics-list
244 // to initialise workers. Derived class re-implementing this method
245 // must also call this base class method.
246 virtual void InitializeWorker();
247 // Destroy thread-local data. Note that derived classes
248 // implementing this method should still call this base class one.
249 virtual void TerminateWorker();
250
251 protected:
252
253 void AddTransportation();
254 // User must invoke this method in his ConstructProcess()
255 // implementation in order to enable particle transportation.
256
258 // Register a process to the particle type
259 // according to the ordering parameter table.
260 // 'true' is returned if the process is registerd successfully.
261
263 // Build PhysicsTable for making the integral schema.
264
266 const G4String& directory,
267 G4bool ascii = false);
268 // Retrieve PhysicsTable from files for process belonging to the particle.
269 // Normal BuildPhysics procedure of processes will be invoked, if it
270 // fails (in case of process's RetrievePhysicsTable() returns false).
271
273 // Adds new ProcessManager to all particles in the Particle Table.
274 // This function is used in Construct().
275
277
278 protected:
279
281 // The particle table has the complete List of existing particle types.
282
284
286 // Default cut value for all particles
288
290 // Pointer to ProductionCutsTable.
291
293 // Flag to determine if physics table will be build from file or not.
295
298
300 // Directory name for physics table files.
301
303 // Flag for CheckParticleList().
304
307 // MT data
308
309 private:
310
311 enum
312 {
313 FixedStringLengthForStore = 32
314 };
315};
316
317// Inline methods implementations
318
320{
321 #ifdef G4VERBOSE
322 if(verboseLevel > 1)
323 G4cout << "G4VUserPhysicsList::Construct()" << G4endl;
324 #endif
325
327
329
330 #ifdef G4VERBOSE
331 if(verboseLevel > 1)
332 G4cout << "Construct processes " << G4endl;
333 #endif
335}
336
338{
339 return defaultCutValue;
340}
341
343{
344 return verboseLevel;
345}
346
348{
350}
351
353{
354 return fStoredInAscii;
355}
356
358{
360}
361
363{
364 fStoredInAscii = true;
365}
366
368{
369 fRetrievePhysicsTable = false;
370 fIsRestoredCutValues = false;
372}
373
375{
376 fStoredInAscii = false;
377}
378
380{
382}
383
385{
386 return g4vuplInstanceID;
387}
388
390{
391 return subInstanceManager;
392}
393
394#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:57
G4GLOB_DLL std::ostream G4cout
G4int _fDisplayThreshold
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)
G4bool fIsCheckedForRetrievePhysicsTable
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 *)
G4int GetInstanceID() const
virtual void InitializeWorker()
G4double GetDefaultCutValue() const
static const G4VUPLManager & GetSubInstanceManager()
G4bool IsMasterThread()
Definition: G4Threading.cc:124
#define G4RUN_DLL
Definition: rundefs.hh:45