Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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// G4ImportanceAlgorithm implementation
27//
28// Author: Michael Dressel (CERN), 2002
29// ----------------------------------------------------------------------
30
31#include "G4Types.hh"
32#include <sstream>
33#include "Randomize.hh"
34#include "G4Threading.hh"
35
37
38#ifdef G4MULTITHREADED
39G4Mutex G4ImportanceAlgorithm::ImportanceMutex = G4MUTEX_INITIALIZER;
40#endif
41
43{
44}
45
47{
48}
49
52 G4double ipost,
53 G4double init_w) const
54{
55
56#ifdef G4MULTITHREADED
57 G4MUTEXLOCK(&G4ImportanceAlgorithm::ImportanceMutex);
58#endif
59
61 if (ipost>0.)
62 {
63 if (!(ipre>0.))
64 {
65 Error("Calculate() - ipre==0.");
66 }
67 G4double ipre_over_ipost = ipre/ipost;
68 if ((ipre_over_ipost<0.25 || ipre_over_ipost> 4) && !fWarned)
69 {
70 std::ostringstream os;
71 os << "Calculate() - ipre_over_ipost ! in [0.25, 4]." << G4endl
72 << "ipre_over_ipost = " << ipre_over_ipost << ".";
73 Warning(os.str());
74 fWarned = true;
75 if (ipre_over_ipost<=0)
76 {
77 Error("Calculate() - ipre_over_ipost<=0.");
78 }
79 }
80 if (init_w<=0.)
81 {
82 Error("Calculate() - iniitweight<= 0. found!");
83 }
84
85 // default geometrical splitting
86 // in integer mode
87 // for ipre_over_ipost <= 1
88 G4double inv = 1./ipre_over_ipost;
89 nw.fN = static_cast<G4int>(inv);
90 nw.fW = init_w * ipre_over_ipost;
91
92 // geometrical splitting for double mode
93 if (ipre_over_ipost<1)
94 {
95 if ( static_cast<G4double>(nw.fN) != inv)
96 {
97 // double mode
98 // probability p for splitting into n+1 tracks
99 G4double p = inv - nw.fN;
100 // get a random number out of [0,1)
102 if (r<p)
103 {
104 ++nw.fN;
105 }
106 }
107 }
108 else if (ipre_over_ipost>1) // russian roulette
109 {
110 // probabiity for killing track
111 G4double p = 1-inv;
112 // get a random number out of [0,1)
114 if (r<p)
115 {
116 // kill track
117 nw.fN = 0;
118 nw.fW = 0;
119 }
120 else
121 {
122 nw.fN = 1;
123 }
124 }
125 }
126#ifdef G4MULTITHREADED
127 G4MUTEXUNLOCK(&G4ImportanceAlgorithm::ImportanceMutex);
128#endif
129 return nw;
130}
131
132void G4ImportanceAlgorithm::Error(const G4String& msg) const
133{
134 G4Exception("G4ImportanceAlgorithm::Error()",
135 "GeomBias0002", FatalException, msg);
136}
137
138void G4ImportanceAlgorithm::Warning(const G4String& msg) const
139{
140 G4Exception("G4ImportanceAlgorithm::Warning()",
141 "GeomBias1001", JustWarning, msg);
142}
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:85
#define G4MUTEXLOCK(mutex)
Definition: G4Threading.hh:251
#define G4MUTEXUNLOCK(mutex)
Definition: G4Threading.hh:254
std::mutex G4Mutex
Definition: G4Threading.hh:81
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
#define G4UniformRand()
Definition: Randomize.hh:52
virtual G4Nsplit_Weight Calculate(G4double ipre, G4double ipost, G4double init_w) const