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 | // $Id: G4InterpolationManager.hh,v 1.13 2007/06/06 12:45:13 ahoward Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-03 $ |
---|
29 | // |
---|
30 | #ifndef G4InterpolationManager_h |
---|
31 | #define G4InterpolationManager_h 1 |
---|
32 | |
---|
33 | #include "globals.hh" |
---|
34 | #include "G4InterpolationScheme.hh" |
---|
35 | #include "G4ios.hh" |
---|
36 | #include <fstream> |
---|
37 | #include "G4HadronicException.hh" |
---|
38 | |
---|
39 | class G4InterpolationManager |
---|
40 | { |
---|
41 | public: |
---|
42 | |
---|
43 | friend class G4InterpolationIterator; |
---|
44 | |
---|
45 | G4InterpolationManager() |
---|
46 | { |
---|
47 | nRanges = 1; |
---|
48 | start = new G4int[1]; |
---|
49 | start[0] = 0; |
---|
50 | range = new G4int[1]; |
---|
51 | range [0] = 100000; |
---|
52 | scheme = new G4InterpolationScheme[1]; |
---|
53 | scheme[0] = LINLIN; |
---|
54 | nEntries = 0; |
---|
55 | } |
---|
56 | |
---|
57 | ~G4InterpolationManager() |
---|
58 | { |
---|
59 | if(start!=0) delete [] start; |
---|
60 | if(range!=0) delete [] range; |
---|
61 | if(scheme!=0) delete [] scheme; |
---|
62 | } |
---|
63 | |
---|
64 | G4InterpolationManager & operator= (const G4InterpolationManager & aManager) |
---|
65 | { |
---|
66 | if(this != &aManager) |
---|
67 | { |
---|
68 | nRanges = aManager.nRanges; |
---|
69 | nEntries = aManager.nEntries; |
---|
70 | if(scheme!=0) delete [] scheme; |
---|
71 | if(start!=0) delete [] start; |
---|
72 | if(range!=0) delete [] range; |
---|
73 | scheme = new G4InterpolationScheme[nRanges]; |
---|
74 | start = new G4int[nRanges]; |
---|
75 | range = new G4int[nRanges]; |
---|
76 | for(G4int i=0; i<nRanges; i++) |
---|
77 | { |
---|
78 | scheme[i]=aManager.scheme[i]; |
---|
79 | start[i]=aManager.start[i]; |
---|
80 | range[i]=aManager.range[i]; |
---|
81 | } |
---|
82 | } |
---|
83 | return *this; |
---|
84 | } |
---|
85 | |
---|
86 | inline void Init(G4int aScheme, G4int aRange) |
---|
87 | { |
---|
88 | nRanges = 1; |
---|
89 | start[0] = 0; |
---|
90 | range [0] = aRange; |
---|
91 | scheme[0] = MakeScheme(aScheme); |
---|
92 | nEntries = aRange; |
---|
93 | } |
---|
94 | inline void Init(G4InterpolationScheme aScheme, G4int aRange) |
---|
95 | { |
---|
96 | nRanges = 1; |
---|
97 | start[0] = 0; |
---|
98 | range [0] = aRange; |
---|
99 | scheme[0] = aScheme; |
---|
100 | nEntries = aRange; |
---|
101 | } |
---|
102 | |
---|
103 | inline void Init(std::ifstream & aDataFile) |
---|
104 | { |
---|
105 | delete [] start; |
---|
106 | delete [] range; |
---|
107 | delete [] scheme; |
---|
108 | aDataFile >> nRanges; |
---|
109 | start = new G4int[nRanges]; |
---|
110 | range = new G4int[nRanges]; |
---|
111 | scheme = new G4InterpolationScheme[nRanges]; |
---|
112 | start[0] = 0; |
---|
113 | G4int it; |
---|
114 | for(G4int i=0; i<nRanges; i++) |
---|
115 | { |
---|
116 | aDataFile>>range[i]; |
---|
117 | if(i!=0) start[i] = start[i-1]+range[i-1]; |
---|
118 | aDataFile>>it; |
---|
119 | scheme[i] = MakeScheme(it); |
---|
120 | } |
---|
121 | nEntries = start[nRanges-1]+range[nRanges-1]; |
---|
122 | } |
---|
123 | |
---|
124 | G4InterpolationScheme MakeScheme(G4int it); |
---|
125 | |
---|
126 | inline G4InterpolationScheme GetScheme(G4int index) const |
---|
127 | { |
---|
128 | G4int it = 0; |
---|
129 | for(G4int i=1; i<nRanges; i++) |
---|
130 | { |
---|
131 | if(index<start[i]) break; |
---|
132 | it = i; |
---|
133 | } |
---|
134 | return scheme[it]; |
---|
135 | } |
---|
136 | |
---|
137 | inline void CleanUp() |
---|
138 | { |
---|
139 | nRanges = 0; |
---|
140 | nEntries = 0; |
---|
141 | } |
---|
142 | |
---|
143 | inline G4InterpolationScheme GetInverseScheme(G4int index) |
---|
144 | { |
---|
145 | G4InterpolationScheme result = GetScheme(index); |
---|
146 | if(result == HISTO) |
---|
147 | { |
---|
148 | result = RANDOM; |
---|
149 | } |
---|
150 | else if(result == LINLOG) |
---|
151 | { |
---|
152 | result = LOGLIN; |
---|
153 | } |
---|
154 | else if(result == LOGLIN) |
---|
155 | { |
---|
156 | result = LINLOG; |
---|
157 | } |
---|
158 | else if(result == CHISTO) |
---|
159 | { |
---|
160 | result = CRANDOM; |
---|
161 | } |
---|
162 | else if(result == CLINLOG) |
---|
163 | { |
---|
164 | result = CLOGLIN; |
---|
165 | } |
---|
166 | else if(result == CLOGLIN) |
---|
167 | { |
---|
168 | result = CLINLOG; |
---|
169 | } |
---|
170 | else if(result == UHISTO) |
---|
171 | { |
---|
172 | result = URANDOM; |
---|
173 | } |
---|
174 | else if(result == ULINLOG) |
---|
175 | { |
---|
176 | result = ULOGLIN; |
---|
177 | } |
---|
178 | else if(result == ULOGLIN) |
---|
179 | { |
---|
180 | result = ULINLOG; |
---|
181 | } |
---|
182 | return result; |
---|
183 | } |
---|
184 | |
---|
185 | void AppendScheme(G4int aPoint, const G4InterpolationScheme & aScheme); |
---|
186 | |
---|
187 | private: |
---|
188 | |
---|
189 | G4int nRanges; |
---|
190 | G4InterpolationScheme * scheme; |
---|
191 | G4int * start; |
---|
192 | G4int * range; |
---|
193 | G4int nEntries; |
---|
194 | |
---|
195 | }; |
---|
196 | #endif |
---|