Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // $Id: G4EmCalculator.cc 93291 2015-10-15 10:04:27Z gcosmo $ 26 // 27 // 27 // ------------------------------------------- 28 // ------------------------------------------------------------------- 28 // 29 // 29 // GEANT4 Class file 30 // GEANT4 Class file 30 // 31 // 31 // 32 // 32 // File name: G4EmCalculator 33 // File name: G4EmCalculator 33 // 34 // 34 // Author: Vladimir Ivanchenko 35 // Author: Vladimir Ivanchenko 35 // 36 // 36 // Creation date: 28.06.2004 37 // Creation date: 28.06.2004 37 // 38 // >> 39 // Modifications: >> 40 // 12.09.2004 Add verbosity (V.Ivanchenko) >> 41 // 17.11.2004 Change signature of methods, add new methods (V.Ivanchenko) >> 42 // 08.04.2005 Major optimisation of internal interfaces (V.Ivantchenko) >> 43 // 08.05.2005 Use updated interfaces (V.Ivantchenko) >> 44 // 23.10.2005 Fix computations for ions (V.Ivantchenko) >> 45 // 11.01.2006 Add GetCSDARange (V.Ivantchenko) >> 46 // 26.01.2006 Rename GetRange -> GetRangeFromRestricteDEDX (V.Ivanchenko) >> 47 // 14.03.2006 correction in GetCrossSectionPerVolume (mma) >> 48 // suppress GetCrossSectionPerAtom >> 49 // elm->GetA() in ComputeCrossSectionPerAtom >> 50 // 22.03.2006 Add ComputeElectronicDEDX and ComputeTotalDEDX (V.Ivanchenko) >> 51 // 13.05.2006 Add Corrections for ion stopping (V.Ivanchenko) >> 52 // 29.09.2006 Uncomment computation of smoothing factor (V.Ivanchenko) >> 53 // 27.10.2006 Change test energy to access lowEnergy model from >> 54 // 10 keV to 1 keV (V. Ivanchenko) >> 55 // 15.03.2007 Add ComputeEnergyCutFromRangeCut methods (V.Ivanchenko) >> 56 // 21.04.2008 Updated computations for ions (V.Ivanchenko) 38 // 57 // 39 // Class Description: V.Ivanchenko & M.Novak << 58 // Class Description: 40 // 59 // 41 // ------------------------------------------- 60 // ------------------------------------------------------------------- 42 // 61 // 43 //....oooOO0OOooo........oooOO0OOooo........oo 62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 44 //....oooOO0OOooo........oooOO0OOooo........oo 63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 45 64 46 #include "G4EmCalculator.hh" 65 #include "G4EmCalculator.hh" 47 #include "G4SystemOfUnits.hh" 66 #include "G4SystemOfUnits.hh" 48 #include "G4LossTableManager.hh" 67 #include "G4LossTableManager.hh" 49 #include "G4EmParameters.hh" << 50 #include "G4NistManager.hh" 68 #include "G4NistManager.hh" 51 #include "G4DynamicParticle.hh" << 52 #include "G4VEmProcess.hh" 69 #include "G4VEmProcess.hh" 53 #include "G4VEnergyLossProcess.hh" 70 #include "G4VEnergyLossProcess.hh" 54 #include "G4VMultipleScattering.hh" 71 #include "G4VMultipleScattering.hh" 55 #include "G4Material.hh" 72 #include "G4Material.hh" 56 #include "G4MaterialCutsCouple.hh" 73 #include "G4MaterialCutsCouple.hh" 57 #include "G4ParticleDefinition.hh" 74 #include "G4ParticleDefinition.hh" 58 #include "G4ParticleTable.hh" 75 #include "G4ParticleTable.hh" 59 #include "G4IonTable.hh" 76 #include "G4IonTable.hh" 60 #include "G4PhysicsTable.hh" 77 #include "G4PhysicsTable.hh" 61 #include "G4ProductionCutsTable.hh" 78 #include "G4ProductionCutsTable.hh" 62 #include "G4ProcessManager.hh" 79 #include "G4ProcessManager.hh" 63 #include "G4ionEffectiveCharge.hh" 80 #include "G4ionEffectiveCharge.hh" 64 #include "G4RegionStore.hh" 81 #include "G4RegionStore.hh" 65 #include "G4Element.hh" 82 #include "G4Element.hh" 66 #include "G4EmCorrections.hh" 83 #include "G4EmCorrections.hh" 67 #include "G4GenericIon.hh" 84 #include "G4GenericIon.hh" 68 #include "G4ProcessVector.hh" 85 #include "G4ProcessVector.hh" 69 #include "G4Gamma.hh" 86 #include "G4Gamma.hh" 70 #include "G4Electron.hh" 87 #include "G4Electron.hh" 71 #include "G4Positron.hh" 88 #include "G4Positron.hh" 72 #include "G4EmUtility.hh" << 73 89 74 //....oooOO0OOooo........oooOO0OOooo........oo 90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 75 91 76 G4EmCalculator::G4EmCalculator() 92 G4EmCalculator::G4EmCalculator() 77 { 93 { 78 manager = G4LossTableManager::Instance(); 94 manager = G4LossTableManager::Instance(); 79 nist = G4NistManager::Instance(); 95 nist = G4NistManager::Instance(); 80 theParameters = G4EmParameters::Instance(); << 81 corr = manager->EmCorrections(); 96 corr = manager->EmCorrections(); 82 cutenergy[0] = cutenergy[1] = cutenergy[2] = << 97 nLocalMaterials = 0; 83 theGenericIon = G4GenericIon::GenericIon(); << 98 verbose = 0; 84 ionEffCharge = new G4ionEffectiveCharge(); << 99 currentCoupleIndex = 0; 85 dynParticle = new G4DynamicParticle(); << 100 currentCouple = nullptr; 86 ionTable = G4ParticleTable::GetParticle << 101 currentMaterial = cutMaterial = nullptr; >> 102 currentParticle = nullptr; >> 103 lambdaParticle = nullptr; >> 104 baseParticle = nullptr; >> 105 currentLambda = nullptr; >> 106 currentModel = nullptr; >> 107 currentProcess = nullptr; >> 108 loweModel = nullptr; >> 109 chargeSquare = 1.0; >> 110 massRatio = 1.0; >> 111 mass = 0.0; >> 112 currentCut = 0.0; >> 113 cutenergy[0] = cutenergy[1] = cutenergy[2] = DBL_MAX; >> 114 currentParticleName= ""; >> 115 currentMaterialName= ""; >> 116 currentName = ""; >> 117 lambdaName = ""; >> 118 theGenericIon = G4GenericIon::GenericIon(); >> 119 ionEffCharge = new G4ionEffectiveCharge(); >> 120 ionTable = G4ParticleTable::GetParticleTable()->GetIonTable(); >> 121 isIon = false; >> 122 isApplicable = false; 87 } 123 } 88 124 89 //....oooOO0OOooo........oooOO0OOooo........oo 125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 90 126 91 G4EmCalculator::~G4EmCalculator() 127 G4EmCalculator::~G4EmCalculator() 92 { 128 { 93 delete ionEffCharge; 129 delete ionEffCharge; 94 delete dynParticle; << 95 for (G4int i=0; i<nLocalMaterials; ++i) { 130 for (G4int i=0; i<nLocalMaterials; ++i) { 96 delete localCouples[i]; 131 delete localCouples[i]; 97 } 132 } 98 } 133 } 99 134 100 //....oooOO0OOooo........oooOO0OOooo........oo 135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 101 136 102 G4double G4EmCalculator::GetDEDX(G4double kinE 137 G4double G4EmCalculator::GetDEDX(G4double kinEnergy, 103 const G4Parti 138 const G4ParticleDefinition* p, 104 const G4Mater 139 const G4Material* mat, 105 const G4Regio 140 const G4Region* region) 106 { 141 { 107 G4double res = 0.0; 142 G4double res = 0.0; 108 const G4MaterialCutsCouple* couple = FindCou 143 const G4MaterialCutsCouple* couple = FindCouple(mat, region); 109 if(nullptr != couple && UpdateParticle(p, ki << 144 if(couple && UpdateParticle(p, kinEnergy) ) { 110 res = manager->GetDEDX(p, kinEnergy, coupl 145 res = manager->GetDEDX(p, kinEnergy, couple); 111 146 112 if(isIon) { 147 if(isIon) { 113 if(FindEmModel(p, currentProcessName, ki 148 if(FindEmModel(p, currentProcessName, kinEnergy)) { 114 G4double length = CLHEP::nm; 149 G4double length = CLHEP::nm; 115 G4double eloss = res*length; 150 G4double eloss = res*length; 116 //G4cout << "### GetDEDX: E= " << kinE 151 //G4cout << "### GetDEDX: E= " << kinEnergy << " dedx0= " << res 117 // << " de= " << eloss << G4endl 152 // << " de= " << eloss << G4endl;; 118 dynParticle->SetKineticEnergy(kinEnerg << 153 G4double niel = 0.0; >> 154 dynParticle.SetKineticEnergy(kinEnergy); 119 currentModel->GetChargeSquareRatio(p, 155 currentModel->GetChargeSquareRatio(p, mat, kinEnergy); 120 currentModel->CorrectionsAlongStep(cou << 156 currentModel->CorrectionsAlongStep(couple,&dynParticle,eloss,niel,length); 121 res = eloss/length; 157 res = eloss/length; 122 //G4cout << " de1= " << eloss << 158 //G4cout << " de1= " << eloss << " res1= " << res 123 // << " " << p->GetParticleName( 159 // << " " << p->GetParticleName() <<G4endl;; 124 } 160 } 125 } 161 } 126 162 127 if(verbose>0) { 163 if(verbose>0) { 128 G4cout << "G4EmCalculator::GetDEDX: E(Me 164 G4cout << "G4EmCalculator::GetDEDX: E(MeV)= " << kinEnergy/MeV 129 << " DEDX(MeV/mm)= " << res*mm/Me 165 << " DEDX(MeV/mm)= " << res*mm/MeV 130 << " DEDX(MeV*cm^2/g)= " << res*g 166 << " DEDX(MeV*cm^2/g)= " << res*gram/(MeV*cm2*mat->GetDensity()) 131 << " " << p->GetParticleName() 167 << " " << p->GetParticleName() 132 << " in " << mat->GetName() 168 << " in " << mat->GetName() 133 << " isIon= " << isIon 169 << " isIon= " << isIon 134 << G4endl; 170 << G4endl; 135 } 171 } 136 } 172 } 137 return res; 173 return res; 138 } 174 } 139 175 140 //....oooOO0OOooo........oooOO0OOooo........oo 176 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 141 177 142 G4double G4EmCalculator::GetRangeFromRestricte 178 G4double G4EmCalculator::GetRangeFromRestricteDEDX(G4double kinEnergy, 143 179 const G4ParticleDefinition* p, 144 180 const G4Material* mat, 145 181 const G4Region* region) 146 { 182 { 147 G4double res = 0.0; 183 G4double res = 0.0; 148 const G4MaterialCutsCouple* couple = FindCou 184 const G4MaterialCutsCouple* couple = FindCouple(mat,region); 149 if(couple && UpdateParticle(p, kinEnergy)) { 185 if(couple && UpdateParticle(p, kinEnergy)) { 150 res = manager->GetRangeFromRestricteDEDX(p 186 res = manager->GetRangeFromRestricteDEDX(p, kinEnergy, couple); 151 if(verbose>1) { << 187 if(verbose>0) { 152 G4cout << " G4EmCalculator::GetRangeFrom << 188 G4cout << "G4EmCalculator::GetRange: E(MeV)= " << kinEnergy/MeV 153 << kinEnergy/MeV << 154 << " range(mm)= " << res/mm 189 << " range(mm)= " << res/mm 155 << " " << p->GetParticleName() 190 << " " << p->GetParticleName() 156 << " in " << mat->GetName() 191 << " in " << mat->GetName() 157 << G4endl; 192 << G4endl; 158 } 193 } 159 } 194 } 160 return res; 195 return res; 161 } 196 } 162 197 163 //....oooOO0OOooo........oooOO0OOooo........oo 198 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 164 199 165 G4double G4EmCalculator::GetCSDARange(G4double 200 G4double G4EmCalculator::GetCSDARange(G4double kinEnergy, 166 const G4 201 const G4ParticleDefinition* p, 167 const G4 202 const G4Material* mat, 168 const G4 203 const G4Region* region) 169 { 204 { 170 G4double res = 0.0; 205 G4double res = 0.0; 171 if(!theParameters->BuildCSDARange()) { << 206 if(!G4LossTableManager::Instance()->BuildCSDARange()) { 172 G4ExceptionDescription ed; 207 G4ExceptionDescription ed; 173 ed << "G4EmCalculator::GetCSDARange: CSDA 208 ed << "G4EmCalculator::GetCSDARange: CSDA table is not built; " 174 << " use UI command: /process/eLoss/CSD 209 << " use UI command: /process/eLoss/CSDARange true"; 175 G4Exception("G4EmCalculator::GetCSDARange" 210 G4Exception("G4EmCalculator::GetCSDARange", "em0077", 176 JustWarning, ed); 211 JustWarning, ed); 177 return res; 212 return res; 178 } 213 } 179 214 180 const G4MaterialCutsCouple* couple = FindCou 215 const G4MaterialCutsCouple* couple = FindCouple(mat,region); 181 if(nullptr != couple && UpdateParticle(p, ki << 216 if(couple && UpdateParticle(p, kinEnergy)) { 182 res = manager->GetCSDARange(p, kinEnergy, 217 res = manager->GetCSDARange(p, kinEnergy, couple); 183 if(verbose>1) { << 218 if(verbose>0) { 184 G4cout << " G4EmCalculator::GetCSDARange << 219 G4cout << "G4EmCalculator::GetRange: E(MeV)= " << kinEnergy/MeV 185 << " range(mm)= " << res/mm 220 << " range(mm)= " << res/mm 186 << " " << p->GetParticleName() 221 << " " << p->GetParticleName() 187 << " in " << mat->GetName() 222 << " in " << mat->GetName() 188 << G4endl; 223 << G4endl; 189 } 224 } 190 } 225 } 191 return res; 226 return res; 192 } 227 } 193 228 194 //....oooOO0OOooo........oooOO0OOooo........oo 229 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 195 230 196 G4double G4EmCalculator::GetRange(G4double kin 231 G4double G4EmCalculator::GetRange(G4double kinEnergy, 197 const G4Part 232 const G4ParticleDefinition* p, 198 const G4Mate 233 const G4Material* mat, 199 const G4Regi 234 const G4Region* region) 200 { 235 { 201 G4double res = 0.0; 236 G4double res = 0.0; 202 if(theParameters->BuildCSDARange()) { << 237 const G4MaterialCutsCouple* couple = FindCouple(mat,region); 203 res = GetCSDARange(kinEnergy, p, mat, regi << 238 if(couple && UpdateParticle(p, kinEnergy)) { 204 } else { << 239 res = manager->GetRange(p, kinEnergy, couple); 205 res = GetRangeFromRestricteDEDX(kinEnergy, << 240 if(verbose>0) { >> 241 G4cout << "G4EmCalculator::GetRange: E(MeV)= " << kinEnergy/MeV >> 242 << " range(mm)= " << res/mm >> 243 << " " << p->GetParticleName() >> 244 << " in " << mat->GetName() >> 245 << G4endl; >> 246 } 206 } 247 } 207 return res; 248 return res; 208 } 249 } 209 250 210 //....oooOO0OOooo........oooOO0OOooo........oo 251 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 211 252 212 G4double G4EmCalculator::GetKinEnergy(G4double 253 G4double G4EmCalculator::GetKinEnergy(G4double range, 213 const G4 254 const G4ParticleDefinition* p, 214 const G4 255 const G4Material* mat, 215 const G4 256 const G4Region* region) 216 { 257 { 217 G4double res = 0.0; 258 G4double res = 0.0; 218 const G4MaterialCutsCouple* couple = FindCou 259 const G4MaterialCutsCouple* couple = FindCouple(mat,region); 219 if(nullptr != couple && UpdateParticle(p, 1. << 260 if(couple && UpdateParticle(p, 1.0*GeV)) { 220 res = manager->GetEnergy(p, range, couple) 261 res = manager->GetEnergy(p, range, couple); 221 if(verbose>0) { 262 if(verbose>0) { 222 G4cout << "G4EmCalculator::GetKinEnergy: 263 G4cout << "G4EmCalculator::GetKinEnergy: Range(mm)= " << range/mm 223 << " KinE(MeV)= " << res/MeV 264 << " KinE(MeV)= " << res/MeV 224 << " " << p->GetParticleName() 265 << " " << p->GetParticleName() 225 << " in " << mat->GetName() 266 << " in " << mat->GetName() 226 << G4endl; 267 << G4endl; 227 } 268 } 228 } 269 } 229 return res; 270 return res; 230 } 271 } 231 272 232 //....oooOO0OOooo........oooOO0OOooo........oo 273 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 233 274 234 G4double G4EmCalculator::GetCrossSectionPerVol 275 G4double G4EmCalculator::GetCrossSectionPerVolume(G4double kinEnergy, 235 co 276 const G4ParticleDefinition* p, 236 co 277 const G4String& processName, 237 co 278 const G4Material* mat, 238 co 279 const G4Region* region) 239 { 280 { 240 G4double res = 0.0; 281 G4double res = 0.0; 241 const G4MaterialCutsCouple* couple = FindCou 282 const G4MaterialCutsCouple* couple = FindCouple(mat,region); 242 283 243 if(nullptr != couple && UpdateParticle(p, ki << 284 if(couple && UpdateParticle(p, kinEnergy)) { 244 if(FindEmModel(p, processName, kinEnergy)) << 285 G4int idx = couple->GetIndex(); 245 G4int idx = couple->GetIndex(); << 286 FindLambdaTable(p, processName, kinEnergy); 246 G4int procType = -1; << 287 247 FindLambdaTable(p, processName, kinEnerg << 288 if(currentLambda) { 248 << 289 G4double e = kinEnergy*massRatio; 249 G4VEmProcess* emproc = FindDiscreteProce << 290 res = (((*currentLambda)[idx])->Value(e))*chargeSquare; 250 if(nullptr != emproc) { << 291 } else { 251 res = emproc->GetCrossSection(kinEnergy, cou << 292 res = ComputeCrossSectionPerVolume(kinEnergy, p, processName, mat, 252 } else if(currentLambda) { << 293 kinEnergy); 253 // special tables are built for Msc mo << 254 // procType is set in FindLambdaTable << 255 if(procType==2) { << 256 auto mscM = static_cast<G4VMscModel* << 257 mscM->SetCurrentCouple(couple); << 258 G4double tr1Mfp = mscM->GetTransport << 259 if (tr1Mfp<DBL_MAX) { << 260 res = 1./tr1Mfp; << 261 } << 262 } else { << 263 G4double e = kinEnergy*massRatio; << 264 res = (((*currentLambda)[idx])->Valu << 265 } << 266 } else { << 267 res = ComputeCrossSectionPerVolume(kin << 268 } << 269 if(verbose>0) { << 270 G4cout << "G4EmCalculator::GetXSPerVol << 271 << " cross(cm-1)= " << res*cm << 272 << " " << p->GetParticleName( << 273 << " in " << mat->GetName(); << 274 if(verbose>1) << 275 G4cout << " idx= " << idx << " Esc << 276 << kinEnergy*massRatio << 277 << " q2= " << chargeSquare; << 278 G4cout << G4endl; << 279 } << 280 } 294 } >> 295 if(verbose>0) { >> 296 G4cout << "G4EmCalculator::GetXSPerVolume: E(MeV)= " << kinEnergy/MeV >> 297 << " cross(cm-1)= " << res*cm >> 298 << " " << p->GetParticleName() >> 299 << " in " << mat->GetName(); >> 300 if(verbose>1) >> 301 G4cout << " idx= " << idx << " Escaled((MeV)= " >> 302 << kinEnergy*massRatio >> 303 << " q2= " << chargeSquare; >> 304 G4cout << G4endl; >> 305 } 281 } 306 } 282 return res; 307 return res; 283 } 308 } 284 309 285 //....oooOO0OOooo........oooOO0OOooo........oo 310 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 286 311 287 G4double G4EmCalculator::GetShellIonisationCro 312 G4double G4EmCalculator::GetShellIonisationCrossSectionPerAtom( 288 const 313 const G4String& particle, 289 G4int 314 G4int Z, 290 G4Ato 315 G4AtomicShellEnumerator shell, 291 G4dou 316 G4double kinEnergy) 292 { 317 { 293 G4double res = 0.0; 318 G4double res = 0.0; 294 const G4ParticleDefinition* p = FindParticle 319 const G4ParticleDefinition* p = FindParticle(particle); 295 G4VAtomDeexcitation* ad = manager->AtomDeexc 320 G4VAtomDeexcitation* ad = manager->AtomDeexcitation(); 296 if(nullptr != p && nullptr != ad) { << 321 if(p && ad) { 297 res = ad->GetShellIonisationCrossSectionPe 322 res = ad->GetShellIonisationCrossSectionPerAtom(p, Z, shell, kinEnergy); 298 } 323 } 299 return res; 324 return res; 300 } 325 } 301 326 302 //....oooOO0OOooo........oooOO0OOooo........oo 327 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 303 328 304 G4double G4EmCalculator::GetMeanFreePath(G4dou 329 G4double G4EmCalculator::GetMeanFreePath(G4double kinEnergy, 305 const 330 const G4ParticleDefinition* p, 306 const 331 const G4String& processName, 307 const 332 const G4Material* mat, 308 const 333 const G4Region* region) 309 { 334 { 310 G4double res = DBL_MAX; 335 G4double res = DBL_MAX; 311 G4double x = GetCrossSectionPerVolume(kinEne 336 G4double x = GetCrossSectionPerVolume(kinEnergy,p, processName, mat,region); 312 if(x > 0.0) { res = 1.0/x; } 337 if(x > 0.0) { res = 1.0/x; } 313 if(verbose>1) { 338 if(verbose>1) { 314 G4cout << "G4EmCalculator::GetMeanFreePath 339 G4cout << "G4EmCalculator::GetMeanFreePath: E(MeV)= " << kinEnergy/MeV 315 << " MFP(mm)= " << res/mm 340 << " MFP(mm)= " << res/mm 316 << " " << p->GetParticleName() 341 << " " << p->GetParticleName() 317 << " in " << mat->GetName() 342 << " in " << mat->GetName() 318 << G4endl; 343 << G4endl; 319 } 344 } 320 return res; 345 return res; 321 } 346 } 322 347 323 //....oooOO0OOooo........oooOO0OOooo........oo 348 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 324 349 325 void G4EmCalculator::PrintDEDXTable(const G4Pa 350 void G4EmCalculator::PrintDEDXTable(const G4ParticleDefinition* p) 326 { 351 { 327 const G4VEnergyLossProcess* elp = manager->G << 352 const G4VEnergyLossProcess* elp = FindEnergyLossProcess(p); 328 G4cout << "##### DEDX Table for " << p->GetP 353 G4cout << "##### DEDX Table for " << p->GetParticleName() << G4endl; 329 if(nullptr != elp) G4cout << *(elp->DEDXTabl << 354 if(elp) G4cout << *(elp->DEDXTable()) << G4endl; 330 } 355 } 331 356 332 //....oooOO0OOooo........oooOO0OOooo........oo 357 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 333 358 334 void G4EmCalculator::PrintRangeTable(const G4P 359 void G4EmCalculator::PrintRangeTable(const G4ParticleDefinition* p) 335 { 360 { 336 const G4VEnergyLossProcess* elp = manager->G << 361 const G4VEnergyLossProcess* elp = FindEnergyLossProcess(p); 337 G4cout << "##### Range Table for " << p->Get 362 G4cout << "##### Range Table for " << p->GetParticleName() << G4endl; 338 if(nullptr != elp) G4cout << *(elp->RangeTab << 363 if(elp) G4cout << *(elp->RangeTableForLoss()) << G4endl; 339 } 364 } 340 365 341 //....oooOO0OOooo........oooOO0OOooo........oo 366 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 342 367 343 void G4EmCalculator::PrintInverseRangeTable(co 368 void G4EmCalculator::PrintInverseRangeTable(const G4ParticleDefinition* p) 344 { 369 { 345 const G4VEnergyLossProcess* elp = manager->G << 370 const G4VEnergyLossProcess* elp = FindEnergyLossProcess(p); 346 G4cout << "### G4EmCalculator: Inverse Range 371 G4cout << "### G4EmCalculator: Inverse Range Table for " 347 << p->GetParticleName() << G4endl; 372 << p->GetParticleName() << G4endl; 348 if(nullptr != elp) G4cout << *(elp->InverseR << 373 if(elp) G4cout << *(elp->InverseRangeTable()) << G4endl; 349 } 374 } 350 375 351 //....oooOO0OOooo........oooOO0OOooo........oo 376 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 352 377 353 G4double G4EmCalculator::ComputeDEDX(G4double 378 G4double G4EmCalculator::ComputeDEDX(G4double kinEnergy, 354 const G4P 379 const G4ParticleDefinition* p, 355 const G4S 380 const G4String& processName, 356 const G4M 381 const G4Material* mat, 357 G4d 382 G4double cut) 358 { 383 { 359 SetupMaterial(mat); 384 SetupMaterial(mat); 360 G4double res = 0.0; 385 G4double res = 0.0; 361 if(verbose > 1) { 386 if(verbose > 1) { 362 G4cout << "### G4EmCalculator::ComputeDEDX 387 G4cout << "### G4EmCalculator::ComputeDEDX: " << p->GetParticleName() 363 << " in " << currentMaterialName 388 << " in " << currentMaterialName 364 << " e(MeV)= " << kinEnergy/MeV << 389 << " e(MeV)= " << kinEnergy/MeV << " cut(MeV)= " << cut/MeV 365 << G4endl; 390 << G4endl; 366 } 391 } 367 if(UpdateParticle(p, kinEnergy)) { 392 if(UpdateParticle(p, kinEnergy)) { 368 if(FindEmModel(p, processName, kinEnergy)) 393 if(FindEmModel(p, processName, kinEnergy)) { 369 G4double escaled = kinEnergy*massRatio; << 394 370 if(nullptr != baseParticle) { << 395 // Special case of ICRU'73 model 371 res = currentModel->ComputeDEDXPerVolume(mat << 396 if(currentModel->GetName() == "ParamICRU73") { 372 << 397 res = currentModel->ComputeDEDXPerVolume(mat, p, kinEnergy, cut); 373 if(verbose > 1) { << 398 if(verbose > 1) { 374 G4cout << "Particle: " << p->GetParticleNa << 399 G4cout << " ICRU73 ion E(MeV)= " << kinEnergy << " "; 375 << " E(MeV)=" << kinEnergy << 400 G4cout << currentModel->GetName() << ": DEDX(MeV/mm)= " << res*mm/MeV 376 << " Base particle: " << baseParticle->Ge << 401 << " DEDX(MeV*cm^2/g)= " 377 << " Escaled(MeV)= " << escaled << 402 << res*gram/(MeV*cm2*mat->GetDensity()) 378 << " q2=" << chargeSquare << G4endl; << 403 << G4endl; 379 } << 380 } else { << 381 res = currentModel->ComputeDEDXPerVolume(mat << 382 if(verbose > 1) { << 383 G4cout << "Particle: " << p->GetParticleNa << 384 << " E(MeV)=" << kinEnergy << G4endl; << 385 } << 386 } << 387 if(verbose > 1) { << 388 G4cout << currentModel->GetName() << ": DEDX << 389 << " DEDX(MeV*cm^2/g)= " << 390 << res*gram/(MeV*cm2*mat->GetDensity( << 391 << G4endl; << 392 } << 393 // emulate smoothing procedure << 394 if(applySmoothing && nullptr != loweMode << 395 G4double eth = currentModel->LowEnergyLimit( << 396 G4double res0 = 0.0; << 397 G4double res1 = 0.0; << 398 if(nullptr != baseParticle) { << 399 res1 = chargeSquare* << 400 currentModel->ComputeDEDXPerVolume(mat, << 401 res0 = chargeSquare* << 402 loweModel->ComputeDEDXPerVolume(mat, bas << 403 } else { << 404 res1 = currentModel->ComputeDEDXPerVolume( << 405 res0 = loweModel->ComputeDEDXPerVolume(mat << 406 } << 407 if(res1 > 0.0 && escaled > 0.0) { << 408 res *= (1.0 + (res0/res1 - 1.0)*eth/escale << 409 } << 410 if(verbose > 1) { << 411 G4cout << "At boundary energy(MeV)= " << e << 412 << " DEDX(MeV/mm)= " << res0*mm/MeV << " << 413 << " after correction DEDX(MeV/mm)=" << r << 414 } 404 } 415 } << 405 } else { 416 // correction for ions << 406 417 if(isIon) { << 407 G4double escaled = kinEnergy*massRatio; 418 const G4double length = CLHEP::nm; << 408 if(baseParticle) { 419 if(UpdateCouple(mat, cut)) { << 409 res = currentModel->ComputeDEDXPerVolume( 420 G4double eloss = res*length; << 410 mat, baseParticle, escaled, cut) * chargeSquare; 421 dynParticle->SetKineticEnergy(kinEnergy); << 411 if(verbose > 1) { 422 currentModel->CorrectionsAlongStep(current << 412 G4cout << baseParticle->GetParticleName() 423 l << 413 << " Escaled(MeV)= " << escaled; 424 res = eloss/length; << 414 } >> 415 } else { >> 416 res = currentModel->ComputeDEDXPerVolume(mat, p, kinEnergy, cut); >> 417 if(verbose > 1) { G4cout << " no basePart E(MeV)= " << kinEnergy << " "; } >> 418 } >> 419 if(verbose > 1) { >> 420 G4cout << currentModel->GetName() << ": DEDX(MeV/mm)= " << res*mm/MeV >> 421 << " DEDX(MeV*cm^2/g)= " >> 422 << res*gram/(MeV*cm2*mat->GetDensity()) >> 423 << G4endl; >> 424 } >> 425 >> 426 // emulate smoothing procedure >> 427 G4double eth = currentModel->LowEnergyLimit(); >> 428 // G4cout << "massRatio= " << massRatio << " eth= " << eth << G4endl; >> 429 if(loweModel) { >> 430 G4double res0 = 0.0; >> 431 G4double res1 = 0.0; >> 432 if(baseParticle) { >> 433 res1 = currentModel->ComputeDEDXPerVolume(mat, baseParticle, eth, cut) >> 434 * chargeSquare; >> 435 res0 = loweModel->ComputeDEDXPerVolume(mat, baseParticle, eth, cut) >> 436 * chargeSquare; >> 437 } else { >> 438 res1 = currentModel->ComputeDEDXPerVolume(mat, p, eth, cut); >> 439 res0 = loweModel->ComputeDEDXPerVolume(mat, p, eth, cut); >> 440 } >> 441 if(verbose > 1) { >> 442 G4cout << "At boundary energy(MeV)= " << eth/MeV >> 443 << " DEDX(MeV/mm)= " << res1*mm/MeV >> 444 << G4endl; >> 445 } 425 446 426 if(verbose > 1) { << 447 //G4cout << "eth= " << eth << " escaled= " << escaled 427 G4cout << "After Corrections: DEDX(MeV/m << 448 // << " res0= " << res0 << " res1= " 428 << " DEDX(MeV*cm^2/g)= " << 449 // << res1 << " q2= " << chargeSquare << G4endl; 429 << res*gram/(MeV*cm2*mat->GetDensity()) << 450 430 } << 451 if(res1 > 0.0 && escaled > 0.0) { 431 } << 452 res *= (1.0 + (res0/res1 - 1.0)*eth/escaled); 432 } << 453 } 433 if(verbose > 0) { << 454 } 434 G4cout << "## E(MeV)= " << kinEnergy/MeV << 455 435 << " DEDX(MeV/mm)= " << res*mm/MeV << 456 // low energy correction for ions 436 << " DEDX(MeV*cm^2/g)= " << res*gram/ << 457 if(isIon) { 437 << " cut(MeV)= " << cut/MeV << 458 G4double length = CLHEP::nm; 438 << " " << p->GetParticleName() << 459 const G4Region* r = 0; 439 << " in " << currentMaterialName << 460 const G4MaterialCutsCouple* couple = FindCouple(mat, r); 440 << " Zi^2= " << chargeSquare << 461 G4double eloss = res*length; 441 << " isIon=" << isIon << 462 G4double niel = 0.0; 442 << G4endl; << 463 dynParticle.SetKineticEnergy(kinEnergy); >> 464 currentModel->GetChargeSquareRatio(p, mat, kinEnergy); >> 465 currentModel->CorrectionsAlongStep(couple,&dynParticle,eloss,niel,length); >> 466 res = eloss/length; >> 467 >> 468 if(verbose > 1) { >> 469 G4cout << "After Corrections: DEDX(MeV/mm)= " << res*mm/MeV >> 470 << " DEDX(MeV*cm^2/g)= " << res*gram/(MeV*cm2*mat->GetDensity()) >> 471 << G4endl; >> 472 } >> 473 } 443 } 474 } 444 } 475 } >> 476 if(verbose > 0) { >> 477 G4cout << "Sum: E(MeV)= " << kinEnergy/MeV >> 478 << " DEDX(MeV/mm)= " << res*mm/MeV >> 479 << " DEDX(MeV*cm^2/g)= " << res*gram/(MeV*cm2*mat->GetDensity()) >> 480 << " cut(MeV)= " << cut/MeV >> 481 << " " << p->GetParticleName() >> 482 << " in " << currentMaterialName >> 483 << " Zi^2= " << chargeSquare >> 484 << " isIon=" << isIon >> 485 << G4endl; >> 486 } 445 } 487 } 446 return res; 488 return res; 447 } 489 } 448 490 449 //....oooOO0OOooo........oooOO0OOooo........oo 491 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 450 492 451 G4double G4EmCalculator::ComputeElectronicDEDX 493 G4double G4EmCalculator::ComputeElectronicDEDX(G4double kinEnergy, 452 494 const G4ParticleDefinition* part, 453 495 const G4Material* mat, 454 496 G4double cut) 455 { 497 { 456 SetupMaterial(mat); 498 SetupMaterial(mat); 457 G4double dedx = 0.0; 499 G4double dedx = 0.0; 458 if(UpdateParticle(part, kinEnergy)) { 500 if(UpdateParticle(part, kinEnergy)) { 459 501 460 G4LossTableManager* lManager = G4LossTable 502 G4LossTableManager* lManager = G4LossTableManager::Instance(); 461 const std::vector<G4VEnergyLossProcess*> v 503 const std::vector<G4VEnergyLossProcess*> vel = 462 lManager->GetEnergyLossProcessVector(); 504 lManager->GetEnergyLossProcessVector(); 463 std::size_t n = vel.size(); << 505 G4int n = vel.size(); 464 506 465 //G4cout << "ComputeElectronicDEDX for " < 507 //G4cout << "ComputeElectronicDEDX for " << part->GetParticleName() 466 // << " n= " << n << G4endl; 508 // << " n= " << n << G4endl; 467 509 468 for(std::size_t i=0; i<n; ++i) { << 510 for(G4int i=0; i<n; ++i) { 469 if(vel[i]) { 511 if(vel[i]) { 470 auto p = static_cast<G4VProcess*>(vel[ << 512 G4VProcess* p = reinterpret_cast<G4VProcess*>(vel[i]); 471 if(ActiveForParticle(part, p)) { 513 if(ActiveForParticle(part, p)) { 472 //G4cout << "idx= " << i << " " << ( 514 //G4cout << "idx= " << i << " " << (vel[i])->GetProcessName() 473 // << " " << (vel[i])->Particle()- << 515 // << " " << (vel[i])->Particle()->GetParticleName() << G4endl; 474 dedx += ComputeDEDX(kinEnergy,part,( 516 dedx += ComputeDEDX(kinEnergy,part,(vel[i])->GetProcessName(),mat,cut); 475 } 517 } 476 } 518 } 477 } 519 } 478 } 520 } 479 return dedx; 521 return dedx; 480 } 522 } 481 523 482 //....oooOO0OOooo........oooOO0OOooo........oo 524 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 483 525 484 G4double << 526 G4double G4EmCalculator::ComputeDEDXForCutInRange(G4double kinEnergy, 485 G4EmCalculator::ComputeDEDXForCutInRange(G4dou << 527 const G4ParticleDefinition* part, 486 const << 528 const G4Material* mat, 487 const << 529 G4double rangecut) 488 G4dou << 489 { 530 { 490 SetupMaterial(mat); 531 SetupMaterial(mat); 491 G4double dedx = 0.0; 532 G4double dedx = 0.0; 492 if(UpdateParticle(part, kinEnergy)) { 533 if(UpdateParticle(part, kinEnergy)) { 493 534 494 G4LossTableManager* lManager = G4LossTable 535 G4LossTableManager* lManager = G4LossTableManager::Instance(); 495 const std::vector<G4VEnergyLossProcess*> v 536 const std::vector<G4VEnergyLossProcess*> vel = 496 lManager->GetEnergyLossProcessVector(); 537 lManager->GetEnergyLossProcessVector(); 497 std::size_t n = vel.size(); << 538 G4int n = vel.size(); 498 539 499 if(mat != cutMaterial) { 540 if(mat != cutMaterial) { 500 cutMaterial = mat; 541 cutMaterial = mat; 501 cutenergy[0] = << 542 cutenergy[0] = ComputeEnergyCutFromRangeCut(rangecut, G4Gamma::Gamma(), mat); 502 ComputeEnergyCutFromRangeCut(rangecut, << 543 cutenergy[1] = ComputeEnergyCutFromRangeCut(rangecut, G4Electron::Electron(), mat); 503 cutenergy[1] = << 544 cutenergy[2] = ComputeEnergyCutFromRangeCut(rangecut, G4Positron::Positron(), mat); 504 ComputeEnergyCutFromRangeCut(rangecut, << 505 cutenergy[2] = << 506 ComputeEnergyCutFromRangeCut(rangecut, << 507 } 545 } 508 546 509 //G4cout << "ComputeElectronicDEDX for " < 547 //G4cout << "ComputeElectronicDEDX for " << part->GetParticleName() 510 // << " n= " << n << G4endl; 548 // << " n= " << n << G4endl; 511 549 512 for(std::size_t i=0; i<n; ++i) { << 550 for(G4int i=0; i<n; ++i) { 513 if(vel[i]) { 551 if(vel[i]) { 514 auto p = static_cast<G4VProcess*>(vel[ << 552 G4VProcess* p = reinterpret_cast<G4VProcess*>(vel[i]); 515 if(ActiveForParticle(part, p)) { 553 if(ActiveForParticle(part, p)) { 516 //G4cout << "idx= " << i << " " << ( 554 //G4cout << "idx= " << i << " " << (vel[i])->GetProcessName() 517 // << " " << (vel[i])->Particle()-> << 555 // << " " << (vel[i])->Particle()->GetParticleName() << G4endl; 518 const G4ParticleDefinition* sec = (v 556 const G4ParticleDefinition* sec = (vel[i])->SecondaryParticle(); 519 std::size_t idx = 0; << 557 G4int idx = 0; 520 if(sec == G4Electron::Electron()) { 558 if(sec == G4Electron::Electron()) { idx = 1; } 521 else if(sec == G4Positron::Positron( 559 else if(sec == G4Positron::Positron()) { idx = 2; } 522 560 523 dedx += ComputeDEDX(kinEnergy,part,( 561 dedx += ComputeDEDX(kinEnergy,part,(vel[i])->GetProcessName(), 524 mat,cutenergy[id 562 mat,cutenergy[idx]); 525 } 563 } 526 } 564 } 527 } 565 } 528 } 566 } 529 return dedx; 567 return dedx; 530 } 568 } 531 569 532 //....oooOO0OOooo........oooOO0OOooo........oo 570 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 533 571 534 G4double G4EmCalculator::ComputeTotalDEDX(G4do 572 G4double G4EmCalculator::ComputeTotalDEDX(G4double kinEnergy, 535 cons 573 const G4ParticleDefinition* part, 536 cons 574 const G4Material* mat, 537 G4do 575 G4double cut) 538 { 576 { 539 G4double dedx = ComputeElectronicDEDX(kinEne 577 G4double dedx = ComputeElectronicDEDX(kinEnergy,part,mat,cut); 540 if(mass > 700.*MeV) { dedx += ComputeNuclear 578 if(mass > 700.*MeV) { dedx += ComputeNuclearDEDX(kinEnergy,part,mat); } 541 return dedx; 579 return dedx; 542 } 580 } 543 581 544 //....oooOO0OOooo........oooOO0OOooo........oo 582 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 545 583 546 G4double G4EmCalculator::ComputeNuclearDEDX(G4 584 G4double G4EmCalculator::ComputeNuclearDEDX(G4double kinEnergy, 547 const G4 585 const G4ParticleDefinition* p, 548 const G4 586 const G4Material* mat) 549 { 587 { 550 G4double res = 0.0; << 588 551 G4VEmProcess* nucst = FindDiscreteProcess(p, << 589 G4double res = corr->NuclearDEDX(p, mat, kinEnergy, false); 552 if(nucst) { << 553 G4VEmModel* mod = nucst->EmModel(); << 554 if(mod) { << 555 mod->SetFluctuationFlag(false); << 556 res = mod->ComputeDEDXPerVolume(mat, p, << 557 } << 558 } << 559 590 560 if(verbose > 1) { 591 if(verbose > 1) { 561 G4cout << p->GetParticleName() << " E(MeV 592 G4cout << p->GetParticleName() << " E(MeV)= " << kinEnergy/MeV 562 << " NuclearDEDX(MeV/mm)= " << res* 593 << " NuclearDEDX(MeV/mm)= " << res*mm/MeV 563 << " NuclearDEDX(MeV*cm^2/g)= " 594 << " NuclearDEDX(MeV*cm^2/g)= " 564 << res*gram/(MeV*cm2*mat->GetDensit 595 << res*gram/(MeV*cm2*mat->GetDensity()) 565 << G4endl; 596 << G4endl; 566 } 597 } 567 return res; 598 return res; 568 } 599 } 569 600 570 //....oooOO0OOooo........oooOO0OOooo........oo 601 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 571 602 572 G4double G4EmCalculator::ComputeCrossSectionPe 603 G4double G4EmCalculator::ComputeCrossSectionPerVolume( 573 604 G4double kinEnergy, 574 c 605 const G4ParticleDefinition* p, 575 c 606 const G4String& processName, 576 c 607 const G4Material* mat, 577 608 G4double cut) 578 { 609 { 579 SetupMaterial(mat); 610 SetupMaterial(mat); 580 G4double res = 0.0; 611 G4double res = 0.0; 581 if(UpdateParticle(p, kinEnergy)) { 612 if(UpdateParticle(p, kinEnergy)) { 582 if(FindEmModel(p, processName, kinEnergy)) 613 if(FindEmModel(p, processName, kinEnergy)) { 583 G4double e = kinEnergy; 614 G4double e = kinEnergy; 584 G4double aCut = std::max(cut, theParamet << 585 if(baseParticle) { 615 if(baseParticle) { 586 e *= kinEnergy*massRatio; 616 e *= kinEnergy*massRatio; 587 res = currentModel->CrossSectionPerVol 617 res = currentModel->CrossSectionPerVolume( 588 mat, baseParticle, e, aCut, e) * << 618 mat, baseParticle, e, cut, e) * chargeSquare; 589 } else { 619 } else { 590 res = currentModel->CrossSectionPerVol << 620 res = currentModel->CrossSectionPerVolume(mat, p, e, cut, e); 591 } 621 } 592 if(verbose>0) { 622 if(verbose>0) { 593 G4cout << "G4EmCalculator::ComputeXSPe << 623 G4cout << "G4EmCalculator::ComputeXSPerVolume: E(MeV)= " << kinEnergy/MeV 594 << kinEnergy/MeV << 595 << " cross(cm-1)= " << res*cm 624 << " cross(cm-1)= " << res*cm 596 << " cut(keV)= " << aCut/keV << 625 << " cut(keV)= " << cut/keV 597 << " " << p->GetParticleName( 626 << " " << p->GetParticleName() 598 << " in " << mat->GetName() 627 << " in " << mat->GetName() 599 << G4endl; 628 << G4endl; 600 } 629 } 601 } 630 } 602 } 631 } 603 return res; 632 return res; 604 } 633 } 605 634 606 //....oooOO0OOooo........oooOO0OOooo........oo 635 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 607 636 608 G4double << 637 G4double G4EmCalculator::ComputeCrossSectionPerAtom( 609 G4EmCalculator::ComputeCrossSectionPerAtom(G4d << 638 G4double kinEnergy, 610 con << 639 const G4ParticleDefinition* p, 611 con << 640 const G4String& processName, 612 G4d << 641 G4double Z, G4double A, 613 G4d << 642 G4double cut) 614 { 643 { 615 G4double res = 0.0; 644 G4double res = 0.0; 616 if(UpdateParticle(p, kinEnergy)) { 645 if(UpdateParticle(p, kinEnergy)) { 617 G4int iz = G4lrint(Z); << 646 CheckMaterial(G4lrint(Z)); 618 CheckMaterial(iz); << 619 if(FindEmModel(p, processName, kinEnergy)) 647 if(FindEmModel(p, processName, kinEnergy)) { 620 G4double e = kinEnergy; 648 G4double e = kinEnergy; 621 G4double aCut = std::max(cut, theParamet << 622 if(baseParticle) { 649 if(baseParticle) { 623 e *= kinEnergy*massRatio; 650 e *= kinEnergy*massRatio; 624 currentModel->InitialiseForElement(bas << 651 currentModel->InitialiseForElement(baseParticle, G4lrint(Z)); 625 res = currentModel->ComputeCrossSectio 652 res = currentModel->ComputeCrossSectionPerAtom( 626 baseParticle, e, Z, A, aCut) * c << 653 baseParticle, e, Z, A, cut) * chargeSquare; 627 } else { 654 } else { 628 currentModel->InitialiseForElement(p, << 655 currentModel->InitialiseForElement(p, G4lrint(Z)); 629 res = currentModel->ComputeCrossSectio << 656 res = currentModel->ComputeCrossSectionPerAtom(p, e, Z, A, cut); 630 } 657 } 631 if(verbose>0) { 658 if(verbose>0) { 632 G4cout << "E(MeV)= " << kinEnergy/MeV 659 G4cout << "E(MeV)= " << kinEnergy/MeV 633 << " cross(barn)= " << res/barn 660 << " cross(barn)= " << res/barn 634 << " " << p->GetParticleName( 661 << " " << p->GetParticleName() 635 << " Z= " << Z << " A= " << A/ 662 << " Z= " << Z << " A= " << A/(g/mole) << " g/mole" 636 << " cut(keV)= " << aCut/keV << 637 << G4endl; 663 << G4endl; 638 } 664 } 639 } 665 } 640 } 666 } 641 return res; 667 return res; 642 } 668 } 643 669 644 //....oooOO0OOooo........oooOO0OOooo........oo 670 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 645 671 646 G4double << 672 G4double G4EmCalculator::ComputeCrossSectionPerShell(G4double kinEnergy, 647 G4EmCalculator::ComputeCrossSectionPerShell(G4 << 673 const G4ParticleDefinition* p, 648 co << 674 const G4String& processName, 649 co << 675 G4int Z, G4int shellIdx, 650 G4 << 676 G4double cut) 651 G4 << 652 { 677 { 653 G4double res = 0.0; 678 G4double res = 0.0; 654 if(UpdateParticle(p, kinEnergy)) { 679 if(UpdateParticle(p, kinEnergy)) { 655 CheckMaterial(Z); 680 CheckMaterial(Z); 656 if(FindEmModel(p, processName, kinEnergy)) 681 if(FindEmModel(p, processName, kinEnergy)) { 657 G4double e = kinEnergy; 682 G4double e = kinEnergy; 658 G4double aCut = std::max(cut, theParamet << 683 if(baseParticle) { 659 if(nullptr != baseParticle) { << 660 e *= kinEnergy*massRatio; 684 e *= kinEnergy*massRatio; 661 currentModel->InitialiseForElement(bas 685 currentModel->InitialiseForElement(baseParticle, Z); 662 res = << 686 res = currentModel->ComputeCrossSectionPerShell(baseParticle, Z, shellIdx, 663 currentModel->ComputeCrossSectionPer << 687 e, cut) * chargeSquare; 664 << 665 } else { 688 } else { 666 currentModel->InitialiseForElement(p, 689 currentModel->InitialiseForElement(p, Z); 667 res = currentModel->ComputeCrossSectio << 690 res = currentModel->ComputeCrossSectionPerAtom(p, Z, shellIdx, e, cut); 668 } 691 } 669 if(verbose>0) { 692 if(verbose>0) { 670 G4cout << "E(MeV)= " << kinEnergy/MeV 693 G4cout << "E(MeV)= " << kinEnergy/MeV 671 << " cross(barn)= " << res/barn 694 << " cross(barn)= " << res/barn 672 << " " << p->GetParticleName( 695 << " " << p->GetParticleName() 673 << " Z= " << Z << " shellIdx= << 696 << " Z= " << Z << " shellIdx= " << shellIdx << G4endl; 674 << " cut(keV)= " << aCut/keV << 675 << G4endl; << 676 } 697 } 677 } 698 } 678 } 699 } 679 return res; 700 return res; 680 } 701 } 681 702 682 //....oooOO0OOooo........oooOO0OOooo........oo 703 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 683 704 684 G4double 705 G4double 685 G4EmCalculator::ComputeGammaAttenuationLength( 706 G4EmCalculator::ComputeGammaAttenuationLength(G4double kinEnergy, 686 707 const G4Material* mat) 687 { 708 { 688 G4double res = 0.0; 709 G4double res = 0.0; 689 const G4ParticleDefinition* gamma = G4Gamma: 710 const G4ParticleDefinition* gamma = G4Gamma::Gamma(); 690 res += ComputeCrossSectionPerVolume(kinEnerg 711 res += ComputeCrossSectionPerVolume(kinEnergy, gamma, "conv", mat, 0.0); 691 res += ComputeCrossSectionPerVolume(kinEnerg 712 res += ComputeCrossSectionPerVolume(kinEnergy, gamma, "compt", mat, 0.0); 692 res += ComputeCrossSectionPerVolume(kinEnerg 713 res += ComputeCrossSectionPerVolume(kinEnergy, gamma, "phot", mat, 0.0); 693 res += ComputeCrossSectionPerVolume(kinEnerg 714 res += ComputeCrossSectionPerVolume(kinEnergy, gamma, "Rayl", mat, 0.0); 694 if(res > 0.0) { res = 1.0/res; } 715 if(res > 0.0) { res = 1.0/res; } 695 return res; 716 return res; 696 } 717 } 697 718 698 //....oooOO0OOooo........oooOO0OOooo........oo 719 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 699 720 700 G4double G4EmCalculator::ComputeShellIonisatio 721 G4double G4EmCalculator::ComputeShellIonisationCrossSectionPerAtom( 701 const 722 const G4String& particle, 702 G4int 723 G4int Z, 703 G4Ato 724 G4AtomicShellEnumerator shell, 704 G4dou 725 G4double kinEnergy, 705 const 726 const G4Material* mat) 706 { 727 { 707 G4double res = 0.0; 728 G4double res = 0.0; 708 const G4ParticleDefinition* p = FindParticle 729 const G4ParticleDefinition* p = FindParticle(particle); 709 G4VAtomDeexcitation* ad = manager->AtomDeexc 730 G4VAtomDeexcitation* ad = manager->AtomDeexcitation(); 710 if(p && ad) { 731 if(p && ad) { 711 res = ad->ComputeShellIonisationCrossSecti 732 res = ad->ComputeShellIonisationCrossSectionPerAtom(p, Z, shell, 712 733 kinEnergy, mat); 713 } 734 } 714 return res; 735 return res; 715 } 736 } 716 737 717 //....oooOO0OOooo........oooOO0OOooo........oo 738 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 718 739 719 G4double G4EmCalculator::ComputeMeanFreePath(G 740 G4double G4EmCalculator::ComputeMeanFreePath(G4double kinEnergy, 720 c 741 const G4ParticleDefinition* p, 721 c 742 const G4String& processName, 722 c 743 const G4Material* mat, 723 G << 744 G4double cut) 724 { 745 { 725 G4double mfp = DBL_MAX; 746 G4double mfp = DBL_MAX; 726 G4double x = << 747 G4double x = ComputeCrossSectionPerVolume(kinEnergy, p, processName, mat, cut); 727 ComputeCrossSectionPerVolume(kinEnergy, p, << 728 if(x > 0.0) { mfp = 1.0/x; } 748 if(x > 0.0) { mfp = 1.0/x; } 729 if(verbose>1) { 749 if(verbose>1) { 730 G4cout << "E(MeV)= " << kinEnergy/MeV 750 G4cout << "E(MeV)= " << kinEnergy/MeV 731 << " MFP(mm)= " << mfp/mm 751 << " MFP(mm)= " << mfp/mm 732 << " " << p->GetParticleName() 752 << " " << p->GetParticleName() 733 << " in " << mat->GetName() 753 << " in " << mat->GetName() 734 << G4endl; 754 << G4endl; 735 } 755 } 736 return mfp; 756 return mfp; 737 } 757 } 738 758 739 //....oooOO0OOooo........oooOO0OOooo........oo 759 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 740 760 741 G4double G4EmCalculator::ComputeEnergyCutFromR 761 G4double G4EmCalculator::ComputeEnergyCutFromRangeCut( 742 G4double range, 762 G4double range, 743 const G4ParticleDefin 763 const G4ParticleDefinition* part, 744 const G4Material* mat 764 const G4Material* mat) 745 { 765 { 746 return G4ProductionCutsTable::GetProductionC 766 return G4ProductionCutsTable::GetProductionCutsTable()-> 747 ConvertRangeToEnergy(part, mat, range); 767 ConvertRangeToEnergy(part, mat, range); 748 } 768 } 749 769 750 //....oooOO0OOooo........oooOO0OOooo........oo 770 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 751 771 752 G4bool G4EmCalculator::UpdateParticle(const G4 772 G4bool G4EmCalculator::UpdateParticle(const G4ParticleDefinition* p, 753 G4double 773 G4double kinEnergy) 754 { 774 { 755 if(p != currentParticle) { 775 if(p != currentParticle) { 756 776 757 // new particle 777 // new particle 758 currentParticle = p; 778 currentParticle = p; 759 dynParticle->SetDefinition(const_cast<G4Pa << 779 dynParticle.SetDefinition(const_cast<G4ParticleDefinition*>(p)); 760 dynParticle->SetKineticEnergy(kinEnergy); << 780 dynParticle.SetKineticEnergy(kinEnergy); 761 baseParticle = nullptr; << 781 baseParticle = 0; 762 currentParticleName = p->GetParticleName() 782 currentParticleName = p->GetParticleName(); 763 massRatio = 1.0; 783 massRatio = 1.0; 764 mass = p->GetPDGMass(); 784 mass = p->GetPDGMass(); 765 chargeSquare = 1.0; 785 chargeSquare = 1.0; 766 currentProcess = manager->GetEnergyLossPr << 786 currentProcess = FindEnergyLossProcess(p); 767 currentProcessName = ""; 787 currentProcessName = ""; 768 isIon = false; 788 isIon = false; 769 789 770 // ionisation process exist 790 // ionisation process exist 771 if(nullptr != currentProcess) { << 791 if(currentProcess) { 772 currentProcessName = currentProcess->Get 792 currentProcessName = currentProcess->GetProcessName(); 773 baseParticle = currentProcess->BaseParti 793 baseParticle = currentProcess->BaseParticle(); 774 if(currentProcessName == "ionIoni" && p- << 775 baseParticle = theGenericIon; << 776 isIon = true; << 777 } << 778 794 779 // base particle is used 795 // base particle is used 780 if(nullptr != baseParticle) { << 796 if(baseParticle) { 781 massRatio = baseParticle->GetPDGMass() 797 massRatio = baseParticle->GetPDGMass()/p->GetPDGMass(); 782 G4double q = p->GetPDGCharge()/basePar 798 G4double q = p->GetPDGCharge()/baseParticle->GetPDGCharge(); 783 chargeSquare = q*q; 799 chargeSquare = q*q; 784 } 800 } >> 801 >> 802 if(p->GetParticleType() == "nucleus" >> 803 && currentParticleName != "deuteron" >> 804 && currentParticleName != "triton" >> 805 && currentParticleName != "alpha+" >> 806 && currentParticleName != "helium" >> 807 && currentParticleName != "hydrogen" >> 808 ) { >> 809 isIon = true; >> 810 massRatio = theGenericIon->GetPDGMass()/p->GetPDGMass(); >> 811 baseParticle = theGenericIon; >> 812 // G4cout << p->GetParticleName() >> 813 // << " in " << currentMaterial->GetName() >> 814 // << " e= " << kinEnergy << G4endl; >> 815 } 785 } 816 } 786 } 817 } >> 818 787 // Effective charge for ions 819 // Effective charge for ions 788 if(isIon && nullptr != currentProcess) { << 820 if(isIon) { 789 chargeSquare = 821 chargeSquare = 790 corr->EffectiveChargeSquareRatio(p, curr << 822 corr->EffectiveChargeSquareRatio(p, currentMaterial, kinEnergy) 791 currentProcess->SetDynamicMassCharge(massR << 823 * corr->EffectiveChargeCorrection(p,currentMaterial,kinEnergy); 792 if(verbose>1) { << 824 if(currentProcess) { 793 G4cout <<"\n NewIon: massR= "<< massRati << 825 currentProcess->SetDynamicMassCharge(massRatio,chargeSquare); 794 << chargeSquare << " " << currentProce << 826 //G4cout <<"NewP: massR= "<< massRatio << " q2= " >> 827 // << chargeSquare << G4endl; 795 } 828 } 796 } 829 } 797 return true; 830 return true; 798 } 831 } 799 832 800 //....oooOO0OOooo........oooOO0OOooo........oo 833 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 801 834 802 const G4ParticleDefinition* G4EmCalculator::Fi 835 const G4ParticleDefinition* G4EmCalculator::FindParticle(const G4String& name) 803 { 836 { 804 const G4ParticleDefinition* p = nullptr; << 837 const G4ParticleDefinition* p = 0; 805 if(name != currentParticleName) { 838 if(name != currentParticleName) { 806 p = G4ParticleTable::GetParticleTable()->F 839 p = G4ParticleTable::GetParticleTable()->FindParticle(name); 807 if(nullptr == p) { << 840 if(!p) { 808 G4cout << "### WARNING: G4EmCalculator:: 841 G4cout << "### WARNING: G4EmCalculator::FindParticle fails to find " 809 << name << G4endl; 842 << name << G4endl; 810 } 843 } 811 } else { 844 } else { 812 p = currentParticle; 845 p = currentParticle; 813 } 846 } 814 return p; 847 return p; 815 } 848 } 816 849 817 //....oooOO0OOooo........oooOO0OOooo........oo 850 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 818 851 819 const G4ParticleDefinition* G4EmCalculator::Fi 852 const G4ParticleDefinition* G4EmCalculator::FindIon(G4int Z, G4int A) 820 { 853 { 821 const G4ParticleDefinition* p = ionTable->Ge 854 const G4ParticleDefinition* p = ionTable->GetIon(Z,A,0); 822 return p; 855 return p; 823 } 856 } 824 857 825 //....oooOO0OOooo........oooOO0OOooo........oo 858 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 826 859 827 const G4Material* G4EmCalculator::FindMaterial 860 const G4Material* G4EmCalculator::FindMaterial(const G4String& name) 828 { 861 { 829 if(name != currentMaterialName) { 862 if(name != currentMaterialName) { 830 SetupMaterial(G4Material::GetMaterial(name 863 SetupMaterial(G4Material::GetMaterial(name, false)); 831 if(nullptr == currentMaterial) { << 864 if(!currentMaterial) { 832 G4cout << "### WARNING: G4EmCalculator:: 865 G4cout << "### WARNING: G4EmCalculator::FindMaterial fails to find " 833 << name << G4endl; 866 << name << G4endl; 834 } 867 } 835 } 868 } 836 return currentMaterial; 869 return currentMaterial; 837 } 870 } 838 871 839 //....oooOO0OOooo........oooOO0OOooo........oo 872 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 840 873 841 const G4Region* G4EmCalculator::FindRegion(con 874 const G4Region* G4EmCalculator::FindRegion(const G4String& reg) 842 { 875 { 843 return G4EmUtility::FindRegion(reg); << 876 const G4Region* r = 0; >> 877 if(reg != "" && reg != "world") { >> 878 r = G4RegionStore::GetInstance()->GetRegion(reg); >> 879 } else { >> 880 r = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForTheWorld"); >> 881 } >> 882 return r; 844 } 883 } 845 884 846 //....oooOO0OOooo........oooOO0OOooo........oo 885 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 847 886 848 const G4MaterialCutsCouple* G4EmCalculator::Fi 887 const G4MaterialCutsCouple* G4EmCalculator::FindCouple( 849 const G4Material* 888 const G4Material* material, 850 const G4Region* re 889 const G4Region* region) 851 { 890 { 852 const G4MaterialCutsCouple* couple = nullptr << 891 const G4MaterialCutsCouple* couple = 0; 853 SetupMaterial(material); 892 SetupMaterial(material); 854 if(nullptr != currentMaterial) { << 893 if(currentMaterial) { 855 // Access to materials 894 // Access to materials 856 const G4ProductionCutsTable* theCoupleTabl 895 const G4ProductionCutsTable* theCoupleTable= 857 G4ProductionCutsTable::GetProductionCuts 896 G4ProductionCutsTable::GetProductionCutsTable(); 858 const G4Region* r = region; 897 const G4Region* r = region; 859 if(nullptr != r) { << 898 if(r) { 860 couple = theCoupleTable->GetMaterialCuts 899 couple = theCoupleTable->GetMaterialCutsCouple(material, 861 900 r->GetProductionCuts()); 862 } else { 901 } else { 863 G4RegionStore* store = G4RegionStore::Ge 902 G4RegionStore* store = G4RegionStore::GetInstance(); 864 std::size_t nr = store->size(); << 903 size_t nr = store->size(); 865 if(0 < nr) { 904 if(0 < nr) { 866 for(std::size_t i=0; i<nr; ++i) { << 905 for(size_t i=0; i<nr; ++i) { 867 couple = theCoupleTable->GetMaterial 906 couple = theCoupleTable->GetMaterialCutsCouple( 868 material, ((*store)[i])->GetProduc 907 material, ((*store)[i])->GetProductionCuts()); 869 if(nullptr != couple) { break; } << 908 if(couple) { break; } 870 } 909 } 871 } 910 } 872 } 911 } 873 } 912 } 874 if(nullptr == couple) { << 913 if(!couple) { 875 G4ExceptionDescription ed; 914 G4ExceptionDescription ed; 876 ed << "G4EmCalculator::FindCouple: fail fo 915 ed << "G4EmCalculator::FindCouple: fail for material <" 877 << currentMaterialName << ">"; 916 << currentMaterialName << ">"; 878 if(region) { ed << " and region " << regio 917 if(region) { ed << " and region " << region->GetName(); } 879 G4Exception("G4EmCalculator::FindCouple", 918 G4Exception("G4EmCalculator::FindCouple", "em0078", 880 FatalException, ed); 919 FatalException, ed); 881 } 920 } 882 return couple; 921 return couple; 883 } 922 } 884 923 885 //....oooOO0OOooo........oooOO0OOooo........oo 924 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 886 925 887 G4bool G4EmCalculator::UpdateCouple(const G4Ma 926 G4bool G4EmCalculator::UpdateCouple(const G4Material* material, G4double cut) 888 { 927 { 889 SetupMaterial(material); 928 SetupMaterial(material); 890 if(!currentMaterial) { return false; } 929 if(!currentMaterial) { return false; } 891 for (G4int i=0; i<nLocalMaterials; ++i) { 930 for (G4int i=0; i<nLocalMaterials; ++i) { 892 if(material == localMaterials[i] && cut == 931 if(material == localMaterials[i] && cut == localCuts[i]) { 893 currentCouple = localCouples[i]; 932 currentCouple = localCouples[i]; 894 currentCoupleIndex = currentCouple->GetI 933 currentCoupleIndex = currentCouple->GetIndex(); 895 currentCut = cut; 934 currentCut = cut; 896 return true; 935 return true; 897 } 936 } 898 } 937 } 899 const G4MaterialCutsCouple* cc = new G4Mater 938 const G4MaterialCutsCouple* cc = new G4MaterialCutsCouple(material); 900 localMaterials.push_back(material); 939 localMaterials.push_back(material); 901 localCouples.push_back(cc); 940 localCouples.push_back(cc); 902 localCuts.push_back(cut); 941 localCuts.push_back(cut); 903 ++nLocalMaterials; << 942 nLocalMaterials++; 904 currentCouple = cc; 943 currentCouple = cc; 905 currentCoupleIndex = currentCouple->GetIndex 944 currentCoupleIndex = currentCouple->GetIndex(); 906 currentCut = cut; 945 currentCut = cut; 907 return true; 946 return true; 908 } 947 } 909 948 910 //....oooOO0OOooo........oooOO0OOooo........oo 949 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 911 950 912 void G4EmCalculator::FindLambdaTable(const G4P 951 void G4EmCalculator::FindLambdaTable(const G4ParticleDefinition* p, 913 const G4S 952 const G4String& processName, 914 G4double << 953 G4double kinEnergy) 915 { 954 { 916 // Search for the process 955 // Search for the process 917 if (!currentLambda || p != lambdaParticle || 956 if (!currentLambda || p != lambdaParticle || processName != lambdaName) { 918 lambdaName = processName; 957 lambdaName = processName; 919 currentLambda = nullptr; << 958 currentLambda = 0; 920 lambdaParticle = p; 959 lambdaParticle = p; 921 isApplicable = false; << 922 960 923 const G4ParticleDefinition* part = (isIon) << 961 const G4ParticleDefinition* part = p; >> 962 if(isIon) { part = theGenericIon; } 924 963 925 // Search for energy loss process 964 // Search for energy loss process 926 currentName = processName; 965 currentName = processName; 927 currentModel = nullptr; << 966 currentModel = 0; 928 loweModel = nullptr; << 967 loweModel = 0; 929 968 930 G4VEnergyLossProcess* elproc = FindEnLossP 969 G4VEnergyLossProcess* elproc = FindEnLossProcess(part, processName); 931 if(nullptr != elproc) { << 970 if(elproc) { 932 currentLambda = elproc->LambdaTable(); 971 currentLambda = elproc->LambdaTable(); 933 proctype = 0; << 972 if(currentLambda) { 934 if(nullptr != currentLambda) { << 935 isApplicable = true; 973 isApplicable = true; 936 if(verbose>1) { 974 if(verbose>1) { 937 G4cout << "G4VEnergyLossProcess is f 975 G4cout << "G4VEnergyLossProcess is found out: " << currentName 938 << G4endl; 976 << G4endl; 939 } 977 } 940 } 978 } 941 curProcess = elproc; << 942 return; 979 return; 943 } 980 } 944 981 945 // Search for discrete process 982 // Search for discrete process 946 G4VEmProcess* proc = FindDiscreteProcess(p 983 G4VEmProcess* proc = FindDiscreteProcess(part, processName); 947 if(nullptr != proc) { << 984 if(proc) { 948 currentLambda = proc->LambdaTable(); 985 currentLambda = proc->LambdaTable(); 949 proctype = 1; << 986 if(currentLambda) { 950 if(nullptr != currentLambda) { << 951 isApplicable = true; 987 isApplicable = true; 952 if(verbose>1) { 988 if(verbose>1) { 953 G4cout << "G4VEmProcess is found out 989 G4cout << "G4VEmProcess is found out: " << currentName << G4endl; 954 } 990 } 955 } 991 } 956 curProcess = proc; << 957 return; 992 return; 958 } 993 } 959 994 960 // Search for msc process 995 // Search for msc process 961 G4VMultipleScattering* msc = FindMscProces 996 G4VMultipleScattering* msc = FindMscProcess(part, processName); 962 if(nullptr != msc) { << 997 if(msc) { 963 currentModel = msc->SelectModel(kinEnerg 998 currentModel = msc->SelectModel(kinEnergy,0); 964 proctype = 2; << 999 if(currentModel) { 965 if(nullptr != currentModel) { << 966 currentLambda = currentModel->GetCross 1000 currentLambda = currentModel->GetCrossSectionTable(); 967 if(nullptr != currentLambda) { << 1001 if(currentLambda) { 968 isApplicable = true; 1002 isApplicable = true; 969 if(verbose>1) { 1003 if(verbose>1) { 970 G4cout << "G4VMultipleScattering i 1004 G4cout << "G4VMultipleScattering is found out: " << currentName 971 << G4endl; 1005 << G4endl; 972 } 1006 } 973 } 1007 } 974 } 1008 } 975 curProcess = msc; << 976 } 1009 } 977 } 1010 } 978 } 1011 } 979 1012 980 //....oooOO0OOooo........oooOO0OOooo........oo 1013 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 981 1014 982 G4bool G4EmCalculator::FindEmModel(const G4Par 1015 G4bool G4EmCalculator::FindEmModel(const G4ParticleDefinition* p, 983 const G4Str 1016 const G4String& processName, 984 G4 1017 G4double kinEnergy) 985 { 1018 { 986 isApplicable = false; 1019 isApplicable = false; 987 if(nullptr == p || nullptr == currentMateria << 1020 if(!p || !currentMaterial) { 988 G4cout << "G4EmCalculator::FindEmModel WAR 1021 G4cout << "G4EmCalculator::FindEmModel WARNING: no particle" 989 << " or materail defined; particle: 1022 << " or materail defined; particle: " << p << G4endl; 990 return isApplicable; 1023 return isApplicable; 991 } 1024 } 992 G4String partname = p->GetParticleName(); 1025 G4String partname = p->GetParticleName(); >> 1026 const G4ParticleDefinition* part = p; 993 G4double scaledEnergy = kinEnergy*massRatio; 1027 G4double scaledEnergy = kinEnergy*massRatio; 994 const G4ParticleDefinition* part = (isIon) ? << 1028 if(isIon) { part = theGenericIon; } 995 1029 996 if(verbose > 1) { 1030 if(verbose > 1) { 997 G4cout << "## G4EmCalculator::FindEmModel 1031 G4cout << "## G4EmCalculator::FindEmModel for " << partname 998 << " (type= " << p->GetParticleType 1032 << " (type= " << p->GetParticleType() 999 << ") and " << processName << " at 1033 << ") and " << processName << " at E(MeV)= " << scaledEnergy 1000 << G4endl; 1034 << G4endl; 1001 if(p != part) { G4cout << " GenericIon i 1035 if(p != part) { G4cout << " GenericIon is the base particle" << G4endl; } 1002 } 1036 } 1003 1037 1004 // Search for energy loss process 1038 // Search for energy loss process 1005 currentName = processName; 1039 currentName = processName; 1006 currentModel = nullptr; << 1040 currentModel = 0; 1007 loweModel = nullptr; << 1041 loweModel = 0; 1008 std::size_t idx = 0; << 1042 size_t idx = 0; 1009 1043 1010 G4VEnergyLossProcess* elproc = FindEnLossPr 1044 G4VEnergyLossProcess* elproc = FindEnLossProcess(part, processName); 1011 if(nullptr != elproc) { << 1045 if(elproc) { 1012 currentModel = elproc->SelectModelForMate 1046 currentModel = elproc->SelectModelForMaterial(scaledEnergy, idx); 1013 currentModel->InitialiseForMaterial(part, 1047 currentModel->InitialiseForMaterial(part, currentMaterial); 1014 currentModel->SetupForMaterial(part, curr << 1048 currentModel->SetupForMaterial(part, currentMaterial, scaledEnergy); 1015 G4double eth = currentModel->LowEnergyLim 1049 G4double eth = currentModel->LowEnergyLimit(); 1016 if(eth > 0.0) { 1050 if(eth > 0.0) { 1017 loweModel = elproc->SelectModelForMater 1051 loweModel = elproc->SelectModelForMaterial(eth - CLHEP::eV, idx); 1018 if(loweModel == currentModel) { loweMod 1052 if(loweModel == currentModel) { loweModel = nullptr; } 1019 else { 1053 else { 1020 loweModel->InitialiseForMaterial(part 1054 loweModel->InitialiseForMaterial(part, currentMaterial); 1021 loweModel->SetupForMaterial(part, cur 1055 loweModel->SetupForMaterial(part, currentMaterial, eth - CLHEP::eV); 1022 } 1056 } 1023 } 1057 } 1024 } 1058 } 1025 1059 1026 // Search for discrete process 1060 // Search for discrete process 1027 if(nullptr == currentModel) { << 1061 if(!currentModel) { 1028 G4VEmProcess* proc = FindDiscreteProcess( 1062 G4VEmProcess* proc = FindDiscreteProcess(part, processName); 1029 if(nullptr != proc) { << 1063 if(proc) { 1030 currentModel = proc->SelectModelForMate 1064 currentModel = proc->SelectModelForMaterial(kinEnergy, idx); 1031 currentModel->InitialiseForMaterial(par 1065 currentModel->InitialiseForMaterial(part, currentMaterial); 1032 currentModel->SetupForMaterial(part, cu 1066 currentModel->SetupForMaterial(part, currentMaterial, kinEnergy); 1033 G4double eth = currentModel->LowEnergyL 1067 G4double eth = currentModel->LowEnergyLimit(); 1034 if(eth > 0.0) { 1068 if(eth > 0.0) { 1035 loweModel = proc->SelectModelForMater 1069 loweModel = proc->SelectModelForMaterial(eth - CLHEP::eV, idx); 1036 if(loweModel == currentModel) { loweM << 1070 if(loweModel == currentModel) { loweModel = 0; } 1037 else { 1071 else { 1038 loweModel->InitialiseForMaterial(pa 1072 loweModel->InitialiseForMaterial(part, currentMaterial); 1039 loweModel->SetupForMaterial(part, c 1073 loweModel->SetupForMaterial(part, currentMaterial, eth - CLHEP::eV); 1040 } 1074 } 1041 } 1075 } 1042 } 1076 } 1043 } 1077 } 1044 1078 1045 // Search for msc process 1079 // Search for msc process 1046 if(nullptr == currentModel) { << 1080 if(!currentModel) { 1047 G4VMultipleScattering* proc = FindMscProc 1081 G4VMultipleScattering* proc = FindMscProcess(part, processName); 1048 if(nullptr != proc) { << 1082 if(proc) { 1049 currentModel = proc->SelectModel(kinEne 1083 currentModel = proc->SelectModel(kinEnergy, idx); 1050 loweModel = nullptr; << 1084 loweModel = 0; 1051 } 1085 } 1052 } 1086 } 1053 if(nullptr != currentModel) { << 1087 if(currentModel) { 1054 if(loweModel == currentModel) { loweModel << 1088 if(loweModel == currentModel) { loweModel = 0; } 1055 isApplicable = true; 1089 isApplicable = true; 1056 currentModel->InitialiseForMaterial(part, 1090 currentModel->InitialiseForMaterial(part, currentMaterial); 1057 if(loweModel) { 1091 if(loweModel) { 1058 loweModel->InitialiseForMaterial(part, 1092 loweModel->InitialiseForMaterial(part, currentMaterial); 1059 } 1093 } 1060 if(verbose > 1) { 1094 if(verbose > 1) { 1061 G4cout << " Model <" << currentModel- 1095 G4cout << " Model <" << currentModel->GetName() 1062 << "> Emin(MeV)= " << currentMod 1096 << "> Emin(MeV)= " << currentModel->LowEnergyLimit()/MeV 1063 << " for " << part->GetParticleN 1097 << " for " << part->GetParticleName(); 1064 if(nullptr != elproc) { << 1098 if(elproc) { 1065 G4cout << " and " << elproc->GetProce 1099 G4cout << " and " << elproc->GetProcessName() << " " << elproc 1066 << G4endl; 1100 << G4endl; 1067 } 1101 } 1068 if(nullptr != loweModel) { << 1102 if(loweModel) { 1069 G4cout << " LowEnergy model <" << low 1103 G4cout << " LowEnergy model <" << loweModel->GetName() << ">"; 1070 } 1104 } 1071 G4cout << G4endl; 1105 G4cout << G4endl; 1072 } 1106 } 1073 } 1107 } 1074 return isApplicable; 1108 return isApplicable; 1075 } 1109 } 1076 1110 1077 //....oooOO0OOooo........oooOO0OOooo........o 1111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1078 1112 >> 1113 G4VEnergyLossProcess* G4EmCalculator::FindEnergyLossProcess( >> 1114 const G4ParticleDefinition* p) >> 1115 { >> 1116 G4VEnergyLossProcess* elp = 0; >> 1117 G4String partname = p->GetParticleName(); >> 1118 const G4ParticleDefinition* part = p; >> 1119 >> 1120 if(p->GetParticleType() == "nucleus" >> 1121 && currentParticleName != "deuteron" >> 1122 && currentParticleName != "triton" >> 1123 && currentParticleName != "alpha+" >> 1124 && currentParticleName != "helium" >> 1125 && currentParticleName != "hydrogen" >> 1126 ) { part = theGenericIon; } >> 1127 >> 1128 elp = G4LossTableManager::Instance()->GetEnergyLossProcess(part); >> 1129 return elp; >> 1130 } >> 1131 >> 1132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 1133 1079 G4VEnergyLossProcess* 1134 G4VEnergyLossProcess* 1080 G4EmCalculator::FindEnLossProcess(const G4Par 1135 G4EmCalculator::FindEnLossProcess(const G4ParticleDefinition* part, 1081 const G4Str 1136 const G4String& processName) 1082 { 1137 { 1083 G4VEnergyLossProcess* proc = nullptr; << 1138 G4VEnergyLossProcess* proc = 0; 1084 const std::vector<G4VEnergyLossProcess*> v 1139 const std::vector<G4VEnergyLossProcess*> v = 1085 manager->GetEnergyLossProcessVector(); << 1140 G4LossTableManager::Instance()->GetEnergyLossProcessVector(); 1086 std::size_t n = v.size(); << 1141 G4int n = v.size(); 1087 for(std::size_t i=0; i<n; ++i) { << 1142 for(G4int i=0; i<n; ++i) { 1088 if((v[i])->GetProcessName() == processNam 1143 if((v[i])->GetProcessName() == processName) { 1089 auto p = static_cast<G4VProcess*>(v[i]) << 1144 G4VProcess* p = reinterpret_cast<G4VProcess*>(v[i]); 1090 if(ActiveForParticle(part, p)) { 1145 if(ActiveForParticle(part, p)) { 1091 proc = v[i]; 1146 proc = v[i]; 1092 break; 1147 break; 1093 } 1148 } 1094 } 1149 } 1095 } 1150 } 1096 return proc; 1151 return proc; 1097 } 1152 } 1098 1153 1099 //....oooOO0OOooo........oooOO0OOooo........o 1154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1100 1155 1101 G4VEmProcess* 1156 G4VEmProcess* 1102 G4EmCalculator::FindDiscreteProcess(const G4P 1157 G4EmCalculator::FindDiscreteProcess(const G4ParticleDefinition* part, 1103 const G4S 1158 const G4String& processName) 1104 { 1159 { 1105 G4VEmProcess* proc = nullptr; << 1160 G4VEmProcess* proc = 0; 1106 auto v = manager->GetEmProcessVector(); << 1161 const std::vector<G4VEmProcess*> v = 1107 std::size_t n = v.size(); << 1162 G4LossTableManager::Instance()->GetEmProcessVector(); 1108 for(std::size_t i=0; i<n; ++i) { << 1163 G4int n = v.size(); 1109 const G4String& pName = v[i]->GetProcessN << 1164 for(G4int i=0; i<n; ++i) { 1110 if(pName == "GammaGeneralProc") { << 1165 if((v[i])->GetProcessName() == processName) { 1111 proc = v[i]->GetEmProcess(processName); << 1166 G4VProcess* p = reinterpret_cast<G4VProcess*>(v[i]); 1112 break; << 1113 } else if(pName == processName) { << 1114 const auto p = static_cast<G4VProcess*> << 1115 if(ActiveForParticle(part, p)) { 1167 if(ActiveForParticle(part, p)) { 1116 proc = v[i]; 1168 proc = v[i]; 1117 break; 1169 break; 1118 } 1170 } 1119 } 1171 } 1120 } 1172 } 1121 return proc; 1173 return proc; 1122 } 1174 } 1123 1175 1124 //....oooOO0OOooo........oooOO0OOooo........o 1176 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1125 1177 1126 G4VMultipleScattering* 1178 G4VMultipleScattering* 1127 G4EmCalculator::FindMscProcess(const G4Partic 1179 G4EmCalculator::FindMscProcess(const G4ParticleDefinition* part, 1128 const G4String 1180 const G4String& processName) 1129 { 1181 { 1130 G4VMultipleScattering* proc = nullptr; << 1182 G4VMultipleScattering* proc = 0; 1131 const std::vector<G4VMultipleScattering*> v 1183 const std::vector<G4VMultipleScattering*> v = 1132 manager->GetMultipleScatteringVector(); << 1184 G4LossTableManager::Instance()->GetMultipleScatteringVector(); 1133 std::size_t n = v.size(); << 1185 G4int n = v.size(); 1134 for(std::size_t i=0; i<n; ++i) { << 1186 for(G4int i=0; i<n; ++i) { 1135 if((v[i])->GetProcessName() == processNam 1187 if((v[i])->GetProcessName() == processName) { 1136 auto p = static_cast<G4VProcess*>(v[i]) << 1188 G4VProcess* p = reinterpret_cast<G4VProcess*>(v[i]); 1137 if(ActiveForParticle(part, p)) { 1189 if(ActiveForParticle(part, p)) { 1138 proc = v[i]; 1190 proc = v[i]; 1139 break; 1191 break; 1140 } 1192 } 1141 } 1193 } 1142 } 1194 } 1143 return proc; 1195 return proc; 1144 } 1196 } 1145 1197 1146 //....oooOO0OOooo........oooOO0OOooo........o 1198 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1147 1199 1148 G4VProcess* G4EmCalculator::FindProcess(const 1200 G4VProcess* G4EmCalculator::FindProcess(const G4ParticleDefinition* part, 1149 const 1201 const G4String& processName) 1150 { 1202 { 1151 G4VProcess* proc = nullptr; << 1203 G4VProcess* proc = 0; 1152 const G4ProcessManager* procman = part->Get 1204 const G4ProcessManager* procman = part->GetProcessManager(); 1153 G4ProcessVector* pv = procman->GetProcessLi 1205 G4ProcessVector* pv = procman->GetProcessList(); 1154 G4int nproc = (G4int)pv->size(); << 1206 G4int nproc = pv->size(); 1155 for(G4int i=0; i<nproc; ++i) { 1207 for(G4int i=0; i<nproc; ++i) { 1156 if(processName == (*pv)[i]->GetProcessNam 1208 if(processName == (*pv)[i]->GetProcessName()) { 1157 proc = (*pv)[i]; 1209 proc = (*pv)[i]; 1158 break; 1210 break; 1159 } 1211 } 1160 } 1212 } 1161 return proc; 1213 return proc; 1162 } 1214 } 1163 1215 >> 1216 1164 //....oooOO0OOooo........oooOO0OOooo........o 1217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1165 1218 1166 G4bool G4EmCalculator::ActiveForParticle(cons 1219 G4bool G4EmCalculator::ActiveForParticle(const G4ParticleDefinition* part, 1167 G4VP 1220 G4VProcess* proc) 1168 { 1221 { 1169 G4ProcessManager* pm = part->GetProcessMana 1222 G4ProcessManager* pm = part->GetProcessManager(); 1170 G4ProcessVector* pv = pm->GetProcessList(); 1223 G4ProcessVector* pv = pm->GetProcessList(); 1171 G4int n = (G4int)pv->size(); << 1224 G4int n = pv->size(); 1172 G4bool res = false; 1225 G4bool res = false; 1173 for(G4int i=0; i<n; ++i) { 1226 for(G4int i=0; i<n; ++i) { 1174 if((*pv)[i] == proc) { 1227 if((*pv)[i] == proc) { 1175 if(pm->GetProcessActivation(i)) { res = 1228 if(pm->GetProcessActivation(i)) { res = true; } 1176 break; 1229 break; 1177 } 1230 } 1178 } 1231 } 1179 return res; 1232 return res; 1180 } 1233 } 1181 1234 1182 //....oooOO0OOooo........oooOO0OOooo........o 1235 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1183 1236 1184 void G4EmCalculator::SetupMaterial(const G4Ma 1237 void G4EmCalculator::SetupMaterial(const G4Material* mat) 1185 { 1238 { 1186 if(mat) { 1239 if(mat) { 1187 currentMaterial = mat; 1240 currentMaterial = mat; 1188 currentMaterialName = mat->GetName(); 1241 currentMaterialName = mat->GetName(); 1189 } else { 1242 } else { 1190 currentMaterial = nullptr; << 1243 currentMaterial = 0; 1191 currentMaterialName = ""; 1244 currentMaterialName = ""; 1192 } 1245 } 1193 } 1246 } 1194 1247 1195 //....oooOO0OOooo........oooOO0OOooo........o 1248 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1196 1249 1197 void G4EmCalculator::SetupMaterial(const G4St 1250 void G4EmCalculator::SetupMaterial(const G4String& mname) 1198 { 1251 { 1199 SetupMaterial(nist->FindOrBuildMaterial(mna 1252 SetupMaterial(nist->FindOrBuildMaterial(mname)); 1200 } 1253 } 1201 1254 1202 //....oooOO0OOooo........oooOO0OOooo........o 1255 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1203 1256 1204 void G4EmCalculator::CheckMaterial(G4int Z) 1257 void G4EmCalculator::CheckMaterial(G4int Z) 1205 { 1258 { 1206 G4bool isFound = false; 1259 G4bool isFound = false; 1207 if(nullptr != currentMaterial) { << 1260 if(currentMaterial) { 1208 G4int nn = (G4int)currentMaterial->GetNum << 1261 size_t nn = currentMaterial->GetNumberOfElements(); 1209 for(G4int i=0; i<nn; ++i) { << 1262 for(size_t i=0; i<nn; ++i) { 1210 if(Z == currentMaterial->GetElement(i)- << 1263 if(Z == G4lrint(currentMaterial->GetElement(i)->GetZ())) { 1211 isFound = true; 1264 isFound = true; 1212 break; 1265 break; 1213 } 1266 } 1214 } 1267 } 1215 } 1268 } 1216 if(!isFound) { 1269 if(!isFound) { 1217 SetupMaterial(nist->FindOrBuildSimpleMate 1270 SetupMaterial(nist->FindOrBuildSimpleMaterial(Z)); 1218 } 1271 } 1219 } 1272 } 1220 1273 1221 //....oooOO0OOooo........oooOO0OOooo........o 1274 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1222 1275 1223 void G4EmCalculator::SetVerbose(G4int verb) 1276 void G4EmCalculator::SetVerbose(G4int verb) 1224 { 1277 { 1225 verbose = verb; 1278 verbose = verb; 1226 } 1279 } 1227 1280 1228 //....oooOO0OOooo........oooOO0OOooo........o 1281 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1229 1282 1230 1283