[819] | 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 | // $Id: G4NeutronHPEnergyDistribution.hh,v 1.11 2007/06/06 12:45:13 ahoward Exp $ |
---|
[1196] | 28 | // GEANT4 tag $Name: geant4-09-03-cand-01 $ |
---|
[819] | 29 | // |
---|
| 30 | #ifndef G4NeutronHPEnergyDistribution_h |
---|
| 31 | #define G4NeutronHPEnergyDistribution_h 1 |
---|
| 32 | |
---|
| 33 | #include "globals.hh" |
---|
| 34 | #include "G4ios.hh" |
---|
| 35 | #include <fstream> |
---|
| 36 | #include "G4NeutronHPArbitaryTab.hh" |
---|
| 37 | #include "G4NeutronHPEvapSpectrum.hh" |
---|
| 38 | #include "G4NeutronHPSimpleEvapSpectrum.hh" |
---|
| 39 | #include "G4NeutronHPFissionSpectrum.hh" |
---|
| 40 | #include "G4NeutronHPWattSpectrum.hh" |
---|
| 41 | #include "G4NeutronHPMadlandNixSpectrum.hh" |
---|
| 42 | #include "G4VNeutronHPEDis.hh" |
---|
| 43 | #include "Randomize.hh" |
---|
| 44 | |
---|
| 45 | // we will need a List of these .... one per term. |
---|
| 46 | |
---|
| 47 | class G4NeutronHPEnergyDistribution |
---|
| 48 | { |
---|
| 49 | public: |
---|
| 50 | G4NeutronHPEnergyDistribution() |
---|
| 51 | { |
---|
| 52 | theEnergyDistribution = 0; |
---|
| 53 | theNumberOfPartials = 0; |
---|
| 54 | theRepresentationType = 0; |
---|
| 55 | } |
---|
| 56 | ~G4NeutronHPEnergyDistribution() |
---|
| 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::ifstream & theData) |
---|
| 69 | { |
---|
| 70 | G4double dummy; |
---|
| 71 | theData >> dummy >> theNumberOfPartials; |
---|
| 72 | theEnergyDistribution = new G4VNeutronHPEDis * [theNumberOfPartials]; |
---|
| 73 | for(G4int i=0; i<theNumberOfPartials; i++) |
---|
| 74 | { |
---|
| 75 | theData >> theRepresentationType; |
---|
| 76 | switch(theRepresentationType) |
---|
| 77 | { |
---|
| 78 | case 1: |
---|
| 79 | theEnergyDistribution[i] = new G4NeutronHPArbitaryTab; |
---|
| 80 | break; |
---|
| 81 | case 5: |
---|
| 82 | theEnergyDistribution[i] = new G4NeutronHPEvapSpectrum; |
---|
| 83 | break; |
---|
| 84 | case 7: |
---|
| 85 | theEnergyDistribution[i] = new G4NeutronHPFissionSpectrum; |
---|
| 86 | break; |
---|
| 87 | case 9: |
---|
| 88 | theEnergyDistribution[i] = new G4NeutronHPSimpleEvapSpectrum; |
---|
| 89 | break; |
---|
| 90 | case 11: |
---|
| 91 | theEnergyDistribution[i] = new G4NeutronHPWattSpectrum; |
---|
| 92 | break; |
---|
| 93 | case 12: |
---|
| 94 | theEnergyDistribution[i] = new G4NeutronHPMadlandNixSpectrum; |
---|
| 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 | G4VNeutronHPEDis ** theEnergyDistribution; |
---|
| 135 | }; |
---|
| 136 | |
---|
| 137 | #endif |
---|