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