File indexing completed on 2025-01-18 09:58:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #ifndef G4CASCADE_SAMPLER_ICC
0027 #define G4CASCADE_SAMPLER_ICC
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 #include "Randomize.hh"
0040 #include <iostream>
0041 #include <vector>
0042
0043
0044 template <G4int NBINS, G4int NMULT> inline
0045 G4double G4CascadeSampler<NBINS,NMULT>::
0046 findCrossSection(G4double ke,
0047 const G4double (&xsec)[energyBins]) const {
0048 return interpolator.interpolate(ke, xsec);
0049 }
0050
0051 template <G4int NBINS, G4int NMULT> inline
0052 G4int G4CascadeSampler<NBINS,NMULT>::
0053 findMultiplicity(G4double ke,
0054 const G4double xmult[][energyBins]) const {
0055 fillSigmaBuffer(ke, xmult);
0056 return sampleFlat() + 2;
0057 }
0058
0059 template <G4int NBINS, G4int NMULT> inline
0060 G4int G4CascadeSampler<NBINS,NMULT>::
0061 findFinalStateIndex(G4int mult, G4double ke, const G4int index[],
0062 const G4double xsec[][energyBins]) const {
0063 G4int start = index[mult-2];
0064 G4int stop = index[mult-1];
0065 if (stop-start <= 1) return start;
0066
0067 fillSigmaBuffer(ke, xsec, start, stop);
0068 return sampleFlat();
0069 }
0070
0071
0072 template <G4int NBINS, G4int NMULT> inline
0073 void G4CascadeSampler<NBINS,NMULT>::
0074 fillSigmaBuffer(G4double ke, const G4double x[][energyBins],
0075 G4int startBin, G4int stopBin) const {
0076 sigmaBuf.clear();
0077 if (stopBin-startBin <= 1) return;
0078
0079
0080 sigmaBuf.reserve(stopBin-startBin);
0081 for(G4int i = startBin; i < stopBin; ++i)
0082 sigmaBuf.push_back(interpolator.interpolate(ke, x[i]));
0083 }
0084
0085
0086 template <G4int NBINS, G4int NMULT> inline
0087 G4int G4CascadeSampler<NBINS,NMULT>::sampleFlat() const {
0088 G4int nbins = (G4int)sigmaBuf.size();
0089 if (nbins <= 1) return 0;
0090
0091 #ifdef G4CASCADE_DEBUG_SAMPLER
0092 G4cout << "G4CascadeSampler::sampleFlat() has " << nbins << "bins:" << G4endl;
0093 for (G4int sbi=0; sbi<nbins; sbi++) G4cout << " " << sigmaBuf[sbi];
0094 G4cout << G4endl;
0095 #endif
0096
0097 G4int i;
0098 G4double fsum = 0.;
0099 for (i = 0; i < nbins; ++i) fsum += sigmaBuf[i];
0100 #ifdef G4CASCADE_DEBUG_SAMPLER
0101 G4cout << " buffer total (fsum) " << fsum;
0102 #endif
0103 fsum *= G4UniformRand();
0104 #ifdef G4CASCADE_DEBUG_SAMPLER
0105 G4cout << " *random-scale " << fsum << G4endl;
0106 #endif
0107
0108 G4double partialSum = 0.0;
0109 for (i = 0; i < nbins; ++i) {
0110 partialSum += sigmaBuf[i];
0111 if (fsum < partialSum) return i;
0112 }
0113
0114 return 0;
0115 }
0116
0117
0118 template <G4int NBINS, G4int NMULT> inline
0119 void G4CascadeSampler<NBINS,NMULT>::print(std::ostream& os) const {
0120 interpolator.printBins(os);
0121 }
0122
0123 #endif