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 // ---------------------------------------------------------------------- 00030 // GEANT 4 class source file 00031 // 00032 // G4WeightWindowAlgorithm.cc 00033 // 00034 // ---------------------------------------------------------------------- 00035 #include "G4WeightWindowAlgorithm.hh" 00036 #include "Randomize.hh" 00037 00038 00039 G4WeightWindowAlgorithm:: 00040 G4WeightWindowAlgorithm(G4double upperLimitFaktor, 00041 G4double survivalFaktor, 00042 G4int maxNumberOfSplits) : 00043 fUpperLimitFaktor(upperLimitFaktor), 00044 fSurvivalFaktor(survivalFaktor), 00045 fMaxNumberOfSplits(maxNumberOfSplits) 00046 {} 00047 00048 G4WeightWindowAlgorithm::~G4WeightWindowAlgorithm() 00049 {} 00050 00051 00052 00053 G4Nsplit_Weight 00054 G4WeightWindowAlgorithm::Calculate(G4double init_w, 00055 G4double lowerWeightBound) const { 00056 00057 G4double survivalWeight = lowerWeightBound * fSurvivalFaktor; 00058 G4double upperWeight = lowerWeightBound * fUpperLimitFaktor; 00059 00060 // initialize return value for case weight in window 00061 G4Nsplit_Weight nw; 00062 nw.fN = 1; 00063 nw.fW = init_w; 00064 00065 if (init_w > upperWeight) { 00066 // splitting 00067 00068 //TB G4double wi_ws = init_w/survivalWeight; 00069 //TB 00070 G4double temp_wi_ws = init_w/upperWeight; 00071 G4int split_i = static_cast<int>(temp_wi_ws); 00072 if(split_i != temp_wi_ws) split_i++; 00073 G4double wi_ws = init_w/split_i; 00074 00075 //TB 00076 //TB G4int int_wi_ws = static_cast<int>(wi_ws); 00077 00078 // values in case integer mode or in csae of double 00079 // mode and the lower number of splits will be diced 00080 //TB nw.fN = int_wi_ws; 00081 //TB nw.fW = survivalWeight; 00082 nw.fN = split_i; 00083 nw.fW = wi_ws; 00084 00085 //TB if (wi_ws <= fMaxNumberOfSplits) { 00086 //TB if (wi_ws > int_wi_ws) { 00087 //TB // double mode 00088 //TB G4double p2 = wi_ws - int_wi_ws; 00089 //TB G4double r = G4UniformRand(); 00090 //TB if (r<p2) { 00091 //TB nw.fN = int_wi_ws + 1; 00092 //TB } 00093 //TB } 00094 //TB } 00095 //TB else { 00096 //TB // fMaxNumberOfSplits < wi_ws 00097 //TB nw.fN = fMaxNumberOfSplits; 00098 //TB nw.fW = init_w/fMaxNumberOfSplits; 00099 //TB } 00100 00101 00102 } else if (init_w < lowerWeightBound) { 00103 // Russian roulette 00104 G4double wi_ws = init_w/survivalWeight; 00105 G4double p = std::max(wi_ws,1./fMaxNumberOfSplits); 00106 G4double r = G4UniformRand(); 00107 if (r<p){ 00108 nw.fW = init_w/p; 00109 nw.fN = 1; 00110 } else { 00111 nw.fW = 0; 00112 nw.fN = 0; 00113 } 00114 } 00115 // else do nothing 00116 00117 00118 return nw; 00119 } 00120