00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "G4Types.hh"
00037 #include <sstream>
00038 #include "Randomize.hh"
00039
00040 #include "G4ImportanceAlgorithm.hh"
00041
00042 G4ImportanceAlgorithm::G4ImportanceAlgorithm(): fWorned(false)
00043 {
00044 }
00045
00046 G4ImportanceAlgorithm::~G4ImportanceAlgorithm()
00047 {
00048 }
00049
00050 G4Nsplit_Weight
00051 G4ImportanceAlgorithm::Calculate(G4double ipre,
00052 G4double ipost,
00053 G4double init_w) const
00054 {
00055 G4Nsplit_Weight nw = {0,0};
00056 if (ipost>0.){
00057 if (!(ipre>0.)){
00058 Error("Calculate() - ipre==0.");
00059 }
00060 G4double ipre_over_ipost = ipre/ipost;
00061 if ((ipre_over_ipost<0.25 || ipre_over_ipost> 4) && !fWorned) {
00062 std::ostringstream os;
00063 os << "Calculate() - ipre_over_ipost ! in [0.25, 4]." << G4endl
00064 << "ipre_over_ipost = " << ipre_over_ipost << ".";
00065 Warning(os.str());
00066 fWorned = true;
00067 if (ipre_over_ipost<=0) {
00068 Error("Calculate() - ipre_over_ipost<=0.");
00069 }
00070 }
00071 if (init_w<=0.) {
00072 Error("Calculate() - iniitweight<= 0. found!");
00073 }
00074
00075
00076
00077
00078 G4double inv = 1./ipre_over_ipost;
00079 nw.fN = static_cast<G4int>(inv);
00080 nw.fW = init_w * ipre_over_ipost;
00081
00082
00083 if (ipre_over_ipost<1) {
00084 if ( static_cast<G4double>(nw.fN) != inv) {
00085
00086
00087 G4double p = inv - nw.fN;
00088
00089 G4double r = G4UniformRand();
00090 if (r<p) {
00091 nw.fN++;
00092 }
00093 }
00094 }
00095
00096
00097 else if (ipre_over_ipost>1) {
00098
00099 G4double p = 1-inv;
00100
00101 G4double r = G4UniformRand();
00102 if (r<p) {
00103
00104 nw.fN = 0;
00105 nw.fW = 0;
00106 }
00107 else {
00108 nw.fN = 1;
00109 }
00110 }
00111 }
00112 return nw;
00113 }
00114
00115 void G4ImportanceAlgorithm::Error(const G4String &msg) const
00116 {
00117 G4Exception("G4ImportanceAlgorithm::Error()",
00118 "GeomBias0002", FatalException, msg);
00119 }
00120
00121 void G4ImportanceAlgorithm::Warning(const G4String &msg) const
00122 {
00123 G4Exception("G4ImportanceAlgorithm::Warning()",
00124 "GeomBias1001", JustWarning, msg);
00125 }