Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/electromagnetic/standard/src/G4PAIModel.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/standard/src/G4PAIModel.cc (Version 11.3.0) and /processes/electromagnetic/standard/src/G4PAIModel.cc (Version 10.1)


  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: G4PAIModel.cc 83400 2014-08-21 14:48:50Z gcosmo $
 26 //                                                 27 //
 27 // -------------------------------------------     28 // -------------------------------------------------------------------
 28 //                                                 29 //
 29 // GEANT4 Class                                    30 // GEANT4 Class
 30 // File name:     G4PAIModel.cc                    31 // File name:     G4PAIModel.cc
 31 //                                                 32 //
 32 // Author: Vladimir.Grichine@cern.ch on base o     33 // Author: Vladimir.Grichine@cern.ch on base of V.Ivanchenko model interface
 33 //                                                 34 //
 34 // Creation date: 05.10.2003                       35 // Creation date: 05.10.2003
 35 //                                                 36 //
 36 // Modifications:                                  37 // Modifications:
 37 //                                                 38 //
 38 // 17.08.04 V.Grichine, bug fixed for Tkin<=0      39 // 17.08.04 V.Grichine, bug fixed for Tkin<=0 in SampleSecondary
 39 // 16.08.04 V.Grichine, bug fixed in massRatio     40 // 16.08.04 V.Grichine, bug fixed in massRatio for DEDX, CrossSection, 
 40 //          SampleSecondary                        41 //          SampleSecondary
 41 // 08.04.05 Major optimisation of internal int     42 // 08.04.05 Major optimisation of internal interfaces (V.Ivantchenko)
 42 // 26.07.09 Fixed logic to work with several m     43 // 26.07.09 Fixed logic to work with several materials (V.Ivantchenko)
 43 // 21.11.10 V. Grichine verbose flag for proto     44 // 21.11.10 V. Grichine verbose flag for protons and G4PAYySection to 
 44 //          check sandia table                     45 //          check sandia table 
 45 // 12.06.13 V. Grichine Bug fixed in SampleSec     46 // 12.06.13 V. Grichine Bug fixed in SampleSecondaries for scaled Tkin 
 46 //          (fMass -> proton_mass_c2)              47 //          (fMass -> proton_mass_c2)
 47 // 19.08.13 V.Ivanchenko extract data handling     48 // 19.08.13 V.Ivanchenko extract data handling to G4PAIModelData class 
 48 //          added sharing of internal data bet     49 //          added sharing of internal data between threads (MT migration)
 49 //                                                 50 //
 50                                                    51 
 51 #include "G4PAIModel.hh"                           52 #include "G4PAIModel.hh"
 52                                                    53 
 53 #include "G4SystemOfUnits.hh"                      54 #include "G4SystemOfUnits.hh"
 54 #include "G4PhysicalConstants.hh"                  55 #include "G4PhysicalConstants.hh"
 55 #include "G4Region.hh"                             56 #include "G4Region.hh"
                                                   >>  57 #include "G4PhysicsLogVector.hh"
                                                   >>  58 #include "G4PhysicsFreeVector.hh"
                                                   >>  59 #include "G4PhysicsTable.hh"
                                                   >>  60 #include "G4ProductionCutsTable.hh"
 56 #include "G4MaterialCutsCouple.hh"                 61 #include "G4MaterialCutsCouple.hh"
 57 #include "G4MaterialTable.hh"                      62 #include "G4MaterialTable.hh"
 58 #include "G4RegionStore.hh"                    <<  63 #include "G4SandiaTable.hh"
                                                   >>  64 #include "G4OrderedTable.hh"
 59                                                    65 
 60 #include "Randomize.hh"                            66 #include "Randomize.hh"
 61 #include "G4Electron.hh"                           67 #include "G4Electron.hh"
 62 #include "G4Positron.hh"                           68 #include "G4Positron.hh"
 63 #include "G4Poisson.hh"                            69 #include "G4Poisson.hh"
 64 #include "G4Step.hh"                               70 #include "G4Step.hh"
 65 #include "G4Material.hh"                           71 #include "G4Material.hh"
 66 #include "G4DynamicParticle.hh"                    72 #include "G4DynamicParticle.hh"
 67 #include "G4ParticleDefinition.hh"                 73 #include "G4ParticleDefinition.hh"
 68 #include "G4ParticleChangeForLoss.hh"              74 #include "G4ParticleChangeForLoss.hh"
 69 #include "G4PAIModelData.hh"                       75 #include "G4PAIModelData.hh"
 70 #include "G4DeltaAngle.hh"                         76 #include "G4DeltaAngle.hh"
 71                                                    77 
 72 //////////////////////////////////////////////     78 ////////////////////////////////////////////////////////////////////////
 73                                                    79 
 74 using namespace std;                               80 using namespace std;
 75                                                    81 
 76 G4PAIModel::G4PAIModel(const G4ParticleDefinit     82 G4PAIModel::G4PAIModel(const G4ParticleDefinition* p, const G4String& nam)
 77   : G4VEmModel(nam),G4VEmFluctuationModel(nam)     83   : G4VEmModel(nam),G4VEmFluctuationModel(nam),
 78     fVerbose(0),                                   84     fVerbose(0),
 79     fModelData(nullptr),                       <<  85     fModelData(0),
 80     fParticle(nullptr)                         <<  86     fParticle(0)
 81 {                                                  87 {  
 82   fElectron = G4Electron::Electron();              88   fElectron = G4Electron::Electron();
 83   fPositron = G4Positron::Positron();              89   fPositron = G4Positron::Positron();
 84                                                    90 
 85   fParticleChange = nullptr;                   <<  91   fParticleChange = 0;
 86                                                    92 
 87   if(p) { SetParticle(p); }                        93   if(p) { SetParticle(p); }
 88   else  { SetParticle(fElectron); }                94   else  { SetParticle(fElectron); }
 89                                                    95 
 90   // default generator                             96   // default generator
 91   SetAngularDistribution(new G4DeltaAngle());      97   SetAngularDistribution(new G4DeltaAngle());
 92   fLowestTcut = 12.5*CLHEP::eV;                <<  98 
                                                   >>  99   isInitialised = false;
 93 }                                                 100 }
 94                                                   101 
 95 //////////////////////////////////////////////    102 ////////////////////////////////////////////////////////////////////////////
 96                                                   103 
 97 G4PAIModel::~G4PAIModel()                         104 G4PAIModel::~G4PAIModel()
 98 {                                                 105 {
 99   if(IsMaster()) { delete fModelData; }           106   if(IsMaster()) { delete fModelData; }
100 }                                                 107 }
101                                                   108 
102 //////////////////////////////////////////////    109 ////////////////////////////////////////////////////////////////////////////
103                                                   110 
104 void G4PAIModel::Initialise(const G4ParticleDe    111 void G4PAIModel::Initialise(const G4ParticleDefinition* p,
105           const G4DataVector& cuts)               112           const G4DataVector& cuts)
106 {                                                 113 {
107   if(fVerbose > 1) {                           << 114   if(fVerbose > 0) {
108     G4cout<<"G4PAIModel::Initialise for "<<p->    115     G4cout<<"G4PAIModel::Initialise for "<<p->GetParticleName()<<G4endl;
109   }                                               116   }
                                                   >> 117 
                                                   >> 118   if(isInitialised) { return; }
                                                   >> 119   isInitialised = true;
                                                   >> 120 
110   SetParticle(p);                                 121   SetParticle(p);
111   fParticleChange = GetParticleChangeForLoss()    122   fParticleChange = GetParticleChangeForLoss();
112                                                   123 
113   if(IsMaster()) {                                124   if(IsMaster()) { 
114                                                   125 
115     delete fModelData;                         << 126     InitialiseElementSelectors(p, cuts);
116     fMaterialCutsCoupleVector.clear();         << 127 
117     if(fVerbose > 1) {                         << 128     if(!fModelData) {
118       G4cout << "G4PAIModel instantiates data  << 
119        << G4endl;                              << 
120     }                                          << 
121     G4double tmin = LowEnergyLimit()*fRatio;   << 
122     G4double tmax = HighEnergyLimit()*fRatio;  << 
123     fModelData = new G4PAIModelData(tmin, tmax << 
124                                                << 
125     // Prepare initialization                  << 
126     const G4MaterialTable* theMaterialTable =  << 
127     std::size_t numOfMat   = G4Material::GetNu << 
128     std::size_t numRegions = fPAIRegionVector. << 
129                                                   129 
130     // protect for unit tests                  << 130       G4double tmin = LowEnergyLimit()*fRatio;
131     if(0 == numRegions) {                      << 131       G4double tmax = HighEnergyLimit()*fRatio;
132       G4Exception("G4PAIModel::Initialise()"," << 132       fModelData = new G4PAIModelData(tmin, tmax, fVerbose);
133                   "no G4Regions are registered << 
134       fPAIRegionVector.push_back(G4RegionStore << 
135          ->GetRegion("DefaultRegionForTheWorld << 
136       numRegions = 1;                          << 
137     }                                             133     }
                                                   >> 134     // Prepare initialization
                                                   >> 135     const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
                                                   >> 136     size_t numOfMat   = G4Material::GetNumberOfMaterials();
                                                   >> 137     size_t numRegions = fPAIRegionVector.size();
138                                                   138 
139     if(fVerbose > 1) {                         << 139     if(fVerbose > 0) {
140       G4cout << "G4PAIModel is defined for " <    140       G4cout << "G4PAIModel is defined for " << numRegions << " regions "   
141        << "; number of materials " << numOfMat << 141        << G4endl;
                                                   >> 142       G4cout << "           total number of materials " << numOfMat << G4endl;
142     }                                             143     } 
143     for(std::size_t iReg = 0; iReg<numRegions; << 144     for(size_t iReg = 0; iReg<numRegions; ++iReg) {
144       const G4Region* curReg = fPAIRegionVecto    145       const G4Region* curReg = fPAIRegionVector[iReg];
145       G4Region* reg = const_cast<G4Region*>(cu    146       G4Region* reg = const_cast<G4Region*>(curReg);
146                                                   147 
147       for(std::size_t jMat = 0; jMat<numOfMat; << 148       for(size_t jMat = 0; jMat<numOfMat; ++jMat) {
148   G4Material* mat = (*theMaterialTable)[jMat];    149   G4Material* mat = (*theMaterialTable)[jMat];
149   const G4MaterialCutsCouple* cutCouple = reg-    150   const G4MaterialCutsCouple* cutCouple = reg->FindCouple(mat);
150   std::size_t n = fMaterialCutsCoupleVector.si << 151   size_t n = fMaterialCutsCoupleVector.size();
151   if(nullptr != cutCouple) {                   << 152   /*
152     if(fVerbose > 1) {                         << 153   G4cout << "Region: " << reg->GetName() << "  " << reg
                                                   >> 154          << " Couple " << cutCouple 
                                                   >> 155          << " PAI defined for " << n << " couples"
                                                   >> 156          << " jMat= " << jMat << "  " << mat->GetName()
                                                   >> 157          << G4endl;
                                                   >> 158   */
                                                   >> 159   if(cutCouple) {
                                                   >> 160     if(fVerbose > 0) {
153       G4cout << "Region <" << curReg->GetName(    161       G4cout << "Region <" << curReg->GetName() << ">  mat <" 
154        << mat->GetName() << ">  CoupleIndex= "    162        << mat->GetName() << ">  CoupleIndex= " 
155        << cutCouple->GetIndex()                   163        << cutCouple->GetIndex()
156        << "  " << p->GetParticleName()            164        << "  " << p->GetParticleName()
157        << " cutsize= " << cuts.size() << G4end    165        << " cutsize= " << cuts.size() << G4endl;
158     }                                             166     }
159     // check if this couple is not already ini    167     // check if this couple is not already initialized
160     G4bool isnew = true;                          168     G4bool isnew = true;
161     if(0 < n) {                                   169     if(0 < n) {
162       for(std::size_t i=0; i<n; ++i) {         << 170       for(size_t i=0; i<n; ++i) {
163         G4cout << i << G4endl;                 << 
164         if(cutCouple == fMaterialCutsCoupleVec    171         if(cutCouple == fMaterialCutsCoupleVector[i]) {
165     isnew = false;                                172     isnew = false;
166     break;                                        173     break;
167         }                                         174         }
168       }                                           175       }
169     }                                             176     }
170     // initialise data banks                      177     // initialise data banks
171     // G4cout << "   isNew: " << isnew << "  " << 178     //G4cout << "   isNew: " << isnew << "  " << cutCouple << G4endl;
172     if(isnew) {                                   179     if(isnew) { 
173       fMaterialCutsCoupleVector.push_back(cutC    180       fMaterialCutsCoupleVector.push_back(cutCouple); 
174       fModelData->Initialise(cutCouple, this); << 181       G4double deltaCutInKinEnergy = cuts[cutCouple->GetIndex()];
                                                   >> 182       fModelData->Initialise(cutCouple, deltaCutInKinEnergy, this);
175     }                                             183     }
176   }                                               184   }
177       }                                           185       }
178     }                                             186     }
179     InitialiseElementSelectors(p, cuts);       << 
180   }                                               187   }
181 }                                                 188 }
182                                                   189 
183 //////////////////////////////////////////////    190 /////////////////////////////////////////////////////////////////////////
184                                                   191 
185 void G4PAIModel::InitialiseLocal(const G4Parti << 192 void G4PAIModel::InitialiseLocal(const G4ParticleDefinition*, 
186          G4VEmModel* masterModel)                 193          G4VEmModel* masterModel)
187 {                                                 194 {
188   fModelData = static_cast<G4PAIModel*>(master    195   fModelData = static_cast<G4PAIModel*>(masterModel)->GetPAIModelData();
189   fMaterialCutsCoupleVector =                  << 
190     static_cast<G4PAIModel*>(masterModel)->Get << 
191   SetElementSelectors(masterModel->GetElementS    196   SetElementSelectors(masterModel->GetElementSelectors());
192 }                                                 197 }
193                                                   198 
194 //////////////////////////////////////////////    199 //////////////////////////////////////////////////////////////////////////////
195                                                   200 
196 G4double G4PAIModel::MinEnergyCut(const G4Part << 
197           const G4MaterialCutsCouple*)         << 
198 {                                              << 
199   return fLowestTcut;                          << 
200 }                                              << 
201                                                << 
202 ////////////////////////////////////////////// << 
203                                                << 
204 G4double G4PAIModel::ComputeDEDXPerVolume(cons    201 G4double G4PAIModel::ComputeDEDXPerVolume(const G4Material*,
205             const G4ParticleDefinition* p,        202             const G4ParticleDefinition* p,
206             G4double kineticEnergy,               203             G4double kineticEnergy,
207             G4double cutEnergy)                   204             G4double cutEnergy)
208 {                                              << 205 {
                                                   >> 206   /*
                                                   >> 207   G4cout << "===1=== " << CurrentCouple() 
                                                   >> 208    << "  idx= " << CurrentCouple()->GetIndex()
                                                   >> 209    << "   " <<  fMaterialCutsCoupleVector[0]
                                                   >> 210    << G4endl;
                                                   >> 211   */
209   G4int coupleIndex = FindCoupleIndex(CurrentC    212   G4int coupleIndex = FindCoupleIndex(CurrentCouple());
                                                   >> 213   //G4cout << "===2=== " << coupleIndex << G4endl;
210   if(0 > coupleIndex) { return 0.0; }             214   if(0 > coupleIndex) { return 0.0; }
211                                                   215 
212   G4double cut = std::min(MaxSecondaryEnergy(p    216   G4double cut = std::min(MaxSecondaryEnergy(p, kineticEnergy), cutEnergy);
                                                   >> 217 
213   G4double scaledTkin = kineticEnergy*fRatio;     218   G4double scaledTkin = kineticEnergy*fRatio;
214   G4double dedx = fChargeSquare*fModelData->DE << 219  
215   return dedx;                                 << 220   return fChargeSquare*fModelData->DEDXPerVolume(coupleIndex, scaledTkin, cut);
216 }                                                 221 }
217                                                   222 
218 //////////////////////////////////////////////    223 /////////////////////////////////////////////////////////////////////////
219                                                   224 
220 G4double G4PAIModel::CrossSectionPerVolume( co    225 G4double G4PAIModel::CrossSectionPerVolume( const G4Material*,
221               const G4ParticleDefinition* p,      226               const G4ParticleDefinition* p,
222               G4double kineticEnergy,             227               G4double kineticEnergy,
223               G4double cutEnergy,                 228               G4double cutEnergy,
224               G4double maxEnergy  )               229               G4double maxEnergy  ) 
225 {                                                 230 {
226   G4int coupleIndex = FindCoupleIndex(CurrentC    231   G4int coupleIndex = FindCoupleIndex(CurrentCouple());
227   if(0 > coupleIndex) { return 0.0; }             232   if(0 > coupleIndex) { return 0.0; }
228                                                   233 
229   G4double tmax = std::min(MaxSecondaryEnergy(    234   G4double tmax = std::min(MaxSecondaryEnergy(p, kineticEnergy), maxEnergy);
230   if(tmax <= cutEnergy) { return 0.0; }           235   if(tmax <= cutEnergy) { return 0.0; }
231                                                   236 
232   G4double scaledTkin = kineticEnergy*fRatio;     237   G4double scaledTkin = kineticEnergy*fRatio;
233   G4double xs = fChargeSquare*fModelData->Cros << 238 
234                                           scal << 239   return fChargeSquare*fModelData->CrossSectionPerVolume(coupleIndex, 
235   return xs;                                   << 240                scaledTkin, 
                                                   >> 241                cutEnergy, tmax);
236 }                                                 242 }
237                                                   243 
238 //////////////////////////////////////////////    244 ///////////////////////////////////////////////////////////////////////////
239 //                                                245 //
240 // It is analog of PostStepDoIt in terms of se    246 // It is analog of PostStepDoIt in terms of secondary electron.
241 //                                                247 //
242                                                   248  
243 void G4PAIModel::SampleSecondaries(std::vector    249 void G4PAIModel::SampleSecondaries(std::vector<G4DynamicParticle*>* vdp,
244            const G4MaterialCutsCouple* matCC,     250            const G4MaterialCutsCouple* matCC,
245            const G4DynamicParticle* dp,           251            const G4DynamicParticle* dp,
246            G4double tmin,                         252            G4double tmin,
247            G4double maxEnergy)                    253            G4double maxEnergy)
248 {                                                 254 {
249   G4int coupleIndex = FindCoupleIndex(matCC);     255   G4int coupleIndex = FindCoupleIndex(matCC);
250                                                << 
251   //G4cout << "G4PAIModel::SampleSecondaries:  << 
252   if(0 > coupleIndex) { return; }                 256   if(0 > coupleIndex) { return; }
253                                                   257 
254   SetParticle(dp->GetDefinition());               258   SetParticle(dp->GetDefinition());
255   G4double kineticEnergy = dp->GetKineticEnerg    259   G4double kineticEnergy = dp->GetKineticEnergy();
256                                                   260 
257   G4double tmax = MaxSecondaryEnergy(fParticle    261   G4double tmax = MaxSecondaryEnergy(fParticle, kineticEnergy);
258   if(maxEnergy < tmax) { tmax = maxEnergy; }      262   if(maxEnergy < tmax) { tmax = maxEnergy; }
259   if(tmin >= tmax) { return; }                    263   if(tmin >= tmax) { return; }
260                                                   264 
261   G4ThreeVector direction= dp->GetMomentumDire    265   G4ThreeVector direction= dp->GetMomentumDirection();
262   G4double scaledTkin    = kineticEnergy*fRati    266   G4double scaledTkin    = kineticEnergy*fRatio;
263   G4double totalEnergy   = kineticEnergy + fMa    267   G4double totalEnergy   = kineticEnergy + fMass;
264   G4double totalMomentum = sqrt(kineticEnergy*    268   G4double totalMomentum = sqrt(kineticEnergy*(totalEnergy+fMass));
265                                                   269 
266   G4double deltaTkin =                            270   G4double deltaTkin = 
267     fModelData->SamplePostStepTransfer(coupleI << 271     fModelData->SamplePostStepTransfer(coupleIndex, scaledTkin, tmax);
268                                                   272 
269   //G4cout<<"G4PAIModel::SampleSecondaries; de    273   //G4cout<<"G4PAIModel::SampleSecondaries; deltaKIn = "<<deltaTkin/keV
270   //  <<" keV "<< " Escaled(MeV)= " << scaledT    274   //  <<" keV "<< " Escaled(MeV)= " << scaledTkin << G4endl;
271                                                   275 
272   if( !(deltaTkin <= 0.) && !(deltaTkin > 0))     276   if( !(deltaTkin <= 0.) && !(deltaTkin > 0)) {
273     G4cout<<"G4PAIModel::SampleSecondaries; de    277     G4cout<<"G4PAIModel::SampleSecondaries; deltaKIn = "<<deltaTkin/keV
274     <<" keV "<< " Escaled(MeV)= " << scaledTki    278     <<" keV "<< " Escaled(MeV)= " << scaledTkin << G4endl;
275     return;                                       279     return;
276   }                                               280   }
277   if( deltaTkin <= 0.) { return; }                281   if( deltaTkin <= 0.) { return; }
278                                                   282 
279   if( deltaTkin > tmax) { deltaTkin = tmax; }     283   if( deltaTkin > tmax) { deltaTkin = tmax; }
280                                                   284 
281   const G4Element* anElement = SelectTargetAto << 285   const G4Element* anElement = SelectRandomAtom(matCC,fParticle,kineticEnergy);
282                                                << 286   G4int Z = G4lrint(anElement->GetZ());
283                                                << 
284   G4int Z = anElement->GetZasInt();            << 
285                                                   287  
286   auto deltaRay = new G4DynamicParticle(fElect << 288   G4DynamicParticle* deltaRay = new G4DynamicParticle(fElectron, 
287       GetAngularDistribution()->SampleDirectio    289       GetAngularDistribution()->SampleDirection(dp, deltaTkin,
288                   Z, matCC->GetMaterial()),       290                   Z, matCC->GetMaterial()),
289                   deltaTkin);                     291                   deltaTkin);
290                                                   292 
291   // primary change                               293   // primary change
292   kineticEnergy -= deltaTkin;                     294   kineticEnergy -= deltaTkin;
293   G4ThreeVector dir = totalMomentum*direction     295   G4ThreeVector dir = totalMomentum*direction - deltaRay->GetMomentum();
294   direction = dir.unit();                         296   direction = dir.unit();
295   fParticleChange->SetProposedKineticEnergy(ki    297   fParticleChange->SetProposedKineticEnergy(kineticEnergy);
296   fParticleChange->SetProposedMomentumDirectio    298   fParticleChange->SetProposedMomentumDirection(direction);
297                                                   299 
298   vdp->push_back(deltaRay);                       300   vdp->push_back(deltaRay);
299 }                                                 301 }
300                                                   302 
301 //////////////////////////////////////////////    303 ///////////////////////////////////////////////////////////////////////
302                                                   304 
303 G4double G4PAIModel::SampleFluctuations(const  << 305 G4double G4PAIModel::SampleFluctuations( const G4MaterialCutsCouple* matCC,
304                                         const  << 306                                          const G4DynamicParticle* aParticle,
305                                         const  << 307            G4double, G4double step,
306           const G4double,                      << 308            G4double eloss)
307                                         const  << 
308           const G4double eloss)                << 
309 {                                                 309 {
310   G4int coupleIndex = FindCoupleIndex(matCC);     310   G4int coupleIndex = FindCoupleIndex(matCC);
311   if(0 > coupleIndex) { return eloss; }           311   if(0 > coupleIndex) { return eloss; }
312                                                   312 
313   SetParticle(aParticle->GetDefinition());        313   SetParticle(aParticle->GetDefinition());
314                                                   314 
315   /*                                              315   /*
316   G4cout << "G4PAIModel::SampleFluctuations st    316   G4cout << "G4PAIModel::SampleFluctuations step(mm)= "<< step/mm
317    << "  Eloss(keV)= " << eloss/keV  << " in "    317    << "  Eloss(keV)= " << eloss/keV  << " in " 
318    << matCC->Getmaterial()->GetName() << G4end    318    << matCC->Getmaterial()->GetName() << G4endl;
319   */                                              319   */
320                                                   320 
321   G4double Tkin       = aParticle->GetKineticE    321   G4double Tkin       = aParticle->GetKineticEnergy();
322   G4double scaledTkin = Tkin*fRatio;              322   G4double scaledTkin = Tkin*fRatio;
323                                                   323 
324   G4double loss = fModelData->SampleAlongStepT    324   G4double loss = fModelData->SampleAlongStepTransfer(coupleIndex, Tkin,
325                   scaledTkin, tcut,            << 325                   scaledTkin,
326                   step*fChargeSquare);            326                   step*fChargeSquare);
327                                                   327   
328   // G4cout<<"PAIModel AlongStepLoss = "<<loss    328   // G4cout<<"PAIModel AlongStepLoss = "<<loss/keV<<" keV, on step = "
329   //<<step/mm<<" mm"<<G4endl;                     329   //<<step/mm<<" mm"<<G4endl; 
330   return loss;                                    330   return loss;
331                                                   331 
332 }                                                 332 }
333                                                   333 
334 //////////////////////////////////////////////    334 //////////////////////////////////////////////////////////////////////
335 //                                                335 //
336 // Returns the statistical estimation of the e    336 // Returns the statistical estimation of the energy loss distribution variance
337 //                                                337 //
338                                                   338 
339                                                   339 
340 G4double G4PAIModel::Dispersion( const G4Mater    340 G4double G4PAIModel::Dispersion( const G4Material* material, 
341                                  const G4Dynam    341                                  const G4DynamicParticle* aParticle,
342          const G4double tcut,                  << 342                G4double tmax, 
343          const G4double tmax,                  << 343                      G4double step       )
344                const G4double step )           << 
345 {                                                 344 {
346   G4double particleMass  = aParticle->GetMass(    345   G4double particleMass  = aParticle->GetMass();
347   G4double electronDensity = material->GetElec    346   G4double electronDensity = material->GetElectronDensity();
348   G4double kineticEnergy = aParticle->GetKinet    347   G4double kineticEnergy = aParticle->GetKineticEnergy();
349   G4double q = aParticle->GetCharge()/eplus;      348   G4double q = aParticle->GetCharge()/eplus;
350   G4double etot = kineticEnergy + particleMass    349   G4double etot = kineticEnergy + particleMass;
351   G4double beta2 = kineticEnergy*(kineticEnerg    350   G4double beta2 = kineticEnergy*(kineticEnergy + 2.0*particleMass)/(etot*etot);
352   G4double siga  = (tmax/beta2 - 0.5*tcut) * t << 351   G4double siga  = (1.0/beta2 - 0.5) * twopi_mc2_rcl2 * tmax * step
353                  * electronDensity * q * q;       352                  * electronDensity * q * q;
354                                                   353 
355   return siga;                                    354   return siga;
                                                   >> 355   /*
                                                   >> 356   G4double loss, sumLoss=0., sumLoss2=0., sigma2, meanLoss=0.;
                                                   >> 357   for(G4int i = 0; i < fMeanNumber; i++)
                                                   >> 358   {
                                                   >> 359     loss      = SampleFluctuations(material,aParticle,tmax,step,meanLoss);
                                                   >> 360     sumLoss  += loss;
                                                   >> 361     sumLoss2 += loss*loss;
                                                   >> 362   }
                                                   >> 363   meanLoss = sumLoss/fMeanNumber;
                                                   >> 364   sigma2   = meanLoss*meanLoss + (sumLoss2-2*sumLoss*meanLoss)/fMeanNumber;
                                                   >> 365   return sigma2;
                                                   >> 366   */
356 }                                                 367 }
357                                                   368 
358 //////////////////////////////////////////////    369 /////////////////////////////////////////////////////////////////////
359                                                   370 
360 G4double G4PAIModel::MaxSecondaryEnergy( const    371 G4double G4PAIModel::MaxSecondaryEnergy( const G4ParticleDefinition* p,
361            G4double kinEnergy)                    372            G4double kinEnergy) 
362 {                                                 373 {
363   SetParticle(p);                                 374   SetParticle(p);
364   G4double tmax = kinEnergy;                      375   G4double tmax = kinEnergy;
365   if(p == fElectron) { tmax *= 0.5; }             376   if(p == fElectron) { tmax *= 0.5; }
366   else if(p != fPositron) {                       377   else if(p != fPositron) { 
367     G4double ratio= electron_mass_c2/fMass;       378     G4double ratio= electron_mass_c2/fMass;
368     G4double gamma= kinEnergy/fMass + 1.0;        379     G4double gamma= kinEnergy/fMass + 1.0;
369     tmax = 2.0*electron_mass_c2*(gamma*gamma -    380     tmax = 2.0*electron_mass_c2*(gamma*gamma - 1.) /
370                   (1. + 2.0*gamma*ratio + rati    381                   (1. + 2.0*gamma*ratio + ratio*ratio);
371   }                                               382   }
372   return tmax;                                    383   return tmax;
373 }                                                 384 }
374                                                   385 
375 //////////////////////////////////////////////    386 ///////////////////////////////////////////////////////////////
376                                                   387 
377 void G4PAIModel::DefineForRegion(const G4Regio    388 void G4PAIModel::DefineForRegion(const G4Region* r) 
378 {                                                 389 {
379   fPAIRegionVector.push_back(r);                  390   fPAIRegionVector.push_back(r);
380 }                                                 391 }
381                                                   392 
382 ////////////////////////////////////////////// << 393 //
383                                                << 394 //
                                                   >> 395 /////////////////////////////////////////////////
384                                                   396