File indexing completed on 2025-01-18 09:58:52
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
0027
0028
0029 #ifndef G4ParticleHPEnergyDistribution_h
0030 #define G4ParticleHPEnergyDistribution_h 1
0031
0032 #include "G4ParticleHPArbitaryTab.hh"
0033 #include "G4ParticleHPEvapSpectrum.hh"
0034 #include "G4ParticleHPFissionSpectrum.hh"
0035 #include "G4ParticleHPMadlandNixSpectrum.hh"
0036 #include "G4ParticleHPSimpleEvapSpectrum.hh"
0037 #include "G4ParticleHPWattSpectrum.hh"
0038 #include "G4VParticleHPEDis.hh"
0039 #include "G4ios.hh"
0040 #include "Randomize.hh"
0041 #include "globals.hh"
0042
0043 #include <fstream>
0044
0045
0046
0047 class G4ParticleHPEnergyDistribution
0048 {
0049 public:
0050 G4ParticleHPEnergyDistribution()
0051 {
0052 theEnergyDistribution = nullptr;
0053 theNumberOfPartials = 0;
0054 theRepresentationType = 0;
0055 }
0056 ~G4ParticleHPEnergyDistribution()
0057 {
0058 if (theEnergyDistribution != nullptr) {
0059 for (G4int i = 0; i < theNumberOfPartials; i++) {
0060 delete theEnergyDistribution[i];
0061 }
0062 delete[] theEnergyDistribution;
0063 }
0064 }
0065
0066 inline void Init(std::istream& theData)
0067 {
0068 G4double dummy;
0069 theData >> dummy >> theNumberOfPartials;
0070 theEnergyDistribution = new G4VParticleHPEDis*[theNumberOfPartials];
0071 for (G4int i = 0; i < theNumberOfPartials; i++) {
0072 theData >> theRepresentationType;
0073 switch (theRepresentationType) {
0074 case 1:
0075 theEnergyDistribution[i] = new G4ParticleHPArbitaryTab;
0076 break;
0077 case 5:
0078 theEnergyDistribution[i] = new G4ParticleHPEvapSpectrum;
0079 break;
0080 case 7:
0081 theEnergyDistribution[i] = new G4ParticleHPFissionSpectrum;
0082 break;
0083 case 9:
0084 theEnergyDistribution[i] = new G4ParticleHPSimpleEvapSpectrum;
0085 break;
0086 case 11:
0087 theEnergyDistribution[i] = new G4ParticleHPWattSpectrum;
0088 break;
0089 case 12:
0090 theEnergyDistribution[i] = new G4ParticleHPMadlandNixSpectrum;
0091 break;
0092 default:
0093 theEnergyDistribution[i] = new G4ParticleHPArbitaryTab;
0094 }
0095 theEnergyDistribution[i]->Init(theData);
0096 }
0097 }
0098
0099 inline G4double Sample(G4double anEnergy, G4int& it)
0100 {
0101 G4double result = 0;
0102 it = 0;
0103 if (theNumberOfPartials != 0) {
0104 G4double sum = 0;
0105 auto running = new G4double[theNumberOfPartials];
0106 running[0] = 0;
0107 G4int i;
0108 for (i = 0; i < theNumberOfPartials; i++) {
0109 if (i != 0) running[i] = running[i - 1];
0110 running[i] += theEnergyDistribution[i]->GetFractionalProbability(anEnergy);
0111 }
0112 sum = running[theNumberOfPartials - 1];
0113 G4double random = G4UniformRand();
0114 for (i = 0; i < theNumberOfPartials; i++) {
0115 it = i;
0116 if (running[i] / sum > random) break;
0117 }
0118 delete[] running;
0119 if (it == theNumberOfPartials) it--;
0120 result = theEnergyDistribution[it]->Sample(anEnergy);
0121 }
0122 return result;
0123 }
0124
0125 private:
0126 G4int theNumberOfPartials;
0127 G4int theRepresentationType;
0128 G4VParticleHPEDis** theEnergyDistribution;
0129 };
0130
0131 #endif