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 10.7.p2)


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