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.2 2002/05/31 09:56:09 dressel Exp $ >> 25 // GEANT4 tag $Name: geant4-04-01 $ >> 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 33 G4WeightWindowAlgorithm:: << 36 34 G4WeightWindowAlgorithm(G4double upperLimitFac << 37 G4WeightWindowAlgorithm::G4WeightWindowAlgorithm() : 35 G4double survivalFacto << 38 fUpper(1), 36 G4int maxNumberOfSplit << 39 fLower(1) 37 : fUpperLimitFactor(upperLimitFactor), << 40 {} 38 fSurvivalFactor(survivalFactor), << 41 39 fMaxNumberOfSplits(maxNumberOfSplits) << 42 void G4WeightWindowAlgorithm::SetUpperLimit(G4double Upper){ 40 { << 43 fUpper = Upper; >> 44 } >> 45 >> 46 void G4WeightWindowAlgorithm::SetLowerLimit(G4double Lower){ >> 47 fLower = Lower; 41 } 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 importance) const { 48 { << 54 49 G4double survivalWeight = lowerWeightBound * << 55 50 G4double upperWeight = lowerWeightBound * fU << 56 G4Nsplit_Weight nw(1, init_w); 51 << 57 G4double iw = importance * init_w; 52 // initialize return value for case weight i << 58 if (iw>fUpper) { 53 // << 59 // f is the factor by which the weight is greater 54 G4Nsplit_Weight nw; << 60 // than allowed by fUpper 55 nw.fN = 1; << 61 // it is almost the number of coppies to be produced 56 nw.fW = init_w; << 62 G4double f = iw / fUpper; 57 << 63 // calculate new weight 58 if (init_w > upperWeight) << 64 nw.fW/=f; 59 { << 65 60 // splitting << 66 // calculate the number of coppies 61 // << 67 nw.fN = int(f); 62 G4double temp_wi_ws = init_w/upperWeight; << 68 // correct the number of coppies in case f is not an integer 63 auto split_i = static_cast<G4int>(temp_wi << 69 if (G4double(nw.fN) != f) { 64 if(split_i != temp_wi_ws) { ++split_i; } << 70 // probabillity p for splitting into nw.fN+1 particles 65 G4double wi_ws = init_w/split_i; << 71 G4double p = f - nw.fN; 66 << 72 // get a random number out of [0,1) 67 // values in case integer mode or in csae << 73 G4double r = G4UniformRand(); 68 // mode and the lower number of splits wil << 74 if (r<p) { 69 // << 75 nw.fN++; 70 nw.fN = split_i; << 76 } 71 nw.fW = wi_ws; << 77 } 72 << 73 //TB if (wi_ws <= fMaxNumberOfSplits) { << 74 //TB if (wi_ws > int_wi_ws) { << 75 //TB // double mode << 76 //TB G4double p2 = wi_ws - int_wi_ws; << 77 //TB G4double r = G4UniformRand(); << 78 //TB if (r<p2) { << 79 //TB nw.fN = int_wi_ws + 1; << 80 //TB } << 81 //TB } << 82 //TB } << 83 //TB else { << 84 //TB // fMaxNumberOfSplits < wi_ws << 85 //TB nw.fN = fMaxNumberOfSplits; << 86 //TB nw.fW = init_w/fMaxNumberOfSplits; << 87 //TB } << 88 78 89 } 79 } 90 else if (init_w < lowerWeightBound) // Russ << 80 else if (iw < fLower) { 91 { << 81 // play russian roulett 92 G4double wi_ws = init_w/survivalWeight; << 82 G4double p = iw / fLower; // survival prob. 93 G4double p = std::max(wi_ws,1./fMaxNumberO << 94 G4double r = G4UniformRand(); 83 G4double r = G4UniformRand(); 95 if (r<p) << 84 if (r>=p) { 96 { << 85 // kill track 97 nw.fW = init_w/p; << 98 nw.fN = 1; << 99 } << 100 else << 101 { << 102 nw.fW = 0; << 103 nw.fN = 0; 86 nw.fN = 0; 104 } << 87 nw.fW = 0; 105 } << 88 } 106 // else do nothing << 89 else { 107 << 90 nw.fW*=1/p; // to be consistant with the survival prob. >> 91 } >> 92 } 108 return nw; 93 return nw; 109 } 94 } 110 95 111 96