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