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

#include <G4HadPhaseSpaceGenbod.hh>

+ Inheritance diagram for G4HadPhaseSpaceGenbod:

Public Member Functions

 G4HadPhaseSpaceGenbod (G4int verbose=0)
 
virtual ~G4HadPhaseSpaceGenbod ()
 
- Public Member Functions inherited from G4VHadPhaseSpaceAlgorithm
 G4VHadPhaseSpaceAlgorithm (const G4String &algName, G4int verbose=0)
 
virtual ~G4VHadPhaseSpaceAlgorithm ()
 
- Public Member Functions inherited from G4VHadDecayAlgorithm
 G4VHadDecayAlgorithm (const G4String &algName, G4int verbose=0)
 
virtual ~G4VHadDecayAlgorithm ()
 
void Generate (G4double initialMass, const std::vector< G4double > &masses, std::vector< G4LorentzVector > &finalState)
 
virtual void SetVerboseLevel (G4int verbose)
 
G4int GetVerboseLevel () const
 
const G4StringGetName () const
 

Protected Member Functions

virtual void GenerateMultiBody (G4double initialMass, const std::vector< G4double > &masses, std::vector< G4LorentzVector > &finalState)
 
void Initialize (G4double initialMass, const std::vector< G4double > &masses)
 
void FillRandomBuffer ()
 
void ComputeWeightScale (const std::vector< G4double > &masses)
 
void FillEnergySteps (G4double initialMass, const std::vector< G4double > &masses)
 
void GenerateMomenta (const std::vector< G4double > &masses, std::vector< G4LorentzVector > &finalState)
 
void AccumulateFinalState (size_t i, const std::vector< G4double > &masses, std::vector< G4LorentzVector > &finalState)
 
G4bool AcceptEvent () const
 
G4double ComputeWeight () const
 
- Protected Member Functions inherited from G4VHadPhaseSpaceAlgorithm
virtual void GenerateTwoBody (G4double initialMass, const std::vector< G4double > &masses, std::vector< G4LorentzVector > &finalState)
 
G4ThreeVector UniformVector (G4double mag=1.) const
 
- Protected Member Functions inherited from G4VHadDecayAlgorithm
virtual void GenerateTwoBody (G4double initialMass, const std::vector< G4double > &masses, std::vector< G4LorentzVector > &finalState)=0
 
virtual void GenerateMultiBody (G4double initialMass, const std::vector< G4double > &masses, std::vector< G4LorentzVector > &finalState)=0
 
virtual G4bool IsDecayAllowed (G4double initialMass, const std::vector< G4double > &masses) const
 
G4double TwoBodyMomentum (G4double M0, G4double M1, G4double M2) const
 
G4double UniformTheta () const
 
G4double UniformPhi () const
 
void PrintVector (const std::vector< G4double > &v, const G4String &name, std::ostream &os) const
 

Detailed Description

Definition at line 37 of file G4HadPhaseSpaceGenbod.hh.

Constructor & Destructor Documentation

◆ G4HadPhaseSpaceGenbod()

G4HadPhaseSpaceGenbod::G4HadPhaseSpaceGenbod ( G4int  verbose = 0)

Definition at line 51 of file G4HadPhaseSpaceGenbod.cc.

52 : G4VHadPhaseSpaceAlgorithm("G4HadPhaseSpaceGenbod",verbose),
53 nFinal(0), totalMass(0.), massExcess(0.), weightMax(0.), nTrials(0) {;}

◆ ~G4HadPhaseSpaceGenbod()

virtual G4HadPhaseSpaceGenbod::~G4HadPhaseSpaceGenbod ( )
inlinevirtual

Definition at line 40 of file G4HadPhaseSpaceGenbod.hh.

40{;}

Member Function Documentation

◆ AcceptEvent()

G4bool G4HadPhaseSpaceGenbod::AcceptEvent ( ) const
protected

Definition at line 170 of file G4HadPhaseSpaceGenbod.cc.

170 {
171 if (GetVerboseLevel()>1)
172 G4cout << GetName() << "::AcceptEvent? " << nTrials << G4endl;
173
174 return (G4UniformRand() <= ComputeWeight());
175}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
#define G4UniformRand()
Definition: Randomize.hh:52
const G4String & GetName() const

Referenced by GenerateMultiBody().

◆ AccumulateFinalState()

void G4HadPhaseSpaceGenbod::AccumulateFinalState ( size_t  i,
const std::vector< G4double > &  masses,
std::vector< G4LorentzVector > &  finalState 
)
protected

Definition at line 196 of file G4HadPhaseSpaceGenbod.cc.

199 {
200 if (GetVerboseLevel()>2)
201 G4cout << GetName() << "::AccumulateFinalState " << i << G4endl;
202
203 if (i==0) { // First final state particle left alone
204 finalState[i].setVectM(G4ThreeVector(0.,pd[i],0.),masses[i]);
205 return;
206 }
207
208 finalState[i].setVectM(G4ThreeVector(0.,-pd[i-1],0.),masses[i]);
209 G4double phi = G4UniformRand() * twopi;
210 G4double theta = std::acos(2.*G4UniformRand() - 1.);
211
212 if (GetVerboseLevel() > 2) {
213 G4cout << " initialized Py " << -pd[i-1] << " phi " << phi
214 << " theta " << theta << G4endl;
215 }
216
217 G4double esys=0.,beta=0.,gamma=1.;
218 if (i < nFinal-1) { // Do not boost final particle
219 esys = std::sqrt(pd[i]*pd[i]+meff[i]*meff[i]);
220 beta = pd[i] / esys;
221 gamma = esys / meff[i];
222
223 if (GetVerboseLevel()>2)
224 G4cout << " esys " << esys << " beta " << beta << " gamma " << gamma
225 << G4endl;
226 }
227
228 for (size_t j=0; j<=i; j++) { // Accumulate rotations
229 finalState[j].rotateZ(theta).rotateY(phi);
230 finalState[j].setY(gamma*(finalState[j].y() + beta*finalState[j].e()));
231 if (GetVerboseLevel()>2) G4cout << " j " << j << " " << finalState[j] << G4endl;
232 }
233}
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83

Referenced by GenerateMomenta().

◆ ComputeWeight()

G4double G4HadPhaseSpaceGenbod::ComputeWeight ( ) const
protected

Definition at line 163 of file G4HadPhaseSpaceGenbod.cc.

163 {
164 if (GetVerboseLevel()>1) G4cout << GetName() << "::ComputeWeight" << G4endl;
165
166 return (std::accumulate(pd.begin(), pd.end(), 1./weightMax,
167 std::multiplies<G4double>()));
168}

Referenced by AcceptEvent().

◆ ComputeWeightScale()

void G4HadPhaseSpaceGenbod::ComputeWeightScale ( const std::vector< G4double > &  masses)
protected

Definition at line 148 of file G4HadPhaseSpaceGenbod.cc.

148 {
149 if (GetVerboseLevel()>1)
150 G4cout << GetName() << "::ComputeWeightScale" << G4endl;
151
152 weightMax = 1.;
153 for (size_t i=1; i<nFinal; i++) {
154 weightMax *= TwoBodyMomentum(massExcess+msum[i], msum[i-1], masses[i]);
155 }
156
157 if (GetVerboseLevel()>2) G4cout << " weightMax = " << weightMax << G4endl;
158}
G4double TwoBodyMomentum(G4double M0, G4double M1, G4double M2) const

Referenced by Initialize().

◆ FillEnergySteps()

void G4HadPhaseSpaceGenbod::FillEnergySteps ( G4double  initialMass,
const std::vector< G4double > &  masses 
)
protected

Definition at line 123 of file G4HadPhaseSpaceGenbod.cc.

124 {
125 if (GetVerboseLevel()>1) G4cout << GetName() << "::FillEnergySteps" << G4endl;
126
127 meff.clear();
128 pd.clear();
129
130 meff.push_back(masses[0]);
131 for (size_t i=1; i<nFinal-1; i++) {
132 meff.push_back(rndm[i-1]*massExcess + msum[i]);
133 pd.push_back(TwoBodyMomentum(meff[i], meff[i-1], masses[i]));
134 }
135 meff.push_back(initialMass);
136 pd.push_back(TwoBodyMomentum(meff[nFinal-1], meff[nFinal-2], masses[nFinal-1]));
137
138 if (GetVerboseLevel()>2) {
139 PrintVector(meff,"meff",G4cout);
140 PrintVector(pd,"pd",G4cout);
141 }
142}
void PrintVector(const std::vector< G4double > &v, const G4String &name, std::ostream &os) const

Referenced by GenerateMultiBody().

◆ FillRandomBuffer()

void G4HadPhaseSpaceGenbod::FillRandomBuffer ( )
protected

Definition at line 110 of file G4HadPhaseSpaceGenbod.cc.

110 {
111 if (GetVerboseLevel()>1) G4cout << GetName() << "::FillRandomBuffer" << G4endl;
112
113 rndm.resize(nFinal-2,0.); // Final states generated in sorted order
114 std::generate(rndm.begin(), rndm.end(), uniformRand);
115 std::sort(rndm.begin(), rndm.end());
116 if (GetVerboseLevel()>2) PrintVector(rndm, "rndm", G4cout);
117}

Referenced by GenerateMultiBody().

◆ GenerateMomenta()

void G4HadPhaseSpaceGenbod::GenerateMomenta ( const std::vector< G4double > &  masses,
std::vector< G4LorentzVector > &  finalState 
)
protected

Definition at line 180 of file G4HadPhaseSpaceGenbod.cc.

182 {
183 if (GetVerboseLevel()>1) G4cout << GetName() << "::GenerateMomenta" << G4endl;
184
185 finalState.resize(nFinal); // Preallocate vectors for convenience below
186
187 for (size_t i=0; i<nFinal; i++) {
188 AccumulateFinalState(i, masses, finalState);
189 if (GetVerboseLevel()>2)
190 G4cout << " finalState[" << i << "] " << finalState[i] << G4endl;
191 }
192}
void AccumulateFinalState(size_t i, const std::vector< G4double > &masses, std::vector< G4LorentzVector > &finalState)

Referenced by GenerateMultiBody().

◆ GenerateMultiBody()

void G4HadPhaseSpaceGenbod::GenerateMultiBody ( G4double  initialMass,
const std::vector< G4double > &  masses,
std::vector< G4LorentzVector > &  finalState 
)
protectedvirtual

Implements G4VHadDecayAlgorithm.

Definition at line 58 of file G4HadPhaseSpaceGenbod.cc.

61 {
62 if (GetVerboseLevel()) G4cout << GetName() << "::GenerateMultiBody" << G4endl;
63
64 finalState.clear();
65
66 Initialize(initialMass, masses);
67
68 const G4int maxNumberOfLoops = 10000;
69 nTrials = 0;
70 do { // Apply accept/reject to get distribution
71 ++nTrials;
73 FillEnergySteps(initialMass, masses);
74 } while ( (!AcceptEvent()) && nTrials < maxNumberOfLoops ); /* Loop checking, 02.11.2015, A.Ribon */
75 if ( nTrials >= maxNumberOfLoops ) {
77 ed << " Failed sampling after maxNumberOfLoops attempts : forced exit" << G4endl;
78 G4Exception( " G4HadPhaseSpaceGenbod::GenerateMultiBody ", "HAD_GENBOD_001", FatalException, ed );
79 }
80 GenerateMomenta(masses, finalState);
81}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
int G4int
Definition: G4Types.hh:85
void GenerateMomenta(const std::vector< G4double > &masses, std::vector< G4LorentzVector > &finalState)
void Initialize(G4double initialMass, const std::vector< G4double > &masses)
void FillEnergySteps(G4double initialMass, const std::vector< G4double > &masses)

◆ Initialize()

void G4HadPhaseSpaceGenbod::Initialize ( G4double  initialMass,
const std::vector< G4double > &  masses 
)
protected

Definition at line 83 of file G4HadPhaseSpaceGenbod.cc.

84 {
85 if (GetVerboseLevel()>1) G4cout << GetName() << "::Initialize" << G4endl;
86
87 nFinal = masses.size();
88 msum.resize(nFinal, 0.); // Initialize buffers for filling
89 msq.resize(nFinal, 0.);
90
91 std::partial_sum(masses.begin(), masses.end(), msum.begin());
92 std::transform(masses.begin(), masses.end(), masses.begin(), msq.begin(),
93 std::multiplies<G4double>());
94 totalMass = msum.back();
95 massExcess = initialMass - totalMass;
96
97 if (GetVerboseLevel()>2) {
98 PrintVector(msum, "msum", G4cout);
99 PrintVector(msq, "msq", G4cout);
100 G4cout << " totalMass " << totalMass << " massExcess " << massExcess
101 << G4endl;
102 }
103
104 ComputeWeightScale(masses);
105}
void ComputeWeightScale(const std::vector< G4double > &masses)

Referenced by GenerateMultiBody().


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