Geant4-11
G4CascadeFunctions.icc
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#ifndef G4_CASCADE_FUNCTIONS_ICC
27#define G4_CASCADE_FUNCTIONS_ICC
28//
29// 20100512 M. Kelsey -- Pass std::vector<> buffer as argument to
30// getOutgoingPartTypes().
31// 20100803 M. Kelsey -- Add printing function for debugging
32// 20100804 M. Kelsey -- Pretty up printing function
33// 20110725 M. Kelsey -- Use ctor to register table in lookup factory
34// 20110728 M. Kelsey -- Fix Coverity #22955, recursive #include; fix
35// Coverity #20228, test (mult>maxMult), set to max if over
36// 20110916 M. Kelsey -- Drop self-registration due to platform inconsistencies
37// Drop "inline" keyword on complex functions
38// 20110923 M. Kelsey -- Add optional ostream& argument to printTable(),
39// pass through to SAMP and DATA
40
41#include "G4CascadeChannelTables.hh"
42#include "globals.hh"
43
44
45// Constructor registers table in lookup
46
47template <class DATA, class SAMP>
48G4CascadeFunctions<DATA,SAMP>::G4CascadeFunctions() : SAMP() {}
49
50
51// Compare summed partial cross section with total cross section
52// Truncate multiplicity at maximum if summed < total
53
54template <class DATA, class SAMP>
55G4int G4CascadeFunctions<DATA,SAMP>::getMultiplicity(G4double ke) const {
56 // Use pointer comparison to see whether tot is just a ref to sum)
57 if (&DATA::data.sum != &DATA::data.tot) {
58 G4double summed = this->findCrossSection(ke, DATA::data.sum);
59 G4double total = this->findCrossSection(ke, DATA::data.tot);
60 if (G4UniformRand() > summed/total) return DATA::data.maxMultiplicity();
61 }
62
63 return this->findMultiplicity(ke, DATA::data.multiplicities);
64}
65
66
67// Generate list of final state particles
68
69template <class DATA, class SAMP>
70void G4CascadeFunctions<DATA,SAMP>::
71getOutgoingParticleTypes(std::vector<G4int>& kinds,
72 G4int mult, G4double ke) const {
73 const G4int maxMult = DATA::data.maxMultiplicity();
74
75 if (mult > maxMult) {
76 G4cerr << " Illegal multiplicity " << mult << " > " << maxMult << G4endl;
77 mult = maxMult;
78 }
79
80 kinds.clear();
81 kinds.reserve(mult);
82
83 G4int channel = this->findFinalStateIndex(mult, ke, DATA::data.index,
84 DATA::data.crossSections);
85#ifdef G4CASCADE_DEBUG_SAMPLER
86 G4cout << " getOutgoingParticleTypes: mult=" << mult << " KE=" << ke
87 << ": channel=" << channel << G4endl;
88#endif
89
90 // Identify final-state array to be copied
91 const G4int* chan = 0;
92 if (mult == 2) chan = DATA::data.x2bfs[channel];
93 if (mult == 3) chan = DATA::data.x3bfs[channel];
94 if (mult == 4) chan = DATA::data.x4bfs[channel];
95 if (mult == 5) chan = DATA::data.x5bfs[channel];
96 if (mult == 6) chan = DATA::data.x6bfs[channel];
97 if (mult == 7) chan = DATA::data.x7bfs[channel];
98 if (mult == 8) chan = DATA::data.x8bfs[channel];
99 if (mult == 9) chan = DATA::data.x9bfs[channel];
100
101 if (!chan) {
102 G4cerr << " getOutgoingParticleTypes: invalid multiplicity " << mult
103 << G4endl;
104 return;
105 }
106
107 kinds.insert(kinds.begin(), chan, chan+mult); // Transfer data into vector
108 return;
109}
110
111
112// Dump lookup tables, including interpolation bins, to log file
113
114template <class DATA, class SAMP>
115void G4CascadeFunctions<DATA,SAMP>::printTable(std::ostream& os) const {
116 os << " ---------- " << DATA::data.name << " ----------" << G4endl;
117 SAMP::print(os);
118 DATA::data.print(os);
119 os << " ------------------------------" << G4endl;
120}
121
122#endif /* G4_CASCADE_FUNCTIONS_ICC */