|
||||
File indexing completed on 2025-01-18 09:59:28
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // G4VUserPhysicsList 0027 // 0028 // Class description: 0029 // 0030 // This class is an abstract class for constructing particles and processes. 0031 // User must implement the following two pure virtual methods in the concrete 0032 // class derived from this class: 0033 // - G4VUserPhysicsList::ConstructParticle() 0034 // Construct particles 0035 // - G4VUserPhysicsList::ConstructProcess() 0036 // Construct procesess and register them to particles. 0037 0038 // Original author: H.Kurashige (Kobe University), 9 January 1998 0039 // -------------------------------------------------------------------- 0040 #ifndef G4VUserPhysicsList_hh 0041 #define G4VUserPhysicsList_hh 1 0042 0043 #include "G4ParticleDefinition.hh" 0044 #include "G4ParticleTable.hh" 0045 #include "G4PhysicsModelCatalog.hh" 0046 #include "G4ProductionCutsTable.hh" 0047 #include "G4Threading.hh" 0048 #include "G4VUPLSplitter.hh" 0049 #include "G4ios.hh" 0050 #include "globals.hh" 0051 0052 #include "rundefs.hh" 0053 #include "tls.hh" 0054 0055 class G4UserPhysicsListMessenger; 0056 class G4PhysicsListHelper; 0057 class G4VProcess; 0058 0059 // Encapsulate the fields of class G4VUserPhysicsList that are per-thread. 0060 class G4VUPLData 0061 { 0062 public: 0063 void initialize(); 0064 0065 G4ParticleTable::G4PTblDicIterator* _theParticleIterator = nullptr; 0066 G4UserPhysicsListMessenger* _theMessenger = nullptr; 0067 G4PhysicsListHelper* _thePLHelper = nullptr; 0068 G4bool _fIsPhysicsTableBuilt = false; 0069 G4int _fDisplayThreshold = 0; 0070 }; 0071 0072 // The type G4VUPLManager is introduced to encapsulate the methods used by 0073 // both the master thread and worker threads to allocate memory space for 0074 // the fields encapsulated by the class G4VUPLData. When each thread 0075 // changes the value for these fields, it refers to them using a macro 0076 // definition defined below. For every G4VUserPhysicsList instance, 0077 // there is a corresponding G4VUPLData instance. All G4VUPLData instances 0078 // are organized by the class G4VUPLManager as an array. 0079 // The field "int g4vuplInstanceID" is added to the class G4VUserPhysicsList. 0080 // The value of this field in each G4VUserPhysicsList instance is the 0081 // subscript of the corresponding G44VUPLData instance. 0082 // In order to use the class G44VUPLManager, we add a static member in the class 0083 // G4VUserPhysicsList as follows: "static G4VUPLManager subInstanceManager". 0084 // Both the master thread and worker threads change the length of the array 0085 // for G44VUPLData instances mutually along with G4VUserPhysicsList 0086 // instances are created. For each worker thread, it dynamically creates ions. 0087 // Consider any thread A, if there is any other thread which creates an ion. 0088 // This ion is shared by the thread A. So the thread A leaves an empty space 0089 // in the array of G4PDefData instances for the ion. 0090 // 0091 // Important Note: you may wonder why we are introducing this mechanism 0092 // since there is only one PL for each application. 0093 // This is true, in the sense that only one PL is allowed 0094 // to be associated to a G4RunManager, however user can 0095 // instantiate as many PLs are needed and at run-time select one 0096 // of the PLs to be used we thus need this mechanism to 0097 // guarantee that the system works without problems in case of 0098 // this (unusual) case. This may be reviewed in the future 0099 // 0100 using G4VUPLManager = G4VUPLSplitter<G4VUPLData>; 0101 using G4VUserPhysicsListSubInstanceManager = G4VUPLManager; 0102 0103 class G4VUserPhysicsList 0104 { 0105 public: 0106 G4VUserPhysicsList(); 0107 virtual ~G4VUserPhysicsList(); 0108 G4VUserPhysicsList(const G4VUserPhysicsList&); 0109 G4VUserPhysicsList& operator=(const G4VUserPhysicsList&); 0110 0111 // Each particle type will be instantiated. 0112 // This method is invoked by the RunManger. 0113 virtual void ConstructParticle() = 0; 0114 0115 // By calling the "Construct" method, 0116 // process manager and processes are created. 0117 void Construct(); 0118 0119 // Each physics process will be instantiated and 0120 // registered to the process manager of each particle type. 0121 // Invoked in the Construct() method. 0122 virtual void ConstructProcess() = 0; 0123 0124 // Sets a cut value for all particle types in the particle table. 0125 virtual void SetCuts(); 0126 0127 // Set/get the default cut value. Calling SetDefaultCutValue() causes 0128 // re-calcuration of cut values and physics tables just before the 0129 // next event loop. 0130 void SetDefaultCutValue(G4double newCutValue); 0131 G4double GetDefaultCutValue() const; 0132 0133 // Invoke BuildPhysicsTable for all processes for all particles. 0134 // In case of "Retrieve" flag is ON, PhysicsTable will be 0135 // retrieved from files. 0136 void BuildPhysicsTable(); 0137 0138 // Prepare the PhysicsTable for specified particle type. 0139 void PreparePhysicsTable(G4ParticleDefinition*); 0140 0141 // Build the PhysicsTable for specified particle type. 0142 void BuildPhysicsTable(G4ParticleDefinition*); 0143 0144 // Store PhysicsTable together with both material and cut value 0145 // information in files under the specified directory. 0146 // Returns "true" if files are successfully created. 0147 G4bool StorePhysicsTable(const G4String& directory = "."); 0148 0149 // Return true if "Retrieve" flag is ON. 0150 // (i.e. PhysicsTable will be retrieved from files). 0151 G4bool IsPhysicsTableRetrieved() const; 0152 G4bool IsStoredInAscii() const; 0153 0154 // Get directory path for physics table files. 0155 const G4String& GetPhysicsTableDirectory() const; 0156 0157 // Set "Retrieve" flag. Directory path can be set together. 0158 // Null string (default) means directory is not changed 0159 // from the current value. 0160 void SetPhysicsTableRetrieved(const G4String& directory = ""); 0161 void SetStoredInAscii(); 0162 0163 // Reset "Retrieve" flag. 0164 void ResetPhysicsTableRetrieved(); 0165 void ResetStoredInAscii(); 0166 0167 // Print out the List of registered particles types. 0168 void DumpList() const; 0169 0170 // Request to print out information of cut values. 0171 // Printing will be performed when all tables are made. 0172 void DumpCutValuesTable(G4int flag = 1); 0173 0174 // Triggers the print-out requested by the above method. 0175 // This method must be invoked by RunManager at the proper moment. 0176 void DumpCutValuesTableIfRequested(); 0177 0178 // Set/get control flag for output message 0179 // 0: Silent 0180 // 1: Warning message 0181 // 2: More 0182 void SetVerboseLevel(G4int value); 0183 G4int GetVerboseLevel() const; 0184 0185 void UseCoupledTransportation(G4bool vl = true); 0186 0187 // Invokes default SetCuts() method. 0188 // Note: cut values will not be overwritten. 0189 // Use of default SetCuts() method is recommended. 0190 void SetCutsWithDefault(); 0191 0192 // Sets a cut value for a particle type for the default region. 0193 void SetCutValue(G4double aCut, const G4String& pname); 0194 0195 // Gets a cut value for a particle type for the default region. 0196 G4double GetCutValue(const G4String& pname) const; 0197 0198 // Sets a cut value for a particle type for a region. 0199 void SetCutValue(G4double aCut, const G4String& pname, const G4String& rname); 0200 0201 // Invoke SetCuts for specified particle for a region. 0202 // If the pointer to the region is NULL, the default region is used 0203 // In case of "Retrieve" flag is ON, cut values will be retrieved 0204 // from files. 0205 void SetParticleCuts(G4double cut, G4ParticleDefinition* particle, G4Region* region = nullptr); 0206 void SetParticleCuts(G4double cut, const G4String& particleName, G4Region* region = nullptr); 0207 0208 // Invoke SetCuts() for all particles in a region. 0209 void SetCutsForRegion(G4double aCut, const G4String& rname); 0210 0211 // Gets/sets the flag for ApplyCuts(). 0212 void SetApplyCuts(G4bool value, const G4String& name); 0213 G4bool GetApplyCuts(const G4String& name) const; 0214 0215 // Remove and delete ProcessManagers for all particles in the 0216 // Particle Table. 0217 void RemoveProcessManager(); 0218 0219 // Remove and delete TrackingManagers for all particles in the 0220 // Particle Table. 0221 void RemoveTrackingManager(); 0222 0223 // Add process manager for particles created on-the-fly. 0224 void AddProcessManager(G4ParticleDefinition* newParticle, 0225 G4ProcessManager* newManager = nullptr); 0226 0227 // Check consistencies of list of particles. 0228 void CheckParticleList(); 0229 0230 void DisableCheckParticleList(); 0231 0232 inline G4int GetInstanceID() const; 0233 static const G4VUPLManager& GetSubInstanceManager(); 0234 0235 // Used by Worker threads on the shared instance of physics-list 0236 // to initialise workers. Derived class re-implementing this method 0237 // must also call this base class method. 0238 virtual void InitializeWorker(); 0239 0240 // Destroy thread-local data. Note that derived classes 0241 // implementing this method should still call this base class one. 0242 virtual void TerminateWorker(); 0243 0244 protected: 0245 // User must invoke this method in his ConstructProcess() 0246 // implementation in order to enable particle transportation. 0247 void AddTransportation(); 0248 0249 // Register a process to the particle type 0250 // according to the ordering parameter table. 0251 // 'true' is returned if the process is registerd successfully. 0252 G4bool RegisterProcess(G4VProcess* process, G4ParticleDefinition* particle); 0253 0254 // Build PhysicsTable for making the integral schema. 0255 void BuildIntegralPhysicsTable(G4VProcess*, G4ParticleDefinition*); 0256 0257 // Retrieve PhysicsTable from files for process belonging to the particle. 0258 // Normal BuildPhysics procedure of processes will be invoked, if it 0259 // fails (in case of process's RetrievePhysicsTable() returns false). 0260 virtual void RetrievePhysicsTable(G4ParticleDefinition*, const G4String& directory, 0261 G4bool ascii = false); 0262 0263 // Adds new ProcessManager to all particles in the Particle Table. 0264 // This function is used in Construct(). 0265 void InitializeProcessManager(); 0266 0267 G4ParticleTable::G4PTblDicIterator* GetParticleIterator() const; 0268 0269 protected: 0270 // The particle table has the complete List of existing particle types. 0271 G4ParticleTable* theParticleTable = nullptr; 0272 0273 G4int verboseLevel = 1; 0274 0275 // Default cut value for all particles 0276 G4double defaultCutValue = 1.0; 0277 G4bool isSetDefaultCutValue = false; 0278 0279 // Pointer to ProductionCutsTable. 0280 G4ProductionCutsTable* fCutsTable = nullptr; 0281 0282 // Flag to determine if physics table will be build from file or not. 0283 G4bool fRetrievePhysicsTable = false; 0284 G4bool fStoredInAscii = true; 0285 0286 G4bool fIsCheckedForRetrievePhysicsTable = false; 0287 G4bool fIsRestoredCutValues = false; 0288 0289 // Directory name for physics table files. 0290 G4String directoryPhysicsTable = "."; 0291 0292 // Flag for CheckParticleList(). 0293 G4bool fDisableCheckParticleList = false; 0294 0295 // MT data 0296 G4int g4vuplInstanceID = 0; 0297 G4RUN_DLL static G4VUPLManager subInstanceManager; 0298 }; 0299 0300 // Inline methods implementations 0301 0302 inline void G4VUserPhysicsList::Construct() 0303 { 0304 #ifdef G4VERBOSE 0305 if (verboseLevel > 1) G4cout << "G4VUserPhysicsList::Construct()" << G4endl; 0306 #endif 0307 0308 if (G4Threading::IsMasterThread()) G4PhysicsModelCatalog::Initialize(); 0309 0310 InitializeProcessManager(); 0311 0312 #ifdef G4VERBOSE 0313 if (verboseLevel > 1) G4cout << "Construct processes " << G4endl; 0314 #endif 0315 ConstructProcess(); 0316 } 0317 0318 inline G4double G4VUserPhysicsList::GetDefaultCutValue() const 0319 { 0320 return defaultCutValue; 0321 } 0322 0323 inline G4int G4VUserPhysicsList::GetVerboseLevel() const 0324 { 0325 return verboseLevel; 0326 } 0327 0328 inline G4bool G4VUserPhysicsList::IsPhysicsTableRetrieved() const 0329 { 0330 return fRetrievePhysicsTable; 0331 } 0332 0333 inline G4bool G4VUserPhysicsList::IsStoredInAscii() const 0334 { 0335 return fStoredInAscii; 0336 } 0337 0338 inline const G4String& G4VUserPhysicsList::GetPhysicsTableDirectory() const 0339 { 0340 return directoryPhysicsTable; 0341 } 0342 0343 inline void G4VUserPhysicsList::SetStoredInAscii() 0344 { 0345 fStoredInAscii = true; 0346 } 0347 0348 inline void G4VUserPhysicsList::ResetPhysicsTableRetrieved() 0349 { 0350 fRetrievePhysicsTable = false; 0351 fIsRestoredCutValues = false; 0352 fIsCheckedForRetrievePhysicsTable = false; 0353 } 0354 0355 inline void G4VUserPhysicsList::ResetStoredInAscii() 0356 { 0357 fStoredInAscii = false; 0358 } 0359 0360 inline void G4VUserPhysicsList::DisableCheckParticleList() 0361 { 0362 fDisableCheckParticleList = true; 0363 } 0364 0365 inline G4int G4VUserPhysicsList::GetInstanceID() const 0366 { 0367 return g4vuplInstanceID; 0368 } 0369 0370 inline const G4VUPLManager& G4VUserPhysicsList::GetSubInstanceManager() 0371 { 0372 return subInstanceManager; 0373 } 0374 0375 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |