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