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 | // |
---|
27 | // |
---|
28 | // =========================================================================== |
---|
29 | // GEANT4 class header file |
---|
30 | // |
---|
31 | // Class: G4IonParametrisedLossTable |
---|
32 | // Helper classes: G4IonLossTableHandle |
---|
33 | // G4DummyScalingAlgorithm |
---|
34 | // |
---|
35 | // Author: Anton Lechner (Anton.Lechner@cern.ch) |
---|
36 | // |
---|
37 | // First implementation: 10. 11. 2008 |
---|
38 | // |
---|
39 | // Modifications: |
---|
40 | // |
---|
41 | // |
---|
42 | // Class descriptions: |
---|
43 | // G4IonParametrisedLossTable: Wrapper class for classes of the material |
---|
44 | // category, which maintain stopping power vectors for ions. This wrapper |
---|
45 | // class includes a cache for faster access of stopping powers and builds |
---|
46 | // stopping power vectors for compounds using Bragg's additivity rule. |
---|
47 | // G4IonLossTableHandle: A handle class for G4IonParametrisedLossTable |
---|
48 | // G4DummyScalingAlgorithm: A dummy algorithm to scale energies and |
---|
49 | // stopping powers (may be replaced with an algorithm, which relies on |
---|
50 | // dynamic information of the particle: This may be required if stopping |
---|
51 | // power data is scaled using an effective charge approximation). |
---|
52 | // |
---|
53 | // Comments: |
---|
54 | // |
---|
55 | // =========================================================================== |
---|
56 | |
---|
57 | |
---|
58 | #ifndef G4IONPARAMETRISEDLOSSTABLE_HH |
---|
59 | #define G4IONPARAMETRISEDLOSSTABLE_HH |
---|
60 | |
---|
61 | #include "globals.hh" |
---|
62 | #include "G4hIonEffChargeSquare.hh" |
---|
63 | #include "G4ParticleDefinition.hh" |
---|
64 | #include "G4Material.hh" |
---|
65 | #include "G4LPhysicsFreeVector.hh" |
---|
66 | #include <vector> |
---|
67 | #include <iomanip> |
---|
68 | #include <map> |
---|
69 | #include <list> |
---|
70 | #include <utility> |
---|
71 | |
---|
72 | |
---|
73 | // ######################################################################### |
---|
74 | // # Type definitions for a local cache |
---|
75 | // # |
---|
76 | // ######################################################################### |
---|
77 | |
---|
78 | typedef std::pair<const G4ParticleDefinition*, const G4Material*> G4CacheKey; |
---|
79 | |
---|
80 | typedef struct CacheValue{ |
---|
81 | G4double energyScaling; // Scaling factor for kinetic energy |
---|
82 | G4PhysicsVector* dedx; // dEdx vector for current projectile- |
---|
83 | // material combination |
---|
84 | G4int dEdxIndex; // dE/dx vector index |
---|
85 | } G4CacheValue; |
---|
86 | |
---|
87 | |
---|
88 | // ######################################################################### |
---|
89 | // # Class G4IonLossTableHandle: Handle for table wrappers (to enable |
---|
90 | // # vectors of table wrappers) |
---|
91 | // ######################################################################### |
---|
92 | |
---|
93 | class G4IonLossTableHandle { |
---|
94 | |
---|
95 | public: |
---|
96 | G4IonLossTableHandle() { } |
---|
97 | virtual ~G4IonLossTableHandle() { } |
---|
98 | |
---|
99 | virtual G4double GetLowerEnergyEdge( |
---|
100 | const G4ParticleDefinition*, // Projectile (ion) |
---|
101 | const G4Material* // Target material |
---|
102 | ) = 0; |
---|
103 | virtual G4double GetUpperEnergyEdge( |
---|
104 | const G4ParticleDefinition*, // Projectile (ion) |
---|
105 | const G4Material* // Target material |
---|
106 | ) = 0; |
---|
107 | virtual G4bool IsApplicable( |
---|
108 | const G4ParticleDefinition*, // Projectile (ion) |
---|
109 | const G4Material* // Target material |
---|
110 | ) = 0; |
---|
111 | virtual G4bool IsApplicable( |
---|
112 | const G4ParticleDefinition*, // Projectile (ion) |
---|
113 | const G4Material*, // Target material |
---|
114 | G4double // Kinetic energy of projectile |
---|
115 | ) = 0; |
---|
116 | virtual G4double GetDEDX( |
---|
117 | const G4ParticleDefinition*, // Projectile (ion) |
---|
118 | const G4Material*, // Target material |
---|
119 | G4double // Kinetic energy of projectile |
---|
120 | ) = 0; |
---|
121 | virtual void ClearCache() { } |
---|
122 | }; |
---|
123 | |
---|
124 | |
---|
125 | // ######################################################################### |
---|
126 | // # Class G4DummyScalingAlgorithm: |
---|
127 | // ######################################################################### |
---|
128 | |
---|
129 | class G4DummyScalingAlgorithm { |
---|
130 | |
---|
131 | public: |
---|
132 | // No scaling for kinetic energy |
---|
133 | inline G4double ScalingFactorEnergy( |
---|
134 | const G4ParticleDefinition*) // Projectile (ion) |
---|
135 | { return 1.0; } |
---|
136 | |
---|
137 | // No scaling for dE/dx |
---|
138 | inline G4double ScalingFactorDEDX( |
---|
139 | const G4ParticleDefinition*, // Projectile (ion) |
---|
140 | const G4Material*, // Target material |
---|
141 | G4double) // Kinetic energy of projectile |
---|
142 | { return 1.0; } |
---|
143 | }; |
---|
144 | |
---|
145 | |
---|
146 | // ######################################################################### |
---|
147 | // # Class G4IonParametrisedLossTable: Wrapper for classes of the material |
---|
148 | // # category, which maintain ion stopping power vectors |
---|
149 | // ######################################################################### |
---|
150 | |
---|
151 | template < |
---|
152 | class LossTabulation, |
---|
153 | class ScalingAlgorithm = G4DummyScalingAlgorithm |
---|
154 | > |
---|
155 | class G4IonParametrisedLossTable : public G4IonLossTableHandle, |
---|
156 | public LossTabulation, |
---|
157 | public ScalingAlgorithm { |
---|
158 | |
---|
159 | public: |
---|
160 | G4IonParametrisedLossTable(G4int maxSizeCache = 5, |
---|
161 | G4bool splines = true); |
---|
162 | ~G4IonParametrisedLossTable(); |
---|
163 | |
---|
164 | // Function checking the availability of stopping power values for a |
---|
165 | // given ion-target combination and a given kinetic energy |
---|
166 | G4bool IsApplicable( |
---|
167 | const G4ParticleDefinition*, // Projectile (ion) |
---|
168 | const G4Material*, // Target material |
---|
169 | G4double); // Kinetic energy of projectile |
---|
170 | |
---|
171 | // Function checking the availability of stopping power values for a |
---|
172 | // given ion-target combination (kinetic energy not considered) |
---|
173 | G4bool IsApplicable( |
---|
174 | const G4ParticleDefinition*, // Projectile (ion) |
---|
175 | const G4Material*); // Target material |
---|
176 | |
---|
177 | // Function returning the stopping power of a given material for a |
---|
178 | // projectile of specified energy |
---|
179 | G4double GetDEDX( |
---|
180 | const G4ParticleDefinition*, // Projectile (ion) |
---|
181 | const G4Material*, // Target material |
---|
182 | G4double); // Kinetic energy of projectile |
---|
183 | |
---|
184 | // Function printing stopping powers for a given ion-material combination |
---|
185 | // within a specified energy range |
---|
186 | void PrintDEDXTable( |
---|
187 | const G4ParticleDefinition*, // Projectile (ion) |
---|
188 | const G4Material* , // Target material |
---|
189 | G4double, // Minimum energy per nucleon |
---|
190 | G4double, // Maximum energy per nucleon |
---|
191 | G4int, // Number of bins |
---|
192 | G4bool logScaleEnergy = true);// Logarithmic scaling of energy |
---|
193 | |
---|
194 | // Function returning the lower energy edge of stopping power tables |
---|
195 | G4double GetLowerEnergyEdge( |
---|
196 | const G4ParticleDefinition*, // Projectile (ion) |
---|
197 | const G4Material*); // Target material |
---|
198 | |
---|
199 | // Function returning the upper energy edge of stopping power tables |
---|
200 | G4double GetUpperEnergyEdge( |
---|
201 | const G4ParticleDefinition*, // Projectile (ion) |
---|
202 | const G4Material*); // Target material |
---|
203 | |
---|
204 | private: |
---|
205 | |
---|
206 | // Function for building stopping power vectors according to Bragg's |
---|
207 | // additivity rule |
---|
208 | G4PhysicsVector* BuildStoppingPowerVector( |
---|
209 | const G4ParticleDefinition*, // Projectile (ion) |
---|
210 | const G4Material*); // Target material |
---|
211 | |
---|
212 | // The assignment operator and the copy constructor are hidden |
---|
213 | G4IonParametrisedLossTable& operator=(const |
---|
214 | G4IonParametrisedLossTable &right); |
---|
215 | G4IonParametrisedLossTable(const G4IonParametrisedLossTable&); |
---|
216 | |
---|
217 | // ###################################################################### |
---|
218 | // # "Most-recently-used" cache, to provide a faster access to physics |
---|
219 | // # vectors |
---|
220 | // ###################################################################### |
---|
221 | |
---|
222 | // A type definition of cache entry containing a key-value pair |
---|
223 | typedef struct CacheEntry { |
---|
224 | G4CacheKey key; |
---|
225 | G4CacheValue value; |
---|
226 | } G4CacheEntry; |
---|
227 | |
---|
228 | // A cache entry list, and a map of pointers to list iterators (for faster |
---|
229 | // searching) |
---|
230 | typedef std::list<G4CacheEntry> CacheEntryList; |
---|
231 | CacheEntryList cacheEntries; |
---|
232 | |
---|
233 | typedef std::map<G4CacheKey, void*> CacheIterPointerMap; |
---|
234 | CacheIterPointerMap cacheKeyPointers; |
---|
235 | |
---|
236 | // Maximum number of cache entries |
---|
237 | G4int maxCacheEntries; |
---|
238 | |
---|
239 | // Function for updating the cache |
---|
240 | G4CacheValue UpdateCacheValue( |
---|
241 | const G4ParticleDefinition*, // Projectile (ion) |
---|
242 | const G4Material*); // Target material |
---|
243 | |
---|
244 | // Function for retrieving cache values |
---|
245 | G4CacheValue GetCacheValue( |
---|
246 | const G4ParticleDefinition*, // Projectile (ion) |
---|
247 | const G4Material*); // Target material |
---|
248 | |
---|
249 | // Function for clearing the cache |
---|
250 | void ClearCache(); |
---|
251 | |
---|
252 | // ###################################################################### |
---|
253 | // # Map of stopping power vectors computed according Bragg rule |
---|
254 | // # |
---|
255 | // ###################################################################### |
---|
256 | |
---|
257 | typedef std::map<G4CacheKey, G4LPhysicsFreeVector*> StoppingPowerTable; |
---|
258 | StoppingPowerTable s; |
---|
259 | |
---|
260 | // Flag indicating the usage of splines |
---|
261 | G4bool useSplines; |
---|
262 | |
---|
263 | // ###################################################################### |
---|
264 | // # Energy boundaries of physics tables |
---|
265 | // ###################################################################### |
---|
266 | |
---|
267 | G4double lowerEnergyEdge; |
---|
268 | G4double upperEnergyEdge; |
---|
269 | }; |
---|
270 | |
---|
271 | #include "G4IonParametrisedLossTable.icc" |
---|
272 | |
---|
273 | #endif // G4IONPARAMETRISEDLOSSTABLE_HH |
---|