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: G4VEnergyLossProcess.cc,v 1.174 2010-12-27 17:42:21 vnivanch Exp $ >> 27 // GEANT4 tag $Name: not supported by cvs2svn $ >> 28 // 26 // ------------------------------------------- 29 // ------------------------------------------------------------------- 27 // 30 // 28 // GEANT4 Class file 31 // GEANT4 Class file 29 // 32 // 30 // 33 // 31 // File name: G4VEnergyLossProcess 34 // File name: G4VEnergyLossProcess 32 // 35 // 33 // Author: Vladimir Ivanchenko 36 // Author: Vladimir Ivanchenko 34 // 37 // 35 // Creation date: 03.01.2002 38 // Creation date: 03.01.2002 36 // 39 // 37 // Modifications: Vladimir Ivanchenko << 40 // Modifications: 38 // 41 // >> 42 // 13-11-02 Minor fix - use normalised direction (V.Ivanchenko) >> 43 // 04-12-02 Minor change in PostStepDoIt (V.Ivanchenko) >> 44 // 23-12-02 Change interface in order to move to cut per region (V.Ivanchenko) >> 45 // 26-12-02 Secondary production moved to derived classes (V.Ivanchenko) >> 46 // 04-01-03 Fix problem of very small steps for ions (V.Ivanchenko) >> 47 // 20-01-03 Migrade to cut per region (V.Ivanchenko) >> 48 // 24-01-03 Temporarily close a control on usage of couples (V.Ivanchenko) >> 49 // 24-01-03 Make models region aware (V.Ivanchenko) >> 50 // 05-02-03 Fix compilation warnings (V.Ivanchenko) >> 51 // 06-02-03 Add control on tmax in PostStepDoIt (V.Ivanchenko) >> 52 // 13-02-03 SubCutoffProcessors defined for regions (V.Ivanchenko) >> 53 // 15-02-03 Lambda table can be scaled (V.Ivanchenko) >> 54 // 17-02-03 Fix problem of store/restore tables (V.Ivanchenko) >> 55 // 18-02-03 Add control on CutCouple usage (V.Ivanchenko) >> 56 // 26-02-03 Simplify control on GenericIons (V.Ivanchenko) >> 57 // 06-03-03 Control on GenericIons using SubType + update verbose (V.Ivanchenko) >> 58 // 10-03-03 Add Ion registration (V.Ivanchenko) >> 59 // 22-03-03 Add Initialisation of cash (V.Ivanchenko) >> 60 // 26-03-03 Remove finalRange modification (V.Ivanchenko) >> 61 // 09-04-03 Fix problem of negative range limit for non integral (V.Ivanchenko) >> 62 // 26-04-03 Fix retrieve tables (V.Ivanchenko) >> 63 // 06-05-03 Set defalt finalRange = 1 mm (V.Ivanchenko) >> 64 // 12-05-03 Update range calculations + lowKinEnergy (V.Ivanchenko) >> 65 // 13-05-03 Add calculation of precise range (V.Ivanchenko) >> 66 // 23-05-03 Remove tracking cuts (V.Ivanchenko) >> 67 // 03-06-03 Fix initialisation problem for STD ionisation (V.Ivanchenko) >> 68 // 21-07-03 Add UpdateEmModel method (V.Ivanchenko) >> 69 // 03-11-03 Fix initialisation problem in RetrievePhysicsTable (V.Ivanchenko) >> 70 // 04-11-03 Add checks in RetrievePhysicsTable (V.Ivanchenko) >> 71 // 12-11-03 G4EnergyLossSTD -> G4EnergyLossProcess (V.Ivanchenko) >> 72 // 21-01-04 Migrade to G4ParticleChangeForLoss (V.Ivanchenko) >> 73 // 27-02-04 Fix problem of loss in low presure gases, cleanup precise range >> 74 // calculation, use functions ForLoss in AlongStepDoIt (V.Ivanchenko) >> 75 // 10-03-04 Fix a problem of Precise Range table (V.Ivanchenko) >> 76 // 19-03-04 Fix a problem energy below lowestKinEnergy (V.Ivanchenko) >> 77 // 31-03-04 Fix a problem of retrieve tables (V.Ivanchenko) >> 78 // 21-07-04 Check weather AtRest are active or not (V.Ivanchenko) >> 79 // 03-08-04 Add pointer of DEDX table to all processes (V.Ivanchenko) >> 80 // 06-08-04 Clear up names of member functions (V.Ivanchenko) >> 81 // 06-08-04 Clear up names of member functions (V.Ivanchenko) >> 82 // 27-08-04 Add NeedBuildTables method (V.Ivanchneko) >> 83 // 08-11-04 Migration to new interface of Store/Retrieve tables (V.Ivantchenko) >> 84 // 11-03-05 Shift verbose level by 1 (V.Ivantchenko) >> 85 // 08-04-05 Major optimisation of internal interfaces (V.Ivantchenko) >> 86 // 11-04-05 Use MaxSecondaryEnergy from a model (V.Ivanchenko) >> 87 // 25-07-05 Add extra protection PostStep for non-integral mode (V.Ivanchenko) >> 88 // 12-08-05 Integral=false; SetStepFunction(0.2, 0.1*mm) (mma) >> 89 // 18-08-05 Return back both AlongStep and PostStep from 7.0 (V.Ivanchenko) >> 90 // 02-09-05 Default StepFunction 0.2 1 mm + integral (V.Ivanchenko) >> 91 // 04-09-05 default lambdaFactor 0.8 (V.Ivanchenko) >> 92 // 05-10-05 protection against 0 energy loss added (L.Urban) >> 93 // 17-10-05 protection above has been removed (L.Urban) >> 94 // 06-01-06 reset currentCouple when StepFunction is changed (V.Ivanchenko) >> 95 // 10-01-06 PreciseRange -> CSDARange (V.Ivantchenko) >> 96 // 18-01-06 Clean up subcutoff including recalculation of presafety (VI) >> 97 // 20-01-06 Introduce G4EmTableType and reducing number of methods (VI) >> 98 // 22-03-06 Add control on warning printout AlongStep (VI) >> 99 // 23-03-06 Use isIonisation flag (V.Ivanchenko) >> 100 // 07-06-06 Do not reflect AlongStep in subcutoff regime (V.Ivanchenko) >> 101 // 14-01-07 add SetEmModel(index) and SetFluctModel() (mma) >> 102 // 16-01-07 add IonisationTable and IonisationSubTable (V.Ivanchenko) >> 103 // 16-02-07 set linLossLimit=1.e-6 (V.Ivanchenko) >> 104 // 13-03-07 use SafetyHelper instead of navigator (V.Ivanchenko) >> 105 // 10-04-07 use unique SafetyHelper (V.Ivanchenko) >> 106 // 12-04-07 Add verbosity at destruction (V.Ivanchenko) >> 107 // 25-04-07 move initialisation of safety helper to BuildPhysicsTable (VI) >> 108 // 27-10-07 Virtual functions moved to source (V.Ivanchenko) >> 109 // 24-06-09 Removed hidden bin in G4PhysicsVector (V.Ivanchenko) >> 110 // 15-10-10 Fixed 4-momentum balance if deexcitation is active (L.Pandola) 39 // 111 // 40 // Class Description: 112 // Class Description: 41 // 113 // 42 // It is the unified energy loss process it ca 114 // It is the unified energy loss process it calculates the continuous 43 // energy loss for charged particles using a s 115 // energy loss for charged particles using a set of Energy Loss 44 // models valid for different energy regions. 116 // models valid for different energy regions. There are a possibility 45 // to create and access to dE/dx and range tab 117 // to create and access to dE/dx and range tables, or to calculate 46 // that information on fly. 118 // that information on fly. 47 // ------------------------------------------- 119 // ------------------------------------------------------------------- 48 // 120 // 49 //....oooOO0OOooo........oooOO0OOooo........oo 121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 50 //....oooOO0OOooo........oooOO0OOooo........oo 122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 51 123 52 #include "G4VEnergyLossProcess.hh" 124 #include "G4VEnergyLossProcess.hh" 53 #include "G4PhysicalConstants.hh" << 54 #include "G4SystemOfUnits.hh" << 55 #include "G4ProcessManager.hh" 125 #include "G4ProcessManager.hh" 56 #include "G4LossTableManager.hh" 126 #include "G4LossTableManager.hh" 57 #include "G4LossTableBuilder.hh" 127 #include "G4LossTableBuilder.hh" 58 #include "G4Step.hh" 128 #include "G4Step.hh" 59 #include "G4ParticleDefinition.hh" 129 #include "G4ParticleDefinition.hh" 60 #include "G4ParticleTable.hh" << 61 #include "G4EmParameters.hh" << 62 #include "G4EmUtility.hh" << 63 #include "G4EmTableUtil.hh" << 64 #include "G4VEmModel.hh" 130 #include "G4VEmModel.hh" 65 #include "G4VEmFluctuationModel.hh" 131 #include "G4VEmFluctuationModel.hh" 66 #include "G4DataVector.hh" 132 #include "G4DataVector.hh" 67 #include "G4PhysicsLogVector.hh" 133 #include "G4PhysicsLogVector.hh" 68 #include "G4VParticleChange.hh" 134 #include "G4VParticleChange.hh" >> 135 #include "G4Gamma.hh" 69 #include "G4Electron.hh" 136 #include "G4Electron.hh" >> 137 #include "G4Positron.hh" >> 138 #include "G4Proton.hh" 70 #include "G4ProcessManager.hh" 139 #include "G4ProcessManager.hh" 71 #include "G4UnitsTable.hh" 140 #include "G4UnitsTable.hh" >> 141 #include "G4GenericIon.hh" >> 142 #include "G4ProductionCutsTable.hh" 72 #include "G4Region.hh" 143 #include "G4Region.hh" 73 #include "G4RegionStore.hh" 144 #include "G4RegionStore.hh" 74 #include "G4PhysicsTableHelper.hh" 145 #include "G4PhysicsTableHelper.hh" 75 #include "G4SafetyHelper.hh" 146 #include "G4SafetyHelper.hh" 76 #include "G4EmDataHandler.hh" << 77 #include "G4TransportationManager.hh" 147 #include "G4TransportationManager.hh" >> 148 #include "G4EmConfigurator.hh" 78 #include "G4VAtomDeexcitation.hh" 149 #include "G4VAtomDeexcitation.hh" 79 #include "G4VSubCutProducer.hh" << 80 #include "G4EmBiasingManager.hh" 150 #include "G4EmBiasingManager.hh" 81 #include "G4Log.hh" << 82 #include <iostream> << 83 151 84 //....oooOO0OOooo........oooOO0OOooo........oo 152 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 85 153 86 namespace << 87 { << 88 G4String tnames[7] = << 89 {"DEDX","Ionisation","DEDXnr","CSDARange", << 90 } << 91 << 92 << 93 G4VEnergyLossProcess::G4VEnergyLossProcess(con 154 G4VEnergyLossProcess::G4VEnergyLossProcess(const G4String& name, 94 G4P << 155 G4ProcessType type): 95 G4VContinuousDiscreteProcess(name, type) << 156 G4VContinuousDiscreteProcess(name, type), >> 157 secondaryParticle(0), >> 158 nSCoffRegions(0), >> 159 idxSCoffRegions(0), >> 160 nProcesses(0), >> 161 theDEDXTable(0), >> 162 theDEDXSubTable(0), >> 163 theDEDXunRestrictedTable(0), >> 164 theIonisationTable(0), >> 165 theIonisationSubTable(0), >> 166 theRangeTableForLoss(0), >> 167 theCSDARangeTable(0), >> 168 theSecondaryRangeTable(0), >> 169 theInverseRangeTable(0), >> 170 theLambdaTable(0), >> 171 theSubLambdaTable(0), >> 172 theDensityFactor(0), >> 173 theDensityIdx(0), >> 174 baseParticle(0), >> 175 minSubRange(0.1), >> 176 lossFluctuationFlag(true), >> 177 rndmStepFlag(false), >> 178 tablesAreBuilt(false), >> 179 integral(true), >> 180 isIon(false), >> 181 isIonisation(true), >> 182 useSubCutoff(false), >> 183 useDeexcitation(false), >> 184 particle(0), >> 185 currentCouple(0), >> 186 nWarnings(0), >> 187 mfpKinEnergy(0.0) 96 { 188 { 97 theParameters = G4EmParameters::Instance(); << 98 SetVerboseLevel(1); 189 SetVerboseLevel(1); 99 190 100 // low energy limit 191 // low energy limit 101 lowestKinEnergy = theParameters->LowestElect << 192 lowestKinEnergy = 1.*eV; 102 193 103 // Size of tables << 194 // Size of tables assuming spline 104 minKinEnergy = 0.1*CLHEP::keV; << 195 minKinEnergy = 0.1*keV; 105 maxKinEnergy = 100.0*CLHEP::TeV; << 196 maxKinEnergy = 10.0*TeV; 106 maxKinEnergyCSDA = 1.0*CLHEP::GeV; << 197 nBins = 77; 107 nBins = 84; << 198 maxKinEnergyCSDA = 1.0*GeV; 108 nBinsCSDA = 35; 199 nBinsCSDA = 35; 109 200 110 invLambdaFactor = 1.0/lambdaFactor; << 201 // default linear loss limit for spline >> 202 linLossLimit = 0.01; >> 203 >> 204 // default dRoverRange and finalRange >> 205 SetStepFunction(0.2, 1.0*mm); >> 206 >> 207 // default lambda factor >> 208 lambdaFactor = 0.8; 111 209 112 // default linear loss limit << 210 // cross section biasing 113 finalRange = 1.*CLHEP::mm; << 211 biasFactor = 1.0; >> 212 >> 213 // particle types >> 214 theElectron = G4Electron::Electron(); >> 215 thePositron = G4Positron::Positron(); >> 216 theGamma = G4Gamma::Gamma(); >> 217 theGenericIon = 0; 114 218 115 // run time objects 219 // run time objects 116 pParticleChange = &fParticleChange; 220 pParticleChange = &fParticleChange; 117 fParticleChange.SetSecondaryWeightByProcess( 221 fParticleChange.SetSecondaryWeightByProcess(true); 118 modelManager = new G4EmModelManager(); 222 modelManager = new G4EmModelManager(); 119 safetyHelper = G4TransportationManager::GetT 223 safetyHelper = G4TransportationManager::GetTransportationManager() 120 ->GetSafetyHelper(); 224 ->GetSafetyHelper(); 121 aGPILSelection = CandidateForSelection; 225 aGPILSelection = CandidateForSelection; 122 226 123 // initialise model 227 // initialise model 124 lManager = G4LossTableManager::Instance(); << 228 (G4LossTableManager::Instance())->Register(this); 125 lManager->Register(this); << 229 fluctModel = 0; 126 isMaster = lManager->IsMaster(); << 230 atomDeexcitation = 0; >> 231 >> 232 biasManager = 0; >> 233 biasFlag = false; >> 234 weightFlag = false; 127 235 128 G4LossTableBuilder* bld = lManager->GetTable << 236 scTracks.reserve(5); 129 theDensityFactor = bld->GetDensityFactors(); << 237 secParticles.reserve(5); 130 theDensityIdx = bld->GetCoupleIndexes(); << 131 << 132 scTracks.reserve(10); << 133 secParticles.reserve(12); << 134 emModels = new std::vector<G4VEmModel*>; << 135 } 238 } 136 239 137 //....oooOO0OOooo........oooOO0OOooo........oo 240 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 138 241 139 G4VEnergyLossProcess::~G4VEnergyLossProcess() 242 G4VEnergyLossProcess::~G4VEnergyLossProcess() 140 { 243 { 141 if (isMaster) { << 244 if(1 < verboseLevel) 142 if(nullptr == baseParticle) { delete theDa << 245 G4cout << "G4VEnergyLossProcess destruct " << GetProcessName() 143 delete theEnergyOfCrossSectionMax; << 246 << G4endl; 144 if(nullptr != fXSpeaks) { << 247 //delete vstrag; 145 for(auto const & v : *fXSpeaks) { delete << 248 Clean(); 146 delete fXSpeaks; << 249 >> 250 if ( !baseParticle ) { >> 251 if(theDEDXTable && theRangeTableForLoss) { >> 252 if(theIonisationTable == theDEDXTable) theIonisationTable = 0; >> 253 theDEDXTable->clearAndDestroy(); >> 254 delete theDEDXTable; >> 255 if(theDEDXSubTable) { >> 256 if(theIonisationSubTable == theDEDXSubTable) >> 257 theIonisationSubTable = 0; >> 258 theDEDXSubTable->clearAndDestroy(); >> 259 delete theDEDXSubTable; >> 260 } >> 261 } >> 262 if(theIonisationTable) { >> 263 theIonisationTable->clearAndDestroy(); >> 264 delete theIonisationTable; >> 265 } >> 266 if(theIonisationSubTable) { >> 267 theIonisationSubTable->clearAndDestroy(); >> 268 delete theIonisationSubTable; >> 269 } >> 270 if(theDEDXunRestrictedTable && theCSDARangeTable) { >> 271 theDEDXunRestrictedTable->clearAndDestroy(); >> 272 delete theDEDXunRestrictedTable; >> 273 } >> 274 if(theCSDARangeTable) { >> 275 theCSDARangeTable->clearAndDestroy(); >> 276 delete theCSDARangeTable; >> 277 } >> 278 if(theRangeTableForLoss) { >> 279 theRangeTableForLoss->clearAndDestroy(); >> 280 delete theRangeTableForLoss; >> 281 } >> 282 if(theInverseRangeTable) { >> 283 theInverseRangeTable->clearAndDestroy(); >> 284 delete theInverseRangeTable; >> 285 } >> 286 if(theLambdaTable) { >> 287 theLambdaTable->clearAndDestroy(); >> 288 delete theLambdaTable; >> 289 } >> 290 if(theSubLambdaTable) { >> 291 theSubLambdaTable->clearAndDestroy(); >> 292 delete theSubLambdaTable; 147 } 293 } 148 } 294 } >> 295 149 delete modelManager; 296 delete modelManager; 150 delete biasManager; 297 delete biasManager; 151 delete scoffRegions; << 298 (G4LossTableManager::Instance())->DeRegister(this); 152 delete emModels; << 299 } 153 lManager->DeRegister(this); << 300 >> 301 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 302 >> 303 void G4VEnergyLossProcess::Clean() >> 304 { >> 305 if(1 < verboseLevel) { >> 306 G4cout << "G4VEnergyLossProcess::Clear() for " << GetProcessName() >> 307 << G4endl; >> 308 } >> 309 delete [] idxSCoffRegions; >> 310 >> 311 tablesAreBuilt = false; >> 312 >> 313 scProcesses.clear(); >> 314 nProcesses = 0; 154 } 315 } 155 316 156 //....oooOO0OOooo........oooOO0OOooo........oo 317 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 157 318 158 G4double G4VEnergyLossProcess::MinPrimaryEnerg 319 G4double G4VEnergyLossProcess::MinPrimaryEnergy(const G4ParticleDefinition*, 159 << 320 const G4Material*, 160 << 321 G4double cut) 161 { 322 { 162 return cut; 323 return cut; 163 } 324 } 164 325 165 //....oooOO0OOooo........oooOO0OOooo........oo 326 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 166 327 167 void G4VEnergyLossProcess::AddEmModel(G4int or << 328 void G4VEnergyLossProcess::AddEmModel(G4int order, G4VEmModel* p, 168 G4VEmFlu << 329 G4VEmFluctuationModel* fluc, 169 const G4 << 330 const G4Region* region) 170 { 331 { 171 if(nullptr == ptr) { return; } << 332 modelManager->AddEmModel(order, p, fluc, region); 172 G4VEmFluctuationModel* afluc = (nullptr == f << 333 if(p) { p->SetParticleChange(pParticleChange, fluc); } 173 modelManager->AddEmModel(order, ptr, afluc, << 174 ptr->SetParticleChange(pParticleChange, aflu << 175 } 334 } 176 335 177 //....oooOO0OOooo........oooOO0OOooo........oo 336 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 178 337 179 void G4VEnergyLossProcess::SetEmModel(G4VEmMod << 338 void G4VEnergyLossProcess::UpdateEmModel(const G4String& nam, >> 339 G4double emin, G4double emax) 180 { 340 { 181 if(nullptr == ptr) { return; } << 341 modelManager->UpdateEmModel(nam, emin, emax); 182 if(!emModels->empty()) { << 183 for(auto & em : *emModels) { if(em == ptr) << 184 } << 185 emModels->push_back(ptr); << 186 } 342 } 187 343 188 //....oooOO0OOooo........oooOO0OOooo........oo 344 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 189 345 190 void G4VEnergyLossProcess::SetDynamicMassCharg << 346 void G4VEnergyLossProcess::SetEmModel(G4VEmModel* p, G4int index) 191 << 192 { 347 { 193 massRatio = massratio; << 348 G4int n = emModels.size(); 194 logMassRatio = G4Log(massRatio); << 349 if(index >= n) { for(G4int i=n; i<=index; ++i) {emModels.push_back(0);} } 195 fFactor = charge2ratio*biasFactor; << 350 emModels[index] = p; 196 if(baseMat) { fFactor *= (*theDensityFactor) << 351 } 197 chargeSqRatio = charge2ratio; << 352 198 reduceFactor = 1.0/(fFactor*massRatio); << 353 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 354 >> 355 G4VEmModel* G4VEnergyLossProcess::EmModel(G4int index) >> 356 { >> 357 G4VEmModel* p = 0; >> 358 if(index >= 0 && index < G4int(emModels.size())) { p = emModels[index]; } >> 359 return p; >> 360 } >> 361 >> 362 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 363 >> 364 G4VEmModel* G4VEnergyLossProcess::GetModelByIndex(G4int idx, G4bool ver) >> 365 { >> 366 return modelManager->GetModel(idx, ver); >> 367 } >> 368 >> 369 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 370 >> 371 G4int G4VEnergyLossProcess::NumberOfModels() >> 372 { >> 373 return modelManager->NumberOfModels(); 199 } 374 } 200 375 201 //....oooOO0OOooo........oooOO0OOooo........oo 376 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 202 377 203 void 378 void 204 G4VEnergyLossProcess::PreparePhysicsTable(cons 379 G4VEnergyLossProcess::PreparePhysicsTable(const G4ParticleDefinition& part) 205 { 380 { 206 particle = G4EmTableUtil::CheckIon(this, &pa << 381 if(1 < verboseLevel) { 207 verboseLe << 382 G4cout << "G4VEnergyLossProcess::PreparePhysicsTable for " >> 383 << GetProcessName() >> 384 << " for " << part.GetParticleName() >> 385 << G4endl; >> 386 } >> 387 >> 388 currentCouple = 0; >> 389 preStepLambda = 0.0; >> 390 mfpKinEnergy = DBL_MAX; >> 391 fRange = DBL_MAX; >> 392 preStepKinEnergy = 0.0; >> 393 chargeSqRatio = 1.0; >> 394 massRatio = 1.0; >> 395 reduceFactor = 1.0; >> 396 fFactor = 1.0; >> 397 >> 398 G4LossTableManager* lManager = G4LossTableManager::Instance(); >> 399 >> 400 // Are particle defined? >> 401 if( !particle ) { >> 402 particle = ∂ >> 403 if(GetProcessName() == "ionIoni") { >> 404 G4String pname = particle->GetParticleName(); >> 405 if(pname != "GenericIon" && pname != "alpha" && pname != "He3") { >> 406 lManager->RegisterIon(&part, this); >> 407 theGenericIon = G4GenericIon::GenericIon(); >> 408 particle = theGenericIon; >> 409 return; >> 410 } >> 411 } >> 412 } >> 413 >> 414 if(part.GetParticleType() == "nucleus") { isIon = true; } 208 415 209 if( particle != &part ) { 416 if( particle != &part ) { 210 if(!isIon) { lManager->RegisterExtraPartic << 417 if(isIon) { >> 418 lManager->RegisterIon(&part, this); >> 419 } else { >> 420 lManager->RegisterExtraParticle(&part, this); >> 421 } 211 if(1 < verboseLevel) { 422 if(1 < verboseLevel) { 212 G4cout << "### G4VEnergyLossProcess::Pre << 423 G4cout << "### G4VEnergyLossProcess::PreparePhysicsTable() interrupted for " 213 << " interrupted for " << GetProc << 424 << part.GetParticleName() << G4endl; 214 << part.GetParticleName() << " is << 215 << " spline=" << spline << G4endl << 216 } 425 } 217 return; 426 return; 218 } 427 } 219 428 220 tablesAreBuilt = false; << 429 Clean(); 221 if (GetProcessSubType() == fIonisation) { Se << 222 << 223 G4LossTableBuilder* bld = lManager->GetTable << 224 lManager->PreparePhysicsTable(&part, this); 430 lManager->PreparePhysicsTable(&part, this); >> 431 G4LossTableBuilder* bld = lManager->GetTableBuilder(); 225 432 226 // Base particle and set of models can be de 433 // Base particle and set of models can be defined here 227 InitialiseEnergyLossProcess(particle, basePa 434 InitialiseEnergyLossProcess(particle, baseParticle); 228 435 229 // parameters of the process << 436 const G4ProductionCutsTable* theCoupleTable= 230 if(!actLossFluc) { lossFluctuationFlag = the << 437 G4ProductionCutsTable::GetProductionCutsTable(); 231 useCutAsFinalRange = theParameters->UseCutAs << 438 size_t n = theCoupleTable->GetTableSize(); 232 if(!actMinKinEnergy) { minKinEnergy = thePar << 439 233 if(!actMaxKinEnergy) { maxKinEnergy = thePar << 440 theDEDXAtMaxEnergy.resize(n, 0.0); 234 if(!actBinning) { nBins = theParameters->Num << 441 theRangeAtMaxEnergy.resize(n, 0.0); 235 maxKinEnergyCSDA = theParameters->MaxEnergyF << 442 theEnergyOfCrossSectionMax.resize(n, 0.0); 236 nBinsCSDA = theParameters->NumberOfBinsPerDe << 443 theCrossSectionMax.resize(n, DBL_MAX); 237 *G4lrint(std::log10(maxKinEnergyCSDA/minKi << 238 if(!actLinLossLimit) { linLossLimit = thePar << 239 lambdaFactor = theParameters->LambdaFactor() << 240 invLambdaFactor = 1.0/lambdaFactor; << 241 if(isMaster) { SetVerboseLevel(theParameters << 242 else { SetVerboseLevel(theParameters->Worker << 243 // integral option may be disabled << 244 if(!theParameters->Integral()) { fXSType = f << 245 << 246 theParameters->DefineRegParamForLoss(this); << 247 << 248 fRangeEnergy = 0.0; << 249 << 250 G4double initialCharge = particle->GetPDGCha << 251 G4double initialMass = particle->GetPDGMas << 252 << 253 theParameters->FillStepFunction(particle, th << 254 << 255 // parameters for scaling from the base part << 256 if (nullptr != baseParticle) { << 257 massRatio = (baseParticle->GetPDGMass() << 258 logMassRatio = G4Log(massRatio); << 259 G4double q = initialCharge/baseParticle->G << 260 chargeSqRatio = q*q; << 261 if(chargeSqRatio > 0.0) { reduceFactor = 1 << 262 } << 263 lowestKinEnergy = (initialMass < CLHEP::MeV) << 264 ? theParameters->LowestElectronEnergy() << 265 : theParameters->LowestMuHadEnergy(); << 266 444 267 // Tables preparation 445 // Tables preparation 268 if (isMaster && nullptr == baseParticle) { << 446 if (!baseParticle) { 269 if(nullptr == theData) { theData = new G4E << 270 << 271 if(nullptr != theDEDXTable && isIonisation << 272 if(nullptr != theIonisationTable && theD << 273 theData->CleanTable(0); << 274 theDEDXTable = theIonisationTable; << 275 theIonisationTable = nullptr; << 276 } << 277 } << 278 447 279 theDEDXTable = theData->MakeTable(theDEDXT << 448 theDEDXTable = G4PhysicsTableHelper::PreparePhysicsTable(theDEDXTable); 280 bld->InitialiseBaseMaterials(theDEDXTable) 449 bld->InitialiseBaseMaterials(theDEDXTable); 281 theData->UpdateTable(theIonisationTable, 1 << 282 450 283 if (theParameters->BuildCSDARange()) { << 451 if (lManager->BuildCSDARange()) { 284 theDEDXunRestrictedTable = theData->Make << 452 theDEDXunRestrictedTable = 285 if(isIonisation) { theCSDARangeTable = t << 453 G4PhysicsTableHelper::PreparePhysicsTable(theDEDXunRestrictedTable); 286 } << 454 theCSDARangeTable = 287 << 455 G4PhysicsTableHelper::PreparePhysicsTable(theCSDARangeTable); 288 theLambdaTable = theData->MakeTable(4); << 456 bld->InitialiseBaseMaterials(theDEDXunRestrictedTable); 289 if(isIonisation) { << 457 bld->InitialiseBaseMaterials(theCSDARangeTable); 290 theRangeTableForLoss = theData->MakeTabl << 458 } 291 theInverseRangeTable = theData->MakeTabl << 459 >> 460 theRangeTableForLoss = >> 461 G4PhysicsTableHelper::PreparePhysicsTable(theRangeTableForLoss); >> 462 theInverseRangeTable = >> 463 G4PhysicsTableHelper::PreparePhysicsTable(theInverseRangeTable); >> 464 theLambdaTable = G4PhysicsTableHelper::PreparePhysicsTable(theLambdaTable); >> 465 >> 466 bld->InitialiseBaseMaterials(theRangeTableForLoss); >> 467 bld->InitialiseBaseMaterials(theInverseRangeTable); >> 468 bld->InitialiseBaseMaterials(theLambdaTable); >> 469 >> 470 if (nSCoffRegions) { >> 471 theDEDXSubTable = >> 472 G4PhysicsTableHelper::PreparePhysicsTable(theDEDXSubTable); >> 473 theSubLambdaTable = >> 474 G4PhysicsTableHelper::PreparePhysicsTable(theSubLambdaTable); >> 475 bld->InitialiseBaseMaterials(theDEDXSubTable); >> 476 bld->InitialiseBaseMaterials(theSubLambdaTable); 292 } 477 } 293 } 478 } 294 479 >> 480 theDensityFactor = bld->GetDensityFactors(); >> 481 theDensityIdx = bld->GetCoupleIndexes(); >> 482 295 // forced biasing 483 // forced biasing 296 if(nullptr != biasManager) { << 484 if(biasManager) { 297 biasManager->Initialise(part,GetProcessNam 485 biasManager->Initialise(part,GetProcessName(),verboseLevel); 298 biasFlag = false; 486 biasFlag = false; 299 } 487 } 300 baseMat = bld->GetBaseMaterialFlag(); << 488 301 numberOfModels = modelManager->NumberOfModel << 489 G4double initialCharge = particle->GetPDGCharge(); 302 currentModel = modelManager->GetModel(0); << 490 G4double initialMass = particle->GetPDGMass(); 303 G4EmTableUtil::UpdateModels(this, modelManag << 491 304 numberOfModels, << 492 if (baseParticle) { 305 mainSecondaries, << 493 if(baseParticle->GetParticleName() == "GenericIon") { 306 theParameters->U << 494 theGenericIon = G4GenericIon::GenericIon(); 307 theCuts = modelManager->Initialise(particle, << 495 } 308 verboseLe << 496 massRatio = (baseParticle->GetPDGMass())/initialMass; 309 // subcut processor << 497 G4double q = initialCharge/baseParticle->GetPDGCharge(); 310 if(isIonisation) { << 498 chargeSqRatio = q*q; 311 subcutProducer = lManager->SubCutProducer( << 499 if(chargeSqRatio > 0.0) { reduceFactor = 1.0/(chargeSqRatio*massRatio); } 312 } 500 } 313 if(1 == nSCoffRegions) { << 501 314 if((*scoffRegions)[0]->GetName() == "Defau << 502 // initialisation of models 315 delete scoffRegions; << 503 G4int nmod = modelManager->NumberOfModels(); 316 scoffRegions = nullptr; << 504 for(G4int i=0; i<nmod; ++i) { 317 nSCoffRegions = 0; << 505 G4VEmModel* mod = modelManager->GetModel(i); >> 506 if(mod->HighEnergyLimit() > maxKinEnergy) { >> 507 mod->SetHighEnergyLimit(maxKinEnergy); 318 } 508 } 319 } 509 } 320 510 321 if(1 < verboseLevel) { << 511 theCuts = modelManager->Initialise(particle, secondaryParticle, 322 G4cout << "G4VEnergyLossProcess::PrepearPh << 512 minSubRange, verboseLevel); 323 << " for " << GetProcessName() << " << 513 324 << " isIon= " << isIon << " spline= << 514 // Sub Cutoff 325 if(baseParticle) { << 515 if (nSCoffRegions>0) { 326 G4cout << "; base: " << baseParticle->Ge << 516 theSubCuts = modelManager->SubCutoff(); >> 517 >> 518 if(nSCoffRegions>0) { idxSCoffRegions = new G4bool[n]; } >> 519 for (size_t j=0; j<n; ++j) { >> 520 >> 521 const G4MaterialCutsCouple* couple = >> 522 theCoupleTable->GetMaterialCutsCouple(j); >> 523 const G4ProductionCuts* pcuts = couple->GetProductionCuts(); >> 524 >> 525 if(nSCoffRegions>0) { >> 526 G4bool reg = false; >> 527 for(G4int i=0; i<nSCoffRegions; ++i) { >> 528 if( pcuts == scoffRegions[i]->GetProductionCuts()) { reg = true; } >> 529 } >> 530 idxSCoffRegions[j] = reg; >> 531 } 327 } 532 } 328 G4cout << G4endl; << 533 } 329 G4cout << " chargeSqRatio= " << chargeSqRa << 534 >> 535 if (1 < verboseLevel) { >> 536 G4cout << "G4VEnergyLossProcess::Initialise() is done " >> 537 << " for local " << particle->GetParticleName() >> 538 << " isIon= " << isIon >> 539 << " chargeSqRatio= " << chargeSqRatio 330 << " massRatio= " << massRatio 540 << " massRatio= " << massRatio 331 << " reduceFactor= " << reduceFacto 541 << " reduceFactor= " << reduceFactor << G4endl; 332 if (nSCoffRegions > 0) { << 542 if (nSCoffRegions) { 333 G4cout << " SubCut secondary production << 543 G4cout << " SubCutoff Regime is ON for regions: " << G4endl; 334 for (G4int i=0; i<nSCoffRegions; ++i) { 544 for (G4int i=0; i<nSCoffRegions; ++i) { 335 const G4Region* r = (*scoffRegions)[i] << 545 const G4Region* r = scoffRegions[i]; 336 G4cout << " " << r->GetName( << 546 G4cout << " " << r->GetName() << G4endl; 337 } 547 } 338 } else if(nullptr != subcutProducer) { << 339 G4cout << " SubCut secondary production << 340 } 548 } 341 } 549 } 342 } 550 } 343 551 344 //....oooOO0OOooo........oooOO0OOooo........oo 552 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 345 553 346 void G4VEnergyLossProcess::BuildPhysicsTable(c 554 void G4VEnergyLossProcess::BuildPhysicsTable(const G4ParticleDefinition& part) 347 { 555 { 348 if(1 < verboseLevel) { << 556 if(1 < verboseLevel) { 349 G4cout << "### G4VEnergyLossProcess::Build 557 G4cout << "### G4VEnergyLossProcess::BuildPhysicsTable() for " 350 << GetProcessName() 558 << GetProcessName() 351 << " and particle " << part.GetPart 559 << " and particle " << part.GetParticleName() 352 << "; the first particle " << parti << 560 << "; local: " << particle->GetParticleName(); 353 if(baseParticle) { << 561 if(baseParticle) G4cout << "; base: " << baseParticle->GetParticleName(); 354 G4cout << "; base: " << baseParticle->Ge << 355 } << 356 G4cout << G4endl; 562 G4cout << G4endl; 357 G4cout << " TablesAreBuilt= " << tables << 358 << " spline=" << spline << " ptr: " << 359 } 563 } 360 564 361 if(&part == particle) { 565 if(&part == particle) { 362 if(isMaster) { << 566 if(!tablesAreBuilt) { 363 lManager->BuildPhysicsTable(particle, th << 567 G4LossTableManager::Instance()->BuildPhysicsTable(particle, this); 364 << 568 } 365 } else { << 569 if(!baseParticle) { 366 const auto masterProcess = << 570 if(0 < verboseLevel) { PrintInfoDefinition(); } 367 static_cast<const G4VEnergyLossProcess << 571 368 << 572 // needs to be done only once 369 numberOfModels = modelManager->NumberOfM << 573 safetyHelper->InitialiseHelper(); 370 G4EmTableUtil::BuildLocalElossProcess(th << 371 pa << 372 tablesAreBuilt = true; << 373 baseMat = masterProcess->UseBaseMaterial << 374 lManager->LocalPhysicsTables(particle, t << 375 } 574 } 376 << 377 // needs to be done only once << 378 safetyHelper->InitialiseHelper(); << 379 } 575 } >> 576 380 // Added tracking cut to avoid tracking arti 577 // Added tracking cut to avoid tracking artifacts 381 // and identified deexcitation flag << 578 // identify deexcitation flag 382 if(isIonisation) { 579 if(isIonisation) { 383 atomDeexcitation = lManager->AtomDeexcitat << 580 fParticleChange.SetLowEnergyLimit(lowestKinEnergy); 384 if(nullptr != atomDeexcitation) { << 581 atomDeexcitation = G4LossTableManager::Instance()->AtomDeexcitation(); >> 582 if(atomDeexcitation) { 385 if(atomDeexcitation->IsPIXEActive()) { u 583 if(atomDeexcitation->IsPIXEActive()) { useDeexcitation = true; } 386 } 584 } 387 } 585 } 388 586 389 // protection against double printout << 390 if(theParameters->IsPrintLocked()) { return; << 391 << 392 // explicitly defined printout by particle n << 393 G4String num = part.GetParticleName(); << 394 if(1 < verboseLevel || << 395 (0 < verboseLevel && (num == "e-" || << 396 num == "e+" || n << 397 num == "mu-" || n << 398 num == "pi+" || n << 399 num == "kaon+" || n << 400 num == "alpha" || n << 401 num == "GenericIon" << 402 StreamInfo(G4cout, part); << 403 } << 404 if(1 < verboseLevel) { 587 if(1 < verboseLevel) { 405 G4cout << "### G4VEnergyLossProcess::Build 588 G4cout << "### G4VEnergyLossProcess::BuildPhysicsTable() done for " 406 << GetProcessName() 589 << GetProcessName() 407 << " and particle " << part.GetPart 590 << " and particle " << part.GetParticleName(); 408 if(isIonisation) { G4cout << " isIonisati << 591 if(isIonisation) { G4cout << " isIonisation flag = 1"; } 409 G4cout << " baseMat=" << baseMat << G4endl << 592 G4cout << G4endl; 410 } 593 } 411 } 594 } 412 595 413 //....oooOO0OOooo........oooOO0OOooo........oo 596 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 414 597 415 G4PhysicsTable* G4VEnergyLossProcess::BuildDED 598 G4PhysicsTable* G4VEnergyLossProcess::BuildDEDXTable(G4EmTableType tType) 416 { 599 { 417 G4PhysicsTable* table = nullptr; << 600 if(1 < verboseLevel) { >> 601 G4cout << "G4VEnergyLossProcess::BuildDEDXTable() of type " << tType >> 602 << " for " << GetProcessName() >> 603 << " and particle " << particle->GetParticleName() >> 604 << G4endl; >> 605 } >> 606 G4PhysicsTable* table = 0; 418 G4double emax = maxKinEnergy; 607 G4double emax = maxKinEnergy; 419 G4int bin = nBins; 608 G4int bin = nBins; 420 609 421 if(fTotal == tType) { 610 if(fTotal == tType) { 422 emax = maxKinEnergyCSDA; 611 emax = maxKinEnergyCSDA; 423 bin = nBinsCSDA; 612 bin = nBinsCSDA; 424 table = theDEDXunRestrictedTable; 613 table = theDEDXunRestrictedTable; 425 } else if(fRestricted == tType) { 614 } else if(fRestricted == tType) { 426 table = theDEDXTable; 615 table = theDEDXTable; >> 616 if(theIonisationTable) >> 617 table = G4PhysicsTableHelper::PreparePhysicsTable(theIonisationTable); >> 618 } else if(fSubRestricted == tType) { >> 619 table = theDEDXSubTable; >> 620 if(theIonisationSubTable) >> 621 table = G4PhysicsTableHelper::PreparePhysicsTable(theIonisationSubTable); 427 } else { 622 } else { 428 G4cout << "G4VEnergyLossProcess::BuildDEDX 623 G4cout << "G4VEnergyLossProcess::BuildDEDXTable WARNING: wrong type " 429 << tType << G4endl; << 624 << tType << G4endl; 430 } 625 } >> 626 >> 627 // Access to materials >> 628 const G4ProductionCutsTable* theCoupleTable= >> 629 G4ProductionCutsTable::GetProductionCutsTable(); >> 630 size_t numOfCouples = theCoupleTable->GetTableSize(); >> 631 431 if(1 < verboseLevel) { 632 if(1 < verboseLevel) { 432 G4cout << "G4VEnergyLossProcess::BuildDEDX << 633 G4cout << numOfCouples << " materials" 433 << " for " << GetProcessName() << 634 << " minKinEnergy= " << minKinEnergy 434 << " and " << particle->GetParticle << 635 << " maxKinEnergy= " << emax 435 << "spline=" << spline << G4endl; << 636 << " nbin= " << bin >> 637 << " EmTableType= " << tType >> 638 << " table= " << table >> 639 << G4endl; 436 } 640 } 437 if(nullptr == table) { return table; } << 641 if(!table) return table; 438 642 439 G4LossTableBuilder* bld = lManager->GetTable << 643 G4LossTableBuilder* bld = (G4LossTableManager::Instance())->GetTableBuilder(); 440 G4EmTableUtil::BuildDEDXTable(this, particle << 644 G4bool splineFlag = (G4LossTableManager::Instance())->SplineFlag(); 441 table, minKinE << 645 G4PhysicsLogVector* aVector = 0; 442 verboseLevel, << 646 G4PhysicsLogVector* bVector = 0; 443 return table; << 444 } << 445 647 446 //....oooOO0OOooo........oooOO0OOooo........oo << 648 for(size_t i=0; i<numOfCouples; ++i) { 447 649 448 G4PhysicsTable* G4VEnergyLossProcess::BuildLam << 650 if(1 < verboseLevel) { 449 { << 651 G4cout << "G4VEnergyLossProcess::BuildDEDXVector flagTable= " 450 if(nullptr == theLambdaTable) { return theLa << 652 << table->GetFlag(i) << " Flag= " << bld->GetFlag(i) << G4endl; >> 653 } >> 654 if (/*table->GetFlag(i)*/bld->GetFlag(i)) { 451 655 452 G4double scale = theParameters->MaxKinEnergy << 656 // create physics vector and fill it 453 G4int nbin = << 657 const G4MaterialCutsCouple* couple = 454 theParameters->NumberOfBinsPerDecade()*G4l << 658 theCoupleTable->GetMaterialCutsCouple(i); 455 scale = nbin/G4Log(scale); << 659 //bVector = static_cast<G4PhysicsLogVector*>((*table)[i]); 456 << 660 if(!bVector) { 457 G4LossTableBuilder* bld = lManager->GetTable << 661 aVector = new G4PhysicsLogVector(minKinEnergy, emax, bin); 458 G4EmTableUtil::BuildLambdaTable(this, partic << 662 bVector = aVector; 459 bld, theLamb << 663 } else { 460 minKinEnergy << 664 aVector = new G4PhysicsLogVector(*bVector); 461 verboseLevel << 665 } 462 return theLambdaTable; << 666 aVector->SetSpline(splineFlag); 463 } << 464 667 465 //....oooOO0OOooo........oooOO0OOooo........oo << 668 modelManager->FillDEDXVector(aVector, couple, tType); >> 669 if(splineFlag) { aVector->FillSecondDerivatives(); } 466 670 467 void G4VEnergyLossProcess::StreamInfo(std::ost << 671 // Insert vector for this material into the table 468 const G4ParticleDefinition& pa << 672 G4PhysicsTableHelper::SetPhysicsVector(table, i, aVector); 469 { << 470 G4String indent = (rst ? " " : ""); << 471 out << std::setprecision(6); << 472 out << G4endl << indent << GetProcessName() << 473 if (!rst) out << " for " << part.GetParticle << 474 out << " XStype:" << fXSType << 475 << " SubType=" << GetProcessSubType() < << 476 << " dE/dx and range tables from " << 477 << G4BestUnit(minKinEnergy,"Energy") << 478 << " to " << G4BestUnit(maxKinEnergy,"En << 479 << " in " << nBins << " bins" << G4endl << 480 << " Lambda tables from threshold t << 481 << G4BestUnit(maxKinEnergy,"Energy") << 482 << ", " << theParameters->NumberOfBinsPe << 483 << " bins/decade, spline: " << spline << 484 << G4endl; << 485 if(nullptr != theRangeTableForLoss && isIoni << 486 out << " StepFunction=(" << dRoverRan << 487 << finalRange/mm << " mm)" << 488 << ", integ: " << fXSType << 489 << ", fluct: " << lossFluctuationFlag << 490 << ", linLossLim= " << linLossLimit << 491 << G4endl; << 492 } << 493 StreamProcessInfo(out); << 494 modelManager->DumpModelList(out, verboseLeve << 495 if(nullptr != theCSDARangeTable && isIonisat << 496 out << " CSDA range table up" << 497 << " to " << G4BestUnit(maxKinEnergyCS << 498 << " in " << nBinsCSDA << " bins" << G << 499 } << 500 if(nSCoffRegions>0 && isIonisation) { << 501 out << " Subcutoff sampling in " << n << 502 << " regions" << G4endl; << 503 } << 504 if(2 < verboseLevel) { << 505 for(std::size_t i=0; i<7; ++i) { << 506 auto ta = theData->Table(i); << 507 out << " " << tnames[i] << " addres << 508 if(nullptr != ta) { out << *ta << G4endl << 509 } 673 } 510 } 674 } >> 675 >> 676 if(1 < verboseLevel) { >> 677 G4cout << "G4VEnergyLossProcess::BuildDEDXTable(): table is built for " >> 678 << particle->GetParticleName() >> 679 << " and process " << GetProcessName() >> 680 << G4endl; >> 681 // if(2 < verboseLevel) G4cout << (*table) << G4endl; >> 682 } >> 683 >> 684 return table; 511 } 685 } 512 686 513 //....oooOO0OOooo........oooOO0OOooo........oo 687 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 514 688 515 void G4VEnergyLossProcess::ActivateSubCutoff(c << 689 G4PhysicsTable* G4VEnergyLossProcess::BuildLambdaTable(G4EmTableType tType) 516 { 690 { 517 if(nullptr == scoffRegions) { << 691 G4PhysicsTable* table = 0; 518 scoffRegions = new std::vector<const G4Reg << 692 >> 693 if(fRestricted == tType) { >> 694 table = theLambdaTable; >> 695 } else if(fSubRestricted == tType) { >> 696 table = theSubLambdaTable; >> 697 } else { >> 698 G4cout << "G4VEnergyLossProcess::BuildLambdaTable WARNING: wrong type " >> 699 << tType << G4endl; 519 } 700 } 520 // the region is in the list << 701 521 if(!scoffRegions->empty()) { << 702 if(1 < verboseLevel) { 522 for (auto & reg : *scoffRegions) { << 703 G4cout << "G4VEnergyLossProcess::BuildLambdaTable() of type " 523 if (reg == r) { return; } << 704 << tType << " for process " >> 705 << GetProcessName() << " and particle " >> 706 << particle->GetParticleName() >> 707 << " EmTableType= " << tType >> 708 << " table= " << table >> 709 << G4endl; >> 710 } >> 711 if(!table) {return table;} >> 712 >> 713 // Access to materials >> 714 const G4ProductionCutsTable* theCoupleTable= >> 715 G4ProductionCutsTable::GetProductionCutsTable(); >> 716 size_t numOfCouples = theCoupleTable->GetTableSize(); >> 717 >> 718 G4LossTableBuilder* bld = (G4LossTableManager::Instance())->GetTableBuilder(); >> 719 G4bool splineFlag = (G4LossTableManager::Instance())->SplineFlag(); >> 720 G4PhysicsLogVector* aVector = 0; >> 721 G4double scale = std::log(maxKinEnergy/minKinEnergy); >> 722 >> 723 for(size_t i=0; i<numOfCouples; ++i) { >> 724 >> 725 if (/*table->GetFlag(i)*/bld->GetFlag(i)) { >> 726 // if (table->GetFlag(i)) { >> 727 >> 728 // create physics vector and fill it >> 729 const G4MaterialCutsCouple* couple = >> 730 theCoupleTable->GetMaterialCutsCouple(i); >> 731 G4double emin = MinPrimaryEnergy(particle,couple->GetMaterial(),(*theCuts)[i]); >> 732 if(0.0 >= emin) { emin = eV; } >> 733 else if(maxKinEnergy <= emin) { emin = 0.5*maxKinEnergy; } >> 734 G4int bin = G4int(nBins*std::log(maxKinEnergy/emin)/scale + 0.5); >> 735 if(bin < 3) { bin = 3; } >> 736 aVector = new G4PhysicsLogVector(emin, maxKinEnergy, bin); >> 737 aVector->SetSpline(splineFlag); >> 738 >> 739 modelManager->FillLambdaVector(aVector, couple, true, tType); >> 740 if(splineFlag) { aVector->FillSecondDerivatives(); } >> 741 >> 742 // Insert vector for this material into the table >> 743 G4PhysicsTableHelper::SetPhysicsVector(table, i, aVector); 524 } 744 } 525 } 745 } 526 // new region << 746 527 scoffRegions->push_back(r); << 747 if(1 < verboseLevel) { 528 ++nSCoffRegions; << 748 G4cout << "Lambda table is built for " >> 749 << particle->GetParticleName() >> 750 << G4endl; >> 751 } >> 752 >> 753 return table; 529 } 754 } 530 755 531 //....oooOO0OOooo........oooOO0OOooo........oo 756 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 532 757 533 G4bool G4VEnergyLossProcess::IsRegionForCubcut << 758 void G4VEnergyLossProcess::PrintInfoDefinition() 534 { 759 { 535 if(0 == nSCoffRegions) { return true; } << 760 if(0 < verboseLevel) { 536 const G4Region* r = aTrack.GetVolume()->GetL << 761 G4cout << G4endl << GetProcessName() << ": for " 537 for(auto & reg : *scoffRegions) { << 762 << particle->GetParticleName() 538 if(r == reg) { return true; } << 763 << " SubType= " << GetProcessSubType() >> 764 << G4endl >> 765 << " dE/dx and range tables from " >> 766 << G4BestUnit(minKinEnergy,"Energy") >> 767 << " to " << G4BestUnit(maxKinEnergy,"Energy") >> 768 << " in " << nBins << " bins" << G4endl >> 769 << " Lambda tables from threshold to " >> 770 << G4BestUnit(maxKinEnergy,"Energy") >> 771 << " in " << nBins << " bins, spline: " >> 772 << (G4LossTableManager::Instance())->SplineFlag() >> 773 << G4endl; >> 774 if(theRangeTableForLoss && isIonisation) { >> 775 G4cout << " finalRange(mm)= " << finalRange/mm >> 776 << ", dRoverRange= " << dRoverRange >> 777 << ", integral: " << integral >> 778 << ", fluct: " << lossFluctuationFlag >> 779 << ", linLossLimit= " << linLossLimit >> 780 << G4endl; >> 781 } >> 782 PrintInfo(); >> 783 modelManager->DumpModelList(verboseLevel); >> 784 if(theCSDARangeTable && isIonisation) { >> 785 G4cout << " CSDA range table up" >> 786 << " to " << G4BestUnit(maxKinEnergyCSDA,"Energy") >> 787 << " in " << nBinsCSDA << " bins" << G4endl; >> 788 } >> 789 if(nSCoffRegions>0 && isIonisation) { >> 790 G4cout << " Subcutoff sampling in " << nSCoffRegions >> 791 << " regions" << G4endl; >> 792 } >> 793 if(2 < verboseLevel) { >> 794 G4cout << " DEDXTable address= " << theDEDXTable << G4endl; >> 795 if(theDEDXTable && isIonisation) G4cout << (*theDEDXTable) << G4endl; >> 796 G4cout << "non restricted DEDXTable address= " >> 797 << theDEDXunRestrictedTable << G4endl; >> 798 if(theDEDXunRestrictedTable && isIonisation) { >> 799 G4cout << (*theDEDXunRestrictedTable) << G4endl; >> 800 } >> 801 if(theDEDXSubTable && isIonisation) { >> 802 G4cout << (*theDEDXSubTable) << G4endl; >> 803 } >> 804 G4cout << " CSDARangeTable address= " << theCSDARangeTable >> 805 << G4endl; >> 806 if(theCSDARangeTable && isIonisation) { >> 807 G4cout << (*theCSDARangeTable) << G4endl; >> 808 } >> 809 G4cout << " RangeTableForLoss address= " << theRangeTableForLoss >> 810 << G4endl; >> 811 if(theRangeTableForLoss && isIonisation) { >> 812 G4cout << (*theRangeTableForLoss) << G4endl; >> 813 } >> 814 G4cout << " InverseRangeTable address= " << theInverseRangeTable >> 815 << G4endl; >> 816 if(theInverseRangeTable && isIonisation) { >> 817 G4cout << (*theInverseRangeTable) << G4endl; >> 818 } >> 819 G4cout << " LambdaTable address= " << theLambdaTable << G4endl; >> 820 if(theLambdaTable && isIonisation) { >> 821 G4cout << (*theLambdaTable) << G4endl; >> 822 } >> 823 G4cout << " SubLambdaTable address= " << theSubLambdaTable << G4endl; >> 824 if(theSubLambdaTable && isIonisation) { >> 825 G4cout << (*theSubLambdaTable) << G4endl; >> 826 } >> 827 } 539 } 828 } 540 return false; << 541 } 829 } 542 830 543 //....oooOO0OOooo........oooOO0OOooo........oo 831 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 544 832 545 void G4VEnergyLossProcess::StartTracking(G4Tra << 833 void G4VEnergyLossProcess::ActivateSubCutoff(G4bool val, const G4Region* r) 546 { 834 { 547 // reset parameters for the new track << 835 G4RegionStore* regionStore = G4RegionStore::GetInstance(); 548 theNumberOfInteractionLengthLeft = -1.0; << 836 const G4Region* reg = r; 549 mfpKinEnergy = DBL_MAX; << 837 if (!reg) {reg = regionStore->GetRegion("DefaultRegionForTheWorld", false);} 550 preStepLambda = 0.0; << 551 currentCouple = nullptr; << 552 838 553 // reset ion << 839 // the region is in the list 554 if(isIon) { << 840 if (nSCoffRegions) { 555 const G4double newmass = track->GetDefinit << 841 for (G4int i=0; i<nSCoffRegions; ++i) { 556 massRatio = (nullptr == baseParticle) ? CL << 842 if (reg == scoffRegions[i]) { 557 : baseParticle->GetPDGMass()/newmass; << 843 return; 558 logMassRatio = G4Log(massRatio); << 844 } 559 } << 560 // forced biasing only for primary particles << 561 if(nullptr != biasManager) { << 562 if(0 == track->GetParentID()) { << 563 biasFlag = true; << 564 biasManager->ResetForcedInteraction(); << 565 } 845 } 566 } 846 } >> 847 >> 848 // new region >> 849 if(val) { >> 850 useSubCutoff = true; >> 851 scoffRegions.push_back(reg); >> 852 ++nSCoffRegions; >> 853 } else { >> 854 useSubCutoff = false; >> 855 } 567 } 856 } 568 857 569 //....oooOO0OOooo........oooOO0OOooo........oo 858 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 570 859 571 G4double G4VEnergyLossProcess::AlongStepGetPhy 860 G4double G4VEnergyLossProcess::AlongStepGetPhysicalInteractionLength( 572 const G4Track& tr << 861 const G4Track&,G4double,G4double,G4double&, 573 G4GPILSelection* 862 G4GPILSelection* selection) 574 { 863 { 575 G4double x = DBL_MAX; 864 G4double x = DBL_MAX; 576 *selection = aGPILSelection; 865 *selection = aGPILSelection; 577 if(isIonisation && currentModel->IsActive(pr << 866 if(isIonisation) { 578 GetScaledRangeForScaledEnergy(preStepScale << 867 fRange = GetScaledRangeForScaledEnergy(preStepScaledEnergy)*reduceFactor; 579 x = (useCutAsFinalRange) ? std::min(finalR << 868 580 currentCouple->GetProductionCuts()->GetP << 869 x = fRange; 581 x = (fRange > x) ? fRange*dRoverRange + x* << 870 G4double y = x*dRoverRange; 582 : fRange; << 871 G4double finR = finalRange; 583 /* << 872 if(rndmStepFlag) { 584 G4cout<<"AlongStepGPIL: " << GetProcessN << 873 finR = std::min(finR,currentCouple->GetProductionCuts()->GetProductionCut(1)); 585 << " fRange=" << fRange << " finR=" << finR << 874 } >> 875 if(x > finR) { x = y + finR*(1.0 - dRoverRange)*(2.0 - finR/fRange); } >> 876 /* >> 877 G4cout<<GetProcessName()<<": e= "<<preStepKinEnergy >> 878 <<" range= "<<fRange << " idx= " << basedCoupleIndex >> 879 << " y= " << y << " finR= " << finR >> 880 << " limit= " << x <<G4endl; 586 */ 881 */ 587 } 882 } >> 883 //G4cout<<GetProcessName()<<": e= "<<preStepKinEnergy <<" stepLimit= "<<x<<G4endl; 588 return x; 884 return x; 589 } 885 } 590 886 591 //....oooOO0OOooo........oooOO0OOooo........oo 887 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 592 888 593 G4double G4VEnergyLossProcess::PostStepGetPhys 889 G4double G4VEnergyLossProcess::PostStepGetPhysicalInteractionLength( 594 const G4Track& tr 890 const G4Track& track, 595 G4double previo 891 G4double previousStepSize, 596 G4ForceCondition* 892 G4ForceCondition* condition) 597 { 893 { 598 // condition is set to "Not Forced" 894 // condition is set to "Not Forced" 599 *condition = NotForced; 895 *condition = NotForced; 600 G4double x = DBL_MAX; 896 G4double x = DBL_MAX; 601 897 602 // initialisation of material, mass, charge, << 898 // initialisation of material, mass, charge, model at the beginning of the step 603 // at the beginning of the step << 899 const G4ParticleDefinition* currPart = track.GetParticleDefinition(); >> 900 if(theGenericIon == particle) { >> 901 massRatio = proton_mass_c2/currPart->GetPDGMass(); >> 902 } >> 903 /* >> 904 if(!theDensityFactor || !theDensityIdx) { >> 905 G4cout << "G4VEnergyLossProcess::PostStepGetPhysicalInteractionLength 1: " >> 906 << theDensityFactor << " " << theDensityIdx >> 907 << G4endl; >> 908 G4cout << track.GetDefinition()->GetParticleName() >> 909 << " e(MeV)= " << track.GetKineticEnergy() >> 910 << " mat " << track.GetMaterialCutsCouple()->GetMaterial()->GetName() >> 911 << G4endl; >> 912 } >> 913 */ 604 DefineMaterial(track.GetMaterialCutsCouple() 914 DefineMaterial(track.GetMaterialCutsCouple()); 605 preStepKinEnergy = track.GetKineticEne << 915 preStepKinEnergy = track.GetKineticEnergy(); 606 preStepScaledEnergy = preStepKinEnergy*ma << 916 preStepScaledEnergy = preStepKinEnergy*massRatio; 607 SelectModel(preStepScaledEnergy); 917 SelectModel(preStepScaledEnergy); >> 918 if(!currentModel->IsActive(preStepScaledEnergy)) { return x; } 608 919 609 if(!currentModel->IsActive(preStepScaledEner << 920 // change effective charge of an ion on fly 610 theNumberOfInteractionLengthLeft = -1.0; << 611 mfpKinEnergy = DBL_MAX; << 612 preStepLambda = 0.0; << 613 currentInteractionLength = DBL_MAX; << 614 return x; << 615 } << 616 << 617 // change effective charge of a charged part << 618 if(isIon) { 921 if(isIon) { 619 const G4double q2 = currentModel->ChargeSq << 922 G4double q2 = currentModel->ChargeSquareRatio(track); 620 fFactor = q2*biasFactor; << 923 if(q2 != chargeSqRatio) { 621 if(baseMat) { fFactor *= (*theDensityFacto << 924 chargeSqRatio = q2; 622 reduceFactor = 1.0/(fFactor*massRatio); << 925 fFactor = q2*biasFactor*(*theDensityFactor)[currentCoupleIndex]; 623 if (lossFluctuationFlag) { << 926 reduceFactor = 1.0/(fFactor*massRatio); 624 auto fluc = currentModel->GetModelOfFluc << 625 fluc->SetParticleAndCharge(track.GetDefi << 626 } 927 } 627 } 928 } >> 929 //G4cout << "q2= " << chargeSqRatio << " massRatio= " << massRatio << G4endl; >> 930 // initialisation for sampling of the interaction length >> 931 if(previousStepSize <= 0.0) { theNumberOfInteractionLengthLeft = -1.0; } >> 932 if(theNumberOfInteractionLengthLeft < 0.0) { mfpKinEnergy = DBL_MAX; } 628 933 629 // forced biasing only for primary particles 934 // forced biasing only for primary particles 630 if(biasManager) { 935 if(biasManager) { 631 if(0 == track.GetParentID() && biasFlag && << 936 if(0 == track.GetParentID()) { 632 biasManager->ForcedInteractionRegion((G << 937 if(0 == track.GetCurrentStepNumber()) { 633 return biasManager->GetStepLimit((G4int) << 938 biasFlag = true; >> 939 biasManager->ResetForcedInteraction(); >> 940 } >> 941 if(biasFlag && biasManager->ForcedInteractionRegion(currentCoupleIndex)) { >> 942 return biasManager->GetStepLimit(currentCoupleIndex, previousStepSize); >> 943 } 634 } 944 } 635 } 945 } 636 946 637 ComputeLambdaForScaledEnergy(preStepScaledEn << 947 // compute mean free path 638 << 948 if(preStepScaledEnergy < mfpKinEnergy) { 639 // zero cross section << 949 if (integral) { ComputeLambdaForScaledEnergy(preStepScaledEnergy); } 640 if(preStepLambda <= 0.0) { << 950 else { preStepLambda = GetLambdaForScaledEnergy(preStepScaledEnergy); } 641 theNumberOfInteractionLengthLeft = -1.0; << 951 if(preStepLambda <= 0.0) { mfpKinEnergy = 0.0; } 642 currentInteractionLength = DBL_MAX; << 952 } 643 } else { << 644 953 645 // non-zero cross section << 954 // non-zero cross section >> 955 if(preStepLambda > 0.0) { 646 if (theNumberOfInteractionLengthLeft < 0.0 956 if (theNumberOfInteractionLengthLeft < 0.0) { 647 << 648 // beggining of tracking (or just after 957 // beggining of tracking (or just after DoIt of this process) 649 theNumberOfInteractionLengthLeft = -G4Lo << 958 ResetNumberOfInteractionLengthLeft(); 650 theInitialNumberOfInteractionLength = th << 651 << 652 } else if(currentInteractionLength < DBL_M 959 } else if(currentInteractionLength < DBL_MAX) { 653 << 960 // subtract NumberOfInteractionLengthLeft 654 // subtract NumberOfInteractionLengthLef << 961 SubtractNumberOfInteractionLengthLeft(previousStepSize); 655 theNumberOfInteractionLengthLeft -= << 962 if(theNumberOfInteractionLengthLeft < 0.) { 656 previousStepSize/currentInteractionLen << 963 theNumberOfInteractionLengthLeft = perMillion; 657 << 964 } 658 theNumberOfInteractionLengthLeft = << 659 std::max(theNumberOfInteractionLengthL << 660 } 965 } 661 966 662 // new mean free path and step limit << 967 // get mean free path and step limit 663 currentInteractionLength = 1.0/preStepLamb 968 currentInteractionLength = 1.0/preStepLambda; 664 x = theNumberOfInteractionLengthLeft * cur 969 x = theNumberOfInteractionLengthLeft * currentInteractionLength; 665 } << 666 #ifdef G4VERBOSE << 667 if (verboseLevel>2) { << 668 G4cout << "G4VEnergyLossProcess::PostStepG << 669 G4cout << "[ " << GetProcessName() << "]" << 670 G4cout << " for " << track.GetDefinition() << 671 << " in Material " << currentMate << 672 << " Ekin(MeV)= " << preStepKinEner << 673 << " track material: " << track.Get << 674 <<G4endl; << 675 G4cout << "MeanFreePath = " << currentInte << 676 << "InteractionLength= " << x/cm << << 677 } << 678 #endif << 679 return x; << 680 } << 681 << 682 //....oooOO0OOooo........oooOO0OOooo........oo << 683 970 684 void << 971 #ifdef G4VERBOSE 685 G4VEnergyLossProcess::ComputeLambdaForScaledEn << 972 if (verboseLevel>2){ 686 { << 973 G4cout << "G4VEnergyLossProcess::PostStepGetPhysicalInteractionLength "; 687 // cross section increased with energy << 974 G4cout << "[ " << GetProcessName() << "]" << G4endl; 688 if(fXSType == fEmIncreasing) { << 975 G4cout << " for " << currPart->GetParticleName() 689 if(e*invLambdaFactor < mfpKinEnergy) { << 976 << " in Material " << currentMaterial->GetName() 690 preStepLambda = GetLambdaForScaledEnergy << 977 << " Ekin(MeV)= " << preStepKinEnergy/MeV 691 mfpKinEnergy = (preStepLambda > 0.0) ? e << 978 <<G4endl; 692 } << 979 G4cout << "MeanFreePath = " << currentInteractionLength/cm << "[cm]" 693 << 980 << "InteractionLength= " << x/cm <<"[cm] " <<G4endl; 694 // cross section has one peak << 695 } else if(fXSType == fEmOnePeak) { << 696 const G4double epeak = (*theEnergyOfCrossS << 697 if(e <= epeak) { << 698 if(e*invLambdaFactor < mfpKinEnergy) { << 699 preStepLambda = GetLambdaForScaledEner << 700 mfpKinEnergy = (preStepLambda > 0.0) ? << 701 } << 702 } else if(e < mfpKinEnergy) { << 703 const G4double e1 = std::max(epeak, e*la << 704 mfpKinEnergy = e1; << 705 preStepLambda = GetLambdaForScaledEnergy << 706 } << 707 << 708 // cross section has more than one peaks << 709 } else if(fXSType == fEmTwoPeaks) { << 710 G4TwoPeaksXS* xs = (*fXSpeaks)[basedCouple << 711 const G4double e1peak = xs->e1peak; << 712 << 713 // below the 1st peak << 714 if(e <= e1peak) { << 715 if(e*invLambdaFactor < mfpKinEnergy) { << 716 preStepLambda = GetLambdaForScaledEner << 717 mfpKinEnergy = (preStepLambda > 0.0) ? << 718 } << 719 return; << 720 } << 721 const G4double e1deep = xs->e1deep; << 722 // above the 1st peak, below the deep << 723 if(e <= e1deep) { << 724 if(mfpKinEnergy >= e1deep || e <= mfpKin << 725 const G4double e1 = std::max(e1peak, e << 726 mfpKinEnergy = e1; << 727 preStepLambda = GetLambdaForScaledEner << 728 } << 729 return; << 730 } << 731 const G4double e2peak = xs->e2peak; << 732 // above the deep, below 2nd peak << 733 if(e <= e2peak) { << 734 if(e*invLambdaFactor < mfpKinEnergy) { << 735 mfpKinEnergy = e; << 736 preStepLambda = GetLambdaForScaledEner << 737 } << 738 return; << 739 } << 740 const G4double e2deep = xs->e2deep; << 741 // above the 2nd peak, below the deep << 742 if(e <= e2deep) { << 743 if(mfpKinEnergy >= e2deep || e <= mfpKin << 744 const G4double e1 = std::max(e2peak, e << 745 mfpKinEnergy = e1; << 746 preStepLambda = GetLambdaForScaledEner << 747 } << 748 return; << 749 } << 750 const G4double e3peak = xs->e3peak; << 751 // above the deep, below 3d peak << 752 if(e <= e3peak) { << 753 if(e*invLambdaFactor < mfpKinEnergy) { << 754 mfpKinEnergy = e; << 755 preStepLambda = GetLambdaForScaledEner << 756 } << 757 return; << 758 } << 759 // above 3d peak << 760 if(e <= mfpKinEnergy) { << 761 const G4double e1 = std::max(e3peak, e*l << 762 mfpKinEnergy = e1; << 763 preStepLambda = GetLambdaForScaledEnergy << 764 } 981 } 765 // integral method is not used << 982 #endif >> 983 // zero cross section case 766 } else { 984 } else { 767 preStepLambda = GetLambdaForScaledEnergy(e << 985 if(theNumberOfInteractionLengthLeft > DBL_MIN && >> 986 currentInteractionLength < DBL_MAX) { >> 987 // subtract NumberOfInteractionLengthLeft >> 988 SubtractNumberOfInteractionLengthLeft(previousStepSize); >> 989 if(theNumberOfInteractionLengthLeft < 0.) { >> 990 theNumberOfInteractionLengthLeft = perMillion; >> 991 } >> 992 } >> 993 currentInteractionLength = DBL_MAX; 768 } 994 } >> 995 return x; 769 } 996 } 770 997 771 //....oooOO0OOooo........oooOO0OOooo........oo 998 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 772 999 773 G4VParticleChange* G4VEnergyLossProcess::Along 1000 G4VParticleChange* G4VEnergyLossProcess::AlongStepDoIt(const G4Track& track, 774 1001 const G4Step& step) 775 { 1002 { 776 fParticleChange.InitializeForAlongStep(track 1003 fParticleChange.InitializeForAlongStep(track); 777 // The process has range table - calculate e 1004 // The process has range table - calculate energy loss 778 if(!isIonisation || !currentModel->IsActive( 1005 if(!isIonisation || !currentModel->IsActive(preStepScaledEnergy)) { 779 return &fParticleChange; 1006 return &fParticleChange; 780 } 1007 } 781 1008 >> 1009 // Get the actual (true) Step length 782 G4double length = step.GetStepLength(); 1010 G4double length = step.GetStepLength(); >> 1011 if(length <= 0.0) { return &fParticleChange; } 783 G4double eloss = 0.0; 1012 G4double eloss = 0.0; 784 1013 785 /* << 1014 /* 786 if(-1 < verboseLevel) { << 1015 if(1 < verboseLevel) { 787 const G4ParticleDefinition* d = track.GetP 1016 const G4ParticleDefinition* d = track.GetParticleDefinition(); 788 G4cout << "AlongStepDoIt for " 1017 G4cout << "AlongStepDoIt for " 789 << GetProcessName() << " and partic << 1018 << GetProcessName() << " and particle " 790 << " eScaled(MeV)=" << preStepScal << 1019 << d->GetParticleName() 791 << " range(mm)=" << fRange/mm << " << 1020 << " eScaled(MeV)= " << preStepScaledEnergy/MeV 792 << " rf=" << reduceFactor << " q^ << 1021 << " range(mm)= " << fRange/mm 793 << " md=" << d->GetPDGMass() << " << 1022 << " s(mm)= " << length/mm 794 << " " << track.GetMaterial()->Get << 1023 << " rf= " << reduceFactor >> 1024 << " q^2= " << chargeSqRatio >> 1025 << " md= " << d->GetPDGMass() >> 1026 << " status= " << track.GetTrackStatus() >> 1027 << G4endl; 795 } 1028 } 796 */ 1029 */ >> 1030 797 const G4DynamicParticle* dynParticle = track 1031 const G4DynamicParticle* dynParticle = track.GetDynamicParticle(); 798 1032 799 // define new weight for primary and seconda 1033 // define new weight for primary and secondaries 800 G4double weight = fParticleChange.GetParentW 1034 G4double weight = fParticleChange.GetParentWeight(); 801 if(weightFlag) { 1035 if(weightFlag) { 802 weight /= biasFactor; 1036 weight /= biasFactor; 803 fParticleChange.ProposeWeight(weight); << 1037 fParticleChange.ProposeParentWeight(weight); 804 } 1038 } 805 1039 806 // stopping, check actual range and kinetic << 1040 // stopping 807 if (length >= fRange || preStepKinEnergy <= << 1041 if (length >= fRange) { 808 eloss = preStepKinEnergy; 1042 eloss = preStepKinEnergy; 809 if (useDeexcitation) { 1043 if (useDeexcitation) { 810 atomDeexcitation->AlongStepDeexcitation( 1044 atomDeexcitation->AlongStepDeexcitation(scTracks, step, 811 << 1045 eloss, currentCoupleIndex); 812 if(scTracks.size() > 0) { FillSecondarie << 1046 FillSecondariesAlongStep(eloss, weight); 813 eloss = std::max(eloss, 0.0); << 814 } 1047 } 815 fParticleChange.SetProposedKineticEnergy(0 1048 fParticleChange.SetProposedKineticEnergy(0.0); 816 fParticleChange.ProposeLocalEnergyDeposit( 1049 fParticleChange.ProposeLocalEnergyDeposit(eloss); 817 return &fParticleChange; 1050 return &fParticleChange; 818 } 1051 } 819 // zero step length with non-zero range << 820 if(length <= 0.0) { return &fParticleChange; << 821 1052 822 // Short step 1053 // Short step 823 eloss = length*GetDEDXForScaledEnergy(preSte << 1054 eloss = GetDEDXForScaledEnergy(preStepScaledEnergy)*length; 824 LogSca << 1055 825 /* << 826 G4cout << "##### Short STEP: eloss= " << elo << 827 << " Escaled=" << preStepScaledEnergy << 828 << " R=" << fRange << 829 << " L=" << length << 830 << " fFactor=" << fFactor << " minE=" << mi << 831 << " idxBase=" << basedCoupleIndex << G4end << 832 */ << 833 // Long step 1056 // Long step 834 if(eloss > preStepKinEnergy*linLossLimit) { 1057 if(eloss > preStepKinEnergy*linLossLimit) { 835 1058 836 const G4double x = (fRange - length)/reduc << 1059 G4double x = GetScaledRangeForScaledEnergy(preStepScaledEnergy) 837 const G4double de = preStepKinEnergy - Sca << 1060 - length/reduceFactor; 838 if(de > 0.0) { eloss = de; } << 1061 eloss = preStepKinEnergy - ScaledKinEnergyForLoss(x)/massRatio; >> 1062 839 /* 1063 /* 840 if(-1 < verboseLevel) 1064 if(-1 < verboseLevel) 841 G4cout << " Long STEP: rPre(mm)=" << 1065 G4cout << "Long STEP: rPre(mm)= " 842 << GetScaledRangeForScaledEnergy( 1066 << GetScaledRangeForScaledEnergy(preStepScaledEnergy)/mm 843 << " x(mm)=" << x/mm << 1067 << " rPost(mm)= " << x/mm 844 << " eloss(MeV)=" << eloss/MeV << 1068 << " ePre(MeV)= " << preStepScaledEnergy/MeV 845 << " rFactor=" << reduceFactor << 1069 << " eloss(MeV)= " << eloss/MeV 846 << " massRatio=" << massRatio << 1070 << " eloss0(MeV)= " >> 1071 << GetDEDXForScaledEnergy(preStepScaledEnergy)*length/MeV >> 1072 << " lim(MeV)= " << preStepKinEnergy*linLossLimit/MeV 847 << G4endl; 1073 << G4endl; 848 */ 1074 */ 849 } 1075 } 850 1076 851 /* << 1077 /* >> 1078 G4double eloss0 = eloss; 852 if(-1 < verboseLevel ) { 1079 if(-1 < verboseLevel ) { 853 G4cout << "Before fluct: eloss(MeV)= " << 1080 G4cout << "Before fluct: eloss(MeV)= " << eloss/MeV 854 << " e-eloss= " << preStepKinEnergy 1081 << " e-eloss= " << preStepKinEnergy-eloss 855 << " step(mm)= " << length/mm << " << 1082 << " step(mm)= " << length/mm 856 << " fluct= " << lossFluctuationFla << 1083 << " range(mm)= " << fRange/mm >> 1084 << " fluct= " << lossFluctuationFlag >> 1085 << G4endl; 857 } 1086 } 858 */ 1087 */ 859 1088 860 const G4double cut = (*theCuts)[currentCoupl << 1089 G4double cut = (*theCuts)[currentCoupleIndex]; 861 G4double esec = 0.0; 1090 G4double esec = 0.0; 862 1091 >> 1092 // SubCutOff >> 1093 if(useSubCutoff) { >> 1094 if(idxSCoffRegions[currentCoupleIndex]) { >> 1095 >> 1096 G4bool yes = false; >> 1097 G4StepPoint* prePoint = step.GetPreStepPoint(); >> 1098 >> 1099 // Check boundary >> 1100 if(prePoint->GetStepStatus() == fGeomBoundary) { yes = true; } >> 1101 >> 1102 // Check PrePoint >> 1103 else { >> 1104 G4double preSafety = prePoint->GetSafety(); >> 1105 G4double rcut = currentCouple->GetProductionCuts()->GetProductionCut(1); >> 1106 >> 1107 // recompute presafety >> 1108 if(preSafety < rcut) { >> 1109 preSafety = safetyHelper->ComputeSafety(prePoint->GetPosition()); >> 1110 } >> 1111 >> 1112 if(preSafety < rcut) { yes = true; } >> 1113 >> 1114 // Check PostPoint >> 1115 else { >> 1116 G4double postSafety = preSafety - length; >> 1117 if(postSafety < rcut) { >> 1118 postSafety = >> 1119 safetyHelper->ComputeSafety(step.GetPostStepPoint()->GetPosition()); >> 1120 if(postSafety < rcut) { yes = true; } >> 1121 } >> 1122 } >> 1123 } >> 1124 >> 1125 // Decided to start subcut sampling >> 1126 if(yes) { >> 1127 >> 1128 cut = (*theSubCuts)[currentCoupleIndex]; >> 1129 eloss -= GetSubDEDXForScaledEnergy(preStepScaledEnergy)*length; >> 1130 esec = SampleSubCutSecondaries(scTracks, step, >> 1131 currentModel,currentCoupleIndex); >> 1132 // add bremsstrahlung sampling >> 1133 /* >> 1134 if(nProcesses > 0) { >> 1135 for(G4int i=0; i<nProcesses; ++i) { >> 1136 (scProcesses[i])->SampleSubCutSecondaries( >> 1137 scTracks, step, (scProcesses[i])-> >> 1138 SelectModelForMaterial(preStepKinEnergy, currentCoupleIndex), >> 1139 currentCoupleIndex); >> 1140 } >> 1141 } >> 1142 */ >> 1143 } >> 1144 } >> 1145 } >> 1146 863 // Corrections, which cannot be tabulated 1147 // Corrections, which cannot be tabulated 864 if(isIon) { 1148 if(isIon) { >> 1149 G4double eadd = 0.0; >> 1150 G4double eloss_before = eloss; 865 currentModel->CorrectionsAlongStep(current 1151 currentModel->CorrectionsAlongStep(currentCouple, dynParticle, 866 length, << 1152 eloss, eadd, length); 867 eloss = std::max(eloss, 0.0); << 1153 if(eloss < 0.0) { eloss = 0.5*eloss_before; } 868 } 1154 } 869 1155 870 // Sample fluctuations if not full energy lo << 1156 // Sample fluctuations 871 if(eloss >= preStepKinEnergy) { << 1157 if (lossFluctuationFlag) { 872 eloss = preStepKinEnergy; << 873 << 874 } else if (lossFluctuationFlag) { << 875 const G4double tmax = currentModel->MaxSec << 876 const G4double tcut = std::min(cut, tmax); << 877 G4VEmFluctuationModel* fluc = currentModel 1158 G4VEmFluctuationModel* fluc = currentModel->GetModelOfFluctuations(); 878 eloss = fluc->SampleFluctuations(currentCo << 1159 if(fluc && 879 tcut, tma << 1160 (eloss + esec + lowestKinEnergy) < preStepKinEnergy) { 880 /* << 1161 881 if(-1 < verboseLevel) << 1162 G4double tmax = >> 1163 std::min(currentModel->MaxSecondaryKinEnergy(dynParticle),cut); >> 1164 G4double emean = eloss; >> 1165 eloss = fluc->SampleFluctuations(currentMaterial,dynParticle, >> 1166 tmax,length,emean); >> 1167 /* >> 1168 if(-1 < verboseLevel) 882 G4cout << "After fluct: eloss(MeV)= " << 1169 G4cout << "After fluct: eloss(MeV)= " << eloss/MeV 883 << " fluc= " << (eloss-eloss0)/Me 1170 << " fluc= " << (eloss-eloss0)/MeV 884 << " ChargeSqRatio= " << chargeSq 1171 << " ChargeSqRatio= " << chargeSqRatio 885 << " massRatio= " << massRatio << << 1172 << " massRatio= " << massRatio 886 */ << 1173 << " tmax= " << tmax >> 1174 << G4endl; >> 1175 */ >> 1176 } 887 } 1177 } 888 1178 889 // deexcitation 1179 // deexcitation 890 if (useDeexcitation) { 1180 if (useDeexcitation) { 891 G4double esecfluo = preStepKinEnergy; << 1181 G4double eloss_before = eloss; 892 G4double de = esecfluo; << 893 atomDeexcitation->AlongStepDeexcitation(sc 1182 atomDeexcitation->AlongStepDeexcitation(scTracks, step, 894 de << 1183 eloss, currentCoupleIndex); 895 << 1184 esec += eloss_before - eloss; 896 // sum of de-excitation energies << 897 esecfluo -= de; << 898 << 899 // subtracted from energy loss << 900 if(eloss >= esecfluo) { << 901 esec += esecfluo; << 902 eloss -= esecfluo; << 903 } else { << 904 esec += esecfluo; << 905 eloss = 0.0; << 906 } << 907 } << 908 if(nullptr != subcutProducer && IsRegionForC << 909 subcutProducer->SampleSecondaries(step, sc << 910 } 1185 } 911 // secondaries from atomic de-excitation and << 912 if(!scTracks.empty()) { FillSecondariesAlong << 913 1186 914 // Energy balance << 1187 // Energy balanse 915 G4double finalT = preStepKinEnergy - eloss - 1188 G4double finalT = preStepKinEnergy - eloss - esec; 916 if (finalT <= lowestKinEnergy) { 1189 if (finalT <= lowestKinEnergy) { 917 eloss += finalT; 1190 eloss += finalT; 918 finalT = 0.0; 1191 finalT = 0.0; 919 } else if(isIon) { 1192 } else if(isIon) { 920 fParticleChange.SetProposedCharge( 1193 fParticleChange.SetProposedCharge( 921 currentModel->GetParticleCharge(track.Ge 1194 currentModel->GetParticleCharge(track.GetParticleDefinition(), 922 currentM << 1195 currentMaterial,finalT)); 923 } 1196 } 924 eloss = std::max(eloss, 0.0); << 925 1197 >> 1198 FillSecondariesAlongStep(eloss, weight); 926 fParticleChange.SetProposedKineticEnergy(fin 1199 fParticleChange.SetProposedKineticEnergy(finalT); 927 fParticleChange.ProposeLocalEnergyDeposit(el 1200 fParticleChange.ProposeLocalEnergyDeposit(eloss); 928 /* << 1201 >> 1202 /* 929 if(-1 < verboseLevel) { 1203 if(-1 < verboseLevel) { 930 G4double del = finalT + eloss + esec - pre << 931 G4cout << "Final value eloss(MeV)= " << el 1204 G4cout << "Final value eloss(MeV)= " << eloss/MeV 932 << " preStepKinEnergy= " << preStep 1205 << " preStepKinEnergy= " << preStepKinEnergy 933 << " postStepKinEnergy= " << finalT 1206 << " postStepKinEnergy= " << finalT 934 << " de(keV)= " << del/keV << 935 << " lossFlag= " << lossFluctuation 1207 << " lossFlag= " << lossFluctuationFlag 936 << " status= " << track.GetTrackSt 1208 << " status= " << track.GetTrackStatus() 937 << G4endl; 1209 << G4endl; 938 } 1210 } 939 */ << 1211 */ >> 1212 940 return &fParticleChange; 1213 return &fParticleChange; 941 } 1214 } 942 1215 943 //....oooOO0OOooo........oooOO0OOooo........oo 1216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 944 1217 945 void G4VEnergyLossProcess::FillSecondariesAlon << 1218 void >> 1219 G4VEnergyLossProcess::FillSecondariesAlongStep(G4double& eloss, G4double& weight) 946 { 1220 { 947 const std::size_t n0 = scTracks.size(); << 1221 if(eloss < 0.0) { eloss = 0.0; } 948 G4double weight = wt; << 1222 G4int n = scTracks.size(); >> 1223 if(0 == n) { return; } >> 1224 949 // weight may be changed by biasing manager 1225 // weight may be changed by biasing manager >> 1226 G4bool weightNotChanged = true; 950 if(biasManager) { 1227 if(biasManager) { 951 if(biasManager->SecondaryBiasingRegion((G4 << 1228 if(biasManager->SecondaryBiasingRegion(currentCoupleIndex)) { 952 weight *= << 1229 biasManager->ApplySecondaryBiasing(scTracks,weight,currentCoupleIndex); 953 biasManager->ApplySecondaryBiasing(scT << 1230 weightNotChanged = false; 954 } 1231 } 955 } << 1232 } 956 1233 957 // fill secondaries 1234 // fill secondaries 958 const std::size_t n = scTracks.size(); << 1235 fParticleChange.SetNumberOfSecondaries(n); 959 fParticleChange.SetNumberOfSecondaries((G4in << 1236 for(G4int i=0; i<n; ++i) { 960 << 961 for(std::size_t i=0; i<n; ++i) { << 962 G4Track* t = scTracks[i]; 1237 G4Track* t = scTracks[i]; 963 if(nullptr != t) { << 1238 if(t) { 964 t->SetWeight(weight); << 1239 if(weightNotChanged) { t->SetWeight(weight); } 965 pParticleChange->AddSecondary(t); 1240 pParticleChange->AddSecondary(t); 966 G4int pdg = t->GetDefinition()->GetPDGEn << 967 if (i < n0) { << 968 if (pdg == 22) { << 969 t->SetCreatorModelID(gpixeID); << 970 } else if (pdg == 11) { << 971 t->SetCreatorModelID(epixeID); << 972 } else { << 973 t->SetCreatorModelID(biasID); << 974 } << 975 } else { << 976 t->SetCreatorModelID(biasID); << 977 } << 978 } 1241 } 979 } 1242 } 980 scTracks.clear(); 1243 scTracks.clear(); 981 } 1244 } 982 1245 983 //....oooOO0OOooo........oooOO0OOooo........oo 1246 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 984 1247 >> 1248 G4double >> 1249 G4VEnergyLossProcess::SampleSubCutSecondaries(std::vector<G4Track*>& tracks, >> 1250 const G4Step& step, >> 1251 G4VEmModel* model, >> 1252 G4int idx) >> 1253 { >> 1254 // Fast check weather subcutoff can work >> 1255 G4double esec = 0.0; >> 1256 G4double subcut = (*theSubCuts)[idx]; >> 1257 G4double cut = (*theCuts)[idx]; >> 1258 if(cut <= subcut) { return esec; } >> 1259 >> 1260 const G4Track* track = step.GetTrack(); >> 1261 const G4DynamicParticle* dp = track->GetDynamicParticle(); >> 1262 G4double e = dp->GetKineticEnergy()*massRatio; >> 1263 G4double cross = (*theDensityFactor)[idx]*chargeSqRatio >> 1264 *(((*theSubLambdaTable)[(*theDensityIdx)[idx]])->Value(e)); >> 1265 G4double length = step.GetStepLength(); >> 1266 >> 1267 // negligible probability to get any interaction >> 1268 if(length*cross < perMillion) { return esec; } >> 1269 /* >> 1270 if(-1 < verboseLevel) >> 1271 G4cout << "<<< Subcutoff for " << GetProcessName() >> 1272 << " cross(1/mm)= " << cross*mm << ">>>" >> 1273 << " e(MeV)= " << preStepScaledEnergy >> 1274 << " matIdx= " << currentCoupleIndex >> 1275 << G4endl; >> 1276 */ >> 1277 >> 1278 // Sample subcutoff secondaries >> 1279 G4StepPoint* preStepPoint = step.GetPreStepPoint(); >> 1280 G4StepPoint* postStepPoint = step.GetPostStepPoint(); >> 1281 G4ThreeVector prepoint = preStepPoint->GetPosition(); >> 1282 G4ThreeVector dr = postStepPoint->GetPosition() - prepoint; >> 1283 G4double pretime = preStepPoint->GetGlobalTime(); >> 1284 G4double dt = postStepPoint->GetGlobalTime() - pretime; >> 1285 //G4double dt = length/preStepPoint->GetVelocity(); >> 1286 G4double fragment = 0.0; >> 1287 >> 1288 do { >> 1289 G4double del = -std::log(G4UniformRand())/cross; >> 1290 fragment += del/length; >> 1291 if (fragment > 1.0) break; >> 1292 >> 1293 // sample secondaries >> 1294 secParticles.clear(); >> 1295 model->SampleSecondaries(&secParticles,track->GetMaterialCutsCouple(), >> 1296 dp,subcut,cut); >> 1297 >> 1298 // position of subcutoff particles >> 1299 G4ThreeVector r = prepoint + fragment*dr; >> 1300 std::vector<G4DynamicParticle*>::iterator it; >> 1301 for(it=secParticles.begin(); it!=secParticles.end(); ++it) { >> 1302 >> 1303 G4bool addSec = true; >> 1304 /* >> 1305 // do not track very low-energy delta-electrons >> 1306 if(theSecondaryRangeTable && (*it)->GetParticleDefinition() == theElectron) { >> 1307 G4double ekin = (*it)->GetKineticEnergy(); >> 1308 G4double rg = ((*theSecondaryRangeTable)[idx]->Value(ekin)); >> 1309 // if(rg < currentMinSafety) { >> 1310 if(rg < safetyHelper->ComputeSafety(r)) { >> 1311 extraEdep += ekin; >> 1312 delete (*it); >> 1313 addSec = false; >> 1314 } >> 1315 } >> 1316 */ >> 1317 if(addSec) { >> 1318 G4Track* t = new G4Track((*it), pretime + fragment*dt, r); >> 1319 t->SetTouchableHandle(track->GetTouchableHandle()); >> 1320 tracks.push_back(t); >> 1321 esec += t->GetKineticEnergy(); >> 1322 if (t->GetParticleDefinition() == thePositron) { >> 1323 esec += 2.0*electron_mass_c2; >> 1324 } >> 1325 >> 1326 /* >> 1327 if(-1 < verboseLevel) >> 1328 G4cout << "New track " << t->GetParticleDefinition()->GetParticleName() >> 1329 << " e(keV)= " << t->GetKineticEnergy()/keV >> 1330 << " fragment= " << fragment >> 1331 << G4endl; >> 1332 */ >> 1333 } >> 1334 } >> 1335 } while (fragment <= 1.0); >> 1336 return esec; >> 1337 } >> 1338 >> 1339 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 1340 985 G4VParticleChange* G4VEnergyLossProcess::PostS 1341 G4VParticleChange* G4VEnergyLossProcess::PostStepDoIt(const G4Track& track, 986 << 1342 const G4Step&) 987 { 1343 { 988 // clear number of interaction lengths in an << 1344 // In all cases clear number of interaction lengths 989 theNumberOfInteractionLengthLeft = -1.0; 1345 theNumberOfInteractionLengthLeft = -1.0; 990 mfpKinEnergy = DBL_MAX; << 991 1346 992 fParticleChange.InitializeForPostStep(track) 1347 fParticleChange.InitializeForPostStep(track); 993 const G4double finalT = track.GetKineticEner << 1348 G4double finalT = track.GetKineticEnergy(); >> 1349 if(finalT <= lowestKinEnergy) { return &fParticleChange; } 994 1350 995 const G4double postStepScaledEnergy = finalT << 1351 G4double postStepScaledEnergy = finalT*massRatio; 996 SelectModel(postStepScaledEnergy); << 997 1352 998 if(!currentModel->IsActive(postStepScaledEne << 1353 if(!currentModel->IsActive(postStepScaledEnergy)) { return &fParticleChange; } 999 return &fParticleChange; << 1000 } << 1001 /* 1354 /* 1002 if(1 < verboseLevel) { << 1355 if(-1 < verboseLevel) { 1003 G4cout<<GetProcessName()<<" PostStepDoIt: << 1356 G4cout << GetProcessName() >> 1357 << "::PostStepDoIt: E(MeV)= " << finalT/MeV >> 1358 << G4endl; 1004 } 1359 } 1005 */ 1360 */ >> 1361 1006 // forced process - should happen only once 1362 // forced process - should happen only once per track 1007 if(biasFlag) { 1363 if(biasFlag) { 1008 if(biasManager->ForcedInteractionRegion(( << 1364 if(biasManager->ForcedInteractionRegion(currentCoupleIndex)) { 1009 biasFlag = false; 1365 biasFlag = false; 1010 } 1366 } 1011 } 1367 } 1012 const G4DynamicParticle* dp = track.GetDyna << 1013 1368 1014 // Integral approach 1369 // Integral approach 1015 if (fXSType != fEmNoIntegral) { << 1370 if (integral) { 1016 const G4double logFinalT = dp->GetLogKine << 1371 G4double lx = GetLambdaForScaledEnergy(postStepScaledEnergy); 1017 G4double lx = GetLambdaForScaledEnergy(po << 1372 /* 1018 lo << 1373 if(preStepLambda<lx && 1 < verboseLevel && nWarnings<200) { 1019 lx = std::max(lx, 0.0); << 1374 G4cout << "WARNING: for " << particle->GetParticleName() 1020 << 1375 << " and " << GetProcessName() 1021 // if both lg and lx are zero then no int << 1376 << " E(MeV)= " << finalT/MeV 1022 if(preStepLambda*G4UniformRand() >= lx) { << 1377 << " preLambda= " << preStepLambda >> 1378 << " < " << lx << " (postLambda) " >> 1379 << G4endl; >> 1380 ++nWarnings; >> 1381 } >> 1382 */ >> 1383 if(lx <= 0.0) { >> 1384 return &fParticleChange; >> 1385 } else if(preStepLambda*G4UniformRand() > lx) { 1023 return &fParticleChange; 1386 return &fParticleChange; 1024 } 1387 } 1025 } 1388 } 1026 1389 >> 1390 SelectModel(postStepScaledEnergy); >> 1391 1027 // define new weight for primary and second 1392 // define new weight for primary and secondaries 1028 G4double weight = fParticleChange.GetParent 1393 G4double weight = fParticleChange.GetParentWeight(); 1029 if(weightFlag) { 1394 if(weightFlag) { 1030 weight /= biasFactor; 1395 weight /= biasFactor; 1031 fParticleChange.ProposeWeight(weight); << 1396 fParticleChange.ProposeParentWeight(weight); 1032 } 1397 } 1033 1398 1034 const G4double tcut = (*theCuts)[currentCou << 1399 const G4DynamicParticle* dynParticle = track.GetDynamicParticle(); >> 1400 G4double tcut = (*theCuts)[currentCoupleIndex]; 1035 1401 1036 // sample secondaries 1402 // sample secondaries 1037 secParticles.clear(); 1403 secParticles.clear(); 1038 currentModel->SampleSecondaries(&secParticl << 1404 currentModel->SampleSecondaries(&secParticles, currentCouple, dynParticle, tcut); 1039 << 1040 const G4int num0 = (G4int)secParticles.size << 1041 1405 1042 // bremsstrahlung splitting or Russian roul 1406 // bremsstrahlung splitting or Russian roulette 1043 if(biasManager) { 1407 if(biasManager) { 1044 if(biasManager->SecondaryBiasingRegion((G << 1408 if(biasManager->SecondaryBiasingRegion(currentCoupleIndex)) { 1045 G4double eloss = 0.0; << 1409 weight *= biasManager->ApplySecondaryBiasing(secParticles,currentCoupleIndex); 1046 weight *= biasManager->ApplySecondaryBi << 1047 secPart << 1048 track, << 1049 &fParti << 1050 (G4int) << 1051 step.Ge << 1052 if(eloss > 0.0) { << 1053 eloss += fParticleChange.GetLocalEner << 1054 fParticleChange.ProposeLocalEnergyDep << 1055 } << 1056 } 1410 } 1057 } 1411 } 1058 1412 1059 // save secondaries 1413 // save secondaries 1060 const G4int num = (G4int)secParticles.size( << 1414 G4int num = secParticles.size(); 1061 if(num > 0) { 1415 if(num > 0) { 1062 << 1063 fParticleChange.SetNumberOfSecondaries(nu 1416 fParticleChange.SetNumberOfSecondaries(num); 1064 G4double time = track.GetGlobalTime(); << 1065 << 1066 G4int n1(0), n2(0); << 1067 if(num0 > mainSecondaries) { << 1068 currentModel->FillNumberOfSecondaries(n << 1069 } << 1070 << 1071 for (G4int i=0; i<num; ++i) { 1417 for (G4int i=0; i<num; ++i) { 1072 if(nullptr != secParticles[i]) { << 1418 1073 G4Track* t = new G4Track(secParticles << 1419 if(secParticles[i]) { 1074 t->SetTouchableHandle(track.GetToucha << 1420 G4Track* t = new G4Track(secParticles[i], track.GetGlobalTime(), 1075 if (biasManager) { << 1421 track.GetPosition()); 1076 t->SetWeight(weight * biasManager-> << 1422 t->SetTouchableHandle(track.GetTouchableHandle()); 1077 } else { << 1423 t->SetWeight(weight); 1078 t->SetWeight(weight); << 1424 pParticleChange->AddSecondary(t); 1079 } << 1080 if(i < num0) { << 1081 t->SetCreatorModelID(secID); << 1082 } else if(i < num0 + n1) { << 1083 t->SetCreatorModelID(tripletID); << 1084 } else { << 1085 t->SetCreatorModelID(biasID); << 1086 } << 1087 << 1088 //G4cout << "Secondary(post step) has << 1089 // << ", kenergy " << t->GetKin << 1090 // << " time= " << time/ns << " << 1091 pParticleChange->AddSecondary(t); << 1092 } 1425 } 1093 } 1426 } 1094 } 1427 } 1095 1428 1096 if(0.0 == fParticleChange.GetProposedKineti 1429 if(0.0 == fParticleChange.GetProposedKineticEnergy() && 1097 fAlive == fParticleChange.GetTrackStatus 1430 fAlive == fParticleChange.GetTrackStatus()) { 1098 if(particle->GetProcessManager()->GetAtRe 1431 if(particle->GetProcessManager()->GetAtRestProcessVector()->size() > 0) 1099 { fParticleChange.ProposeTrackStatus 1432 { fParticleChange.ProposeTrackStatus(fStopButAlive); } 1100 else { fParticleChange.ProposeTrackStatus 1433 else { fParticleChange.ProposeTrackStatus(fStopAndKill); } 1101 } 1434 } 1102 1435 1103 /* 1436 /* 1104 if(-1 < verboseLevel) { 1437 if(-1 < verboseLevel) { 1105 G4cout << "::PostStepDoIt: Sample seconda 1438 G4cout << "::PostStepDoIt: Sample secondary; Efin= " 1106 << fParticleChange.GetProposedKineticEner 1439 << fParticleChange.GetProposedKineticEnergy()/MeV 1107 << " MeV; model= (" << currentMode 1440 << " MeV; model= (" << currentModel->LowEnergyLimit() 1108 << ", " << currentModel->HighEner 1441 << ", " << currentModel->HighEnergyLimit() << ")" 1109 << " preStepLambda= " << preStepL 1442 << " preStepLambda= " << preStepLambda 1110 << " dir= " << track.GetMomentumD 1443 << " dir= " << track.GetMomentumDirection() 1111 << " status= " << track.GetTrackS 1444 << " status= " << track.GetTrackStatus() 1112 << G4endl; 1445 << G4endl; 1113 } 1446 } 1114 */ 1447 */ 1115 return &fParticleChange; 1448 return &fParticleChange; 1116 } 1449 } 1117 1450 1118 //....oooOO0OOooo........oooOO0OOooo........o 1451 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1119 1452 1120 G4bool G4VEnergyLossProcess::StorePhysicsTabl 1453 G4bool G4VEnergyLossProcess::StorePhysicsTable( 1121 const G4ParticleDefinition* part, cons << 1454 const G4ParticleDefinition* part, const G4String& directory, >> 1455 G4bool ascii) 1122 { 1456 { 1123 if (!isMaster || nullptr != baseParticle || << 1457 G4bool res = true; 1124 for(std::size_t i=0; i<7; ++i) { << 1458 if ( baseParticle || part != particle ) return res; 1125 // ionisation table only for ionisation p << 1459 1126 if (nullptr == theData->Table(i) || (!isI << 1460 if(!StoreTable(part,theDEDXTable,ascii,directory,"DEDX")) 1127 continue; << 1461 {res = false;} 1128 } << 1462 1129 if (-1 < verboseLevel) { << 1463 if(!StoreTable(part,theDEDXunRestrictedTable,ascii,directory,"DEDXnr")) 1130 G4cout << "G4VEnergyLossProcess::StoreP << 1464 {res = false;} 1131 << " " << particle->GetParticleName() << 1465 1132 << " " << GetProcessName() << 1466 if(!StoreTable(part,theDEDXSubTable,ascii,directory,"SubDEDX")) 1133 << " " << tnames[i] << " " << theDat << 1467 {res = false;} 1134 } << 1468 1135 if (!G4EmTableUtil::StoreTable(this, part << 1469 if(!StoreTable(part,theIonisationTable,ascii,directory,"Ionisation")) 1136 dir, tnames[i], verboseLevel, asci << 1470 {res = false;} 1137 return false; << 1471 >> 1472 if(!StoreTable(part,theIonisationSubTable,ascii,directory,"SubIonisation")) >> 1473 {res = false;} >> 1474 >> 1475 if(isIonisation && >> 1476 !StoreTable(part,theCSDARangeTable,ascii,directory,"CSDARange")) >> 1477 {res = false;} >> 1478 >> 1479 if(isIonisation && >> 1480 !StoreTable(part,theRangeTableForLoss,ascii,directory,"Range")) >> 1481 {res = false;} >> 1482 >> 1483 if(isIonisation && >> 1484 !StoreTable(part,theInverseRangeTable,ascii,directory,"InverseRange")) >> 1485 {res = false;} >> 1486 >> 1487 if(!StoreTable(part,theLambdaTable,ascii,directory,"Lambda")) >> 1488 {res = false;} >> 1489 >> 1490 if(!StoreTable(part,theSubLambdaTable,ascii,directory,"SubLambda")) >> 1491 {res = false;} >> 1492 >> 1493 if ( res ) { >> 1494 if(0 < verboseLevel) { >> 1495 G4cout << "Physics tables are stored for " << particle->GetParticleName() >> 1496 << " and process " << GetProcessName() >> 1497 << " in the directory <" << directory >> 1498 << "> " << G4endl; 1138 } 1499 } >> 1500 } else { >> 1501 G4cout << "Fail to store Physics Tables for " >> 1502 << particle->GetParticleName() >> 1503 << " and process " << GetProcessName() >> 1504 << " in the directory <" << directory >> 1505 << "> " << G4endl; 1139 } 1506 } 1140 return true; << 1507 return res; 1141 } 1508 } 1142 1509 1143 //....oooOO0OOooo........oooOO0OOooo........o 1510 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 1144 1511 1145 G4bool 1512 G4bool 1146 G4VEnergyLossProcess::RetrievePhysicsTable(co 1513 G4VEnergyLossProcess::RetrievePhysicsTable(const G4ParticleDefinition* part, 1147 co << 1514 const G4String& directory, >> 1515 G4bool ascii) 1148 { 1516 { 1149 if (!isMaster || nullptr != baseParticle || << 1517 G4bool res = true; 1150 for(std::size_t i=0; i<7; ++i) { << 1518 const G4String particleName = part->GetParticleName(); 1151 // ionisation table only for ionisation p << 1519 1152 if (!isIonisation && 1 == i) { continue; << 1520 if(1 < verboseLevel) { 1153 if(!G4EmTableUtil::RetrieveTable(this, pa << 1521 G4cout << "G4VEnergyLossProcess::RetrievePhysicsTable() for " 1154 verboseL << 1522 << particleName << " and process " << GetProcessName() 1155 return false; << 1523 << "; tables_are_built= " << tablesAreBuilt >> 1524 << G4endl; >> 1525 } >> 1526 if(particle == part) { >> 1527 >> 1528 if ( !baseParticle ) { >> 1529 >> 1530 G4bool fpi = true; >> 1531 if(!RetrieveTable(part,theDEDXTable,ascii,directory,"DEDX",fpi)) >> 1532 {fpi = false;} >> 1533 >> 1534 // ionisation table keeps individual dEdx and not sum of sub-processes >> 1535 if(!RetrieveTable(part,theDEDXTable,ascii,directory,"Ionisation",false)) >> 1536 {fpi = false;} >> 1537 >> 1538 if(!RetrieveTable(part,theRangeTableForLoss,ascii,directory,"Range",fpi)) >> 1539 {res = false;} >> 1540 >> 1541 if(!RetrieveTable(part,theDEDXunRestrictedTable,ascii,directory,"DEDXnr",false)) >> 1542 {res = false;} >> 1543 >> 1544 if(!RetrieveTable(part,theCSDARangeTable,ascii,directory,"CSDARange",false)) >> 1545 {res = false;} >> 1546 >> 1547 if(!RetrieveTable(part,theInverseRangeTable,ascii,directory,"InverseRange",fpi)) >> 1548 {res = false;} >> 1549 >> 1550 if(!RetrieveTable(part,theLambdaTable,ascii,directory,"Lambda",true)) >> 1551 {res = false;} >> 1552 >> 1553 G4bool yes = false; >> 1554 if(nSCoffRegions > 0) {yes = true;} >> 1555 >> 1556 if(!RetrieveTable(part,theDEDXSubTable,ascii,directory,"SubDEDX",yes)) >> 1557 {res = false;} >> 1558 >> 1559 if(!RetrieveTable(part,theSubLambdaTable,ascii,directory,"SubLambda",yes)) >> 1560 {res = false;} >> 1561 >> 1562 if(!fpi) yes = false; >> 1563 if(!RetrieveTable(part,theIonisationSubTable,ascii,directory,"SubIonisation",yes)) >> 1564 {res = false;} >> 1565 } >> 1566 } >> 1567 >> 1568 return res; >> 1569 } >> 1570 >> 1571 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... >> 1572 >> 1573 G4bool G4VEnergyLossProcess::StoreTable(const G4ParticleDefinition* part, >> 1574 G4PhysicsTable* aTable, G4bool ascii, >> 1575 const G4String& directory, >> 1576 const G4String& tname) >> 1577 { >> 1578 G4bool res = true; >> 1579 if ( aTable ) { >> 1580 const G4String name = GetPhysicsTableFileName(part,directory,tname,ascii); >> 1581 if( !aTable->StorePhysicsTable(name,ascii)) res = false; >> 1582 } >> 1583 return res; >> 1584 } >> 1585 >> 1586 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... >> 1587 >> 1588 G4bool >> 1589 G4VEnergyLossProcess::RetrieveTable(const G4ParticleDefinition* part, >> 1590 G4PhysicsTable* aTable, >> 1591 G4bool ascii, >> 1592 const G4String& directory, >> 1593 const G4String& tname, >> 1594 G4bool mandatory) >> 1595 { >> 1596 G4bool isRetrieved = false; >> 1597 G4String filename = GetPhysicsTableFileName(part,directory,tname,ascii); >> 1598 if(aTable) { >> 1599 if(aTable->ExistPhysicsTable(filename)) { >> 1600 if(G4PhysicsTableHelper::RetrievePhysicsTable(aTable,filename,ascii)) { >> 1601 isRetrieved = true; >> 1602 if((G4LossTableManager::Instance())->SplineFlag()) { >> 1603 size_t n = aTable->length(); >> 1604 for(size_t i=0; i<n; ++i) { >> 1605 if((*aTable)[i]) { (*aTable)[i]->SetSpline(true); } >> 1606 } >> 1607 } >> 1608 if (0 < verboseLevel) { >> 1609 G4cout << tname << " table for " << part->GetParticleName() >> 1610 << " is Retrieved from <" << filename << ">" >> 1611 << G4endl; >> 1612 } >> 1613 } 1156 } 1614 } 1157 } 1615 } >> 1616 if(mandatory && !isRetrieved) { >> 1617 if(0 < verboseLevel) { >> 1618 G4cout << tname << " table for " << part->GetParticleName() >> 1619 << " from file <" >> 1620 << filename << "> is not Retrieved" >> 1621 << G4endl; >> 1622 } >> 1623 return false; >> 1624 } 1158 return true; 1625 return true; 1159 } 1626 } 1160 1627 1161 //....oooOO0OOooo........oooOO0OOooo........o 1628 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1162 1629 1163 G4double G4VEnergyLossProcess::GetDEDXDispers 1630 G4double G4VEnergyLossProcess::GetDEDXDispersion( 1164 const G4Mat 1631 const G4MaterialCutsCouple *couple, 1165 const G4Dyn 1632 const G4DynamicParticle* dp, 1166 G4dou 1633 G4double length) 1167 { 1634 { 1168 DefineMaterial(couple); 1635 DefineMaterial(couple); 1169 G4double ekin = dp->GetKineticEnergy(); 1636 G4double ekin = dp->GetKineticEnergy(); 1170 SelectModel(ekin*massRatio); 1637 SelectModel(ekin*massRatio); 1171 G4double tmax = currentModel->MaxSecondaryK 1638 G4double tmax = currentModel->MaxSecondaryKinEnergy(dp); 1172 G4double tcut = std::min(tmax,(*theCuts)[cu << 1639 tmax = std::min(tmax,(*theCuts)[currentCoupleIndex]); 1173 G4double d = 0.0; 1640 G4double d = 0.0; 1174 G4VEmFluctuationModel* fm = currentModel->G 1641 G4VEmFluctuationModel* fm = currentModel->GetModelOfFluctuations(); 1175 if(nullptr != fm) { d = fm->Dispersion(curr << 1642 if(fm) { d = fm->Dispersion(currentMaterial,dp,tmax,length); } 1176 return d; 1643 return d; 1177 } 1644 } 1178 1645 1179 //....oooOO0OOooo........oooOO0OOooo........o 1646 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1180 1647 1181 G4double << 1648 G4double G4VEnergyLossProcess::CrossSectionPerVolume( 1182 G4VEnergyLossProcess::CrossSectionPerVolume(G << 1649 G4double kineticEnergy, const G4MaterialCutsCouple* couple) 1183 c << 1184 G << 1185 { 1650 { 1186 // Cross section per volume is calculated 1651 // Cross section per volume is calculated 1187 DefineMaterial(couple); 1652 DefineMaterial(couple); 1188 G4double cross = 0.0; 1653 G4double cross = 0.0; 1189 if (nullptr != theLambdaTable) { << 1654 if(theLambdaTable) { 1190 cross = GetLambdaForScaledEnergy(kineticE << 1655 cross = (*theDensityFactor)[currentCoupleIndex]* 1191 logKinet << 1656 ((*theLambdaTable)[basedCoupleIndex])->Value(kineticEnergy); 1192 } else { 1657 } else { 1193 SelectModel(kineticEnergy*massRatio); << 1658 SelectModel(kineticEnergy); 1194 cross = (!baseMat) ? biasFactor : biasFac << 1659 cross = currentModel->CrossSectionPerVolume(currentMaterial, 1195 cross *= (currentModel->CrossSectionPerVo << 1660 particle, kineticEnergy, 1196 << 1661 (*theCuts)[currentCoupleIndex]); 1197 } 1662 } 1198 return std::max(cross, 0.0); << 1663 if(cross < 0.0) { cross = 0.0; } >> 1664 return cross; 1199 } 1665 } 1200 1666 1201 //....oooOO0OOooo........oooOO0OOooo........o 1667 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1202 1668 1203 G4double G4VEnergyLossProcess::MeanFreePath(c 1669 G4double G4VEnergyLossProcess::MeanFreePath(const G4Track& track) 1204 { 1670 { 1205 DefineMaterial(track.GetMaterialCutsCouple( 1671 DefineMaterial(track.GetMaterialCutsCouple()); 1206 const G4double kinEnergy = track.GetKine << 1672 preStepLambda = GetLambdaForScaledEnergy(track.GetKineticEnergy()*massRatio); 1207 const G4double logKinEnergy = track.GetDyna << 1673 G4double x = DBL_MAX; 1208 const G4double cs = GetLambdaForScaledEnerg << 1674 if(0.0 < preStepLambda) { x = 1.0/preStepLambda; } 1209 << 1675 return x; 1210 return (0.0 < cs) ? 1.0/cs : DBL_MAX; << 1211 } 1676 } 1212 1677 1213 //....oooOO0OOooo........oooOO0OOooo........o 1678 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1214 1679 1215 G4double G4VEnergyLossProcess::ContinuousStep 1680 G4double G4VEnergyLossProcess::ContinuousStepLimit(const G4Track& track, 1216 << 1681 G4double x, G4double y, 1217 << 1682 G4double& z) 1218 { 1683 { 1219 return AlongStepGetPhysicalInteractionLengt << 1684 G4GPILSelection sel; >> 1685 return AlongStepGetPhysicalInteractionLength(track, x, y, z, &sel); 1220 } 1686 } 1221 1687 1222 //....oooOO0OOooo........oooOO0OOooo........o 1688 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1223 1689 1224 G4double G4VEnergyLossProcess::GetMeanFreePat 1690 G4double G4VEnergyLossProcess::GetMeanFreePath( 1225 const G4Track& t 1691 const G4Track& track, 1226 G4double, 1692 G4double, 1227 G4ForceCondition 1693 G4ForceCondition* condition) 1228 1694 1229 { 1695 { 1230 *condition = NotForced; 1696 *condition = NotForced; 1231 return MeanFreePath(track); 1697 return MeanFreePath(track); 1232 } 1698 } 1233 1699 1234 //....oooOO0OOooo........oooOO0OOooo........o 1700 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1235 1701 1236 G4double G4VEnergyLossProcess::GetContinuousS 1702 G4double G4VEnergyLossProcess::GetContinuousStepLimit( 1237 const G4Track&, << 1703 const G4Track&, 1238 G4double, G4double, G4double& 1704 G4double, G4double, G4double&) 1239 { 1705 { 1240 return DBL_MAX; 1706 return DBL_MAX; 1241 } 1707 } 1242 1708 1243 //....oooOO0OOooo........oooOO0OOooo........o 1709 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1244 1710 1245 G4PhysicsVector* 1711 G4PhysicsVector* 1246 G4VEnergyLossProcess::LambdaPhysicsVector(con << 1712 G4VEnergyLossProcess::LambdaPhysicsVector(const G4MaterialCutsCouple* /*couple*/, 1247 G4d << 1713 G4double /*cut*/) 1248 { 1714 { 1249 DefineMaterial(couple); << 1715 G4PhysicsVector* v = new G4PhysicsLogVector(minKinEnergy, maxKinEnergy, nBins); 1250 G4PhysicsVector* v = (*theLambdaTable)[base << 1716 v->SetSpline((G4LossTableManager::Instance())->SplineFlag()); 1251 return new G4PhysicsVector(*v); << 1717 return v; 1252 } 1718 } 1253 1719 1254 //....oooOO0OOooo........oooOO0OOooo........o 1720 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1255 << 1721 1256 void << 1722 void G4VEnergyLossProcess::AddCollaborativeProcess( 1257 G4VEnergyLossProcess::SetDEDXTable(G4PhysicsT << 1723 G4VEnergyLossProcess* p) 1258 { 1724 { 1259 if(1 < verboseLevel) { << 1725 G4bool add = true; 1260 G4cout << "### Set DEDX table " << p << " << 1726 if(p->GetProcessName() != "eBrem") { add = false; } 1261 << " " << theDEDXunRestrictedTable << << 1727 if(add && nProcesses > 0) { 1262 << " for " << particle->GetParticl << 1728 for(G4int i=0; i<nProcesses; ++i) { 1263 << " and process " << GetProcessNa << 1729 if(p == scProcesses[i]) { 1264 << " type=" << tType << " isIonisation:" << 1730 add = false; >> 1731 break; >> 1732 } >> 1733 } 1265 } 1734 } 1266 if(fTotal == tType) { << 1735 if(add) { >> 1736 scProcesses.push_back(p); >> 1737 ++nProcesses; >> 1738 if (1 < verboseLevel) { >> 1739 G4cout << "### The process " << p->GetProcessName() >> 1740 << " is added to the list of collaborative processes of " >> 1741 << GetProcessName() << G4endl; >> 1742 } >> 1743 } >> 1744 } >> 1745 >> 1746 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 1747 >> 1748 void G4VEnergyLossProcess::SetDEDXTable(G4PhysicsTable* p, G4EmTableType tType) >> 1749 { >> 1750 if(fTotal == tType && theDEDXunRestrictedTable != p && !baseParticle) { >> 1751 if(theDEDXunRestrictedTable) { >> 1752 theDEDXunRestrictedTable->clearAndDestroy(); >> 1753 delete theDEDXunRestrictedTable; >> 1754 } 1267 theDEDXunRestrictedTable = p; 1755 theDEDXunRestrictedTable = p; 1268 } else if(fRestricted == tType) { << 1756 if(p) { >> 1757 size_t n = p->length(); >> 1758 G4PhysicsVector* pv = (*p)[0]; >> 1759 G4double emax = maxKinEnergyCSDA; >> 1760 >> 1761 for (size_t i=0; i<n; ++i) { >> 1762 G4double dedx = 0.0; >> 1763 pv = (*p)[i]; >> 1764 if(pv) { dedx = pv->Value(emax); } >> 1765 else { >> 1766 pv = (*p)[(*theDensityIdx)[i]]; >> 1767 if(pv) { dedx = pv->Value(emax)*(*theDensityFactor)[i]; } >> 1768 } >> 1769 theDEDXAtMaxEnergy[i] = dedx; >> 1770 //G4cout << "i= " << i << " emax(MeV)= " << emax/MeV<< " dedx= " >> 1771 //<< dedx << G4endl; >> 1772 } >> 1773 } >> 1774 >> 1775 } else if(fRestricted == tType && theDEDXTable != p) { >> 1776 //G4cout << "G4VEnergyLossProcess::SetDEDXTable " << particle->GetParticleName() >> 1777 // << " old table " << theDEDXTable << " new table " << p >> 1778 // << " ion " << theIonisationTable << " bp " << baseParticle << G4endl; >> 1779 if(theDEDXTable && !baseParticle) { >> 1780 if(theDEDXTable == theIonisationTable) { theIonisationTable = 0; } >> 1781 theDEDXTable->clearAndDestroy(); >> 1782 delete theDEDXTable; >> 1783 } 1269 theDEDXTable = p; 1784 theDEDXTable = p; 1270 if(isMaster && nullptr == baseParticle) { << 1785 } else if(fSubRestricted == tType && theDEDXSubTable != p) { 1271 theData->UpdateTable(theDEDXTable, 0); << 1786 if(theDEDXSubTable && !baseParticle) { >> 1787 if(theDEDXSubTable == theIonisationSubTable) { theIonisationSubTable = 0; } >> 1788 theDEDXSubTable->clearAndDestroy(); >> 1789 delete theDEDXSubTable; >> 1790 } >> 1791 theDEDXSubTable = p; >> 1792 } else if(fIsIonisation == tType && theIonisationTable != p) { >> 1793 if(theIonisationTable && theIonisationTable != theDEDXTable && !baseParticle) { >> 1794 theIonisationTable->clearAndDestroy(); >> 1795 delete theIonisationTable; 1272 } 1796 } 1273 } else if(fIsIonisation == tType) { << 1274 theIonisationTable = p; 1797 theIonisationTable = p; 1275 if(isMaster && nullptr == baseParticle) { << 1798 } else if(fIsSubIonisation == tType && theIonisationSubTable != p) { 1276 theData->UpdateTable(theIonisationTable << 1799 if(theIonisationSubTable && theIonisationSubTable != theDEDXSubTable && !baseParticle) { >> 1800 theIonisationSubTable->clearAndDestroy(); >> 1801 delete theIonisationSubTable; 1277 } 1802 } >> 1803 theIonisationSubTable = p; 1278 } 1804 } 1279 } 1805 } 1280 1806 1281 //....oooOO0OOooo........oooOO0OOooo........o 1807 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1282 1808 1283 void G4VEnergyLossProcess::SetCSDARangeTable( 1809 void G4VEnergyLossProcess::SetCSDARangeTable(G4PhysicsTable* p) 1284 { 1810 { 1285 theCSDARangeTable = p; << 1811 if(theCSDARangeTable != p) { theCSDARangeTable = p; } >> 1812 >> 1813 if(p) { >> 1814 size_t n = p->length(); >> 1815 G4PhysicsVector* pv; >> 1816 G4double emax = maxKinEnergyCSDA; >> 1817 >> 1818 for (size_t i=0; i<n; ++i) { >> 1819 pv = (*p)[i]; >> 1820 G4double rmax = 0.0; >> 1821 if(pv) { rmax = pv->Value(emax); } >> 1822 else { >> 1823 pv = (*p)[(*theDensityIdx)[i]]; >> 1824 if(pv) { rmax = pv->Value(emax)/(*theDensityFactor)[i]; } >> 1825 } >> 1826 theRangeAtMaxEnergy[i] = rmax; >> 1827 //G4cout << "i= " << i << " Emax(MeV)= " << emax/MeV << " Rmax= " >> 1828 //<< rmax<< G4endl; >> 1829 } >> 1830 } 1286 } 1831 } 1287 1832 1288 //....oooOO0OOooo........oooOO0OOooo........o 1833 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1289 1834 1290 void G4VEnergyLossProcess::SetRangeTableForLo 1835 void G4VEnergyLossProcess::SetRangeTableForLoss(G4PhysicsTable* p) 1291 { 1836 { 1292 theRangeTableForLoss = p; << 1837 if(theRangeTableForLoss != p) { >> 1838 theRangeTableForLoss = p; >> 1839 if(1 < verboseLevel) { >> 1840 G4cout << "### Set Range table " << p >> 1841 << " for " << particle->GetParticleName() >> 1842 << " and process " << GetProcessName() << G4endl; >> 1843 } >> 1844 } >> 1845 } >> 1846 >> 1847 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 1848 >> 1849 void G4VEnergyLossProcess::SetSecondaryRangeTable(G4PhysicsTable* p) >> 1850 { >> 1851 if(theSecondaryRangeTable != p) { >> 1852 theSecondaryRangeTable = p; >> 1853 if(1 < verboseLevel) { >> 1854 G4cout << "### Set SecondaryRange table " << p >> 1855 << " for " << particle->GetParticleName() >> 1856 << " and process " << GetProcessName() << G4endl; >> 1857 } >> 1858 } 1293 } 1859 } 1294 1860 1295 //....oooOO0OOooo........oooOO0OOooo........o 1861 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1296 1862 1297 void G4VEnergyLossProcess::SetInverseRangeTab 1863 void G4VEnergyLossProcess::SetInverseRangeTable(G4PhysicsTable* p) 1298 { 1864 { 1299 theInverseRangeTable = p; << 1865 if(theInverseRangeTable != p) { >> 1866 theInverseRangeTable = p; >> 1867 if(1 < verboseLevel) { >> 1868 G4cout << "### Set InverseRange table " << p >> 1869 << " for " << particle->GetParticleName() >> 1870 << " and process " << GetProcessName() << G4endl; >> 1871 } >> 1872 } 1300 } 1873 } 1301 1874 1302 //....oooOO0OOooo........oooOO0OOooo........o 1875 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1303 1876 1304 void G4VEnergyLossProcess::SetLambdaTable(G4P 1877 void G4VEnergyLossProcess::SetLambdaTable(G4PhysicsTable* p) 1305 { 1878 { 1306 if(1 < verboseLevel) { 1879 if(1 < verboseLevel) { 1307 G4cout << "### Set Lambda table " << p << << 1880 G4cout << "### Set Lambda table " << p 1308 << " for " << particle->GetParticl << 1881 << " for " << particle->GetParticleName() 1309 << " and process " << GetProcessNa 1882 << " and process " << GetProcessName() << G4endl; 1310 } 1883 } 1311 theLambdaTable = p; << 1884 if(theLambdaTable != p) { theLambdaTable = p; } 1312 tablesAreBuilt = true; 1885 tablesAreBuilt = true; 1313 1886 1314 if(isMaster && nullptr != p) { << 1887 if(theLambdaTable) { 1315 delete theEnergyOfCrossSectionMax; << 1888 size_t n = theLambdaTable->length(); 1316 theEnergyOfCrossSectionMax = nullptr; << 1889 G4PhysicsVector* pv = (*theLambdaTable)[0]; 1317 if(fEmTwoPeaks == fXSType) { << 1890 G4double e, s, smax, emax; 1318 if(nullptr != fXSpeaks) { << 1891 1319 for(auto & ptr : *fXSpeaks) { delete ptr; } << 1892 size_t i; 1320 delete fXSpeaks; << 1893 >> 1894 // first loop on existing vectors >> 1895 for (i=0; i<n; ++i) { >> 1896 pv = (*theLambdaTable)[i]; >> 1897 if(pv) { >> 1898 size_t nb = pv->GetVectorLength(); >> 1899 emax = DBL_MAX; >> 1900 smax = 0.0; >> 1901 if(nb > 0) { >> 1902 for (size_t j=0; j<nb; ++j) { >> 1903 e = pv->Energy(j); >> 1904 s = (*pv)(j); >> 1905 if(s > smax) { >> 1906 smax = s; >> 1907 emax = e; >> 1908 } >> 1909 } >> 1910 } >> 1911 theEnergyOfCrossSectionMax[i] = emax; >> 1912 theCrossSectionMax[i] = smax; >> 1913 if(1 < verboseLevel) { >> 1914 G4cout << "For " << particle->GetParticleName() >> 1915 << " Max CS at i= " << i << " emax(MeV)= " << emax/MeV >> 1916 << " lambda= " << smax << G4endl; >> 1917 } 1321 } 1918 } 1322 G4LossTableBuilder* bld = lManager->Get << 1323 fXSpeaks = G4EmUtility::FillPeaksStruct << 1324 if(nullptr == fXSpeaks) { fXSType = fEm << 1325 } 1919 } 1326 if(fXSType == fEmOnePeak) { << 1920 // second loop using base materials 1327 theEnergyOfCrossSectionMax = G4EmUtilit << 1921 for (size_t i=0; i<n; ++i) { 1328 if(nullptr == theEnergyOfCrossSectionMa << 1922 pv = (*theLambdaTable)[i]; >> 1923 if(!pv){ >> 1924 G4int j = (*theDensityIdx)[i]; >> 1925 theEnergyOfCrossSectionMax[i] = theEnergyOfCrossSectionMax[j]; >> 1926 theCrossSectionMax[i] = (*theDensityFactor)[i]*theCrossSectionMax[j]; >> 1927 } 1329 } 1928 } 1330 } 1929 } 1331 } 1930 } 1332 1931 1333 //....oooOO0OOooo........oooOO0OOooo........o 1932 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1334 1933 1335 void G4VEnergyLossProcess::SetEnergyOfCrossSe << 1934 void G4VEnergyLossProcess::SetSubLambdaTable(G4PhysicsTable* p) 1336 { << 1337 theEnergyOfCrossSectionMax = p; << 1338 } << 1339 << 1340 //....oooOO0OOooo........oooOO0OOooo........o << 1341 << 1342 void G4VEnergyLossProcess::SetTwoPeaksXS(std: << 1343 { 1935 { 1344 fXSpeaks = ptr; << 1936 if(theSubLambdaTable != p) { >> 1937 theSubLambdaTable = p; >> 1938 if(1 < verboseLevel) { >> 1939 G4cout << "### Set SebLambda table " << p >> 1940 << " for " << particle->GetParticleName() >> 1941 << " and process " << GetProcessName() << G4endl; >> 1942 } >> 1943 } 1345 } 1944 } 1346 1945 1347 //....oooOO0OOooo........oooOO0OOooo........o 1946 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1348 1947 1349 const G4Element* G4VEnergyLossProcess::GetCur 1948 const G4Element* G4VEnergyLossProcess::GetCurrentElement() const 1350 { 1949 { 1351 return (nullptr != currentModel) << 1950 const G4Element* elm = 0; 1352 ? currentModel->GetCurrentElement(current << 1951 if(currentModel) { elm = currentModel->GetCurrentElement(); } >> 1952 return elm; 1353 } 1953 } 1354 1954 1355 //....oooOO0OOooo........oooOO0OOooo........o 1955 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1356 1956 1357 void G4VEnergyLossProcess::SetCrossSectionBia 1957 void G4VEnergyLossProcess::SetCrossSectionBiasingFactor(G4double f, 1358 << 1958 G4bool flag) 1359 { 1959 { 1360 if(f > 0.0) { 1960 if(f > 0.0) { 1361 biasFactor = f; 1961 biasFactor = f; 1362 weightFlag = flag; 1962 weightFlag = flag; 1363 if(1 < verboseLevel) { 1963 if(1 < verboseLevel) { 1364 G4cout << "### SetCrossSectionBiasingFa 1964 G4cout << "### SetCrossSectionBiasingFactor: for " 1365 << " process " << GetProcessName << 1965 << " process " << GetProcessName() 1366 << " biasFactor= " << f << " wei << 1966 << " biasFactor= " << f << " weightFlag= " << flag 1367 << G4endl; << 1967 << G4endl; 1368 } 1968 } 1369 } 1969 } 1370 } 1970 } 1371 1971 1372 //....oooOO0OOooo........oooOO0OOooo........o 1972 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1373 1973 1374 void G4VEnergyLossProcess::ActivateForcedInte << 1974 void 1375 << 1975 G4VEnergyLossProcess::ActivateForcedInteraction(G4double length, 1376 << 1976 const G4String& region, >> 1977 G4bool flag) 1377 { 1978 { 1378 if(nullptr == biasManager) { biasManager = << 1979 if(!biasManager) { biasManager = new G4EmBiasingManager(); } 1379 if(1 < verboseLevel) { 1980 if(1 < verboseLevel) { 1380 G4cout << "### ActivateForcedInteraction: 1981 G4cout << "### ActivateForcedInteraction: for " 1381 << " process " << GetProcessName() << 1982 << " process " << GetProcessName() 1382 << " length(mm)= " << length/mm << 1983 << " length(mm)= " << length/mm 1383 << " in G4Region <" << region << 1984 << " in G4Region <" << region 1384 << "> weightFlag= " << flag << 1985 << "> weightFlag= " << flag 1385 << G4endl; << 1986 << G4endl; 1386 } 1987 } 1387 weightFlag = flag; 1988 weightFlag = flag; 1388 biasManager->ActivateForcedInteraction(leng 1989 biasManager->ActivateForcedInteraction(length, region); 1389 } 1990 } 1390 1991 1391 //....oooOO0OOooo........oooOO0OOooo........o 1992 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1392 1993 1393 void 1994 void 1394 G4VEnergyLossProcess::ActivateSecondaryBiasin 1995 G4VEnergyLossProcess::ActivateSecondaryBiasing(const G4String& region, 1395 << 1996 G4double factor, 1396 << 1997 G4double energyLimit) 1397 { 1998 { 1398 if (0.0 <= factor) { << 1999 if (0.0 < factor) { 1399 // Range cut can be applied only for e- << 2000 if(!biasManager) { biasManager = new G4EmBiasingManager(); } 1400 if(0.0 == factor && secondaryParticle != << 1401 { return; } << 1402 << 1403 if(nullptr == biasManager) { biasManager << 1404 biasManager->ActivateSecondaryBiasing(reg 2001 biasManager->ActivateSecondaryBiasing(region, factor, energyLimit); 1405 if(1 < verboseLevel) { 2002 if(1 < verboseLevel) { 1406 G4cout << "### ActivateSecondaryBiasing 2003 G4cout << "### ActivateSecondaryBiasing: for " 1407 << " process " << GetProcessName << 2004 << " process " << GetProcessName() 1408 << " factor= " << factor << 2005 << " factor= " << factor 1409 << " in G4Region <" << region << 2006 << " in G4Region <" << region 1410 << "> energyLimit(MeV)= " << ene << 2007 << "> energyLimit(MeV)= " << energyLimit/MeV 1411 << G4endl; << 2008 << G4endl; 1412 } 2009 } 1413 } 2010 } 1414 } 2011 } 1415 2012 1416 //....oooOO0OOooo........oooOO0OOooo........o 2013 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 1417 2014 1418 void G4VEnergyLossProcess::SetIonisation(G4bo << 1419 { << 1420 isIonisation = val; << 1421 aGPILSelection = (val) ? CandidateForSelect << 1422 } << 1423 << 1424 //....oooOO0OOooo........oooOO0OOooo........o << 1425 << 1426 void G4VEnergyLossProcess::SetLinearLossLimi << 1427 { << 1428 if(0.0 < val && val < 1.0) { << 1429 linLossLimit = val; << 1430 actLinLossLimit = true; << 1431 } else { PrintWarning("SetLinearLossLimit", << 1432 } << 1433 << 1434 //....oooOO0OOooo........oooOO0OOooo........o << 1435 << 1436 void G4VEnergyLossProcess::SetStepFunction(G4 << 1437 { << 1438 if(0.0 < v1 && 0.0 < v2) { << 1439 dRoverRange = std::min(1.0, v1); << 1440 finalRange = std::min(v2, 1.e+50); << 1441 } else { << 1442 PrintWarning("SetStepFunctionV1", v1); << 1443 PrintWarning("SetStepFunctionV2", v2); << 1444 } << 1445 } << 1446 << 1447 //....oooOO0OOooo........oooOO0OOooo........o << 1448 << 1449 void G4VEnergyLossProcess::SetLowestEnergyLim << 1450 { << 1451 if(1.e-18 < val && val < 1.e+50) { lowestKi << 1452 else { PrintWarning("SetLowestEnergyLimit", << 1453 } << 1454 << 1455 //....oooOO0OOooo........oooOO0OOooo........o << 1456 << 1457 void G4VEnergyLossProcess::SetDEDXBinning(G4i << 1458 { << 1459 if(2 < n && n < 1000000000) { << 1460 nBins = n; << 1461 actBinning = true; << 1462 } else { << 1463 G4double e = (G4double)n; << 1464 PrintWarning("SetDEDXBinning", e); << 1465 } << 1466 } << 1467 << 1468 //....oooOO0OOooo........oooOO0OOooo........o << 1469 << 1470 void G4VEnergyLossProcess::SetMinKinEnergy(G4 << 1471 { << 1472 if(1.e-18 < e && e < maxKinEnergy) { << 1473 minKinEnergy = e; << 1474 actMinKinEnergy = true; << 1475 } else { PrintWarning("SetMinKinEnergy", e) << 1476 } << 1477 << 1478 //....oooOO0OOooo........oooOO0OOooo........o << 1479 << 1480 void G4VEnergyLossProcess::SetMaxKinEnergy(G4 << 1481 { << 1482 if(minKinEnergy < e && e < 1.e+50) { << 1483 maxKinEnergy = e; << 1484 actMaxKinEnergy = true; << 1485 if(e < maxKinEnergyCSDA) { maxKinEnergyCS << 1486 } else { PrintWarning("SetMaxKinEnergy", e) << 1487 } << 1488 << 1489 //....oooOO0OOooo........oooOO0OOooo........o << 1490 << 1491 void G4VEnergyLossProcess::PrintWarning(const << 1492 { << 1493 G4String ss = "G4VEnergyLossProcess::" + ti << 1494 G4ExceptionDescription ed; << 1495 ed << "Parameter is out of range: " << val << 1496 << " it will have no effect!\n" << " Pr << 1497 << GetProcessName() << " nbins= " << nB << 1498 << " Emin(keV)= " << minKinEnergy/keV << 1499 << " Emax(GeV)= " << maxKinEnergy/GeV; << 1500 G4Exception(ss, "em0044", JustWarning, ed); << 1501 } << 1502 << 1503 //....oooOO0OOooo........oooOO0OOooo........o << 1504 << 1505 void G4VEnergyLossProcess::ProcessDescription << 1506 { << 1507 if(nullptr != particle) { StreamInfo(out, * << 1508 } << 1509 << 1510 //....oooOO0OOooo........oooOO0OOooo........o << 1511 2015