EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4BlockGeomv1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4BlockGeomv1.cc
1 #include "PHG4BlockGeomv1.h"
2 
3 #include <algorithm>
4 #include <cmath>
5 
6 using namespace std;
7 
10  _layer(-1),
11  _rotation_z(NAN)
12 {
13  const double filldval = 1.;
14  fill( _size, _size + sizeof(_size)/sizeof(double),NAN);
15  fill( _center, _center + sizeof(_center)/sizeof(double),NAN);
16  fill( &_rot_matrix[0][0], &_rot_matrix[0][0] + sizeof(_rot_matrix)/sizeof(double),filldval);
17 }
18 
20  const double sizex, const double sizey, const double sizez,
21  const double centerx, const double centery, const double centerz,
22  const double zrot) :
23  PHG4BlockGeom(),
24  _layer(layer),
25  _rotation_z(zrot)
26 {
27  _size[0] = sizex;
28  _size[1] = sizey;
29  _size[2] = sizez;
30  _center[0] = centerx;
31  _center[1] = centery;
32  _center[2] = centerz;
33 
35 }
36 
37 void
38 PHG4BlockGeomv1::identify(std::ostream& os) const
39 {
40  os << "PHG4BlockGeomv1: layer: " << _layer
41  << ", rotation in z: " << _rotation_z
42  << ", size: (" << _size[0] << ", " << _size[1] << ", " << _size[2] << ")"
43  << ", center: (" << _center[0] << ", " << _center[1] << ", " << _center[2] << ")"
44  << endl;
45  return;
46 }
47 
48 void
49 PHG4BlockGeomv1::set_size(const double sizex, const double sizey, const double sizez)
50 {
51  _size[0] = sizex;
52  _size[1] = sizey;
53  _size[2] = sizez;
54  return;
55 }
56 
57 void
58 PHG4BlockGeomv1::set_center(const double centerx, const double centery, const double centerz)
59 {
60  _center[0] = centerx;
61  _center[1] = centery;
62  _center[2] = centerz;
63  return;
64 }
65 
66 void PHG4BlockGeomv1::convert_local_to_global(double lx, double ly, double lz,
67  double &gx, double &gy, double &gz) const
68 {
69  // gvec = R^T lvec + offset
70  gx = _rot_matrix[0][0]*lx + _rot_matrix[1][0]*ly + _rot_matrix[2][0]*lz;
71  gy = _rot_matrix[0][1]*lx + _rot_matrix[1][1]*ly + _rot_matrix[2][1]*lz;
72  gz = _rot_matrix[0][2]*lx + _rot_matrix[1][2]*ly + _rot_matrix[2][2]*lz;
73  gx += _center[0];
74  gy += _center[1];
75  gz += _center[2];
76  return;
77 }
78 
79 void PHG4BlockGeomv1::convert_global_x_to_local(double gx, double gy, double gz,
80  double &lx, double &ly, double &lz) const
81 {
82  // lvec = R (gvec - offset)
83  gx -= _center[0];
84  gy -= _center[1];
85  gz -= _center[2];
86  lx = _rot_matrix[0][0]*gx + _rot_matrix[0][1]*gy + _rot_matrix[0][2]*gz;
87  ly = _rot_matrix[1][0]*gx + _rot_matrix[1][1]*gy + _rot_matrix[1][2]*gz;
88  lz = _rot_matrix[2][0]*gx + _rot_matrix[2][1]*gy + _rot_matrix[2][2]*gz;
89  return;
90 }
91 
93 {
94  _rot_matrix[0][0] = cos(_rotation_z);
95  _rot_matrix[0][1] = sin(_rotation_z);
96  _rot_matrix[1][0] = -sin(_rotation_z);
97  _rot_matrix[1][1] = cos(_rotation_z);
98  _rot_matrix[2][2] = 1.;
99 }