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: G4PenelopePhotoElectricModel.cc,v 1.6 2010-12-15 10:26:41 pandola Exp $ >> 27 // GEANT4 tag $Name: not supported by cvs2svn $ 26 // 28 // 27 // Author: Luciano Pandola 29 // Author: Luciano Pandola 28 // 30 // 29 // History: 31 // History: 30 // -------- 32 // -------- 31 // 08 Jan 2010 L Pandola First implementati 33 // 08 Jan 2010 L Pandola First implementation 32 // 01 Feb 2011 L Pandola Suppress fake ener << 34 // 01 Feb 2011 L Pandola Suppress fake energy-violation warning when Auger is active. 33 // is active. << 35 // Make sure that fluorescence/Auger is generated only if 34 // Make sure that flu << 36 // above threshold 35 // only if above thre << 36 // 25 May 2011 L Pandola Renamed (make v200 37 // 25 May 2011 L Pandola Renamed (make v2008 as default Penelope) 37 // 10 Jun 2011 L Pandola Migrate atomic dee 38 // 10 Jun 2011 L Pandola Migrate atomic deexcitation interface 38 // 07 Oct 2011 L Pandola Bug fix (potential 39 // 07 Oct 2011 L Pandola Bug fix (potential violation of energy conservation) 39 // 27 Sep 2013 L Pandola Migrate to MT para << 40 // tables. << 41 // 02 Oct 2013 L Pandola Rewrite sampling a << 42 // to improve CPU per << 43 // 40 // 44 41 45 #include "G4PenelopePhotoElectricModel.hh" 42 #include "G4PenelopePhotoElectricModel.hh" 46 #include "G4PhysicalConstants.hh" << 47 #include "G4SystemOfUnits.hh" << 48 #include "G4ParticleDefinition.hh" 43 #include "G4ParticleDefinition.hh" 49 #include "G4MaterialCutsCouple.hh" 44 #include "G4MaterialCutsCouple.hh" 50 #include "G4DynamicParticle.hh" 45 #include "G4DynamicParticle.hh" 51 #include "G4PhysicsTable.hh" 46 #include "G4PhysicsTable.hh" 52 #include "G4PhysicsFreeVector.hh" 47 #include "G4PhysicsFreeVector.hh" 53 #include "G4ElementTable.hh" 48 #include "G4ElementTable.hh" 54 #include "G4Element.hh" 49 #include "G4Element.hh" 55 #include "G4AtomicTransitionManager.hh" 50 #include "G4AtomicTransitionManager.hh" 56 #include "G4AtomicShell.hh" 51 #include "G4AtomicShell.hh" 57 #include "G4Gamma.hh" 52 #include "G4Gamma.hh" 58 #include "G4Electron.hh" 53 #include "G4Electron.hh" 59 #include "G4AutoLock.hh" << 60 #include "G4LossTableManager.hh" 54 #include "G4LossTableManager.hh" 61 #include "G4Exp.hh" << 62 55 63 //....oooOO0OOooo........oooOO0OOooo........oo 56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 64 57 65 const G4int G4PenelopePhotoElectricModel::fMax << 66 G4PhysicsTable* G4PenelopePhotoElectricModel:: << 67 58 68 //....oooOO0OOooo........oooOO0OOooo........oo << 59 G4PenelopePhotoElectricModel::G4PenelopePhotoElectricModel(const G4ParticleDefinition*, 69 << 70 G4PenelopePhotoElectricModel::G4PenelopePhotoE << 71 const G4String& nam) 60 const G4String& nam) 72 :G4VEmModel(nam),fParticleChange(nullptr),fP << 61 :G4VEmModel(nam),fParticleChange(0),isInitialised(false),fAtomDeexcitation(0), 73 fAtomDeexcitation(nullptr),fIsInitialised(f << 62 logAtomicShellXS(0) 74 { 63 { 75 fIntrinsicLowEnergyLimit = 100.0*eV; 64 fIntrinsicLowEnergyLimit = 100.0*eV; 76 fIntrinsicHighEnergyLimit = 100.0*GeV; 65 fIntrinsicHighEnergyLimit = 100.0*GeV; 77 // SetLowEnergyLimit(fIntrinsicLowEnergyLim 66 // SetLowEnergyLimit(fIntrinsicLowEnergyLimit); 78 SetHighEnergyLimit(fIntrinsicHighEnergyLimit 67 SetHighEnergyLimit(fIntrinsicHighEnergyLimit); 79 // 68 // 80 << 69 verboseLevel= 0; 81 if (part) << 82 SetParticle(part); << 83 << 84 fVerboseLevel= 0; << 85 // Verbosity scale: 70 // Verbosity scale: 86 // 0 = nothing << 71 // 0 = nothing 87 // 1 = warning for energy non-conservation << 72 // 1 = warning for energy non-conservation 88 // 2 = details of energy budget 73 // 2 = details of energy budget 89 // 3 = calculation of cross sections, file o 74 // 3 = calculation of cross sections, file openings, sampling of atoms 90 // 4 = entering in methods 75 // 4 = entering in methods 91 76 92 //Mark this model as "applicable" for atomic 77 //Mark this model as "applicable" for atomic deexcitation 93 SetDeexcitationFlag(true); 78 SetDeexcitationFlag(true); 94 79 95 fTransitionManager = G4AtomicTransitionManag 80 fTransitionManager = G4AtomicTransitionManager::Instance(); 96 } 81 } 97 82 98 //....oooOO0OOooo........oooOO0OOooo........oo 83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 99 84 100 G4PenelopePhotoElectricModel::~G4PenelopePhoto 85 G4PenelopePhotoElectricModel::~G4PenelopePhotoElectricModel() 101 { << 86 { 102 if (IsMaster() || fLocalTable) << 87 std::map <const G4int,G4PhysicsTable*>::iterator i; >> 88 if (logAtomicShellXS) 103 { 89 { 104 for(G4int i=0; i<=fMaxZ; ++i) << 90 for (i=logAtomicShellXS->begin();i != logAtomicShellXS->end();i++) 105 { 91 { 106 if(fLogAtomicShellXS[i]) { << 92 G4PhysicsTable* tab = i->second; 107 fLogAtomicShellXS[i]->clearAndDestroy(); << 93 tab->clearAndDestroy(); 108 delete fLogAtomicShellXS[i]; << 94 delete tab; 109 fLogAtomicShellXS[i] = nullptr; << 110 } << 111 } 95 } 112 } 96 } >> 97 delete logAtomicShellXS; 113 } 98 } 114 99 115 //....oooOO0OOooo........oooOO0OOooo........oo 100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 116 101 117 void G4PenelopePhotoElectricModel::Initialise( 102 void G4PenelopePhotoElectricModel::Initialise(const G4ParticleDefinition* particle, 118 const G4DataVector& cuts) 103 const G4DataVector& cuts) 119 { 104 { 120 if (fVerboseLevel > 3) << 105 if (verboseLevel > 3) 121 G4cout << "Calling G4PenelopePhotoElectri 106 G4cout << "Calling G4PenelopePhotoElectricModel::Initialise()" << G4endl; 122 107 123 fAtomDeexcitation = G4LossTableManager::Inst << 108 // logAtomicShellXS is created only once, since it is never cleared 124 //Issue warning if the AtomicDeexcitation ha << 109 if (!logAtomicShellXS) 125 if (!fAtomDeexcitation) << 110 logAtomicShellXS = new std::map<const G4int,G4PhysicsTable*>; 126 { << 127 G4cout << G4endl; << 128 G4cout << "WARNING from G4PenelopePhotoE << 129 G4cout << "Atomic de-excitation module i << 130 G4cout << "any fluorescence/Auger emissi << 131 G4cout << "Please make sure this is inte << 132 } << 133 << 134 SetParticle(particle); << 135 << 136 //Only the master model creates/fills/destro << 137 if (IsMaster() && particle == fParticle) << 138 { << 139 G4ProductionCutsTable* theCoupleTable = << 140 G4ProductionCutsTable::GetProductionCutsTabl << 141 << 142 for (G4int i=0;i<(G4int)theCoupleTable-> << 143 { << 144 const G4Material* material = << 145 theCoupleTable->GetMaterialCutsCouple(i) << 146 const G4ElementVector* theElementVector = << 147 << 148 for (std::size_t j=0;j<material->GetNumber << 149 { << 150 G4int iZ = theElementVector->at(j)->Ge << 151 //read data files only in the master << 152 if (!fLogAtomicShellXS[iZ]) << 153 ReadDataFile(iZ); << 154 } << 155 } << 156 111 157 InitialiseElementSelectors(particle,cuts << 112 InitialiseElementSelectors(particle,cuts); >> 113 fAtomDeexcitation = G4LossTableManager::Instance()->AtomDeexcitation(); 158 114 159 if (fVerboseLevel > 0) { << 115 if (verboseLevel > 0) { 160 G4cout << "Penelope Photo-Electric model v20 << 116 G4cout << "Penelope Photo-Electric model v2008 is initialized " << G4endl 161 << "Energy range: " << 117 << "Energy range: " 162 << LowEnergyLimit() / MeV << " MeV - << 118 << LowEnergyLimit() / MeV << " MeV - " 163 << HighEnergyLimit() / GeV << " GeV"; << 119 << HighEnergyLimit() / GeV << " GeV"; 164 } << 120 } 165 } << 166 121 167 if(fIsInitialised) return; << 122 if(isInitialised) return; 168 fParticleChange = GetParticleChangeForGamma( 123 fParticleChange = GetParticleChangeForGamma(); 169 fIsInitialised = true; << 124 isInitialised = true; 170 125 171 } 126 } 172 127 173 void G4PenelopePhotoElectricModel::InitialiseL << 174 G4VEmModel *masterModel) << 175 { << 176 if (fVerboseLevel > 3) << 177 G4cout << "Calling G4PenelopePhotoElectri << 178 // << 179 //Check that particle matches: one might hav << 180 //for e+ and e-). << 181 // << 182 if (part == fParticle) << 183 { << 184 SetElementSelectors(masterModel->GetElem << 185 << 186 //Get the const table pointers from the << 187 const G4PenelopePhotoElectricModel* theM << 188 static_cast<G4PenelopePhotoElectricModel*> ( << 189 for(G4int i=0; i<=fMaxZ; ++i) << 190 fLogAtomicShellXS[i] = theModel->fLogAtomicS << 191 //Same verbosity for all workers, as the << 192 fVerboseLevel = theModel->fVerboseLevel; << 193 } << 194 << 195 return; << 196 } << 197 << 198 //....oooOO0OOooo........oooOO0OOooo........oo 128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 199 namespace { G4Mutex PenelopePhotoElectricMode << 129 200 G4double G4PenelopePhotoElectricModel::Compute 130 G4double G4PenelopePhotoElectricModel::ComputeCrossSectionPerAtom( 201 const G4ParticleDefinition*, 131 const G4ParticleDefinition*, 202 G4double energy, 132 G4double energy, 203 G4double Z, G4double, 133 G4double Z, G4double, 204 G4double, G4double) 134 G4double, G4double) 205 { 135 { 206 // 136 // 207 // Penelope model v2008 137 // Penelope model v2008 208 // 138 // 209 if (fVerboseLevel > 3) << 210 G4cout << "Calling ComputeCrossSectionPerA << 211 139 212 G4int iZ = G4int(Z); << 140 if (verboseLevel > 3) >> 141 G4cout << "Calling ComputeCrossSectionPerAtom() of G4PenelopePhotoElectricModel" << G4endl; 213 142 214 if (!fLogAtomicShellXS[iZ]) << 143 G4int iZ = (G4int) Z; 215 { << 216 //If we are here, it means that Initiali << 217 //not filled up. This can happen in a Un << 218 if (fVerboseLevel > 0) << 219 { << 220 //Issue a G4Exception (warning) only in ve << 221 G4ExceptionDescription ed; << 222 ed << "Unable to retrieve the shell cross << 223 ed << "This can happen only in Unit Tests << 224 G4Exception("G4PenelopePhotoElectricModel: << 225 "em2038",JustWarning,ed); << 226 } << 227 //protect file reading via autolock << 228 G4AutoLock lock(&PenelopePhotoElectricMo << 229 ReadDataFile(iZ); << 230 lock.unlock(); << 231 } << 232 144 >> 145 //read data files >> 146 if (!logAtomicShellXS->count(iZ)) >> 147 ReadDataFile(iZ); >> 148 //now it should be ok >> 149 if (!logAtomicShellXS->count(iZ)) >> 150 G4Exception("G4PenelopePhotoElectricModel::ComputeCrossSectionPerAtom()", >> 151 "em2038",FatalException, >> 152 "Unable to retrieve the shell cross section table"); >> 153 233 G4double cross = 0; 154 G4double cross = 0; 234 G4PhysicsTable* theTable = fLogAtomicShellX << 155 >> 156 G4PhysicsTable* theTable = logAtomicShellXS->find(iZ)->second; 235 G4PhysicsFreeVector* totalXSLog = (G4Physics 157 G4PhysicsFreeVector* totalXSLog = (G4PhysicsFreeVector*) (*theTable)[0]; 236 158 237 if (!totalXSLog) 159 if (!totalXSLog) 238 { 160 { 239 G4Exception("G4PenelopePhotoElectricMod 161 G4Exception("G4PenelopePhotoElectricModel::ComputeCrossSectionPerAtom()", 240 "em2039",FatalException, 162 "em2039",FatalException, 241 "Unable to retrieve the total cross sec << 163 "Unable to retrieve the total cross section table"); 242 return 0; 164 return 0; 243 } 165 } 244 G4double logene = G4Log(energy); << 166 G4double logene = std::log(energy); 245 G4double logXS = totalXSLog->Value(logene); 167 G4double logXS = totalXSLog->Value(logene); 246 cross = G4Exp(logXS); << 168 cross = std::exp(logXS); 247 << 169 248 if (fVerboseLevel > 2) << 170 if (verboseLevel > 2) 249 G4cout << "Photoelectric cross section at 171 G4cout << "Photoelectric cross section at " << energy/MeV << " MeV for Z=" << Z << 250 " = " << cross/barn << " barn" << G4endl 172 " = " << cross/barn << " barn" << G4endl; 251 return cross; 173 return cross; 252 } 174 } 253 175 254 //....oooOO0OOooo........oooOO0OOooo........oo 176 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 255 177 256 void G4PenelopePhotoElectricModel::SampleSecon 178 void G4PenelopePhotoElectricModel::SampleSecondaries(std::vector<G4DynamicParticle*>* fvect, 257 const G4MaterialCutsCouple* c 179 const G4MaterialCutsCouple* couple, 258 const G4DynamicParticle* aDyn 180 const G4DynamicParticle* aDynamicGamma, 259 G4double, 181 G4double, 260 G4double) 182 G4double) 261 { 183 { 262 // 184 // 263 // Photoelectric effect, Penelope model v200 185 // Photoelectric effect, Penelope model v2008 264 // 186 // 265 // The target atom and the target shell are << 187 // The target atom and the target shell are sampled according to the Livermore 266 // database << 188 // database 267 // D.E. Cullen et al., Report UCRL-50400 (1 189 // D.E. Cullen et al., Report UCRL-50400 (1989) 268 // The angular distribution of the electron << 190 // The angular distribution of the electron in the final state is sampled 269 // according to the Sauter distribution from << 191 // according to the Sauter distribution from 270 // F. Sauter, Ann. Phys. 11 (1931) 454 192 // F. Sauter, Ann. Phys. 11 (1931) 454 271 // The energy of the final electron is given << 193 // The energy of the final electron is given by the initial photon energy minus 272 // the binding energy. Fluorescence de-excit << 194 // the binding energy. Fluorescence de-excitation is subsequently produced 273 // (to fill the vacancy) according to the ge 195 // (to fill the vacancy) according to the general Geant4 G4DeexcitationManager: 274 // J. Stepanek, Comp. Phys. Comm. 1206 pp 1 196 // J. Stepanek, Comp. Phys. Comm. 1206 pp 1-1-9 (1997) 275 197 276 if (fVerboseLevel > 3) << 198 if (verboseLevel > 3) 277 G4cout << "Calling SamplingSecondaries() o 199 G4cout << "Calling SamplingSecondaries() of G4PenelopePhotoElectricModel" << G4endl; 278 200 279 G4double photonEnergy = aDynamicGamma->GetKi 201 G4double photonEnergy = aDynamicGamma->GetKineticEnergy(); 280 202 281 // always kill primary 203 // always kill primary 282 fParticleChange->ProposeTrackStatus(fStopAnd 204 fParticleChange->ProposeTrackStatus(fStopAndKill); 283 fParticleChange->SetProposedKineticEnergy(0. 205 fParticleChange->SetProposedKineticEnergy(0.); 284 206 285 if (photonEnergy <= fIntrinsicLowEnergyLimit 207 if (photonEnergy <= fIntrinsicLowEnergyLimit) 286 { 208 { 287 fParticleChange->ProposeLocalEnergyDepos 209 fParticleChange->ProposeLocalEnergyDeposit(photonEnergy); 288 return ; 210 return ; 289 } 211 } 290 212 291 G4ParticleMomentum photonDirection = aDynami 213 G4ParticleMomentum photonDirection = aDynamicGamma->GetMomentumDirection(); 292 214 293 // Select randomly one element in the curren 215 // Select randomly one element in the current material 294 if (fVerboseLevel > 2) << 216 if (verboseLevel > 2) 295 G4cout << "Going to select element in " << 217 G4cout << "Going to select element in " << couple->GetMaterial()->GetName() << G4endl; 296 218 297 // atom can be selected efficiently if eleme 219 // atom can be selected efficiently if element selectors are initialised 298 const G4Element* anElement = 220 const G4Element* anElement = 299 SelectRandomAtom(couple,G4Gamma::GammaDefi 221 SelectRandomAtom(couple,G4Gamma::GammaDefinition(),photonEnergy); 300 G4int Z = anElement->GetZasInt(); << 222 G4int Z = (G4int) anElement->GetZ(); 301 if (fVerboseLevel > 2) << 223 if (verboseLevel > 2) 302 G4cout << "Selected " << anElement->GetNam 224 G4cout << "Selected " << anElement->GetName() << G4endl; 303 << 225 304 // Select the ionised shell in the current a 226 // Select the ionised shell in the current atom according to shell cross sections 305 //shellIndex = 0 --> K shell 227 //shellIndex = 0 --> K shell 306 // 1-3 --> L shells 228 // 1-3 --> L shells 307 // 4-8 --> M shells 229 // 4-8 --> M shells 308 // 9 --> outer shells cumulative 230 // 9 --> outer shells cumulatively 309 // 231 // 310 std::size_t shellIndex = SelectRandomShell(Z << 232 size_t shellIndex = SelectRandomShell(Z,photonEnergy); 311 233 312 if (fVerboseLevel > 2) << 234 if (verboseLevel > 2) 313 G4cout << "Selected shell " << shellIndex 235 G4cout << "Selected shell " << shellIndex << " of element " << anElement->GetName() << G4endl; 314 236 315 // Retrieve the corresponding identifier and 237 // Retrieve the corresponding identifier and binding energy of the selected shell 316 const G4AtomicTransitionManager* transitionM 238 const G4AtomicTransitionManager* transitionManager = G4AtomicTransitionManager::Instance(); 317 239 318 //The number of shell cross section possibly << 240 //The number of shell cross section possibly reported in the Penelope database 319 //might be different from the number of shel 241 //might be different from the number of shells in the G4AtomicTransitionManager 320 //(namely, Penelope may contain more shell, 242 //(namely, Penelope may contain more shell, especially for very light elements). 321 //In order to avoid a warning message from t << 243 //In order to avoid a warning message from the G4AtomicTransitionManager, I 322 //add this protection. Results are anyway ch 244 //add this protection. Results are anyway changed, because when G4AtomicTransitionManager 323 //has a shellID>maxID, it sets the shellID t << 245 //has a shellID>maxID, it sets the shellID to the last valid shell. 324 std::size_t numberOfShells = (std::size_t) t << 246 size_t numberOfShells = (size_t) transitionManager->NumberOfShells(Z); 325 if (shellIndex >= numberOfShells) 247 if (shellIndex >= numberOfShells) 326 shellIndex = numberOfShells-1; 248 shellIndex = numberOfShells-1; 327 249 328 const G4AtomicShell* shell = fTransitionMana 250 const G4AtomicShell* shell = fTransitionManager->Shell(Z,shellIndex); 329 G4double bindingEnergy = shell->BindingEnerg 251 G4double bindingEnergy = shell->BindingEnergy(); >> 252 //G4int shellId = shell->ShellId(); 330 253 331 //Penelope considers only K, L and M shells. << 254 //Penelope considers only K, L and M shells. Cross sections of outer shells are 332 //not included in the Penelope database. If << 255 //not included in the Penelope database. If SelectRandomShell() returns 333 //shellIndex = 9, it means that an outer she << 256 //shellIndex = 9, it means that an outer shell was ionized. In this case the 334 //Penelope recipe is to set bindingEnergy = << 257 //Penelope recipe is to set bindingEnergy = 0 (the energy is entirely assigned 335 //to the electron) and to disregard fluoresc 258 //to the electron) and to disregard fluorescence. 336 if (shellIndex == 9) 259 if (shellIndex == 9) 337 bindingEnergy = 0.*eV; 260 bindingEnergy = 0.*eV; 338 261 >> 262 339 G4double localEnergyDeposit = 0.0; 263 G4double localEnergyDeposit = 0.0; 340 G4double cosTheta = 1.0; 264 G4double cosTheta = 1.0; 341 265 342 // Primary outcoming electron 266 // Primary outcoming electron 343 G4double eKineticEnergy = photonEnergy - bin 267 G4double eKineticEnergy = photonEnergy - bindingEnergy; 344 << 268 345 // There may be cases where the binding ener 269 // There may be cases where the binding energy of the selected shell is > photon energy 346 // In such cases do not generate secondaries 270 // In such cases do not generate secondaries 347 if (eKineticEnergy > 0.) 271 if (eKineticEnergy > 0.) 348 { 272 { 349 // The electron is created 273 // The electron is created 350 // Direction sampled from the Sauter dis 274 // Direction sampled from the Sauter distribution 351 cosTheta = SampleElectronDirection(eKine 275 cosTheta = SampleElectronDirection(eKineticEnergy); 352 G4double sinTheta = std::sqrt(1-cosTheta 276 G4double sinTheta = std::sqrt(1-cosTheta*cosTheta); 353 G4double phi = twopi * G4UniformRand() ; 277 G4double phi = twopi * G4UniformRand() ; 354 G4double dirx = sinTheta * std::cos(phi) 278 G4double dirx = sinTheta * std::cos(phi); 355 G4double diry = sinTheta * std::sin(phi) 279 G4double diry = sinTheta * std::sin(phi); 356 G4double dirz = cosTheta ; 280 G4double dirz = cosTheta ; 357 G4ThreeVector electronDirection(dirx,dir 281 G4ThreeVector electronDirection(dirx,diry,dirz); //electron direction 358 electronDirection.rotateUz(photonDirecti 282 electronDirection.rotateUz(photonDirection); 359 G4DynamicParticle* electron = new G4Dyna << 283 G4DynamicParticle* electron = new G4DynamicParticle (G4Electron::Electron(), 360 electronDirection, << 284 electronDirection, 361 eKineticEnergy); 285 eKineticEnergy); 362 fvect->push_back(electron); 286 fvect->push_back(electron); 363 } << 287 } 364 else << 288 else 365 bindingEnergy = photonEnergy; 289 bindingEnergy = photonEnergy; 366 290 >> 291 367 G4double energyInFluorescence = 0; //testing 292 G4double energyInFluorescence = 0; //testing purposes 368 G4double energyInAuger = 0; //testing purpos 293 G4double energyInAuger = 0; //testing purposes 369 << 294 370 //Now, take care of fluorescence, if require 295 //Now, take care of fluorescence, if required. According to the Penelope 371 //recipe, I have to skip fluoresence complet << 296 //recipe, I have to skip fluoresence completely if shellIndex == 9 372 //(= sampling of a shell outer than K,L,M) 297 //(= sampling of a shell outer than K,L,M) 373 if (fAtomDeexcitation && shellIndex<9) 298 if (fAtomDeexcitation && shellIndex<9) 374 { << 299 { 375 G4int index = couple->GetIndex(); 300 G4int index = couple->GetIndex(); 376 if (fAtomDeexcitation->CheckDeexcitation 301 if (fAtomDeexcitation->CheckDeexcitationActiveRegion(index)) 377 { << 302 { 378 std::size_t nBefore = fvect->size(); << 303 size_t nBefore = fvect->size(); 379 fAtomDeexcitation->GenerateParticles(fvect 304 fAtomDeexcitation->GenerateParticles(fvect,shell,Z,index); 380 std::size_t nAfter = fvect->size(); << 305 size_t nAfter = fvect->size(); 381 306 382 if (nAfter > nBefore) //actual production 307 if (nAfter > nBefore) //actual production of fluorescence 383 { 308 { 384 for (std::size_t j=nBefore;j<nAfter;++ << 309 for (size_t j=nBefore;j<nAfter;j++) //loop on products 385 { 310 { 386 G4double itsEnergy = ((*fvect)[j])->GetK 311 G4double itsEnergy = ((*fvect)[j])->GetKineticEnergy(); 387 if (itsEnergy < bindingEnergy) // valid << 312 bindingEnergy -= itsEnergy; 388 { << 313 if (((*fvect)[j])->GetParticleDefinition() == G4Gamma::Definition()) 389 bindingEnergy -= itsEnergy; << 314 energyInFluorescence += itsEnergy; 390 if (((*fvect)[j])->GetParticleDefini << 315 else if (((*fvect)[j])->GetParticleDefinition() == G4Electron::Definition()) 391 energyInFluorescence += itsEnergy; << 316 energyInAuger += itsEnergy; 392 else if (((*fvect)[j])->GetParticleD << 317 393 energyInAuger += itsEnergy; << 394 } << 395 else //invalid secondary: takes more tha << 396 { << 397 delete (*fvect)[j]; << 398 (*fvect)[j] = nullptr; << 399 } << 400 } 318 } 401 } 319 } >> 320 402 } 321 } 403 } 322 } 404 323 405 //Residual energy is deposited locally 324 //Residual energy is deposited locally 406 localEnergyDeposit += bindingEnergy; 325 localEnergyDeposit += bindingEnergy; 407 << 326 408 if (localEnergyDeposit < 0) //Should not be: << 327 if (localEnergyDeposit < 0) 409 { 328 { 410 G4Exception("G4PenelopePhotoElectricMode << 329 G4cout << "WARNING - " 411 "em2099",JustWarning,"WARNING: Negative << 330 << "G4PenelopePhotoElectricModel::SampleSecondaries() - Negative energy deposit" >> 331 << G4endl; 412 localEnergyDeposit = 0; 332 localEnergyDeposit = 0; 413 } 333 } 414 334 415 fParticleChange->ProposeLocalEnergyDeposit(l 335 fParticleChange->ProposeLocalEnergyDeposit(localEnergyDeposit); 416 336 417 if (fVerboseLevel > 1) << 337 if (verboseLevel > 1) 418 { 338 { 419 G4cout << "----------------------------- 339 G4cout << "-----------------------------------------------------------" << G4endl; 420 G4cout << "Energy balance from G4Penelop 340 G4cout << "Energy balance from G4PenelopePhotoElectric" << G4endl; 421 G4cout << "Selected shell: " << WriteTar << 341 G4cout << "Selected shell: " << WriteTargetShell(shellIndex) << " of element " << 422 anElement->GetName() << G4endl; 342 anElement->GetName() << G4endl; 423 G4cout << "Incoming photon energy: " << 343 G4cout << "Incoming photon energy: " << photonEnergy/keV << " keV" << G4endl; 424 G4cout << "----------------------------- 344 G4cout << "-----------------------------------------------------------" << G4endl; 425 if (eKineticEnergy) 345 if (eKineticEnergy) 426 G4cout << "Outgoing electron " << eKineticEn 346 G4cout << "Outgoing electron " << eKineticEnergy/keV << " keV" << G4endl; 427 if (energyInFluorescence) 347 if (energyInFluorescence) 428 G4cout << "Fluorescence x-rays: " << energyI 348 G4cout << "Fluorescence x-rays: " << energyInFluorescence/keV << " keV" << G4endl; 429 if (energyInAuger) 349 if (energyInAuger) 430 G4cout << "Auger electrons: " << energyInAug 350 G4cout << "Auger electrons: " << energyInAuger/keV << " keV" << G4endl; 431 G4cout << "Local energy deposit " << loc 351 G4cout << "Local energy deposit " << localEnergyDeposit/keV << " keV" << G4endl; 432 G4cout << "Total final state: " << << 352 G4cout << "Total final state: " << 433 (eKineticEnergy+energyInFluorescence+localEn << 353 (eKineticEnergy+energyInFluorescence+localEnergyDeposit+energyInAuger)/keV << 434 " keV" << G4endl; 354 " keV" << G4endl; 435 G4cout << "----------------------------- 355 G4cout << "-----------------------------------------------------------" << G4endl; 436 } 356 } 437 if (fVerboseLevel > 0) << 357 if (verboseLevel > 0) 438 { 358 { 439 G4double energyDiff = << 359 G4double energyDiff = 440 std::fabs(eKineticEnergy+energyInFluorescenc 360 std::fabs(eKineticEnergy+energyInFluorescence+localEnergyDeposit+energyInAuger-photonEnergy); 441 if (energyDiff > 0.05*keV) 361 if (energyDiff > 0.05*keV) 442 { 362 { 443 G4cout << "Warning from G4PenelopePhotoEle << 363 G4cout << "Warning from G4PenelopePhotoElectric: problem with energy conservation: " << 444 (eKineticEnergy+energyInFluorescence+loc << 364 (eKineticEnergy+energyInFluorescence+localEnergyDeposit+energyInAuger)/keV 445 << " keV (final) vs. " << << 365 << " keV (final) vs. " << 446 photonEnergy/keV << " keV (initial)" << 366 photonEnergy/keV << " keV (initial)" << G4endl; 447 G4cout << "------------------------------- 367 G4cout << "-----------------------------------------------------------" << G4endl; 448 G4cout << "Energy balance from G4PenelopeP 368 G4cout << "Energy balance from G4PenelopePhotoElectric" << G4endl; 449 G4cout << "Selected shell: " << WriteTarge << 369 G4cout << "Selected shell: " << WriteTargetShell(shellIndex) << " of element " << 450 anElement->GetName() << G4endl; 370 anElement->GetName() << G4endl; 451 G4cout << "Incoming photon energy: " << ph 371 G4cout << "Incoming photon energy: " << photonEnergy/keV << " keV" << G4endl; 452 G4cout << "------------------------------- 372 G4cout << "-----------------------------------------------------------" << G4endl; 453 if (eKineticEnergy) 373 if (eKineticEnergy) 454 G4cout << "Outgoing electron " << eKinet 374 G4cout << "Outgoing electron " << eKineticEnergy/keV << " keV" << G4endl; 455 if (energyInFluorescence) 375 if (energyInFluorescence) 456 G4cout << "Fluorescence x-rays: " << ene 376 G4cout << "Fluorescence x-rays: " << energyInFluorescence/keV << " keV" << G4endl; 457 if (energyInAuger) 377 if (energyInAuger) 458 G4cout << "Auger electrons: " << energyI 378 G4cout << "Auger electrons: " << energyInAuger/keV << " keV" << G4endl; 459 G4cout << "Local energy deposit " << local 379 G4cout << "Local energy deposit " << localEnergyDeposit/keV << " keV" << G4endl; 460 G4cout << "Total final state: " << << 380 G4cout << "Total final state: " << 461 (eKineticEnergy+energyInFluorescence+loc << 381 (eKineticEnergy+energyInFluorescence+localEnergyDeposit+energyInAuger)/keV << 462 " keV" << G4endl; 382 " keV" << G4endl; 463 G4cout << "------------------------------- 383 G4cout << "-----------------------------------------------------------" << G4endl; 464 } 384 } 465 } 385 } 466 } 386 } 467 387 468 //....oooOO0OOooo........oooOO0OOooo........oo 388 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 469 389 470 G4double G4PenelopePhotoElectricModel::SampleE 390 G4double G4PenelopePhotoElectricModel::SampleElectronDirection(G4double energy) 471 { 391 { 472 G4double costheta = 1.0; 392 G4double costheta = 1.0; 473 if (energy>1*GeV) return costheta; 393 if (energy>1*GeV) return costheta; 474 << 394 475 //1) initialize energy-dependent variables 395 //1) initialize energy-dependent variables 476 // Variable naming according to Eq. (2.24) o 396 // Variable naming according to Eq. (2.24) of Penelope Manual 477 // (pag. 44) 397 // (pag. 44) 478 G4double gamma = 1.0 + energy/electron_mass_ 398 G4double gamma = 1.0 + energy/electron_mass_c2; 479 G4double gamma2 = gamma*gamma; 399 G4double gamma2 = gamma*gamma; 480 G4double beta = std::sqrt((gamma2-1.0)/gamma 400 G4double beta = std::sqrt((gamma2-1.0)/gamma2); 481 << 401 482 // ac corresponds to "A" of Eq. (2.31) 402 // ac corresponds to "A" of Eq. (2.31) 483 // 403 // 484 G4double ac = (1.0/beta) - 1.0; 404 G4double ac = (1.0/beta) - 1.0; 485 G4double a1 = 0.5*beta*gamma*(gamma-1.0)*(ga 405 G4double a1 = 0.5*beta*gamma*(gamma-1.0)*(gamma-2.0); 486 G4double a2 = ac + 2.0; 406 G4double a2 = ac + 2.0; 487 G4double gtmax = 2.0*(a1 + 1.0/ac); 407 G4double gtmax = 2.0*(a1 + 1.0/ac); 488 << 408 489 G4double tsam = 0; 409 G4double tsam = 0; 490 G4double gtr = 0; 410 G4double gtr = 0; 491 411 492 //2) sampling. Eq. (2.31) of Penelope Manual 412 //2) sampling. Eq. (2.31) of Penelope Manual 493 // tsam = 1-std::cos(theta) 413 // tsam = 1-std::cos(theta) 494 // gtr = rejection function according to Eq. 414 // gtr = rejection function according to Eq. (2.28) 495 do{ 415 do{ 496 G4double rand = G4UniformRand(); 416 G4double rand = G4UniformRand(); 497 tsam = 2.0*ac * (2.0*rand + a2*std::sqrt(r 417 tsam = 2.0*ac * (2.0*rand + a2*std::sqrt(rand)) / (a2*a2 - 4.0*rand); 498 gtr = (2.0 - tsam) * (a1 + 1.0/(ac+tsam)); 418 gtr = (2.0 - tsam) * (a1 + 1.0/(ac+tsam)); 499 }while(G4UniformRand()*gtmax > gtr); 419 }while(G4UniformRand()*gtmax > gtr); 500 costheta = 1.0-tsam; 420 costheta = 1.0-tsam; >> 421 501 422 502 return costheta; 423 return costheta; 503 } 424 } 504 425 505 //....oooOO0OOooo........oooOO0OOooo........oo 426 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 506 427 507 void G4PenelopePhotoElectricModel::ReadDataFil 428 void G4PenelopePhotoElectricModel::ReadDataFile(G4int Z) 508 { 429 { 509 if (!IsMaster()) << 430 if (verboseLevel > 2) 510 //Should not be here! << 511 G4Exception("G4PenelopePhotoElectricModel: << 512 "em0100",FatalException,"Worker thread in << 513 << 514 if (fVerboseLevel > 2) << 515 { 431 { 516 G4cout << "G4PenelopePhotoElectricModel: 432 G4cout << "G4PenelopePhotoElectricModel::ReadDataFile()" << G4endl; 517 G4cout << "Going to read PhotoElectric d 433 G4cout << "Going to read PhotoElectric data files for Z=" << Z << G4endl; 518 } 434 } 519 << 435 520 const char* path = G4FindDataDir("G4LEDATA << 436 char* path = getenv("G4LEDATA"); 521 if(!path) << 437 if (!path) 522 { 438 { 523 G4String excep = "G4PenelopePhotoElectri 439 G4String excep = "G4PenelopePhotoElectricModel - G4LEDATA environment variable not set!"; 524 G4Exception("G4PenelopePhotoElectricMode 440 G4Exception("G4PenelopePhotoElectricModel::ReadDataFile()", 525 "em0006",FatalException,excep); 441 "em0006",FatalException,excep); 526 return; 442 return; 527 } 443 } 528 << 444 529 /* 445 /* 530 Read the cross section file 446 Read the cross section file 531 */ 447 */ 532 std::ostringstream ost; 448 std::ostringstream ost; 533 if (Z>9) 449 if (Z>9) 534 ost << path << "/penelope/photoelectric/pd 450 ost << path << "/penelope/photoelectric/pdgph" << Z << ".p08"; 535 else 451 else 536 ost << path << "/penelope/photoelectric/pd 452 ost << path << "/penelope/photoelectric/pdgph0" << Z << ".p08"; 537 std::ifstream file(ost.str().c_str()); 453 std::ifstream file(ost.str().c_str()); 538 if (!file.is_open()) 454 if (!file.is_open()) 539 { 455 { 540 G4String excep = "G4PenelopePhotoElectri 456 G4String excep = "G4PenelopePhotoElectricModel - data file " + G4String(ost.str()) + " not found!"; 541 G4Exception("G4PenelopePhotoElectricMode 457 G4Exception("G4PenelopePhotoElectricModel::ReadDataFile()", 542 "em0003",FatalException,excep); 458 "em0003",FatalException,excep); 543 } 459 } 544 //I have to know in advance how many points 460 //I have to know in advance how many points are in the data list 545 //to initialize the G4PhysicsFreeVector() 461 //to initialize the G4PhysicsFreeVector() 546 std::size_t ndata=0; << 462 size_t ndata=0; 547 G4String line; 463 G4String line; 548 while( getline(file, line) ) 464 while( getline(file, line) ) 549 ndata++; 465 ndata++; 550 ndata -= 1; 466 ndata -= 1; 551 //G4cout << "Found: " << ndata << " lines" < 467 //G4cout << "Found: " << ndata << " lines" << G4endl; 552 468 553 file.clear(); 469 file.clear(); 554 file.close(); 470 file.close(); 555 file.open(ost.str().c_str()); 471 file.open(ost.str().c_str()); 556 472 557 G4int readZ =0; 473 G4int readZ =0; 558 std::size_t nShells= 0; << 474 size_t nShells= 0; 559 file >> readZ >> nShells; 475 file >> readZ >> nShells; 560 476 561 if (fVerboseLevel > 3) << 477 if (verboseLevel > 3) 562 G4cout << "Element Z=" << Z << " , nShells 478 G4cout << "Element Z=" << Z << " , nShells = " << nShells << G4endl; 563 479 564 //check the right file is opened. 480 //check the right file is opened. 565 if (readZ != Z || nShells <= 0 || nShells > 481 if (readZ != Z || nShells <= 0 || nShells > 50) //protect nShell against large values 566 { 482 { 567 G4ExceptionDescription ed; 483 G4ExceptionDescription ed; 568 ed << "Corrupted data file for Z=" << Z 484 ed << "Corrupted data file for Z=" << Z << G4endl; 569 G4Exception("G4PenelopePhotoElectricMode 485 G4Exception("G4PenelopePhotoElectricModel::ReadDataFile()", 570 "em0005",FatalException,ed); 486 "em0005",FatalException,ed); 571 return; 487 return; 572 } 488 } 573 G4PhysicsTable* thePhysicsTable = new G4Phys 489 G4PhysicsTable* thePhysicsTable = new G4PhysicsTable(); 574 << 490 575 //the table has to contain nShell+1 G4Physic << 491 //the table has to contain nShell+1 G4PhysicsFreeVectors, 576 //(theTable)[0] --> total cross section 492 //(theTable)[0] --> total cross section 577 //(theTable)[ishell] --> cross section for s 493 //(theTable)[ishell] --> cross section for shell (ishell-1) 578 494 579 //reserve space for the vectors 495 //reserve space for the vectors 580 //everything is log-log 496 //everything is log-log 581 for (std::size_t i=0;i<nShells+1;++i) << 497 for (size_t i=0;i<nShells+1;i++) 582 thePhysicsTable->push_back(new G4PhysicsFr 498 thePhysicsTable->push_back(new G4PhysicsFreeVector(ndata)); 583 499 584 std::size_t k =0; << 500 size_t k =0; 585 for (k=0;k<ndata && !file.eof();++k) << 501 for (k=0;k<ndata && !file.eof();k++) 586 { 502 { 587 G4double energy = 0; 503 G4double energy = 0; 588 G4double aValue = 0; 504 G4double aValue = 0; 589 file >> energy ; 505 file >> energy ; 590 energy *= eV; 506 energy *= eV; 591 G4double logene = G4Log(energy); << 507 G4double logene = std::log(energy); 592 //loop on the columns 508 //loop on the columns 593 for (std::size_t i=0;i<nShells+1;++i) << 509 for (size_t i=0;i<nShells+1;i++) 594 { 510 { 595 file >> aValue; 511 file >> aValue; 596 aValue *= barn; 512 aValue *= barn; 597 G4PhysicsFreeVector* theVec = (G4PhysicsFr << 513 G4PhysicsFreeVector* theVec = (G4PhysicsFreeVector*) ((*thePhysicsTable)[i]); 598 if (aValue < 1e-40*cm2) //protection again 514 if (aValue < 1e-40*cm2) //protection against log(0) 599 aValue = 1e-40*cm2; 515 aValue = 1e-40*cm2; 600 theVec->PutValue(k,logene,G4Log(aValue)); << 516 theVec->PutValue(k,logene,std::log(aValue)); 601 } 517 } 602 } 518 } 603 519 604 if (fVerboseLevel > 2) << 520 if (verboseLevel > 2) 605 { 521 { 606 G4cout << "G4PenelopePhotoElectricModel: << 522 G4cout << "G4PenelopePhotoElectricModel: read " << k << " points for element Z = " 607 << Z << G4endl; 523 << Z << G4endl; 608 } 524 } 609 525 610 fLogAtomicShellXS[Z] = thePhysicsTable; << 526 logAtomicShellXS->insert(std::make_pair(Z,thePhysicsTable)); 611 << 527 612 file.close(); 528 file.close(); 613 return; 529 return; 614 } 530 } 615 531 616 //....oooOO0OOooo........oooOO0OOooo........oo 532 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 617 533 618 std::size_t G4PenelopePhotoElectricModel::GetN << 534 size_t G4PenelopePhotoElectricModel::SelectRandomShell(G4int Z,G4double energy) 619 { 535 { 620 if (!IsMaster()) << 536 G4double logEnergy = std::log(energy); 621 //Should not be here! << 537 622 G4Exception("G4PenelopePhotoElectricModel: << 538 //Check if data have been read (it should be!) 623 "em0100",FatalException,"Worker thread in << 539 if (!logAtomicShellXS->count(Z)) >> 540 { >> 541 G4ExceptionDescription ed; >> 542 ed << "Cannot find shell cross section data for Z=" << Z << G4endl; >> 543 G4Exception("G4PenelopePhotoElectricModel::SelectRandomShell()", >> 544 "em2038",FatalException,ed); >> 545 } >> 546 >> 547 size_t shellIndex = 0; >> 548 >> 549 G4PhysicsTable* theTable = logAtomicShellXS->find(Z)->second; >> 550 >> 551 G4DataVector* tempVector = new G4DataVector(); >> 552 >> 553 G4double sum = 0; >> 554 //loop on shell partial XS, retrieve the value for the given energy and store on >> 555 //a temporary vector >> 556 tempVector->push_back(sum); //first element is zero >> 557 >> 558 G4PhysicsFreeVector* totalXSLog = (G4PhysicsFreeVector*) (*theTable)[0]; >> 559 G4double logXS = totalXSLog->Value(logEnergy); >> 560 G4double totalXS = std::exp(logXS); >> 561 >> 562 //Notice: totalXS is the total cross section and it does *not* correspond to >> 563 //the sum of partialXS's, since these include only K, L and M shells. >> 564 // >> 565 // Therefore, here one have to consider the possibility of ionisation of >> 566 // an outer shell. Conventionally, it is indicated with id=10 in Penelope >> 567 // >> 568 >> 569 for (size_t k=1;k<theTable->entries();k++) >> 570 { >> 571 G4PhysicsFreeVector* partialXSLog = (G4PhysicsFreeVector*) (*theTable)[k]; >> 572 G4double logXS = partialXSLog->Value(logEnergy); >> 573 G4double partialXS = std::exp(logXS); >> 574 sum += partialXS; >> 575 tempVector->push_back(sum); >> 576 } >> 577 >> 578 tempVector->push_back(totalXS); //last element 624 579 >> 580 G4double random = G4UniformRand()*totalXS; >> 581 >> 582 /* >> 583 for (size_t i=0;i<tempVector->size(); i++) >> 584 G4cout << i << " " << (*tempVector)[i]/totalXS << G4endl; >> 585 */ >> 586 >> 587 //locate bin of tempVector >> 588 //Now one has to sample according to the elements in tempVector >> 589 //This gives the left edge of the interval... >> 590 size_t lowerBound = 0; >> 591 size_t upperBound = tempVector->size()-1; >> 592 while (lowerBound <= upperBound) >> 593 { >> 594 size_t midBin = (lowerBound + upperBound)/2; >> 595 if( random < (*tempVector)[midBin]) >> 596 upperBound = midBin-1; >> 597 else >> 598 lowerBound = midBin+1; >> 599 } >> 600 >> 601 shellIndex = upperBound; >> 602 >> 603 delete tempVector; >> 604 return shellIndex; >> 605 } >> 606 >> 607 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 608 >> 609 size_t G4PenelopePhotoElectricModel::GetNumberOfShellXS(G4int Z) >> 610 { 625 //read data files 611 //read data files 626 if (!fLogAtomicShellXS[Z]) << 612 if (!logAtomicShellXS->count(Z)) 627 ReadDataFile(Z); 613 ReadDataFile(Z); 628 //now it should be ok 614 //now it should be ok 629 if (!fLogAtomicShellXS[Z]) << 615 if (!logAtomicShellXS->count(Z)) 630 { 616 { 631 G4ExceptionDescription ed; 617 G4ExceptionDescription ed; 632 ed << "Cannot find shell cross section 618 ed << "Cannot find shell cross section data for Z=" << Z << G4endl; 633 G4Exception("G4PenelopePhotoElectricMod 619 G4Exception("G4PenelopePhotoElectricModel::GetNumberOfShellXS()", 634 "em2038",FatalException,ed); 620 "em2038",FatalException,ed); 635 } 621 } 636 //one vector is allocated for the _total_ cr 622 //one vector is allocated for the _total_ cross section 637 std::size_t nEntries = fLogAtomicShellXS[Z]- << 623 size_t nEntries = logAtomicShellXS->find(Z)->second->entries(); 638 return (nEntries-1); 624 return (nEntries-1); 639 } 625 } 640 626 641 //....oooOO0OOooo........oooOO0OOooo........oo 627 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 642 628 643 G4double G4PenelopePhotoElectricModel::GetShel << 629 G4double G4PenelopePhotoElectricModel::GetShellCrossSection(G4int Z,size_t shellID,G4double energy) 644 { 630 { 645 //this forces also the loading of the data 631 //this forces also the loading of the data 646 std::size_t entries = GetNumberOfShellXS(Z); << 632 size_t entries = GetNumberOfShellXS(Z); 647 633 648 if (shellID >= entries) 634 if (shellID >= entries) 649 { 635 { 650 G4cout << "Element Z=" << Z << " has dat 636 G4cout << "Element Z=" << Z << " has data for " << entries << " shells only" << G4endl; 651 G4cout << "so shellID should be from 0 t 637 G4cout << "so shellID should be from 0 to " << entries-1 << G4endl; 652 return 0; 638 return 0; 653 } 639 } 654 << 640 655 G4PhysicsTable* theTable = fLogAtomicShellX << 641 G4PhysicsTable* theTable = logAtomicShellXS->find(Z)->second; 656 //[0] is the total XS, shellID is in the ele 642 //[0] is the total XS, shellID is in the element [shellID+1] 657 G4PhysicsFreeVector* totalXSLog = (G4Physics 643 G4PhysicsFreeVector* totalXSLog = (G4PhysicsFreeVector*) (*theTable)[shellID+1]; 658 << 644 659 if (!totalXSLog) 645 if (!totalXSLog) 660 { 646 { 661 G4Exception("G4PenelopePhotoElectricMod 647 G4Exception("G4PenelopePhotoElectricModel::GetShellCrossSection()", 662 "em2039",FatalException, 648 "em2039",FatalException, 663 "Unable to retrieve the total cross sec 649 "Unable to retrieve the total cross section table"); 664 return 0; 650 return 0; 665 } 651 } 666 G4double logene = G4Log(energy); << 652 G4double logene = std::log(energy); 667 G4double logXS = totalXSLog->Value(logene); 653 G4double logXS = totalXSLog->Value(logene); 668 G4double cross = G4Exp(logXS); << 654 G4double cross = std::exp(logXS); 669 if (cross < 2e-40*cm2) cross = 0; 655 if (cross < 2e-40*cm2) cross = 0; 670 return cross; 656 return cross; 671 } 657 } 672 658 673 //....oooOO0OOooo........oooOO0OOooo........oo 659 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 674 660 675 G4String G4PenelopePhotoElectricModel::WriteTa << 661 G4String G4PenelopePhotoElectricModel::WriteTargetShell(size_t shellID) 676 { 662 { 677 G4String theShell = "outer shell"; 663 G4String theShell = "outer shell"; 678 if (shellID == 0) 664 if (shellID == 0) 679 theShell = "K"; 665 theShell = "K"; 680 else if (shellID == 1) 666 else if (shellID == 1) 681 theShell = "L1"; 667 theShell = "L1"; 682 else if (shellID == 2) 668 else if (shellID == 2) 683 theShell = "L2"; 669 theShell = "L2"; 684 else if (shellID == 3) 670 else if (shellID == 3) 685 theShell = "L3"; 671 theShell = "L3"; 686 else if (shellID == 4) 672 else if (shellID == 4) 687 theShell = "M1"; 673 theShell = "M1"; 688 else if (shellID == 5) 674 else if (shellID == 5) 689 theShell = "M2"; 675 theShell = "M2"; 690 else if (shellID == 6) 676 else if (shellID == 6) 691 theShell = "M3"; 677 theShell = "M3"; 692 else if (shellID == 7) 678 else if (shellID == 7) 693 theShell = "M4"; 679 theShell = "M4"; 694 else if (shellID == 8) 680 else if (shellID == 8) 695 theShell = "M5"; 681 theShell = "M5"; 696 << 682 697 return theShell; 683 return theShell; 698 } << 699 << 700 //....oooOO0OOooo........oooOO0OOooo........oo << 701 << 702 void G4PenelopePhotoElectricModel::SetParticle << 703 { << 704 if(!fParticle) { << 705 fParticle = p; << 706 } << 707 } << 708 << 709 //....oooOO0OOooo........oooOO0OOooo........oo << 710 << 711 std::size_t G4PenelopePhotoElectricModel::Sele << 712 { << 713 G4double logEnergy = G4Log(energy); << 714 << 715 //Check if data have been read (it should be << 716 if (!fLogAtomicShellXS[Z]) << 717 { << 718 G4ExceptionDescription ed; << 719 ed << "Cannot find shell cross section << 720 G4Exception("G4PenelopePhotoElectricMod << 721 "em2038",FatalException,ed); << 722 } << 723 << 724 G4PhysicsTable* theTable = fLogAtomicShellX << 725 << 726 G4double sum = 0; << 727 G4PhysicsFreeVector* totalXSLog = (G4Physics << 728 G4double logXS = totalXSLog->Value(logEnergy << 729 G4double totalXS = G4Exp(logXS); << 730 << 731 //Notice: totalXS is the total cross section << 732 //the sum of partialXS's, since these includ << 733 // << 734 // Therefore, here one have to consider the << 735 // an outer shell. Conventionally, it is ind << 736 // << 737 G4double random = G4UniformRand()*totalXS; << 738 << 739 for (std::size_t k=1;k<theTable->entries();+ << 740 { << 741 //Add one shell << 742 G4PhysicsFreeVector* partialXSLog = (G4P << 743 G4double logXSLocal = partialXSLog->Valu << 744 G4double partialXS = G4Exp(logXSLocal); << 745 sum += partialXS; << 746 if (random <= sum) << 747 return k-1; << 748 } << 749 //none of the shells K, L, M: return outer s << 750 return 9; << 751 } 684 } 752 685