EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4BlockCellGeom.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4BlockCellGeom.cc
1 #include "PHG4BlockCellGeom.h"
2 #include "PHG4CylinderCellDefs.h"
3 
4 #include <cmath>
5 #include <cstdlib>
6 
7 using namespace std;
8 
10  _layer(-9999),
11  _binning(0),
12  _nzbins(-1),
13  _zmin(NAN),
14  _zstep(NAN),
15  _nxbins(-1),
16  _xmin(NAN),
17  _xstep(NAN)
18 {
19  return;
20 }
21 
22 void
24 {
26  _nzbins = i;
27 }
28 
29 void
31 {
33  _zmin = z;
34 }
35 
36 int
38 {
40  return _nzbins;
41 }
42 
43 double
45 {
47  return _zmin;
48 }
49 
50 double
52 {
54  return _zstep;
55 }
56 
57 void
59 {
61  _zstep = z;
62 }
63 
64 int
66 {
67  check_binning_method_x("PHG4BlockCellGeom::get_xbins");
68  return _nxbins;
69 }
70 
71 double
73 {
74  check_binning_method_x("PHG4BlockCellGeom::get_xstep");
75  return _xstep;
76 }
77 
78 double
80 {
81  check_binning_method_x("PHG4BlockCellGeom::get_xmin");
82  return _xmin;
83 }
84 
85 void
87 {
88  check_binning_method_x("PHG4BlockCellGeom::set_xbins");
89  _nxbins = i;
90 }
91 
92 void
94 {
95  check_binning_method_x("PHG4BlockCellGeom::set_xstep");
96  _xstep = r;
97 }
98 
99 void
101 {
102  check_binning_method_x("PHG4BlockCellGeom::set_xmin");
103  _xmin = r;
104 }
105 
106 int
108 {
109  check_binning_method_eta("PHG4BlockCellGeom::get_etabins");
110  return _nzbins;
111 }
112 
113 double
115 {
116  check_binning_method_eta("PHG4BlockCellGeom::get_etastep");
117  return _zstep;
118 }
119 double
121 {
122  check_binning_method_eta("PHG4BlockCellGeom::get_etamin");
123  return _zmin;
124 }
125 
126 void
128 {
129  check_binning_method_eta("PHG4BlockCellGeom::set_etamin");
130  _zmin = z;
131 }
132 
133 void
135 {
136  check_binning_method_eta("PHG4BlockCellGeom::set_etastep");
137  _zstep = z;
138 }
139 
140 void
142 {
143  check_binning_method_eta("PHG4BlockCellGeom::set_etabins");
144  _nzbins = i;
145 }
146 
147 void
148 PHG4BlockCellGeom::identify(std::ostream& os) const
149 {
150  os << "layer: " << _layer;
151  switch (_binning)
152  {
154  os << ", zbins: " << _nzbins
155  << ", zmin: " << _zmin
156  << ", zstepsize: " << _zstep;
157  break;
158 
160  os << ", etabins: " << _nzbins
161  << ", etamin: " << _zmin
162  << ", etastepsize: " << _zstep;
163  break;
164 
166  os << ", etabins: " << _nzbins
167  << ", etamin: " << _zmin
168  << ", etastepsize: " << _zstep;
169  break;
170 
171  default:
172  os << "no valid binning method: " << _binning << endl;
173  return;
174  break;
175  }
176 
177  os << ", xmin: " << _xmin
178  << ", xbins: " << _nxbins
179  << ", xstep: " << _xstep
180  << endl;
181  return;
182 }
183 
184 pair<double, double>
185 PHG4BlockCellGeom::get_zbounds(const int ibin) const
186 {
187  if (ibin < 0 || ibin > _nzbins)
188  {
189  cout << "Asking for invalid bin in z: " << ibin << endl;
190  exit(1);
191  }
193  double zlow = _zmin + ibin * _zstep;
194  double zhigh = zlow + _zstep;
195  return make_pair(zlow, zhigh);
196 }
197 
198 pair<double, double>
199 PHG4BlockCellGeom::get_etabounds(const int ibin) const
200 {
201  if (ibin < 0 || ibin > _nzbins)
202  {
203  cout << "Asking for invalid bin in z: " << ibin << endl;
204  exit(1);
205  }
206  check_binning_method_eta("PHG4BlockCellGeom::get_etabounds");
207  // check_binning_method(PHG4CylinderCellDefs::etaphibinning);
208  double zlow = _zmin + ibin * _zstep;
209  double zhigh = zlow + _zstep;
210  return make_pair(zlow, zhigh);
211 }
212 
213 
214 pair<double, double>
215 PHG4BlockCellGeom::get_xbounds(const int ibin) const
216 {
217  if (ibin < 0 || ibin > _nxbins)
218  {
219  cout << "Asking for invalid bin in x: " << ibin << endl;
220  exit(1);
221  }
222 
223  double xlow = _xmin + ibin * _xstep;
224  double xhigh = xlow + _xstep;
225  return make_pair(xlow, xhigh);
226 }
227 
228 int
229 PHG4BlockCellGeom::get_zbin(const double z) const
230 {
231  if (z < _zmin || z > (_zmin+_nzbins*_zstep))
232  {
233  cout << "Asking for bin for z outside of z range: " << z << endl;
234  return -1;
235  }
236 
238  return floor( (z-_zmin)/_zstep );
239 }
240 
241 int
243 {
244  if (eta < _zmin || eta > (_zmin+_nzbins*_zstep))
245  {
246  cout << "Asking for bin for eta outside of eta range: " << eta << endl;
247  return -1;
248  }
250  return floor( (eta-_zmin)/_zstep );
251 }
252 
253 int
254 PHG4BlockCellGeom::get_xbin(const double x) const
255 {
256  double norm_x = x;
257  if(x < _xmin || x > (_xmin+_nxbins*_xstep))
258  {
259  cout << "Asking for bin for x outside of x range: " << x << endl;
260  return -1;
261  }
263  return floor( (norm_x-_xmin)/_xstep );
264 }
265 
266 double
267 PHG4BlockCellGeom::get_zcenter(const int ibin) const
268 {
269  if (ibin < 0 || ibin > _nzbins)
270  {
271  cout << "Asking for invalid bin in z: " << ibin << endl;
272  exit(1);
273  }
275  return _zmin + (ibin + 0.5)*_zstep;
276 }
277 
278 double
279 PHG4BlockCellGeom::get_etacenter(const int ibin) const
280 {
281  if (ibin < 0 || ibin > _nzbins)
282  {
283  cout << "Asking for invalid bin in eta: " << ibin << endl;
284  cout << "minbin: 0, maxbin " << _nzbins << endl;
285  exit(1);
286  }
288  return _zmin + (ibin + 0.5)*_zstep;
289 }
290 
291 double
292 PHG4BlockCellGeom::get_xcenter(const int ibin) const
293 {
294  if (ibin < 0 || ibin > _nxbins)
295  {
296  cout << "Asking for invalid bin in x: " << ibin << endl;
297  exit(1);
298  }
299 
301  return (_xmin + (ibin + 0.5)*_xstep);
302 }
303 
304 string
306 {
307  switch (i)
308  {
310  return "Bins in cm";
311  break;
313  return "Eta/Phi bins";
314  break;
316  return "Eta/numslat bins";
317  break;
318  default:
319  break;
320  }
321  return "Unknown";
322 }
323 
324 void
326 {
327  if (_binning != i)
328  {
329  cout << "different binning method used " << methodname(_binning)
330  << ", not : " << methodname(i)
331  << endl;
332  exit(1);
333  }
334  return;
335 }
336 
337 void
338 PHG4BlockCellGeom::check_binning_method_eta(const std::string & src) const
339 {
342  {
343  if (src.size())
344  cout << src<<" : ";
345 
346  cout << "different binning method used " << methodname(_binning)
349  << endl;
350  exit(1);
351  }
352  return;
353 }
354 
355 void
356 PHG4BlockCellGeom::check_binning_method_x(const std::string & src) const
357 {
361  {
362  if (src.size())
363  cout << src<<" : ";
364 
365  cout << "different binning method used " << methodname(_binning)
368  << endl;
369  exit(1);
370  }
371  return;
372 }