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 // G4ProcessPlacer 27 // -------------------------------------------------------------------- 28 29 #include "G4ProcessPlacer.hh" 30 #include "G4ProcessManager.hh" 31 #include "G4VProcess.hh" 32 #include "G4ParticleTable.hh" 33 34 G4ProcessPlacer::G4ProcessPlacer(const G4String& particlename) 35 : fParticleName(particlename) 36 { 37 } 38 39 G4ProcessPlacer::~G4ProcessPlacer() 40 { 41 } 42 43 void G4ProcessPlacer::RemoveProcess(G4VProcess* process) 44 { 45 G4cout << "=== G4ProcessPlacer::RemoveProcess: for: " << fParticleName 46 << G4endl; 47 G4cout << " ProcessName: " << process->GetProcessName() 48 << ", will be removed!" << G4endl; 49 50 G4cout << " The initial AlongStep Vectors: " << G4endl; 51 PrintAlongStepGPILVec(); 52 PrintAlongStepDoItVec(); 53 54 G4cout << " The initial PostStep Vectors: " << G4endl; 55 PrintPostStepGPILVec(); 56 PrintPostStepDoItVec(); 57 58 GetProcessManager()->RemoveProcess(process); 59 60 G4cout << " The final AlongStep Vectors: " << G4endl; 61 PrintAlongStepGPILVec(); 62 PrintAlongStepDoItVec(); 63 64 G4cout << " The final PostStep Vectors: " << G4endl; 65 PrintPostStepGPILVec(); 66 PrintPostStepDoItVec(); 67 68 G4cout << "================================================" << G4endl; 69 70 } 71 72 void G4ProcessPlacer::AddProcessAs(G4VProcess* process, SecondOrLast sol) 73 { 74 G4cout << " Modifying Process Order for ProcessName: " << process->GetProcessName() << G4endl; 75 76 G4cout << " The initial AlongStep Vectors: " << G4endl; 77 PrintAlongStepGPILVec(); 78 PrintAlongStepDoItVec(); 79 80 G4cout << "The initial PostStep Vectors: " << G4endl; 81 PrintPostStepGPILVec(); 82 PrintPostStepDoItVec(); 83 84 if (sol == eLast) 85 { 86 GetProcessManager()->AddProcess(process, ordInActive, ordInActive, ordLast); 87 } 88 else if (sol == eSecond) 89 { 90 // get transportation process 91 G4VProcess *transportation = 92 (* (GetProcessManager()->GetProcessList()))[0]; 93 94 if (!transportation) 95 { 96 G4Exception("G4ProcessPlacer::AddProcessAs","Bias0001",RunMustBeAborted," could not get process id=0"); 97 } 98 if (transportation->GetProcessName() != "Transportation" && transportation->GetProcessName() != "Transportation8" && transportation->GetProcessName() != "CoupledTransportation") 99 { 100 // G4cout << " GOT HERE CoupledTransportation" << G4endl; 101 G4cout << transportation->GetProcessName() << G4endl; 102 G4Exception("G4ProcessPlacer::AddProcessAs","Bias0002",RunMustBeAborted," process id=0 is not Transportation"); 103 } 104 105 // place the given proces as first for the moment 106 // 31/5/11 previously set to first, then transportation set ahead of it, 107 // which is more conveniently correctly set with placing it second! 108 GetProcessManager()->AddProcess(process); 109 GetProcessManager()->SetProcessOrderingToSecond(process, 110 idxAlongStep); 111 GetProcessManager()->SetProcessOrderingToSecond(process, 112 idxPostStep); 113 } 114 115 // for verification inly 116 G4cout << " The final AlongStep Vectors: " << G4endl; 117 PrintAlongStepGPILVec(); 118 PrintAlongStepDoItVec(); 119 120 G4cout << "The final PostStep Vectors: " << G4endl; 121 PrintPostStepGPILVec(); 122 PrintPostStepDoItVec(); 123 124 G4cout << "================================================" << G4endl; 125 } 126 127 void G4ProcessPlacer::AddProcessAsSecondDoIt(G4VProcess* process) 128 { 129 G4cout << "=== G4ProcessPlacer::AddProcessAsSecondDoIt: for: " 130 << fParticleName << G4endl; 131 AddProcessAs(process, eSecond); 132 } 133 134 void G4ProcessPlacer::AddProcessAsLastDoIt(G4VProcess* process) 135 { 136 G4cout << "=== G4ProcessPlacer::AddProcessAsLastDoIt: for: " 137 << fParticleName << G4endl; 138 AddProcessAs(process, eLast); 139 } 140 141 G4ProcessManager* G4ProcessPlacer::GetProcessManager() 142 { 143 // get particle iterator to add processes --------------------- 144 G4ParticleTable* theParticleTable = nullptr; 145 G4ParticleTable::G4PTblDicIterator* theParticleIterator = nullptr; 146 theParticleTable = G4ParticleTable::GetParticleTable(); 147 theParticleIterator = theParticleTable->GetIterator(); 148 // ------------------------------------------------------- 149 G4ProcessManager* processmanager = nullptr; 150 // find process manager --------------------------- 151 theParticleIterator->reset(); 152 while( (*theParticleIterator)() ) /* while checked for unending loop, 30.05.2016, Marc Verderi */ 153 { 154 G4ParticleDefinition* particle = theParticleIterator->value(); 155 if (particle->GetParticleName() == fParticleName) 156 { 157 processmanager = particle->GetProcessManager(); 158 break; 159 } 160 } 161 // --------------------------------------------------------- 162 if (!processmanager) 163 { 164 G4Exception("G4ProcessPlacer::GetProcessManager()", "InvalidSetup", 165 FatalException, "NULL pointer to Process Manager ! Sampler.Configure() must be after PhysicsList instantiation"); 166 } 167 return processmanager; 168 } 169 170 void G4ProcessPlacer::PrintAlongStepGPILVec() 171 { 172 G4cout << "GPIL Vector: " << G4endl; 173 G4ProcessVector* processGPILVec = 174 GetProcessManager()->GetAlongStepProcessVector(typeGPIL); 175 PrintProcVec(processGPILVec); 176 } 177 178 void G4ProcessPlacer::PrintAlongStepDoItVec() 179 { 180 G4cout << "DoIt Vector: " << G4endl; 181 G4ProcessVector* processDoItVec = 182 GetProcessManager()->GetAlongStepProcessVector(typeDoIt); 183 PrintProcVec(processDoItVec); 184 } 185 186 187 void G4ProcessPlacer::PrintPostStepGPILVec() 188 { 189 G4cout << "GPIL Vector: " << G4endl; 190 G4ProcessVector* processGPILVec = 191 GetProcessManager()->GetPostStepProcessVector(typeGPIL); 192 PrintProcVec(processGPILVec); 193 } 194 195 void G4ProcessPlacer::PrintPostStepDoItVec() 196 { 197 G4cout << "DoIt Vector: " << G4endl; 198 G4ProcessVector* processDoItVec = 199 GetProcessManager()->GetPostStepProcessVector(typeDoIt); 200 PrintProcVec(processDoItVec); 201 } 202 203 204 void G4ProcessPlacer::PrintProcVec(G4ProcessVector* processVec) 205 { 206 if (!processVec) 207 { 208 G4Exception("G4ProcessPlacer::G4ProcessPlacer()", "InvalidArgument", 209 FatalException, "NULL pointer to process-vector !"); 210 } 211 G4int len = (G4int)processVec->length(); 212 if (len==0) 213 { 214 G4Exception("G4ProcessPlacer::G4ProcessPlacer()", "InvalidSetup", 215 FatalException, "Length of process-vector is zero !"); 216 } 217 for (G4int i=0; i<len; ++i) 218 { 219 G4VProcess *p = (*processVec)[i]; 220 if (p) 221 { 222 G4cout << " " << p->GetProcessName() << G4endl; 223 } 224 else 225 { 226 G4cout << " " << "no process found for position: " << i 227 << ", in vector of length: " << len << G4endl; 228 } 229 } 230 } 231