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.6)


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