Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:18:54

0001 #include "PHG4BlockGeomv1.h"
0002 
0003 #include <algorithm>
0004 #include <cmath>
0005 
0006 using namespace std;
0007 
0008 PHG4BlockGeomv1::PHG4BlockGeomv1()
0009   : PHG4BlockGeom()
0010   , _layer(-1)
0011   , _rotation_z(NAN)
0012 {
0013   const double filldval = 1.;
0014   fill(_size, _size + sizeof(_size) / sizeof(double), NAN);
0015   fill(_center, _center + sizeof(_center) / sizeof(double), NAN);
0016   fill(&_rot_matrix[0][0], &_rot_matrix[0][0] + sizeof(_rot_matrix) / sizeof(double), filldval);
0017 }
0018 
0019 PHG4BlockGeomv1::PHG4BlockGeomv1(const int layer,
0020                                  const double sizex, const double sizey, const double sizez,
0021                                  const double centerx, const double centery, const double centerz,
0022                                  const double zrot)
0023   : PHG4BlockGeom()
0024   , _layer(layer)
0025   , _rotation_z(zrot)
0026 {
0027   _size[0] = sizex;
0028   _size[1] = sizey;
0029   _size[2] = sizez;
0030   _center[0] = centerx;
0031   _center[1] = centery;
0032   _center[2] = centerz;
0033 
0034   _build_rot_matrix();
0035 }
0036 
0037 void PHG4BlockGeomv1::identify(std::ostream &os) const
0038 {
0039   os << "PHG4BlockGeomv1: layer: " << _layer
0040      << ", rotation in z: " << _rotation_z
0041      << ", size: (" << _size[0] << ", " << _size[1] << ", " << _size[2] << ")"
0042      << ", center: (" << _center[0] << ", " << _center[1] << ", " << _center[2] << ")"
0043      << endl;
0044   return;
0045 }
0046 
0047 void PHG4BlockGeomv1::set_size(const double sizex, const double sizey, const double sizez)
0048 {
0049   _size[0] = sizex;
0050   _size[1] = sizey;
0051   _size[2] = sizez;
0052   return;
0053 }
0054 
0055 void PHG4BlockGeomv1::set_center(const double centerx, const double centery, const double centerz)
0056 {
0057   _center[0] = centerx;
0058   _center[1] = centery;
0059   _center[2] = centerz;
0060   return;
0061 }
0062 
0063 void PHG4BlockGeomv1::convert_local_to_global(double lx, double ly, double lz,
0064                                               double &gx, double &gy, double &gz) const
0065 {
0066   // gvec = R^T lvec + offset
0067   gx = _rot_matrix[0][0] * lx + _rot_matrix[1][0] * ly + _rot_matrix[2][0] * lz;
0068   gy = _rot_matrix[0][1] * lx + _rot_matrix[1][1] * ly + _rot_matrix[2][1] * lz;
0069   gz = _rot_matrix[0][2] * lx + _rot_matrix[1][2] * ly + _rot_matrix[2][2] * lz;
0070   gx += _center[0];
0071   gy += _center[1];
0072   gz += _center[2];
0073   return;
0074 }
0075 
0076 void PHG4BlockGeomv1::convert_global_x_to_local(double gx, double gy, double gz,
0077                                                 double &lx, double &ly, double &lz) const
0078 {
0079   // lvec = R (gvec - offset)
0080   gx -= _center[0];
0081   gy -= _center[1];
0082   gz -= _center[2];
0083   lx = _rot_matrix[0][0] * gx + _rot_matrix[0][1] * gy + _rot_matrix[0][2] * gz;
0084   ly = _rot_matrix[1][0] * gx + _rot_matrix[1][1] * gy + _rot_matrix[1][2] * gz;
0085   lz = _rot_matrix[2][0] * gx + _rot_matrix[2][1] * gy + _rot_matrix[2][2] * gz;
0086   return;
0087 }
0088 
0089 void PHG4BlockGeomv1::_build_rot_matrix()
0090 {
0091   _rot_matrix[0][0] = cos(_rotation_z);
0092   _rot_matrix[0][1] = sin(_rotation_z);
0093   _rot_matrix[1][0] = -sin(_rotation_z);
0094   _rot_matrix[1][1] = cos(_rotation_z);
0095   _rot_matrix[2][2] = 1.;
0096 }