Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/electromagnetic/xrays/src/G4VXTRenergyLoss.cc

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

Diff markup

Differences between /processes/electromagnetic/xrays/src/G4VXTRenergyLoss.cc (Version 11.3.0) and /processes/electromagnetic/xrays/src/G4VXTRenergyLoss.cc (Version 9.4.p3)


  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 //
                                                   >>  27 // $Id: G4VXTRenergyLoss.cc,v 1.45 2010-06-16 15:34:15 gcosmo Exp $
                                                   >>  28 // GEANT4 tag $Name: not supported by cvs2svn $
                                                   >>  29 //
 26 // History:                                        30 // History:
 27 // 2001-2002 R&D by V.Grichine                     31 // 2001-2002 R&D by V.Grichine
 28 // 19.06.03 V. Grichine, modifications in Buil <<  32 // 19.06.03 V. Grichine, modifications in BuildTable for the integration 
 29 //                       in respect of angle:      33 //                       in respect of angle: range is increased, accuracy is
 30 //                       improved                  34 //                       improved
 31 // 28.07.05, P.Gumplinger add G4ProcessType to     35 // 28.07.05, P.Gumplinger add G4ProcessType to constructor
 32 // 28.09.07, V.Ivanchenko general cleanup with     36 // 28.09.07, V.Ivanchenko general cleanup without change of algorithms
 33 //                                                 37 //
 34                                                    38 
 35 #include "G4VXTRenergyLoss.hh"                 <<  39 #include "G4Timer.hh"
 36                                                    40 
 37 #include "G4AffineTransform.hh"                <<  41 #include "G4VXTRenergyLoss.hh"
 38 #include "G4DynamicParticle.hh"                <<  42 #include "G4Poisson.hh"
 39 #include "G4EmProcessSubType.hh"               << 
 40 #include "G4Integrator.hh"                     << 
 41 #include "G4MaterialTable.hh"                      43 #include "G4MaterialTable.hh"
 42 #include "G4ParticleMomentum.hh"               << 
 43 #include "G4PhysicalConstants.hh"              << 
 44 #include "G4PhysicsFreeVector.hh"              << 
 45 #include "G4PhysicsLinearVector.hh"            << 
 46 #include "G4PhysicsLogVector.hh"               << 
 47 #include "G4RotationMatrix.hh"                 << 
 48 #include "G4SandiaTable.hh"                    << 
 49 #include "G4SystemOfUnits.hh"                  << 
 50 #include "G4ThreeVector.hh"                    << 
 51 #include "G4Timer.hh"                          << 
 52 #include "G4VDiscreteProcess.hh"                   44 #include "G4VDiscreteProcess.hh"
 53 #include "G4VParticleChange.hh"                    45 #include "G4VParticleChange.hh"
 54 #include "G4VSolid.hh"                             46 #include "G4VSolid.hh"
 55 #include "G4PhysicsModelCatalog.hh"            <<  47 
                                                   >>  48 #include "G4RotationMatrix.hh"
                                                   >>  49 #include "G4ThreeVector.hh"
                                                   >>  50 #include "G4AffineTransform.hh"
                                                   >>  51 #include "G4SandiaTable.hh"
                                                   >>  52 
                                                   >>  53 #include "G4PhysicsVector.hh"
                                                   >>  54 #include "G4PhysicsFreeVector.hh"
                                                   >>  55 #include "G4PhysicsLinearVector.hh"
 56                                                    56 
 57 //////////////////////////////////////////////     57 ////////////////////////////////////////////////////////////////////////////
                                                   >>  58 //
 58 // Constructor, destructor                         59 // Constructor, destructor
 59 G4VXTRenergyLoss::G4VXTRenergyLoss(G4LogicalVo <<  60 
 60                                    G4Material* <<  61 G4VXTRenergyLoss::G4VXTRenergyLoss(G4LogicalVolume *anEnvelope,
 61                                    G4double a, <<  62            G4Material* foilMat,G4Material* gasMat,
 62                                    const G4Str <<  63            G4double a, G4double b,
 63                                    G4ProcessTy <<  64            G4int n,const G4String& processName,
 64   : G4VDiscreteProcess(processName, type)      <<  65            G4ProcessType type) :
 65   , fGammaCutInKineticEnergy(nullptr)          <<  66   G4VDiscreteProcess(processName, type),
 66   , fAngleDistrTable(nullptr)                  <<  67   fGammaCutInKineticEnergy(0),
 67   , fEnergyDistrTable(nullptr)                 <<  68   fGammaTkinCut(0),
 68   , fAngleForEnergyTable(nullptr)              <<  69   fAngleDistrTable(0),
 69   , fPlatePhotoAbsCof(nullptr)                 <<  70   fEnergyDistrTable(0),
 70   , fGasPhotoAbsCof(nullptr)                   <<  71   fPlatePhotoAbsCof(0),
 71   , fGammaTkinCut(0.0)                         <<  72   fGasPhotoAbsCof(0),
                                                   >>  73   fAngleForEnergyTable(0)
 72 {                                                  74 {
 73   verboseLevel = 1;                                75   verboseLevel = 1;
 74   secID = G4PhysicsModelCatalog::GetModelID("m << 
 75   SetProcessSubType(fTransitionRadiation);     << 
 76                                                    76 
 77   fPtrGamma    = nullptr;                      <<  77   fPtrGamma = 0;
 78   fMinEnergyTR = fMaxEnergyTR = fMaxThetaTR =  <<  78   fMinEnergyTR = fMaxEnergyTR = fMaxThetaTR = fGamma = fEnergy = fVarAngle 
 79   fVarAngle = fLambda = fTotalDist = fPlateThi <<  79     = fLambda = fTotalDist = fPlateThick = fGasThick = fAlphaPlate = fAlphaGas = 0.0;
 80   fAlphaPlate = 100.;                          <<  80 
 81   fAlphaGas = 40.;                             <<  81   // Initialization of local constants
 82                                                <<  82   fTheMinEnergyTR = 1.0*keV;
 83   fTheMinEnergyTR = CLHEP::keV * 1.; //  1.; / <<  83   fTheMaxEnergyTR = 100.0*keV;
 84   fTheMaxEnergyTR = CLHEP::keV * 100.; // 40.; <<  84   fTheMaxAngle    = 1.0e-3;
 85                                                <<  85   fTheMinAngle    = 5.0e-6;
 86   fTheMinAngle    = 1.e-8;  //                 <<  86   fBinTR          = 50;
 87   fTheMaxAngle    = 4.e-4;                     <<  87 
 88                                                <<  88   fMinProtonTkin  = 100.0*GeV;
 89   fTotBin = 50;  //  number of bins in log sca <<  89   fMaxProtonTkin  = 100.0*TeV;
 90   fBinTR  = 100; //   number of bins in TR vec <<  90   fTotBin         = 50;
 91   fKrange = 229;                               << 
 92   // min/max angle2 in log-vectors             << 
 93                                                    91 
 94   fMinThetaTR = 3.0e-9;                        << 
 95   fMaxThetaTR = 1.0e-4;                        << 
 96                                                << 
 97                                                << 
 98   // Proton energy vector initialization           92   // Proton energy vector initialization
 99   fProtonEnergyVector =                        << 
100     new G4PhysicsLogVector(fMinProtonTkin, fMa << 
101                                                    93 
102   fXTREnergyVector =                           <<  94   fProtonEnergyVector = new G4PhysicsLogVector(fMinProtonTkin,
103     new G4PhysicsLogVector(fTheMinEnergyTR, fT <<  95                  fMaxProtonTkin,
                                                   >>  96                  fTotBin  );
                                                   >>  97 
                                                   >>  98   fXTREnergyVector = new G4PhysicsLogVector(fTheMinEnergyTR,
                                                   >>  99               fTheMaxEnergyTR,
                                                   >> 100               fBinTR  );
104                                                   101 
105   fEnvelope = anEnvelope;                      << 102   fPlasmaCof = 4.0*pi*fine_structure_const*hbarc*hbarc*hbarc/electron_mass_c2;
106                                                   103 
107   fPlateNumber = n;                            << 104   fCofTR     = fine_structure_const/pi;
                                                   >> 105 
                                                   >> 106   fEnvelope  = anEnvelope ;
                                                   >> 107 
                                                   >> 108   fPlateNumber = n ;
108   if(verboseLevel > 0)                            109   if(verboseLevel > 0)
109     G4cout << "### G4VXTRenergyLoss: the numbe << 110     G4cout<<"### G4VXTRenergyLoss: the number of TR radiator plates = "
110            << fPlateNumber << G4endl;          << 111     <<fPlateNumber<<G4endl ;
111   if(fPlateNumber == 0)                           112   if(fPlateNumber == 0)
112   {                                               113   {
113     G4Exception("G4VXTRenergyLoss::G4VXTRenerg << 114     G4Exception("G4VXTRenergyLoss: No plates in X-ray TR radiator") ;
114                 FatalException, "No plates in  << 
115   }                                               115   }
116   // default is XTR dEdx, not flux after radia    116   // default is XTR dEdx, not flux after radiator
                                                   >> 117 
117   fExitFlux      = false;                         118   fExitFlux      = false;
118   // default angle distribution according nume << 119   fAngleRadDistr = false;
119   fFastAngle     = false; // no angle accordin << 
120   fAngleRadDistr = true;                       << 
121   fCompton       = false;                         120   fCompton       = false;
122                                                   121 
123   fLambda = DBL_MAX;                              122   fLambda = DBL_MAX;
124                                                << 
125   // Mean thicknesses of plates and gas gaps      123   // Mean thicknesses of plates and gas gaps
126   fPlateThick = a;                             << 124 
127   fGasThick   = b;                             << 125   fPlateThick = a ;
128   fTotalDist  = fPlateNumber * (fPlateThick +  << 126   fGasThick   = b ;
                                                   >> 127   fTotalDist  = fPlateNumber*(fPlateThick+fGasThick) ;
129   if(verboseLevel > 0)                            128   if(verboseLevel > 0)
130     G4cout << "total radiator thickness = " << << 129     G4cout<<"total radiator thickness = "<<fTotalDist/cm<<" cm"<<G4endl ;
131            << G4endl;                          << 
132                                                   130 
133   // index of plate material                      131   // index of plate material
134   fMatIndex1 = (G4int)foilMat->GetIndex();     << 132   fMatIndex1 = foilMat->GetIndex()  ;
135   if(verboseLevel > 0)                            133   if(verboseLevel > 0)
136     G4cout << "plate material = " << foilMat-> << 134     G4cout<<"plate material = "<<foilMat->GetName()<<G4endl ;
137                                                   135 
138   // index of gas material                        136   // index of gas material
139   fMatIndex2 = (G4int)gasMat->GetIndex();      << 137   fMatIndex2 = gasMat->GetIndex()  ;
140   if(verboseLevel > 0)                            138   if(verboseLevel > 0)
141     G4cout << "gas material = " << gasMat->Get << 139     G4cout<<"gas material = "<<gasMat->GetName()<<G4endl ;
142                                                   140 
143   // plasma energy squared for plate material     141   // plasma energy squared for plate material
144   fSigma1 = fPlasmaCof * foilMat->GetElectronD << 142 
                                                   >> 143   fSigma1 = fPlasmaCof*foilMat->GetElectronDensity()  ;
                                                   >> 144   //  fSigma1 = (20.9*eV)*(20.9*eV) ;
145   if(verboseLevel > 0)                            145   if(verboseLevel > 0)
146     G4cout << "plate plasma energy = " << std: << 146     G4cout<<"plate plasma energy = "<<std::sqrt(fSigma1)/eV<<" eV"<<G4endl ;
147            << G4endl;                          << 
148                                                   147 
149   // plasma energy squared for gas material       148   // plasma energy squared for gas material
150   fSigma2 = fPlasmaCof * gasMat->GetElectronDe << 149 
                                                   >> 150   fSigma2 = fPlasmaCof*gasMat->GetElectronDensity()  ;
151   if(verboseLevel > 0)                            151   if(verboseLevel > 0)
152     G4cout << "gas plasma energy = " << std::s << 152     G4cout<<"gas plasma energy = "<<std::sqrt(fSigma2)/eV<<" eV"<<G4endl ;
153            << G4endl;                          << 
154                                                   153 
155   // Compute cofs for preparation of linear ph    154   // Compute cofs for preparation of linear photo absorption
                                                   >> 155 
156   ComputePlatePhotoAbsCof();                      156   ComputePlatePhotoAbsCof();
157   ComputeGasPhotoAbsCof();                        157   ComputeGasPhotoAbsCof();
158                                                   158 
159   pParticleChange = &fParticleChange;             159   pParticleChange = &fParticleChange;
160 }                                                 160 }
161                                                   161 
162 //////////////////////////////////////////////    162 ///////////////////////////////////////////////////////////////////////////
                                                   >> 163 
163 G4VXTRenergyLoss::~G4VXTRenergyLoss()             164 G4VXTRenergyLoss::~G4VXTRenergyLoss()
164 {                                                 165 {
                                                   >> 166   if(fEnvelope) delete fEnvelope;
165   delete fProtonEnergyVector;                     167   delete fProtonEnergyVector;
166   delete fXTREnergyVector;                        168   delete fXTREnergyVector;
167   if(fEnergyDistrTable)                        << 169   delete fEnergyDistrTable;
168   {                                            << 170   delete fAngleDistrTable;
169     fEnergyDistrTable->clearAndDestroy();      << 171   delete fAngleForEnergyTable;
170     delete fEnergyDistrTable;                  << 
171   }                                            << 
172   if(fAngleRadDistr)                           << 
173   {                                            << 
174     fAngleDistrTable->clearAndDestroy();       << 
175     delete fAngleDistrTable;                   << 
176   }                                            << 
177   if(fAngleForEnergyTable)                     << 
178   {                                            << 
179     fAngleForEnergyTable->clearAndDestroy();   << 
180     delete fAngleForEnergyTable;               << 
181   }                                            << 
182 }                                              << 
183                                                << 
184 void G4VXTRenergyLoss::ProcessDescription(std: << 
185 {                                              << 
186   out << "Base class for 'fast' parameterisati << 
187          "transition\n"                        << 
188          "radiation. Angular distribution is v << 
189 }                                                 172 }
190                                                   173 
191 //////////////////////////////////////////////    174 ///////////////////////////////////////////////////////////////////////////////
                                                   >> 175 //
192 // Returns condition for application of the mo    176 // Returns condition for application of the model depending on particle type
                                                   >> 177 
                                                   >> 178 
193 G4bool G4VXTRenergyLoss::IsApplicable(const G4    179 G4bool G4VXTRenergyLoss::IsApplicable(const G4ParticleDefinition& particle)
194 {                                                 180 {
195   return (particle.GetPDGCharge() != 0.0);     << 181   return  ( particle.GetPDGCharge() != 0.0 ) ;
196 }                                                 182 }
197                                                   183 
198 //////////////////////////////////////////////    184 /////////////////////////////////////////////////////////////////////////////////
                                                   >> 185 //
199 // Calculate step size for XTR process inside     186 // Calculate step size for XTR process inside raaditor
200 G4double G4VXTRenergyLoss::GetMeanFreePath(con << 187 
201                                            G4F << 188 G4double G4VXTRenergyLoss::GetMeanFreePath(const G4Track& aTrack,
                                                   >> 189              G4double, // previousStepSize,
                                                   >> 190              G4ForceCondition* condition)
202 {                                                 191 {
203   G4int iTkin, iPlace;                            192   G4int iTkin, iPlace;
204   G4double lambda, sigma, kinEnergy, mass, gam    193   G4double lambda, sigma, kinEnergy, mass, gamma;
205   G4double charge, chargeSq, massRatio, TkinSc    194   G4double charge, chargeSq, massRatio, TkinScaled;
206   G4double E1, E2, W, W1, W2;                  << 195   G4double E1,E2,W,W1,W2;
207                                                   196 
208   *condition = NotForced;                         197   *condition = NotForced;
209                                                << 198   
210   if(aTrack.GetVolume()->GetLogicalVolume() != << 199   if( aTrack.GetVolume()->GetLogicalVolume() != fEnvelope ) lambda = DBL_MAX;
211     lambda = DBL_MAX;                          << 
212   else                                            200   else
213   {                                               201   {
214     const G4DynamicParticle* aParticle = aTrac    202     const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
215     kinEnergy                          = aPart << 203     kinEnergy = aParticle->GetKineticEnergy();
216     mass  = aParticle->GetDefinition()->GetPDG << 204     mass      = aParticle->GetDefinition()->GetPDGMass();
217     gamma = 1.0 + kinEnergy / mass;            << 205     gamma     = 1.0 + kinEnergy/mass;
218     if(verboseLevel > 1)                          206     if(verboseLevel > 1)
219     {                                             207     {
220       G4cout << " gamma = " << gamma << ";   f << 208       G4cout<<" gamma = "<<gamma<<";   fGamma = "<<fGamma<<G4endl;
221     }                                             209     }
222                                                   210 
223     if(std::fabs(gamma - fGamma) < 0.05 * gamm << 211     if ( std::fabs( gamma - fGamma ) < 0.05*gamma ) lambda = fLambda;
224       lambda = fLambda;                        << 
225     else                                          212     else
226     {                                             213     {
227       charge     = aParticle->GetDefinition()- << 214       charge = aParticle->GetDefinition()->GetPDGCharge();
228       chargeSq   = charge * charge;            << 215       chargeSq  = charge*charge;
229       massRatio  = proton_mass_c2 / mass;      << 216       massRatio = proton_mass_c2/mass;
230       TkinScaled = kinEnergy * massRatio;      << 217       TkinScaled = kinEnergy*massRatio;
231                                                   218 
232       for(iTkin = 0; iTkin < fTotBin; ++iTkin) << 219       for(iTkin = 0; iTkin < fTotBin; iTkin++)
233       {                                           220       {
234         if(TkinScaled < fProtonEnergyVector->G << 221         if( TkinScaled < fProtonEnergyVector->GetLowEdgeEnergy(iTkin))  break ;    
235           break;                               << 
236       }                                           222       }
237       iPlace = iTkin - 1;                      << 223       iPlace = iTkin - 1 ;
238                                                   224 
239       if(iTkin == 0)                           << 225       if(iTkin == 0) lambda = DBL_MAX; // Tkin is too small, neglect of TR photon generation
240         lambda = DBL_MAX;  // Tkin is too smal << 226       else          // general case: Tkin between two vectors of the material
241       else  // general case: Tkin between two  << 
242       {                                           227       {
243         if(iTkin == fTotBin)                   << 228         if(iTkin == fTotBin) 
244         {                                         229         {
245           sigma = (*(*fEnergyDistrTable)(iPlac << 230           sigma = (*(*fEnergyDistrTable)(iPlace))(0)*chargeSq;
246         }                                         231         }
247         else                                      232         else
248         {                                         233         {
249           E1    = fProtonEnergyVector->GetLowE << 234           E1 = fProtonEnergyVector->GetLowEdgeEnergy(iTkin - 1) ; 
250           E2    = fProtonEnergyVector->GetLowE << 235           E2 = fProtonEnergyVector->GetLowEdgeEnergy(iTkin)     ;
251           W     = 1.0 / (E2 - E1);             << 236            W = 1.0/(E2 - E1) ;
252           W1    = (E2 - TkinScaled) * W;       << 237           W1 = (E2 - TkinScaled)*W ;
253           W2    = (TkinScaled - E1) * W;       << 238           W2 = (TkinScaled - E1)*W ;
254           sigma = ((*(*fEnergyDistrTable)(iPla << 239           sigma = ( (*(*fEnergyDistrTable)(iPlace  ))(0)*W1 +
255                    (*(*fEnergyDistrTable)(iPla << 240                 (*(*fEnergyDistrTable)(iPlace+1))(0)*W2   )*chargeSq;
256                   chargeSq;                    << 241       
257         }                                         242         }
258         if(sigma < DBL_MIN)                    << 243         if (sigma < DBL_MIN) lambda = DBL_MAX;
259           lambda = DBL_MAX;                    << 244         else                 lambda = 1./sigma; 
260         else                                   << 
261           lambda = 1. / sigma;                 << 
262         fLambda = lambda;                         245         fLambda = lambda;
263         fGamma  = gamma;                       << 246         fGamma  = gamma;   
264         if(verboseLevel > 1)                      247         if(verboseLevel > 1)
265         {                                         248         {
266           G4cout << " lambda = " << lambda / m << 249     G4cout<<" lambda = "<<lambda/mm<<" mm"<<G4endl;
267         }                                         250         }
268       }                                           251       }
269     }                                             252     }
270   }                                            << 253   }  
271   return lambda;                                  254   return lambda;
272 }                                                 255 }
273                                                   256 
274 //////////////////////////////////////////////    257 //////////////////////////////////////////////////////////////////////////
                                                   >> 258 //
275 // Interface for build table from physics list    259 // Interface for build table from physics list
                                                   >> 260 
276 void G4VXTRenergyLoss::BuildPhysicsTable(const    261 void G4VXTRenergyLoss::BuildPhysicsTable(const G4ParticleDefinition& pd)
277 {                                                 262 {
278   if(pd.GetPDGCharge() == 0.)                  << 263   if(pd.GetPDGCharge()  == 0.) 
279   {                                               264   {
280     G4Exception("G4VXTRenergyLoss::BuildPhysic << 265     G4Exception("G4VXTRenergyLoss::BuildPhysicsTable", "Notification", JustWarning,
281                 JustWarning, "XTR initialisati << 266                  "XTR initialisation for neutral particle ?!" );   
282   }                                               267   }
283   BuildEnergyTable();                          << 268   BuildTable();
284                                                << 269   if (fAngleRadDistr) 
285   if(fAngleRadDistr)                           << 
286   {                                               270   {
287     if(verboseLevel > 0)                          271     if(verboseLevel > 0)
288     {                                          << 272       G4cout<<"Build angle distribution according the transparent regular radiator"
289       G4cout                                   << 273       <<G4endl;
290         << "Build angle for energy distributio << 274     BuildAngleTable();
291         << G4endl;                             << 
292     }                                          << 
293     BuildAngleForEnergyBank();                 << 
294   }                                               275   }
295 }                                                 276 }
296                                                   277 
                                                   >> 278 
297 //////////////////////////////////////////////    279 //////////////////////////////////////////////////////////////////////////
                                                   >> 280 //
298 // Build integral energy distribution of XTR p    281 // Build integral energy distribution of XTR photons
299 void G4VXTRenergyLoss::BuildEnergyTable()      << 282 
                                                   >> 283 void G4VXTRenergyLoss::BuildTable()
300 {                                                 284 {
301   G4int iTkin, iTR, iPlace;                       285   G4int iTkin, iTR, iPlace;
302   G4double radiatorCof = 1.0;  // for tuning o << 286   G4double radiatorCof = 1.0;           // for tuning of XTR yield
303   G4double energySum   = 0.0;                  << 
304                                                   287 
305   fEnergyDistrTable = new G4PhysicsTable(fTotB    288   fEnergyDistrTable = new G4PhysicsTable(fTotBin);
306   if(fAngleRadDistr)                           << 289   fAngleDistrTable = new G4PhysicsTable(fTotBin);
307     fAngleDistrTable = new G4PhysicsTable(fTot << 
308                                                   290 
309   fGammaTkinCut = 0.0;                            291   fGammaTkinCut = 0.0;
                                                   >> 292   
                                                   >> 293   // setting of min/max TR energies 
                                                   >> 294   
                                                   >> 295   if(fGammaTkinCut > fTheMinEnergyTR)  fMinEnergyTR = fGammaTkinCut ;
                                                   >> 296   else                                 fMinEnergyTR = fTheMinEnergyTR ;
                                                   >> 297   
                                                   >> 298   if(fGammaTkinCut > fTheMaxEnergyTR) fMaxEnergyTR = 2.0*fGammaTkinCut ;  
                                                   >> 299   else                                fMaxEnergyTR = fTheMaxEnergyTR ;
310                                                   300 
311   // setting of min/max TR energies            << 301   G4cout.precision(4) ;
312   if(fGammaTkinCut > fTheMinEnergyTR)          << 302   G4Timer timer ;
313     fMinEnergyTR = fGammaTkinCut;              << 303   timer.Start() ;
314   else                                         << 
315     fMinEnergyTR = fTheMinEnergyTR;            << 
316                                                << 
317   if(fGammaTkinCut > fTheMaxEnergyTR)          << 
318     fMaxEnergyTR = 2.0 * fGammaTkinCut;        << 
319   else                                         << 
320     fMaxEnergyTR = fTheMaxEnergyTR;            << 
321                                                << 
322   G4Integrator<G4VXTRenergyLoss, G4double (G4V << 
323     integral;                                  << 
324                                                   304 
325   G4cout.precision(4);                         << 305   if(verboseLevel > 0) {
326   G4Timer timer;                               << 306     G4cout<<G4endl;
327   timer.Start();                               << 307     G4cout<<"Lorentz Factor"<<"\t"<<"XTR photon number"<<G4endl;
328                                                << 308     G4cout<<G4endl;
329   if(verboseLevel > 0)                         << 
330   {                                            << 
331     G4cout << G4endl;                          << 
332     G4cout << "Lorentz Factor"                 << 
333            << "\t"                             << 
334            << "XTR photon number" << G4endl;   << 
335     G4cout << G4endl;                          << 
336   }                                               309   }
337   for(iTkin = 0; iTkin < fTotBin; ++iTkin)  // << 310   for( iTkin = 0 ; iTkin < fTotBin ; iTkin++ )      // Lorentz factor loop
338   {                                               311   {
339     auto energyVector =                        << 312     G4PhysicsLogVector* energyVector = new G4PhysicsLogVector( fMinEnergyTR,
340       new G4PhysicsLogVector(fMinEnergyTR, fMa << 313                      fMaxEnergyTR,
                                                   >> 314                      fBinTR  ) ;
341                                                   315 
342     fGamma =                                   << 316     fGamma = 1.0 + (fProtonEnergyVector->
343       1.0 + (fProtonEnergyVector->GetLowEdgeEn << 317         GetLowEdgeEnergy(iTkin)/proton_mass_c2) ;
344                                                   318 
345     // if(fMaxThetaTR > fTheMaxAngle)     fMax << 319     fMaxThetaTR = 25.0/(fGamma*fGamma) ;  // theta^2
346     // else if(fMaxThetaTR < fTheMinAngle)     << 
347                                                   320 
348     energySum = 0.0;                           << 321     fTheMinAngle = 1.0e-3 ; // was 5.e-6, e-6 !!!, e-5, e-4
                                                   >> 322  
                                                   >> 323     if( fMaxThetaTR > fTheMaxAngle )    fMaxThetaTR = fTheMaxAngle; 
                                                   >> 324     else
                                                   >> 325       {
                                                   >> 326   if( fMaxThetaTR < fTheMinAngle )  fMaxThetaTR = fTheMinAngle;
                                                   >> 327       }
                                                   >> 328     G4PhysicsLinearVector* angleVector = new G4PhysicsLinearVector(0.0,
                                                   >> 329                    fMaxThetaTR,
                                                   >> 330                    fBinTR  );
349                                                   331 
350     energyVector->PutValue(fBinTR - 1, energyS << 332     G4double energySum = 0.0;
                                                   >> 333     G4double angleSum  = 0.0;
351                                                   334 
352     for(iTR = fBinTR - 2; iTR >= 0; --iTR)     << 335     G4Integrator<G4VXTRenergyLoss,G4double(G4VXTRenergyLoss::*)(G4double)> integral;
353     {                                          << 
354       // Legendre96 or Legendre10              << 
355                                                   336 
356       energySum += radiatorCof * fCofTR *      << 337     energyVector->PutValue(fBinTR-1,energySum);
357                                                << 338     angleVector->PutValue(fBinTR-1,angleSum);
358   // integral.Legendre10(this, &G4VXTRenergyLo << 
359                                                << 
360                    integral.Legendre96(this, & << 
361                                                << 
362                                        energyV << 
363                                        energyV << 
364                                                   339 
365       energyVector->PutValue(iTR, energySum /  << 340     for( iTR = fBinTR - 2 ; iTR >= 0 ; iTR-- )
366     }                                          << 341       {
367     iPlace = iTkin;                            << 342         energySum += radiatorCof*fCofTR*integral.Legendre10(
368     fEnergyDistrTable->insertAt(iPlace, energy << 343          this,&G4VXTRenergyLoss::SpectralXTRdEdx,
                                                   >> 344                      energyVector->GetLowEdgeEnergy(iTR),
                                                   >> 345                      energyVector->GetLowEdgeEnergy(iTR+1) ); 
                                                   >> 346 
                                                   >> 347   //    angleSum  += fCofTR*integral.Legendre96(
                                                   >> 348   //       this,&G4VXTRenergyLoss::AngleXTRdEdx,
                                                   >> 349   //       angleVector->GetLowEdgeEnergy(iTR),
                                                   >> 350   //       angleVector->GetLowEdgeEnergy(iTR+1) );
369                                                   351 
                                                   >> 352         energyVector->PutValue(iTR,energySum/fTotalDist);
                                                   >> 353         //  angleVector ->PutValue(iTR,angleSum);
                                                   >> 354       }
370     if(verboseLevel > 0)                          355     if(verboseLevel > 0)
371     {                                          << 356       {
372       G4cout << fGamma << "\t" << energySum << << 357   G4cout
373     }                                          << 358     // <<iTkin<<"\t"
374   }                                            << 359     //   <<"fGamma = "
                                                   >> 360     <<fGamma<<"\t"  //  <<"  fMaxThetaTR = "<<fMaxThetaTR
                                                   >> 361     //  <<"sumN = "
                                                   >> 362     <<energySum      // <<" ; sumA = "<<angleSum
                                                   >> 363     <<G4endl;
                                                   >> 364       }
                                                   >> 365     iPlace = iTkin;
                                                   >> 366     fEnergyDistrTable->insertAt(iPlace,energyVector);
                                                   >> 367     fAngleDistrTable->insertAt(iPlace,angleVector);
                                                   >> 368   }     
375   timer.Stop();                                   369   timer.Stop();
376   G4cout.precision(6);                            370   G4cout.precision(6);
377   if(verboseLevel > 0)                         << 371   if(verboseLevel > 0) {
378   {                                            << 372     G4cout<<G4endl;
379     G4cout << G4endl;                          << 373     G4cout<<"total time for build X-ray TR energy loss tables = "
380     G4cout << "total time for build X-ray TR e << 374     <<timer.GetUserElapsed()<<" s"<<G4endl;
381            << timer.GetUserElapsed() << " s" < << 
382   }                                               375   }
383   fGamma = 0.;                                    376   fGamma = 0.;
384   return;                                      << 377   return ;
385 }                                                 378 }
386                                                   379 
387 //////////////////////////////////////////////    380 //////////////////////////////////////////////////////////////////////////
388 // Bank of angle distributions for given energ << 381 //
                                                   >> 382 //
389                                                   383 
390 void G4VXTRenergyLoss::BuildAngleForEnergyBank << 384 void G4VXTRenergyLoss::BuildEnergyTable()
391 {                                                 385 {
392                                                << 
393   if( ( this->GetProcessName() == "TranspRegXT << 
394         this->GetProcessName() == "TranspRegXT << 
395         this->GetProcessName() == "RegularXTRa << 
396   this->GetProcessName() == "RegularXTRmodel"  << 
397   {                                            << 
398     BuildAngleTable(); // by sum of delta-func << 
399     return;                                    << 
400   }                                            << 
401   G4int i, iTkin, iTR;                         << 
402   G4double angleSum = 0.0;                     << 
403                                                << 
404   fGammaTkinCut = 0.0;                         << 
405                                                << 
406   // setting of min/max TR energies            << 
407   if(fGammaTkinCut > fTheMinEnergyTR)          << 
408     fMinEnergyTR = fGammaTkinCut;              << 
409   else                                         << 
410     fMinEnergyTR = fTheMinEnergyTR;            << 
411                                                << 
412   if(fGammaTkinCut > fTheMaxEnergyTR)          << 
413     fMaxEnergyTR = 2.0 * fGammaTkinCut;        << 
414   else                                         << 
415     fMaxEnergyTR = fTheMaxEnergyTR;            << 
416                                                << 
417   auto energyVector =                          << 
418     new G4PhysicsLogVector(fMinEnergyTR, fMaxE << 
419                                                << 
420   G4Integrator<G4VXTRenergyLoss, G4double (G4V << 
421     integral;                                  << 
422                                                << 
423   G4cout.precision(4);                         << 
424   G4Timer timer;                               << 
425   timer.Start();                               << 
426                                                << 
427   for(iTkin = 0; iTkin < fTotBin; ++iTkin)  // << 
428   {                                            << 
429     fGamma =                                   << 
430       1.0 + (fProtonEnergyVector->GetLowEdgeEn << 
431                                                << 
432     if(fMaxThetaTR > fTheMaxAngle)             << 
433       fMaxThetaTR = fTheMaxAngle;              << 
434     else if(fMaxThetaTR < fTheMinAngle)        << 
435       fMaxThetaTR = fTheMinAngle;              << 
436                                                << 
437     fAngleForEnergyTable = new G4PhysicsTable( << 
438                                                << 
439     for(iTR = 0; iTR < fBinTR; ++iTR)          << 
440     {                                          << 
441       angleSum = 0.0;                          << 
442       fEnergy  = energyVector->GetLowEdgeEnerg << 
443                                                << 
444      // log-vector to increase number of thin  << 
445       auto angleVector = new G4PhysicsLogVecto << 
446                                                << 
447                                                << 
448                                                << 
449       angleVector->PutValue(fBinTR - 1, angleS << 
450                                                << 
451       for(i = fBinTR - 2; i >= 0; --i)         << 
452       {                                        << 
453         // Legendre96 or Legendre10            << 
454                                                << 
455         angleSum +=                            << 
456           integral.Legendre10(this, &G4VXTRene << 
457                               angleVector->Get << 
458                               angleVector->Get << 
459                                                << 
460         angleVector->PutValue(i, angleSum);    << 
461       }                                        << 
462       fAngleForEnergyTable->insertAt(iTR, angl << 
463     }                                          << 
464     fAngleBank.push_back(fAngleForEnergyTable) << 
465   }                                            << 
466   timer.Stop();                                << 
467   G4cout.precision(6);                         << 
468   if(verboseLevel > 0)                         << 
469   {                                            << 
470     G4cout << G4endl;                          << 
471     G4cout << "total time for build X-ray TR a << 
472            << timer.GetUserElapsed() << " s" < << 
473   }                                            << 
474   fGamma = 0.;                                 << 
475   delete energyVector;                         << 
476 }                                                 386 }
477                                                   387 
478 //////////////////////////////////////////////    388 ////////////////////////////////////////////////////////////////////////
479 // Build XTR angular distribution at given ene << 389 //
                                                   >> 390 // Build XTR angular distribution at given energy based on the model 
480 // of transparent regular radiator                391 // of transparent regular radiator
                                                   >> 392 
481 void G4VXTRenergyLoss::BuildAngleTable()          393 void G4VXTRenergyLoss::BuildAngleTable()
482 {                                                 394 {
483   G4int iTkin, iTR;                               395   G4int iTkin, iTR;
484   G4double energy;                             << 396   G4double  energy;
485                                                   397 
486   fGammaTkinCut = 0.0;                            398   fGammaTkinCut = 0.0;
487                                                << 399                               
488   // setting of min/max TR energies            << 400   // setting of min/max TR energies 
489   if(fGammaTkinCut > fTheMinEnergyTR)          << 401   
490     fMinEnergyTR = fGammaTkinCut;              << 402   if(fGammaTkinCut > fTheMinEnergyTR)  fMinEnergyTR = fGammaTkinCut;
491   else                                         << 403   else                                 fMinEnergyTR = fTheMinEnergyTR;
492     fMinEnergyTR = fTheMinEnergyTR;            << 404   
493                                                << 405   if(fGammaTkinCut > fTheMaxEnergyTR) fMaxEnergyTR = 2.0*fGammaTkinCut;  
494   if(fGammaTkinCut > fTheMaxEnergyTR)          << 406   else                                fMaxEnergyTR = fTheMaxEnergyTR;
495     fMaxEnergyTR = 2.0 * fGammaTkinCut;        << 
496   else                                         << 
497     fMaxEnergyTR = fTheMaxEnergyTR;            << 
498                                                   407 
499   G4cout.precision(4);                            408   G4cout.precision(4);
500   G4Timer timer;                                  409   G4Timer timer;
501   timer.Start();                                  410   timer.Start();
502   if(verboseLevel > 0)                         << 411   if(verboseLevel > 0) {
503   {                                            << 412     G4cout<<G4endl;
504     G4cout << G4endl << "Lorentz Factor" << "\ << 413     G4cout<<"Lorentz Factor"<<"\t"<<"XTR photon number"<<G4endl;
505            << "XTR photon number" << G4endl << << 414     G4cout<<G4endl;
506   }                                               415   }
507   for(iTkin = 0; iTkin < fTotBin; ++iTkin)  // << 416   for( iTkin = 0 ; iTkin < fTotBin ; iTkin++ )      // Lorentz factor loop
508   {                                               417   {
509     fGamma =                                   << 418     
510       1.0 + (fProtonEnergyVector->GetLowEdgeEn << 419     fGamma = 1.0 + (fProtonEnergyVector->
                                                   >> 420                             GetLowEdgeEnergy(iTkin)/proton_mass_c2) ;
511                                                   421 
512     // fMaxThetaTR = 25. * 2500.0 / (fGamma *  << 422     fMaxThetaTR = 25.0/(fGamma*fGamma) ;  // theta^2
513                                                   423 
514     if(fMaxThetaTR > fTheMaxAngle)             << 424     fTheMinAngle = 1.0e-3 ; // was 5.e-6, e-6 !!!, e-5, e-4
515       fMaxThetaTR = fTheMaxAngle;              << 425  
                                                   >> 426     if( fMaxThetaTR > fTheMaxAngle )    fMaxThetaTR = fTheMaxAngle; 
516     else                                          427     else
517     {                                             428     {
518       if(fMaxThetaTR < fTheMinAngle)           << 429        if( fMaxThetaTR < fTheMinAngle )  fMaxThetaTR = fTheMinAngle;
519         fMaxThetaTR = fTheMinAngle;            << 
520     }                                             430     }
521                                                   431 
522     fAngleForEnergyTable = new G4PhysicsTable(    432     fAngleForEnergyTable = new G4PhysicsTable(fBinTR);
523                                                   433 
524     for(iTR = 0; iTR < fBinTR; ++iTR)          << 434     for( iTR = 0; iTR < fBinTR; iTR++ )
525     {                                             435     {
                                                   >> 436       // energy = fMinEnergyTR*(iTR+1);
                                                   >> 437 
526       energy = fXTREnergyVector->GetLowEdgeEne    438       energy = fXTREnergyVector->GetLowEdgeEnergy(iTR);
527                                                   439 
528       G4PhysicsFreeVector* angleVector = GetAn << 440       G4PhysicsFreeVector* angleVector = GetAngleVector(energy,fBinTR);
                                                   >> 441       // G4cout<<G4endl;
529                                                   442 
530       fAngleForEnergyTable->insertAt(iTR, angl << 443       fAngleForEnergyTable->insertAt(iTR,angleVector) ;
531     }                                             444     }
532     fAngleBank.push_back(fAngleForEnergyTable) << 445     
533   }                                            << 446     fAngleBank.push_back(fAngleForEnergyTable); 
                                                   >> 447   }     
534   timer.Stop();                                   448   timer.Stop();
535   G4cout.precision(6);                            449   G4cout.precision(6);
536   if(verboseLevel > 0)                         << 450   if(verboseLevel > 0) {
537   {                                            << 451     G4cout<<G4endl;
538     G4cout << G4endl;                          << 452     G4cout<<"total time for build XTR angle for given energy tables = "
539     G4cout << "total time for build XTR angle  << 453     <<timer.GetUserElapsed()<<" s"<<G4endl;
540            << timer.GetUserElapsed() << " s" < << 
541   }                                               454   }
542   fGamma = 0.;                                    455   fGamma = 0.;
543                                                << 456   
544   return;                                         457   return;
545 }                                              << 458 } 
546                                                   459 
547 //////////////////////////////////////////////    460 /////////////////////////////////////////////////////////////////////////
                                                   >> 461 //
548 // Vector of angles and angle integral distrib    462 // Vector of angles and angle integral distributions
                                                   >> 463 
549 G4PhysicsFreeVector* G4VXTRenergyLoss::GetAngl    464 G4PhysicsFreeVector* G4VXTRenergyLoss::GetAngleVector(G4double energy, G4int n)
550 {                                                 465 {
551   G4double theta = 0., result, tmp = 0., cof1, << 466   G4double theta=0., result, tmp=0., cof1, cof2, cofMin, cofPHC, angleSum  = 0.;
552            angleSum = 0.;                      << 467   G4int iTheta, k, /*kMax,*/ kMin;
553   G4int iTheta, k, kMin;                       << 468 
554                                                << 469   G4PhysicsFreeVector* angleVector = new G4PhysicsFreeVector(n);
555   auto angleVector = new G4PhysicsFreeVector(n << 470   
556                                                << 471   cofPHC  = 4*pi*hbarc;
557   cofPHC = 4. * pi * hbarc;                    << 472   tmp     = (fSigma1 - fSigma2)/cofPHC/energy;
558   tmp    = (fSigma1 - fSigma2) / cofPHC / ener << 473   cof1    = fPlateThick*tmp;
559   cof1   = fPlateThick * tmp;                  << 474   cof2    = fGasThick*tmp;
560   cof2   = fGasThick * tmp;                    << 
561                                                   475 
562   cofMin = energy * (fPlateThick + fGasThick)  << 476   cofMin  =  energy*(fPlateThick + fGasThick)/fGamma/fGamma;
563   cofMin += (fPlateThick * fSigma1 + fGasThick << 477   cofMin += (fPlateThick*fSigma1 + fGasThick*fSigma2)/energy;
564   cofMin /= cofPHC;                               478   cofMin /= cofPHC;
565                                                   479 
566   kMin = G4int(cofMin);                           480   kMin = G4int(cofMin);
567   if(cofMin > kMin)                            << 481   if (cofMin > kMin) kMin++;
568     kMin++;                                    << 
569                                                   482 
                                                   >> 483   //kMax = kMin + fBinTR -1;
570   if(verboseLevel > 2)                            484   if(verboseLevel > 2)
571   {                                               485   {
572     G4cout << "n-1 = " << n - 1                << 486     G4cout<<"n-1 = "<<n-1<<"; theta = "
573            << "; theta = " << std::sqrt(fMaxTh << 487           <<std::sqrt(fMaxThetaTR)*fGamma<<"; tmp = "
574            << "; tmp = " << 0. << ";    angleS << 488           <<0. 
                                                   >> 489           <<";    angleSum = "<<angleSum<<G4endl; 
575   }                                               490   }
                                                   >> 491   angleVector->PutValue(n-1,fMaxThetaTR, angleSum);
576                                                   492 
577   for(iTheta = n - 1; iTheta >= 1; --iTheta)   << 493   for( iTheta = n - 2 ; iTheta >= 1 ; iTheta-- )
578   {                                               494   {
579     k      = iTheta - 1 + kMin;                << 
580     tmp    = pi * fPlateThick * (k + cof2) / ( << 
581     result = (k - cof1) * (k - cof1) * (k + co << 
582     tmp    = std::sin(tmp) * std::sin(tmp) * s << 
583                                                   495 
584     if(k == kMin && kMin == G4int(cofMin))     << 496     k = iTheta- 1 + kMin;
                                                   >> 497 
                                                   >> 498     tmp    = pi*fPlateThick*(k + cof2)/(fPlateThick + fGasThick);
                                                   >> 499 
                                                   >> 500     result = (k - cof1)*(k - cof1)*(k + cof2)*(k + cof2);
                                                   >> 501 
                                                   >> 502     tmp = std::sin(tmp)*std::sin(tmp)*std::abs(k-cofMin)/result;
                                                   >> 503 
                                                   >> 504     if( k == kMin && kMin == G4int(cofMin) )
585     {                                             505     {
586       // angleSum += 0.5 * tmp;                << 506       angleSum   += 0.5*tmp; // 0.5*std::sin(tmp)*std::sin(tmp)*std::abs(k-cofMin)/result;
587       angleSum += tmp; // ATLAS TB             << 
588     }                                             507     }
589     else if(iTheta == n - 1)                   << 
590       ;                                        << 
591     else                                          508     else
592     {                                             509     {
593       angleSum += tmp;                         << 510       angleSum   += tmp; // std::sin(tmp)*std::sin(tmp)*std::abs(k-cofMin)/result;
594     }                                             511     }
595     theta = std::abs(k - cofMin) * cofPHC / en << 512     theta = std::abs(k-cofMin)*cofPHC/energy/(fPlateThick + fGasThick);
596                                                << 
597     if(verboseLevel > 2)                          513     if(verboseLevel > 2)
598     {                                             514     {
599       G4cout << "iTheta = " << iTheta << "; k  << 515       G4cout<<"iTheta = "<<iTheta<<"; k = "<<k<<"; theta = "
600              << "; theta = " << std::sqrt(thet << 516             <<std::sqrt(theta)*fGamma<<"; tmp = "
601              << ";    angleSum = " << angleSum << 517             <<tmp // std::sin(tmp)*std::sin(tmp)*std::abs(k-cofMin)/result
                                                   >> 518             <<";    angleSum = "<<angleSum<<G4endl;
602     }                                             519     }
603     angleVector->PutValue(iTheta, theta, angle << 520     angleVector->PutValue( iTheta, theta, angleSum );       
604   }                                               521   }
605   if(theta > 0.)                               << 522   if (theta > 0.)
606   {                                               523   {
607     // angleSum += 0.5 * tmp;                  << 524     angleSum += 0.5*tmp;
608     angleSum += 0.;  // ATLAS TB               << 525     theta = 0.;
609     theta     = 0.;                            << 
610   }                                               526   }
611   if(verboseLevel > 2)                            527   if(verboseLevel > 2)
612   {                                               528   {
613     G4cout << "iTheta = " << iTheta << "; thet << 529     G4cout<<"iTheta = "<<iTheta<<"; theta = "
614            << "; tmp = " << tmp << ";    angle << 530           <<std::sqrt(theta)*fGamma<<"; tmp = "
                                                   >> 531           <<tmp 
                                                   >> 532           <<";    angleSum = "<<angleSum<<G4endl;
615   }                                               533   }
616   angleVector->PutValue(iTheta, theta, angleSu << 534   angleVector->PutValue( iTheta, theta, angleSum );
617                                                   535 
618   return angleVector;                             536   return angleVector;
619 }                                                 537 }
620                                                   538 
621 //////////////////////////////////////////////    539 ////////////////////////////////////////////////////////////////////////
622 // Build XTR angular distribution based on the << 540 //
623 // radiator                                    << 541 // Build XTR angular distribution based on the model of transparent regular radiator
                                                   >> 542 
624 void G4VXTRenergyLoss::BuildGlobalAngleTable()    543 void G4VXTRenergyLoss::BuildGlobalAngleTable()
625 {                                                 544 {
626   G4int iTkin, iTR, iPlace;                       545   G4int iTkin, iTR, iPlace;
627   G4double radiatorCof = 1.0;  // for tuning o << 546   G4double radiatorCof = 1.0;           // for tuning of XTR yield
628   G4double angleSum;                              547   G4double angleSum;
629   fAngleDistrTable = new G4PhysicsTable(fTotBi    548   fAngleDistrTable = new G4PhysicsTable(fTotBin);
630                                                   549 
631   fGammaTkinCut = 0.0;                            550   fGammaTkinCut = 0.0;
                                                   >> 551   
                                                   >> 552   // setting of min/max TR energies 
                                                   >> 553   
                                                   >> 554   if(fGammaTkinCut > fTheMinEnergyTR)  fMinEnergyTR = fGammaTkinCut ;
                                                   >> 555   else                                 fMinEnergyTR = fTheMinEnergyTR ;
                                                   >> 556   
                                                   >> 557   if(fGammaTkinCut > fTheMaxEnergyTR) fMaxEnergyTR = 2.0*fGammaTkinCut ;  
                                                   >> 558   else                                fMaxEnergyTR = fTheMaxEnergyTR ;
632                                                   559 
633   // setting of min/max TR energies            << 560   G4cout.precision(4) ;
634   if(fGammaTkinCut > fTheMinEnergyTR)          << 561   G4Timer timer ;
635     fMinEnergyTR = fGammaTkinCut;              << 562   timer.Start() ;
636   else                                         << 563   if(verboseLevel > 0) {
637     fMinEnergyTR = fTheMinEnergyTR;            << 564     G4cout<<G4endl;
638                                                << 565     G4cout<<"Lorentz Factor"<<"\t"<<"XTR photon number"<<G4endl;
639   if(fGammaTkinCut > fTheMaxEnergyTR)          << 566     G4cout<<G4endl;
640     fMaxEnergyTR = 2.0 * fGammaTkinCut;        << 567   }
641   else                                         << 568   for( iTkin = 0 ; iTkin < fTotBin ; iTkin++ )      // Lorentz factor loop
642     fMaxEnergyTR = fTheMaxEnergyTR;            << 569   {
643                                                << 570     
644   G4cout.precision(4);                         << 571     fGamma = 1.0 + (fProtonEnergyVector->
645   G4Timer timer;                               << 572                             GetLowEdgeEnergy(iTkin)/proton_mass_c2) ;
646   timer.Start();                               << 
647   if(verboseLevel > 0)                         << 
648   {                                            << 
649     G4cout << G4endl;                          << 
650     G4cout << "Lorentz Factor"                 << 
651            << "\t"                             << 
652            << "XTR photon number" << G4endl;   << 
653     G4cout << G4endl;                          << 
654   }                                            << 
655   for(iTkin = 0; iTkin < fTotBin; ++iTkin)  // << 
656   {                                            << 
657     fGamma =                                   << 
658       1.0 + (fProtonEnergyVector->GetLowEdgeEn << 
659                                                   573 
660     // fMaxThetaTR = 25.0 / (fGamma * fGamma); << 574     fMaxThetaTR = 25.0/(fGamma*fGamma) ;  // theta^2
661     // fMaxThetaTR = 1.e-4;  // theta^2        << 
662                                                   575 
663     if(fMaxThetaTR > fTheMaxAngle)             << 576     fTheMinAngle = 1.0e-3 ; // was 5.e-6, e-6 !!!, e-5, e-4
664       fMaxThetaTR = fTheMaxAngle;              << 577  
                                                   >> 578     if( fMaxThetaTR > fTheMaxAngle )    fMaxThetaTR = fTheMaxAngle; 
665     else                                          579     else
666     {                                             580     {
667       if(fMaxThetaTR < fTheMinAngle)           << 581        if( fMaxThetaTR < fTheMinAngle )  fMaxThetaTR = fTheMinAngle;
668         fMaxThetaTR = fTheMinAngle;            << 
669     }                                             582     }
670     auto angleVector =                         << 583     G4PhysicsLinearVector* angleVector = new G4PhysicsLinearVector(0.0,
671     // G4PhysicsLogVector* angleVector =       << 584                                                                fMaxThetaTR,
672       new G4PhysicsLinearVector(0.0, fMaxTheta << 585                                                                fBinTR      );
673     //  new G4PhysicsLogVector(1.e-8, fMaxThet << 
674                                                   586 
675     angleSum = 0.0;                            << 587     angleSum  = 0.0;
676                                                   588 
677     G4Integrator<G4VXTRenergyLoss, G4double (G << 589     G4Integrator<G4VXTRenergyLoss,G4double(G4VXTRenergyLoss::*)(G4double)> integral;
678       integral;                                << 
679                                                   590 
680     angleVector->PutValue(fBinTR - 1, angleSum << 591    
                                                   >> 592     angleVector->PutValue(fBinTR-1,angleSum);
681                                                   593 
682     for(iTR = fBinTR - 2; iTR >= 0; --iTR)     << 594     for( iTR = fBinTR - 2 ; iTR >= 0 ; iTR-- )
683     {                                             595     {
684       angleSum += radiatorCof * fCofTR *       << 
685                   integral.Legendre96(this, &G << 
686                                       angleVec << 
687                                       angleVec << 
688                                                   596 
689       angleVector->PutValue(iTR, angleSum);    << 597       angleSum  += radiatorCof*fCofTR*integral.Legendre96(
                                                   >> 598              this,&G4VXTRenergyLoss::AngleXTRdEdx,
                                                   >> 599              angleVector->GetLowEdgeEnergy(iTR),
                                                   >> 600              angleVector->GetLowEdgeEnergy(iTR+1) );
                                                   >> 601 
                                                   >> 602       angleVector ->PutValue(iTR,angleSum);
690     }                                             603     }
691     if(verboseLevel > 1)                       << 604     if(verboseLevel > 1) {
692     {                                          << 605       G4cout
693       G4cout << fGamma << "\t" << angleSum <<  << 606   // <<iTkin<<"\t"
                                                   >> 607   //   <<"fGamma = "
                                                   >> 608   <<fGamma<<"\t"  //  <<"  fMaxThetaTR = "<<fMaxThetaTR
                                                   >> 609   //  <<"sumN = "<<energySum      // <<" ; sumA = "
                                                   >> 610   <<angleSum
                                                   >> 611   <<G4endl;
694     }                                             612     }
695     iPlace = iTkin;                               613     iPlace = iTkin;
696     fAngleDistrTable->insertAt(iPlace, angleVe << 614     fAngleDistrTable->insertAt(iPlace,angleVector);
697   }                                            << 615   }     
698   timer.Stop();                                   616   timer.Stop();
699   G4cout.precision(6);                            617   G4cout.precision(6);
700   if(verboseLevel > 0)                         << 618   if(verboseLevel > 0) {
701   {                                            << 619     G4cout<<G4endl;
702     G4cout << G4endl;                          << 620     G4cout<<"total time for build X-ray TR angle tables = "
703     G4cout << "total time for build X-ray TR a << 621     <<timer.GetUserElapsed()<<" s"<<G4endl;
704            << timer.GetUserElapsed() << " s" < << 
705   }                                               622   }
706   fGamma = 0.;                                    623   fGamma = 0.;
707                                                << 624   
708   return;                                         625   return;
709 }                                              << 626 } 
                                                   >> 627 
710                                                   628 
711 //////////////////////////////////////////////    629 //////////////////////////////////////////////////////////////////////////////
712 // The main function which is responsible for  << 630 //
713 // passage through G4Envelope with discrete ge << 631 // The main function which is responsible for the treatment of a particle passage
714 G4VParticleChange* G4VXTRenergyLoss::PostStepD << 632 // trough G4Envelope with discrete generation of G4Gamma
715                                                << 633 
                                                   >> 634 G4VParticleChange* G4VXTRenergyLoss::PostStepDoIt( const G4Track& aTrack, 
                                                   >> 635                                       const G4Step&  aStep   )
716 {                                                 636 {
717   G4int iTkin;                                 << 637   G4int iTkin /*, iPlace*/;
718   G4double energyTR, theta, theta2, phi, dirX, << 638   G4double energyTR, theta,theta2, phi, dirX, dirY, dirZ;
                                                   >> 639  
719                                                   640 
720   fParticleChange.Initialize(aTrack);             641   fParticleChange.Initialize(aTrack);
721                                                   642 
722   if(verboseLevel > 1)                            643   if(verboseLevel > 1)
723   {                                               644   {
724     G4cout << "Start of G4VXTRenergyLoss::Post << 645     G4cout<<"Start of G4VXTRenergyLoss::PostStepDoIt "<<G4endl ;
725     G4cout << "name of current material =  "   << 646     G4cout<<"name of current material =  "
726            << aTrack.GetVolume()->GetLogicalVo << 647           <<aTrack.GetVolume()->GetLogicalVolume()->GetMaterial()->GetName()<<G4endl ;
727            << G4endl;                          << 
728   }                                               648   }
729   if(aTrack.GetVolume()->GetLogicalVolume() != << 649   if( aTrack.GetVolume()->GetLogicalVolume() != fEnvelope ) 
730   {                                               650   {
731     if(verboseLevel > 0)                          651     if(verboseLevel > 0)
732     {                                             652     {
733       G4cout << "Go out from G4VXTRenergyLoss: << 653       G4cout<<"Go out from G4VXTRenergyLoss::PostStepDoIt: wrong volume "<<G4endl;
734              << G4endl;                        << 
735     }                                             654     }
736     return G4VDiscreteProcess::PostStepDoIt(aT    655     return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
737   }                                               656   }
738   else                                            657   else
739   {                                               658   {
740     G4StepPoint* pPostStepPoint        = aStep    659     G4StepPoint* pPostStepPoint        = aStep.GetPostStepPoint();
741     const G4DynamicParticle* aParticle = aTrac    660     const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
742                                                << 661    
743     // Now we are ready to Generate one TR pho    662     // Now we are ready to Generate one TR photon
744     G4double kinEnergy = aParticle->GetKinetic << 
745     G4double mass      = aParticle->GetDefinit << 
746     G4double gamma     = 1.0 + kinEnergy / mas << 
747                                                   663 
748     if(verboseLevel > 1)                       << 664     G4double kinEnergy = aParticle->GetKineticEnergy() ;
                                                   >> 665     G4double mass      = aParticle->GetDefinition()->GetPDGMass() ;
                                                   >> 666     G4double gamma     = 1.0 + kinEnergy/mass ;
                                                   >> 667 
                                                   >> 668     if(verboseLevel > 1 )
749     {                                             669     {
750       G4cout << "gamma = " << gamma << G4endl; << 670       G4cout<<"gamma = "<<gamma<<G4endl ;
751     }                                             671     }
752     G4double massRatio           = proton_mass << 672     G4double         massRatio   = proton_mass_c2/mass ;
753     G4double TkinScaled          = kinEnergy * << 673     G4double          TkinScaled = kinEnergy*massRatio ;
754     G4ThreeVector position       = pPostStepPo << 674     G4ThreeVector      position  = pPostStepPoint->GetPosition();
755     G4ParticleMomentum direction = aParticle->    675     G4ParticleMomentum direction = aParticle->GetMomentumDirection();
756     G4double startTime           = pPostStepPo << 676     G4double           startTime = pPostStepPoint->GetGlobalTime();
757                                                   677 
758     for(iTkin = 0; iTkin < fTotBin; ++iTkin)   << 678     for( iTkin = 0; iTkin < fTotBin; iTkin++ )
759     {                                             679     {
760       if(TkinScaled < fProtonEnergyVector->Get << 680       if(TkinScaled < fProtonEnergyVector->GetLowEdgeEnergy(iTkin))  break;    
761         break;                                 << 
762     }                                             681     }
                                                   >> 682     //iPlace = iTkin - 1;
763                                                   683 
764     if(iTkin == 0)  // Tkin is too small, negl << 684     if(iTkin == 0) // Tkin is too small, neglect of TR photon generation
765     {                                             685     {
766       if(verboseLevel > 0)                     << 686       if( verboseLevel > 0)
767       {                                           687       {
768         G4cout << "Go out from G4VXTRenergyLos << 688         G4cout<<"Go out from G4VXTRenergyLoss::PostStepDoIt:iTkin = "<<iTkin<<G4endl;
769                << G4endl;                      << 
770       }                                           689       }
771       return G4VDiscreteProcess::PostStepDoIt(    690       return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
772     }                                          << 691     } 
773     else  // general case: Tkin between two ve << 692     else          // general case: Tkin between two vectors of the material
774     {                                             693     {
775       fParticleChange.SetNumberOfSecondaries(1    694       fParticleChange.SetNumberOfSecondaries(1);
776                                                   695 
777       energyTR = GetXTRrandomEnergy(TkinScaled << 696       energyTR = GetXTRrandomEnergy(TkinScaled,iTkin);
778                                                   697 
779       if(verboseLevel > 1)                     << 698       if( verboseLevel > 1)
780       {                                           699       {
781         G4cout << "energyTR = " << energyTR /  << 700   G4cout<<"energyTR = "<<energyTR/keV<<" keV"<<G4endl;
782       }                                           701       }
783       if(fAngleRadDistr)                       << 702       if (fAngleRadDistr)
784       {                                           703       {
785         theta2 = GetRandomAngle(energyTR, iTki << 704         // theta = std::fabs(G4RandGauss::shoot(0.0,pi/gamma));
786         if(theta2 > 0.)                        << 705         theta2 = GetRandomAngle(energyTR,iTkin);
787           theta = std::sqrt(theta2);           << 706         if(theta2 > 0.) theta = std::sqrt(theta2);
788         else                                   << 707         else            theta = theta2;
789           theta = 0.;                          << 
790       }                                           708       }
791       else                                     << 709       else theta = std::fabs(G4RandGauss::shoot(0.0,pi/gamma));
792         theta = std::fabs(G4RandGauss::shoot(0 << 710 
                                                   >> 711       if( theta >= 0.1 ) theta = 0.1;
793                                                   712 
794       if(theta >= 0.1)                         << 713       // G4cout<<" : theta = "<<theta<<endl ;
795         theta = 0.1;                           << 
796                                                   714 
797       phi = twopi * G4UniformRand();           << 715       phi = twopi*G4UniformRand();
798                                                   716 
799       dirX = std::sin(theta) * std::cos(phi);  << 717       dirX = std::sin(theta)*std::cos(phi);
800       dirY = std::sin(theta) * std::sin(phi);  << 718       dirY = std::sin(theta)*std::sin(phi);
801       dirZ = std::cos(theta);                     719       dirZ = std::cos(theta);
802                                                   720 
803       G4ThreeVector directionTR(dirX, dirY, di << 721       G4ThreeVector directionTR(dirX,dirY,dirZ);
804       directionTR.rotateUz(direction);            722       directionTR.rotateUz(direction);
805       directionTR.unit();                         723       directionTR.unit();
806                                                   724 
807       auto aPhotonTR =                         << 725       G4DynamicParticle* aPhotonTR = new G4DynamicParticle(G4Gamma::Gamma(),
808         new G4DynamicParticle(G4Gamma::Gamma() << 726                                                            directionTR, energyTR);
809                                                   727 
810       // A XTR photon is set on the particle t << 728       // A XTR photon is set on the particle track inside the radiator 
811       // and is moved to the G4Envelope surfac    729       // and is moved to the G4Envelope surface for standard X-ray TR models
812       // only. The case of fExitFlux=true         730       // only. The case of fExitFlux=true
813                                                   731 
814       if(fExitFlux)                            << 732       if( fExitFlux )
815       {                                           733       {
816         const G4RotationMatrix* rotM =         << 734         const G4RotationMatrix* rotM = pPostStepPoint->GetTouchable()->GetRotation();
817           pPostStepPoint->GetTouchable()->GetR << 
818         G4ThreeVector transl = pPostStepPoint-    735         G4ThreeVector transl = pPostStepPoint->GetTouchable()->GetTranslation();
819         G4AffineTransform transform = G4Affine << 736         G4AffineTransform transform = G4AffineTransform(rotM,transl);
820         transform.Invert();                       737         transform.Invert();
821         G4ThreeVector localP = transform.Trans    738         G4ThreeVector localP = transform.TransformPoint(position);
822         G4ThreeVector localV = transform.Trans    739         G4ThreeVector localV = transform.TransformAxis(directionTR);
823                                                   740 
824         G4double distance =                    << 741         G4double distance = fEnvelope->GetSolid()->DistanceToOut(localP, localV);
825           fEnvelope->GetSolid()->DistanceToOut << 
826         if(verboseLevel > 1)                      742         if(verboseLevel > 1)
827         {                                         743         {
828           G4cout << "distance to exit = " << d << 744           G4cout<<"distance to exit = "<<distance/mm<<" mm"<<G4endl;
829         }                                         745         }
830         position += distance * directionTR;    << 746         position         += distance*directionTR;
831         startTime += distance / c_light;       << 747         startTime        += distance/c_light;
832       }                                           748       }
833       G4Track* aSecondaryTrack = new G4Track(a << 749       G4Track* aSecondaryTrack = new G4Track( aPhotonTR, 
                                                   >> 750                                     startTime, position );
834       aSecondaryTrack->SetTouchableHandle(        751       aSecondaryTrack->SetTouchableHandle(
835         aStep.GetPostStepPoint()->GetTouchable << 752                          aStep.GetPostStepPoint()->GetTouchableHandle());
836       aSecondaryTrack->SetParentID(aTrack.GetT << 753       aSecondaryTrack->SetParentID( aTrack.GetTrackID() );
837                                                   754 
838       fParticleChange.AddSecondary(aSecondaryT    755       fParticleChange.AddSecondary(aSecondaryTrack);
839       fParticleChange.ProposeEnergy(kinEnergy) << 756       fParticleChange.ProposeEnergy(kinEnergy);     
840     }                                             757     }
841   }                                               758   }
842   return G4VDiscreteProcess::PostStepDoIt(aTra    759   return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep);
843 }                                                 760 }
844                                                   761 
845 //////////////////////////////////////////////    762 ///////////////////////////////////////////////////////////////////////
                                                   >> 763 //
846 // This function returns the spectral and angl    764 // This function returns the spectral and angle density of TR quanta
847 // in X-ray energy region generated forward wh    765 // in X-ray energy region generated forward when a relativistic
848 // charged particle crosses interface between     766 // charged particle crosses interface between two materials.
849 // The high energy small theta approximation i    767 // The high energy small theta approximation is applied.
850 // (matter1 -> matter2, or 2->1)                  768 // (matter1 -> matter2, or 2->1)
851 // varAngle =2* (1 - std::cos(theta)) or appro    769 // varAngle =2* (1 - std::cos(theta)) or approximately = theta*theta
852 G4complex G4VXTRenergyLoss::OneInterfaceXTRdEd << 770 //
853                                                << 771 
854 {                                              << 772 G4complex G4VXTRenergyLoss::OneInterfaceXTRdEdx( G4double energy,
855   G4complex Z1 = GetPlateComplexFZ(energy, gam << 773                                            G4double gamma,
856   G4complex Z2 = GetGasComplexFZ(energy, gamma << 774                                            G4double varAngle ) 
                                                   >> 775 {
                                                   >> 776   G4complex Z1    = GetPlateComplexFZ(energy,gamma,varAngle) ;
                                                   >> 777   G4complex Z2    = GetGasComplexFZ(energy,gamma,varAngle) ;
                                                   >> 778 
                                                   >> 779   G4complex zOut  = (Z1 - Z2)*(Z1 - Z2)
                                                   >> 780                     * (varAngle*energy/hbarc/hbarc) ;  
                                                   >> 781   return    zOut  ;
857                                                   782 
858   G4complex zOut = (Z1 - Z2) * (Z1 - Z2) * (va << 
859   return zOut;                                 << 
860 }                                                 783 }
861                                                   784 
                                                   >> 785 
862 //////////////////////////////////////////////    786 //////////////////////////////////////////////////////////////////////////////
                                                   >> 787 //
863 // For photon energy distribution tables. Inte    788 // For photon energy distribution tables. Integrate first over angle
                                                   >> 789 //
                                                   >> 790 
864 G4double G4VXTRenergyLoss::SpectralAngleXTRdEd    791 G4double G4VXTRenergyLoss::SpectralAngleXTRdEdx(G4double varAngle)
865 {                                                 792 {
866   G4double result = GetStackFactor(fEnergy, fG << 793   G4double result =  GetStackFactor(fEnergy,fGamma,varAngle);
867   if(result < 0.0)                             << 794   if(result < 0.0) result = 0.0;
868     result = 0.0;                              << 
869   return result;                                  795   return result;
870 }                                                 796 }
871                                                   797 
872 //////////////////////////////////////////////    798 /////////////////////////////////////////////////////////////////////////
                                                   >> 799 //
873 // For second integration over energy             800 // For second integration over energy
                                                   >> 801  
874 G4double G4VXTRenergyLoss::SpectralXTRdEdx(G4d    802 G4double G4VXTRenergyLoss::SpectralXTRdEdx(G4double energy)
875 {                                                 803 {
876   G4int i;                                     << 804   G4int i, iMax = 8;
877   static constexpr G4int iMax = 8;             << 805   G4double result = 0.0;
878   G4double angleSum           = 0.0;           << 
879                                                   806 
880   G4double lim[iMax] = { 0.0, 0.01, 0.02, 0.05 << 807   G4double lim[8] = { 0.0, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1.0 };
881                                                   808 
882   for(i = 0; i < iMax; ++i)                    << 809   for( i = 0; i < iMax; i++ ) lim[i] *= fMaxThetaTR;
883     lim[i] *= fMaxThetaTR;                     << 
884                                                   810 
885   G4Integrator<G4VXTRenergyLoss, G4double (G4V << 811   G4Integrator<G4VXTRenergyLoss,G4double(G4VXTRenergyLoss::*)(G4double)> integral;
886     integral;                                  << 
887                                                   812 
888   fEnergy = energy;                               813   fEnergy = energy;
                                                   >> 814 
                                                   >> 815   for( i = 0; i < iMax-1; i++ )
889   {                                               816   {
890     for(i = 0; i < iMax - 1; ++i)              << 817     result += integral.Legendre96(this,&G4VXTRenergyLoss::SpectralAngleXTRdEdx,
891     {                                          << 818              lim[i],lim[i+1]);
892       angleSum += integral.Legendre96(         << 819     // result += integral.Legendre10(this,&G4VXTRenergyLoss::SpectralAngleXTRdEdx,
893         this, &G4VXTRenergyLoss::SpectralAngle << 820     //         lim[i],lim[i+1]);
894     }                                          << 
895   }                                               821   }
896   return angleSum;                             << 
897 }                                              << 
898                                                   822 
                                                   >> 823   return result;
                                                   >> 824 } 
                                                   >> 825  
899 //////////////////////////////////////////////    826 //////////////////////////////////////////////////////////////////////////
                                                   >> 827 // 
900 // for photon angle distribution tables           828 // for photon angle distribution tables
                                                   >> 829 //
                                                   >> 830 
901 G4double G4VXTRenergyLoss::AngleSpectralXTRdEd    831 G4double G4VXTRenergyLoss::AngleSpectralXTRdEdx(G4double energy)
902 {                                                 832 {
903   G4double result = GetStackFactor(energy, fGa << 833   G4double result =  GetStackFactor(energy,fGamma,fVarAngle);
904   if(result < 0)                               << 834   if(result < 0) result = 0.0;
905     result = 0.0;                              << 
906   return result;                                  835   return result;
907 }                                              << 836 } 
908                                                   837 
909 //////////////////////////////////////////////    838 ///////////////////////////////////////////////////////////////////////////
                                                   >> 839 //
910 // The XTR angular distribution based on trans    840 // The XTR angular distribution based on transparent regular radiator
911 G4double G4VXTRenergyLoss::AngleXTRdEdx(G4doub << 841 
                                                   >> 842 G4double G4VXTRenergyLoss::AngleXTRdEdx(G4double varAngle) 
912 {                                                 843 {
                                                   >> 844   // G4cout<<"angle2 = "<<varAngle<<"; fGamma = "<<fGamma<<G4endl;
                                                   >> 845  
913   G4double result;                                846   G4double result;
914   G4double sum = 0., tmp1, tmp2, tmp = 0., cof << 847   G4double sum = 0., tmp1, tmp2, tmp=0., cof1, cof2, cofMin, cofPHC, energy1, energy2;
915            energy2;                            << 
916   G4int k, kMax, kMin, i;                         848   G4int k, kMax, kMin, i;
917                                                   849 
918   cofPHC = twopi * hbarc;                      << 850   cofPHC  = twopi*hbarc;
                                                   >> 851 
                                                   >> 852   cof1    = (fPlateThick + fGasThick)*(1./fGamma/fGamma + varAngle);
                                                   >> 853   cof2    = fPlateThick*fSigma1 + fGasThick*fSigma2;
919                                                   854 
920   cof1 = (fPlateThick + fGasThick) * (1. / fGa << 855   // G4cout<<"cof1 = "<<cof1<<"; cof2 = "<<cof2<<"; cofPHC = "<<cofPHC<<G4endl; 
921   cof2 = fPlateThick * fSigma1 + fGasThick * f << 
922                                                   856 
923   cofMin = std::sqrt(cof1 * cof2);             << 857   cofMin  =  std::sqrt(cof1*cof2); 
924   cofMin /= cofPHC;                               858   cofMin /= cofPHC;
925                                                   859 
926   kMin = G4int(cofMin);                           860   kMin = G4int(cofMin);
927   if(cofMin > kMin)                            << 861   if (cofMin > kMin) kMin++;
928     kMin++;                                    << 
929                                                   862 
930   kMax = kMin + 9;                             << 863   kMax = kMin + 9; //  9; // kMin + G4int(tmp);
931                                                   864 
932   for(k = kMin; k <= kMax; ++k)                << 865   // G4cout<<"cofMin = "<<cofMin<<"; kMin = "<<kMin<<"; kMax = "<<kMax<<G4endl;
                                                   >> 866 
                                                   >> 867   for( k = kMin; k <= kMax; k++ )
933   {                                               868   {
934     tmp1    = cofPHC * k;                      << 869     tmp1 = cofPHC*k;
935     tmp2    = std::sqrt(tmp1 * tmp1 - cof1 * c << 870     tmp2 = std::sqrt(tmp1*tmp1-cof1*cof2);
936     energy1 = (tmp1 + tmp2) / cof1;            << 871     energy1 = (tmp1+tmp2)/cof1;
937     energy2 = (tmp1 - tmp2) / cof1;            << 872     energy2 = (tmp1-tmp2)/cof1;
938                                                   873 
939     for(i = 0; i < 2; ++i)                     << 874     for(i = 0; i < 2; i++)
940     {                                             875     {
941       if(i == 0)                               << 876       if( i == 0 )
942       {                                           877       {
943         if(energy1 > fTheMaxEnergyTR || energy << 878         if (energy1 > fTheMaxEnergyTR || energy1 < fTheMinEnergyTR) continue;
944           continue;                            << 879         tmp1 = ( energy1*energy1*(1./fGamma/fGamma + varAngle) + fSigma1 )
945                                                << 880     * fPlateThick/(4*hbarc*energy1);
946         tmp1 =                                 << 
947           (energy1 * energy1 * (1. / fGamma /  << 
948           fPlateThick / (4 * hbarc * energy1); << 
949         tmp2 = std::sin(tmp1);                    881         tmp2 = std::sin(tmp1);
950         tmp  = energy1 * tmp2 * tmp2;          << 882         tmp  = energy1*tmp2*tmp2;
951         tmp2 = fPlateThick / (4. * tmp1);      << 883         tmp2 = fPlateThick/(4*tmp1);
952         tmp1 =                                 << 884         tmp1 = hbarc*energy1/( energy1*energy1*(1./fGamma/fGamma + varAngle) + fSigma2 );
953           hbarc * energy1 /                    << 885   tmp *= (tmp1-tmp2)*(tmp1-tmp2);
954           (energy1 * energy1 * (1. / fGamma /  << 886   tmp1 = cof1/(4*hbarc) - cof2/(4*hbarc*energy1*energy1);
955         tmp *= (tmp1 - tmp2) * (tmp1 - tmp2);  << 887   tmp2 = std::abs(tmp1);
956         tmp1 = cof1 / (4. * hbarc) - cof2 / (4 << 888   if(tmp2 > 0.) tmp /= tmp2;
957         tmp2 = std::abs(tmp1);                 << 889         else continue;
958                                                << 
959         if(tmp2 > 0.)                          << 
960           tmp /= tmp2;                         << 
961         else                                   << 
962           continue;                            << 
963       }                                           890       }
964       else                                        891       else
965       {                                           892       {
966         if(energy2 > fTheMaxEnergyTR || energy << 893         if (energy2 > fTheMaxEnergyTR || energy2 < fTheMinEnergyTR) continue;
967           continue;                            << 894         tmp1 = ( energy2*energy2*(1./fGamma/fGamma + varAngle) + fSigma1 )
968                                                << 895     * fPlateThick/(4*hbarc*energy2);
969         tmp1 =                                 << 
970           (energy2 * energy2 * (1. / fGamma /  << 
971           fPlateThick / (4. * hbarc * energy2) << 
972         tmp2 = std::sin(tmp1);                    896         tmp2 = std::sin(tmp1);
973         tmp  = energy2 * tmp2 * tmp2;          << 897         tmp  = energy2*tmp2*tmp2;
974         tmp2 = fPlateThick / (4. * tmp1);      << 898         tmp2 = fPlateThick/(4*tmp1);
975         tmp1 =                                 << 899         tmp1 = hbarc*energy2/( energy2*energy2*(1./fGamma/fGamma + varAngle) + fSigma2 );
976           hbarc * energy2 /                    << 900   tmp *= (tmp1-tmp2)*(tmp1-tmp2);
977           (energy2 * energy2 * (1. / fGamma /  << 901   tmp1 = cof1/(4*hbarc) - cof2/(4*hbarc*energy2*energy2);
978         tmp *= (tmp1 - tmp2) * (tmp1 - tmp2);  << 902   tmp2 = std::abs(tmp1);
979         tmp1 = cof1 / (4. * hbarc) - cof2 / (4 << 903   if(tmp2 > 0.) tmp /= tmp2;
980         tmp2 = std::abs(tmp1);                 << 904         else continue;
981                                                << 
982         if(tmp2 > 0.)                          << 
983           tmp /= tmp2;                         << 
984         else                                   << 
985           continue;                            << 
986       }                                           905       }
987       sum += tmp;                                 906       sum += tmp;
988     }                                             907     }
                                                   >> 908     // G4cout<<"k = "<<k<<"; energy1 = "<<energy1/keV<<" keV; energy2 = "<<energy2/keV
                                                   >> 909     //  <<" keV; tmp = "<<tmp<<"; sum = "<<sum<<G4endl;
989   }                                               910   }
990   result = 4. * pi * fPlateNumber * sum * varA << 911   result = 4.*pi*fPlateNumber*sum*varAngle;
991   result /= hbarc * hbarc;                     << 912   result /= hbarc*hbarc;
992                                                   913 
                                                   >> 914   // old code based on general numeric integration
                                                   >> 915   // fVarAngle = varAngle;
                                                   >> 916   // G4Integrator<G4VXTRenergyLoss,G4double(G4VXTRenergyLoss::*)(G4double)> integral;
                                                   >> 917   // result = integral.Legendre10(this,&G4VXTRenergyLoss::AngleSpectralXTRdEdx,
                                                   >> 918   //           fMinEnergyTR,fMaxEnergyTR);
993   return result;                                  919   return result;
994 }                                                 920 }
995                                                   921 
                                                   >> 922 
996 //////////////////////////////////////////////    923 //////////////////////////////////////////////////////////////////////
                                                   >> 924 //////////////////////////////////////////////////////////////////////
                                                   >> 925 //////////////////////////////////////////////////////////////////////
                                                   >> 926 //
997 // Calculates formation zone for plates. Omega    927 // Calculates formation zone for plates. Omega is energy !!!
998 G4double G4VXTRenergyLoss::GetPlateFormationZo << 928 
999                                                << 929 G4double G4VXTRenergyLoss::GetPlateFormationZone( G4double omega ,
1000 {                                             << 930                                                 G4double gamma ,
1001   G4double cof, lambda;                       << 931                                                 G4double varAngle    ) 
1002   lambda = 1.0 / gamma / gamma + varAngle + f << 932 {
1003   cof    = 2.0 * hbarc / omega / lambda;      << 933   G4double cof, lambda ;
1004   return cof;                                 << 934   lambda = 1.0/gamma/gamma + varAngle + fSigma1/omega/omega ;
                                                   >> 935   cof = 2.0*hbarc/omega/lambda ;
                                                   >> 936   return cof ;
1005 }                                                937 }
1006                                                  938 
1007 /////////////////////////////////////////////    939 //////////////////////////////////////////////////////////////////////
                                                   >> 940 //
1008 // Calculates complex formation zone for plat    941 // Calculates complex formation zone for plates. Omega is energy !!!
1009 G4complex G4VXTRenergyLoss::GetPlateComplexFZ << 942 
1010                                               << 943 G4complex G4VXTRenergyLoss::GetPlateComplexFZ( G4double omega ,
                                                   >> 944                                              G4double gamma ,
                                                   >> 945                                              G4double varAngle    ) 
1011 {                                                946 {
1012   G4double cof, length, delta, real_v, image_ << 947   G4double cof, length,delta, real_v, image_v ;
1013                                                  948 
1014   length = 0.5 * GetPlateFormationZone(omega, << 949   length = 0.5*GetPlateFormationZone(omega,gamma,varAngle) ;
1015   delta  = length * GetPlateLinearPhotoAbs(om << 950   delta  = length*GetPlateLinearPhotoAbs(omega) ;
1016   cof    = 1.0 / (1.0 + delta * delta);       << 951   cof    = 1.0/(1.0 + delta*delta) ;
1017                                                  952 
1018   real_v  = length * cof;                     << 953   real_v  = length*cof ;
1019   image_v = real_v * delta;                   << 954   image_v = real_v*delta ;
1020                                                  955 
1021   G4complex zone(real_v, image_v);            << 956   G4complex zone(real_v,image_v); 
1022   return zone;                                << 957   return zone ;
1023 }                                                958 }
1024                                                  959 
1025 /////////////////////////////////////////////    960 ////////////////////////////////////////////////////////////////////////
                                                   >> 961 //
1026 // Computes matrix of Sandia photo absorption    962 // Computes matrix of Sandia photo absorption cross section coefficients for
1027 // plate material                                963 // plate material
1028 void G4VXTRenergyLoss::ComputePlatePhotoAbsCo << 964 
                                                   >> 965 void G4VXTRenergyLoss::ComputePlatePhotoAbsCof() 
1029 {                                                966 {
1030   const G4MaterialTable* theMaterialTable = G    967   const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
1031   const G4Material* mat                   = ( << 968   const G4Material* mat = (*theMaterialTable)[fMatIndex1];
1032   fPlatePhotoAbsCof                       = m << 969   fPlatePhotoAbsCof = mat->GetSandiaTable();
1033                                                  970 
1034   return;                                        971   return;
1035 }                                                972 }
1036                                                  973 
                                                   >> 974 
                                                   >> 975 
1037 /////////////////////////////////////////////    976 //////////////////////////////////////////////////////////////////////
1038 // Returns the value of linear photo absorpti << 977 //
                                                   >> 978 // Returns the value of linear photo absorption coefficient (in reciprocal 
1039 // length) for plate for given energy of X-ra    979 // length) for plate for given energy of X-ray photon omega
1040 G4double G4VXTRenergyLoss::GetPlateLinearPhot << 
1041 {                                             << 
1042   G4double omega2, omega3, omega4;            << 
1043                                                  980 
1044   omega2 = omega * omega;                     << 981 G4double G4VXTRenergyLoss::GetPlateLinearPhotoAbs(G4double omega) 
1045   omega3 = omega2 * omega;                    << 982 {
1046   omega4 = omega2 * omega2;                   << 983   //  G4int i ;
                                                   >> 984   G4double omega2, omega3, omega4 ; 
1047                                                  985 
1048   const G4double* SandiaCof = fPlatePhotoAbsC << 986   omega2 = omega*omega ;
1049   G4double cross            = SandiaCof[0] /  << 987   omega3 = omega2*omega ;
1050                    SandiaCof[2] / omega3 + Sa << 988   omega4 = omega2*omega2 ;
                                                   >> 989 
                                                   >> 990   G4double* SandiaCof = fPlatePhotoAbsCof->GetSandiaCofForMaterial(omega);
                                                   >> 991   G4double cross = SandiaCof[0]/omega  + SandiaCof[1]/omega2 +
                                                   >> 992                    SandiaCof[2]/omega3 + SandiaCof[3]/omega4;
1051   return cross;                                  993   return cross;
1052 }                                                994 }
1053                                                  995 
                                                   >> 996 
1054 /////////////////////////////////////////////    997 //////////////////////////////////////////////////////////////////////
                                                   >> 998 //
1055 // Calculates formation zone for gas. Omega i    999 // Calculates formation zone for gas. Omega is energy !!!
1056 G4double G4VXTRenergyLoss::GetGasFormationZon << 1000 
1057                                               << 1001 G4double G4VXTRenergyLoss::GetGasFormationZone( G4double omega ,
1058 {                                             << 1002                                               G4double gamma ,
1059   G4double cof, lambda;                       << 1003                                               G4double varAngle   ) 
1060   lambda = 1.0 / gamma / gamma + varAngle + f << 1004 {
1061   cof    = 2.0 * hbarc / omega / lambda;      << 1005   G4double cof, lambda ;
1062   return cof;                                 << 1006   lambda = 1.0/gamma/gamma + varAngle + fSigma2/omega/omega ;
                                                   >> 1007   cof = 2.0*hbarc/omega/lambda ;
                                                   >> 1008   return cof ;
1063 }                                                1009 }
1064                                                  1010 
                                                   >> 1011 
1065 /////////////////////////////////////////////    1012 //////////////////////////////////////////////////////////////////////
                                                   >> 1013 //
1066 // Calculates complex formation zone for gas     1014 // Calculates complex formation zone for gas gaps. Omega is energy !!!
1067 G4complex G4VXTRenergyLoss::GetGasComplexFZ(G << 1015 
1068                                             G << 1016 G4complex G4VXTRenergyLoss::GetGasComplexFZ( G4double omega ,
                                                   >> 1017                                            G4double gamma ,
                                                   >> 1018                                            G4double varAngle    ) 
1069 {                                                1019 {
1070   G4double cof, length, delta, real_v, image_ << 1020   G4double cof, length,delta, real_v, image_v ;
1071                                                  1021 
1072   length = 0.5 * GetGasFormationZone(omega, g << 1022   length = 0.5*GetGasFormationZone(omega,gamma,varAngle) ;
1073   delta  = length * GetGasLinearPhotoAbs(omeg << 1023   delta  = length*GetGasLinearPhotoAbs(omega) ;
1074   cof    = 1.0 / (1.0 + delta * delta);       << 1024   cof    = 1.0/(1.0 + delta*delta) ;
1075                                                  1025 
1076   real_v  = length * cof;                     << 1026   real_v   = length*cof ;
1077   image_v = real_v * delta;                   << 1027   image_v  = real_v*delta ;
1078                                                  1028 
1079   G4complex zone(real_v, image_v);            << 1029   G4complex zone(real_v,image_v); 
1080   return zone;                                << 1030   return zone ;
1081 }                                                1031 }
1082                                                  1032 
                                                   >> 1033 
                                                   >> 1034 
1083 /////////////////////////////////////////////    1035 ////////////////////////////////////////////////////////////////////////
                                                   >> 1036 //
1084 // Computes matrix of Sandia photo absorption    1037 // Computes matrix of Sandia photo absorption cross section coefficients for
1085 // gas material                                  1038 // gas material
1086 void G4VXTRenergyLoss::ComputeGasPhotoAbsCof( << 1039 
                                                   >> 1040 void G4VXTRenergyLoss::ComputeGasPhotoAbsCof() 
1087 {                                                1041 {
1088   const G4MaterialTable* theMaterialTable = G    1042   const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
1089   const G4Material* mat                   = ( << 1043   const G4Material* mat = (*theMaterialTable)[fMatIndex2];
1090   fGasPhotoAbsCof                         = m << 1044   fGasPhotoAbsCof = mat->GetSandiaTable();
1091   return;                                        1045   return;
1092 }                                                1046 }
1093                                                  1047 
1094 /////////////////////////////////////////////    1048 //////////////////////////////////////////////////////////////////////
1095 // Returns the value of linear photo absorpti << 1049 //
                                                   >> 1050 // Returns the value of linear photo absorption coefficient (in reciprocal 
1096 // length) for gas                               1051 // length) for gas
1097 G4double G4VXTRenergyLoss::GetGasLinearPhotoA << 1052 
                                                   >> 1053 G4double G4VXTRenergyLoss::GetGasLinearPhotoAbs(G4double omega) 
1098 {                                                1054 {
1099   G4double omega2, omega3, omega4;            << 1055   G4double omega2, omega3, omega4 ; 
1100                                                  1056 
1101   omega2 = omega * omega;                     << 1057   omega2 = omega*omega ;
1102   omega3 = omega2 * omega;                    << 1058   omega3 = omega2*omega ;
1103   omega4 = omega2 * omega2;                   << 1059   omega4 = omega2*omega2 ;
1104                                                  1060 
1105   const G4double* SandiaCof = fGasPhotoAbsCof << 1061   G4double* SandiaCof = fGasPhotoAbsCof->GetSandiaCofForMaterial(omega);
1106   G4double cross            = SandiaCof[0] /  << 1062   G4double cross = SandiaCof[0]/omega  + SandiaCof[1]/omega2 +
1107                    SandiaCof[2] / omega3 + Sa << 1063                    SandiaCof[2]/omega3 + SandiaCof[3]/omega4;
1108   return cross;                                  1064   return cross;
                                                   >> 1065 
1109 }                                                1066 }
1110                                                  1067 
1111 /////////////////////////////////////////////    1068 //////////////////////////////////////////////////////////////////////
1112 // Calculates the product of linear cof by fo << 1069 //
                                                   >> 1070 // Calculates the product of linear cof by formation zone for plate. 
1113 // Omega is energy !!!                           1071 // Omega is energy !!!
1114 G4double G4VXTRenergyLoss::GetPlateZmuProduct << 1072 
1115                                               << 1073 G4double G4VXTRenergyLoss::GetPlateZmuProduct( G4double omega ,
                                                   >> 1074                                              G4double gamma ,
                                                   >> 1075                                              G4double varAngle   ) 
1116 {                                                1076 {
1117   return GetPlateFormationZone(omega, gamma,  << 1077   return GetPlateFormationZone(omega,gamma,varAngle)
1118          GetPlateLinearPhotoAbs(omega);       << 1078     * GetPlateLinearPhotoAbs(omega) ;
1119 }                                                1079 }
1120 /////////////////////////////////////////////    1080 //////////////////////////////////////////////////////////////////////
1121 // Calculates the product of linear cof by fo << 1081 //
                                                   >> 1082 // Calculates the product of linear cof by formation zone for plate. 
1122 // G4cout and output in file in some energy r    1083 // G4cout and output in file in some energy range.
1123 void G4VXTRenergyLoss::GetPlateZmuProduct()   << 1084 
                                                   >> 1085 void G4VXTRenergyLoss::GetPlateZmuProduct() 
1124 {                                                1086 {
1125   std::ofstream outPlate("plateZmu.dat", std: << 1087   std::ofstream outPlate("plateZmu.dat", std::ios::out ) ;
1126   outPlate.setf(std::ios::scientific, std::io << 1088   outPlate.setf( std::ios::scientific, std::ios::floatfield );
1127                                                  1089 
1128   G4int i;                                    << 1090   G4int i ;
1129   G4double omega, varAngle, gamma;            << 1091   G4double omega, varAngle, gamma ;
1130   gamma    = 10000.;                          << 1092   gamma = 10000. ;
1131   varAngle = 1 / gamma / gamma;               << 1093   varAngle = 1/gamma/gamma ;
1132   if(verboseLevel > 0)                           1094   if(verboseLevel > 0)
1133     G4cout << "energy, keV" << "\t" << "Zmu f << 1095     G4cout<<"energy, keV"<<"\t"<<"Zmu for plate"<<G4endl ;
1134   for(i = 0; i < 100; ++i)                    << 1096   for(i=0;i<100;i++)
1135   {                                              1097   {
1136     omega = (1.0 + i) * keV;                  << 1098     omega = (1.0 + i)*keV ;
1137     if(verboseLevel > 1)                         1099     if(verboseLevel > 1)
1138       G4cout << omega / keV << "\t"           << 1100       G4cout<<omega/keV<<"\t"<<GetPlateZmuProduct(omega,gamma,varAngle)<<"\t";
1139              << GetPlateZmuProduct(omega, gam << 
1140     if(verboseLevel > 0)                         1101     if(verboseLevel > 0)
1141       outPlate << omega / keV << "\t\t"       << 1102       outPlate<<omega/keV<<"\t\t"<<GetPlateZmuProduct(omega,gamma,varAngle)<<G4endl ;
1142                << GetPlateZmuProduct(omega, g << 
1143   }                                              1103   }
1144   return;                                     << 1104   return  ;
1145 }                                                1105 }
1146                                                  1106 
1147 /////////////////////////////////////////////    1107 //////////////////////////////////////////////////////////////////////
1148 // Calculates the product of linear cof by fo << 1108 //
                                                   >> 1109 // Calculates the product of linear cof by formation zone for gas. 
1149 // Omega is energy !!!                           1110 // Omega is energy !!!
1150 G4double G4VXTRenergyLoss::GetGasZmuProduct(G << 1111 
1151                                             G << 1112 G4double G4VXTRenergyLoss::GetGasZmuProduct( G4double omega ,
                                                   >> 1113                                              G4double gamma ,
                                                   >> 1114                                              G4double varAngle   ) 
1152 {                                                1115 {
1153   return GetGasFormationZone(omega, gamma, va << 1116   return GetGasFormationZone(omega,gamma,varAngle)*GetGasLinearPhotoAbs(omega) ;
1154          GetGasLinearPhotoAbs(omega);         << 
1155 }                                                1117 }
1156                                               << 
1157 /////////////////////////////////////////////    1118 //////////////////////////////////////////////////////////////////////
1158 // Calculates the product of linear cof by fo << 1119 //
                                                   >> 1120 // Calculates the product of linear cof byformation zone for gas. 
1159 // G4cout and output in file in some energy r    1121 // G4cout and output in file in some energy range.
1160 void G4VXTRenergyLoss::GetGasZmuProduct()     << 1122 
                                                   >> 1123 void G4VXTRenergyLoss::GetGasZmuProduct() 
1161 {                                                1124 {
1162   std::ofstream outGas("gasZmu.dat", std::ios << 1125   std::ofstream outGas("gasZmu.dat", std::ios::out ) ;
1163   outGas.setf(std::ios::scientific, std::ios: << 1126   outGas.setf( std::ios::scientific, std::ios::floatfield );
1164   G4int i;                                    << 1127   G4int i ;
1165   G4double omega, varAngle, gamma;            << 1128   G4double omega, varAngle, gamma ;
1166   gamma    = 10000.;                          << 1129   gamma = 10000. ;
1167   varAngle = 1 / gamma / gamma;               << 1130   varAngle = 1/gamma/gamma ;
1168   if(verboseLevel > 0)                           1131   if(verboseLevel > 0)
1169     G4cout << "energy, keV" << "\t" << "Zmu f << 1132     G4cout<<"energy, keV"<<"\t"<<"Zmu for gas"<<G4endl ;
1170   for(i = 0; i < 100; ++i)                    << 1133   for(i=0;i<100;i++)
1171   {                                              1134   {
1172     omega = (1.0 + i) * keV;                  << 1135     omega = (1.0 + i)*keV ;
1173     if(verboseLevel > 1)                         1136     if(verboseLevel > 1)
1174       G4cout << omega / keV << "\t" << GetGas << 1137       G4cout<<omega/keV<<"\t"<<GetGasZmuProduct(omega,gamma,varAngle)<<"\t" ;
1175              << "\t";                         << 
1176     if(verboseLevel > 0)                         1138     if(verboseLevel > 0)
1177       outGas << omega / keV << "\t\t"         << 1139       outGas<<omega/keV<<"\t\t"<<GetGasZmuProduct(omega,gamma,varAngle)<<G4endl ;
1178              << GetGasZmuProduct(omega, gamma << 
1179   }                                              1140   }
1180   return;                                     << 1141   return  ;
1181 }                                                1142 }
1182                                                  1143 
1183 /////////////////////////////////////////////    1144 ////////////////////////////////////////////////////////////////////////
                                                   >> 1145 //
1184 // Computes Compton cross section for plate m    1146 // Computes Compton cross section for plate material in 1/mm
1185 G4double G4VXTRenergyLoss::GetPlateCompton(G4 << 1147 
                                                   >> 1148 G4double G4VXTRenergyLoss::GetPlateCompton(G4double omega) 
1186 {                                                1149 {
1187   G4int i, numberOfElements;                     1150   G4int i, numberOfElements;
1188   G4double xSection = 0., nowZ, sumZ = 0.;       1151   G4double xSection = 0., nowZ, sumZ = 0.;
1189                                                  1152 
1190   const G4MaterialTable* theMaterialTable = G    1153   const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
1191   numberOfElements = (G4int)(*theMaterialTabl << 1154   numberOfElements = (*theMaterialTable)[fMatIndex1]->GetNumberOfElements() ;
1192                                                  1155 
1193   for(i = 0; i < numberOfElements; ++i)       << 1156   for( i = 0; i < numberOfElements; i++ )
1194   {                                              1157   {
1195     nowZ = (*theMaterialTable)[fMatIndex1]->G << 1158     nowZ      = (*theMaterialTable)[fMatIndex1]->GetElement(i)->GetZ();
1196     sumZ += nowZ;                             << 1159     sumZ     += nowZ;
1197     xSection += GetComptonPerAtom(omega, nowZ << 1160     xSection += GetComptonPerAtom(omega,nowZ); // *nowZ;
1198   }                                              1161   }
1199   xSection /= sumZ;                              1162   xSection /= sumZ;
1200   xSection *= (*theMaterialTable)[fMatIndex1]    1163   xSection *= (*theMaterialTable)[fMatIndex1]->GetElectronDensity();
1201   return xSection;                               1164   return xSection;
1202 }                                                1165 }
1203                                                  1166 
                                                   >> 1167 
1204 /////////////////////////////////////////////    1168 ////////////////////////////////////////////////////////////////////////
                                                   >> 1169 //
1205 // Computes Compton cross section for gas mat    1170 // Computes Compton cross section for gas material in 1/mm
1206 G4double G4VXTRenergyLoss::GetGasCompton(G4do << 1171 
                                                   >> 1172 G4double G4VXTRenergyLoss::GetGasCompton(G4double omega) 
1207 {                                                1173 {
1208   G4double xSection = 0., sumZ = 0.;          << 1174   G4int i, numberOfElements;
                                                   >> 1175   G4double xSection = 0., nowZ, sumZ = 0.;
1209                                                  1176 
1210   const G4MaterialTable* theMaterialTable = G    1177   const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
1211   G4int numberOfElements = (G4int)(*theMateri << 1178   numberOfElements = (*theMaterialTable)[fMatIndex2]->GetNumberOfElements() ;
1212                                                  1179 
1213   for (G4int i = 0; i < numberOfElements; ++i << 1180   for( i = 0; i < numberOfElements; i++ )
1214   {                                              1181   {
1215     G4double nowZ = (*theMaterialTable)[fMatI << 1182     nowZ      = (*theMaterialTable)[fMatIndex2]->GetElement(i)->GetZ();
1216     sumZ += nowZ;                             << 1183     sumZ     += nowZ;
1217     xSection += GetComptonPerAtom(omega, nowZ << 1184     xSection += GetComptonPerAtom(omega,nowZ); // *nowZ;
1218   }                                              1185   }
1219   if (sumZ > 0.0) { xSection /= sumZ; }       << 1186   xSection /= sumZ;
1220   xSection *= (*theMaterialTable)[fMatIndex2]    1187   xSection *= (*theMaterialTable)[fMatIndex2]->GetElectronDensity();
1221   return xSection;                               1188   return xSection;
1222 }                                                1189 }
1223                                                  1190 
1224 /////////////////////////////////////////////    1191 ////////////////////////////////////////////////////////////////////////
                                                   >> 1192 //
1225 // Computes Compton cross section per atom wi    1193 // Computes Compton cross section per atom with Z electrons for gamma with
1226 // the energy GammaEnergy                        1194 // the energy GammaEnergy
1227 G4double G4VXTRenergyLoss::GetComptonPerAtom( << 1195 
                                                   >> 1196 G4double G4VXTRenergyLoss::GetComptonPerAtom(G4double GammaEnergy, G4double Z) 
1228 {                                                1197 {
1229   G4double CrossSection = 0.0;                << 1198   G4double CrossSection = 0.0 ;
1230   if(Z < 0.9999)                              << 1199   if ( Z < 0.9999 )                 return CrossSection;
1231     return CrossSection;                      << 1200   if ( GammaEnergy < 0.1*keV      ) return CrossSection;
1232   if(GammaEnergy < 0.1 * keV)                 << 1201   if ( GammaEnergy > (100.*GeV/Z) ) return CrossSection;
1233     return CrossSection;                      << 1202 
1234   if(GammaEnergy > (100. * GeV / Z))          << 1203   static const G4double a = 20.0 , b = 230.0 , c = 440.0;
1235     return CrossSection;                      << 1204 
1236                                               << 1205   static const G4double
1237   static constexpr G4double a = 20.0;         << 1206   d1= 2.7965e-1*barn, d2=-1.8300e-1*barn, d3= 6.7527   *barn, d4=-1.9798e+1*barn,
1238   static constexpr G4double b = 230.0;        << 1207   e1= 1.9756e-5*barn, e2=-1.0205e-2*barn, e3=-7.3913e-2*barn, e4= 2.7079e-2*barn,
1239   static constexpr G4double c = 440.0;        << 1208   f1=-3.9178e-7*barn, f2= 6.8241e-5*barn, f3= 6.0480e-5*barn, f4= 3.0274e-4*barn;
1240                                               << 1209 
1241   static constexpr G4double d1 = 2.7965e-1 *  << 1210   G4double p1Z = Z*(d1 + e1*Z + f1*Z*Z), p2Z = Z*(d2 + e2*Z + f2*Z*Z),
1242                             d3 = 6.7527 * bar << 1211            p3Z = Z*(d3 + e3*Z + f3*Z*Z), p4Z = Z*(d4 + e4*Z + f4*Z*Z);
1243                             e1 = 1.9756e-5 *  << 1212 
1244                             e3 = -7.3913e-2 * << 1213   G4double T0  = 15.0*keV;
1245                             f1 = -3.9178e-7 * << 1214   if (Z < 1.5) T0 = 40.0*keV;
1246                             f3 = 6.0480e-5 *  << 1215 
1247                                               << 1216   G4double X   = std::max(GammaEnergy, T0) / electron_mass_c2;
1248   G4double p1Z = Z * (d1 + e1 * Z + f1 * Z *  << 1217   CrossSection = p1Z*std::log(1.+2.*X)/X
1249   G4double p2Z = Z * (d2 + e2 * Z + f2 * Z *  << 1218                + (p2Z + p3Z*X + p4Z*X*X)/(1. + a*X + b*X*X + c*X*X*X);
1250   G4double p3Z = Z * (d3 + e3 * Z + f3 * Z *  << 
1251   G4double p4Z = Z * (d4 + e4 * Z + f4 * Z *  << 
1252                                               << 
1253   G4double T0 = 15.0 * keV;                   << 
1254   if(Z < 1.5)                                 << 
1255     T0 = 40.0 * keV;                          << 
1256                                               << 
1257   G4double X = std::max(GammaEnergy, T0) / el << 
1258   CrossSection =                              << 
1259     p1Z * std::log(1. + 2. * X) / X +         << 
1260     (p2Z + p3Z * X + p4Z * X * X) / (1. + a * << 
1261                                                  1219 
1262   //  modification for low energy. (special c    1220   //  modification for low energy. (special case for Hydrogen)
1263   if(GammaEnergy < T0)                        << 1221 
                                                   >> 1222   if (GammaEnergy < T0) 
1264   {                                              1223   {
1265     G4double dT0 = 1. * keV;                  << 1224     G4double dT0 = 1.*keV;
1266     X            = (T0 + dT0) / electron_mass << 1225     X = (T0+dT0) / electron_mass_c2 ;
1267     G4double sigma =                          << 1226     G4double sigma = p1Z*std::log(1.+2*X)/X
1268       p1Z * std::log(1. + 2. * X) / X +       << 1227                     + (p2Z + p3Z*X + p4Z*X*X)/(1. + a*X + b*X*X + c*X*X*X);
1269       (p2Z + p3Z * X + p4Z * X * X) / (1. + a << 1228     G4double   c1 = -T0*(sigma-CrossSection)/(CrossSection*dT0);
1270     G4double c1 = -T0 * (sigma - CrossSection << 1229     G4double   c2 = 0.150;
1271     G4double c2 = 0.150;                      << 1230     if (Z > 1.5) c2 = 0.375-0.0556*std::log(Z);
1272     if(Z > 1.5)                               << 1231     G4double    y = std::log(GammaEnergy/T0);
1273       c2 = 0.375 - 0.0556 * std::log(Z);      << 1232     CrossSection *= std::exp(-y*(c1+c2*y));
1274     G4double y = std::log(GammaEnergy / T0);  << 
1275     CrossSection *= std::exp(-y * (c1 + c2 *  << 
1276   }                                              1233   }
1277   return CrossSection;                        << 1234   //  G4cout << "e= " << GammaEnergy << " Z= " << Z << " cross= " << CrossSection << G4endl;
                                                   >> 1235   return CrossSection;  
1278 }                                                1236 }
1279                                                  1237 
                                                   >> 1238 
1280 /////////////////////////////////////////////    1239 ///////////////////////////////////////////////////////////////////////
                                                   >> 1240 //
1281 // This function returns the spectral and ang    1241 // This function returns the spectral and angle density of TR quanta
1282 // in X-ray energy region generated forward w    1242 // in X-ray energy region generated forward when a relativistic
1283 // charged particle crosses interface between    1243 // charged particle crosses interface between two materials.
1284 // The high energy small theta approximation     1244 // The high energy small theta approximation is applied.
1285 // (matter1 -> matter2, or 2->1)                 1245 // (matter1 -> matter2, or 2->1)
1286 // varAngle =2* (1 - std::cos(theta)) or appr    1246 // varAngle =2* (1 - std::cos(theta)) or approximately = theta*theta
1287 G4double G4VXTRenergyLoss::OneBoundaryXTRNden << 1247 //
1288                                               << 1248 
1289                                               << 1249 G4double
1290 {                                             << 1250 G4VXTRenergyLoss::OneBoundaryXTRNdensity( G4double energy,G4double gamma,
1291   G4double formationLength1, formationLength2 << 1251                                          G4double varAngle ) const
1292   formationLength1 =                          << 1252 {
1293     1.0 / (1.0 / (gamma * gamma) + fSigma1 /  << 1253   G4double  formationLength1, formationLength2 ;
1294   formationLength2 =                          << 1254   formationLength1 = 1.0/
1295     1.0 / (1.0 / (gamma * gamma) + fSigma2 /  << 1255   (1.0/(gamma*gamma)
1296   return (varAngle / energy) * (formationLeng << 1256   + fSigma1/(energy*energy)
1297          (formationLength1 - formationLength2 << 1257   + varAngle) ;
                                                   >> 1258   formationLength2 = 1.0/
                                                   >> 1259   (1.0/(gamma*gamma)
                                                   >> 1260   + fSigma2/(energy*energy)
                                                   >> 1261   + varAngle) ;
                                                   >> 1262   return (varAngle/energy)*(formationLength1 - formationLength2)
                                                   >> 1263               *(formationLength1 - formationLength2)  ;
                                                   >> 1264 
1298 }                                                1265 }
1299                                                  1266 
1300 G4double G4VXTRenergyLoss::GetStackFactor(G4d << 1267 G4double G4VXTRenergyLoss::GetStackFactor( G4double energy, G4double gamma,
1301                                           G4d << 1268                                                      G4double varAngle )
1302 {                                                1269 {
1303   // return stack factor corresponding to one    1270   // return stack factor corresponding to one interface
1304   return std::real(OneInterfaceXTRdEdx(energy << 1271 
                                                   >> 1272   return std::real( OneInterfaceXTRdEdx(energy,gamma,varAngle) );
1305 }                                                1273 }
1306                                                  1274 
1307 /////////////////////////////////////////////    1275 //////////////////////////////////////////////////////////////////////////////
                                                   >> 1276 //
1308 // For photon energy distribution tables. Int    1277 // For photon energy distribution tables. Integrate first over angle
                                                   >> 1278 //
                                                   >> 1279 
1309 G4double G4VXTRenergyLoss::XTRNSpectralAngleD    1280 G4double G4VXTRenergyLoss::XTRNSpectralAngleDensity(G4double varAngle)
1310 {                                                1281 {
1311   return OneBoundaryXTRNdensity(fEnergy, fGam << 1282   return OneBoundaryXTRNdensity(fEnergy,fGamma,varAngle)*
1312          GetStackFactor(fEnergy, fGamma, varA << 1283          GetStackFactor(fEnergy,fGamma,varAngle)             ;
1313 }                                                1284 }
1314                                                  1285 
1315 /////////////////////////////////////////////    1286 /////////////////////////////////////////////////////////////////////////
                                                   >> 1287 //
1316 // For second integration over energy            1288 // For second integration over energy
                                                   >> 1289  
1317 G4double G4VXTRenergyLoss::XTRNSpectralDensit    1290 G4double G4VXTRenergyLoss::XTRNSpectralDensity(G4double energy)
1318 {                                                1291 {
1319   fEnergy = energy;                           << 1292   fEnergy = energy ;
1320   G4Integrator<G4VXTRenergyLoss, G4double (G4 << 1293   G4Integrator<G4VXTRenergyLoss,G4double(G4VXTRenergyLoss::*)(G4double)> integral ;
1321     integral;                                 << 1294   return integral.Legendre96(this,&G4VXTRenergyLoss::XTRNSpectralAngleDensity,
1322   return integral.Legendre96(this, &G4VXTRene << 1295                              0.0,0.2*fMaxThetaTR) +
1323                              0.0, 0.2 * fMaxT << 1296          integral.Legendre10(this,&G4VXTRenergyLoss::XTRNSpectralAngleDensity,
1324          integral.Legendre10(this, &G4VXTRene << 1297                        0.2*fMaxThetaTR,fMaxThetaTR) ;
1325                              0.2 * fMaxThetaT << 1298 } 
1326 }                                             << 1299  
1327                                               << 
1328 /////////////////////////////////////////////    1300 //////////////////////////////////////////////////////////////////////////
                                                   >> 1301 // 
1329 // for photon angle distribution tables          1302 // for photon angle distribution tables
                                                   >> 1303 //
                                                   >> 1304 
1330 G4double G4VXTRenergyLoss::XTRNAngleSpectralD    1305 G4double G4VXTRenergyLoss::XTRNAngleSpectralDensity(G4double energy)
1331 {                                                1306 {
1332   return OneBoundaryXTRNdensity(energy, fGamm << 1307   return OneBoundaryXTRNdensity(energy,fGamma,fVarAngle)*
1333          GetStackFactor(energy, fGamma, fVarA << 1308          GetStackFactor(energy,fGamma,fVarAngle)             ;
1334 }                                             << 1309 } 
1335                                                  1310 
1336 /////////////////////////////////////////////    1311 ///////////////////////////////////////////////////////////////////////////
1337 G4double G4VXTRenergyLoss::XTRNAngleDensity(G << 1312 //
                                                   >> 1313 //
                                                   >> 1314 
                                                   >> 1315 G4double G4VXTRenergyLoss::XTRNAngleDensity(G4double varAngle) 
1338 {                                                1316 {
1339   fVarAngle = varAngle;                       << 1317   fVarAngle = varAngle ;
1340   G4Integrator<G4VXTRenergyLoss, G4double (G4 << 1318   G4Integrator<G4VXTRenergyLoss,G4double(G4VXTRenergyLoss::*)(G4double)> integral ;
1341     integral;                                 << 1319   return integral.Legendre96(this,&G4VXTRenergyLoss::XTRNAngleSpectralDensity,
1342   return integral.Legendre96(this, &G4VXTRene << 1320            fMinEnergyTR,fMaxEnergyTR) ;
1343                              fMinEnergyTR, fM << 
1344 }                                                1321 }
1345                                                  1322 
1346 /////////////////////////////////////////////    1323 //////////////////////////////////////////////////////////////////////////////
1347 // Check number of photons for a range of Lor << 1324 //
                                                   >> 1325 // Check number of photons for a range of Lorentz factors from both energy 
1348 // and angular tables                            1326 // and angular tables
                                                   >> 1327 
1349 void G4VXTRenergyLoss::GetNumberOfPhotons()      1328 void G4VXTRenergyLoss::GetNumberOfPhotons()
1350 {                                                1329 {
1351   G4int iTkin;                                << 1330   G4int iTkin ;
1352   G4double gamma, numberE;                    << 1331   G4double gamma, numberE ;
1353                                                  1332 
1354   std::ofstream outEn("numberE.dat", std::ios << 1333   std::ofstream outEn("numberE.dat", std::ios::out ) ;
1355   outEn.setf(std::ios::scientific, std::ios:: << 1334   outEn.setf( std::ios::scientific, std::ios::floatfield );
1356                                                  1335 
1357   std::ofstream outAng("numberAng.dat", std:: << 1336   std::ofstream outAng("numberAng.dat", std::ios::out ) ;
1358   outAng.setf(std::ios::scientific, std::ios: << 1337   outAng.setf( std::ios::scientific, std::ios::floatfield );
1359                                                  1338 
1360   for(iTkin = 0; iTkin < fTotBin; ++iTkin)  / << 1339   for(iTkin=0;iTkin<fTotBin;iTkin++)      // Lorentz factor loop
1361   {                                           << 1340   {
1362     gamma =                                   << 1341      gamma = 1.0 + (fProtonEnergyVector->
1363       1.0 + (fProtonEnergyVector->GetLowEdgeE << 1342                             GetLowEdgeEnergy(iTkin)/proton_mass_c2) ;
1364     numberE = (*(*fEnergyDistrTable)(iTkin))( << 1343      numberE = (*(*fEnergyDistrTable)(iTkin))(0) ;
1365     if(verboseLevel > 1)                      << 1344      //  numberA = (*(*fAngleDistrTable)(iTkin))(0) ;
1366       G4cout << gamma << "\t\t" << numberE << << 1345      if(verboseLevel > 1)
1367     if(verboseLevel > 0)                      << 1346        G4cout<<gamma<<"\t\t"<<numberE<<"\t"    //  <<numberA
1368       outEn << gamma << "\t\t" << numberE <<  << 1347        <<G4endl ; 
                                                   >> 1348      if(verboseLevel > 0)
                                                   >> 1349        outEn<<gamma<<"\t\t"<<numberE<<G4endl ; 
1369   }                                              1350   }
1370   return;                                     << 1351   return ;
1371 }                                             << 1352 }  
1372                                                  1353 
1373 /////////////////////////////////////////////    1354 /////////////////////////////////////////////////////////////////////////
1374 // Returns random energy of a X-ray TR photon << 1355 //
                                                   >> 1356 // Returns randon energy of a X-ray TR photon for given scaled kinetic energy
1375 // of a charged particle                         1357 // of a charged particle
1376 G4double G4VXTRenergyLoss::GetXTRrandomEnergy << 1358 
                                                   >> 1359 G4double G4VXTRenergyLoss::GetXTRrandomEnergy( G4double scaledTkin, G4int iTkin )
1377 {                                                1360 {
1378   G4int iTransfer, iPlace;                    << 1361   G4int iTransfer, iPlace  ;
1379   G4double transfer = 0.0, position, E1, E2,  << 1362   G4double transfer = 0.0, position, E1, E2, W1, W2, W ;
                                                   >> 1363 
                                                   >> 1364   iPlace = iTkin - 1 ;
1380                                                  1365 
1381   iPlace = iTkin - 1;                         << 1366   //  G4cout<<"iPlace = "<<iPlace<<endl ;
1382                                                  1367 
1383   if(iTkin == fTotBin)  // relativistic plato << 1368   if(iTkin == fTotBin) // relativistic plato, try from left
1384   {                                              1369   {
1385     position = (*(*fEnergyDistrTable)(iPlace) << 1370       position = (*(*fEnergyDistrTable)(iPlace))(0)*G4UniformRand() ;
1386                                                  1371 
1387     for(iTransfer = 0;; ++iTransfer)          << 1372       for(iTransfer=0;;iTransfer++)
1388     {                                         << 1373       {
1389       if(position >= (*(*fEnergyDistrTable)(i << 1374         if(position >= (*(*fEnergyDistrTable)(iPlace))(iTransfer)) break ;
1390         break;                                << 1375       }
1391     }                                         << 1376       transfer = GetXTRenergy(iPlace,position,iTransfer);
1392     transfer = GetXTRenergy(iPlace, position, << 
1393   }                                              1377   }
1394   else                                           1378   else
1395   {                                              1379   {
1396     E1 = fProtonEnergyVector->GetLowEdgeEnerg << 1380     E1 = fProtonEnergyVector->GetLowEdgeEnergy(iTkin - 1) ; 
1397     E2 = fProtonEnergyVector->GetLowEdgeEnerg << 1381     E2 = fProtonEnergyVector->GetLowEdgeEnergy(iTkin)     ;
1398     W  = 1.0 / (E2 - E1);                     << 1382     W  = 1.0/(E2 - E1) ;
1399     W1 = (E2 - scaledTkin) * W;               << 1383     W1 = (E2 - scaledTkin)*W ;
1400     W2 = (scaledTkin - E1) * W;               << 1384     W2 = (scaledTkin - E1)*W ;
1401                                               << 1385 
1402     position = ((*(*fEnergyDistrTable)(iPlace << 1386     position =( (*(*fEnergyDistrTable)(iPlace))(0)*W1 + 
1403                 (*(*fEnergyDistrTable)(iPlace << 1387                     (*(*fEnergyDistrTable)(iPlace+1))(0)*W2 )*G4UniformRand() ;
1404                G4UniformRand();               << 1388 
1405                                               << 1389         // G4cout<<position<<"\t" ;
1406     for(iTransfer = 0;; ++iTransfer)          << 1390 
1407     {                                         << 1391     for(iTransfer=0;;iTransfer++)
1408       if(position >= ((*(*fEnergyDistrTable)( << 1392     {
1409                       (*(*fEnergyDistrTable)( << 1393           if( position >=
1410         break;                                << 1394           ( (*(*fEnergyDistrTable)(iPlace))(iTransfer)*W1 + 
1411     }                                         << 1395             (*(*fEnergyDistrTable)(iPlace+1))(iTransfer)*W2) ) break ;
1412     transfer = GetXTRenergy(iPlace, position, << 1396     }
1413   }                                           << 1397     transfer = GetXTRenergy(iPlace,position,iTransfer);
1414   if(transfer < 0.0)                          << 1398     
1415     transfer = 0.0;                           << 1399   } 
1416   return transfer;                            << 1400   //  G4cout<<"XTR transfer = "<<transfer/keV<<" keV"<<endl ; 
                                                   >> 1401   if(transfer < 0.0 ) transfer = 0.0 ;
                                                   >> 1402   return transfer ;
1417 }                                                1403 }
1418                                                  1404 
1419 /////////////////////////////////////////////    1405 ////////////////////////////////////////////////////////////////////////
                                                   >> 1406 //
1420 // Returns approximate position of X-ray phot    1407 // Returns approximate position of X-ray photon energy during random sampling
1421 // over integral energy distribution             1408 // over integral energy distribution
1422 G4double G4VXTRenergyLoss::GetXTRenergy(G4int << 1409 
                                                   >> 1410 G4double G4VXTRenergyLoss::GetXTRenergy( G4int    iPlace, 
                                                   >> 1411                                        G4double position, 
                                                   >> 1412                                        G4int    iTransfer )
1423 {                                                1413 {
1424   G4double x1, x2, y1, y2, result;            << 1414   G4double x1, x2, y1, y2, result ;
1425                                                  1415 
1426   if(iTransfer == 0)                             1416   if(iTransfer == 0)
1427   {                                              1417   {
1428     result = (*fEnergyDistrTable)(iPlace)->Ge << 1418     result = (*fEnergyDistrTable)(iPlace)->GetLowEdgeEnergy(iTransfer) ;
1429   }                                           << 1419   }  
1430   else                                           1420   else
1431   {                                              1421   {
1432     y1 = (*(*fEnergyDistrTable)(iPlace))(iTra << 1422     y1 = (*(*fEnergyDistrTable)(iPlace))(iTransfer-1) ;
1433     y2 = (*(*fEnergyDistrTable)(iPlace))(iTra << 1423     y2 = (*(*fEnergyDistrTable)(iPlace))(iTransfer) ;
1434                                                  1424 
1435     x1 = (*fEnergyDistrTable)(iPlace)->GetLow << 1425     x1 = (*fEnergyDistrTable)(iPlace)->GetLowEdgeEnergy(iTransfer-1) ;
1436     x2 = (*fEnergyDistrTable)(iPlace)->GetLow << 1426     x2 = (*fEnergyDistrTable)(iPlace)->GetLowEdgeEnergy(iTransfer) ;
1437                                                  1427 
1438     if(x1 == x2)                              << 1428     if ( x1 == x2 )    result = x2 ;
1439       result = x2;                            << 
1440     else                                         1429     else
1441     {                                            1430     {
1442       if(y1 == y2)                            << 1431       if ( y1 == y2  ) result = x1 + (x2 - x1)*G4UniformRand() ;
1443         result = x1 + (x2 - x1) * G4UniformRa << 
1444       else                                       1432       else
1445       {                                          1433       {
1446         result = x1 + (x2 - x1) * G4UniformRa << 1434         result = x1 + (position - y1)*(x2 - x1)/(y2 - y1) ;
1447       }                                          1435       }
1448     }                                            1436     }
1449   }                                              1437   }
1450   return result;                              << 1438   return result ;
1451 }                                                1439 }
1452                                                  1440 
1453 /////////////////////////////////////////////    1441 /////////////////////////////////////////////////////////////////////////
                                                   >> 1442 //
1454 //  Get XTR photon angle at given energy and     1443 //  Get XTR photon angle at given energy and Tkin
1455                                                  1444 
1456 G4double G4VXTRenergyLoss::GetRandomAngle(G4d << 1445 G4double G4VXTRenergyLoss::GetRandomAngle( G4double energyXTR, G4int iTkin )
1457 {                                                1446 {
1458   G4int iTR, iAngle;                             1447   G4int iTR, iAngle;
1459   G4double position, angle;                      1448   G4double position, angle;
1460                                                  1449 
1461   if(iTkin == fTotBin)                        << 1450   if (iTkin == fTotBin) iTkin--;
1462     --iTkin;                                  << 
1463                                                  1451 
1464   fAngleForEnergyTable = fAngleBank[iTkin];      1452   fAngleForEnergyTable = fAngleBank[iTkin];
1465                                                  1453 
1466   for(iTR = 0; iTR < fBinTR; ++iTR)           << 1454   for( iTR = 0; iTR < fBinTR; iTR++ )
1467   {                                              1455   {
1468     if(energyXTR < fXTREnergyVector->GetLowEd << 1456     if( energyXTR < fXTREnergyVector->GetLowEdgeEnergy(iTR) )  break;    
1469       break;                                  << 
1470   }                                              1457   }
1471   if(iTR == fBinTR)                           << 1458   if (iTR == fBinTR) iTR--;
1472     --iTR;                                    << 1459       
1473                                               << 1460   position = (*(*fAngleForEnergyTable)(iTR))(0)*G4UniformRand() ;
1474   position = (*(*fAngleForEnergyTable)(iTR))( << 
1475   // position = (*(*fAngleForEnergyTable)(iTR << 
1476                                                  1461 
1477   for(iAngle = 0;; ++iAngle)                  << 1462   for(iAngle = 0;;iAngle++)
1478   // for(iAngle = 1;; ++iAngle) // ATLAS TB   << 
1479   {                                              1463   {
1480     if(position >= (*(*fAngleForEnergyTable)( << 1464     if(position >= (*(*fAngleForEnergyTable)(iTR))(iAngle)) break ;
1481       break;                                  << 
1482   }                                              1465   }
1483   angle = GetAngleXTR(iTR, position, iAngle); << 1466   angle = GetAngleXTR(iTR,position,iAngle);
1484   return angle;                                  1467   return angle;
1485 }                                                1468 }
1486                                                  1469 
1487 /////////////////////////////////////////////    1470 ////////////////////////////////////////////////////////////////////////
1488 // Returns approximate position of X-ray phot << 1471 //
1489 // random sampling over integral energy distr << 1472 // Returns approximate position of X-ray photon angle at given energy during random sampling
                                                   >> 1473 // over integral energy distribution
1490                                                  1474 
1491 G4double G4VXTRenergyLoss::GetAngleXTR(G4int  << 1475 G4double G4VXTRenergyLoss::GetAngleXTR( G4int    iPlace, 
1492                                        G4int  << 1476                                        G4double position, 
                                                   >> 1477                                        G4int    iTransfer )
1493 {                                                1478 {
1494   G4double x1, x2, y1, y2, result;            << 1479   G4double x1, x2, y1, y2, result ;
1495                                                  1480 
1496   if( iTransfer == 0 )                        << 1481   if(iTransfer == 0)
1497   // if( iTransfer == 1 ) // ATLAS TB         << 
1498   {                                              1482   {
1499     result = (*fAngleForEnergyTable)(iPlace)- << 1483     result = (*fAngleForEnergyTable)(iPlace)->GetLowEdgeEnergy(iTransfer) ;
1500   }                                           << 1484   }  
1501   else                                           1485   else
1502   {                                              1486   {
1503     y1 = (*(*fAngleForEnergyTable)(iPlace))(i << 1487     y1 = (*(*fAngleForEnergyTable)(iPlace))(iTransfer-1) ;
1504     y2 = (*(*fAngleForEnergyTable)(iPlace))(i << 1488     y2 = (*(*fAngleForEnergyTable)(iPlace))(iTransfer) ;
1505                                                  1489 
1506     x1 = (*fAngleForEnergyTable)(iPlace)->Get << 1490     x1 = (*fAngleForEnergyTable)(iPlace)->GetLowEdgeEnergy(iTransfer-1) ;
1507     x2 = (*fAngleForEnergyTable)(iPlace)->Get << 1491     x2 = (*fAngleForEnergyTable)(iPlace)->GetLowEdgeEnergy(iTransfer) ;
1508                                                  1492 
1509     if(x1 == x2) result = x2;                 << 1493     if ( x1 == x2 )    result = x2 ;
1510     else                                         1494     else
1511     {                                            1495     {
1512       if( y1 == y2 )  result = x1 + (x2 - x1) << 1496       if ( y1 == y2  ) result = x1 + (x2 - x1)*G4UniformRand() ;
1513       else                                       1497       else
1514       {                                          1498       {
1515         result = x1 + (position - y1) * (x2 - << 1499         result = x1 + (position - y1)*(x2 - x1)/(y2 - y1) ;
1516         // result = x1 + 0.1*(position - y1)  << 
1517         // result = x1 + 0.05*(position - y1) << 
1518       }                                          1500       }
1519     }                                            1501     }
1520   }                                              1502   }
1521   return result;                              << 1503   return result ;
1522 }                                                1504 }
                                                   >> 1505 
                                                   >> 1506 
                                                   >> 1507 //
                                                   >> 1508 //
                                                   >> 1509 ///////////////////////////////////////////////////////////////////////
                                                   >> 1510 
1523                                                  1511