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