00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 // 00029 #ifndef G4NeutronHPEnergyDistribution_h 00030 #define G4NeutronHPEnergyDistribution_h 1 00031 00032 #include <fstream> 00033 00034 #include "globals.hh" 00035 #include "G4ios.hh" 00036 #include "Randomize.hh" 00037 #include "G4NeutronHPArbitaryTab.hh" 00038 #include "G4NeutronHPEvapSpectrum.hh" 00039 #include "G4NeutronHPSimpleEvapSpectrum.hh" 00040 #include "G4NeutronHPFissionSpectrum.hh" 00041 #include "G4NeutronHPWattSpectrum.hh" 00042 #include "G4NeutronHPMadlandNixSpectrum.hh" 00043 #include "G4VNeutronHPEDis.hh" 00044 00045 // we will need a List of these .... one per term. 00046 00047 class G4NeutronHPEnergyDistribution 00048 { 00049 public: 00050 G4NeutronHPEnergyDistribution() 00051 { 00052 theEnergyDistribution = 0; 00053 theNumberOfPartials = 0; 00054 theRepresentationType = 0; 00055 } 00056 ~G4NeutronHPEnergyDistribution() 00057 { 00058 if(theEnergyDistribution != 0) 00059 { 00060 for(G4int i=0; i<theNumberOfPartials; i++) 00061 { 00062 delete theEnergyDistribution[i]; 00063 } 00064 delete [] theEnergyDistribution; 00065 } 00066 } 00067 00068 inline void Init(std::ifstream & theData) 00069 { 00070 G4double dummy; 00071 theData >> dummy >> theNumberOfPartials; 00072 theEnergyDistribution = new G4VNeutronHPEDis * [theNumberOfPartials]; 00073 for(G4int i=0; i<theNumberOfPartials; i++) 00074 { 00075 theData >> theRepresentationType; 00076 switch(theRepresentationType) 00077 { 00078 case 1: 00079 theEnergyDistribution[i] = new G4NeutronHPArbitaryTab; 00080 break; 00081 case 5: 00082 theEnergyDistribution[i] = new G4NeutronHPEvapSpectrum; 00083 break; 00084 case 7: 00085 theEnergyDistribution[i] = new G4NeutronHPFissionSpectrum; 00086 break; 00087 case 9: 00088 theEnergyDistribution[i] = new G4NeutronHPSimpleEvapSpectrum; 00089 break; 00090 case 11: 00091 theEnergyDistribution[i] = new G4NeutronHPWattSpectrum; 00092 break; 00093 case 12: 00094 theEnergyDistribution[i] = new G4NeutronHPMadlandNixSpectrum; 00095 break; 00096 } 00097 theEnergyDistribution[i]->Init(theData); 00098 } 00099 } 00100 00101 inline G4double Sample(G4double anEnergy, G4int & it) 00102 { 00103 G4double result = 0; 00104 it = 0; 00105 if (theNumberOfPartials != 0) 00106 { 00107 G4double sum=0; 00108 G4double * running = new G4double[theNumberOfPartials]; 00109 running[0] = 0; 00110 G4int i; 00111 for (i=0; i<theNumberOfPartials; i++) 00112 { 00113 if (i!=0) running[i]=running[i-1]; 00114 running[i]+=theEnergyDistribution[i]->GetFractionalProbability(anEnergy); 00115 } 00116 sum = running[theNumberOfPartials-1]; 00117 G4double random = G4UniformRand(); 00118 for(i=0; i<theNumberOfPartials; i++) 00119 { 00120 it = i; 00121 if(running[i]/sum>random) break; 00122 } 00123 delete [] running; 00124 if(it==theNumberOfPartials) it--; 00125 result = theEnergyDistribution[it]->Sample(anEnergy); 00126 } 00127 return result; 00128 } 00129 00130 private: 00131 00132 G4int theNumberOfPartials; 00133 G4int theRepresentationType; 00134 G4VNeutronHPEDis ** theEnergyDistribution; 00135 }; 00136 00137 #endif