Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ParticleHPEnergyDistribution.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// P. Arce, June-2014 Conversion neutron_hp to particle_hp
28//
29#ifndef G4ParticleHPEnergyDistribution_h
30#define G4ParticleHPEnergyDistribution_h 1
31
38#include "G4VParticleHPEDis.hh"
39#include "G4ios.hh"
40#include "Randomize.hh"
41#include "globals.hh"
42
43#include <fstream>
44
45// we will need a List of these .... one per term.
46
48{
49 public:
51 {
52 theEnergyDistribution = nullptr;
53 theNumberOfPartials = 0;
54 theRepresentationType = 0;
55 }
57 {
58 if (theEnergyDistribution != nullptr) {
59 for (G4int i = 0; i < theNumberOfPartials; i++) {
60 delete theEnergyDistribution[i];
61 }
62 delete[] theEnergyDistribution;
63 }
64 }
65
66 inline void Init(std::istream& theData)
67 {
68 G4double dummy;
69 theData >> dummy >> theNumberOfPartials;
70 theEnergyDistribution = new G4VParticleHPEDis*[theNumberOfPartials];
71 for (G4int i = 0; i < theNumberOfPartials; i++) {
72 theData >> theRepresentationType;
73 switch (theRepresentationType) {
74 case 1:
75 theEnergyDistribution[i] = new G4ParticleHPArbitaryTab;
76 break;
77 case 5:
78 theEnergyDistribution[i] = new G4ParticleHPEvapSpectrum;
79 break;
80 case 7:
81 theEnergyDistribution[i] = new G4ParticleHPFissionSpectrum;
82 break;
83 case 9:
84 theEnergyDistribution[i] = new G4ParticleHPSimpleEvapSpectrum;
85 break;
86 case 11:
87 theEnergyDistribution[i] = new G4ParticleHPWattSpectrum;
88 break;
89 case 12:
90 theEnergyDistribution[i] = new G4ParticleHPMadlandNixSpectrum;
91 break;
92 default:
93 theEnergyDistribution[i] = new G4ParticleHPArbitaryTab;
94 }
95 theEnergyDistribution[i]->Init(theData);
96 }
97 }
98
99 inline G4double Sample(G4double anEnergy, G4int& it)
100 {
101 G4double result = 0;
102 it = 0;
103 if (theNumberOfPartials != 0) {
104 G4double sum = 0;
105 auto running = new G4double[theNumberOfPartials];
106 running[0] = 0;
107 G4int i;
108 for (i = 0; i < theNumberOfPartials; i++) {
109 if (i != 0) running[i] = running[i - 1];
110 running[i] += theEnergyDistribution[i]->GetFractionalProbability(anEnergy);
111 }
112 sum = running[theNumberOfPartials - 1];
113 G4double random = G4UniformRand();
114 for (i = 0; i < theNumberOfPartials; i++) {
115 it = i;
116 if (running[i] / sum > random) break;
117 }
118 delete[] running;
119 if (it == theNumberOfPartials) it--;
120 result = theEnergyDistribution[it]->Sample(anEnergy);
121 }
122 return result;
123 }
124
125 private:
126 G4int theNumberOfPartials;
127 G4int theRepresentationType;
128 G4VParticleHPEDis** theEnergyDistribution;
129};
130
131#endif
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
#define G4UniformRand()
Definition Randomize.hh:52
G4double Sample(G4double anEnergy, G4int &it)
virtual void Init(std::istream &theData)=0
virtual G4double GetFractionalProbability(G4double anEnergy)=0
virtual G4double Sample(G4double anEnergy)=0