Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4WeightWindowAlgorithm implementation << 27 // 23 // 28 // Author: Michael Dressel (CERN), 2003 << 24 // $Id: G4WeightWindowAlgorithm.cc,v 1.7 2003/08/19 15:16:56 dressel Exp $ >> 25 // GEANT4 tag $Name: geant4-08-00 $ >> 26 // >> 27 // ---------------------------------------------------------------------- >> 28 // GEANT 4 class source file >> 29 // >> 30 // G4WeightWindowAlgorithm.cc >> 31 // 29 // ------------------------------------------- 32 // ---------------------------------------------------------------------- 30 #include "G4WeightWindowAlgorithm.hh" 33 #include "G4WeightWindowAlgorithm.hh" 31 #include "Randomize.hh" 34 #include "Randomize.hh" 32 35 >> 36 33 G4WeightWindowAlgorithm:: 37 G4WeightWindowAlgorithm:: 34 G4WeightWindowAlgorithm(G4double upperLimitFac << 38 G4WeightWindowAlgorithm(G4double upperLimitFaktor, 35 G4double survivalFacto << 39 G4double survivalFaktor, 36 G4int maxNumberOfSplit << 40 G4int maxNumberOfSplits) : 37 : fUpperLimitFactor(upperLimitFactor), << 41 fUpperLimitFaktor(upperLimitFaktor), 38 fSurvivalFactor(survivalFactor), << 42 fSurvivalFaktor(survivalFaktor), 39 fMaxNumberOfSplits(maxNumberOfSplits) << 43 fMaxNumberOfSplits(maxNumberOfSplits) 40 { << 44 {} 41 } << 45 >> 46 G4WeightWindowAlgorithm::~G4WeightWindowAlgorithm() >> 47 {} >> 48 42 49 43 G4WeightWindowAlgorithm::~G4WeightWindowAlgori << 44 50 45 G4Nsplit_Weight 51 G4Nsplit_Weight 46 G4WeightWindowAlgorithm::Calculate(G4double in 52 G4WeightWindowAlgorithm::Calculate(G4double init_w, 47 G4double lo << 53 G4double lowerWeightBound) const { 48 { << 54 49 G4double survivalWeight = lowerWeightBound * << 55 G4double survivalWeight = lowerWeightBound * fSurvivalFaktor; 50 G4double upperWeight = lowerWeightBound * fU << 56 G4double upperWeight = lowerWeightBound * fUpperLimitFaktor; 51 57 52 // initialize return value for case weight i 58 // initialize return value for case weight in window 53 // << 54 G4Nsplit_Weight nw; 59 G4Nsplit_Weight nw; 55 nw.fN = 1; 60 nw.fN = 1; 56 nw.fW = init_w; 61 nw.fW = init_w; 57 62 58 if (init_w > upperWeight) << 63 if (init_w > upperWeight) { 59 { << 60 // splitting 64 // splitting 61 // << 65 62 G4double temp_wi_ws = init_w/upperWeight; << 66 G4double wi_ws = init_w/survivalWeight; 63 auto split_i = static_cast<G4int>(temp_wi << 67 G4int int_wi_ws = static_cast<int>(wi_ws); 64 if(split_i != temp_wi_ws) { ++split_i; } << 65 G4double wi_ws = init_w/split_i; << 66 68 67 // values in case integer mode or in csae 69 // values in case integer mode or in csae of double 68 // mode and the lower number of splits wil 70 // mode and the lower number of splits will be diced 69 // << 71 nw.fN = int_wi_ws; 70 nw.fN = split_i; << 72 nw.fW = survivalWeight; 71 nw.fW = wi_ws; << 73 72 << 74 if (wi_ws <= fMaxNumberOfSplits) { 73 //TB if (wi_ws <= fMaxNumberOfSplits) { << 75 if (wi_ws > int_wi_ws) { 74 //TB if (wi_ws > int_wi_ws) { << 76 // double mode 75 //TB // double mode << 77 G4double p2 = wi_ws - int_wi_ws; 76 //TB G4double p2 = wi_ws - int_wi_ws; << 78 G4double r = G4UniformRand(); 77 //TB G4double r = G4UniformRand(); << 79 if (r<p2) { 78 //TB if (r<p2) { << 80 nw.fN = int_wi_ws + 1; 79 //TB nw.fN = int_wi_ws + 1; << 81 } 80 //TB } << 82 } 81 //TB } << 83 } 82 //TB } << 84 else { 83 //TB else { << 85 // fMaxNumberOfSplits < wi_ws 84 //TB // fMaxNumberOfSplits < wi_ws << 86 nw.fN = fMaxNumberOfSplits; 85 //TB nw.fN = fMaxNumberOfSplits; << 87 nw.fW = init_w/fMaxNumberOfSplits; 86 //TB nw.fW = init_w/fMaxNumberOfSplits; << 88 } 87 //TB } << 89 88 << 90 89 } << 91 } else if (init_w < lowerWeightBound) { 90 else if (init_w < lowerWeightBound) // Russ << 92 // Russian roulette 91 { << 92 G4double wi_ws = init_w/survivalWeight; 93 G4double wi_ws = init_w/survivalWeight; 93 G4double p = std::max(wi_ws,1./fMaxNumberO 94 G4double p = std::max(wi_ws,1./fMaxNumberOfSplits); 94 G4double r = G4UniformRand(); 95 G4double r = G4UniformRand(); 95 if (r<p) << 96 if (r<p){ 96 { << 97 nw.fW = init_w/p; 97 nw.fW = init_w/p; 98 nw.fN = 1; 98 nw.fN = 1; 99 } << 99 } else { 100 else << 101 { << 102 nw.fW = 0; 100 nw.fW = 0; 103 nw.fN = 0; 101 nw.fN = 0; 104 } 102 } 105 } 103 } 106 // else do nothing 104 // else do nothing 107 << 105 >> 106 108 return nw; 107 return nw; 109 } 108 } 110 109 111 110