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 // 27 // ------------------------------------------------------------------- 28 // 29 // GEANT4 Class 30 // 31 // File name: G4EmConfigurator 32 // 33 // Author: Vladimir Ivanchenko 34 // 35 // Creation date: 14.07.2008 36 // 37 // Modifications: 38 // 39 // Class Description: 40 // 41 // This class provides configuration EM models for 42 // particles/processes/regions 43 // 44 45 // ------------------------------------------------------------------- 46 // 47 48 #include "G4EmConfigurator.hh" 49 #include "G4EmUtility.hh" 50 #include "G4SystemOfUnits.hh" 51 #include "G4ParticleTable.hh" 52 #include "G4ParticleDefinition.hh" 53 #include "G4ProcessManager.hh" 54 #include "G4VProcess.hh" 55 #include "G4ProcessVector.hh" 56 #include "G4RegionStore.hh" 57 #include "G4Region.hh" 58 #include "G4DummyModel.hh" 59 #include "G4VEnergyLossProcess.hh" 60 #include "G4VEmProcess.hh" 61 #include "G4VMultipleScattering.hh" 62 #include "G4TransportationWithMsc.hh" 63 64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 65 66 G4EmConfigurator::G4EmConfigurator(G4int val):verbose(val) 67 { 68 index = -10; 69 } 70 71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 72 73 G4EmConfigurator::~G4EmConfigurator() = default; 74 75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 76 77 void G4EmConfigurator::SetExtraEmModel(const G4String& particleName, 78 const G4String& processName, 79 G4VEmModel* mod, 80 const G4String& regionName, 81 G4double emin, 82 G4double emax, 83 G4VEmFluctuationModel* fm) 84 { 85 if(nullptr == mod) { return; } 86 if(1 < verbose) { 87 G4cout << " G4EmConfigurator::SetExtraEmModel " << mod->GetName() 88 << " for " << particleName 89 << " and " << processName 90 << " in the region <" << regionName 91 << "> Emin(MeV)= " << emin/MeV 92 << " Emax(MeV)= " << emax/MeV 93 << G4endl; 94 } 95 96 models.push_back(mod); 97 flucModels.push_back(fm); 98 G4double emin0 = std::max(emin, mod->LowEnergyLimit()); 99 G4double emax0 = std::min(emax, mod->HighEnergyLimit()); 100 mod->SetActivationHighEnergyLimit(emax0); 101 102 particles.push_back(particleName); 103 processes.push_back(processName); 104 regions.push_back(regionName); 105 lowEnergy.push_back(emin0); 106 highEnergy.push_back(emax0); 107 } 108 109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 110 111 void G4EmConfigurator::AddModels() 112 { 113 size_t n = models.size(); 114 if(1 < verbose) { 115 G4cout << "### G4EmConfigurator::AddModels n= " << n << G4endl; 116 } 117 if(n > 0) { 118 for(size_t i=0; i<n; ++i) { 119 if(nullptr != models[i]) { 120 const G4Region* reg = G4EmUtility::FindRegion(regions[i]); 121 if(nullptr != reg) { 122 --index; 123 SetModelForRegion(models[i],flucModels[i],reg, 124 particles[i],processes[i], 125 lowEnergy[i],highEnergy[i]); 126 } 127 } 128 } 129 } 130 Clear(); 131 } 132 133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 134 135 void G4EmConfigurator::SetModelForRegion(G4VEmModel* mod, 136 G4VEmFluctuationModel* fm, 137 const G4Region* reg, 138 const G4String& particleName, 139 const G4String& processName, 140 G4double emin, G4double emax) 141 { 142 if(nullptr == mod) { return; } 143 if(1 < verbose) { 144 G4cout << " G4EmConfigurator::SetModelForRegion: " << mod->GetName() 145 << G4endl; 146 G4cout << " For " << particleName 147 << " and " << processName 148 << " in the region <" << reg->GetName() 149 << " Emin(MeV)= " << emin/MeV 150 << " Emax(MeV)= " << emax/MeV; 151 if(nullptr != fm) { G4cout << " FLmodel " << fm->GetName(); } 152 G4cout << G4endl; 153 } 154 155 // Loop checking, 03-Aug-2015, Vladimir Ivanchenko 156 auto myParticleIterator = G4ParticleTable::GetParticleTable()->GetIterator(); 157 myParticleIterator->reset(); 158 while( (*myParticleIterator)() ) { 159 const G4ParticleDefinition* part = myParticleIterator->value(); 160 161 if((part->GetParticleName() == particleName) || 162 (particleName == "all") || 163 (particleName == "charged" && part->GetPDGCharge() != 0.0)) { 164 165 // search for process 166 G4ProcessManager* pmanager = part->GetProcessManager(); 167 G4ProcessVector* plist = pmanager->GetProcessList(); 168 G4int np = pmanager->GetProcessListLength(); 169 170 if(1 < verbose) { 171 G4cout << "Check process <" << processName << "> for " << particleName << " in list of " 172 << np << " processes" << G4endl; 173 } 174 G4VProcess* proc = nullptr; 175 for(G4int i=0; i<np; ++i) { 176 if(processName == (*plist)[i]->GetProcessName()) { 177 proc = (*plist)[i]; 178 break; 179 } 180 } 181 if(nullptr == proc) { 182 if(processName == "msc") { 183 for (G4int i = 0; i < np; ++i) { 184 auto* trans = dynamic_cast<G4TransportationWithMsc*>((*plist)[i]); 185 if (nullptr != trans) { 186 G4cout << "G4TransportationWithMsc is found out!" << G4endl; 187 proc = trans; 188 break; 189 } 190 } 191 } 192 if (nullptr == proc) { 193 if (0 < verbose) { 194 G4cout << "### G4EmConfigurator WARNING: fails to find a process <" << processName 195 << "> for " << particleName << G4endl; 196 } 197 return; 198 } 199 } 200 201 if(!UpdateModelEnergyRange(mod, emin, emax)) { return; } 202 // classify process 203 G4int ii = proc->GetProcessSubType(); 204 auto msc = dynamic_cast<G4VMscModel*>(mod); 205 if (nullptr != msc) { 206 if (auto* trans = dynamic_cast<G4TransportationWithMsc*>(proc)) { 207 trans->AddMscModel(msc, index, reg); 208 if (1 < verbose) { 209 G4cout << "### Added msc model order= " << index << " for " << particleName << " and " 210 << proc->GetProcessName() << G4endl; 211 } 212 } 213 else if (10 == ii) { 214 auto p = dynamic_cast<G4VMultipleScattering*>(proc); 215 if (nullptr != p) { 216 p->AddEmModel(index, msc, reg); 217 if (1 < verbose) { 218 G4cout << "### Added msc model order= " << index << " for " << particleName << " and " 219 << processName << G4endl; 220 } 221 } 222 } 223 else { 224 G4cout << "### Unable to add msc model for " << particleName << " and " << processName 225 << G4endl; 226 } 227 } 228 else if (2 <= ii && 4 >= ii) { 229 auto p = dynamic_cast<G4VEnergyLossProcess*>(proc); 230 if (nullptr != p) { 231 p->AddEmModel(index, mod, fm, reg); 232 if (1 < verbose) { 233 G4cout << "### Added eloss model order= " << index << " for " << particleName << " and " 234 << processName << G4endl; 235 } 236 } 237 } 238 else { 239 auto p = dynamic_cast<G4VEmProcess*>(proc); 240 if (nullptr != p) { 241 p->AddEmModel(index, mod, reg); 242 if (1 < verbose) { 243 G4cout << "### Added em model order= " << index << " for " << particleName << " and " 244 << processName << G4endl; 245 } 246 } 247 else { 248 G4cout << "### Unable to add em model for " << particleName << " and " << processName 249 << G4endl; 250 } 251 } 252 return; 253 } 254 } 255 } 256 257 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 258 259 void 260 G4EmConfigurator::PrepareModels(const G4ParticleDefinition* aParticle, 261 G4VEnergyLossProcess* p) 262 { 263 size_t n = particles.size(); 264 if(1 < verbose) { 265 G4cout << " G4EmConfigurator::PrepareModels for EnergyLoss n= " 266 << n << G4endl; 267 } 268 if(n > 0) { 269 G4String particleName = aParticle->GetParticleName(); 270 G4String processName = p->GetProcessName(); 271 //G4cout << particleName << " " << processName << G4endl; 272 for(size_t i=0; i<n; ++i) { 273 //G4cout << particles[i] << " " << processes[i] << G4endl; 274 if(processName == processes[i]) { 275 if((particleName == particles[i]) || 276 (particles[i] == "all") || 277 (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) { 278 const G4Region* reg = G4EmUtility::FindRegion(regions[i]); 279 //G4cout << "Region " << reg << G4endl; 280 if(nullptr != reg) { 281 --index; 282 G4VEmModel* mod = models[i]; 283 G4VEmFluctuationModel* fm = flucModels[i]; 284 if(nullptr != mod) { 285 if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) { 286 p->AddEmModel(index,mod,fm,reg); 287 if(1 < verbose) { 288 G4cout << "### Added eloss model order= " << index << " for " << particleName 289 << " and " << processName << " for " << reg->GetName() << G4endl; 290 } 291 } 292 } else if(nullptr != fm) { 293 p->SetFluctModel(fm); 294 } 295 } 296 } 297 } 298 } 299 } 300 } 301 302 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 303 304 void 305 G4EmConfigurator::PrepareModels(const G4ParticleDefinition* aParticle, 306 G4VEmProcess* p) 307 { 308 size_t n = particles.size(); 309 if(1 < verbose) { 310 G4cout << " G4EmConfigurator::PrepareModels for EM process n= " 311 << n << G4endl; 312 } 313 if(n > 0) { 314 G4String particleName = aParticle->GetParticleName(); 315 G4String processName = p->GetProcessName(); 316 //G4cout << particleName << " " << particleName << G4endl; 317 for(size_t i=0; i<n; ++i) { 318 if(processName == processes[i]) { 319 if((particleName == particles[i]) || 320 (particles[i] == "all") || 321 (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) { 322 const G4Region* reg = G4EmUtility::FindRegion(regions[i]); 323 //G4cout << "Region " << reg << G4endl; 324 if(nullptr != reg) { 325 --index; 326 G4VEmModel* mod = models[i]; 327 if(nullptr != mod) { 328 if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) { 329 p->AddEmModel(index,mod,reg); 330 if(1 < verbose) { 331 G4cout << "### Added em model order= " << index << " for " 332 << particleName << " and " << processName << G4endl; 333 } 334 } 335 } 336 } 337 } 338 } 339 } 340 } 341 } 342 343 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 344 345 void 346 G4EmConfigurator::PrepareModels(const G4ParticleDefinition* aParticle, 347 G4VMultipleScattering* p, 348 G4TransportationWithMsc* trans) 349 { 350 size_t n = particles.size(); 351 if(1 < verbose) { 352 G4cout << " G4EmConfigurator::PrepareModels for MSC process n= " 353 << n << G4endl; 354 } 355 356 if(n > 0) { 357 G4String particleName = aParticle->GetParticleName(); 358 G4String processName = (nullptr == p) ? G4String("msc") : p->GetProcessName(); 359 for(size_t i=0; i<n; ++i) { 360 if(processName == processes[i]) { 361 if ((particleName == particles[i]) || (particles[i] == "all") 362 || (particles[i] == "charged" && aParticle->GetPDGCharge() != 0.0)) 363 { 364 const G4Region* reg = G4EmUtility::FindRegion(regions[i]); 365 if (nullptr != reg) { 366 --index; 367 auto mod = dynamic_cast<G4VMscModel*>(models[i]); 368 if(nullptr != mod) { 369 if(UpdateModelEnergyRange(mod, lowEnergy[i], highEnergy[i])) { 370 if(nullptr != p) { 371 p->AddEmModel(index, mod, reg); 372 } 373 else { 374 trans->AddMscModel(mod, index, reg); 375 } 376 //G4cout << "### Added msc model order= " << index << " for " 377 // << particleName << " and " << processName << G4endl; 378 } 379 } 380 } 381 } 382 } 383 } 384 } 385 } 386 387 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 388 389 void G4EmConfigurator::Clear() 390 { 391 particles.clear(); 392 processes.clear(); 393 models.clear(); 394 flucModels.clear(); 395 regions.clear(); 396 lowEnergy.clear(); 397 highEnergy.clear(); 398 } 399 400 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 401 402 G4bool G4EmConfigurator::UpdateModelEnergyRange(G4VEmModel* mod, 403 G4double emin, G4double emax) 404 { 405 // energy limits 406 G4double e1 = std::max(emin,mod->LowEnergyLimit()); 407 G4double e2 = std::min(emax,mod->HighEnergyLimit()); 408 if(e2 <= e1) { 409 G4cout << "### G4EmConfigurator WARNING: empty energy interval" 410 << " for <" << mod->GetName() 411 << "> Emin(MeV)= " << e1/CLHEP::MeV 412 << "> Emax(MeV)= " << e2/CLHEP::MeV 413 << G4endl; 414 return false; 415 } 416 mod->SetLowEnergyLimit(e1); 417 mod->SetHighEnergyLimit(e2); 418 if(verbose > 1) { 419 G4cout << "### G4EmConfigurator for " << mod->GetName() 420 << " Emin(MeV)= " << e1/MeV << " Emax(MeV)= " << e2/MeV 421 << G4endl; 422 } 423 return true; 424 } 425 426 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 427