Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/electromagnetic/utils/src/G4VEnergyLossProcess.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/electromagnetic/utils/src/G4VEnergyLossProcess.cc (Version 11.3.0) and /processes/electromagnetic/utils/src/G4VEnergyLossProcess.cc (Version 9.2.p2)


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