Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ProductionCutsTable.hh
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// G4ProductionCutsTable
27//
28// Class description:
29//
30// G4ProductionCutsTable is a singleton class for a table of
31// G4ProductionCuts objects. This class manages tables of production
32// cuts and energy cuts for each particle type.
33
34// Author: M.Asai, 5 October 2002 - First implementation
35// Modifications: H.Kurashige, 2004-2008
36// --------------------------------------------------------------------
37#ifndef G4ProductionCutsTable_hh
38#define G4ProductionCutsTable_hh 1
39
40#include <cmath>
41#include <vector>
42
43#include "globals.hh"
44#include "G4ios.hh"
47#include "G4Region.hh"
48
49class G4RegionStore;
51class G4LogicalVolume;
55
57{
58 public:
59
61 // This static method returns the singleton pointer of this class object.
62 // At first invocation, the singleton object is instantiated
63
66
67 virtual ~G4ProductionCutsTable();
68
69 void CreateCoupleTables();
70 // Creates material cuts couples table and allocate the other tables
71
72 void UpdateCoupleTable(G4VPhysicalVolume* currentWorld);
73 // Triggers an update of the table of G4ProductionCuts objects
74
75 void SetEnergyRange(G4double lowedge, G4double highedge);
76 // Sets the limits of energy cuts for all particles
77
80 // Get the limits of energy cuts for all particles
81
83 void SetMaxEnergyCut(G4double value);
84 // Get/set max cut energy of RangeToEnergy converter
85 // for all particle types
86
87 void DumpCouples() const;
88 // Displays a list of registered couples
89
91 // Gives the pointer to the MCCIndexConversionTable
92
93 const std::vector<G4double>* GetRangeCutsVector(std::size_t pcIdx) const;
94 const std::vector<G4double>* GetEnergyCutsVector(std::size_t pcIdx) const;
95
96 std::size_t GetTableSize() const;
97 // Returns the size of the couple table
98
100 // Returns the pointer to the couple
101
103 const G4ProductionCuts* aCut) const;
104 // Returns the pointer to the couple
105
106 G4int GetCoupleIndex(const G4MaterialCutsCouple* aCouple) const;
107 G4int GetCoupleIndex(const G4Material* aMat,
108 const G4ProductionCuts* aCut) const;
109 // Return the index of the couple.
110 // -1 is returned if index is not found
111
112 G4bool IsModified() const;
113 // Returns TRUE if at least one production cut value is modified
114
115 void PhysicsTableUpdated();
116 // Resets the status of IsModified(). This method must be exclusively
117 // used by the RunManager when physics tables are built
118
120 // Returns the default production cuts
121
123 const G4Material* material,
124 G4double range);
125 // Gives energy corresponding to range value.
126 // -1 is returned if particle or material is not found
127
128 void ResetConverters();
129 // Resets all range to energy converters
130
131 G4bool StoreCutsTable(const G4String& directory,
132 G4bool ascii = false);
133 // Stores cuts and material information in files under the
134 // the specified directory
135
136 G4bool RetrieveCutsTable(const G4String& directory,
137 G4bool ascii = false);
138 // Retrieve material cut couple information
139 // in files under the specified directory
140
141 G4bool CheckForRetrieveCutsTable(const G4String& directory,
142 G4bool ascii = false);
143 // Checks stored material and cut values are consistent
144 // with the current detector setup
145
146 G4double* GetRangeCutsDoubleVector(std::size_t pcIdx) const;
147 G4double* GetEnergyCutsDoubleVector(std::size_t pcIdx) const;
148 // Methods for backward compatibility
149
150 void SetEnergyCutVector(const std::vector<G4double>& cutE, std::size_t idx);
151 // User defined cut vectors (idx < 4) range cut should be defined
152 // to avoid inconsistency in physics
153
154 void SetVerboseLevel(G4int value);
155 G4int GetVerboseLevel() const;
156 // Control flag for output message
157 // 0: Silent
158 // 1: Warning message
159 // 2: More
160
161 protected:
162
164
165 virtual G4bool StoreMaterialInfo(const G4String& directory,
166 G4bool ascii = false);
167 // Stores material information in files under the specified directory
168
169 virtual G4bool CheckMaterialInfo(const G4String& directory,
170 G4bool ascii = false);
171 // Checks stored material is consistent with the current detector setup
172
173 virtual G4bool StoreMaterialCutsCoupleInfo(const G4String& directory,
174 G4bool ascii = false);
175 // Stores materialCutsCouple information in files under the
176 // specified directory
177
178 virtual G4bool CheckMaterialCutsCoupleInfo(const G4String& directory,
179 G4bool ascii = false);
180 // Checks stored materialCutsCouple is consistent with
181 // the current detector setup
182
183 virtual G4bool StoreCutsInfo(const G4String& directory,
184 G4bool ascii = false);
185 // Stores cut values information in files under the specified directory
186
187 virtual G4bool RetrieveCutsInfo(const G4String& directory,
188 G4bool ascii = false);
189 // Retrieves cut values information in files under the
190 // specified directory
191
192 private:
193
194 void ScanAndSetCouple(G4LogicalVolume* aLV,
195 G4MaterialCutsCouple* aCouple,
196 G4Region* aRegion);
197
198 G4bool IsCoupleUsedInTheRegion(const G4MaterialCutsCouple* aCouple,
199 const G4Region* aRegion) const;
200
201
202 private:
203
204 static G4ProductionCutsTable* fProductionCutsTable;
205
206 std::vector<G4MaterialCutsCouple*> coupleTable;
207 std::vector<std::vector<G4double>*> rangeCutTable;
208 std::vector<std::vector<G4double>*> energyCutTable;
209
210 std::vector<G4double>* userEnergyCuts[4] = {nullptr, nullptr, nullptr, nullptr};
211
212 G4RegionStore* fG4RegionStore = nullptr;
214
215 G4ProductionCuts* defaultProductionCuts = nullptr;
216
217 G4MCCIndexConversionTable mccConversionTable;
218
219 // These two vectors are for backward compatibility
220 G4double* rangeDoubleVector[NumberOfG4CutIndex];
221 G4double* energyDoubleVector[NumberOfG4CutIndex];
222
223 enum { FixedStringLengthForStore = 32 };
224
225 G4ProductionCutsTableMessenger* fMessenger = nullptr;
226 G4int verboseLevel = 1;
227 G4bool firstUse = true;
228};
229
230// ------------------
231// Inline methods
232// ------------------
233
234inline
235const std::vector<G4double>*
237{
238 return rangeCutTable[pcIdx];
239}
240
241inline
242const std::vector<G4double>*
244{
245 return energyCutTable[pcIdx];
246}
247
248inline
250{
251 return coupleTable.size();
252}
253
254inline
257{
258 return coupleTable[std::size_t(i)];
259}
260
261inline
263{
264 if(firstUse) return true;
265 for(auto itr=coupleTable.cbegin(); itr!=coupleTable.cend(); ++itr)
266 {
267 if((*itr)->IsRecalcNeeded())
268 {
269 return true;
270 }
271 }
272 return false;
273}
274
275inline
277{
278 for(auto itr=coupleTable.cbegin(); itr!=coupleTable.cend(); ++itr)
279 {
280 (*itr)->PhysicsTableUpdated();
281 }
282}
283
284inline
287{
288 return rangeDoubleVector[pcIdx];
289}
290
291inline
294{
295 return energyDoubleVector[pcIdx];
296}
297
298inline
300{
301 return defaultProductionCuts;
302}
303
304inline
305G4bool G4ProductionCutsTable::IsCoupleUsedInTheRegion(
306 const G4MaterialCutsCouple* aCouple,
307 const G4Region* aRegion) const
308{
309 G4ProductionCuts* fProductionCut = aRegion->GetProductionCuts();
310 auto mItr = aRegion->GetMaterialIterator();
311 std::size_t nMaterial = aRegion->GetNumberOfMaterials();
312 for(std::size_t iMate=0;iMate<nMaterial; ++iMate, ++mItr)
313 {
314 if(aCouple->GetMaterial()==(*mItr) &&
315 aCouple->GetProductionCuts()==fProductionCut)
316 {
317 return true;
318 }
319 }
320 return false;
321}
322
323inline
326 const G4ProductionCuts* aCut) const
327{
328 for(auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr)
329 {
330 if((*cItr)->GetMaterial()!=aMat) continue;
331 if((*cItr)->GetProductionCuts()==aCut) return (*cItr);
332 }
333 return nullptr;
334}
335
336inline
337G4int
339{
340 G4int idx = 0;
341 for(auto cItr=coupleTable.cbegin(); cItr!=coupleTable.cend(); ++cItr)
342 {
343 if((*cItr)==aCouple) return idx;
344 ++idx;
345 }
346 return -1;
347}
348
349inline
351 const G4ProductionCuts* aCut) const
352{
353 const G4MaterialCutsCouple* aCouple = GetMaterialCutsCouple(aMat,aCut);
354 return GetCoupleIndex(aCouple);
355}
356
357inline
359{
360 return verboseLevel;
361}
362
363inline
366{
367 return &mccConversionTable;
368}
369
370#endif
@ NumberOfG4CutIndex
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
const G4Material * GetMaterial() const
G4ProductionCuts * GetProductionCuts() const
const std::vector< G4double > * GetRangeCutsVector(std::size_t pcIdx) const
virtual G4bool RetrieveCutsInfo(const G4String &directory, G4bool ascii=false)
G4double * GetEnergyCutsDoubleVector(std::size_t pcIdx) const
G4bool RetrieveCutsTable(const G4String &directory, G4bool ascii=false)
virtual G4bool StoreCutsInfo(const G4String &directory, G4bool ascii=false)
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
void SetMaxEnergyCut(G4double value)
void UpdateCoupleTable(G4VPhysicalVolume *currentWorld)
std::size_t GetTableSize() const
virtual G4bool CheckMaterialInfo(const G4String &directory, G4bool ascii=false)
virtual G4bool StoreMaterialInfo(const G4String &directory, G4bool ascii=false)
G4double * GetRangeCutsDoubleVector(std::size_t pcIdx) const
const std::vector< G4double > * GetEnergyCutsVector(std::size_t pcIdx) const
G4bool StoreCutsTable(const G4String &directory, G4bool ascii=false)
G4ProductionCutsTable & operator=(const G4ProductionCutsTable &)=delete
const G4MCCIndexConversionTable * GetMCCIndexConversionTable() const
G4bool CheckForRetrieveCutsTable(const G4String &directory, G4bool ascii=false)
void SetEnergyRange(G4double lowedge, G4double highedge)
static G4ProductionCutsTable * GetProductionCutsTable()
G4int GetCoupleIndex(const G4MaterialCutsCouple *aCouple) const
virtual G4bool CheckMaterialCutsCoupleInfo(const G4String &directory, G4bool ascii=false)
void SetEnergyCutVector(const std::vector< G4double > &cutE, std::size_t idx)
G4ProductionCuts * GetDefaultProductionCuts() const
G4ProductionCutsTable(const G4ProductionCutsTable &)=delete
G4double ConvertRangeToEnergy(const G4ParticleDefinition *particle, const G4Material *material, G4double range)
virtual G4bool StoreMaterialCutsCoupleInfo(const G4String &directory, G4bool ascii=false)
std::size_t GetNumberOfMaterials() const
G4ProductionCuts * GetProductionCuts() const
std::vector< G4Material * >::const_iterator GetMaterialIterator() const