Geant4  10.03
G4WeightWindowAlgorithm.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4WeightWindowAlgorithm.cc 66356 2012-12-18 09:02:32Z gcosmo $
28 //
29 // ----------------------------------------------------------------------
30 // GEANT 4 class source file
31 //
32 // G4WeightWindowAlgorithm.cc
33 //
34 // ----------------------------------------------------------------------
36 #include "Randomize.hh"
37 
38 
41  G4double survivalFaktor,
42  G4int maxNumberOfSplits) :
43  fUpperLimitFaktor(upperLimitFaktor),
44  fSurvivalFaktor(survivalFaktor),
45  fMaxNumberOfSplits(maxNumberOfSplits)
46 {}
47 
49 {}
50 
51 
52 
55  G4double lowerWeightBound) const {
56 
57  G4double survivalWeight = lowerWeightBound * fSurvivalFaktor;
58  G4double upperWeight = lowerWeightBound * fUpperLimitFaktor;
59 
60  // initialize return value for case weight in window
61  G4Nsplit_Weight nw;
62  nw.fN = 1;
63  nw.fW = init_w;
64 
65  if (init_w > upperWeight) {
66  // splitting
67 
68  //TB G4double wi_ws = init_w/survivalWeight;
69  //TB
70  G4double temp_wi_ws = init_w/upperWeight;
71  G4int split_i = static_cast<int>(temp_wi_ws);
72  if(split_i != temp_wi_ws) split_i++;
73  G4double wi_ws = init_w/split_i;
74 
75  //TB
76 //TB G4int int_wi_ws = static_cast<int>(wi_ws);
77 
78  // values in case integer mode or in csae of double
79  // mode and the lower number of splits will be diced
80  //TB nw.fN = int_wi_ws;
81  //TB nw.fW = survivalWeight;
82  nw.fN = split_i;
83  nw.fW = wi_ws;
84 
85 //TB if (wi_ws <= fMaxNumberOfSplits) {
86 //TB if (wi_ws > int_wi_ws) {
87 //TB // double mode
88 //TB G4double p2 = wi_ws - int_wi_ws;
89 //TB G4double r = G4UniformRand();
90 //TB if (r<p2) {
91 //TB nw.fN = int_wi_ws + 1;
92 //TB }
93 //TB }
94 //TB }
95 //TB else {
96 //TB // fMaxNumberOfSplits < wi_ws
97 //TB nw.fN = fMaxNumberOfSplits;
98 //TB nw.fW = init_w/fMaxNumberOfSplits;
99 //TB }
100 
101 
102  } else if (init_w < lowerWeightBound) {
103  // Russian roulette
104  G4double wi_ws = init_w/survivalWeight;
105  G4double p = std::max(wi_ws,1./fMaxNumberOfSplits);
106  G4double r = G4UniformRand();
107  if (r<p){
108  nw.fW = init_w/p;
109  nw.fN = 1;
110  } else {
111  nw.fW = 0;
112  nw.fN = 0;
113  }
114  }
115  // else do nothing
116 
117 
118  return nw;
119 }
120 
int G4int
Definition: G4Types.hh:78
virtual G4Nsplit_Weight Calculate(G4double init_w, G4double lowerWeightBound) const
#define G4UniformRand()
Definition: Randomize.hh:97
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4WeightWindowAlgorithm(G4double upperLimitFaktor=5, G4double survivalFaktor=3, G4int maxNumberOfSplits=5)
double G4double
Definition: G4Types.hh:76