54 fAccumSpectrum.clear();
57 fFa.resize(fNMCPhotons);
58 fSs.resize(fNMCPhotons);
59 fSc.resize(fNMCPhotons);
60 fSsx.resize(fNMCPhotons);
61 fSsy.resize(fNMCPhotons);
62 fScx.resize(fNMCPhotons);
63 fScy.resize(fNMCPhotons);
64 std::fill(fFa.begin(), fFa.end(), 0.);
65 std::fill(fSs.begin(), fSs.end(), 0.);
66 std::fill(fSc.begin(), fSc.end(), 0.);
67 std::fill(fSsx.begin(), fSsx.end(), 0.);
68 std::fill(fSsy.begin(), fSsy.end(), 0.);
69 std::fill(fScx.begin(), fScx.end(), 0.);
70 std::fill(fScy.begin(), fScy.end(), 0.);
73 fMeanPhotonAngleX =0.;
75 fParamPhotonAngleX=1.e-3*rad;
77 fMeanPhotonAngleY =0.;
79 fParamPhotonAngleY=1.e-3*rad;
85 fParticleAnglesX.clear();
86 fParticleAnglesY.clear();
87 fScatteringAnglesX.clear();
88 fScatteringAnglesY.clear();
91 fParticleCoordinatesXYZ.clear();
99 fTotalRadiationProbabilityAlongTrajectory.clear();
101 fTotalRadiationProbabilityAlongTrajectory.push_back(0.);
110 fMinPhotonEnergy = emin;
111 fMaxPhotonEnergy = emax;
112 fNBinsSpectrum = numberOfBins;
114 fLogEmaxdEmin =
G4Log(fMaxPhotonEnergy/fMinPhotonEnergy);
117 fNPhotonsPerBin.resize(fNBinsSpectrum);
118 std::fill(fNPhotonsPerBin.begin(), fNPhotonsPerBin.end(), 0);
121 fSpectrum.resize(fNBinsSpectrum);
122 std::fill(fSpectrum.begin(), fSpectrum.end(), 0);
125 fAccumTotalSpectrum.resize(fNBinsSpectrum);
126 std::fill(fAccumTotalSpectrum.begin(), fAccumTotalSpectrum.end(), 0);
129 fTotalSpectrum.resize(fNBinsSpectrum);
130 std::fill(fTotalSpectrum.begin(), fTotalSpectrum.end(), 0);
132 fPhotonEnergyInSpectrum.clear();
133 for (
G4int j=0;j<fNBinsSpectrum;j++)
136 fPhotonEnergyInSpectrum.push_back(fMinPhotonEnergy*
137 (std::exp(fLogEmaxdEmin*j/fNBinsSpectrum)+
138 std::exp(fLogEmaxdEmin*(j+1)/fNBinsSpectrum))/2.);
150 G4int timesPhotonStatistics)
153 if(timesPhotonStatistics<=1)
155 G4cout <<
"G4BaierKatkov model, "
156 "function AddStatisticsInPhotonEnergyRegion("
157 << emin/CLHEP::MeV <<
" MeV, "
158 << emax/CLHEP::MeV <<
" MeV, "
159 << timesPhotonStatistics <<
")" <<
G4endl;
160 G4cout <<
"Warning: the statistics factor cannot be <=1." <<
G4endl;
164 else if(fMinPhotonEnergy>emin)
166 G4cout <<
"G4BaierKatkov model, "
167 "function AddStatisticsInPhotonEnergyRegion("
168 << emin/CLHEP::MeV <<
" MeV, "
169 << emax/CLHEP::MeV <<
" MeV, "
170 << timesPhotonStatistics <<
")" <<
G4endl;
171 G4cout <<
"Warning: the minimal energy inserted is less then "
172 "the minimal energy cut of the spectrum: "
173 << fMinPhotonEnergy/CLHEP::MeV <<
" MeV." <<
G4endl;
179 G4cout <<
"G4BaierKatkov model, "
180 "function AddStatisticsInPhotonEnergyRegion("
181 << emin/CLHEP::MeV <<
" MeV, "
182 << emax/CLHEP::MeV <<
" MeV, "
183 << timesPhotonStatistics <<
")" <<
G4endl;
184 G4cout <<
"Warning: the maximal energy <= the minimal energy." <<
G4endl;
191 G4double logAddRangeEmindEmin =
G4Log(emin/fMinPhotonEnergy);
192 G4double logAddRangeEmaxdEmin =
G4Log(emax/fMinPhotonEnergy);
194 G4int nAddRange = (
G4int)fTimesPhotonStatistics.size();
195 for (
G4int j=0;j<nAddRange;j++)
197 if((logAddRangeEmindEmin>=fLogAddRangeEmindEmin[j]&&
198 logAddRangeEmindEmin< fLogAddRangeEmaxdEmin[j])||
199 (logAddRangeEmaxdEmin> fLogAddRangeEmindEmin[j]&&
200 logAddRangeEmaxdEmin<=fLogAddRangeEmaxdEmin[j])||
201 (logAddRangeEmindEmin<=fLogAddRangeEmindEmin[j]&&
202 logAddRangeEmaxdEmin>=fLogAddRangeEmaxdEmin[j]))
204 G4cout <<
"G4BaierKatkov model, "
205 "function AddStatisticsInPhotonEnergyRegion("
206 << emin/CLHEP::MeV <<
" MeV, "
207 << emax/CLHEP::MeV <<
" MeV, "
208 << timesPhotonStatistics <<
")" <<
G4endl;
209 G4cout <<
"Warning: the energy range intersects another "
210 "added energy range." <<
G4endl;
219 fLogAddRangeEmindEmin.push_back(logAddRangeEmindEmin);
220 fLogAddRangeEmaxdEmin.push_back(logAddRangeEmaxdEmin);
221 fTimesPhotonStatistics.push_back(timesPhotonStatistics);
223 G4cout <<
"G4BaierKatkov model: increasing the statistics of photon sampling "
224 "in Baier-Katkov with a factor of "
225 << timesPhotonStatistics <<
G4endl;
226 G4cout <<
"in the energy spectrum range: ("
227 << emin/CLHEP::MeV <<
" MeV, "
228 << emax/CLHEP::MeV <<
" MeV)" <<
G4endl;
235void G4BaierKatkov::SetPhotonSamplingParameters(
G4double ekin,
241 fLogEdEmin =
G4Log(ekin/fMinPhotonEnergy);
242 fMeanPhotonAngleX = (maxPhotonAngleX+minPhotonAngleX)/2.;
243 fParamPhotonAngleX = (maxPhotonAngleX-minPhotonAngleX)/2.;
244 fMeanPhotonAngleY = (maxPhotonAngleY+minPhotonAngleY)/2.;
245 fParamPhotonAngleY = (maxPhotonAngleY-minPhotonAngleY)/2.;
250void G4BaierKatkov::GeneratePhotonSampling()
252 fPhotonEnergyInIntegral.clear();
253 fPhotonAngleInIntegralX.clear();
254 fPhotonAngleInIntegralY.clear();
255 fPhotonAngleNormCoef.clear();
256 fInsideVirtualCollimator.clear();
257 fIBinsSpectrum.clear();
260 std::vector<G4int> moreStatistics;
261 moreStatistics.resize(fTimesPhotonStatistics.size());
262 std::fill(moreStatistics.begin(), moreStatistics.end(), 0);
263 G4int nAddRange = (
G4int)fTimesPhotonStatistics.size();
267 for (
G4int j=0;j<fNMCPhotons;j++)
270 fIBinsSpectrum.push_back((
G4int)std::trunc(
271 ksi*fNBinsSpectrum/fLogEmaxdEmin));
275 if(fIBinsSpectrum[j]<fNBinsSpectrum) {fNPhotonsPerBin[fIBinsSpectrum[j]]+=1;}
277 fPhotonEnergyInIntegral.push_back(fMinPhotonEnergy*std::exp(ksi));
279 fPhotonAngleNormCoef.push_back(1.);
281 for (
G4int j2=0;j2<nAddRange;j2++)
283 if(ksi>fLogAddRangeEmindEmin[j2]&&
284 ksi<fLogAddRangeEmaxdEmin[j2])
288 moreStatistics[j2]+=1;
289 fPhotonAngleNormCoef[j]/=fTimesPhotonStatistics[j2];
295 for (
G4int j2=0;j2<nAddRange;j2++)
297 G4int totalAddRangeStatistics = moreStatistics[j2]*fTimesPhotonStatistics[j2];
298 for (
G4int j=moreStatistics[j2];j<totalAddRangeStatistics;j++)
300 ksi = fLogAddRangeEmindEmin[j2]+
301 G4UniformRand()*(std::min(fLogAddRangeEmaxdEmin[j2],fLogEdEmin)-
302 fLogAddRangeEmindEmin[j2]);
303 fIBinsSpectrum.push_back((
G4int)std::trunc(
304 ksi*fNBinsSpectrum/fLogEmaxdEmin));
311 fPhotonEnergyInIntegral.push_back(fMinPhotonEnergy*std::exp(ksi));
313 fPhotonAngleNormCoef.push_back(1./fTimesPhotonStatistics[j2]);
319 G4double norm=std::atan(rhocut*rhocut)*
320 CLHEP::pi*fParamPhotonAngleX*fParamPhotonAngleY;
324 G4int nmctotal = (
G4int)fPhotonEnergyInIntegral.size();
325 for (
G4int j=0;j<nmctotal;j++)
337 fPhotonAngleInIntegralX.push_back(fMeanPhotonAngleX+
339 rho*std::cos(CLHEP::twopi*ksi));
340 fPhotonAngleInIntegralY.push_back(fMeanPhotonAngleY+
342 rho*std::sin(CLHEP::twopi*ksi));
343 fPhotonAngleNormCoef[j]*=(1.+rho*rho*rho*rho)*norm;
348 fInsideVirtualCollimator.push_back(fVirtualCollimatorAngularDiameter >
349 std::sqrt(fPhotonAngleInIntegralX[j]*
350 fPhotonAngleInIntegralX[j]+
351 fPhotonAngleInIntegralY[j]*
352 fPhotonAngleInIntegralY[j]));
355 fPhotonProductionCDF.resize(nmctotal+1);
356 std::fill(fPhotonProductionCDF.begin(), fPhotonProductionCDF.end(), 0.);
359 if (nmctotal>fNMCPhotons)
362 fFa.resize(nmctotal);
363 fSs.resize(nmctotal);
364 fSc.resize(nmctotal);
365 fSsx.resize(nmctotal);
366 fSsy.resize(nmctotal);
367 fScx.resize(nmctotal);
368 fScy.resize(nmctotal);
369 std::fill(fFa.begin(), fFa.end(), 0.);
370 std::fill(fSs.begin(), fSs.end(), 0.);
371 std::fill(fSc.begin(), fSc.end(), 0.);
372 std::fill(fSsx.begin(), fSsx.end(), 0.);
373 std::fill(fSsy.begin(), fSsy.end(), 0.);
374 std::fill(fScx.begin(), fScx.end(), 0.);
375 std::fill(fScy.begin(), fScy.end(), 0.);
382 std::vector<G4double> &vectorParticleAnglesX,
383 std::vector<G4double> &vectorParticleAnglesY,
384 std::vector<G4double> &vectorScatteringAnglesX,
385 std::vector<G4double> &vectorScatteringAnglesY,
386 std::vector<G4double> &vectorSteps,
394 G4double vxin =0.,vyin=0.,vxno=0.,vyno=0.;
397 G4double fa1=0.,faseBefore=0.,faseBeforedz=0.,faseBeforedzd2=0.;
398 G4double faseAfter=0.,fa2dfaseBefore2=0.;
404 std::size_t nparts=vectorParticleAnglesX.size();
406 if(imin==0) {kmin=1;}
409 G4double totalRadiationProbabilityPhj = 0.;
412 fTotalRadiationProbabilityAlongTrajectory.resize(nparts);
415 std::fill(fSpectrum.begin(), fSpectrum.end(), 0.);
418 std::vector<G4double> axt;
420 std::vector<G4double> ayt;
422 std::vector<G4double> dz;
425 for(std::size_t k=kmin;k<nparts;k++)
427 dz[k]=vectorSteps[k]/CLHEP::hbarc;
430 axt[k]=(vectorParticleAnglesX[k]-vectorScatteringAnglesX[k]-
431 vectorParticleAnglesX[k-1])/dz[k];
432 ayt[k]=(vectorParticleAnglesY[k]-vectorScatteringAnglesY[k]-
433 vectorParticleAnglesY[k-1])/dz[k];
441 G4double gammaInverse2 = mass*mass/(etotal*etotal);
443 G4double coefNormLogdNMC = fLogEdEmin/fNMCPhotons;
446 G4double coefNorm = CLHEP::fine_structure_const/(8*(CLHEP::pi2))*coefNormLogdNMC;
451 std::size_t nmctotal = fPhotonEnergyInIntegral.size();
452 for (std::size_t j=0;j<nmctotal;j++)
455 om = fPhotonEnergyInIntegral[j];
457 eprime2 = eprime*eprime;
458 e2pluseprime2 =e2+eprime2;
459 omprime=etotal*
om/eprime;
461 coefNormom2deprime2 = coefNorm*
om*
om/eprime2;
462 gammaInverse2om = gammaInverse2*
om;
464 for(std::size_t k=kmin;k<nparts;k++)
467 vxin = vectorParticleAnglesX[k]-fPhotonAngleInIntegralX[j];
468 vyin = vectorParticleAnglesY[k]-fPhotonAngleInIntegralY[j];
470 vxno = vxin-vectorScatteringAnglesX[k];
471 vyno = vyin-vectorScatteringAnglesY[k];
474 faseBefore=omprimed2*(gammaInverse2+vxno*vxno+vyno*vyno);
476 faseBeforedz = faseBefore*dz[k];
477 faseBeforedzd2 = faseBeforedz/2.;
478 fFa[j]+=faseBeforedz;
479 fa1=fFa[j]-faseBeforedzd2;
480 dzmod=2*std::sin(faseBeforedzd2)/faseBefore;
483 fa2dfaseBefore2 = omprime*(axt[k]*vxno+ayt[k]*vyno)/(faseBefore*faseBefore);
486 faseAfter=omprimed2*(gammaInverse2+vxin*vxin+vyin*vyin);
488 skJ=1/faseAfter-1/faseBefore-fa2dfaseBefore2*dzmod;
489 skIx=vxin/faseAfter-vxno/faseBefore+dzmod*(axt[k]/faseBefore-
490 vxno*fa2dfaseBefore2);
491 skIy=vyin/faseAfter-vyno/faseBefore+dzmod*(ayt[k]/faseBefore-
492 vyno*fa2dfaseBefore2);
494 sinfa1 = std::sin(fa1);
495 cosfa1 = std::cos(fa1);
499 fSsx[j]+=sinfa1*skIx;
500 fSsy[j]+=sinfa1*skIy;
501 fScx[j]+=cosfa1*skIx;
502 fScy[j]+=cosfa1*skIy;
504 i2=fSsx[j]*fSsx[j]+fScx[j]*fScx[j]+fSsy[j]*fSsy[j]+fScy[j]*fScy[j];
505 j2=fSs[j]*fSs[j]+fSc[j]*fSc[j];
508 totalRadiationProbabilityPhj = coefNormom2deprime2*fPhotonAngleNormCoef[j]*
509 (i2*e2pluseprime2+j2*gammaInverse2om);
510 fTotalRadiationProbabilityAlongTrajectory[k] += totalRadiationProbabilityPhj;
513 fPhotonProductionCDF[j+1] = fTotalRadiationProbabilityAlongTrajectory.back();
520 if((fIBinsSpectrum[j]<fNBinsSpectrum)&&fInsideVirtualCollimator[j])
521 {fSpectrum[fIBinsSpectrum[j]] += totalRadiationProbabilityPhj/
522 (
om*coefNormLogdNMC);}
526 fAccumSpectrum.push_back(fSpectrum);
528 return fTotalRadiationProbabilityAlongTrajectory.back();
533G4int G4BaierKatkov::FindVectorIndex(std::vector<G4double> &myvector,
G4double value)
535 auto iteratorbegin = myvector.begin();
536 auto iteratorend = myvector.end();
539 auto loweriterator = std::lower_bound(iteratorbegin, iteratorend, value);
541 return (
G4int)std::distance(iteratorbegin, loweriterator);
549 G4bool flagPhotonProduced =
false;
553 std::size_t nodeNumber = fAccumSpectrum.size()-1;
561 if (ksi< fTotalRadiationProbabilityAlongTrajectory.back())
567 G4int iphoton = FindVectorIndex(fPhotonProductionCDF,ksi1)-1;
571 fEph0 = fPhotonEnergyInIntegral[iphoton];
573 G4double photonAngleX = fPhotonAngleInIntegralX[iphoton];
574 G4double photonAngleY = fPhotonAngleInIntegralY[iphoton];
577 std::sqrt(1.+std::pow(std::tan(photonAngleX),2)+
578 std::pow(std::tan(photonAngleY),2));
581 PhMomentumDirection.
set(momentumDirectionZ*std::tan(photonAngleX),
582 momentumDirectionZ*std::tan(photonAngleY),
590 std::vector<G4double> temporaryVector;
591 temporaryVector.assign(fTotalRadiationProbabilityAlongTrajectory.begin(),
592 fTotalRadiationProbabilityAlongTrajectory.end());
593 std::sort(temporaryVector.begin(), temporaryVector.end());
596 G4int iNode = FindVectorIndex(temporaryVector,ksi);
599 auto it = std::find_if(fTotalRadiationProbabilityAlongTrajectory.begin(),
600 fTotalRadiationProbabilityAlongTrajectory.end(),
602 {return std::abs(value - temporaryVector[iNode]) < DBL_EPSILON;});
603 iNode = (
G4int)std::distance(fTotalRadiationProbabilityAlongTrajectory.begin(), it);
606 nodeNumber = FindVectorIndex(fImax0,iNode*1.)-1;
611 fNewParticleEnergy = etotal-fEph0;
612 fNewParticleAngleX = fParticleAnglesX[iNode];
613 fNewParticleAngleY = fParticleAnglesY[iNode];
614 fNewGlobalTime = fGlobalTimes[iNode];
615 fNewParticleCoordinateXYZ = fParticleCoordinatesXYZ[iNode];
620 G4double pratio = fEph0/std::sqrt(etotal*etotal-mass*mass);
621 fNewParticleAngleX -= std::asin(pratio*std::sin(photonAngleX));
622 fNewParticleAngleY -= std::asin(pratio*std::sin(photonAngleY));
624 flagPhotonProduced =
true;
628 for (
G4int j=0;j<fNBinsSpectrum;j++)
630 fAccumTotalSpectrum[j] += fAccumSpectrum[nodeNumber][j];
633 if(fNPhotonsPerBin[j]==0)
635 fTotalSpectrum[j] = 0;
639 fTotalSpectrum[j] = fAccumTotalSpectrum[j]/fNPhotonsPerBin[j]*fItrajectories;
643 return flagPhotonProduced;
687 G4bool flagPhotonProduced =
false;
690 fParticleAnglesX.push_back(angleX);
691 fParticleAnglesY.push_back(angleY);
692 fScatteringAnglesX.push_back(angleScatteringX);
693 fScatteringAnglesY.push_back(angleScatteringY);
694 fSteps.push_back(step);
695 fGlobalTimes.push_back(globalTime);
696 fParticleCoordinatesXYZ.push_back(coordinateXYZ);
699 if((imax==fImin0+fNSmallTrajectorySteps)||flagEndTrajectory)
705 G4double radiationAngleLimit=fRadiationAngleFactor*mass/etotal;
707 SetPhotonSamplingParameters(etotal-mass,
708 *std::min_element(fParticleAnglesX.begin(),
709 fParticleAnglesX.end())-radiationAngleLimit,
710 *std::max_element(fParticleAnglesX.begin(),
711 fParticleAnglesX.end())+radiationAngleLimit,
712 *std::min_element(fParticleAnglesY.begin(),
713 fParticleAnglesY.end())-radiationAngleLimit,
714 *std::max_element(fParticleAnglesY.begin(),
715 fParticleAnglesY.end())+radiationAngleLimit);
719 GeneratePhotonSampling();
724 fTotalRadiationProbability = RadIntegral(etotal,mass,
725 fParticleAnglesX,fParticleAnglesY,
726 fScatteringAnglesX,fScatteringAnglesY,
731 fImax0.push_back(imax*1.);
735 if(fTotalRadiationProbability>fSinglePhotonRadiationProbabilityLimit||
740 flagPhotonProduced = SetPhotonProductionParameters(etotal,mass);
751 return flagPhotonProduced;
759 PhMomentumDirection,fEph0);
Definition of the G4BaierKatkov class This class is designed for the calculation of radiation probabi...
G4double G4Log(G4double x)
G4GLOB_DLL std::ostream G4cout
void set(double x, double y, double z)
void GeneratePhoton(G4FastStep &fastStep)
void SetSpectrumEnergyRange(G4double emin, G4double emax, G4int numberOfBins)
void AddStatisticsInPhotonEnergyRegion(G4double emin, G4double emax, G4int timesPhotonStatistics)
G4bool DoRadiation(G4double etotal, G4double mass, G4double angleX, G4double angleY, G4double angleScatteringX, G4double angleScatteringY, G4double step, G4double globalTime, G4ThreeVector coordinateXYZ, G4bool flagEndTrajectory=false)
G4Track * CreateSecondaryTrack(const G4DynamicParticle &, G4ThreeVector, G4ThreeVector, G4double, G4bool localCoordinates=true)