CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
G4Physics2DVector95.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 //
27 //
28 // --------------------------------------------------------------
29 // GEANT 4 class implementation file
30 //
31 // G4Physics2DVector95.cc
32 //
33 // Author: Vladimir Ivanchenko
34 //
35 // Creation date: 25.09.2011
36 //
37 // --------------------------------------------------------------
38 
39 #include "G4Physics2DVector95.hh"
40 #include <iomanip>
41 
42 // --------------------------------------------------------------
43 
44 G4Physics2DVector95::G4Physics2DVector95()
45  : type(T_G4PhysicsFreeVector),
46  numberOfXNodes(0), numberOfYNodes(0),
47  verboseLevel(0)
48 {
49  cache = new G4Physics2DVectorCache95();
50 }
51 
52 // --------------------------------------------------------------
53 
54 G4Physics2DVector95::G4Physics2DVector95(size_t nx, size_t ny)
55  : type(T_G4PhysicsFreeVector),
56  numberOfXNodes(nx), numberOfYNodes(ny),
57  verboseLevel(0)
58 {
59  cache = new G4Physics2DVectorCache95();
60  PrepareVectors();
61 }
62 
63 // --------------------------------------------------------------
64 
65 G4Physics2DVector95::~G4Physics2DVector95()
66 {
67  delete cache;
68  ClearVectors();
69 }
70 
71 // --------------------------------------------------------------
72 
73 G4Physics2DVector95::G4Physics2DVector95(const G4Physics2DVector95& right)
74 {
75  type = right.type;
76 
77  numberOfXNodes = right.numberOfXNodes;
78  numberOfYNodes = right.numberOfYNodes;
79 
80  verboseLevel = right.verboseLevel;
81 
82  xVector = right.xVector;
83  yVector = right.yVector;
84 
85  cache = new G4Physics2DVectorCache95();
86  PrepareVectors();
87  CopyData(right);
88 }
89 
90 // --------------------------------------------------------------
91 
92 G4Physics2DVector95& G4Physics2DVector95::operator=(const G4Physics2DVector95& right)
93 {
94  if (&right==this) { return *this; }
95  ClearVectors();
96 
97  type = right.type;
98 
99  numberOfXNodes = right.numberOfXNodes;
100  numberOfYNodes = right.numberOfYNodes;
101 
102  verboseLevel = right.verboseLevel;
103 
104  cache->Clear();
105  PrepareVectors();
106  CopyData(right);
107 
108  return *this;
109 }
110 
111 // --------------------------------------------------------------
112 
113 void G4Physics2DVector95::PrepareVectors()
114 {
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.);
121  value[j] = v;
122  }
123 }
124 
125 // --------------------------------------------------------------
126 
127 void G4Physics2DVector95::ClearVectors()
128 {
129  for(size_t j=0; j<numberOfYNodes; ++j) {
130  delete value[j];
131  }
132 }
133 
134 // --------------------------------------------------------------
135 
136 void G4Physics2DVector95::CopyData(const G4Physics2DVector95 &right)
137 {
138  for(size_t i=0; i<numberOfXNodes; ++i) {
139  xVector[i] = right.xVector[i];
140  }
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]);
146  }
147  }
148 }
149 
150 // --------------------------------------------------------------
151 
152 void G4Physics2DVector95::ComputeValue(G4double xx, G4double yy)
153 {
154  if(xx != cache->lastBinX) {
155  if(xx <= xVector[0]) {
156  cache->lastX = xVector[0];
157  cache->lastBinX = 0;
158  } else if(xx >= xVector[numberOfXNodes-1]) {
159  cache->lastX = xVector[numberOfXNodes-1];
160  cache->lastBinX = numberOfXNodes-2;
161  } else {
162  cache->lastX = xx;
163  FindBinLocationX(xx);
164  }
165  }
166  if(yy != cache->lastBinY) {
167  if(yy <= yVector[0]) {
168  cache->lastY = yVector[0];
169  cache->lastBinY = 0;
170  } else if(yy >= yVector[numberOfYNodes-1]) {
171  cache->lastY = yVector[numberOfYNodes-1];
172  cache->lastBinY = numberOfYNodes-2;
173  } else {
174  cache->lastY = yy;
175  FindBinLocationY(yy);
176  }
177  }
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);
190  cache->lastValue =
191  ((y2 - y)*(v11*(x2 - x) + v12*(x - x1)) +
192  ((y - y1)*(v21*(x2 - x) + v22*(x - x1))))/((x2 - x1)*(y2 - y1));
193 }
194 
195 // --------------------------------------------------------------
196 
197 void
198 G4Physics2DVector95::PutVectors(const std::vector<G4double>& vecX,
199  const std::vector<G4double>& vecY)
200 {
201  ClearVectors();
202  numberOfXNodes = vecX.size();
203  numberOfYNodes = vecY.size();
204  PrepareVectors();
205  if(!cache) { cache = new G4Physics2DVectorCache95(); }
206  cache->Clear();
207  for(size_t i = 0; i<numberOfXNodes; ++i) {
208  xVector[i] = vecX[i];
209  }
210  for(size_t j = 0; j<numberOfYNodes; ++j) {
211  yVector[j] = vecY[j];
212  }
213 }
214 
215 // --------------------------------------------------------------
216 
217 void G4Physics2DVector95::Store(std::ofstream& out)
218 {
219  // binning
220  G4int prec = out.precision();
221  out << G4int(type) << " " << numberOfXNodes << " " << numberOfYNodes
222  << G4endl;
223  out << std::setprecision(5);
224 
225  // contents
226  for(size_t i = 0; i<numberOfXNodes-1; ++i) {
227  out << xVector[i] << " ";
228  }
229  out << xVector[numberOfXNodes-1] << G4endl;
230  for(size_t j = 0; j<numberOfYNodes-1; ++j) {
231  out << yVector[j] << " ";
232  }
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) << " ";
237  }
238  out << GetValue(numberOfXNodes-1,j) << G4endl;
239  }
240  out.precision(prec);
241  out.close();
242 }
243 
244 // --------------------------------------------------------------
245 
246 G4bool G4Physics2DVector95::Retrieve(std::ifstream& in)
247 {
248  // initialisation
249  cache->Clear();
250  ClearVectors();
251 
252  // binning
253  G4int k;
254  in >> k >> numberOfXNodes >> numberOfYNodes;
255  if (in.fail()) { return false; }
256  PrepareVectors();
257  type = G4PhysicsVectorType(k);
258 
259  // contents
260  G4double val;
261  for(size_t i = 0; i<numberOfXNodes; ++i) {
262  in >> xVector[i];
263  if (in.fail()) { return false; }
264  }
265  for(size_t j = 0; j<numberOfYNodes; ++j) {
266  in >> yVector[j];
267  if (in.fail()) { return false; }
268  }
269  for(size_t j = 0; j<numberOfYNodes; ++j) {
270  for(size_t i = 0; i<numberOfXNodes; ++i) {
271  in >> val;
272  if (in.fail()) { return false; }
273  PutValue(i, j, val);
274  }
275  }
276  in.close();
277  return true;
278 }
279 
280 // --------------------------------------------------------------
281 
282 void
283 G4Physics2DVector95::ScaleVector(G4double factor)
284 {
285  G4double val;
286  for(size_t j = 0; j<numberOfYNodes; ++j) {
287  for(size_t i = 0; i<numberOfXNodes; ++i) {
288  val = GetValue(i, j)*factor;
289  PutValue(i, j, val);
290  }
291  }
292 }
293 
294 // --------------------------------------------------------------
295 
296 size_t
297 G4Physics2DVector95::FindBinLocation(G4double z,
298  const G4PV2DDataVector& v)
299 {
300  size_t lowerBound = 0;
301  size_t upperBound = v.size() - 2;
302 
303  while (lowerBound <= upperBound)
304  {
305  size_t midBin = (lowerBound + upperBound)/2;
306  if( z < v[midBin] ) { upperBound = midBin-1; }
307  else { lowerBound = midBin+1; }
308  }
309 
310  return upperBound;
311 }
312 
313 // --------------------------------------------------------------
nocap nocap const skelname & operator=(const skelname &)
type
Definition: HCALResponse.h:22
int i
Definition: DBlmapReader.cc:9
double double double z
int j
Definition: DBlmapReader.cc:9
int k[5][pyjets_maxn]
tuple out
Definition: dbtoconf.py:99
Definition: DDAxes.h:10
mathSSE::Vec4< T > v