Analysis Software
Documentation for sPHENIX simulation 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 
9  : PHG4BlockGeom()
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 PHG4BlockGeomv1::identify(std::ostream &os) const
38 {
39  os << "PHG4BlockGeomv1: layer: " << _layer
40  << ", rotation in z: " << _rotation_z
41  << ", size: (" << _size[0] << ", " << _size[1] << ", " << _size[2] << ")"
42  << ", center: (" << _center[0] << ", " << _center[1] << ", " << _center[2] << ")"
43  << endl;
44  return;
45 }
46 
47 void PHG4BlockGeomv1::set_size(const double sizex, const double sizey, const double sizez)
48 {
49  _size[0] = sizex;
50  _size[1] = sizey;
51  _size[2] = sizez;
52  return;
53 }
54 
55 void PHG4BlockGeomv1::set_center(const double centerx, const double centery, const double centerz)
56 {
57  _center[0] = centerx;
58  _center[1] = centery;
59  _center[2] = centerz;
60  return;
61 }
62 
63 void PHG4BlockGeomv1::convert_local_to_global(double lx, double ly, double lz,
64  double &gx, double &gy, double &gz) const
65 {
66  // gvec = R^T lvec + offset
67  gx = _rot_matrix[0][0] * lx + _rot_matrix[1][0] * ly + _rot_matrix[2][0] * lz;
68  gy = _rot_matrix[0][1] * lx + _rot_matrix[1][1] * ly + _rot_matrix[2][1] * lz;
69  gz = _rot_matrix[0][2] * lx + _rot_matrix[1][2] * ly + _rot_matrix[2][2] * lz;
70  gx += _center[0];
71  gy += _center[1];
72  gz += _center[2];
73  return;
74 }
75 
76 void PHG4BlockGeomv1::convert_global_x_to_local(double gx, double gy, double gz,
77  double &lx, double &ly, double &lz) const
78 {
79  // lvec = R (gvec - offset)
80  gx -= _center[0];
81  gy -= _center[1];
82  gz -= _center[2];
83  lx = _rot_matrix[0][0] * gx + _rot_matrix[0][1] * gy + _rot_matrix[0][2] * gz;
84  ly = _rot_matrix[1][0] * gx + _rot_matrix[1][1] * gy + _rot_matrix[1][2] * gz;
85  lz = _rot_matrix[2][0] * gx + _rot_matrix[2][1] * gy + _rot_matrix[2][2] * gz;
86  return;
87 }
88 
90 {
91  _rot_matrix[0][0] = cos(_rotation_z);
92  _rot_matrix[0][1] = sin(_rotation_z);
93  _rot_matrix[1][0] = -sin(_rotation_z);
94  _rot_matrix[1][1] = cos(_rotation_z);
95  _rot_matrix[2][2] = 1.;
96 }