39 #include "G4Physics2DVector95.hh"
44 G4Physics2DVector95::G4Physics2DVector95()
45 :
type(T_G4PhysicsFreeVector),
46 numberOfXNodes(0), numberOfYNodes(0),
49 cache =
new G4Physics2DVectorCache95();
54 G4Physics2DVector95::G4Physics2DVector95(
size_t nx,
size_t ny)
55 :
type(T_G4PhysicsFreeVector),
56 numberOfXNodes(nx), numberOfYNodes(ny),
59 cache =
new G4Physics2DVectorCache95();
65 G4Physics2DVector95::~G4Physics2DVector95()
73 G4Physics2DVector95::G4Physics2DVector95(
const G4Physics2DVector95& right)
77 numberOfXNodes = right.numberOfXNodes;
78 numberOfYNodes = right.numberOfYNodes;
80 verboseLevel = right.verboseLevel;
82 xVector = right.xVector;
83 yVector = right.yVector;
85 cache =
new G4Physics2DVectorCache95();
94 if (&right==
this) {
return *
this; }
99 numberOfXNodes = right.numberOfXNodes;
100 numberOfYNodes = right.numberOfYNodes;
102 verboseLevel = right.verboseLevel;
113 void G4Physics2DVector95::PrepareVectors()
115 xVector.resize(numberOfXNodes,0.);
116 yVector.resize(numberOfYNodes,0.);
117 value.resize(numberOfYNodes,0);
118 for(
size_t j=0;
j<numberOfYNodes; ++
j) {
119 G4PV2DDataVector*
v =
new G4PV2DDataVector();
120 v->resize(numberOfXNodes,0.);
127 void G4Physics2DVector95::ClearVectors()
129 for(
size_t j=0;
j<numberOfYNodes; ++
j) {
136 void G4Physics2DVector95::CopyData(
const G4Physics2DVector95 &right)
138 for(
size_t i=0;
i<numberOfXNodes; ++
i) {
139 xVector[
i] = right.xVector[
i];
141 for(
size_t j=0;
j<numberOfYNodes; ++
j) {
142 yVector[
j] = right.yVector[
j];
143 G4PV2DDataVector* v0 = right.value[
j];
144 for(
size_t i=0;
i<numberOfXNodes; ++
i) {
145 PutValue(
i,
j,(*v0)[
i]);
152 void G4Physics2DVector95::ComputeValue(G4double xx, G4double yy)
154 if(xx != cache->lastBinX) {
155 if(xx <= xVector[0]) {
156 cache->lastX = xVector[0];
158 }
else if(xx >= xVector[numberOfXNodes-1]) {
159 cache->lastX = xVector[numberOfXNodes-1];
160 cache->lastBinX = numberOfXNodes-2;
163 FindBinLocationX(xx);
166 if(yy != cache->lastBinY) {
167 if(yy <= yVector[0]) {
168 cache->lastY = yVector[0];
170 }
else if(yy >= yVector[numberOfYNodes-1]) {
171 cache->lastY = yVector[numberOfYNodes-1];
172 cache->lastBinY = numberOfYNodes-2;
175 FindBinLocationY(yy);
178 size_t idx = cache->lastBinX;
179 size_t idy = cache->lastBinY;
180 G4double x1 = xVector[idx];
181 G4double x2 = xVector[idx+1];
182 G4double y1 = yVector[idy];
183 G4double y2 = yVector[idy+1];
184 G4double
x = cache->lastX;
185 G4double
y = cache->lastY;
186 G4double v11= GetValue(idx, idy);
187 G4double v12= GetValue(idx+1, idy);
188 G4double v21= GetValue(idx, idy+1);
189 G4double v22= GetValue(idx+1, idy+1);
191 ((y2 -
y)*(v11*(x2 - x) + v12*(x - x1)) +
192 ((y - y1)*(v21*(x2 - x) + v22*(x - x1))))/((x2 - x1)*(y2 - y1));
198 G4Physics2DVector95::PutVectors(
const std::vector<G4double>& vecX,
199 const std::vector<G4double>& vecY)
202 numberOfXNodes = vecX.size();
203 numberOfYNodes = vecY.size();
205 if(!cache) { cache =
new G4Physics2DVectorCache95(); }
207 for(
size_t i = 0;
i<numberOfXNodes; ++
i) {
208 xVector[
i] = vecX[
i];
210 for(
size_t j = 0;
j<numberOfYNodes; ++
j) {
211 yVector[
j] = vecY[
j];
217 void G4Physics2DVector95::Store(std::ofstream&
out)
220 G4int prec = out.precision();
221 out << G4int(
type) <<
" " << numberOfXNodes <<
" " << numberOfYNodes
223 out << std::setprecision(5);
226 for(
size_t i = 0;
i<numberOfXNodes-1; ++
i) {
227 out << xVector[
i] <<
" ";
229 out << xVector[numberOfXNodes-1] << G4endl;
230 for(
size_t j = 0;
j<numberOfYNodes-1; ++
j) {
231 out << yVector[
j] <<
" ";
233 out << yVector[numberOfYNodes-1] << G4endl;
234 for(
size_t j = 0;
j<numberOfYNodes; ++
j) {
235 for(
size_t i = 0;
i<numberOfXNodes-1; ++
i) {
236 out << GetValue(
i,
j) <<
" ";
238 out << GetValue(numberOfXNodes-1,
j) << G4endl;
246 G4bool G4Physics2DVector95::Retrieve(std::ifstream&
in)
254 in >> k >> numberOfXNodes >> numberOfYNodes;
255 if (in.fail()) {
return false; }
257 type = G4PhysicsVectorType(k);
261 for(
size_t i = 0;
i<numberOfXNodes; ++
i) {
263 if (in.fail()) {
return false; }
265 for(
size_t j = 0;
j<numberOfYNodes; ++
j) {
267 if (in.fail()) {
return false; }
269 for(
size_t j = 0;
j<numberOfYNodes; ++
j) {
270 for(
size_t i = 0;
i<numberOfXNodes; ++
i) {
272 if (in.fail()) {
return false; }
283 G4Physics2DVector95::ScaleVector(G4double factor)
286 for(
size_t j = 0;
j<numberOfYNodes; ++
j) {
287 for(
size_t i = 0;
i<numberOfXNodes; ++
i) {
288 val = GetValue(
i,
j)*factor;
297 G4Physics2DVector95::FindBinLocation(G4double
z,
298 const G4PV2DDataVector&
v)
300 size_t lowerBound = 0;
301 size_t upperBound = v.size() - 2;
303 while (lowerBound <= upperBound)
305 size_t midBin = (lowerBound + upperBound)/2;
306 if( z < v[midBin] ) { upperBound = midBin-1; }
307 else { lowerBound = midBin+1; }
nocap nocap const skelname & operator=(const skelname &)