Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4CascadeChannelTables.cc
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 // Factory to return pointer to Bertini cross-section table based on
27 // collision initial state (hadron type codes).
28 //
29 // Author: Michael Kelsey (SLAC)
30 //
31 // 20110729 M. Kelsey -- Use static instance() function to work around
32 // "disappearance" bug on Linux (GCC 4.1.2). Add diagnostics.
33 // 20110916 M. Kelsey -- Add "load on demand" to GetTable(), with full set
34 // of channel .hh files for use with LoadTable().
35 // 20110923 M. Kelsey -- Add optional stream& argument to printTable(),
36 // pass through.
37 // 20111007 M. Kelsey -- Add new gamma-n and gamma-p tables.
38 
40 #include "G4CascadeChannel.hh"
41 #include <iostream>
42 #include <map>
43 
44 
45 // Singleton is created at first invocation
46 
47 G4CascadeChannelTables& G4CascadeChannelTables::instance() {
48  static G4CascadeChannelTables theInstance;
49  return theInstance;
50 }
51 
52 
53 // Argument is interaction code, product of G4InuclEP types
54 
56  const G4CascadeChannel* theTable = instance().FindTable(initialState);
57  if (!theTable) theTable = instance().LoadTable(initialState);
58  return theTable;
59 }
60 
61 // Arguments are individual G4InuclElementaryParticle types
62 
63 const G4CascadeChannel*
65  return GetTable(had1*had2);
66 }
67 
68 // Register cross-section table for later lookup
69 
70 void
72  instance().SaveTable(initialState, table);
73 }
74 
75 // Return cross-section table requested by user
76 
77 const G4CascadeChannel*
78 G4CascadeChannelTables::FindTable(G4int initialState) {
79 #ifdef G4CASCADE_DEBUG_SAMPLER
80  G4cout << "G4CascadeChannelTables::FindTable " << initialState << G4endl;
81 #endif
82  return (tables.find(initialState)!=tables.end()) ? tables[initialState] : 0;
83 }
84 
85 
86 // Register specified table in list, replacing previous version
87 
88 void
89 G4CascadeChannelTables::SaveTable(G4int initialState, G4CascadeChannel* table) {
90 #ifdef G4CASCADE_DEBUG_SAMPLER
91  G4cout << "G4CascadeChannelTables::SaveTable " << initialState << G4endl;
92 #endif
93  if (!table) return; // Avoid unnecessary work
94 
95  if (FindTable(initialState)) delete tables[initialState];
96  tables[initialState] = table;
97 }
98 
99 
100 // Convenience function for diagnostic output
101 
102 void G4CascadeChannelTables::PrintTable(G4int initialState, std::ostream& os) {
103  const G4CascadeChannel* tbl = GetTable(initialState);
104  if (tbl) tbl->printTable(os);
105 }
106 
107 
108 // Special function to create and store table for specified interaction
109 
110 #include "G4CascadeGamNChannel.hh"
111 #include "G4CascadeGamPChannel.hh"
114 #include "G4CascadeKplusNChannel.hh"
115 #include "G4CascadeKplusPChannel.hh"
118 #include "G4CascadeKzeroNChannel.hh"
119 #include "G4CascadeKzeroPChannel.hh"
122 #include "G4CascadeNNChannel.hh"
123 #include "G4CascadeNPChannel.hh"
124 #include "G4CascadePPChannel.hh"
143 #include "G4InuclParticleNames.hh"
144 using namespace G4InuclParticleNames;
145 
146 const G4CascadeChannel* G4CascadeChannelTables::LoadTable(G4int initialState) {
147 #ifdef G4CASCADE_DEBUG_SAMPLER
148  G4cout << "G4CascadeChannelTables::LoadTable " << initialState << G4endl;
149 #endif
150 
151  G4CascadeChannel* tbl = 0;
152  switch (initialState) {
153  case gam*neu: tbl = new G4CascadeGamNChannel; break;
154  case gam*pro: tbl = new G4CascadeGamPChannel; break;
155  case k0*neu: tbl = new G4CascadeKzeroNChannel; break;
156  case k0*pro: tbl = new G4CascadeKzeroPChannel; break;
157  case k0b*neu: tbl = new G4CascadeKzeroBarNChannel; break;
158  case k0b*pro: tbl = new G4CascadeKzeroBarPChannel; break;
159  case kmi*neu: tbl = new G4CascadeKminusNChannel; break;
160  case kmi*pro: tbl = new G4CascadeKminusPChannel; break;
161  case kpl*neu: tbl = new G4CascadeKplusNChannel; break;
162  case kpl*pro: tbl = new G4CascadeKplusPChannel; break;
163  case lam*neu: tbl = new G4CascadeLambdaNChannel; break;
164  case lam*pro: tbl = new G4CascadeLambdaPChannel; break;
165  case neu*neu: tbl = new G4CascadeNNChannel; break;
166  case neu*pro: tbl = new G4CascadeNPChannel; break;
167  case pi0*neu: tbl = new G4CascadePiZeroNChannel; break;
168  case pi0*pro: tbl = new G4CascadePiZeroPChannel; break;
169  case pim*neu: tbl = new G4CascadePiMinusNChannel; break;
170  case pim*pro: tbl = new G4CascadePiMinusPChannel; break;
171  case pip*neu: tbl = new G4CascadePiPlusNChannel; break;
172  case pip*pro: tbl = new G4CascadePiPlusPChannel; break;
173  case pro*pro: tbl = new G4CascadePPChannel; break;
174  case s0*neu: tbl = new G4CascadeSigmaZeroNChannel; break;
175  case s0*pro: tbl = new G4CascadeSigmaZeroPChannel; break;
176  case sm*neu: tbl = new G4CascadeSigmaMinusNChannel; break;
177  case sm*pro: tbl = new G4CascadeSigmaMinusPChannel; break;
178  case sp*neu: tbl = new G4CascadeSigmaPlusNChannel; break;
179  case sp*pro: tbl = new G4CascadeSigmaPlusPChannel; break;
180  case xi0*neu: tbl = new G4CascadeXiZeroNChannel; break;
181  case xi0*pro: tbl = new G4CascadeXiZeroPChannel; break;
182  case xim*neu: tbl = new G4CascadeXiMinusNChannel; break;
183  case xim*pro: tbl = new G4CascadeXiMinusPChannel; break;
184  case om*neu: tbl = new G4CascadeOmegaMinusNChannel; break;
185  case om*pro: tbl = new G4CascadeOmegaMinusPChannel; break;
186  default: tbl = 0;
187  }
188 
189  SaveTable(initialState, tbl);
190  return tbl;
191 }