Geant4  10.00.p02
G4ImportanceAlgorithm.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: G4ImportanceAlgorithm.cc 66356 2012-12-18 09:02:32Z gcosmo $
28 //
29 // ----------------------------------------------------------------------
30 // GEANT 4 class source file
31 //
32 // G4ImportanceAlgorithm.cc
33 //
34 // ----------------------------------------------------------------------
35 
36 #include "G4Types.hh"
37 #include <sstream>
38 #include "Randomize.hh"
39 
40 #include "G4ImportanceAlgorithm.hh"
41 
43 {
44 }
45 
47 {
48 }
49 
52  G4double ipost,
53  G4double init_w) const
54 {
55  G4Nsplit_Weight nw = {0,0};
56  if (ipost>0.){
57  if (!(ipre>0.)){
58  Error("Calculate() - ipre==0.");
59  }
60  G4double ipre_over_ipost = ipre/ipost;
61  if ((ipre_over_ipost<0.25 || ipre_over_ipost> 4) && !fWorned) {
62  std::ostringstream os;
63  os << "Calculate() - ipre_over_ipost ! in [0.25, 4]." << G4endl
64  << "ipre_over_ipost = " << ipre_over_ipost << ".";
65  Warning(os.str());
66  fWorned = true;
67  if (ipre_over_ipost<=0) {
68  Error("Calculate() - ipre_over_ipost<=0.");
69  }
70  }
71  if (init_w<=0.) {
72  Error("Calculate() - iniitweight<= 0. found!");
73  }
74 
75  // default geometrical splitting
76  // in integer mode
77  // for ipre_over_ipost <= 1
78  G4double inv = 1./ipre_over_ipost;
79  nw.fN = static_cast<G4int>(inv);
80  nw.fW = init_w * ipre_over_ipost;
81 
82  // geometrical splitting for double mode
83  if (ipre_over_ipost<1) {
84  if ( static_cast<G4double>(nw.fN) != inv) {
85  // double mode
86  // probability p for splitting into n+1 tracks
87  G4double p = inv - nw.fN;
88  // get a random number out of [0,1)
89  G4double r = G4UniformRand();
90  if (r<p) {
91  nw.fN++;
92  }
93  }
94  }
95  // ipre_over_ipost > 1
96  // russian roulett
97  else if (ipre_over_ipost>1) {
98  // probabiity for killing track
99  G4double p = 1-inv;
100  // get a random number out of [0,1)
101  G4double r = G4UniformRand();
102  if (r<p) {
103  // kill track
104  nw.fN = 0;
105  nw.fW = 0;
106  }
107  else {
108  nw.fN = 1;
109  }
110  }
111  }
112  return nw;
113 }
114 
116 {
117  G4Exception("G4ImportanceAlgorithm::Error()",
118  "GeomBias0002", FatalException, msg);
119 }
120 
122 {
123  G4Exception("G4ImportanceAlgorithm::Warning()",
124  "GeomBias1001", JustWarning, msg);
125 }
virtual G4Nsplit_Weight Calculate(G4double ipre, G4double ipost, G4double init_w) const
void Error(const G4String &m) const
int G4int
Definition: G4Types.hh:78
#define G4UniformRand()
Definition: Randomize.hh:87
void Warning(const G4String &m) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76