Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/hadronic/models/coherent_elastic/src/G4DiffuseElastic.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/hadronic/models/coherent_elastic/src/G4DiffuseElastic.cc (Version 11.3.0) and /processes/hadronic/models/coherent_elastic/src/G4DiffuseElastic.cc (Version 10.1.p2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
                                                   >>  26 // $Id: G4DiffuseElastic.cc 88985 2015-03-17 10:30:14Z gcosmo $
 26 //                                                 27 //
 27 //                                                 28 //
 28 // Physics model class G4DiffuseElastic            29 // Physics model class G4DiffuseElastic 
 29 //                                                 30 //
 30 //                                                 31 //
 31 // G4 Model: optical diffuse elastic scatterin     32 // G4 Model: optical diffuse elastic scattering with 4-momentum balance
 32 //                                                 33 //                         
 33 // 24-May-07 V. Grichine                           34 // 24-May-07 V. Grichine
 34 //                                                 35 //
 35 // 21.10.15 V. Grichine                        << 
 36 //             Bug fixed in BuildAngleTable, i << 
 37 //             angle bins at high energies > 5 << 
 38 //                                             << 
 39                                                    36 
 40 #include "G4DiffuseElastic.hh"                     37 #include "G4DiffuseElastic.hh"
 41 #include "G4ParticleTable.hh"                      38 #include "G4ParticleTable.hh"
 42 #include "G4ParticleDefinition.hh"                 39 #include "G4ParticleDefinition.hh"
 43 #include "G4IonTable.hh"                           40 #include "G4IonTable.hh"
 44 #include "G4NucleiProperties.hh"                   41 #include "G4NucleiProperties.hh"
 45                                                    42 
 46 #include "Randomize.hh"                            43 #include "Randomize.hh"
 47 #include "G4Integrator.hh"                         44 #include "G4Integrator.hh"
 48 #include "globals.hh"                              45 #include "globals.hh"
 49 #include "G4PhysicalConstants.hh"                  46 #include "G4PhysicalConstants.hh"
 50 #include "G4SystemOfUnits.hh"                      47 #include "G4SystemOfUnits.hh"
 51                                                    48 
 52 #include "G4Proton.hh"                             49 #include "G4Proton.hh"
 53 #include "G4Neutron.hh"                            50 #include "G4Neutron.hh"
 54 #include "G4Deuteron.hh"                           51 #include "G4Deuteron.hh"
 55 #include "G4Alpha.hh"                              52 #include "G4Alpha.hh"
 56 #include "G4PionPlus.hh"                           53 #include "G4PionPlus.hh"
 57 #include "G4PionMinus.hh"                          54 #include "G4PionMinus.hh"
 58                                                    55 
 59 #include "G4Element.hh"                            56 #include "G4Element.hh"
 60 #include "G4ElementTable.hh"                       57 #include "G4ElementTable.hh"
 61 #include "G4NistManager.hh"                        58 #include "G4NistManager.hh"
 62 #include "G4PhysicsTable.hh"                       59 #include "G4PhysicsTable.hh"
 63 #include "G4PhysicsLogVector.hh"                   60 #include "G4PhysicsLogVector.hh"
 64 #include "G4PhysicsFreeVector.hh"                  61 #include "G4PhysicsFreeVector.hh"
 65                                                    62 
 66 #include "G4Exp.hh"                            << 
 67                                                << 
 68 #include "G4HadronicParameters.hh"             << 
 69                                                << 
 70 //////////////////////////////////////////////     63 /////////////////////////////////////////////////////////////////////////
 71 //                                                 64 //
 72 // Test Constructor. Just to check xsc             65 // Test Constructor. Just to check xsc
 73                                                    66 
 74                                                    67 
 75 G4DiffuseElastic::G4DiffuseElastic()               68 G4DiffuseElastic::G4DiffuseElastic() 
 76   : G4HadronElastic("DiffuseElastic"), fPartic     69   : G4HadronElastic("DiffuseElastic"), fParticle(0)
 77 {                                                  70 {
 78   SetMinEnergy( 0.01*MeV );                    <<  71   SetMinEnergy( 0.01*MeV ); // 0.01*GeV );
 79   SetMaxEnergy( G4HadronicParameters::Instance <<  72   SetMaxEnergy( 1.*TeV );
 80                                                <<  73   verboseLevel = 0;
 81   verboseLevel         = 0;                    << 
 82   lowEnergyRecoilLimit = 100.*keV;                 74   lowEnergyRecoilLimit = 100.*keV;  
 83   lowEnergyLimitQ      = 0.0*GeV;              <<  75   lowEnergyLimitQ  = 0.0*GeV;  
 84   lowEnergyLimitHE     = 0.0*GeV;              <<  76   lowEnergyLimitHE = 0.0*GeV;  
 85   lowestEnergyLimit    = 0.0*keV;              <<  77   lowestEnergyLimit= 0.0*keV;  
 86   plabLowLimit         = 20.0*MeV;             <<  78   plabLowLimit     = 20.0*MeV;
 87                                                <<  79 
 88   theProton    = G4Proton::Proton();           <<  80   theProton   = G4Proton::Proton();
 89   theNeutron   = G4Neutron::Neutron();         <<  81   theNeutron  = G4Neutron::Neutron();
 90   theDeuteron  = G4Deuteron::Deuteron();       <<  82   theDeuteron = G4Deuteron::Deuteron();
 91   theAlpha     = G4Alpha::Alpha();             <<  83   theAlpha    = G4Alpha::Alpha();
 92   thePionPlus  = G4PionPlus::PionPlus();       <<  84   thePionPlus = G4PionPlus::PionPlus();
 93   thePionMinus = G4PionMinus::PionMinus();     <<  85   thePionMinus= G4PionMinus::PionMinus();
 94                                                    86 
 95   fEnergyBin = 300;  // Increased from the ori <<  87   fEnergyBin = 200;
 96   fAngleBin  = 200;                                88   fAngleBin  = 200;
 97                                                    89 
 98   fEnergyVector =  new G4PhysicsLogVector( the     90   fEnergyVector =  new G4PhysicsLogVector( theMinEnergy, theMaxEnergy, fEnergyBin );
 99                                                << 
100   fAngleTable = 0;                                 91   fAngleTable = 0;
101                                                    92 
102   fParticle      = 0;                          <<  93   fParticle = 0;
103   fWaveVector    = 0.;                         <<  94   fWaveVector = 0.;
104   fAtomicWeight  = 0.;                         <<  95   fAtomicWeight = 0.;
105   fAtomicNumber  = 0.;                         <<  96   fAtomicNumber = 0.;
106   fNuclearRadius = 0.;                             97   fNuclearRadius = 0.;
107   fBeta          = 0.;                         <<  98   fBeta = 0.;
108   fZommerfeld    = 0.;                         <<  99   fZommerfeld = 0.;
109   fAm = 0.;                                       100   fAm = 0.;
110   fAddCoulomb = false;                            101   fAddCoulomb = false;
111 }                                                 102 }
112                                                   103 
113 //////////////////////////////////////////////    104 //////////////////////////////////////////////////////////////////////////////
114 //                                                105 //
115 // Destructor                                     106 // Destructor
116                                                   107 
117 G4DiffuseElastic::~G4DiffuseElastic()             108 G4DiffuseElastic::~G4DiffuseElastic()
118 {                                                 109 {
119   if ( fEnergyVector )                            110   if ( fEnergyVector ) 
120   {                                               111   {
121     delete fEnergyVector;                         112     delete fEnergyVector;
122     fEnergyVector = 0;                            113     fEnergyVector = 0;
123   }                                               114   }
124   for ( std::vector<G4PhysicsTable*>::iterator    115   for ( std::vector<G4PhysicsTable*>::iterator it = fAngleBank.begin();
125         it != fAngleBank.end(); ++it )            116         it != fAngleBank.end(); ++it ) 
126   {                                               117   {
127     if ( (*it) ) (*it)->clearAndDestroy();        118     if ( (*it) ) (*it)->clearAndDestroy();
128                                                   119 
129     delete *it;                                   120     delete *it;
130     *it = 0;                                      121     *it = 0;
131   }                                               122   }
132   fAngleTable = 0;                                123   fAngleTable = 0;
133 }                                                 124 }
134                                                   125 
135 //////////////////////////////////////////////    126 //////////////////////////////////////////////////////////////////////////////
136 //                                                127 //
137 // Initialisation for given particle using ele    128 // Initialisation for given particle using element table of application
138                                                   129 
139 void G4DiffuseElastic::Initialise()               130 void G4DiffuseElastic::Initialise() 
140 {                                                 131 {
141                                                   132 
142   // fEnergyVector = new G4PhysicsLogVector( t    133   // fEnergyVector = new G4PhysicsLogVector( theMinEnergy, theMaxEnergy, fEnergyBin );
143                                                   134 
144   const G4ElementTable* theElementTable = G4El    135   const G4ElementTable* theElementTable = G4Element::GetElementTable();
145                                                   136 
146   std::size_t jEl, numOfEl = G4Element::GetNum << 137   size_t jEl, numOfEl = G4Element::GetNumberOfElements();
147                                                   138 
148   for( jEl = 0; jEl < numOfEl; ++jEl) // appli    139   for( jEl = 0; jEl < numOfEl; ++jEl) // application element loop
149   {                                               140   {
150     fAtomicNumber = (*theElementTable)[jEl]->G    141     fAtomicNumber = (*theElementTable)[jEl]->GetZ();     // atomic number
151     fAtomicWeight = G4NistManager::Instance()-    142     fAtomicWeight = G4NistManager::Instance()->GetAtomicMassAmu( static_cast< G4int >( fAtomicNumber ) );
152     fNuclearRadius = CalculateNuclearRad(fAtom    143     fNuclearRadius = CalculateNuclearRad(fAtomicWeight);
153                                                   144 
154     if( verboseLevel > 0 )                        145     if( verboseLevel > 0 ) 
155     {                                             146     {   
156       G4cout<<"G4DiffuseElastic::Initialise()     147       G4cout<<"G4DiffuseElastic::Initialise() the element: "
157       <<(*theElementTable)[jEl]->GetName()<<G4    148       <<(*theElementTable)[jEl]->GetName()<<G4endl;
158     }                                             149     }
159     fElementNumberVector.push_back(fAtomicNumb    150     fElementNumberVector.push_back(fAtomicNumber);
160     fElementNameVector.push_back((*theElementT    151     fElementNameVector.push_back((*theElementTable)[jEl]->GetName());
161                                                   152 
162     BuildAngleTable();                            153     BuildAngleTable();
163     fAngleBank.push_back(fAngleTable);            154     fAngleBank.push_back(fAngleTable);
164   }                                               155   }  
165   return;                                         156   return;
166 }                                                 157 }
167                                                   158 
168 //////////////////////////////////////////////    159 ////////////////////////////////////////////////////////////////////////////
169 //                                                160 //
170 // return differential elastic cross section d    161 // return differential elastic cross section d(sigma)/d(omega) 
171                                                   162 
172 G4double                                          163 G4double 
173 G4DiffuseElastic::GetDiffuseElasticXsc( const     164 G4DiffuseElastic::GetDiffuseElasticXsc( const G4ParticleDefinition* particle, 
174                                         G4doub    165                                         G4double theta, 
175                       G4double momentum,          166                       G4double momentum, 
176                                         G4doub    167                                         G4double A         )
177 {                                                 168 {
178   fParticle      = particle;                      169   fParticle      = particle;
179   fWaveVector    = momentum/hbarc;                170   fWaveVector    = momentum/hbarc;
180   fAtomicWeight  = A;                             171   fAtomicWeight  = A;
181   fAddCoulomb    = false;                         172   fAddCoulomb    = false;
182   fNuclearRadius = CalculateNuclearRad(A);        173   fNuclearRadius = CalculateNuclearRad(A);
183                                                   174 
184   G4double sigma = fNuclearRadius*fNuclearRadi    175   G4double sigma = fNuclearRadius*fNuclearRadius*GetDiffElasticProb(theta);
185                                                   176 
186   return sigma;                                   177   return sigma;
187 }                                                 178 }
188                                                   179 
189 //////////////////////////////////////////////    180 ////////////////////////////////////////////////////////////////////////////
190 //                                                181 //
191 // return invariant differential elastic cross    182 // return invariant differential elastic cross section d(sigma)/d(tMand) 
192                                                   183 
193 G4double                                          184 G4double 
194 G4DiffuseElastic::GetInvElasticXsc( const G4Pa    185 G4DiffuseElastic::GetInvElasticXsc( const G4ParticleDefinition* particle, 
195                                         G4doub    186                                         G4double tMand, 
196                       G4double plab,              187                       G4double plab, 
197                                         G4doub    188                                         G4double A, G4double Z         )
198 {                                                 189 {
199   G4double m1 = particle->GetPDGMass();           190   G4double m1 = particle->GetPDGMass();
200   G4LorentzVector lv1(0.,0.,plab,std::sqrt(pla    191   G4LorentzVector lv1(0.,0.,plab,std::sqrt(plab*plab+m1*m1));
201                                                   192 
202   G4int iZ = static_cast<G4int>(Z+0.5);           193   G4int iZ = static_cast<G4int>(Z+0.5);
203   G4int iA = static_cast<G4int>(A+0.5);           194   G4int iA = static_cast<G4int>(A+0.5);
204   G4ParticleDefinition * theDef = 0;              195   G4ParticleDefinition * theDef = 0;
205                                                   196 
206   if      (iZ == 1 && iA == 1) theDef = thePro    197   if      (iZ == 1 && iA == 1) theDef = theProton;
207   else if (iZ == 1 && iA == 2) theDef = theDeu    198   else if (iZ == 1 && iA == 2) theDef = theDeuteron;
208   else if (iZ == 1 && iA == 3) theDef = G4Trit    199   else if (iZ == 1 && iA == 3) theDef = G4Triton::Triton();
209   else if (iZ == 2 && iA == 3) theDef = G4He3:    200   else if (iZ == 2 && iA == 3) theDef = G4He3::He3();
210   else if (iZ == 2 && iA == 4) theDef = theAlp    201   else if (iZ == 2 && iA == 4) theDef = theAlpha;
211   else theDef = G4ParticleTable::GetParticleTa    202   else theDef = G4ParticleTable::GetParticleTable()->GetIonTable()->GetIon(iZ,iA,0);
212                                                   203  
213   G4double tmass = theDef->GetPDGMass();          204   G4double tmass = theDef->GetPDGMass();
214                                                   205 
215   G4LorentzVector lv(0.0,0.0,0.0,tmass);          206   G4LorentzVector lv(0.0,0.0,0.0,tmass);   
216   lv += lv1;                                      207   lv += lv1;
217                                                   208 
218   G4ThreeVector bst = lv.boostVector();           209   G4ThreeVector bst = lv.boostVector();
219   lv1.boost(-bst);                                210   lv1.boost(-bst);
220                                                   211 
221   G4ThreeVector p1 = lv1.vect();                  212   G4ThreeVector p1 = lv1.vect();
222   G4double ptot    = p1.mag();                    213   G4double ptot    = p1.mag();
223   G4double ptot2 = ptot*ptot;                     214   G4double ptot2 = ptot*ptot;
224   G4double cost = 1 - 0.5*std::fabs(tMand)/pto    215   G4double cost = 1 - 0.5*std::fabs(tMand)/ptot2;
225                                                   216 
226   if( cost >= 1.0 )      cost = 1.0;              217   if( cost >= 1.0 )      cost = 1.0;  
227   else if( cost <= -1.0) cost = -1.0;             218   else if( cost <= -1.0) cost = -1.0;
228                                                   219   
229   G4double thetaCMS = std::acos(cost);            220   G4double thetaCMS = std::acos(cost);
230                                                   221 
231   G4double sigma = GetDiffuseElasticXsc( parti    222   G4double sigma = GetDiffuseElasticXsc( particle, thetaCMS, ptot, A);
232                                                   223 
233   sigma *= pi/ptot2;                              224   sigma *= pi/ptot2;
234                                                   225 
235   return sigma;                                   226   return sigma;
236 }                                                 227 }
237                                                   228 
238 //////////////////////////////////////////////    229 ////////////////////////////////////////////////////////////////////////////
239 //                                                230 //
240 // return differential elastic cross section d    231 // return differential elastic cross section d(sigma)/d(omega) with Coulomb
241 // correction                                     232 // correction
242                                                   233 
243 G4double                                          234 G4double 
244 G4DiffuseElastic::GetDiffuseElasticSumXsc( con    235 G4DiffuseElastic::GetDiffuseElasticSumXsc( const G4ParticleDefinition* particle, 
245                                         G4doub    236                                         G4double theta, 
246                       G4double momentum,          237                       G4double momentum, 
247                                         G4doub    238                                         G4double A, G4double Z         )
248 {                                                 239 {
249   fParticle      = particle;                      240   fParticle      = particle;
250   fWaveVector    = momentum/hbarc;                241   fWaveVector    = momentum/hbarc;
251   fAtomicWeight  = A;                             242   fAtomicWeight  = A;
252   fAtomicNumber  = Z;                             243   fAtomicNumber  = Z;
253   fNuclearRadius = CalculateNuclearRad(A);        244   fNuclearRadius = CalculateNuclearRad(A);
254   fAddCoulomb    = false;                         245   fAddCoulomb    = false;
255                                                   246 
256   G4double z     = particle->GetPDGCharge();      247   G4double z     = particle->GetPDGCharge();
257                                                   248 
258   G4double kRt   = fWaveVector*fNuclearRadius*    249   G4double kRt   = fWaveVector*fNuclearRadius*theta;
259   G4double kRtC  = 1.9;                           250   G4double kRtC  = 1.9;
260                                                   251 
261   if( z && (kRt > kRtC) )                         252   if( z && (kRt > kRtC) )
262   {                                               253   {
263     fAddCoulomb = true;                           254     fAddCoulomb = true;
264     fBeta       = CalculateParticleBeta( parti    255     fBeta       = CalculateParticleBeta( particle, momentum);
265     fZommerfeld = CalculateZommerfeld( fBeta,     256     fZommerfeld = CalculateZommerfeld( fBeta, z, fAtomicNumber);
266     fAm         = CalculateAm( momentum, fZomm    257     fAm         = CalculateAm( momentum, fZommerfeld, fAtomicNumber);
267   }                                               258   }
268   G4double sigma = fNuclearRadius*fNuclearRadi    259   G4double sigma = fNuclearRadius*fNuclearRadius*GetDiffElasticSumProb(theta);
269                                                   260 
270   return sigma;                                   261   return sigma;
271 }                                                 262 }
272                                                   263 
273 //////////////////////////////////////////////    264 ////////////////////////////////////////////////////////////////////////////
274 //                                                265 //
275 // return invariant differential elastic cross    266 // return invariant differential elastic cross section d(sigma)/d(tMand) with Coulomb
276 // correction                                     267 // correction
277                                                   268 
278 G4double                                          269 G4double 
279 G4DiffuseElastic::GetInvElasticSumXsc( const G    270 G4DiffuseElastic::GetInvElasticSumXsc( const G4ParticleDefinition* particle, 
280                                         G4doub    271                                         G4double tMand, 
281                       G4double plab,              272                       G4double plab, 
282                                         G4doub    273                                         G4double A, G4double Z         )
283 {                                                 274 {
284   G4double m1 = particle->GetPDGMass();           275   G4double m1 = particle->GetPDGMass();
285                                                   276 
286   G4LorentzVector lv1(0.,0.,plab,std::sqrt(pla    277   G4LorentzVector lv1(0.,0.,plab,std::sqrt(plab*plab+m1*m1));
287                                                   278 
288   G4int iZ = static_cast<G4int>(Z+0.5);           279   G4int iZ = static_cast<G4int>(Z+0.5);
289   G4int iA = static_cast<G4int>(A+0.5);           280   G4int iA = static_cast<G4int>(A+0.5);
290                                                   281 
291   G4ParticleDefinition* theDef = 0;               282   G4ParticleDefinition* theDef = 0;
292                                                   283 
293   if      (iZ == 1 && iA == 1) theDef = thePro    284   if      (iZ == 1 && iA == 1) theDef = theProton;
294   else if (iZ == 1 && iA == 2) theDef = theDeu    285   else if (iZ == 1 && iA == 2) theDef = theDeuteron;
295   else if (iZ == 1 && iA == 3) theDef = G4Trit    286   else if (iZ == 1 && iA == 3) theDef = G4Triton::Triton();
296   else if (iZ == 2 && iA == 3) theDef = G4He3:    287   else if (iZ == 2 && iA == 3) theDef = G4He3::He3();
297   else if (iZ == 2 && iA == 4) theDef = theAlp    288   else if (iZ == 2 && iA == 4) theDef = theAlpha;
298   else theDef = G4ParticleTable::GetParticleTa    289   else theDef = G4ParticleTable::GetParticleTable()->GetIonTable()->GetIon(iZ,iA,0);
299                                                   290  
300   G4double tmass = theDef->GetPDGMass();          291   G4double tmass = theDef->GetPDGMass();
301                                                   292 
302   G4LorentzVector lv(0.0,0.0,0.0,tmass);          293   G4LorentzVector lv(0.0,0.0,0.0,tmass);   
303   lv += lv1;                                      294   lv += lv1;
304                                                   295 
305   G4ThreeVector bst = lv.boostVector();           296   G4ThreeVector bst = lv.boostVector();
306   lv1.boost(-bst);                                297   lv1.boost(-bst);
307                                                   298 
308   G4ThreeVector p1 = lv1.vect();                  299   G4ThreeVector p1 = lv1.vect();
309   G4double ptot    = p1.mag();                    300   G4double ptot    = p1.mag();
310   G4double ptot2   = ptot*ptot;                   301   G4double ptot2   = ptot*ptot;
311   G4double cost    = 1 - 0.5*std::fabs(tMand)/    302   G4double cost    = 1 - 0.5*std::fabs(tMand)/ptot2;
312                                                   303 
313   if( cost >= 1.0 )      cost = 1.0;              304   if( cost >= 1.0 )      cost = 1.0;  
314   else if( cost <= -1.0) cost = -1.0;             305   else if( cost <= -1.0) cost = -1.0;
315                                                   306   
316   G4double thetaCMS = std::acos(cost);            307   G4double thetaCMS = std::acos(cost);
317                                                   308 
318   G4double sigma = GetDiffuseElasticSumXsc( pa    309   G4double sigma = GetDiffuseElasticSumXsc( particle, thetaCMS, ptot, A, Z );
319                                                   310 
320   sigma *= pi/ptot2;                              311   sigma *= pi/ptot2;
321                                                   312 
322   return sigma;                                   313   return sigma;
323 }                                                 314 }
324                                                   315 
325 //////////////////////////////////////////////    316 ////////////////////////////////////////////////////////////////////////////
326 //                                                317 //
327 // return invariant differential elastic cross    318 // return invariant differential elastic cross section d(sigma)/d(tMand) with Coulomb
328 // correction                                     319 // correction
329                                                   320 
330 G4double                                          321 G4double 
331 G4DiffuseElastic::GetInvCoulombElasticXsc( con    322 G4DiffuseElastic::GetInvCoulombElasticXsc( const G4ParticleDefinition* particle, 
332                                         G4doub    323                                         G4double tMand, 
333                       G4double plab,              324                       G4double plab, 
334                                         G4doub    325                                         G4double A, G4double Z         )
335 {                                                 326 {
336   G4double m1 = particle->GetPDGMass();           327   G4double m1 = particle->GetPDGMass();
337   G4LorentzVector lv1(0.,0.,plab,std::sqrt(pla    328   G4LorentzVector lv1(0.,0.,plab,std::sqrt(plab*plab+m1*m1));
338                                                   329 
339   G4int iZ = static_cast<G4int>(Z+0.5);           330   G4int iZ = static_cast<G4int>(Z+0.5);
340   G4int iA = static_cast<G4int>(A+0.5);           331   G4int iA = static_cast<G4int>(A+0.5);
341   G4ParticleDefinition * theDef = 0;              332   G4ParticleDefinition * theDef = 0;
342                                                   333 
343   if      (iZ == 1 && iA == 1) theDef = thePro    334   if      (iZ == 1 && iA == 1) theDef = theProton;
344   else if (iZ == 1 && iA == 2) theDef = theDeu    335   else if (iZ == 1 && iA == 2) theDef = theDeuteron;
345   else if (iZ == 1 && iA == 3) theDef = G4Trit    336   else if (iZ == 1 && iA == 3) theDef = G4Triton::Triton();
346   else if (iZ == 2 && iA == 3) theDef = G4He3:    337   else if (iZ == 2 && iA == 3) theDef = G4He3::He3();
347   else if (iZ == 2 && iA == 4) theDef = theAlp    338   else if (iZ == 2 && iA == 4) theDef = theAlpha;
348   else theDef = G4ParticleTable::GetParticleTa    339   else theDef = G4ParticleTable::GetParticleTable()->GetIonTable()->GetIon(iZ,iA,0);
349                                                   340  
350   G4double tmass = theDef->GetPDGMass();          341   G4double tmass = theDef->GetPDGMass();
351                                                   342 
352   G4LorentzVector lv(0.0,0.0,0.0,tmass);          343   G4LorentzVector lv(0.0,0.0,0.0,tmass);   
353   lv += lv1;                                      344   lv += lv1;
354                                                   345 
355   G4ThreeVector bst = lv.boostVector();           346   G4ThreeVector bst = lv.boostVector();
356   lv1.boost(-bst);                                347   lv1.boost(-bst);
357                                                   348 
358   G4ThreeVector p1 = lv1.vect();                  349   G4ThreeVector p1 = lv1.vect();
359   G4double ptot    = p1.mag();                    350   G4double ptot    = p1.mag();
360   G4double ptot2 = ptot*ptot;                     351   G4double ptot2 = ptot*ptot;
361   G4double cost = 1 - 0.5*std::fabs(tMand)/pto    352   G4double cost = 1 - 0.5*std::fabs(tMand)/ptot2;
362                                                   353 
363   if( cost >= 1.0 )      cost = 1.0;              354   if( cost >= 1.0 )      cost = 1.0;  
364   else if( cost <= -1.0) cost = -1.0;             355   else if( cost <= -1.0) cost = -1.0;
365                                                   356   
366   G4double thetaCMS = std::acos(cost);            357   G4double thetaCMS = std::acos(cost);
367                                                   358 
368   G4double sigma = GetCoulombElasticXsc( parti    359   G4double sigma = GetCoulombElasticXsc( particle, thetaCMS, ptot, Z );
369                                                   360 
370   sigma *= pi/ptot2;                              361   sigma *= pi/ptot2;
371                                                   362 
372   return sigma;                                   363   return sigma;
373 }                                                 364 }
374                                                   365 
375 //////////////////////////////////////////////    366 ////////////////////////////////////////////////////////////////////////////
376 //                                                367 //
377 // return differential elastic probability d(p    368 // return differential elastic probability d(probability)/d(omega) 
378                                                   369 
379 G4double                                          370 G4double 
380 G4DiffuseElastic::GetDiffElasticProb( // G4Par    371 G4DiffuseElastic::GetDiffElasticProb( // G4ParticleDefinition* particle, 
381                                         G4doub    372                                         G4double theta 
382           //  G4double momentum,                  373           //  G4double momentum, 
383           // G4double A                           374           // G4double A         
384                                      )            375                                      )
385 {                                                 376 {
386   G4double sigma, bzero, bzero2, bonebyarg, bo    377   G4double sigma, bzero, bzero2, bonebyarg, bonebyarg2, damp, damp2;
387   G4double delta, diffuse, gamma;                 378   G4double delta, diffuse, gamma;
388   G4double e1, e2, bone, bone2;                   379   G4double e1, e2, bone, bone2;
389                                                   380 
390   // G4double wavek = momentum/hbarc;  // wave    381   // G4double wavek = momentum/hbarc;  // wave vector
391   // G4double r0    = 1.08*fermi;                 382   // G4double r0    = 1.08*fermi;
392   // G4double rad   = r0*G4Pow::GetInstance()- << 383   // G4double rad   = r0*std::pow(A, 1./3.);
393                                                   384 
394   if (fParticle == theProton)                     385   if (fParticle == theProton)
395   {                                               386   {
396     diffuse = 0.63*fermi;                         387     diffuse = 0.63*fermi;
397     gamma   = 0.3*fermi;                          388     gamma   = 0.3*fermi;
398     delta   = 0.1*fermi*fermi;                    389     delta   = 0.1*fermi*fermi;
399     e1      = 0.3*fermi;                          390     e1      = 0.3*fermi;
400     e2      = 0.35*fermi;                         391     e2      = 0.35*fermi;
401   }                                               392   }
402   else if (fParticle == theNeutron)               393   else if (fParticle == theNeutron)
403   {                                               394   {
404     diffuse =  0.63*fermi; // 1.63*fermi; //      395     diffuse =  0.63*fermi; // 1.63*fermi; //
405     G4double k0 = 1*GeV/hbarc;                    396     G4double k0 = 1*GeV/hbarc;
406     diffuse *= k0/fWaveVector;                    397     diffuse *= k0/fWaveVector;
407                                                   398 
408     gamma   = 0.3*fermi;                          399     gamma   = 0.3*fermi;
409     delta   = 0.1*fermi*fermi;                    400     delta   = 0.1*fermi*fermi;
410     e1      = 0.3*fermi;                          401     e1      = 0.3*fermi;
411     e2      = 0.35*fermi;                         402     e2      = 0.35*fermi;
412   }                                               403   }
413   else // as proton, if were not defined          404   else // as proton, if were not defined 
414   {                                               405   {
415     diffuse = 0.63*fermi;                         406     diffuse = 0.63*fermi;
416     gamma   = 0.3*fermi;                          407     gamma   = 0.3*fermi;
417     delta   = 0.1*fermi*fermi;                    408     delta   = 0.1*fermi*fermi;
418     e1      = 0.3*fermi;                          409     e1      = 0.3*fermi;
419     e2      = 0.35*fermi;                         410     e2      = 0.35*fermi;
420   }                                               411   }
421   G4double kr    = fWaveVector*fNuclearRadius;    412   G4double kr    = fWaveVector*fNuclearRadius; // wavek*rad;
422   G4double kr2   = kr*kr;                         413   G4double kr2   = kr*kr;
423   G4double krt   = kr*theta;                      414   G4double krt   = kr*theta;
424                                                   415 
425   bzero      = BesselJzero(krt);                  416   bzero      = BesselJzero(krt);
426   bzero2     = bzero*bzero;                       417   bzero2     = bzero*bzero;    
427   bone       = BesselJone(krt);                   418   bone       = BesselJone(krt);
428   bone2      = bone*bone;                         419   bone2      = bone*bone;
429   bonebyarg  = BesselOneByArg(krt);               420   bonebyarg  = BesselOneByArg(krt);
430   bonebyarg2 = bonebyarg*bonebyarg;               421   bonebyarg2 = bonebyarg*bonebyarg;  
431                                                   422 
432   G4double lambda = 15.; // 15 ok                 423   G4double lambda = 15.; // 15 ok
433                                                   424 
434   //  G4double kgamma    = fWaveVector*gamma;     425   //  G4double kgamma    = fWaveVector*gamma;   // wavek*delta;
435                                                   426 
436   G4double kgamma    = lambda*(1.-G4Exp(-fWave << 427   G4double kgamma    = lambda*(1.-std::exp(-fWaveVector*gamma/lambda));   // wavek*delta;
437   G4double kgamma2   = kgamma*kgamma;             428   G4double kgamma2   = kgamma*kgamma;
438                                                   429 
439   // G4double dk2t  = delta*fWaveVector*fWaveV    430   // G4double dk2t  = delta*fWaveVector*fWaveVector*theta; // delta*wavek*wavek*theta;
440   // G4double dk2t2 = dk2t*dk2t;                  431   // G4double dk2t2 = dk2t*dk2t;
441   // G4double pikdt = pi*fWaveVector*diffuse*t    432   // G4double pikdt = pi*fWaveVector*diffuse*theta;// pi*wavek*diffuse*theta;
442                                                   433 
443   G4double pikdt    = lambda*(1.-G4Exp(-pi*fWa << 434   G4double pikdt    = lambda*(1.-std::exp(-pi*fWaveVector*diffuse*theta/lambda));   // wavek*delta;
444                                                   435 
445   damp           = DampFactor(pikdt);             436   damp           = DampFactor(pikdt);
446   damp2          = damp*damp;                     437   damp2          = damp*damp;
447                                                   438 
448   G4double mode2k2 = (e1*e1+e2*e2)*fWaveVector    439   G4double mode2k2 = (e1*e1+e2*e2)*fWaveVector*fWaveVector;  
449   G4double e2dk3t  = -2.*e2*delta*fWaveVector*    440   G4double e2dk3t  = -2.*e2*delta*fWaveVector*fWaveVector*fWaveVector*theta;
450                                                   441 
451                                                   442 
452   sigma  = kgamma2;                               443   sigma  = kgamma2;
453   // sigma  += dk2t2;                             444   // sigma  += dk2t2;
454   sigma *= bzero2;                                445   sigma *= bzero2;
455   sigma += mode2k2*bone2 + e2dk3t*bzero*bone;     446   sigma += mode2k2*bone2 + e2dk3t*bzero*bone;
456   sigma += kr2*bonebyarg2;                        447   sigma += kr2*bonebyarg2;
457   sigma *= damp2;          // *rad*rad;           448   sigma *= damp2;          // *rad*rad;
458                                                   449 
459   return sigma;                                   450   return sigma;
460 }                                                 451 }
461                                                   452 
462 //////////////////////////////////////////////    453 ////////////////////////////////////////////////////////////////////////////
463 //                                                454 //
464 // return differential elastic probability d(p    455 // return differential elastic probability d(probability)/d(omega) with 
465 // Coulomb correction                             456 // Coulomb correction
466                                                   457 
467 G4double                                          458 G4double 
468 G4DiffuseElastic::GetDiffElasticSumProb( // G4    459 G4DiffuseElastic::GetDiffElasticSumProb( // G4ParticleDefinition* particle, 
469                                         G4doub    460                                         G4double theta 
470           //  G4double momentum,                  461           //  G4double momentum, 
471           // G4double A                           462           // G4double A         
472                                      )            463                                      )
473 {                                                 464 {
474   G4double sigma, bzero, bzero2, bonebyarg, bo    465   G4double sigma, bzero, bzero2, bonebyarg, bonebyarg2, damp, damp2;
475   G4double delta, diffuse, gamma;                 466   G4double delta, diffuse, gamma;
476   G4double e1, e2, bone, bone2;                   467   G4double e1, e2, bone, bone2;
477                                                   468 
478   // G4double wavek = momentum/hbarc;  // wave    469   // G4double wavek = momentum/hbarc;  // wave vector
479   // G4double r0    = 1.08*fermi;                 470   // G4double r0    = 1.08*fermi;
480   // G4double rad   = r0*G4Pow::GetInstance()- << 471   // G4double rad   = r0*std::pow(A, 1./3.);
481                                                   472 
482   G4double kr    = fWaveVector*fNuclearRadius;    473   G4double kr    = fWaveVector*fNuclearRadius; // wavek*rad;
483   G4double kr2   = kr*kr;                         474   G4double kr2   = kr*kr;
484   G4double krt   = kr*theta;                      475   G4double krt   = kr*theta;
485                                                   476 
486   bzero      = BesselJzero(krt);                  477   bzero      = BesselJzero(krt);
487   bzero2     = bzero*bzero;                       478   bzero2     = bzero*bzero;    
488   bone       = BesselJone(krt);                   479   bone       = BesselJone(krt);
489   bone2      = bone*bone;                         480   bone2      = bone*bone;
490   bonebyarg  = BesselOneByArg(krt);               481   bonebyarg  = BesselOneByArg(krt);
491   bonebyarg2 = bonebyarg*bonebyarg;               482   bonebyarg2 = bonebyarg*bonebyarg;  
492                                                   483 
493   if (fParticle == theProton)                     484   if (fParticle == theProton)
494   {                                               485   {
495     diffuse = 0.63*fermi;                         486     diffuse = 0.63*fermi;
496     // diffuse = 0.6*fermi;                       487     // diffuse = 0.6*fermi;
497     gamma   = 0.3*fermi;                          488     gamma   = 0.3*fermi;
498     delta   = 0.1*fermi*fermi;                    489     delta   = 0.1*fermi*fermi;
499     e1      = 0.3*fermi;                          490     e1      = 0.3*fermi;
500     e2      = 0.35*fermi;                         491     e2      = 0.35*fermi;
501   }                                               492   }
502   else if (fParticle == theNeutron)               493   else if (fParticle == theNeutron)
503   {                                               494   {
504     diffuse = 0.63*fermi;                         495     diffuse = 0.63*fermi;
505     // diffuse = 0.6*fermi;                       496     // diffuse = 0.6*fermi;
506     G4double k0 = 1*GeV/hbarc;                    497     G4double k0 = 1*GeV/hbarc;
507     diffuse *= k0/fWaveVector;                    498     diffuse *= k0/fWaveVector;
508     gamma   = 0.3*fermi;                          499     gamma   = 0.3*fermi;
509     delta   = 0.1*fermi*fermi;                    500     delta   = 0.1*fermi*fermi;
510     e1      = 0.3*fermi;                          501     e1      = 0.3*fermi;
511     e2      = 0.35*fermi;                         502     e2      = 0.35*fermi;
512   }                                               503   }
513   else // as proton, if were not defined          504   else // as proton, if were not defined 
514   {                                               505   {
515     diffuse = 0.63*fermi;                         506     diffuse = 0.63*fermi;
516     gamma   = 0.3*fermi;                          507     gamma   = 0.3*fermi;
517     delta   = 0.1*fermi*fermi;                    508     delta   = 0.1*fermi*fermi;
518     e1      = 0.3*fermi;                          509     e1      = 0.3*fermi;
519     e2      = 0.35*fermi;                         510     e2      = 0.35*fermi;
520   }                                               511   }
521   G4double lambda = 15.; // 15 ok                 512   G4double lambda = 15.; // 15 ok
522   // G4double kgamma    = fWaveVector*gamma;      513   // G4double kgamma    = fWaveVector*gamma;   // wavek*delta;
523   G4double kgamma    = lambda*(1.-G4Exp(-fWave << 514   G4double kgamma    = lambda*(1.-std::exp(-fWaveVector*gamma/lambda));   // wavek*delta;
524                                                   515 
525   // G4cout<<"kgamma = "<<kgamma<<G4endl;         516   // G4cout<<"kgamma = "<<kgamma<<G4endl;
526                                                   517 
527   if(fAddCoulomb)  // add Coulomb correction      518   if(fAddCoulomb)  // add Coulomb correction
528   {                                               519   {
529     G4double sinHalfTheta  = std::sin(0.5*thet    520     G4double sinHalfTheta  = std::sin(0.5*theta);
530     G4double sinHalfTheta2 = sinHalfTheta*sinH    521     G4double sinHalfTheta2 = sinHalfTheta*sinHalfTheta;
531                                                   522 
532     kgamma += 0.5*fZommerfeld/kr/(sinHalfTheta    523     kgamma += 0.5*fZommerfeld/kr/(sinHalfTheta2+fAm); // correction at J0()
533   // kgamma += 0.65*fZommerfeld/kr/(sinHalfThe    524   // kgamma += 0.65*fZommerfeld/kr/(sinHalfTheta2+fAm); // correction at J0()
534   }                                               525   }
535                                                   526 
536   G4double kgamma2   = kgamma*kgamma;             527   G4double kgamma2   = kgamma*kgamma;
537                                                   528 
538   // G4double dk2t  = delta*fWaveVector*fWaveV    529   // G4double dk2t  = delta*fWaveVector*fWaveVector*theta; // delta*wavek*wavek*theta;
539   //   G4cout<<"dk2t = "<<dk2t<<G4endl;           530   //   G4cout<<"dk2t = "<<dk2t<<G4endl;
540   // G4double dk2t2 = dk2t*dk2t;                  531   // G4double dk2t2 = dk2t*dk2t;
541   // G4double pikdt = pi*fWaveVector*diffuse*t    532   // G4double pikdt = pi*fWaveVector*diffuse*theta;// pi*wavek*diffuse*theta;
542                                                   533 
543   G4double pikdt    = lambda*(1.-G4Exp(-pi*fWa << 534   G4double pikdt    = lambda*(1.-std::exp(-pi*fWaveVector*diffuse*theta/lambda));   // wavek*delta;
544                                                   535 
545   // G4cout<<"pikdt = "<<pikdt<<G4endl;           536   // G4cout<<"pikdt = "<<pikdt<<G4endl;
546                                                   537 
547   damp           = DampFactor(pikdt);             538   damp           = DampFactor(pikdt);
548   damp2          = damp*damp;                     539   damp2          = damp*damp;
549                                                   540 
550   G4double mode2k2 = (e1*e1+e2*e2)*fWaveVector    541   G4double mode2k2 = (e1*e1+e2*e2)*fWaveVector*fWaveVector;  
551   G4double e2dk3t  = -2.*e2*delta*fWaveVector*    542   G4double e2dk3t  = -2.*e2*delta*fWaveVector*fWaveVector*fWaveVector*theta;
552                                                   543 
553   sigma  = kgamma2;                               544   sigma  = kgamma2;
554   // sigma += dk2t2;                              545   // sigma += dk2t2;
555   sigma *= bzero2;                                546   sigma *= bzero2;
556   sigma += mode2k2*bone2;                         547   sigma += mode2k2*bone2; 
557   sigma += e2dk3t*bzero*bone;                     548   sigma += e2dk3t*bzero*bone;
558                                                   549 
559   // sigma += kr2*(1 + 8.*fZommerfeld*fZommerf    550   // sigma += kr2*(1 + 8.*fZommerfeld*fZommerfeld/kr2)*bonebyarg2;  // correction at J1()/()
560   sigma += kr2*bonebyarg2;  // correction at J    551   sigma += kr2*bonebyarg2;  // correction at J1()/()
561                                                   552 
562   sigma *= damp2;          // *rad*rad;           553   sigma *= damp2;          // *rad*rad;
563                                                   554 
564   return sigma;                                   555   return sigma;
565 }                                                 556 }
566                                                   557 
567                                                   558 
568 //////////////////////////////////////////////    559 ////////////////////////////////////////////////////////////////////////////
569 //                                                560 //
570 // return differential elastic probability d(p    561 // return differential elastic probability d(probability)/d(t) with 
571 // Coulomb correction. It is called from Build    562 // Coulomb correction. It is called from BuildAngleTable()
572                                                   563 
573 G4double                                          564 G4double 
574 G4DiffuseElastic::GetDiffElasticSumProbA( G4do    565 G4DiffuseElastic::GetDiffElasticSumProbA( G4double alpha )
575 {                                                 566 {
576   G4double theta;                                 567   G4double theta; 
577                                                   568 
578   theta = std::sqrt(alpha);                       569   theta = std::sqrt(alpha);
579                                                   570 
580   // theta = std::acos( 1 - alpha/2. );           571   // theta = std::acos( 1 - alpha/2. );
581                                                   572 
582   G4double sigma, bzero, bzero2, bonebyarg, bo    573   G4double sigma, bzero, bzero2, bonebyarg, bonebyarg2, damp, damp2;
583   G4double delta, diffuse, gamma;                 574   G4double delta, diffuse, gamma;
584   G4double e1, e2, bone, bone2;                   575   G4double e1, e2, bone, bone2;
585                                                   576 
586   // G4double wavek = momentum/hbarc;  // wave    577   // G4double wavek = momentum/hbarc;  // wave vector
587   // G4double r0    = 1.08*fermi;                 578   // G4double r0    = 1.08*fermi;
588   // G4double rad   = r0*G4Pow::GetInstance()- << 579   // G4double rad   = r0*std::pow(A, 1./3.);
589                                                   580 
590   G4double kr    = fWaveVector*fNuclearRadius;    581   G4double kr    = fWaveVector*fNuclearRadius; // wavek*rad;
591   G4double kr2   = kr*kr;                         582   G4double kr2   = kr*kr;
592   G4double krt   = kr*theta;                      583   G4double krt   = kr*theta;
593                                                   584 
594   bzero      = BesselJzero(krt);                  585   bzero      = BesselJzero(krt);
595   bzero2     = bzero*bzero;                       586   bzero2     = bzero*bzero;    
596   bone       = BesselJone(krt);                   587   bone       = BesselJone(krt);
597   bone2      = bone*bone;                         588   bone2      = bone*bone;
598   bonebyarg  = BesselOneByArg(krt);               589   bonebyarg  = BesselOneByArg(krt);
599   bonebyarg2 = bonebyarg*bonebyarg;               590   bonebyarg2 = bonebyarg*bonebyarg;  
600                                                   591 
601   if ( fParticle == theProton )                   592   if ( fParticle == theProton )
602   {                                               593   {
603     diffuse = 0.63*fermi;                         594     diffuse = 0.63*fermi;
604     // diffuse = 0.6*fermi;                       595     // diffuse = 0.6*fermi;
605     gamma   = 0.3*fermi;                          596     gamma   = 0.3*fermi;
606     delta   = 0.1*fermi*fermi;                    597     delta   = 0.1*fermi*fermi;
607     e1      = 0.3*fermi;                          598     e1      = 0.3*fermi;
608     e2      = 0.35*fermi;                         599     e2      = 0.35*fermi;
609   }                                               600   }
610   else if ( fParticle == theNeutron )             601   else if ( fParticle == theNeutron )
611   {                                               602   {
612     diffuse = 0.63*fermi;                         603     diffuse = 0.63*fermi;
613     // diffuse = 0.6*fermi;                       604     // diffuse = 0.6*fermi;
614     // G4double k0 = 0.8*GeV/hbarc;               605     // G4double k0 = 0.8*GeV/hbarc;
615     // diffuse *= k0/fWaveVector;                 606     // diffuse *= k0/fWaveVector;
616     gamma   = 0.3*fermi;                          607     gamma   = 0.3*fermi;
617     delta   = 0.1*fermi*fermi;                    608     delta   = 0.1*fermi*fermi;
618     e1      = 0.3*fermi;                          609     e1      = 0.3*fermi;
619     e2      = 0.35*fermi;                         610     e2      = 0.35*fermi;
620   }                                               611   }
621   else // as proton, if were not defined          612   else // as proton, if were not defined 
622   {                                               613   {
623     diffuse = 0.63*fermi;                         614     diffuse = 0.63*fermi;
624     gamma   = 0.3*fermi;                          615     gamma   = 0.3*fermi;
625     delta   = 0.1*fermi*fermi;                    616     delta   = 0.1*fermi*fermi;
626     e1      = 0.3*fermi;                          617     e1      = 0.3*fermi;
627     e2      = 0.35*fermi;                         618     e2      = 0.35*fermi;
628   }                                               619   }
629   G4double lambda = 15.; // 15 ok                 620   G4double lambda = 15.; // 15 ok
630   // G4double kgamma    = fWaveVector*gamma;      621   // G4double kgamma    = fWaveVector*gamma;   // wavek*delta;
631   G4double kgamma    = lambda*(1.-G4Exp(-fWave << 622   G4double kgamma    = lambda*(1.-std::exp(-fWaveVector*gamma/lambda));   // wavek*delta;
632                                                   623 
633   // G4cout<<"kgamma = "<<kgamma<<G4endl;         624   // G4cout<<"kgamma = "<<kgamma<<G4endl;
634                                                   625 
635   if( fAddCoulomb )  // add Coulomb correction    626   if( fAddCoulomb )  // add Coulomb correction
636   {                                               627   {
637     G4double sinHalfTheta  = theta*0.5; // std    628     G4double sinHalfTheta  = theta*0.5; // std::sin(0.5*theta);
638     G4double sinHalfTheta2 = sinHalfTheta*sinH    629     G4double sinHalfTheta2 = sinHalfTheta*sinHalfTheta;
639                                                   630 
640     kgamma += 0.5*fZommerfeld/kr/(sinHalfTheta    631     kgamma += 0.5*fZommerfeld/kr/(sinHalfTheta2+fAm); // correction at J0()
641   // kgamma += 0.65*fZommerfeld/kr/(sinHalfThe    632   // kgamma += 0.65*fZommerfeld/kr/(sinHalfTheta2+fAm); // correction at J0()
642   }                                               633   }
643   G4double kgamma2   = kgamma*kgamma;             634   G4double kgamma2   = kgamma*kgamma;
644                                                   635 
645   // G4double dk2t  = delta*fWaveVector*fWaveV    636   // G4double dk2t  = delta*fWaveVector*fWaveVector*theta; // delta*wavek*wavek*theta;
646   //   G4cout<<"dk2t = "<<dk2t<<G4endl;           637   //   G4cout<<"dk2t = "<<dk2t<<G4endl;
647   // G4double dk2t2 = dk2t*dk2t;                  638   // G4double dk2t2 = dk2t*dk2t;
648   // G4double pikdt = pi*fWaveVector*diffuse*t    639   // G4double pikdt = pi*fWaveVector*diffuse*theta;// pi*wavek*diffuse*theta;
649                                                   640 
650   G4double pikdt    = lambda*(1. - G4Exp( -pi* << 641   G4double pikdt    = lambda*(1. - std::exp( -pi*fWaveVector*diffuse*theta/lambda ) );   // wavek*delta;
651                                                   642 
652   // G4cout<<"pikdt = "<<pikdt<<G4endl;           643   // G4cout<<"pikdt = "<<pikdt<<G4endl;
653                                                   644 
654   damp           = DampFactor( pikdt );           645   damp           = DampFactor( pikdt );
655   damp2          = damp*damp;                     646   damp2          = damp*damp;
656                                                   647 
657   G4double mode2k2 = ( e1*e1 + e2*e2 )*fWaveVe    648   G4double mode2k2 = ( e1*e1 + e2*e2 )*fWaveVector*fWaveVector;  
658   G4double e2dk3t  = -2.*e2*delta*fWaveVector*    649   G4double e2dk3t  = -2.*e2*delta*fWaveVector*fWaveVector*fWaveVector*theta;
659                                                   650 
660   sigma  = kgamma2;                               651   sigma  = kgamma2;
661   // sigma += dk2t2;                              652   // sigma += dk2t2;
662   sigma *= bzero2;                                653   sigma *= bzero2;
663   sigma += mode2k2*bone2;                         654   sigma += mode2k2*bone2; 
664   sigma += e2dk3t*bzero*bone;                     655   sigma += e2dk3t*bzero*bone;
665                                                   656 
666   // sigma += kr2*(1 + 8.*fZommerfeld*fZommerf    657   // sigma += kr2*(1 + 8.*fZommerfeld*fZommerfeld/kr2)*bonebyarg2;  // correction at J1()/()
667   sigma += kr2*bonebyarg2;  // correction at J    658   sigma += kr2*bonebyarg2;  // correction at J1()/()
668                                                   659 
669   sigma *= damp2;          // *rad*rad;           660   sigma *= damp2;          // *rad*rad;
670                                                   661 
671   return sigma;                                   662   return sigma;
672 }                                                 663 }
673                                                   664 
674                                                   665 
675 //////////////////////////////////////////////    666 ////////////////////////////////////////////////////////////////////////////
676 //                                                667 //
677 // return differential elastic probability 2*p    668 // return differential elastic probability 2*pi*sin(theta)*d(probability)/d(omega) 
678                                                   669 
679 G4double                                          670 G4double 
680 G4DiffuseElastic::GetIntegrandFunction( G4doub    671 G4DiffuseElastic::GetIntegrandFunction( G4double alpha )
681 {                                                 672 {
682   G4double result;                                673   G4double result;
683                                                   674 
684   result  = GetDiffElasticSumProbA(alpha);        675   result  = GetDiffElasticSumProbA(alpha);
685                                                   676 
686   // result *= 2*pi*std::sin(theta);              677   // result *= 2*pi*std::sin(theta);
687                                                   678 
688   return result;                                  679   return result;
689 }                                                 680 }
690                                                   681 
691 //////////////////////////////////////////////    682 ////////////////////////////////////////////////////////////////////////////
692 //                                                683 //
693 // return integral elastic cross section d(sig    684 // return integral elastic cross section d(sigma)/d(omega) integrated 0 - theta 
694                                                   685 
695 G4double                                          686 G4double 
696 G4DiffuseElastic::IntegralElasticProb(  const     687 G4DiffuseElastic::IntegralElasticProb(  const G4ParticleDefinition* particle, 
697                                         G4doub    688                                         G4double theta, 
698                       G4double momentum,          689                       G4double momentum, 
699                                         G4doub    690                                         G4double A         )
700 {                                                 691 {
701   G4double result;                                692   G4double result;
702   fParticle      = particle;                      693   fParticle      = particle;
703   fWaveVector    = momentum/hbarc;                694   fWaveVector    = momentum/hbarc;
704   fAtomicWeight  = A;                             695   fAtomicWeight  = A;
705                                                   696 
706   fNuclearRadius = CalculateNuclearRad(A);        697   fNuclearRadius = CalculateNuclearRad(A);
707                                                   698 
708                                                   699 
709   G4Integrator<G4DiffuseElastic,G4double(G4Dif    700   G4Integrator<G4DiffuseElastic,G4double(G4DiffuseElastic::*)(G4double)> integral;
710                                                   701 
711   // result = integral.Legendre10(this,&G4Diff    702   // result = integral.Legendre10(this,&G4DiffuseElastic::GetIntegrandFunction, 0., theta ); 
712   result = integral.Legendre96(this,&G4Diffuse    703   result = integral.Legendre96(this,&G4DiffuseElastic::GetIntegrandFunction, 0., theta ); 
713                                                   704 
714   return result;                                  705   return result;
715 }                                                 706 }
716                                                   707 
717 //////////////////////////////////////////////    708 ////////////////////////////////////////////////////////////////////////////
718 //                                                709 //
719 // Return inv momentum transfer -t > 0            710 // Return inv momentum transfer -t > 0
720                                                   711 
721 G4double G4DiffuseElastic::SampleT( const G4Pa    712 G4double G4DiffuseElastic::SampleT( const G4ParticleDefinition* aParticle, G4double p, G4double A)
722 {                                                 713 {
723   G4double theta = SampleThetaCMS( aParticle,     714   G4double theta = SampleThetaCMS( aParticle,  p, A); // sample theta in cms
724   G4double t     = 2*p*p*( 1 - std::cos(theta)    715   G4double t     = 2*p*p*( 1 - std::cos(theta) ); // -t !!!
725   return t;                                       716   return t;
726 }                                                 717 }
727                                                   718 
728 //////////////////////////////////////////////    719 ////////////////////////////////////////////////////////////////////////////
729 //                                                720 //
730 // Return scattering angle sampled in cms         721 // Return scattering angle sampled in cms
731                                                   722 
732                                                   723 
733 G4double                                          724 G4double 
734 G4DiffuseElastic::SampleThetaCMS(const G4Parti    725 G4DiffuseElastic::SampleThetaCMS(const G4ParticleDefinition* particle, 
735                                        G4doubl    726                                        G4double momentum, G4double A)
736 {                                                 727 {
737   G4int i, iMax = 100;                            728   G4int i, iMax = 100;  
738   G4double norm, theta1, theta2, thetaMax;     << 729   G4double norm, result, theta1, theta2, thetaMax, sum = 0.;
739   G4double result = 0., sum = 0.;              << 
740                                                   730 
741   fParticle      = particle;                      731   fParticle      = particle;
742   fWaveVector    = momentum/hbarc;                732   fWaveVector    = momentum/hbarc;
743   fAtomicWeight  = A;                             733   fAtomicWeight  = A;
744                                                   734 
745   fNuclearRadius = CalculateNuclearRad(A);        735   fNuclearRadius = CalculateNuclearRad(A);
746                                                   736   
747   thetaMax = 10.174/fWaveVector/fNuclearRadius    737   thetaMax = 10.174/fWaveVector/fNuclearRadius;
748                                                   738 
749   if (thetaMax > pi) thetaMax = pi;               739   if (thetaMax > pi) thetaMax = pi;
750                                                   740 
751   G4Integrator<G4DiffuseElastic,G4double(G4Dif    741   G4Integrator<G4DiffuseElastic,G4double(G4DiffuseElastic::*)(G4double)> integral;
752                                                   742 
753   // result = integral.Legendre10(this,&G4Diff    743   // result = integral.Legendre10(this,&G4DiffuseElastic::GetIntegrandFunction, 0., theta ); 
754   norm = integral.Legendre96(this,&G4DiffuseEl    744   norm = integral.Legendre96(this,&G4DiffuseElastic::GetIntegrandFunction, 0., thetaMax );
755                                                   745 
756   norm *= G4UniformRand();                        746   norm *= G4UniformRand();
757                                                   747 
758   for(i = 1; i <= iMax; i++)                      748   for(i = 1; i <= iMax; i++)
759   {                                               749   {
760     theta1 = (i-1)*thetaMax/iMax;                 750     theta1 = (i-1)*thetaMax/iMax; 
761     theta2 = i*thetaMax/iMax;                     751     theta2 = i*thetaMax/iMax;
762     sum   += integral.Legendre10(this,&G4Diffu    752     sum   += integral.Legendre10(this,&G4DiffuseElastic::GetIntegrandFunction, theta1, theta2);
763                                                   753 
764     if ( sum >= norm )                            754     if ( sum >= norm ) 
765     {                                             755     {
766       result = 0.5*(theta1 + theta2);             756       result = 0.5*(theta1 + theta2);
767       break;                                      757       break;
768     }                                             758     }
769   }                                               759   }
770   if (i > iMax ) result = 0.5*(theta1 + theta2    760   if (i > iMax ) result = 0.5*(theta1 + theta2);
771                                                   761 
772   G4double sigma = pi*thetaMax/iMax;              762   G4double sigma = pi*thetaMax/iMax;
773                                                   763 
774   result += G4RandGauss::shoot(0.,sigma);         764   result += G4RandGauss::shoot(0.,sigma);
775                                                   765 
776   if(result < 0.) result = 0.;                    766   if(result < 0.) result = 0.;
777   if(result > thetaMax) result = thetaMax;        767   if(result > thetaMax) result = thetaMax;
778                                                   768 
779   return result;                                  769   return result;
780 }                                                 770 }
781                                                   771 
782 //////////////////////////////////////////////    772 /////////////////////////////////////////////////////////////////////////////
783 /////////////////////  Table preparation and r    773 /////////////////////  Table preparation and reading ////////////////////////
784 //////////////////////////////////////////////    774 ////////////////////////////////////////////////////////////////////////////
785 //                                                775 //
786 // Return inv momentum transfer -t > 0 from in    776 // Return inv momentum transfer -t > 0 from initialisation table
787                                                   777 
788 G4double G4DiffuseElastic::SampleInvariantT( c    778 G4double G4DiffuseElastic::SampleInvariantT( const G4ParticleDefinition* aParticle, G4double p, 
789                                                   779                                                G4int Z, G4int A)
790 {                                                 780 {
791   fParticle = aParticle;                          781   fParticle = aParticle;
792   G4double m1 = fParticle->GetPDGMass(), t;       782   G4double m1 = fParticle->GetPDGMass(), t;
793   G4double totElab = std::sqrt(m1*m1+p*p);        783   G4double totElab = std::sqrt(m1*m1+p*p);
794   G4double mass2 = G4NucleiProperties::GetNucl    784   G4double mass2 = G4NucleiProperties::GetNuclearMass(A, Z);
795   G4LorentzVector lv1(p,0.0,0.0,totElab);         785   G4LorentzVector lv1(p,0.0,0.0,totElab);
796   G4LorentzVector  lv(0.0,0.0,0.0,mass2);         786   G4LorentzVector  lv(0.0,0.0,0.0,mass2);   
797   lv += lv1;                                      787   lv += lv1;
798                                                   788 
799   G4ThreeVector bst = lv.boostVector();           789   G4ThreeVector bst = lv.boostVector();
800   lv1.boost(-bst);                                790   lv1.boost(-bst);
801                                                   791 
802   G4ThreeVector p1 = lv1.vect();                  792   G4ThreeVector p1 = lv1.vect();
803   G4double momentumCMS = p1.mag();                793   G4double momentumCMS = p1.mag();
804                                                   794   
805   if( aParticle == theNeutron)                    795   if( aParticle == theNeutron)
806   {                                               796   {
807     G4double Tmax = NeutronTuniform( Z );         797     G4double Tmax = NeutronTuniform( Z );
808     G4double pCMS2 = momentumCMS*momentumCMS;     798     G4double pCMS2 = momentumCMS*momentumCMS;
809     G4double Tkin = std::sqrt(pCMS2+m1*m1)-m1;    799     G4double Tkin = std::sqrt(pCMS2+m1*m1)-m1;
810                                                   800 
811     if( Tkin <= Tmax )                            801     if( Tkin <= Tmax )
812     {                                             802     {
813       t = 4.*pCMS2*G4UniformRand();               803       t = 4.*pCMS2*G4UniformRand();
814       // G4cout<<Tkin<<", "<<Tmax<<", "<<std::    804       // G4cout<<Tkin<<", "<<Tmax<<", "<<std::sqrt(t)<<";   ";
815       return t;                                   805       return t;
816     }                                             806     }
817   }                                               807   }
818                                                   808   
819   t = SampleTableT( aParticle,  momentumCMS, G    809   t = SampleTableT( aParticle,  momentumCMS, G4double(Z), G4double(A) ); // sample theta2 in cms
820                                                   810 
821   return t;                                       811   return t;
822 }                                                 812 }
823                                                   813 
824 //////////////////////////////////////////////    814 ///////////////////////////////////////////////////////
825                                                   815 
826 G4double G4DiffuseElastic::NeutronTuniform(G4i    816 G4double G4DiffuseElastic::NeutronTuniform(G4int Z)
827 {                                                 817 {
828   G4double elZ  = G4double(Z);                    818   G4double elZ  = G4double(Z);
829   elZ -= 1.;                                      819   elZ -= 1.;
830   // G4double Tkin = 20.*G4Exp(-elZ/10.) + 1.; << 820   // G4double Tkin = 20.*std::exp(-elZ/10.) + 1.;
831   G4double Tkin = 12.*G4Exp(-elZ/10.) + 1.;    << 821   G4double Tkin = 12.*std::exp(-elZ/10.) + 1.;
832   return Tkin;                                    822   return Tkin;
833 }                                                 823 }
834                                                   824 
835                                                   825 
836 //////////////////////////////////////////////    826 ////////////////////////////////////////////////////////////////////////////
837 //                                                827 //
838 // Return inv momentum transfer -t > 0 from in    828 // Return inv momentum transfer -t > 0 from initialisation table
839                                                   829 
840 G4double G4DiffuseElastic::SampleTableT( const    830 G4double G4DiffuseElastic::SampleTableT( const G4ParticleDefinition* aParticle, G4double p, 
841                                                   831                                                G4double Z, G4double A)
842 {                                                 832 {
843   G4double alpha = SampleTableThetaCMS( aParti    833   G4double alpha = SampleTableThetaCMS( aParticle,  p, Z, A); // sample theta2 in cms
844   G4double t     = 2*p*p*( 1 - std::cos(std::s    834   G4double t     = 2*p*p*( 1 - std::cos(std::sqrt(alpha)) );             // -t !!!
845   // G4double t     = p*p*alpha;             /    835   // G4double t     = p*p*alpha;             // -t !!!
846   return t;                                       836   return t;
847 }                                                 837 }
848                                                   838 
849 //////////////////////////////////////////////    839 ////////////////////////////////////////////////////////////////////////////
850 //                                                840 //
851 // Return scattering angle2 sampled in cms acc    841 // Return scattering angle2 sampled in cms according to precalculated table.
852                                                   842 
853                                                   843 
854 G4double                                          844 G4double 
855 G4DiffuseElastic::SampleTableThetaCMS(const G4    845 G4DiffuseElastic::SampleTableThetaCMS(const G4ParticleDefinition* particle, 
856                                        G4doubl    846                                        G4double momentum, G4double Z, G4double A)
857 {                                                 847 {
858   std::size_t iElement;                        << 848   size_t iElement;
859   G4int iMomentum, iAngle;                        849   G4int iMomentum, iAngle;  
860   G4double randAngle, position, theta1, theta2    850   G4double randAngle, position, theta1, theta2, E1, E2, W1, W2, W;  
861   G4double m1 = particle->GetPDGMass();           851   G4double m1 = particle->GetPDGMass();
862                                                   852 
863   for(iElement = 0; iElement < fElementNumberV    853   for(iElement = 0; iElement < fElementNumberVector.size(); iElement++)
864   {                                               854   {
865     if( std::fabs(Z - fElementNumberVector[iEl    855     if( std::fabs(Z - fElementNumberVector[iElement]) < 0.5) break;
866   }                                               856   }
867   if ( iElement == fElementNumberVector.size()    857   if ( iElement == fElementNumberVector.size() ) 
868   {                                               858   {
869     InitialiseOnFly(Z,A); // table preparation    859     InitialiseOnFly(Z,A); // table preparation, if needed
870                                                   860 
871     // iElement--;                                861     // iElement--;
872                                                   862 
873     // G4cout << "G4DiffuseElastic: Element wi    863     // G4cout << "G4DiffuseElastic: Element with atomic number " << Z
874     // << " is not found, return zero angle" <    864     // << " is not found, return zero angle" << G4endl;
875     // return 0.; // no table for this element    865     // return 0.; // no table for this element
876   }                                               866   }
877   // G4cout<<"iElement = "<<iElement<<G4endl;     867   // G4cout<<"iElement = "<<iElement<<G4endl;
878                                                   868 
879   fAngleTable = fAngleBank[iElement];             869   fAngleTable = fAngleBank[iElement];
880                                                   870 
881   G4double kinE = std::sqrt(momentum*momentum     871   G4double kinE = std::sqrt(momentum*momentum + m1*m1) - m1;
882                                                   872 
883   for( iMomentum = 0; iMomentum < fEnergyBin;     873   for( iMomentum = 0; iMomentum < fEnergyBin; iMomentum++)
884   {                                               874   {
885     if( kinE < fEnergyVector->GetLowEdgeEnergy    875     if( kinE < fEnergyVector->GetLowEdgeEnergy(iMomentum) ) break;
886   }                                               876   }
887   if ( iMomentum >= fEnergyBin ) iMomentum = f    877   if ( iMomentum >= fEnergyBin ) iMomentum = fEnergyBin-1;   // kinE is more then theMaxEnergy
888   if ( iMomentum < 0 )           iMomentum = 0    878   if ( iMomentum < 0 )           iMomentum = 0; // against negative index, kinE < theMinEnergy
889                                                   879 
890   // G4cout<<"iMomentum = "<<iMomentum<<G4endl    880   // G4cout<<"iMomentum = "<<iMomentum<<G4endl;
891                                                   881 
892   if (iMomentum == fEnergyBin -1 || iMomentum     882   if (iMomentum == fEnergyBin -1 || iMomentum == 0 )   // the table edges
893   {                                               883   {
894     position = (*(*fAngleTable)(iMomentum))(fA    884     position = (*(*fAngleTable)(iMomentum))(fAngleBin-2)*G4UniformRand();
895                                                   885 
896     // G4cout<<"position = "<<position<<G4endl    886     // G4cout<<"position = "<<position<<G4endl;
897                                                   887 
898     for(iAngle = 0; iAngle < fAngleBin-1; iAng    888     for(iAngle = 0; iAngle < fAngleBin-1; iAngle++)
899     {                                             889     {
900       if( position > (*(*fAngleTable)(iMomentu    890       if( position > (*(*fAngleTable)(iMomentum))(iAngle) ) break;
901     }                                             891     }
902     if (iAngle >= fAngleBin-1) iAngle = fAngle    892     if (iAngle >= fAngleBin-1) iAngle = fAngleBin-2;
903                                                   893 
904     // G4cout<<"iAngle = "<<iAngle<<G4endl;       894     // G4cout<<"iAngle = "<<iAngle<<G4endl;
905                                                   895 
906     randAngle = GetScatteringAngle(iMomentum,     896     randAngle = GetScatteringAngle(iMomentum, iAngle, position);
907                                                   897 
908     // G4cout<<"randAngle = "<<randAngle<<G4en    898     // G4cout<<"randAngle = "<<randAngle<<G4endl;
909   }                                               899   }
910   else  // kinE inside between energy table ed    900   else  // kinE inside between energy table edges
911   {                                               901   {
912     // position = (*(*fAngleTable)(iMomentum))    902     // position = (*(*fAngleTable)(iMomentum))(fAngleBin-2)*G4UniformRand();
913     position = (*(*fAngleTable)(iMomentum))(0)    903     position = (*(*fAngleTable)(iMomentum))(0)*G4UniformRand();
914                                                   904 
915     // G4cout<<"position = "<<position<<G4endl    905     // G4cout<<"position = "<<position<<G4endl;
916                                                   906 
917     for(iAngle = 0; iAngle < fAngleBin-1; iAng    907     for(iAngle = 0; iAngle < fAngleBin-1; iAngle++)
918     {                                             908     {
919       // if( position < (*(*fAngleTable)(iMome    909       // if( position < (*(*fAngleTable)(iMomentum))(iAngle) ) break;
920       if( position > (*(*fAngleTable)(iMomentu    910       if( position > (*(*fAngleTable)(iMomentum))(iAngle) ) break;
921     }                                             911     }
922     if (iAngle >= fAngleBin-1) iAngle = fAngle    912     if (iAngle >= fAngleBin-1) iAngle = fAngleBin-2;
923                                                   913 
924     // G4cout<<"iAngle = "<<iAngle<<G4endl;       914     // G4cout<<"iAngle = "<<iAngle<<G4endl;
925                                                   915 
926     theta2  = GetScatteringAngle(iMomentum, iA    916     theta2  = GetScatteringAngle(iMomentum, iAngle, position);
927                                                   917 
928     // G4cout<<"theta2 = "<<theta2<<G4endl;       918     // G4cout<<"theta2 = "<<theta2<<G4endl;
929     E2 = fEnergyVector->GetLowEdgeEnergy(iMome    919     E2 = fEnergyVector->GetLowEdgeEnergy(iMomentum);
930                                                   920 
931     // G4cout<<"E2 = "<<E2<<G4endl;               921     // G4cout<<"E2 = "<<E2<<G4endl;
932                                                   922     
933     iMomentum--;                                  923     iMomentum--;
934                                                   924     
935     // position = (*(*fAngleTable)(iMomentum))    925     // position = (*(*fAngleTable)(iMomentum))(fAngleBin-2)*G4UniformRand();
936                                                   926 
937     // G4cout<<"position = "<<position<<G4endl    927     // G4cout<<"position = "<<position<<G4endl;
938                                                   928 
939     for(iAngle = 0; iAngle < fAngleBin-1; iAng    929     for(iAngle = 0; iAngle < fAngleBin-1; iAngle++)
940     {                                             930     {
941       // if( position < (*(*fAngleTable)(iMome    931       // if( position < (*(*fAngleTable)(iMomentum))(iAngle) ) break;
942       if( position > (*(*fAngleTable)(iMomentu    932       if( position > (*(*fAngleTable)(iMomentum))(iAngle) ) break;
943     }                                             933     }
944     if (iAngle >= fAngleBin-1) iAngle = fAngle    934     if (iAngle >= fAngleBin-1) iAngle = fAngleBin-2;
945                                                   935     
946     theta1  = GetScatteringAngle(iMomentum, iA    936     theta1  = GetScatteringAngle(iMomentum, iAngle, position);
947                                                   937 
948     // G4cout<<"theta1 = "<<theta1<<G4endl;       938     // G4cout<<"theta1 = "<<theta1<<G4endl;
949                                                   939 
950     E1 = fEnergyVector->GetLowEdgeEnergy(iMome    940     E1 = fEnergyVector->GetLowEdgeEnergy(iMomentum);
951                                                   941 
952     // G4cout<<"E1 = "<<E1<<G4endl;               942     // G4cout<<"E1 = "<<E1<<G4endl;
953                                                   943 
954     W  = 1.0/(E2 - E1);                           944     W  = 1.0/(E2 - E1);
955     W1 = (E2 - kinE)*W;                           945     W1 = (E2 - kinE)*W;
956     W2 = (kinE - E1)*W;                           946     W2 = (kinE - E1)*W;
957                                                   947 
958     randAngle = W1*theta1 + W2*theta2;            948     randAngle = W1*theta1 + W2*theta2;
959                                                   949     
960     // randAngle = theta2;                        950     // randAngle = theta2;
961     // G4cout<<"randAngle = "<<randAngle<<G4en    951     // G4cout<<"randAngle = "<<randAngle<<G4endl;
962   }                                               952   }
963   // G4double angle = randAngle;                  953   // G4double angle = randAngle;
964   // if (randAngle > 0.) randAngle /= 2*pi*std    954   // if (randAngle > 0.) randAngle /= 2*pi*std::sin(angle);
965                                                   955 
966   if(randAngle < 0.) randAngle = 0.;              956   if(randAngle < 0.) randAngle = 0.;
967                                                   957 
968   return randAngle;                               958   return randAngle;
969 }                                                 959 }
970                                                   960 
971 //////////////////////////////////////////////    961 //////////////////////////////////////////////////////////////////////////////
972 //                                                962 //
973 // Initialisation for given particle on fly us    963 // Initialisation for given particle on fly using new element number
974                                                   964 
975 void G4DiffuseElastic::InitialiseOnFly(G4doubl    965 void G4DiffuseElastic::InitialiseOnFly(G4double Z, G4double A) 
976 {                                                 966 {
977   fAtomicNumber  = Z;     // atomic number        967   fAtomicNumber  = Z;     // atomic number
978   fAtomicWeight  = G4NistManager::Instance()->    968   fAtomicWeight  = G4NistManager::Instance()->GetAtomicMassAmu( static_cast< G4int >( Z ) );
979                                                   969 
980   fNuclearRadius = CalculateNuclearRad(fAtomic    970   fNuclearRadius = CalculateNuclearRad(fAtomicWeight);
981                                                   971 
982   if( verboseLevel > 0 )                          972   if( verboseLevel > 0 )    
983   {                                               973   {
984     G4cout<<"G4DiffuseElastic::InitialiseOnFly    974     G4cout<<"G4DiffuseElastic::InitialiseOnFly() the element with Z = "
985     <<Z<<"; and A = "<<A<<G4endl;                 975     <<Z<<"; and A = "<<A<<G4endl;
986   }                                               976   }
987   fElementNumberVector.push_back(fAtomicNumber    977   fElementNumberVector.push_back(fAtomicNumber);
988                                                   978 
989   BuildAngleTable();                              979   BuildAngleTable();
990                                                   980 
991   fAngleBank.push_back(fAngleTable);              981   fAngleBank.push_back(fAngleTable);
992                                                   982 
993   return;                                         983   return;
994 }                                                 984 }
995                                                   985 
996 //////////////////////////////////////////////    986 ///////////////////////////////////////////////////////////////////////////////
997 //                                                987 //
998 // Build for given particle and element table     988 // Build for given particle and element table of momentum, angle probability.
999 // For the moment in lab system.                  989 // For the moment in lab system. 
1000                                                  990 
1001 void G4DiffuseElastic::BuildAngleTable()         991 void G4DiffuseElastic::BuildAngleTable() 
1002 {                                                992 {
1003   G4int i, j;                                    993   G4int i, j;
1004   G4double partMom, kinE, a = 0., z = fPartic    994   G4double partMom, kinE, a = 0., z = fParticle->GetPDGCharge(), m1 = fParticle->GetPDGMass();
1005   G4double alpha1, alpha2, alphaMax, alphaCou    995   G4double alpha1, alpha2, alphaMax, alphaCoulomb, delta = 0., sum = 0.;
1006                                                  996 
1007   G4Integrator<G4DiffuseElastic,G4double(G4Di    997   G4Integrator<G4DiffuseElastic,G4double(G4DiffuseElastic::*)(G4double)> integral;
1008                                                  998   
1009   fAngleTable = new G4PhysicsTable( fEnergyBi << 999   fAngleTable = new G4PhysicsTable(fEnergyBin);
1010                                                  1000 
1011   for( i = 0; i < fEnergyBin; i++)               1001   for( i = 0; i < fEnergyBin; i++)
1012   {                                              1002   {
1013     kinE        = fEnergyVector->GetLowEdgeEn    1003     kinE        = fEnergyVector->GetLowEdgeEnergy(i);
1014     partMom     = std::sqrt( kinE*(kinE + 2*m    1004     partMom     = std::sqrt( kinE*(kinE + 2*m1) );
1015                                                  1005 
1016     fWaveVector = partMom/hbarc;                 1006     fWaveVector = partMom/hbarc;
1017                                                  1007 
1018     G4double kR     = fWaveVector*fNuclearRad    1008     G4double kR     = fWaveVector*fNuclearRadius;
1019     G4double kR2    = kR*kR;                     1009     G4double kR2    = kR*kR;
1020     G4double kRmax  = 18.6; // 10.6; 10.6, 18    1010     G4double kRmax  = 18.6; // 10.6; 10.6, 18, 10.174; ~ 3 maxima of J1 or 15., 25.
1021     G4double kRcoul = 1.9; // 1.2; 1.4, 2.5;     1011     G4double kRcoul = 1.9; // 1.2; 1.4, 2.5; // on the first slope of J1
1022     // G4double kRlim  = 1.2;                    1012     // G4double kRlim  = 1.2;
1023     // G4double kRlim2 = kRlim*kRlim/kR2;        1013     // G4double kRlim2 = kRlim*kRlim/kR2;
1024                                                  1014 
1025     alphaMax = kRmax*kRmax/kR2;                  1015     alphaMax = kRmax*kRmax/kR2;
1026                                                  1016 
1027                                                  1017 
1028     // if (alphaMax > 4.) alphaMax = 4.;  //     1018     // if (alphaMax > 4.) alphaMax = 4.;  // vmg05-02-09: was pi2 
1029     // if ( alphaMax > 4. || alphaMax < 1. )  << 1019     // if ( alphaMax > 4. || alphaMax < 1. ) alphaMax = 15.;  // vmg27.11.14  
1030                                               << 1020     if ( alphaMax > 4. || alphaMax < 1. ) alphaMax = CLHEP::pi*CLHEP::pi;  // vmg06.01.15  
1031     // if ( alphaMax > 4. || alphaMax < 1. )  << 1021     // if (alphaMax > 4. || alphaMax < 1. ) alphaMax = 4.;  // vmg07.01.15: was pi2 
1032                                               << 
1033     // G4cout<<"alphaMax = "<<alphaMax<<", ";    1022     // G4cout<<"alphaMax = "<<alphaMax<<", ";
1034                                                  1023 
1035     if ( alphaMax >= CLHEP::pi*CLHEP::pi ) al << 
1036                                               << 
1037     alphaCoulomb = kRcoul*kRcoul/kR2;            1024     alphaCoulomb = kRcoul*kRcoul/kR2;
1038                                                  1025 
1039     if( z )                                      1026     if( z )
1040     {                                            1027     {
1041       a           = partMom/m1;         // be    1028       a           = partMom/m1;         // beta*gamma for m1
1042       fBeta       = a/std::sqrt(1+a*a);          1029       fBeta       = a/std::sqrt(1+a*a);
1043       fZommerfeld = CalculateZommerfeld( fBet    1030       fZommerfeld = CalculateZommerfeld( fBeta, z, fAtomicNumber);
1044       fAm         = CalculateAm( partMom, fZo    1031       fAm         = CalculateAm( partMom, fZommerfeld, fAtomicNumber);
1045     }                                            1032     }
1046     G4PhysicsFreeVector* angleVector = new G4    1033     G4PhysicsFreeVector* angleVector = new G4PhysicsFreeVector(fAngleBin-1);
1047                                                  1034 
1048     // G4PhysicsLogVector*  angleBins = new G    1035     // G4PhysicsLogVector*  angleBins = new G4PhysicsLogVector( 0.001*alphaMax, alphaMax, fAngleBin );
1049                                                  1036 
1050     G4double delth = alphaMax/fAngleBin;         1037     G4double delth = alphaMax/fAngleBin;
1051                                                  1038         
1052     sum = 0.;                                    1039     sum = 0.;
1053                                                  1040 
1054     // fAddCoulomb = false;                      1041     // fAddCoulomb = false;
1055     fAddCoulomb = true;                          1042     fAddCoulomb = true;
1056                                                  1043 
1057     // for(j = 1; j < fAngleBin; j++)            1044     // for(j = 1; j < fAngleBin; j++)
1058     for(j = fAngleBin-1; j >= 1; j--)            1045     for(j = fAngleBin-1; j >= 1; j--)
1059     {                                            1046     {
1060       // alpha1 = angleBins->GetLowEdgeEnergy    1047       // alpha1 = angleBins->GetLowEdgeEnergy(j-1);
1061       // alpha2 = angleBins->GetLowEdgeEnergy    1048       // alpha2 = angleBins->GetLowEdgeEnergy(j);
1062                                                  1049 
1063       // alpha1 = alphaMax*(j-1)/fAngleBin;      1050       // alpha1 = alphaMax*(j-1)/fAngleBin;
1064       // alpha2 = alphaMax*( j )/fAngleBin;      1051       // alpha2 = alphaMax*( j )/fAngleBin;
1065                                                  1052 
1066       alpha1 = delth*(j-1);                      1053       alpha1 = delth*(j-1);
1067       // if(alpha1 < kRlim2) alpha1 = kRlim2;    1054       // if(alpha1 < kRlim2) alpha1 = kRlim2;
1068       alpha2 = alpha1 + delth;                   1055       alpha2 = alpha1 + delth;
1069                                                  1056 
1070       // if( ( alpha2 > alphaCoulomb ) && z )    1057       // if( ( alpha2 > alphaCoulomb ) && z ) fAddCoulomb = true;
1071       if( ( alpha1 < alphaCoulomb ) && z ) fA    1058       if( ( alpha1 < alphaCoulomb ) && z ) fAddCoulomb = false;
1072                                                  1059 
1073       delta = integral.Legendre10(this, &G4Di    1060       delta = integral.Legendre10(this, &G4DiffuseElastic::GetIntegrandFunction, alpha1, alpha2);
1074       // delta = integral.Legendre96(this, &G    1061       // delta = integral.Legendre96(this, &G4DiffuseElastic::GetIntegrandFunction, alpha1, alpha2);
1075                                                  1062 
1076       sum += delta;                              1063       sum += delta;
1077                                                  1064       
1078       angleVector->PutValue( j-1 , alpha1, su    1065       angleVector->PutValue( j-1 , alpha1, sum ); // alpha2
1079       //      G4cout<<"j-1 = "<<j-1<<"; alpha << 1066       // G4cout<<"j-1 = "<<j-1<<"; alpha2 = "<<alpha2<<"; sum = "<<sum<<G4endl;
1080     }                                            1067     }
1081     fAngleTable->insertAt(i, angleVector);    << 1068     fAngleTable->insertAt(i,angleVector);
1082                                                  1069 
1083     // delete[] angleVector;                     1070     // delete[] angleVector; 
1084     // delete[] angleBins;                       1071     // delete[] angleBins; 
1085   }                                              1072   }
1086   return;                                        1073   return;
1087 }                                                1074 }
1088                                                  1075 
1089 /////////////////////////////////////////////    1076 /////////////////////////////////////////////////////////////////////////////////
1090 //                                               1077 //
1091 //                                               1078 //
1092                                                  1079 
1093 G4double                                         1080 G4double 
1094 G4DiffuseElastic:: GetScatteringAngle( G4int     1081 G4DiffuseElastic:: GetScatteringAngle( G4int iMomentum, G4int iAngle, G4double position )
1095 {                                                1082 {
1096  G4double x1, x2, y1, y2, randAngle;             1083  G4double x1, x2, y1, y2, randAngle;
1097                                                  1084 
1098   if( iAngle == 0 )                              1085   if( iAngle == 0 )
1099   {                                              1086   {
1100     randAngle = (*fAngleTable)(iMomentum)->Ge    1087     randAngle = (*fAngleTable)(iMomentum)->GetLowEdgeEnergy(iAngle);
1101     // iAngle++;                                 1088     // iAngle++;
1102   }                                              1089   }
1103   else                                           1090   else
1104   {                                              1091   {
1105     if ( iAngle >= G4int((*fAngleTable)(iMome    1092     if ( iAngle >= G4int((*fAngleTable)(iMomentum)->GetVectorLength()) )
1106     {                                            1093     {
1107       iAngle = G4int((*fAngleTable)(iMomentum << 1094       iAngle = (*fAngleTable)(iMomentum)->GetVectorLength() - 1;
1108     }                                            1095     }
1109     y1 = (*(*fAngleTable)(iMomentum))(iAngle-    1096     y1 = (*(*fAngleTable)(iMomentum))(iAngle-1);
1110     y2 = (*(*fAngleTable)(iMomentum))(iAngle)    1097     y2 = (*(*fAngleTable)(iMomentum))(iAngle);
1111                                                  1098 
1112     x1 = (*fAngleTable)(iMomentum)->GetLowEdg    1099     x1 = (*fAngleTable)(iMomentum)->GetLowEdgeEnergy(iAngle-1);
1113     x2 = (*fAngleTable)(iMomentum)->GetLowEdg    1100     x2 = (*fAngleTable)(iMomentum)->GetLowEdgeEnergy(iAngle);
1114                                                  1101 
1115     if ( x1 == x2 )   randAngle = x2;            1102     if ( x1 == x2 )   randAngle = x2;
1116     else                                         1103     else
1117     {                                            1104     {
1118       if ( y1 == y2 ) randAngle = x1 + ( x2 -    1105       if ( y1 == y2 ) randAngle = x1 + ( x2 - x1 )*G4UniformRand();
1119       else                                       1106       else
1120       {                                          1107       {
1121         randAngle = x1 + ( position - y1 )*(     1108         randAngle = x1 + ( position - y1 )*( x2 - x1 )/( y2 - y1 );
1122       }                                          1109       }
1123     }                                            1110     }
1124   }                                              1111   }
1125   return randAngle;                              1112   return randAngle;
1126 }                                                1113 }
1127                                                  1114 
1128                                                  1115 
1129                                                  1116 
1130 /////////////////////////////////////////////    1117 ////////////////////////////////////////////////////////////////////////////
1131 //                                               1118 //
1132 // Return scattering angle sampled in lab sys    1119 // Return scattering angle sampled in lab system (target at rest)
1133                                                  1120 
1134                                                  1121 
1135                                                  1122 
1136 G4double                                         1123 G4double 
1137 G4DiffuseElastic::SampleThetaLab( const G4Had    1124 G4DiffuseElastic::SampleThetaLab( const G4HadProjectile* aParticle, 
1138                                         G4dou    1125                                         G4double tmass, G4double A)
1139 {                                                1126 {
1140   const G4ParticleDefinition* theParticle = a    1127   const G4ParticleDefinition* theParticle = aParticle->GetDefinition();
1141   G4double m1 = theParticle->GetPDGMass();       1128   G4double m1 = theParticle->GetPDGMass();
1142   G4double plab = aParticle->GetTotalMomentum    1129   G4double plab = aParticle->GetTotalMomentum();
1143   G4LorentzVector lv1 = aParticle->Get4Moment    1130   G4LorentzVector lv1 = aParticle->Get4Momentum();
1144   G4LorentzVector lv(0.0,0.0,0.0,tmass);         1131   G4LorentzVector lv(0.0,0.0,0.0,tmass);   
1145   lv += lv1;                                     1132   lv += lv1;
1146                                                  1133 
1147   G4ThreeVector bst = lv.boostVector();          1134   G4ThreeVector bst = lv.boostVector();
1148   lv1.boost(-bst);                               1135   lv1.boost(-bst);
1149                                                  1136 
1150   G4ThreeVector p1 = lv1.vect();                 1137   G4ThreeVector p1 = lv1.vect();
1151   G4double ptot    = p1.mag();                   1138   G4double ptot    = p1.mag();
1152   G4double tmax    = 4.0*ptot*ptot;              1139   G4double tmax    = 4.0*ptot*ptot;
1153   G4double t       = 0.0;                        1140   G4double t       = 0.0;
1154                                                  1141 
1155                                                  1142 
1156   //                                             1143   //
1157   // Sample t                                    1144   // Sample t
1158   //                                             1145   //
1159                                                  1146   
1160   t = SampleT( theParticle, ptot, A);            1147   t = SampleT( theParticle, ptot, A);
1161                                                  1148 
1162   // NaN finder                                  1149   // NaN finder
1163   if(!(t < 0.0 || t >= 0.0))                     1150   if(!(t < 0.0 || t >= 0.0)) 
1164   {                                              1151   {
1165     if (verboseLevel > 0)                        1152     if (verboseLevel > 0) 
1166     {                                            1153     {
1167       G4cout << "G4DiffuseElastic:WARNING: A     1154       G4cout << "G4DiffuseElastic:WARNING: A = " << A 
1168        << " mom(GeV)= " << plab/GeV              1155        << " mom(GeV)= " << plab/GeV 
1169              << " S-wave will be sampled"        1156              << " S-wave will be sampled" 
1170        << G4endl;                                1157        << G4endl; 
1171     }                                            1158     }
1172     t = G4UniformRand()*tmax;                    1159     t = G4UniformRand()*tmax; 
1173   }                                              1160   }
1174   if(verboseLevel>1)                             1161   if(verboseLevel>1)
1175   {                                              1162   {
1176     G4cout <<" t= " << t << " tmax= " << tmax    1163     G4cout <<" t= " << t << " tmax= " << tmax 
1177      << " ptot= " << ptot << G4endl;             1164      << " ptot= " << ptot << G4endl;
1178   }                                              1165   }
1179   // Sampling of angles in CM system             1166   // Sampling of angles in CM system
1180                                                  1167 
1181   G4double phi  = G4UniformRand()*twopi;         1168   G4double phi  = G4UniformRand()*twopi;
1182   G4double cost = 1. - 2.0*t/tmax;               1169   G4double cost = 1. - 2.0*t/tmax;
1183   G4double sint;                                 1170   G4double sint;
1184                                                  1171 
1185   if( cost >= 1.0 )                              1172   if( cost >= 1.0 ) 
1186   {                                              1173   {
1187     cost = 1.0;                                  1174     cost = 1.0;
1188     sint = 0.0;                                  1175     sint = 0.0;
1189   }                                              1176   }
1190   else if( cost <= -1.0)                         1177   else if( cost <= -1.0) 
1191   {                                              1178   {
1192     cost = -1.0;                                 1179     cost = -1.0;
1193     sint =  0.0;                                 1180     sint =  0.0;
1194   }                                              1181   }
1195   else                                           1182   else  
1196   {                                              1183   {
1197     sint = std::sqrt((1.0-cost)*(1.0+cost));     1184     sint = std::sqrt((1.0-cost)*(1.0+cost));
1198   }                                              1185   }    
1199   if (verboseLevel>1)                            1186   if (verboseLevel>1) 
1200   {                                              1187   {
1201     G4cout << "cos(t)=" << cost << " std::sin    1188     G4cout << "cos(t)=" << cost << " std::sin(t)=" << sint << G4endl;
1202   }                                              1189   }
1203   G4ThreeVector v1(sint*std::cos(phi),sint*st    1190   G4ThreeVector v1(sint*std::cos(phi),sint*std::sin(phi),cost);
1204   v1 *= ptot;                                    1191   v1 *= ptot;
1205   G4LorentzVector nlv1(v1.x(),v1.y(),v1.z(),s    1192   G4LorentzVector nlv1(v1.x(),v1.y(),v1.z(),std::sqrt(ptot*ptot + m1*m1));
1206                                                  1193 
1207   nlv1.boost(bst);                               1194   nlv1.boost(bst); 
1208                                                  1195 
1209   G4ThreeVector np1 = nlv1.vect();               1196   G4ThreeVector np1 = nlv1.vect();
1210                                                  1197 
1211     // G4double theta = std::acos( np1.z()/np    1198     // G4double theta = std::acos( np1.z()/np1.mag() );  // degree;
1212                                                  1199 
1213   G4double theta = np1.theta();                  1200   G4double theta = np1.theta();
1214                                                  1201 
1215   return theta;                                  1202   return theta;
1216 }                                                1203 }
1217                                                  1204 
1218 /////////////////////////////////////////////    1205 ////////////////////////////////////////////////////////////////////////////
1219 //                                               1206 //
1220 // Return scattering angle in lab system (tar    1207 // Return scattering angle in lab system (target at rest) knowing theta in CMS
1221                                                  1208 
1222                                                  1209 
1223                                                  1210 
1224 G4double                                         1211 G4double 
1225 G4DiffuseElastic::ThetaCMStoThetaLab( const G    1212 G4DiffuseElastic::ThetaCMStoThetaLab( const G4DynamicParticle* aParticle, 
1226                                         G4dou    1213                                         G4double tmass, G4double thetaCMS)
1227 {                                                1214 {
1228   const G4ParticleDefinition* theParticle = a    1215   const G4ParticleDefinition* theParticle = aParticle->GetDefinition();
1229   G4double m1 = theParticle->GetPDGMass();       1216   G4double m1 = theParticle->GetPDGMass();
1230   // G4double plab = aParticle->GetTotalMomen    1217   // G4double plab = aParticle->GetTotalMomentum();
1231   G4LorentzVector lv1 = aParticle->Get4Moment    1218   G4LorentzVector lv1 = aParticle->Get4Momentum();
1232   G4LorentzVector lv(0.0,0.0,0.0,tmass);         1219   G4LorentzVector lv(0.0,0.0,0.0,tmass);   
1233                                                  1220 
1234   lv += lv1;                                     1221   lv += lv1;
1235                                                  1222 
1236   G4ThreeVector bst = lv.boostVector();          1223   G4ThreeVector bst = lv.boostVector();
1237                                                  1224 
1238   lv1.boost(-bst);                               1225   lv1.boost(-bst);
1239                                                  1226 
1240   G4ThreeVector p1 = lv1.vect();                 1227   G4ThreeVector p1 = lv1.vect();
1241   G4double ptot    = p1.mag();                   1228   G4double ptot    = p1.mag();
1242                                                  1229 
1243   G4double phi  = G4UniformRand()*twopi;         1230   G4double phi  = G4UniformRand()*twopi;
1244   G4double cost = std::cos(thetaCMS);            1231   G4double cost = std::cos(thetaCMS);
1245   G4double sint;                                 1232   G4double sint;
1246                                                  1233 
1247   if( cost >= 1.0 )                              1234   if( cost >= 1.0 ) 
1248   {                                              1235   {
1249     cost = 1.0;                                  1236     cost = 1.0;
1250     sint = 0.0;                                  1237     sint = 0.0;
1251   }                                              1238   }
1252   else if( cost <= -1.0)                         1239   else if( cost <= -1.0) 
1253   {                                              1240   {
1254     cost = -1.0;                                 1241     cost = -1.0;
1255     sint =  0.0;                                 1242     sint =  0.0;
1256   }                                              1243   }
1257   else                                           1244   else  
1258   {                                              1245   {
1259     sint = std::sqrt((1.0-cost)*(1.0+cost));     1246     sint = std::sqrt((1.0-cost)*(1.0+cost));
1260   }                                              1247   }    
1261   if (verboseLevel>1)                            1248   if (verboseLevel>1) 
1262   {                                              1249   {
1263     G4cout << "cos(tcms)=" << cost << " std::    1250     G4cout << "cos(tcms)=" << cost << " std::sin(tcms)=" << sint << G4endl;
1264   }                                              1251   }
1265   G4ThreeVector v1(sint*std::cos(phi),sint*st    1252   G4ThreeVector v1(sint*std::cos(phi),sint*std::sin(phi),cost);
1266   v1 *= ptot;                                    1253   v1 *= ptot;
1267   G4LorentzVector nlv1(v1.x(),v1.y(),v1.z(),s    1254   G4LorentzVector nlv1(v1.x(),v1.y(),v1.z(),std::sqrt(ptot*ptot + m1*m1));
1268                                                  1255 
1269   nlv1.boost(bst);                               1256   nlv1.boost(bst); 
1270                                                  1257 
1271   G4ThreeVector np1 = nlv1.vect();               1258   G4ThreeVector np1 = nlv1.vect();
1272                                                  1259 
1273                                                  1260 
1274   G4double thetaLab = np1.theta();               1261   G4double thetaLab = np1.theta();
1275                                                  1262 
1276   return thetaLab;                               1263   return thetaLab;
1277 }                                                1264 }
1278 /////////////////////////////////////////////    1265 ////////////////////////////////////////////////////////////////////////////
1279 //                                               1266 //
1280 // Return scattering angle in CMS system (tar    1267 // Return scattering angle in CMS system (target at rest) knowing theta in Lab
1281                                                  1268 
1282                                                  1269 
1283                                                  1270 
1284 G4double                                         1271 G4double 
1285 G4DiffuseElastic::ThetaLabToThetaCMS( const G    1272 G4DiffuseElastic::ThetaLabToThetaCMS( const G4DynamicParticle* aParticle, 
1286                                         G4dou    1273                                         G4double tmass, G4double thetaLab)
1287 {                                                1274 {
1288   const G4ParticleDefinition* theParticle = a    1275   const G4ParticleDefinition* theParticle = aParticle->GetDefinition();
1289   G4double m1 = theParticle->GetPDGMass();       1276   G4double m1 = theParticle->GetPDGMass();
1290   G4double plab = aParticle->GetTotalMomentum    1277   G4double plab = aParticle->GetTotalMomentum();
1291   G4LorentzVector lv1 = aParticle->Get4Moment    1278   G4LorentzVector lv1 = aParticle->Get4Momentum();
1292   G4LorentzVector lv(0.0,0.0,0.0,tmass);         1279   G4LorentzVector lv(0.0,0.0,0.0,tmass);   
1293                                                  1280 
1294   lv += lv1;                                     1281   lv += lv1;
1295                                                  1282 
1296   G4ThreeVector bst = lv.boostVector();          1283   G4ThreeVector bst = lv.boostVector();
1297                                                  1284 
1298   // lv1.boost(-bst);                            1285   // lv1.boost(-bst);
1299                                                  1286 
1300   // G4ThreeVector p1 = lv1.vect();              1287   // G4ThreeVector p1 = lv1.vect();
1301   // G4double ptot    = p1.mag();                1288   // G4double ptot    = p1.mag();
1302                                                  1289 
1303   G4double phi  = G4UniformRand()*twopi;         1290   G4double phi  = G4UniformRand()*twopi;
1304   G4double cost = std::cos(thetaLab);            1291   G4double cost = std::cos(thetaLab);
1305   G4double sint;                                 1292   G4double sint;
1306                                                  1293 
1307   if( cost >= 1.0 )                              1294   if( cost >= 1.0 ) 
1308   {                                              1295   {
1309     cost = 1.0;                                  1296     cost = 1.0;
1310     sint = 0.0;                                  1297     sint = 0.0;
1311   }                                              1298   }
1312   else if( cost <= -1.0)                         1299   else if( cost <= -1.0) 
1313   {                                              1300   {
1314     cost = -1.0;                                 1301     cost = -1.0;
1315     sint =  0.0;                                 1302     sint =  0.0;
1316   }                                              1303   }
1317   else                                           1304   else  
1318   {                                              1305   {
1319     sint = std::sqrt((1.0-cost)*(1.0+cost));     1306     sint = std::sqrt((1.0-cost)*(1.0+cost));
1320   }                                              1307   }    
1321   if (verboseLevel>1)                            1308   if (verboseLevel>1) 
1322   {                                              1309   {
1323     G4cout << "cos(tlab)=" << cost << " std::    1310     G4cout << "cos(tlab)=" << cost << " std::sin(tlab)=" << sint << G4endl;
1324   }                                              1311   }
1325   G4ThreeVector v1(sint*std::cos(phi),sint*st    1312   G4ThreeVector v1(sint*std::cos(phi),sint*std::sin(phi),cost);
1326   v1 *= plab;                                    1313   v1 *= plab;
1327   G4LorentzVector nlv1(v1.x(),v1.y(),v1.z(),s    1314   G4LorentzVector nlv1(v1.x(),v1.y(),v1.z(),std::sqrt(plab*plab + m1*m1));
1328                                                  1315 
1329   nlv1.boost(-bst);                              1316   nlv1.boost(-bst); 
1330                                                  1317 
1331   G4ThreeVector np1 = nlv1.vect();               1318   G4ThreeVector np1 = nlv1.vect();
1332                                                  1319 
1333                                                  1320 
1334   G4double thetaCMS = np1.theta();               1321   G4double thetaCMS = np1.theta();
1335                                                  1322 
1336   return thetaCMS;                               1323   return thetaCMS;
1337 }                                                1324 }
1338                                                  1325 
1339 /////////////////////////////////////////////    1326 ///////////////////////////////////////////////////////////////////////////////
1340 //                                               1327 //
1341 // Test for given particle and element table     1328 // Test for given particle and element table of momentum, angle probability.
1342 // For the moment in lab system.                 1329 // For the moment in lab system. 
1343                                                  1330 
1344 void G4DiffuseElastic::TestAngleTable(const G    1331 void G4DiffuseElastic::TestAngleTable(const G4ParticleDefinition* theParticle, G4double partMom,
1345                                             G    1332                                             G4double Z, G4double A) 
1346 {                                                1333 {
1347   fAtomicNumber  = Z;     // atomic number       1334   fAtomicNumber  = Z;     // atomic number
1348   fAtomicWeight  = A;     // number of nucleo    1335   fAtomicWeight  = A;     // number of nucleons
1349   fNuclearRadius = CalculateNuclearRad(fAtomi    1336   fNuclearRadius = CalculateNuclearRad(fAtomicWeight);
1350                                                  1337   
1351                                                  1338      
1352                                                  1339   
1353   G4cout<<"G4DiffuseElastic::TestAngleTable()    1340   G4cout<<"G4DiffuseElastic::TestAngleTable() init the element with Z = "
1354     <<Z<<"; and A = "<<A<<G4endl;                1341     <<Z<<"; and A = "<<A<<G4endl;
1355                                                  1342  
1356   fElementNumberVector.push_back(fAtomicNumbe    1343   fElementNumberVector.push_back(fAtomicNumber);
1357                                                  1344 
1358                                                  1345  
1359                                                  1346 
1360                                                  1347 
1361   G4int i=0, j;                                  1348   G4int i=0, j;
1362   G4double a = 0., z = theParticle->GetPDGCha    1349   G4double a = 0., z = theParticle->GetPDGCharge(),  m1 = fParticle->GetPDGMass();
1363   G4double alpha1=0., alpha2=0., alphaMax=0.,    1350   G4double alpha1=0., alpha2=0., alphaMax=0., alphaCoulomb=0.;
1364   G4double deltaL10 = 0., deltaL96 = 0., delt    1351   G4double deltaL10 = 0., deltaL96 = 0., deltaAG = 0.;
1365   G4double sumL10 = 0.,sumL96 = 0.,sumAG = 0.    1352   G4double sumL10 = 0.,sumL96 = 0.,sumAG = 0.;
1366   G4double epsilon = 0.001;                      1353   G4double epsilon = 0.001;
1367                                                  1354 
1368   G4Integrator<G4DiffuseElastic,G4double(G4Di    1355   G4Integrator<G4DiffuseElastic,G4double(G4DiffuseElastic::*)(G4double)> integral;
1369                                                  1356   
1370   fAngleTable = new G4PhysicsTable(fEnergyBin    1357   fAngleTable = new G4PhysicsTable(fEnergyBin);
1371                                                  1358 
1372   fWaveVector = partMom/hbarc;                   1359   fWaveVector = partMom/hbarc;
1373                                                  1360 
1374   G4double kR     = fWaveVector*fNuclearRadiu    1361   G4double kR     = fWaveVector*fNuclearRadius;
1375   G4double kR2    = kR*kR;                       1362   G4double kR2    = kR*kR;
1376   G4double kRmax  = 10.6; // 10.6, 18, 10.174    1363   G4double kRmax  = 10.6; // 10.6, 18, 10.174; ~ 3 maxima of J1 or 15., 25.
1377   G4double kRcoul = 1.2; // 1.4, 2.5; // on t    1364   G4double kRcoul = 1.2; // 1.4, 2.5; // on the first slope of J1
1378                                                  1365 
1379   alphaMax = kRmax*kRmax/kR2;                    1366   alphaMax = kRmax*kRmax/kR2;
1380                                                  1367 
1381   if (alphaMax > 4.) alphaMax = 4.;  // vmg05    1368   if (alphaMax > 4.) alphaMax = 4.;  // vmg05-02-09: was pi2 
1382                                                  1369 
1383   alphaCoulomb = kRcoul*kRcoul/kR2;              1370   alphaCoulomb = kRcoul*kRcoul/kR2;
1384                                                  1371 
1385   if( z )                                        1372   if( z )
1386   {                                              1373   {
1387       a           = partMom/m1; // beta*gamma    1374       a           = partMom/m1; // beta*gamma for m1
1388       fBeta       = a/std::sqrt(1+a*a);          1375       fBeta       = a/std::sqrt(1+a*a);
1389       fZommerfeld = CalculateZommerfeld( fBet    1376       fZommerfeld = CalculateZommerfeld( fBeta, z, fAtomicNumber);
1390       fAm         = CalculateAm( partMom, fZo    1377       fAm         = CalculateAm( partMom, fZommerfeld, fAtomicNumber);
1391   }                                              1378   }
1392   G4PhysicsFreeVector* angleVector = new G4Ph    1379   G4PhysicsFreeVector* angleVector = new G4PhysicsFreeVector(fAngleBin-1);
1393                                                  1380 
1394   // G4PhysicsLogVector*  angleBins = new G4P    1381   // G4PhysicsLogVector*  angleBins = new G4PhysicsLogVector( 0.001*alphaMax, alphaMax, fAngleBin );
1395                                                  1382     
1396                                                  1383   
1397   fAddCoulomb = false;                           1384   fAddCoulomb = false;
1398                                                  1385 
1399   for(j = 1; j < fAngleBin; j++)                 1386   for(j = 1; j < fAngleBin; j++)
1400   {                                              1387   {
1401       // alpha1 = angleBins->GetLowEdgeEnergy    1388       // alpha1 = angleBins->GetLowEdgeEnergy(j-1);
1402       // alpha2 = angleBins->GetLowEdgeEnergy    1389       // alpha2 = angleBins->GetLowEdgeEnergy(j);
1403                                                  1390 
1404     alpha1 = alphaMax*(j-1)/fAngleBin;           1391     alpha1 = alphaMax*(j-1)/fAngleBin;
1405     alpha2 = alphaMax*( j )/fAngleBin;           1392     alpha2 = alphaMax*( j )/fAngleBin;
1406                                                  1393 
1407     if( ( alpha2 > alphaCoulomb ) && z ) fAdd    1394     if( ( alpha2 > alphaCoulomb ) && z ) fAddCoulomb = true;
1408                                                  1395 
1409     deltaL10 = integral.Legendre10(this, &G4D    1396     deltaL10 = integral.Legendre10(this, &G4DiffuseElastic::GetIntegrandFunction, alpha1, alpha2);
1410     deltaL96 = integral.Legendre96(this, &G4D    1397     deltaL96 = integral.Legendre96(this, &G4DiffuseElastic::GetIntegrandFunction, alpha1, alpha2);
1411     deltaAG  = integral.AdaptiveGauss(this, &    1398     deltaAG  = integral.AdaptiveGauss(this, &G4DiffuseElastic::GetIntegrandFunction, 
1412                                        alpha1    1399                                        alpha1, alpha2,epsilon);
1413                                                  1400 
1414       // G4cout<<alpha1<<"\t"<<std::sqrt(alph    1401       // G4cout<<alpha1<<"\t"<<std::sqrt(alpha1)/degree<<"\t"
1415       //     <<deltaL10<<"\t"<<deltaL96<<"\t"    1402       //     <<deltaL10<<"\t"<<deltaL96<<"\t"<<deltaAG<<G4endl;
1416                                                  1403 
1417     sumL10 += deltaL10;                          1404     sumL10 += deltaL10;
1418     sumL96 += deltaL96;                          1405     sumL96 += deltaL96;
1419     sumAG  += deltaAG;                           1406     sumAG  += deltaAG;
1420                                                  1407 
1421     G4cout<<alpha1<<"\t"<<std::sqrt(alpha1)/d    1408     G4cout<<alpha1<<"\t"<<std::sqrt(alpha1)/degree<<"\t"
1422             <<sumL10<<"\t"<<sumL96<<"\t"<<sum    1409             <<sumL10<<"\t"<<sumL96<<"\t"<<sumAG<<G4endl;
1423                                                  1410       
1424     angleVector->PutValue( j-1 , alpha1, sumL    1411     angleVector->PutValue( j-1 , alpha1, sumL10 ); // alpha2
1425   }                                              1412   }
1426   fAngleTable->insertAt(i,angleVector);          1413   fAngleTable->insertAt(i,angleVector);
1427   fAngleBank.push_back(fAngleTable);             1414   fAngleBank.push_back(fAngleTable);
1428                                                  1415 
1429   /*                                             1416   /*
1430   // Integral over all angle range - Bad accu    1417   // Integral over all angle range - Bad accuracy !!!
1431                                                  1418 
1432   sumL10 = integral.Legendre10(this, &G4Diffu    1419   sumL10 = integral.Legendre10(this, &G4DiffuseElastic::GetIntegrandFunction, 0., alpha2);
1433   sumL96 = integral.Legendre96(this, &G4Diffu    1420   sumL96 = integral.Legendre96(this, &G4DiffuseElastic::GetIntegrandFunction, 0., alpha2);
1434   sumAG  = integral.AdaptiveGauss(this, &G4Di    1421   sumAG  = integral.AdaptiveGauss(this, &G4DiffuseElastic::GetIntegrandFunction, 
1435                                        0., al    1422                                        0., alpha2,epsilon);
1436   G4cout<<G4endl;                                1423   G4cout<<G4endl;
1437   G4cout<<alpha2<<"\t"<<std::sqrt(alpha2)/deg    1424   G4cout<<alpha2<<"\t"<<std::sqrt(alpha2)/degree<<"\t"
1438             <<sumL10<<"\t"<<sumL96<<"\t"<<sum    1425             <<sumL10<<"\t"<<sumL96<<"\t"<<sumAG<<G4endl;
1439   */                                             1426   */
1440   return;                                        1427   return;
1441 }                                                1428 }
1442                                                  1429 
1443 //                                               1430 //
1444 //                                               1431 //
1445 /////////////////////////////////////////////    1432 /////////////////////////////////////////////////////////////////////////////////
1446                                                  1433