Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ImportanceAlgorithm Class Reference

G4ImportanceAlgorithm is a concrete implementation of a G4VImportanceAlgorithm. More...

#include <G4ImportanceAlgorithm.hh>

Inheritance diagram for G4ImportanceAlgorithm:

Public Member Functions

 G4ImportanceAlgorithm ()=default
 ~G4ImportanceAlgorithm () override=default
G4Nsplit_Weight Calculate (G4double ipre, G4double ipost, G4double init_w) const override
Public Member Functions inherited from G4VImportanceAlgorithm
 G4VImportanceAlgorithm ()=default
virtual ~G4VImportanceAlgorithm ()=default

Detailed Description

G4ImportanceAlgorithm is a concrete implementation of a G4VImportanceAlgorithm.

Definition at line 46 of file G4ImportanceAlgorithm.hh.

Constructor & Destructor Documentation

◆ G4ImportanceAlgorithm()

G4ImportanceAlgorithm::G4ImportanceAlgorithm ( )
default

Default Constructor and Destructor.

◆ ~G4ImportanceAlgorithm()

G4ImportanceAlgorithm::~G4ImportanceAlgorithm ( )
overridedefault

Member Function Documentation

◆ Calculate()

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

Calculates the number of tracks and their weight according to the pre and post importance value and the weight of the mother track.

Parameters
[in]ipre"pre" importance value.
[in]ipost"post" importance value.
[in]init_wInitial weight value.
Returns
A struct containing the number of copies (including the mother track) to be produced and the weight of each track.

Implements G4VImportanceAlgorithm.

Definition at line 46 of file G4ImportanceAlgorithm.cc.

49{
50 G4AutoLock l(&ImportanceMutex);
51 G4Nsplit_Weight nw;
52 if (ipost>0.)
53 {
54 if (!(ipre>0.))
55 {
56 Error("Calculate() - ipre==0.");
57 }
58 G4double ipre_over_ipost = ipre/ipost;
59 if ((ipre_over_ipost<0.25 || ipre_over_ipost> 4) && !fWarned)
60 {
61 std::ostringstream os;
62 os << "Calculate() - ipre_over_ipost ! in [0.25, 4]." << G4endl
63 << "ipre_over_ipost = " << ipre_over_ipost << ".";
64 Warning(os.str());
65 fWarned = true;
66 if (ipre_over_ipost<=0)
67 {
68 Error("Calculate() - ipre_over_ipost<=0.");
69 }
70 }
71 if (init_w<=0.)
72 {
73 Error("Calculate() - iniitweight<= 0. found!");
74 }
75
76 // default geometrical splitting
77 // in integer mode
78 // for ipre_over_ipost <= 1
79 G4double inv = 1./ipre_over_ipost;
80 nw.fN = static_cast<G4int>(inv);
81 nw.fW = init_w * ipre_over_ipost;
82
83 // geometrical splitting for double mode
84 if (ipre_over_ipost<1)
85 {
86 if ( static_cast<G4double>(nw.fN) != inv)
87 {
88 // double mode
89 // probability p for splitting into n+1 tracks
90 G4double p = inv - nw.fN;
91 // get a random number out of [0,1)
93 if (r<p)
94 {
95 ++nw.fN;
96 }
97 }
98 }
99 else if (ipre_over_ipost>1) // russian roulette
100 {
101 // probabiity for killing track
102 G4double p = 1-inv;
103 // get a random number out of [0,1)
105 if (r<p)
106 {
107 // kill track
108 nw.fN = 0;
109 nw.fW = 0;
110 }
111 else
112 {
113 nw.fN = 1;
114 }
115 }
116 }
117 l.unlock();
118
119 return nw;
120}
G4TemplateAutoLock< G4Mutex > G4AutoLock
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
#define G4UniformRand()
Definition Randomize.hh:52

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