Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PhysicsTableHelper.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// G4PhysicsTableHelper class implementation
27//
28// Author: H.Kurashige, 20 August 2004 - First implementation
29// --------------------------------------------------------------------
30
33
35
36// --------------------------------------------------------------------
38{
39}
40
41// --------------------------------------------------------------------
43{
44}
45
46// --------------------------------------------------------------------
49{
50 G4ProductionCutsTable* cutTable
52 std::size_t numberOfMCC = cutTable->GetTableSize();
53
54 if ( physTable != nullptr)
55 {
56 // compare size of physics table and number of material-cuts-couple
57 if ( physTable->size() < numberOfMCC)
58 {
59 // enlarge physics table
60 physTable->resize(numberOfMCC, nullptr);
61#ifdef G4VERBOSE
62 if (verboseLevel>2)
63 {
64 G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable ";
65 G4cerr << "Physics Table "<< physTable ;
66 G4cerr << " is resized to " << numberOfMCC << G4endl;
67 }
68#endif
69 }
70 else if ( physTable->size() > numberOfMCC)
71 {
72 // ERROR: this situation should not occur
73 // size of physics table is shorter than number of material-cuts-couple
74 physTable->resize(numberOfMCC);
75#ifdef G4VERBOSE
76 if (verboseLevel>0)
77 {
78 G4cerr << "G4PhysicsTableHelper::PreparePhysicsTable ";
79 G4cerr << "Physics Table "<< physTable ;
80 G4cerr << " is longer than number of material-cuts-couple " << G4endl;
81 }
82#endif
83 G4Exception( "G4PhysicsTableHelper::PreparePhysicsTable()",
84 "ProcCuts001", FatalException,
85 "Physics Table is inconsistent with material-cuts-couple");
86 }
87 }
88 else
89 {
90 // create PhysicsTable is given poitner is null
91 physTable = new G4PhysicsTable(numberOfMCC);
92 if (physTable != nullptr)
93 {
94 physTable->resize(numberOfMCC, nullptr);
95 }
96 else
97 {
98 G4Exception( "G4PhysicsTableHelper::PreparePhysicsTable()",
99 "ProcCuts002", FatalException,
100 "Can't create Physics Table");
101 }
102 }
103
104#ifdef G4VERBOSE
105 if (verboseLevel>2)
106 {
107 if ( physTable != nullptr)
108 {
109 G4cerr << "Physics Table size "<< physTable->size();
110 }
111 else
112 {
113 G4cerr << "Physics Table does not exist ";
114 }
115 G4cerr << ": number of material-cuts-couple " << numberOfMCC << G4endl;
116 }
117#endif
118
119 // Reset recal-needed flag for all physics vectors
120 physTable->ResetFlagArray();
121
122 for (std::size_t idx = 0; idx <numberOfMCC; ++idx)
123 {
124 const G4MaterialCutsCouple* mcc = cutTable->GetMaterialCutsCouple(idx);
125
126 // check if re-calculation of the physics vector is needed
127 // MCC is not used
128 if ( !mcc->IsUsed() ) physTable->ClearFlag(idx);
129
130 // RecalcNeeded flag of MCC is not asserted
131 if ( !mcc->IsRecalcNeeded() ) physTable->ClearFlag(idx);
132 }
133
134 return physTable;
135}
136
137// --------------------------------------------------------------------
139 const G4String& fileName,
140 G4bool ascii )
141{
142 if (physTable == nullptr ) return false;
143
144 // retrieve physics table from the given file
145 G4PhysicsTable* tempTable = new G4PhysicsTable();
146 if (! tempTable->RetrievePhysicsTable(fileName,ascii) )
147 {
148#ifdef G4VERBOSE
149 if (verboseLevel>1)
150 {
151 G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable ";
152 G4cerr << "Fail to retrieve from "<< fileName << G4endl;
153 }
154#endif
155 G4Exception( "G4ProductionCutsTable::RetrievePhysicsTable()",
156 "ProcCuts105",
157 JustWarning, "Can not retrieve physics tables from file");
158 delete tempTable;
159 return false;
160 }
161
162 G4ProductionCutsTable* cutTable
164 const G4MCCIndexConversionTable* converter
165 = cutTable->GetMCCIndexConversionTable();
166
167 // check physics table size
168 if ( tempTable->size() != converter->size())
169 {
170#ifdef G4VERBOSE
171 if (verboseLevel>0)
172 {
173 G4cerr << "G4PhysicsTableHelper::RetrievePhysicsTable ";
174 G4cerr << "Size of the physics table in "<< fileName;
175 G4cerr << "( size =" << tempTable->size() << ")";
176 G4cerr << " is inconsistent with material-cut info";
177 G4cerr << "( size =" << converter->size() << ")";
178 G4cerr << G4endl;
179 }
180#endif
181 G4Exception("G4ProductionCutsTable::RetrievePhysicsTable()",
182 "ProcCuts106", JustWarning,
183 "Retrieved file is inconsistent with current physics tables!");
184 delete tempTable;
185 return false;
186 }
187
188 // fill the given physics table with retrieved physics vectors
189 for (std::size_t idx=0; idx<converter->size(); ++idx)
190 {
191 if (converter->IsUsed(idx))
192 {
193 if (converter->GetIndex(idx)<0) continue;
194 std::size_t i = converter->GetIndex(idx);
195 G4PhysicsVector* vec = (*physTable)[i];
196 if (vec != nullptr ) delete vec;
197 (*physTable)[i] = (*tempTable)[idx];
198 physTable->ClearFlag(i);
199 }
200 }
201 tempTable->clear();
202 delete tempTable;
203
204 return true;
205}
206
207// --------------------------------------------------------------------
209 std::size_t idx,
210 G4PhysicsVector* vec)
211{
212 if ( physTable == nullptr) { return; }
213
214 if ( physTable->size() <= idx)
215 {
216#ifdef G4VERBOSE
217 if (verboseLevel>0)
218 {
219 G4cerr << "G4PhysicsTableHelper::SetPhysicsVector ";
220 G4cerr << "Given index (" << idx << ") exceeds ";
221 G4cerr << "size of the physics table ";
222 G4cerr << "( size =" << physTable->size()<< ")";
223 G4cerr << G4endl;
224 }
225#endif
226 G4Exception("G4ProductionCutsTable::SetPhysicsVector()",
227 "ProcCuts107",
228 JustWarning, "Illegal index!");
229 return;
230 }
231
232 // set physics vector
233 (*physTable)[idx] = vec;
234 // clear flag
235 physTable->ClearFlag(idx);
236}
237
238// --------------------------------------------------------------------
240{
241 verboseLevel = value;
242}
243
244// --------------------------------------------------------------------
246{
247 return verboseLevel;
248}
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4bool IsUsed(std::size_t index) const
G4int GetIndex(std::size_t index) const
static G4ThreadLocal G4int verboseLevel
static G4PhysicsTable * PreparePhysicsTable(G4PhysicsTable *physTable)
static void SetVerboseLevel(G4int value)
static void SetPhysicsVector(G4PhysicsTable *physTable, std::size_t idx, G4PhysicsVector *vec)
static G4bool RetrievePhysicsTable(G4PhysicsTable *physTable, const G4String &fileName, G4bool ascii)
G4bool RetrievePhysicsTable(const G4String &filename, G4bool ascii=false)
void resize(std::size_t, G4PhysicsVector *vec=(G4PhysicsVector *)(0))
void ClearFlag(std::size_t i)
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
std::size_t GetTableSize() const
const G4MCCIndexConversionTable * GetMCCIndexConversionTable() const
static G4ProductionCutsTable * GetProductionCutsTable()
#define G4ThreadLocal
Definition: tls.hh:77