Geant4 Cross Reference |
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 // G4ProcessManager 27 // 28 // Class Description: 29 // 30 // G4ProcessManager collects all physics a particle can undertake as 31 // vectors. These vectors are: 32 // - one vector for all processes (called as "process List") 33 // - two vectors for processes with AtRestGetPhysicalInteractionLength() 34 // and AtRestDoIt() 35 // - two vectors for processes with AlongStepGetPhysicalInteractionLength() 36 // and AlongStepDoIt() 37 // - two vectors for processes with PostStepGetPhysicalInteractionLength() 38 // and PostStepDoIt() 39 // The tracking will message three types of GetPhysicalInteractionLength() 40 // in order to limit the Step and select the occurrence of processes. 41 // It will message the corresponding DoIt() to apply the selected 42 // processes. In addition, the Tracking will limit the Step 43 // and select the occurrence of the processes according to 44 // the shortest physical interaction length computed (except for 45 // processes at rest, for which the Tracking will select the 46 // occurrence of the process which returns the shortest mean 47 // life-time from the GetPhysicalInteractionLength()). 48 49 // Authors: 50 // - 02.12.1995, G.Cosmo - First implementation, based on object model 51 // - 06.05.1996, G.Cosmo - Revised; added vector of processes at rest 52 // - 08.01.1997, H.Kurashige - New Physics scheme 53 // -------------------------------------------------------------------- 54 #ifndef G4ProcessManager_hh 55 #define G4ProcessManager_hh 1 56 57 #include <vector> 58 59 #include "globals.hh" 60 #include "G4ios.hh" 61 62 #include "G4VProcess.hh" 63 #include "G4ProcessVector.hh" 64 #include "G4ParticleDefinition.hh" 65 66 class G4ProcessManagerMessenger; 67 class G4ProcessAttribute; 68 69 // Indexes for ProcessVector 70 // 71 enum G4ProcessVectorTypeIndex 72 { 73 typeGPIL = 0, // for GetPhysicalInteractionLength 74 typeDoIt =1 // for DoIt 75 }; 76 enum G4ProcessVectorDoItIndex 77 { 78 idxAll = -1, // for all DoIt/GPIL 79 idxAtRest = 0, // for AtRestDoIt/GPIL 80 idxAlongStep = 1, // for AlongStepDoIt/GPIL 81 idxPostStep =2, // for AlongSTepDoIt/GPIL 82 NDoit =3 83 }; 84 85 // Enumeration for Ordering Parameter 86 // 87 enum G4ProcessVectorOrdering 88 { 89 ordInActive = -1, // ordering parameter to indicate InActive DoIt 90 ordDefault = 1000, // default ordering parameter 91 ordLast = 9999 // ordering parameter to indicate the last DoIt 92 }; 93 94 class G4ProcessManager 95 { 96 using G4ProcessAttrVector = std::vector<G4ProcessAttribute*>; 97 98 public: 99 100 G4ProcessManager(const G4ParticleDefinition* aParticleType); 101 // Constructor 102 103 G4ProcessManager(G4ProcessManager& right); 104 // copy constructor 105 106 G4ProcessManager() = delete; 107 G4ProcessManager& operator=(const G4ProcessManager&) = delete; 108 // Default constructor and assignment operator not allowed 109 110 ~G4ProcessManager(); 111 // Destructor 112 113 G4bool operator==(const G4ProcessManager &right) const; 114 G4bool operator!=(const G4ProcessManager &right) const; 115 116 inline G4ProcessVector* GetProcessList() const; 117 // Returns the address of the vector of all processes 118 119 inline G4int GetProcessListLength() const; 120 // Returns the number of process in the ProcessVector 121 122 inline G4int GetProcessIndex(G4VProcess*) const; 123 // Returns the index of the process in the process List 124 125 inline G4ProcessVector* GetProcessVector( 126 G4ProcessVectorDoItIndex idx, 127 G4ProcessVectorTypeIndex typ = typeGPIL 128 ) const; 129 // Returns the address of the vector of processes 130 131 inline G4ProcessVector* GetAtRestProcessVector( 132 G4ProcessVectorTypeIndex typ = typeGPIL 133 ) const; 134 // Returns the address of the vector of processes for 135 // AtRestGetPhysicalInteractionLength idx =0 136 // AtRestGetPhysicalDoIt idx =1 137 138 inline G4ProcessVector* GetAlongStepProcessVector( 139 G4ProcessVectorTypeIndex typ = typeGPIL 140 ) const; 141 // Returns the address of the vector of processes for 142 // AlongStepGetPhysicalInteractionLength idx =0 143 // AlongStepGetPhysicalDoIt idx =1 144 145 inline G4ProcessVector* GetPostStepProcessVector( 146 G4ProcessVectorTypeIndex typ = typeGPIL 147 ) const; 148 // Returns the address of the vector of processes for 149 // PostStepGetPhysicalInteractionLength idx =0 150 // PostStepGetPhysicalDoIt idx =1 151 152 G4int GetProcessVectorIndex( 153 G4VProcess* aProcess, 154 G4ProcessVectorDoItIndex idx, 155 G4ProcessVectorTypeIndex typ = typeGPIL 156 ) const; 157 inline G4int GetAtRestIndex( 158 G4VProcess* aProcess, 159 G4ProcessVectorTypeIndex typ = typeGPIL 160 ) const; 161 inline G4int GetAlongStepIndex( 162 G4VProcess* aProcess, 163 G4ProcessVectorTypeIndex typ = typeGPIL 164 ) const; 165 inline G4int GetPostStepIndex( 166 G4VProcess* aProcess, 167 G4ProcessVectorTypeIndex typ = typeGPIL 168 ) const; 169 // Returns the index for GPIL/DoIt process vector of the process 170 171 G4int AddProcess( G4VProcess* aProcess, 172 G4int ordAtRestDoIt = ordInActive, 173 G4int ordAlongSteptDoIt = ordInActive, 174 G4int ordPostStepDoIt = ordInActive ); 175 // Adds a process to the process List 176 // Return values is the index to the List. Negative return value 177 // indicates that the process has not been added due to some errors 178 // The first argument is a pointer to the process. 179 // Successive arguments are ordering parameters of the process in 180 // process vectors. If value is negative, the process is 181 // not added to the corresponding process vector 182 183 /////////////////////////////////////////////// 184 // The following methods are provided for simple processes 185 // AtRestProcess has only AtRestDoIt 186 // ContinuousProcess has only AlongStepDoIt 187 // DiscreteProcess has only PostStepDoIt 188 // If the ordering parameter is not specified, the process is 189 // added at the end of List of process vectors 190 // If a process with same ordering parameter exists, 191 // this new process will be added just after processes 192 // with same ordering parameter (except for processes assigned to LAST 193 // explicitly) for both DoIt() and GetPhysicalInteractionLength() 194 /////////////////////////////////////////////// 195 196 inline G4int AddRestProcess(G4VProcess* aProcess, G4int ord=ordDefault); 197 inline G4int AddDiscreteProcess(G4VProcess* aProcess, G4int ord=ordDefault); 198 inline G4int AddContinuousProcess(G4VProcess* aProcess, G4int ord=ordDefault); 199 200 /////////////////////////////////////////////// 201 // Alternative methods for setting ordering parameters 202 // Note: AddProcess() method should precede calls to these methods 203 /////////////////////////////////////////////// 204 205 G4int GetProcessOrdering( 206 G4VProcess* aProcess, 207 G4ProcessVectorDoItIndex idDoIt 208 ); 209 210 void SetProcessOrdering( 211 G4VProcess* aProcess, 212 G4ProcessVectorDoItIndex idDoIt, 213 G4int ordDoIt = ordDefault 214 ); 215 // Set ordering parameter for DoIt() specified by typeDoIt. 216 // If a process with same ordering parameter exists, 217 // this new process will be added just after processes 218 // with same ordering parameter 219 // Note: Ordering parameter will bet set to non-zero 220 // even if you set ordDoIt = 0 221 222 void SetProcessOrderingToFirst( 223 G4VProcess* aProcess, 224 G4ProcessVectorDoItIndex idDoIt 225 ); 226 // Set ordering parameter to the first of all processes 227 // for DoIt() specified by idDoIt. 228 // Note: If you use this method for two processes, 229 // a process called later will be first 230 231 void SetProcessOrderingToSecond( 232 G4VProcess* aProcess, 233 G4ProcessVectorDoItIndex idDoIt 234 ); 235 // Set ordering parameter to 1 for DoIt() specified by idDoIt 236 // and the process will be added just after 237 // the processes with ordering parameter equal to zero 238 // Note: If you use this method for two processes, 239 // a process called later will be first 240 241 void SetProcessOrderingToLast( 242 G4VProcess* aProcess, 243 G4ProcessVectorDoItIndex idDoIt 244 ); 245 // Set ordering parameter to the last of all processes 246 // for DoIt() specified by idDoIt. 247 // Note: If you use this method for two processes, 248 // a process called later will precede. 249 250 /////////////////////////////////////////////// 251 252 G4VProcess* RemoveProcess(G4VProcess* aProcess); 253 G4VProcess* RemoveProcess(G4int index); 254 // Removes a process from the process List. 255 // Returns pointer to the removed process. 256 // (nullptr value will be returned in case of errors) 257 258 G4VProcess* SetProcessActivation(G4VProcess* aProcess, G4bool fActive); 259 G4VProcess* SetProcessActivation(G4int index, G4bool fActive); 260 // Set activation flag. 261 // Returns pointer to the applied process. 262 // (nullptr value will be returned in case of errors) 263 264 G4bool GetProcessActivation(G4VProcess* aProcess) const; 265 G4bool GetProcessActivation(G4int index) const; 266 // Get activation flag. 267 268 inline G4ParticleDefinition* GetParticleType() const; 269 // Get the particle type 270 inline void SetParticleType(const G4ParticleDefinition*); 271 // Set the particle type 272 273 G4VProcess* GetProcess (const G4String&) const; 274 // Get process by process name 275 276 void StartTracking(G4Track* aTrack = nullptr); 277 void EndTracking(); 278 // These two methods are used by G4TrackingManager 279 // in order to inform Start/End of tracking for each track 280 // to the process manager and all physics processes 281 282 void DumpInfo(); 283 284 inline void SetVerboseLevel(G4int value); 285 inline G4int GetVerboseLevel() const; 286 // Control flag for output message 287 // 0: Silent 288 // 1: Warning message 289 // 2: More 290 291 enum {SizeOfProcVectorArray = 6}; 292 293 private: 294 295 G4int InsertAt(G4int position, G4VProcess* process, G4int ivec); 296 // Insert process at position in theProcVector[ivec] 297 298 G4int RemoveAt(G4int position, G4VProcess* process, G4int ivec); 299 // Remove process at position in theProcVector[ivec] 300 301 G4int FindInsertPosition(G4int ord, G4int ivec); 302 // Find insert position according to ordering parameter 303 // in theProcVector[ivec] 304 305 inline G4int GetProcessVectorId(G4ProcessVectorDoItIndex idx, 306 G4ProcessVectorTypeIndex typ = typeGPIL) const; 307 308 void CheckOrderingParameters(G4VProcess*) const; 309 // Check consistencies between ordering parameters and 310 // validity of DoIt() of the Process 311 312 G4ProcessAttribute* GetAttribute(G4int index) const; 313 G4ProcessAttribute* GetAttribute(G4VProcess* aProcess) const; 314 // Get Pointer to ProcessAttribute 315 316 void CreateGPILvectors(); 317 void SetIndexToProcessVector(G4int ivec); 318 319 G4VProcess* ActivateProcess(G4int index); 320 G4VProcess* InActivateProcess(G4int index); 321 // Activate/InActivate process 322 323 private: 324 325 G4ProcessVector* theProcVector[SizeOfProcVectorArray]; 326 // Vector for processes with GetPhysicalInteractionLength()/DoIt() 327 328 G4ProcessAttrVector* theAttrVector = nullptr; 329 // Vector for process attribute 330 331 const G4ParticleDefinition* theParticleType = nullptr; 332 // Particle which has this process manager object 333 334 G4int numberOfProcesses = 0; 335 G4ProcessVector* theProcessList = nullptr; 336 // Vector for all processes (called as "process List") 337 338 G4bool duringTracking = false; 339 340 G4bool isSetOrderingFirstInvoked[NDoit]; 341 G4bool isSetOrderingLastInvoked[NDoit]; 342 343 G4int verboseLevel = 1; 344 345 static G4ThreadLocal G4ProcessManagerMessenger* fProcessManagerMessenger; 346 static G4ThreadLocal G4int counterOfObjects; 347 }; 348 349 #include "G4ProcessManager.icc" 350 351 #endif 352