Geant4-11
Public Member Functions | Private Member Functions | Private Attributes
G4ImportanceAlgorithm Class Reference

#include <G4ImportanceAlgorithm.hh>

Inheritance diagram for G4ImportanceAlgorithm:
G4VImportanceAlgorithm

Public Member Functions

virtual G4Nsplit_Weight Calculate (G4double ipre, G4double ipost, G4double init_w) const
 
 G4ImportanceAlgorithm ()
 
virtual ~G4ImportanceAlgorithm ()
 

Private Member Functions

void Error (const G4String &m) const
 
void Warning (const G4String &m) const
 

Private Attributes

G4bool fWarned = false
 

Detailed Description

Definition at line 41 of file G4ImportanceAlgorithm.hh.

Constructor & Destructor Documentation

◆ G4ImportanceAlgorithm()

G4ImportanceAlgorithm::G4ImportanceAlgorithm ( )

Definition at line 42 of file G4ImportanceAlgorithm.cc.

43{
44}

◆ ~G4ImportanceAlgorithm()

G4ImportanceAlgorithm::~G4ImportanceAlgorithm ( )
virtual

Definition at line 46 of file G4ImportanceAlgorithm.cc.

47{
48}

Member Function Documentation

◆ Calculate()

G4Nsplit_Weight G4ImportanceAlgorithm::Calculate ( G4double  ipre,
G4double  ipost,
G4double  init_w 
) const
virtual

Implements G4VImportanceAlgorithm.

Definition at line 51 of file G4ImportanceAlgorithm.cc.

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}
#define G4MUTEXLOCK(mutex)
Definition: G4Threading.hh:251
#define G4MUTEXUNLOCK(mutex)
Definition: G4Threading.hh:254
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
#define G4UniformRand()
Definition: Randomize.hh:52
void Warning(const G4String &m) const
void Error(const G4String &m) const

References Error(), G4Nsplit_Weight::fN, G4Nsplit_Weight::fW, fWarned, G4endl, G4MUTEXLOCK, G4MUTEXUNLOCK, G4UniformRand, and Warning().

◆ Error()

void G4ImportanceAlgorithm::Error ( const G4String m) const
private

Definition at line 132 of file G4ImportanceAlgorithm.cc.

133{
134 G4Exception("G4ImportanceAlgorithm::Error()",
135 "GeomBias0002", FatalException, msg);
136}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35

References FatalException, and G4Exception().

Referenced by Calculate().

◆ Warning()

void G4ImportanceAlgorithm::Warning ( const G4String m) const
private

Definition at line 138 of file G4ImportanceAlgorithm.cc.

139{
140 G4Exception("G4ImportanceAlgorithm::Warning()",
141 "GeomBias1001", JustWarning, msg);
142}
@ JustWarning

References G4Exception(), and JustWarning.

Referenced by Calculate().

Field Documentation

◆ fWarned

G4bool G4ImportanceAlgorithm::fWarned = false
mutableprivate

Definition at line 64 of file G4ImportanceAlgorithm.hh.

Referenced by Calculate().


The documentation for this class was generated from the following files: