source: trunk/source/geometry/biasing/src/G4ImportanceAlgorithm.cc@ 1195

Last change on this file since 1195 was 1058, checked in by garnier, 17 years ago

file release beta

File size: 4.3 KB
Line 
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,v 1.14 2006/06/29 18:17:20 gunter Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
29//
30// ----------------------------------------------------------------------
31// GEANT 4 class source file
32//
33// G4ImportanceAlgorithm.cc
34//
35// ----------------------------------------------------------------------
36
37#include "G4Types.hh"
38#include <sstream>
39#include "Randomize.hh"
40
41#include "G4ImportanceAlgorithm.hh"
42
43G4ImportanceAlgorithm::G4ImportanceAlgorithm(): fWorned(false)
44{}
45
46G4ImportanceAlgorithm::~G4ImportanceAlgorithm()
47{
48 if(fWorned) {
49 G4cout << G4endl;
50 Warning("~G4ImportanceAlgorithm: ipre_over_ipost ! in [0.25, 4] seen");
51 G4cout << G4endl;
52 }
53}
54
55G4Nsplit_Weight
56G4ImportanceAlgorithm::Calculate(G4double ipre,
57 G4double ipost,
58 G4double init_w) const
59{
60 G4Nsplit_Weight nw = {0,0};
61 if (ipost>0.){
62 if (!(ipre>0.)){
63 Error("G4ImportanceAlgorithm::Calculate() - ipre==0.");
64 }
65 G4double ipre_over_ipost = ipre/ipost;
66 if ((ipre_over_ipost<0.25 || ipre_over_ipost> 4) && !fWorned) {
67 std::ostringstream os;
68 os << "Calculate: ipre_over_ipost ! in [0.25, 4]: ipre_over_ipost = "
69 << ipre_over_ipost << '\0' << G4endl;
70 Warning(os.str());
71 fWorned = true;
72 if (ipre_over_ipost<=0) {
73 Error("G4ImportanceAlgorithm::Calculate() - ipre_over_ipost<=0");
74 }
75 }
76 if (init_w<=0.) {
77 Error("G4ImportanceAlgorithm::Calculate() - iniitweight<= 0. found");
78 }
79
80 // default geometrical splitting
81 // in integer mode
82 // for ipre_over_ipost <= 1
83 G4double inv = 1./ipre_over_ipost;
84 nw.fN = static_cast<G4int>(inv);
85 nw.fW = init_w * ipre_over_ipost;
86
87 // geometrical splitting for double mode
88 if (ipre_over_ipost<1) {
89 if ( static_cast<G4double>(nw.fN) != inv) {
90 // double mode
91 // probability p for splitting into n+1 tracks
92 G4double p = inv - nw.fN;
93 // get a random number out of [0,1)
94 G4double r = G4UniformRand();
95 if (r<p) {
96 nw.fN++;
97 }
98 }
99 }
100 // ipre_over_ipost > 1
101 // russian roulett
102 else if (ipre_over_ipost>1) {
103 // probabiity for killing track
104 G4double p = 1-inv;
105 // get a random number out of [0,1)
106 G4double r = G4UniformRand();
107 if (r<p) {
108 // kill track
109 nw.fN = 0;
110 nw.fW = 0;
111 }
112 else {
113 nw.fN = 1;
114 }
115 }
116 }
117 return nw;
118}
119
120void G4ImportanceAlgorithm::Error(const G4String &m) const
121{
122 G4cerr << "ERROR - G4ImportanceAlgorithm: " << m << G4endl;
123 G4Exception("G4ImportanceAlgorithm::Error()",
124 "FatalException", FatalException, m);
125}
126
127void G4ImportanceAlgorithm::Warning(const G4String &m) const
128{
129 G4Exception("G4ImportanceAlgorithm::Warning()",
130 "Notification", JustWarning, m);
131}
Note: See TracBrowser for help on using the repository browser.