Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4TpcCylinderGeom.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4TpcCylinderGeom.cc
1 #include "PHG4TpcCylinderGeom.h"
2 #include "PHG4CylinderCellDefs.h"
3 
4 #include <phool/phool.h>
5 #include <cstdlib>
6 
7 namespace
8 {
9  // streamer for internal 2dimensional arrays
10  using array_t = std::array<std::vector<double>, PHG4TpcCylinderGeom::NSides >;
11  std::ostream& operator << (std::ostream& out, const array_t& array )
12  {
13  out << "{ ";
14  for( size_t iside = 0; iside < array.size(); ++iside )
15  {
16  out << "{";
17  bool first = true;
18  for( const auto& value:array[iside] )
19  {
20  if( !first ) out << ", ";
21  first = false;
22  out << value;
23  }
24  out << "} ";
25  }
26  out << " }";
27  return out;
28  }
29 }
30 
31 std::ostream& operator << (std::ostream& out, const PHG4TpcCylinderGeom& geom )
32 {
33  out << "PHG4TpcCylinderGeom - layer: " << geom.layer << std::endl;
34  out
35  << " binnig: " << geom.binning
36  << ", radius: " << geom.radius
37  << ", nzbins: " << geom.nzbins
38  << ", zmin: " << geom.zmin
39  << ", zstep: " << geom.zstep
40  << ", nphibins: " << geom.nphibins
41  << ", phimin: " << geom.phimin
42  << ", phistep: " << geom.phistep
43  << ", thickness: " << geom.thickness
44  << std::endl;
45 
46  out << " sector_R_bias: " << geom.sector_R_bias << std::endl;
47  out << " sector_Phi_bias: " << geom.sector_Phi_bias << std::endl;
48  out << " sector_min_Phi: " << geom.sector_min_Phi << std::endl;
49  out << " sector_max_Phi: " << geom.sector_max_Phi << std::endl;
50 
51  return out;
52 }
53 
54 
56 {
58  nzbins = i;
59 }
60 
61 void PHG4TpcCylinderGeom::set_zmin(const double z)
62 {
64  zmin = z;
65 }
66 
68 {
70  return nzbins;
71 }
72 
73 double
75 {
77  return zmin;
78 }
79 
80 double
82 {
84  return zstep;
85 }
86 
88 {
90  zstep = z;
91 }
92 
94 {
95  check_binning_method_phi("PHG4TpcCylinderGeom::get_phibins");
96  return nphibins;
97 }
98 
99 double
101 {
102  check_binning_method_phi("PHG4TpcCylinderGeom::get_phistep");
103  return phistep;
104 }
105 
106 double
108 {
109  check_binning_method_phi("PHG4TpcCylinderGeom::get_phimin");
110  return phimin;
111 }
112 
114 {
115  check_binning_method_phi("PHG4TpcCylinderGeom::set_phibins");
116  nphibins = i;
117 }
118 
120 {
121  check_binning_method_phi("PHG4TpcCylinderGeom::set_phistep");
122  phistep = r;
123 }
124 
126 {
127  check_binning_method_phi("PHG4TpcCylinderGeom::set_phimin");
128  phimin = r;
129 }
130 
132 {
133  check_binning_method_eta("PHG4TpcCylinderGeom::get_etabins");
134  return nzbins;
135 }
136 
137 double
139 {
140  check_binning_method_eta("PHG4TpcCylinderGeom::get_etastep");
141  return zstep;
142 }
143 double
145 {
146  check_binning_method_eta("PHG4TpcCylinderGeom::get_etamin");
147  return zmin;
148 }
149 
151 {
152  check_binning_method_eta("PHG4TpcCylinderGeom::set_etamin");
153  zmin = z;
154 }
155 
157 {
158  check_binning_method_eta("PHG4TpcCylinderGeom::set_etastep");
159  zstep = z;
160 }
161 
163 {
164  check_binning_method_eta("PHG4TpcCylinderGeom::set_etabins");
165  nzbins = i;
166 }
167 
168 void PHG4TpcCylinderGeom::identify(std::ostream& os) const
169 {
170  os << "PHG4TpcCylinderGeom::identify - layer: " << layer
171  << ", radius: " << radius
172  << ", thickness: " << thickness;
173  switch (binning)
174  {
176  os << ", zbins: " << nzbins
177  << ", zmin: " << zmin
178  << ", zstepsize: " << zstep;
179  break;
181  os << ", etabins: " << nzbins
182  << ", etamin: " << zmin
183  << ", etastepsize: " << zstep;
184  break;
186  os << ", etabins: " << nzbins
187  << ", etamin: " << zmin
188  << ", etastepsize: " << zstep;
189  break;
191  os << ", etabins: " << nzbins << " for Spacal";
192  break;
193  default:
194  os << "no valid binning method: " << binning << std::endl;
195  return;
196  break;
197  }
198  os << ", phimin: " << phimin
199  << ", phibins: " << nphibins
200  << ", phistep: " << phistep
201  << std::endl;
202  return;
203 }
204 
205 std::pair<double, double>
207 {
208  if (ibin < 0 || ibin > nzbins)
209  {
210  std::cout << PHWHERE << " Asking for invalid bin in z: " << ibin << std::endl;
211  exit(1);
212  }
214  double zlow = zmin + ibin * zstep;
215  double zhigh = zlow + zstep;
216  return std::make_pair(zlow, zhigh);
217 }
218 
219 std::pair<double, double>
221 {
222  if (ibin < 0 || ibin > nzbins)
223  {
224  std::cout << PHWHERE << " Asking for invalid bin in z: " << ibin << std::endl;
225  exit(1);
226  }
227  check_binning_method_eta("PHG4TpcCylinderGeom::get_etabounds");
228  // check_binning_method(PHG4CylinderCellDefs::etaphibinning);
229  double zlow = zmin + ibin * zstep;
230  double zhigh = zlow + zstep;
231  return std::make_pair(zlow, zhigh);
232 }
233 
234 std::pair<double, double>
236 {
237  if (ibin < 0 || ibin > nphibins)
238  {
239  std::cout << PHWHERE << "Asking for invalid bin in phi: " << ibin << std::endl;
240  exit(1);
241  }
242 
243  double philow = phimin + ibin * phistep;
244  double phihigh = philow + phistep;
245  return std::make_pair(philow, phihigh);
246 }
247 
248 int PHG4TpcCylinderGeom::get_zbin(const double z) const
249 {
250  if (z < zmin || z > (zmin + nzbins * zstep))
251  {
252  // cout << PHWHERE << "Asking for bin for z outside of z range: " << z << endl;
253  return -1;
254  }
255 
257  return floor((z - zmin) / zstep);
258 }
259 
260 int PHG4TpcCylinderGeom::get_etabin(const double eta) const
261 {
262  if (eta < zmin || eta > (zmin + nzbins * zstep))
263  {
264  // cout << "Asking for bin for eta outside of eta range: " << eta << endl;
265  return -1;
266  }
268  return floor((eta - zmin) / zstep);
269 }
270 
272 {
273  double norm_phi = phi;
274  if (phi < phimin || phi > (phimin + nphibins * phistep))
275  {
276  int nwraparound = -floor((phi - phimin) * 0.5 / M_PI);
277  norm_phi += 2 * M_PI * nwraparound;
278  }
280  return floor((norm_phi - phimin) / phistep);
281 
282 }
283 
284 int PHG4TpcCylinderGeom::find_phibin(const double phi, int side ) const
285 {
286  double norm_phi = phi;
287  if (phi < phimin || phi > (phimin + nphibins * phistep))
288  {
289  int nwraparound = -floor((phi - phimin) * 0.5 / M_PI);
290  norm_phi += 2 * M_PI * nwraparound;
291  }
292  //if (phi > M_PI){
293  // norm_phi = phi - 2* M_PI;
294  //}
295  //if (phi < phimin){
296  // norm_phi = phi + 2* M_PI;
297  //}
298  side = 0 ;
299 
300  int phi_bin = -1;
301 
302  for(std::size_t s=0;s<sector_max_Phi[side].size();s++){
303  if(norm_phi < sector_max_Phi[side][s] && norm_phi > sector_min_Phi[side][s]){
304  phi_bin = ( floor(std::abs(sector_max_Phi[side][s] - norm_phi)/phistep) + nphibins/12 * s);
305  break;
306  }
307  if (s==11){
308  if(norm_phi < sector_max_Phi[side][s] && norm_phi >= -M_PI){
309  phi_bin = floor( std::abs(sector_max_Phi[side][s] - norm_phi)/phistep ) + nphibins/12 * s;
310  break;
311  }
312  if(norm_phi > sector_min_Phi[side][s]+2*M_PI ){
313  phi_bin = floor( std::abs(sector_max_Phi[side][s] - (norm_phi - 2*M_PI))/phistep ) + nphibins/12 * s;
314  break;
315  }
316 
317  }
318  }
319  return phi_bin;
320 }
321 
322 float PHG4TpcCylinderGeom::get_pad_float(const double phi, int side ) const
323 {
324  double norm_phi = phi;
325  if (phi < phimin || phi > (phimin + nphibins * phistep))
326  {
327  int nwraparound = -floor((phi - phimin) * 0.5 / M_PI);
328  norm_phi += 2 * M_PI * nwraparound;
329  }
330  //if (phi > M_PI){
331  // norm_phi = phi - 2* M_PI;
332  //}
333  //if (phi < phimin){
334  // norm_phi = phi + 2* M_PI;
335  //}
336  side = 0 ;
337 
338  float phi_bin = -1;
339 
340  for(std::size_t s=0;s<sector_max_Phi[side].size();s++){
341  if(norm_phi < sector_max_Phi[side][s] && norm_phi > sector_min_Phi[side][s]){
342  phi_bin = ( std::abs(sector_max_Phi[side][s] - norm_phi)/phistep) + nphibins/12 * s;
343  break;
344  }
345  if (s==11){
346  if(norm_phi < sector_max_Phi[side][s] && norm_phi >= -M_PI){
347  phi_bin = ( std::abs(sector_max_Phi[side][s] - norm_phi)/phistep ) + nphibins/12 * s;
348  break;
349  }
350  if(norm_phi > sector_min_Phi[side][s]+2*M_PI ){
351  phi_bin = ( std::abs(sector_max_Phi[side][s] - (norm_phi - 2*M_PI))/phistep ) + nphibins/12 * s;
352  break;
353  }
354 
355  }
356  }
357  return phi_bin - 0.5;
358 }
359 
360 float PHG4TpcCylinderGeom::get_tbin_float(const double z) const
361 {
362  if (z < zmin || z > (zmin + nzbins * zstep))
363  {
364  // cout << PHWHERE << "Asking for bin for z outside of z range: " << z << endl;
365  return -1;
366  }
367 
369  return ((z - zmin) / zstep)-0.5;
370 }
371 
372 int PHG4TpcCylinderGeom::get_phibin(const double phi, int side ) const
373 {
374  double new_phi = phi;
375  if (phi > M_PI){
376  new_phi = phi - 2* M_PI;
377  }
378  if (phi < phimin){
379  new_phi = phi + 2* M_PI;
380  }
381  // Get phi-bin number
382  int phi_bin = find_phibin(new_phi);
383 
384  side = 0;
385  // If phi-bin is not defined, check that it is in the dead area and put it to the edge of sector
386  if (phi_bin<0){
387 
388  //
389  for(std::size_t s=0;s<sector_max_Phi[side].size();s++){
390  double daPhi = 0;
391  if (s==0){
392  daPhi = fabs(sector_min_Phi[side][11] + 2*M_PI - sector_max_Phi[side][s]);
393  }else{
394  daPhi = fabs(sector_min_Phi[side][s-1] - sector_max_Phi[side][s]);
395  }
396 
397  double min_phi = sector_max_Phi[side][s];
398  double max_phi = sector_max_Phi[side][s]+daPhi;
399  if (new_phi<=max_phi && new_phi>=min_phi){
400  if(fabs(max_phi - new_phi) > fabs(new_phi - min_phi)){
401  new_phi = min_phi-phistep/5;
402  }else{
403  new_phi = max_phi+phistep/5;
404  }
405  }
406  }
407  //exit(1);
408 
409  phi_bin = find_phibin(new_phi);
410  if (phi_bin<0){
411  std::cout << PHWHERE << "Asking for bin for phi outside of phi range: " << phi << std::endl;
412  exit(1);
413  //phi_bin=0;
414  }
415 
416  }
417  return phi_bin;
418 }
419 
420 double
422 {
423  if (ibin < 0 || ibin > nzbins)
424  {
425  std::cout << PHWHERE << "Asking for invalid bin in z: " << ibin << std::endl;
426  exit(1);
427  }
429  return zmin + (ibin + 0.5) * zstep;
430 }
431 
432 double
434 {
435  if (ibin < 0 || ibin > nzbins)
436  {
437  std::cout << PHWHERE << "Asking for invalid bin in eta: " << ibin << std::endl;
438  std::cout << "minbin: 0, maxbin " << nzbins << std::endl;
439  exit(1);
440  }
442  return zmin + (ibin + 0.5) * zstep;
443 }
444 
445 double
447 {
448  if (ibin < 0 || ibin > nphibins)
449  {
450  std::cout << PHWHERE << "Asking for invalid bin in phi: " << ibin << std::endl;
451  exit(1);
452  }
453 
455 
456  return (phimin + (ibin + 0.5) * phistep);
457 }
458 
459 
460 double
462 {
463  //double phi_center = -999;
464  if (ibin < 0 || ibin > nphibins)
465  {
466  std::cout << PHWHERE << "Asking for invalid bin in phi: " << ibin << std::endl;
467  exit(1);
468  }
469 
471 
472  const int side = 0 ;
473  unsigned int pads_per_sector = nphibins / 12;
474  unsigned int sector = ibin / pads_per_sector;
475  double phi_center = (sector_max_Phi[side][sector] - (ibin + 0.5 - sector * pads_per_sector) * phistep);
476  if(phi_center <= -M_PI){
477  phi_center += 2*M_PI;
478  }
479  return phi_center;
480 }
481 
482 double
484 {
485  //double phi_center = -999;
486  if (ibin < 0 || ibin > nphibins)
487  {
488  std::cout << PHWHERE << "Asking for invalid bin in phi: " << ibin << std::endl;
489  exit(1);
490  }
491 
493 
494  const int side = 0 ;
495  unsigned int pads_per_sector = nphibins / 12;
496  unsigned int sector = ibin / pads_per_sector;
497  double phi = (sector_max_Phi[side][sector] - (ibin +0.5 - sector * pads_per_sector) * phistep);
498  if(phi <= -M_PI){
499  phi += 2*M_PI;
500  }
501  return phi;
502 }
503 
506 {
507  switch (i)
508  {
510  return "Bins in cm";
511  break;
513  return "Eta/Phi bins";
514  break;
516  return "Eta/numslat bins";
517  break;
519  return "SPACAL Tower bins";
520  break;
521  default:
522  break;
523  }
524  return "Unknown";
525 }
526 
528 {
529  if (binning != i)
530  {
531  std::cout << "different binning method used " << methodname(binning)
532  << ", not : " << methodname(i)
533  << std::endl;
534  exit(1);
535  }
536  return;
537 }
538 
540 {
544  {
545  if (src.size())
546  std::cout << src << " : ";
547 
548  std::cout << "different binning method used " << methodname(binning)
552  << std::endl;
553  exit(1);
554  }
555  return;
556 }
557 
559 {
564  {
565  if (src.size())
566  std::cout << src << " : ";
567 
568  std::cout << "different binning method used " << methodname(binning)
573  << std::endl;
574  exit(1);
575  }
576  return;
577 }