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 // 26 // 27 // ------------------------------------------- 27 // ------------------------------------------------------------------- 28 // 28 // 29 // GEANT4 Class file 29 // GEANT4 Class file 30 // 30 // 31 // 31 // 32 // File name: G4EmBiasingManager 32 // File name: G4EmBiasingManager 33 // 33 // 34 // Author: Vladimir Ivanchenko 34 // Author: Vladimir Ivanchenko 35 // 35 // 36 // Creation date: 28.07.2011 36 // Creation date: 28.07.2011 37 // 37 // 38 // Modifications: 38 // Modifications: 39 // 39 // 40 // 31-05-12 D. Sawkey put back in high energy 40 // 31-05-12 D. Sawkey put back in high energy limit for brem, russian roulette 41 // 30-05-12 D. Sawkey brem split gammas are u 41 // 30-05-12 D. Sawkey brem split gammas are unique; do weight tests for 42 // brem, russian roulette 42 // brem, russian roulette 43 // ------------------------------------------- 43 // ------------------------------------------------------------------- 44 // 44 // 45 //....oooOO0OOooo........oooOO0OOooo........oo 45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 46 //....oooOO0OOooo........oooOO0OOooo........oo 46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 47 47 48 #include "G4EmBiasingManager.hh" 48 #include "G4EmBiasingManager.hh" 49 #include "G4SystemOfUnits.hh" 49 #include "G4SystemOfUnits.hh" 50 #include "G4PhysicalConstants.hh" 50 #include "G4PhysicalConstants.hh" 51 #include "G4MaterialCutsCouple.hh" 51 #include "G4MaterialCutsCouple.hh" 52 #include "G4ProductionCutsTable.hh" 52 #include "G4ProductionCutsTable.hh" 53 #include "G4ProductionCuts.hh" 53 #include "G4ProductionCuts.hh" 54 #include "G4Region.hh" 54 #include "G4Region.hh" 55 #include "G4RegionStore.hh" 55 #include "G4RegionStore.hh" 56 #include "G4Track.hh" 56 #include "G4Track.hh" 57 #include "G4Electron.hh" 57 #include "G4Electron.hh" 58 #include "G4Gamma.hh" 58 #include "G4Gamma.hh" 59 #include "G4VEmModel.hh" 59 #include "G4VEmModel.hh" 60 #include "G4LossTableManager.hh" 60 #include "G4LossTableManager.hh" 61 #include "G4ParticleChangeForLoss.hh" 61 #include "G4ParticleChangeForLoss.hh" 62 #include "G4ParticleChangeForGamma.hh" 62 #include "G4ParticleChangeForGamma.hh" 63 #include "G4EmParameters.hh" 63 #include "G4EmParameters.hh" 64 64 65 //....oooOO0OOooo........oooOO0OOooo........oo 65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 66 66 67 G4EmBiasingManager::G4EmBiasingManager() 67 G4EmBiasingManager::G4EmBiasingManager() 68 : fDirectionalSplittingTarget(0.0,0.0,0.0) 68 : fDirectionalSplittingTarget(0.0,0.0,0.0) 69 { 69 { 70 fSafetyMin = 1.e-6*mm; 70 fSafetyMin = 1.e-6*mm; 71 theElectron = G4Electron::Electron(); 71 theElectron = G4Electron::Electron(); 72 theGamma = G4Gamma::Gamma(); 72 theGamma = G4Gamma::Gamma(); 73 } 73 } 74 74 75 //....oooOO0OOooo........oooOO0OOooo........oo 75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 76 76 77 G4EmBiasingManager::~G4EmBiasingManager() = de << 77 G4EmBiasingManager::~G4EmBiasingManager() >> 78 {} 78 79 79 //....oooOO0OOooo........oooOO0OOooo........oo 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 80 81 81 void G4EmBiasingManager::Initialise(const G4Pa 82 void G4EmBiasingManager::Initialise(const G4ParticleDefinition& part, 82 const G4St 83 const G4String& procName, G4int verbose) 83 { 84 { 84 //G4cout << "G4EmBiasingManager::Initialise 85 //G4cout << "G4EmBiasingManager::Initialise for " 85 // << part.GetParticleName() 86 // << part.GetParticleName() 86 // << " and " << procName << G4endl; 87 // << " and " << procName << G4endl; 87 const G4ProductionCutsTable* theCoupleTable= 88 const G4ProductionCutsTable* theCoupleTable= 88 G4ProductionCutsTable::GetProductionCutsTa 89 G4ProductionCutsTable::GetProductionCutsTable(); 89 G4int numOfCouples = (G4int)theCoupleTable-> << 90 size_t numOfCouples = theCoupleTable->GetTableSize(); 90 91 91 if(0 < nForcedRegions) { idxForcedCouple.res 92 if(0 < nForcedRegions) { idxForcedCouple.resize(numOfCouples, -1); } 92 if(0 < nSecBiasedRegions) { idxSecBiasedCoup 93 if(0 < nSecBiasedRegions) { idxSecBiasedCouple.resize(numOfCouples, -1); } 93 94 94 // Deexcitation 95 // Deexcitation 95 for (G4int j=0; j<numOfCouples; ++j) { << 96 for (size_t j=0; j<numOfCouples; ++j) { 96 const G4MaterialCutsCouple* couple = 97 const G4MaterialCutsCouple* couple = 97 theCoupleTable->GetMaterialCutsCouple(j) 98 theCoupleTable->GetMaterialCutsCouple(j); 98 const G4ProductionCuts* pcuts = couple->Ge 99 const G4ProductionCuts* pcuts = couple->GetProductionCuts(); 99 if(0 < nForcedRegions) { 100 if(0 < nForcedRegions) { 100 for(G4int i=0; i<nForcedRegions; ++i) { 101 for(G4int i=0; i<nForcedRegions; ++i) { 101 if(forcedRegions[i]) { 102 if(forcedRegions[i]) { 102 if(pcuts == forcedRegions[i]->GetPro 103 if(pcuts == forcedRegions[i]->GetProductionCuts()) { 103 idxForcedCouple[j] = i; 104 idxForcedCouple[j] = i; 104 break; 105 break; 105 } 106 } 106 } 107 } 107 } 108 } 108 } 109 } 109 if(0 < nSecBiasedRegions) { 110 if(0 < nSecBiasedRegions) { 110 for(G4int i=0; i<nSecBiasedRegions; ++i) 111 for(G4int i=0; i<nSecBiasedRegions; ++i) { 111 if(secBiasedRegions[i]) { 112 if(secBiasedRegions[i]) { 112 if(pcuts == secBiasedRegions[i]->Get 113 if(pcuts == secBiasedRegions[i]->GetProductionCuts()) { 113 idxSecBiasedCouple[j] = i; 114 idxSecBiasedCouple[j] = i; 114 break; 115 break; 115 } 116 } 116 } 117 } 117 } 118 } 118 } 119 } 119 } 120 } 120 121 121 G4EmParameters* param = G4EmParameters::Inst 122 G4EmParameters* param = G4EmParameters::Instance(); 122 SetDirectionalSplitting(param->GetDirectiona 123 SetDirectionalSplitting(param->GetDirectionalSplitting()); 123 if (fDirectionalSplitting) { 124 if (fDirectionalSplitting) { 124 SetDirectionalSplittingTarget(param->GetDi 125 SetDirectionalSplittingTarget(param->GetDirectionalSplittingTarget()); 125 SetDirectionalSplittingRadius(param->GetDi 126 SetDirectionalSplittingRadius(param->GetDirectionalSplittingRadius()); 126 } 127 } 127 128 128 if (nForcedRegions > 0 && 0 < verbose) { 129 if (nForcedRegions > 0 && 0 < verbose) { 129 G4cout << " Forced Interaction is activate 130 G4cout << " Forced Interaction is activated for " 130 << part.GetParticleName() << " and 131 << part.GetParticleName() << " and " 131 << procName 132 << procName 132 << " inside G4Regions: " << G4endl; 133 << " inside G4Regions: " << G4endl; 133 for (G4int i=0; i<nForcedRegions; ++i) { 134 for (G4int i=0; i<nForcedRegions; ++i) { 134 const G4Region* r = forcedRegions[i]; 135 const G4Region* r = forcedRegions[i]; 135 if(r) { G4cout << " " << r->Ge 136 if(r) { G4cout << " " << r->GetName() << G4endl; } 136 } 137 } 137 } 138 } 138 if (nSecBiasedRegions > 0 && 0 < verbose) { 139 if (nSecBiasedRegions > 0 && 0 < verbose) { 139 G4cout << " Secondary biasing is activated 140 G4cout << " Secondary biasing is activated for " 140 << part.GetParticleName() << " and 141 << part.GetParticleName() << " and " 141 << procName 142 << procName 142 << " inside G4Regions: " << G4endl; 143 << " inside G4Regions: " << G4endl; 143 for (G4int i=0; i<nSecBiasedRegions; ++i) 144 for (G4int i=0; i<nSecBiasedRegions; ++i) { 144 const G4Region* r = secBiasedRegions[i]; 145 const G4Region* r = secBiasedRegions[i]; 145 if(r) { 146 if(r) { 146 G4cout << " " << r->GetName( 147 G4cout << " " << r->GetName() 147 << " BiasingWeight= " << secBi 148 << " BiasingWeight= " << secBiasedWeight[i] << G4endl; 148 } 149 } 149 } 150 } 150 if (fDirectionalSplitting) { 151 if (fDirectionalSplitting) { 151 G4cout << " Directional splitting ac 152 G4cout << " Directional splitting activated, with target position: " 152 << fDirectionalSplittingTarget/cm 153 << fDirectionalSplittingTarget/cm 153 << " cm; radius: " 154 << " cm; radius: " 154 << fDirectionalSplittingRadius/cm 155 << fDirectionalSplittingRadius/cm 155 << "cm." << G4endl; 156 << "cm." << G4endl; 156 } 157 } 157 } 158 } 158 } 159 } 159 160 160 //....oooOO0OOooo........oooOO0OOooo........oo 161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 161 162 162 void G4EmBiasingManager::ActivateForcedInterac 163 void G4EmBiasingManager::ActivateForcedInteraction(G4double val, 163 164 const G4String& rname) 164 { 165 { 165 G4RegionStore* regionStore = G4RegionStore:: 166 G4RegionStore* regionStore = G4RegionStore::GetInstance(); 166 G4String name = rname; 167 G4String name = rname; 167 if(name == "" || name == "world" || name == 168 if(name == "" || name == "world" || name == "World") { 168 name = "DefaultRegionForTheWorld"; 169 name = "DefaultRegionForTheWorld"; 169 } 170 } 170 const G4Region* reg = regionStore->GetRegion 171 const G4Region* reg = regionStore->GetRegion(name, false); 171 if(!reg) { 172 if(!reg) { 172 G4cout << "### G4EmBiasingManager::ForcedI 173 G4cout << "### G4EmBiasingManager::ForcedInteraction WARNING: " 173 << " G4Region <" 174 << " G4Region <" 174 << rname << "> is unknown" << G4end 175 << rname << "> is unknown" << G4endl; 175 return; 176 return; 176 } 177 } 177 178 178 // the region is in the list 179 // the region is in the list 179 if (0 < nForcedRegions) { 180 if (0 < nForcedRegions) { 180 for (G4int i=0; i<nForcedRegions; ++i) { 181 for (G4int i=0; i<nForcedRegions; ++i) { 181 if (reg == forcedRegions[i]) { 182 if (reg == forcedRegions[i]) { 182 lengthForRegion[i] = val; 183 lengthForRegion[i] = val; 183 return; 184 return; 184 } 185 } 185 } 186 } 186 } 187 } 187 if(val < 0.0) { 188 if(val < 0.0) { 188 G4cout << "### G4EmBiasingManager::ForcedI 189 G4cout << "### G4EmBiasingManager::ForcedInteraction WARNING: " 189 << val << " < 0.0, so no activation 190 << val << " < 0.0, so no activation for the G4Region <" 190 << rname << ">" << G4endl; 191 << rname << ">" << G4endl; 191 return; 192 return; 192 } 193 } 193 194 194 // new region 195 // new region 195 forcedRegions.push_back(reg); 196 forcedRegions.push_back(reg); 196 lengthForRegion.push_back(val); 197 lengthForRegion.push_back(val); 197 ++nForcedRegions; 198 ++nForcedRegions; 198 } 199 } 199 200 200 //....oooOO0OOooo........oooOO0OOooo........oo 201 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 201 202 202 void 203 void 203 G4EmBiasingManager::ActivateSecondaryBiasing(c 204 G4EmBiasingManager::ActivateSecondaryBiasing(const G4String& rname, 204 G 205 G4double factor, 205 G 206 G4double energyLimit) 206 { 207 { 207 //G4cout << "G4EmBiasingManager::ActivateSec 208 //G4cout << "G4EmBiasingManager::ActivateSecondaryBiasing: " 208 // << rname << " F= " << factor << " 209 // << rname << " F= " << factor << " E(MeV)= " << energyLimit/MeV 209 // << G4endl; 210 // << G4endl; 210 G4RegionStore* regionStore = G4RegionStore:: 211 G4RegionStore* regionStore = G4RegionStore::GetInstance(); 211 G4String name = rname; 212 G4String name = rname; 212 if(name == "" || name == "world" || name == 213 if(name == "" || name == "world" || name == "World") { 213 name = "DefaultRegionForTheWorld"; 214 name = "DefaultRegionForTheWorld"; 214 } 215 } 215 const G4Region* reg = regionStore->GetRegion 216 const G4Region* reg = regionStore->GetRegion(name, false); 216 if(!reg) { 217 if(!reg) { 217 G4cout << "### G4EmBiasingManager::Activat 218 G4cout << "### G4EmBiasingManager::ActivateBremsstrahlungSplitting " 218 << "WARNING: G4Region <" 219 << "WARNING: G4Region <" 219 << rname << "> is unknown" << G4end 220 << rname << "> is unknown" << G4endl; 220 return; 221 return; 221 } 222 } 222 223 223 // Range cut 224 // Range cut 224 G4int nsplit = 0; 225 G4int nsplit = 0; 225 G4double w = factor; 226 G4double w = factor; 226 227 227 // splitting 228 // splitting 228 if(factor >= 1.0) { 229 if(factor >= 1.0) { 229 nsplit = G4lrint(factor); 230 nsplit = G4lrint(factor); 230 w = 1.0/G4double(nsplit); 231 w = 1.0/G4double(nsplit); 231 232 232 // Russian roulette 233 // Russian roulette 233 } else if(0.0 < factor) { 234 } else if(0.0 < factor) { 234 nsplit = 1; 235 nsplit = 1; 235 w = 1.0/factor; 236 w = 1.0/factor; 236 } 237 } 237 238 238 // the region is in the list - overwrite par 239 // the region is in the list - overwrite parameters 239 if (0 < nSecBiasedRegions) { 240 if (0 < nSecBiasedRegions) { 240 for (G4int i=0; i<nSecBiasedRegions; ++i) 241 for (G4int i=0; i<nSecBiasedRegions; ++i) { 241 if (reg == secBiasedRegions[i]) { 242 if (reg == secBiasedRegions[i]) { 242 secBiasedWeight[i] = w; 243 secBiasedWeight[i] = w; 243 nBremSplitting[i] = nsplit; 244 nBremSplitting[i] = nsplit; 244 secBiasedEnegryLimit[i] = energyLimit; 245 secBiasedEnegryLimit[i] = energyLimit; 245 return; 246 return; 246 } 247 } 247 } 248 } 248 } 249 } 249 /* 250 /* 250 G4cout << "### G4EmBiasingManager::Activat 251 G4cout << "### G4EmBiasingManager::ActivateSecondaryBiasing: " 251 << " nsplit= " << nsplit << " for t 252 << " nsplit= " << nsplit << " for the G4Region <" 252 << rname << ">" << G4endl; 253 << rname << ">" << G4endl; 253 */ 254 */ 254 255 255 // new region 256 // new region 256 secBiasedRegions.push_back(reg); 257 secBiasedRegions.push_back(reg); 257 secBiasedWeight.push_back(w); 258 secBiasedWeight.push_back(w); 258 nBremSplitting.push_back(nsplit); 259 nBremSplitting.push_back(nsplit); 259 secBiasedEnegryLimit.push_back(energyLimit); 260 secBiasedEnegryLimit.push_back(energyLimit); 260 ++nSecBiasedRegions; 261 ++nSecBiasedRegions; 261 //G4cout << "nSecBiasedRegions= " << nSecBia 262 //G4cout << "nSecBiasedRegions= " << nSecBiasedRegions << G4endl; 262 } 263 } 263 264 264 //....oooOO0OOooo........oooOO0OOooo........oo 265 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 265 266 266 G4double G4EmBiasingManager::GetStepLimit(G4in 267 G4double G4EmBiasingManager::GetStepLimit(G4int coupleIdx, 267 G4do 268 G4double previousStep) 268 { 269 { 269 if(startTracking) { 270 if(startTracking) { 270 startTracking = false; 271 startTracking = false; 271 G4int i = idxForcedCouple[coupleIdx]; 272 G4int i = idxForcedCouple[coupleIdx]; 272 if(i < 0) { 273 if(i < 0) { 273 currentStepLimit = DBL_MAX; 274 currentStepLimit = DBL_MAX; 274 } else { 275 } else { 275 currentStepLimit = lengthForRegion[i]; 276 currentStepLimit = lengthForRegion[i]; 276 if(currentStepLimit > 0.0) { currentStep 277 if(currentStepLimit > 0.0) { currentStepLimit *= G4UniformRand(); } 277 } 278 } 278 } else { 279 } else { 279 currentStepLimit -= previousStep; 280 currentStepLimit -= previousStep; 280 } 281 } 281 if(currentStepLimit < 0.0) { currentStepLimi 282 if(currentStepLimit < 0.0) { currentStepLimit = 0.0; } 282 return currentStepLimit; 283 return currentStepLimit; 283 } 284 } 284 285 285 //....oooOO0OOooo........oooOO0OOooo........oo 286 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 286 287 287 G4double 288 G4double 288 G4EmBiasingManager::ApplySecondaryBiasing( 289 G4EmBiasingManager::ApplySecondaryBiasing( 289 std::vector<G4DynamicParti 290 std::vector<G4DynamicParticle*>& vd, 290 const G4Track& track, 291 const G4Track& track, 291 G4VEmModel* currentModel, 292 G4VEmModel* currentModel, 292 G4ParticleChangeForLoss* p 293 G4ParticleChangeForLoss* pPartChange, 293 G4double& eloss, 294 G4double& eloss, 294 G4int coupleIdx, 295 G4int coupleIdx, 295 G4double tcut, 296 G4double tcut, 296 G4double safety) 297 G4double safety) 297 { 298 { 298 G4int index = idxSecBiasedCouple[coupleIdx]; 299 G4int index = idxSecBiasedCouple[coupleIdx]; 299 G4double weight = 1.; 300 G4double weight = 1.; 300 if(0 <= index) { 301 if(0 <= index) { 301 std::size_t n = vd.size(); << 302 size_t n = vd.size(); 302 303 303 // the check cannot be applied per seconda 304 // the check cannot be applied per secondary particle 304 // because weight correction is common, so 305 // because weight correction is common, so the first 305 // secondary is checked 306 // secondary is checked 306 if((0 < n && vd[0]->GetKineticEnergy() < s 307 if((0 < n && vd[0]->GetKineticEnergy() < secBiasedEnegryLimit[index]) 307 || fDirectionalSplitting) { 308 || fDirectionalSplitting) { 308 309 309 G4int nsplit = nBremSplitting[index]; 310 G4int nsplit = nBremSplitting[index]; 310 311 311 // Range cut 312 // Range cut 312 if(0 == nsplit) { 313 if(0 == nsplit) { 313 if(safety > fSafetyMin) { ApplyRangeCu 314 if(safety > fSafetyMin) { ApplyRangeCut(vd, track, eloss, safety); } 314 315 315 // Russian Roulette 316 // Russian Roulette 316 } else if(1 == nsplit) { 317 } else if(1 == nsplit) { 317 weight = ApplyRussianRoulette(vd, inde 318 weight = ApplyRussianRoulette(vd, index); 318 319 319 // Splitting 320 // Splitting 320 } else { 321 } else { 321 if (fDirectionalSplitting) { 322 if (fDirectionalSplitting) { 322 weight = ApplyDirectionalSplitting(v 323 weight = ApplyDirectionalSplitting(vd, track, currentModel, index, tcut); 323 } else { 324 } else { 324 G4double tmpEnergy = pPartChange->Ge 325 G4double tmpEnergy = pPartChange->GetProposedKineticEnergy(); 325 G4ThreeVector tmpMomDir = pPartChang 326 G4ThreeVector tmpMomDir = pPartChange->GetProposedMomentumDirection(); 326 327 327 weight = ApplySplitting(vd, track, c 328 weight = ApplySplitting(vd, track, currentModel, index, tcut); 328 329 329 pPartChange->SetProposedKineticEnerg 330 pPartChange->SetProposedKineticEnergy(tmpEnergy); 330 pPartChange->ProposeMomentumDirectio 331 pPartChange->ProposeMomentumDirection(tmpMomDir); 331 } 332 } 332 } 333 } 333 } 334 } 334 } 335 } 335 return weight; 336 return weight; 336 } 337 } 337 338 338 //....oooOO0OOooo........oooOO0OOooo........oo 339 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 339 340 340 G4double 341 G4double 341 G4EmBiasingManager::ApplySecondaryBiasing( 342 G4EmBiasingManager::ApplySecondaryBiasing( 342 std::vector<G4DynamicParticl 343 std::vector<G4DynamicParticle*>& vd, 343 const G4Track& track, 344 const G4Track& track, 344 G4VEmModel* currentModel, 345 G4VEmModel* currentModel, 345 G4ParticleChangeForGamma* pP 346 G4ParticleChangeForGamma* pPartChange, 346 G4double& eloss, 347 G4double& eloss, 347 G4int coupleIdx, 348 G4int coupleIdx, 348 G4double tcut, 349 G4double tcut, 349 G4double safety) 350 G4double safety) 350 { 351 { 351 G4int index = idxSecBiasedCouple[coupleIdx]; 352 G4int index = idxSecBiasedCouple[coupleIdx]; 352 G4double weight = 1.; 353 G4double weight = 1.; 353 if(0 <= index) { 354 if(0 <= index) { 354 std::size_t n = vd.size(); << 355 size_t n = vd.size(); 355 356 356 // the check cannot be applied per seconda 357 // the check cannot be applied per secondary particle 357 // because weight correction is common, so 358 // because weight correction is common, so the first 358 // secondary is checked 359 // secondary is checked 359 if((0 < n && vd[0]->GetKineticEnergy() < s 360 if((0 < n && vd[0]->GetKineticEnergy() < secBiasedEnegryLimit[index]) 360 || fDirectionalSplitting) { 361 || fDirectionalSplitting) { 361 362 362 G4int nsplit = nBremSplitting[index]; 363 G4int nsplit = nBremSplitting[index]; 363 364 364 // Range cut 365 // Range cut 365 if(0 == nsplit) { 366 if(0 == nsplit) { 366 if(safety > fSafetyMin) { ApplyRangeCu 367 if(safety > fSafetyMin) { ApplyRangeCut(vd, track, eloss, safety); } 367 368 368 // Russian Roulette 369 // Russian Roulette 369 } else if(1 == nsplit) { 370 } else if(1 == nsplit) { 370 weight = ApplyRussianRoulette(vd, inde 371 weight = ApplyRussianRoulette(vd, index); 371 372 372 // Splitting 373 // Splitting 373 } else { 374 } else { 374 if (fDirectionalSplitting) { 375 if (fDirectionalSplitting) { 375 weight = ApplyDirectionalSplitting(v 376 weight = ApplyDirectionalSplitting(vd, track, currentModel, 376 index, tcu 377 index, tcut, pPartChange); 377 } else { 378 } else { 378 G4double tmpEnergy = pPartChange->Ge 379 G4double tmpEnergy = pPartChange->GetProposedKineticEnergy(); 379 G4ThreeVector tmpMomDir = pPartChang 380 G4ThreeVector tmpMomDir = pPartChange->GetProposedMomentumDirection(); 380 381 381 weight = ApplySplitting(vd, track, c 382 weight = ApplySplitting(vd, track, currentModel, index, tcut); 382 383 383 pPartChange->SetProposedKineticEnerg 384 pPartChange->SetProposedKineticEnergy(tmpEnergy); 384 pPartChange->ProposeMomentumDirectio 385 pPartChange->ProposeMomentumDirection(tmpMomDir); 385 } 386 } 386 } 387 } 387 } 388 } 388 } 389 } 389 return weight; 390 return weight; 390 } 391 } 391 392 392 //....oooOO0OOooo........oooOO0OOooo........oo 393 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 393 394 394 G4double 395 G4double 395 G4EmBiasingManager::ApplySecondaryBiasing(std: 396 G4EmBiasingManager::ApplySecondaryBiasing(std::vector<G4Track*>& track, 396 G4in 397 G4int coupleIdx) 397 { 398 { 398 G4int index = idxSecBiasedCouple[coupleIdx]; 399 G4int index = idxSecBiasedCouple[coupleIdx]; 399 G4double weight = 1.; 400 G4double weight = 1.; 400 if(0 <= index) { 401 if(0 <= index) { 401 std::size_t n = track.size(); << 402 size_t n = track.size(); 402 403 403 // the check cannot be applied per seconda 404 // the check cannot be applied per secondary particle 404 // because weight correction is common, so 405 // because weight correction is common, so the first 405 // secondary is checked 406 // secondary is checked 406 if(0 < n && track[0]->GetKineticEnergy() < 407 if(0 < n && track[0]->GetKineticEnergy() < secBiasedEnegryLimit[index]) { 407 408 408 G4int nsplit = nBremSplitting[index]; 409 G4int nsplit = nBremSplitting[index]; 409 410 410 // Russian Roulette only 411 // Russian Roulette only 411 if(1 == nsplit) { 412 if(1 == nsplit) { 412 weight = secBiasedWeight[index]; 413 weight = secBiasedWeight[index]; 413 for(std::size_t k=0; k<n; ++k) { << 414 for(size_t k=0; k<n; ++k) { 414 if(G4UniformRand()*weight > 1.0) { 415 if(G4UniformRand()*weight > 1.0) { 415 const G4Track* t = track[k]; 416 const G4Track* t = track[k]; 416 delete t; 417 delete t; 417 track[k] = nullptr; << 418 track[k] = 0; 418 } 419 } 419 } 420 } 420 } 421 } 421 } 422 } 422 } 423 } 423 return weight; 424 return weight; 424 } 425 } 425 426 426 //....oooOO0OOooo........oooOO0OOooo........oo 427 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 427 428 428 void 429 void 429 G4EmBiasingManager::ApplyRangeCut(std::vector< 430 G4EmBiasingManager::ApplyRangeCut(std::vector<G4DynamicParticle*>& vd, 430 const G4Trac 431 const G4Track& track, 431 G4double& el 432 G4double& eloss, G4double safety) 432 { 433 { 433 std::size_t n = vd.size(); << 434 size_t n = vd.size(); 434 if(!eIonisation) { 435 if(!eIonisation) { 435 eIonisation = 436 eIonisation = 436 G4LossTableManager::Instance()->GetEnerg 437 G4LossTableManager::Instance()->GetEnergyLossProcess(theElectron); 437 } 438 } 438 if(eIonisation) { 439 if(eIonisation) { 439 for(std::size_t k=0; k<n; ++k) { << 440 for(size_t k=0; k<n; ++k) { 440 const G4DynamicParticle* dp = vd[k]; 441 const G4DynamicParticle* dp = vd[k]; 441 if(dp->GetDefinition() == theElectron) { 442 if(dp->GetDefinition() == theElectron) { 442 G4double e = dp->GetKineticEnergy(); 443 G4double e = dp->GetKineticEnergy(); 443 if(eIonisation->GetRange(e, track.GetM 444 if(eIonisation->GetRange(e, track.GetMaterialCutsCouple()) < safety) { 444 eloss += e; 445 eloss += e; 445 delete dp; 446 delete dp; 446 vd[k] = nullptr; << 447 vd[k] = 0; 447 } 448 } 448 } 449 } 449 } 450 } 450 } 451 } 451 } 452 } 452 453 453 //....oooOO0OOooo........oooOO0OOooo........oo 454 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 454 455 455 G4bool G4EmBiasingManager::CheckDirection(G4Th 456 G4bool G4EmBiasingManager::CheckDirection(G4ThreeVector pos, 456 G4Th 457 G4ThreeVector momdir) const 457 { 458 { 458 G4ThreeVector delta = fDirectionalSplittingT 459 G4ThreeVector delta = fDirectionalSplittingTarget - pos; 459 G4double angle = momdir.angle(delta); 460 G4double angle = momdir.angle(delta); 460 G4double dist = delta.cross(momdir).mag(); 461 G4double dist = delta.cross(momdir).mag(); 461 if (dist <= fDirectionalSplittingRadius && a 462 if (dist <= fDirectionalSplittingRadius && angle < halfpi) { 462 return true; 463 return true; 463 } 464 } 464 return false; 465 return false; 465 } 466 } 466 467 467 //....oooOO0OOooo........oooOO0OOooo........oo 468 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 468 469 469 G4double 470 G4double 470 G4EmBiasingManager::ApplySplitting(std::vector 471 G4EmBiasingManager::ApplySplitting(std::vector<G4DynamicParticle*>& vd, 471 const G4Tra 472 const G4Track& track, 472 G4VEmModel* 473 G4VEmModel* currentModel, 473 G4int index 474 G4int index, 474 G4double tc 475 G4double tcut) 475 { 476 { 476 // method is applied only if 1 secondary cre 477 // method is applied only if 1 secondary created PostStep 477 // in the case of many secondaries there is 478 // in the case of many secondaries there is a contradiction 478 G4double weight = 1.; 479 G4double weight = 1.; 479 std::size_t n = vd.size(); << 480 size_t n = vd.size(); 480 G4double w = secBiasedWeight[index]; 481 G4double w = secBiasedWeight[index]; 481 482 482 if(1 != n || 1.0 <= w) { return weight; } 483 if(1 != n || 1.0 <= w) { return weight; } 483 484 484 G4double trackWeight = track.GetWeight(); 485 G4double trackWeight = track.GetWeight(); 485 const G4DynamicParticle* dynParticle = track 486 const G4DynamicParticle* dynParticle = track.GetDynamicParticle(); 486 487 487 G4int nsplit = nBremSplitting[index]; 488 G4int nsplit = nBremSplitting[index]; 488 489 489 // double splitting is suppressed 490 // double splitting is suppressed 490 if(1 < nsplit && trackWeight>w) { 491 if(1 < nsplit && trackWeight>w) { 491 492 492 weight = w; 493 weight = w; 493 if(nsplit > (G4int)tmpSecondaries.size()) 494 if(nsplit > (G4int)tmpSecondaries.size()) { 494 tmpSecondaries.reserve(nsplit); 495 tmpSecondaries.reserve(nsplit); 495 } 496 } 496 const G4MaterialCutsCouple* couple = track 497 const G4MaterialCutsCouple* couple = track.GetMaterialCutsCouple(); 497 // start from 1, because already one secon 498 // start from 1, because already one secondary created 498 for(G4int k=1; k<nsplit; ++k) { 499 for(G4int k=1; k<nsplit; ++k) { 499 tmpSecondaries.clear(); 500 tmpSecondaries.clear(); 500 currentModel->SampleSecondaries(&tmpSeco 501 currentModel->SampleSecondaries(&tmpSecondaries, couple, dynParticle, 501 tcut); 502 tcut); 502 for (std::size_t kk=0; kk<tmpSecondaries << 503 for (size_t kk=0; kk<tmpSecondaries.size(); ++kk) { 503 vd.push_back(tmpSecondaries[kk]); 504 vd.push_back(tmpSecondaries[kk]); 504 } 505 } 505 } 506 } 506 } 507 } 507 return weight; 508 return weight; 508 } 509 } 509 510 510 //....oooOO0OOooo........oooOO0OOooo........oo 511 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 511 512 512 G4double 513 G4double 513 G4EmBiasingManager::ApplyDirectionalSplitting( 514 G4EmBiasingManager::ApplyDirectionalSplitting( 514 std::vector 515 std::vector<G4DynamicParticle*>& vd, 515 const G4Tra 516 const G4Track& track, 516 G4VEmModel* 517 G4VEmModel* currentModel, 517 G4int index 518 G4int index, 518 G4double tc 519 G4double tcut, 519 G4ParticleC 520 G4ParticleChangeForGamma* partChange) 520 { 521 { 521 // primary is gamma. do splitting/RR as appr 522 // primary is gamma. do splitting/RR as appropriate 522 // method applied for any number of secondar 523 // method applied for any number of secondaries 523 524 524 G4double weight = 1.0; 525 G4double weight = 1.0; 525 G4double w = secBiasedWeight[index]; 526 G4double w = secBiasedWeight[index]; 526 527 527 fDirectionalSplittingWeights.clear(); 528 fDirectionalSplittingWeights.clear(); 528 if(1.0 <= w) { 529 if(1.0 <= w) { 529 fDirectionalSplittingWeights.push_back(wei 530 fDirectionalSplittingWeights.push_back(weight); 530 return weight; 531 return weight; 531 } 532 } 532 533 533 G4double trackWeight = track.GetWeight(); 534 G4double trackWeight = track.GetWeight(); 534 G4int nsplit = nBremSplitting[index]; 535 G4int nsplit = nBremSplitting[index]; 535 536 536 // double splitting is suppressed 537 // double splitting is suppressed 537 if(1 < nsplit && trackWeight>w) { 538 if(1 < nsplit && trackWeight>w) { 538 539 539 weight = w; 540 weight = w; 540 const G4ThreeVector pos = track.GetPositio 541 const G4ThreeVector pos = track.GetPosition(); 541 542 542 G4bool foundPrimaryParticle = false; 543 G4bool foundPrimaryParticle = false; 543 G4double primaryEnergy = 0.; 544 G4double primaryEnergy = 0.; 544 G4ThreeVector primaryMomdir(0.,0.,0.); 545 G4ThreeVector primaryMomdir(0.,0.,0.); 545 G4double primaryWeight = trackWeight; 546 G4double primaryWeight = trackWeight; 546 547 547 tmpSecondaries = vd; 548 tmpSecondaries = vd; 548 vd.clear(); 549 vd.clear(); 549 vd.reserve(nsplit); 550 vd.reserve(nsplit); 550 for (G4int k=0; k<nsplit; ++k) { 551 for (G4int k=0; k<nsplit; ++k) { 551 if (k>0) { // for k==0, SampleSecondari 552 if (k>0) { // for k==0, SampleSecondaries has already been called 552 tmpSecondaries.clear(); 553 tmpSecondaries.clear(); 553 // SampleSecondaries modifies primary 554 // SampleSecondaries modifies primary info stored in partChange 554 currentModel->SampleSecondaries(&tmpSe 555 currentModel->SampleSecondaries(&tmpSecondaries, 555 track. 556 track.GetMaterialCutsCouple(), 556 track. 557 track.GetDynamicParticle(), tcut); 557 } 558 } 558 for (std::size_t kk=0; kk<tmpSecondaries << 559 for (size_t kk=0; kk<tmpSecondaries.size(); ++kk) { 559 if (tmpSecondaries[kk]->GetParticleDef 560 if (tmpSecondaries[kk]->GetParticleDefinition() == theGamma) { 560 if (CheckDirection(pos, tmpSecondari 561 if (CheckDirection(pos, tmpSecondaries[kk]->GetMomentumDirection())){ 561 vd.push_back(tmpSecondaries[kk]); 562 vd.push_back(tmpSecondaries[kk]); 562 fDirectionalSplittingWeights.push_ 563 fDirectionalSplittingWeights.push_back(1.); 563 } else if (G4UniformRand() < w) { 564 } else if (G4UniformRand() < w) { 564 vd.push_back(tmpSecondaries[kk]); 565 vd.push_back(tmpSecondaries[kk]); 565 fDirectionalSplittingWeights.push_ 566 fDirectionalSplittingWeights.push_back(1./weight); 566 } else { 567 } else { 567 delete tmpSecondaries[kk]; 568 delete tmpSecondaries[kk]; 568 tmpSecondaries[kk] = nullptr; 569 tmpSecondaries[kk] = nullptr; 569 } 570 } 570 } else if (k==0) { // keep charged 2ry 571 } else if (k==0) { // keep charged 2ry from first splitting 571 vd.push_back(tmpSecondaries[kk]); 572 vd.push_back(tmpSecondaries[kk]); 572 fDirectionalSplittingWeights.push_ba 573 fDirectionalSplittingWeights.push_back(1./weight); 573 } else { 574 } else { 574 delete tmpSecondaries[kk]; 575 delete tmpSecondaries[kk]; 575 tmpSecondaries[kk] = nullptr; 576 tmpSecondaries[kk] = nullptr; 576 } 577 } 577 } 578 } 578 579 579 // primary 580 // primary 580 G4double en = partChange->GetProposedKin 581 G4double en = partChange->GetProposedKineticEnergy(); 581 if (en>0.) { // don't add if kinetic ene 582 if (en>0.) { // don't add if kinetic energy = 0 582 G4ThreeVector momdir = partChange->Get 583 G4ThreeVector momdir = partChange->GetProposedMomentumDirection(); 583 if (CheckDirection(pos,momdir)) { 584 if (CheckDirection(pos,momdir)) { 584 // keep only one primary; others are 585 // keep only one primary; others are secondaries 585 if (!foundPrimaryParticle) { 586 if (!foundPrimaryParticle) { 586 primaryEnergy = en; 587 primaryEnergy = en; 587 primaryMomdir = momdir; 588 primaryMomdir = momdir; 588 foundPrimaryParticle = true; 589 foundPrimaryParticle = true; 589 primaryWeight = weight; 590 primaryWeight = weight; 590 } else { 591 } else { 591 auto dp = new G4DynamicParticle(th << 592 G4DynamicParticle* dp = new G4DynamicParticle(theGamma, 592 partChange->GetPropo << 593 partChange->GetProposedMomentumDirection(), 593 partChange->GetPropo << 594 partChange->GetProposedKineticEnergy()); 594 vd.push_back(dp); 595 vd.push_back(dp); 595 fDirectionalSplittingWeights.push_ 596 fDirectionalSplittingWeights.push_back(1.); 596 } 597 } 597 } else if (G4UniformRand()<w) { // not 598 } else if (G4UniformRand()<w) { // not going to target. play RR. 598 if (!foundPrimaryParticle) { 599 if (!foundPrimaryParticle) { 599 foundPrimaryParticle = true; 600 foundPrimaryParticle = true; 600 primaryEnergy = en; 601 primaryEnergy = en; 601 primaryMomdir = momdir; 602 primaryMomdir = momdir; 602 primaryWeight = 1.; 603 primaryWeight = 1.; 603 } else { 604 } else { 604 auto dp = new G4DynamicParticle(th << 605 G4DynamicParticle* dp = new G4DynamicParticle(theGamma, 605 partChange->GetPropo << 606 partChange->GetProposedMomentumDirection(), 606 partChange->GetPropo << 607 partChange->GetProposedKineticEnergy()); 607 vd.push_back(dp); 608 vd.push_back(dp); 608 fDirectionalSplittingWeights.push_ 609 fDirectionalSplittingWeights.push_back(1./weight); 609 } 610 } 610 } 611 } 611 } 612 } 612 } // end of loop over nsplit 613 } // end of loop over nsplit 613 614 614 partChange->ProposeWeight(primaryWeight); 615 partChange->ProposeWeight(primaryWeight); 615 partChange->SetProposedKineticEnergy(prima 616 partChange->SetProposedKineticEnergy(primaryEnergy); 616 partChange->ProposeMomentumDirection(prima 617 partChange->ProposeMomentumDirection(primaryMomdir); 617 } else { 618 } else { 618 for (std::size_t i = 0; i < vd.size(); ++i << 619 for (size_t i = 0; i < vd.size(); ++i) { 619 fDirectionalSplittingWeights.push_back(1 620 fDirectionalSplittingWeights.push_back(1.); 620 } 621 } 621 } 622 } 622 623 623 return weight; 624 return weight; 624 } 625 } 625 626 626 //....oooOO0OOooo........oooOO0OOooo........oo 627 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 627 628 628 G4double G4EmBiasingManager::GetWeight(G4int i 629 G4double G4EmBiasingManager::GetWeight(G4int i) 629 { 630 { 630 // normally return 1. If a directionally spl 631 // normally return 1. If a directionally split particle survives RR, 631 // return 1./(splitting factor) 632 // return 1./(splitting factor) 632 if (fDirectionalSplittingWeights.size() >= ( 633 if (fDirectionalSplittingWeights.size() >= (unsigned int)(i+1) ) { 633 G4double w = fDirectionalSplittingWeights[ 634 G4double w = fDirectionalSplittingWeights[i]; 634 fDirectionalSplittingWeights[i] = 1.; // e 635 fDirectionalSplittingWeights[i] = 1.; // ensure it's not used again 635 return w; 636 return w; 636 } else { 637 } else { 637 return 1.; 638 return 1.; 638 } 639 } 639 } 640 } 640 641 641 G4double 642 G4double 642 G4EmBiasingManager::ApplyDirectionalSplitting( 643 G4EmBiasingManager::ApplyDirectionalSplitting( 643 std::vector< 644 std::vector<G4DynamicParticle*>& vd, 644 const G4Trac 645 const G4Track& track, 645 G4VEmModel* 646 G4VEmModel* currentModel, 646 G4int index, 647 G4int index, 647 G4double tcu 648 G4double tcut) 648 { 649 { 649 // primary is not a gamma. Do nothing with p 650 // primary is not a gamma. Do nothing with primary 650 651 651 G4double weight = 1.0; 652 G4double weight = 1.0; 652 G4double w = secBiasedWeight[index]; 653 G4double w = secBiasedWeight[index]; 653 654 654 fDirectionalSplittingWeights.clear(); 655 fDirectionalSplittingWeights.clear(); 655 if(1.0 <= w) { 656 if(1.0 <= w) { 656 fDirectionalSplittingWeights.push_back(wei 657 fDirectionalSplittingWeights.push_back(weight); 657 return weight; 658 return weight; 658 } 659 } 659 660 660 G4double trackWeight = track.GetWeight(); 661 G4double trackWeight = track.GetWeight(); 661 G4int nsplit = nBremSplitting[index]; 662 G4int nsplit = nBremSplitting[index]; 662 663 663 // double splitting is suppressed 664 // double splitting is suppressed 664 if(1 < nsplit && trackWeight>w) { 665 if(1 < nsplit && trackWeight>w) { 665 666 666 weight = w; 667 weight = w; 667 const G4ThreeVector pos = track.GetPositio 668 const G4ThreeVector pos = track.GetPosition(); 668 669 669 tmpSecondaries = vd; 670 tmpSecondaries = vd; 670 vd.clear(); 671 vd.clear(); 671 vd.reserve(nsplit); 672 vd.reserve(nsplit); 672 for (G4int k=0; k<nsplit; ++k) { 673 for (G4int k=0; k<nsplit; ++k) { 673 if (k>0) { 674 if (k>0) { 674 tmpSecondaries.clear(); 675 tmpSecondaries.clear(); 675 currentModel->SampleSecondaries(&tmpSe 676 currentModel->SampleSecondaries(&tmpSecondaries, 676 track. 677 track.GetMaterialCutsCouple(), 677 track. 678 track.GetDynamicParticle(), tcut); 678 } 679 } 679 //for (auto sec : tmpSecondaries) { 680 //for (auto sec : tmpSecondaries) { 680 for (std::size_t kk=0; kk < tmpSecondari << 681 for (size_t kk=0; kk < tmpSecondaries.size(); ++kk) { 681 if (CheckDirection(pos, tmpSecondaries 682 if (CheckDirection(pos, tmpSecondaries[kk]->GetMomentumDirection())) { 682 vd.push_back(tmpSecondaries[kk]); 683 vd.push_back(tmpSecondaries[kk]); 683 fDirectionalSplittingWeights.push_ba 684 fDirectionalSplittingWeights.push_back(1.); 684 } else if (G4UniformRand()<w) { 685 } else if (G4UniformRand()<w) { 685 vd.push_back(tmpSecondaries[kk]); 686 vd.push_back(tmpSecondaries[kk]); 686 fDirectionalSplittingWeights.push_ba 687 fDirectionalSplittingWeights.push_back(1./weight); 687 } else { 688 } else { 688 delete tmpSecondaries[kk]; 689 delete tmpSecondaries[kk]; 689 tmpSecondaries[kk] = nullptr; 690 tmpSecondaries[kk] = nullptr; 690 } 691 } 691 } 692 } 692 } // end of loop over nsplit 693 } // end of loop over nsplit 693 } else { // no splitting was done; still nee 694 } else { // no splitting was done; still need weights 694 for (std::size_t i = 0; i < vd.size(); ++i << 695 for (size_t i = 0; i < vd.size(); ++i) { 695 fDirectionalSplittingWeights.push_back(1 696 fDirectionalSplittingWeights.push_back(1.0); 696 } 697 } 697 } 698 } 698 return weight; 699 return weight; 699 } 700 } 700 701