Geant4 11.1.1
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
32#include <fstream>
33
34#include "globals.hh"
35#include "G4ios.hh"
36#include "Randomize.hh"
43#include "G4VParticleHPEDis.hh"
44
45// we will need a List of these .... one per term.
46
48{
49 public:
51 {
52 theEnergyDistribution = 0;
53 theNumberOfPartials = 0;
54 theRepresentationType = 0;
55 }
57 {
58 if(theEnergyDistribution != 0)
59 {
60 for(G4int i=0; i<theNumberOfPartials; i++)
61 {
62 delete theEnergyDistribution[i];
63 }
64 delete [] theEnergyDistribution;
65 }
66 }
67
68 inline void Init(std::istream & theData)
69 {
70 G4double dummy;
71 theData >> dummy >> theNumberOfPartials;
72 theEnergyDistribution = new G4VParticleHPEDis * [theNumberOfPartials];
73 for(G4int i=0; i<theNumberOfPartials; i++)
74 {
75 theData >> theRepresentationType;
76 switch(theRepresentationType)
77 {
78 case 1:
79 theEnergyDistribution[i] = new G4ParticleHPArbitaryTab;
80 break;
81 case 5:
82 theEnergyDistribution[i] = new G4ParticleHPEvapSpectrum;
83 break;
84 case 7:
85 theEnergyDistribution[i] = new G4ParticleHPFissionSpectrum;
86 break;
87 case 9:
88 theEnergyDistribution[i] = new G4ParticleHPSimpleEvapSpectrum;
89 break;
90 case 11:
91 theEnergyDistribution[i] = new G4ParticleHPWattSpectrum;
92 break;
93 case 12:
94 theEnergyDistribution[i] = new G4ParticleHPMadlandNixSpectrum;
95 break;
96 }
97 theEnergyDistribution[i]->Init(theData);
98 }
99 }
100
101 inline G4double Sample(G4double anEnergy, G4int & it)
102 {
103 G4double result = 0;
104 it = 0;
105 if (theNumberOfPartials != 0)
106 {
107 G4double sum=0;
108 G4double * running = new G4double[theNumberOfPartials];
109 running[0] = 0;
110 G4int i;
111 for (i=0; i<theNumberOfPartials; i++)
112 {
113 if (i!=0) running[i]=running[i-1];
114 running[i]+=theEnergyDistribution[i]->GetFractionalProbability(anEnergy);
115 }
116 sum = running[theNumberOfPartials-1];
117 G4double random = G4UniformRand();
118 for(i=0; i<theNumberOfPartials; i++)
119 {
120 it = i;
121 if(running[i]/sum>random) break;
122 }
123 delete [] running;
124 if(it==theNumberOfPartials) it--;
125 result = theEnergyDistribution[it]->Sample(anEnergy);
126 }
127 return result;
128 }
129
130 private:
131
132 G4int theNumberOfPartials;
133 G4int theRepresentationType;
134 G4VParticleHPEDis ** theEnergyDistribution;
135};
136
137#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