Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:39

0001 #include "CylinderGeomInttHelper.h"
0002 
0003 #include <trackbase/ActsGeometry.h>          // for ActsGeometry
0004 #include <trackbase/ActsTrackingGeometry.h>  // for ActsTrackingGeometry
0005 
0006 #include <Acts/Definitions/Units.hpp>
0007 
0008 #include <CLHEP/Vector/Rotation.h>
0009 #include <CLHEP/Vector/ThreeVector.h>
0010 
0011 #include <algorithm>
0012 #include <cmath>
0013 #include <memory>  // for __shared_ptr_access
0014 #include <utility>
0015 
0016 TVector3 CylinderGeomInttHelper::get_world_from_local_coords(const Surface& surface, ActsGeometry* tGeometry, const TVector3& local)
0017 {
0018   Acts::Vector3 loc(local.x(), local.y(), local.z());
0019   loc *= Acts::UnitConstants::cm;
0020 
0021   Acts::Vector3 glob = surface->transform(tGeometry->geometry().getGeoContext()) * loc;
0022   glob /= Acts::UnitConstants::cm;
0023   return TVector3(glob(0), glob(1), glob(2));
0024 }
0025 
0026 TVector3 CylinderGeomInttHelper::get_world_from_local_coords(const Surface& surface, ActsGeometry* tGeometry, const TVector2& local)
0027 {
0028   Acts::Vector2 actslocal;
0029   actslocal(0) = local.X();
0030   actslocal(1) = local.Y();
0031   actslocal *= Acts::UnitConstants::cm;
0032 
0033   /// Acts requires a dummy vector to be passed in the arg list
0034   auto global = surface->localToGlobal(tGeometry->geometry().getGeoContext(),
0035                                        actslocal,
0036                                        Acts::Vector3(1, 1, 1));
0037 
0038   global /= Acts::UnitConstants::cm;
0039 
0040   TVector3 ret;
0041   ret[0] = global(0);
0042   ret[1] = global(1);
0043   ret[2] = global(2);
0044 
0045   return ret;
0046 }
0047 
0048 TVector3 CylinderGeomInttHelper::get_local_from_world_coords(const Surface& surface, ActsGeometry* tGeometry, TVector3 world)
0049 {
0050   Acts::Vector3 global;
0051   global(0) = world[0];
0052   global(1) = world[1];
0053   global(2) = world[2];
0054   global *= Acts::UnitConstants::cm;
0055 
0056   Acts::Vector3 local = surface->transform(tGeometry->geometry().getGeoContext()).inverse() * global;
0057 
0058   local /= Acts::UnitConstants::cm;
0059 
0060   /// The acts transform is offset by one element
0061   return TVector3(local(2), local(0), local(1));
0062 }
0063 
0064 void CylinderGeomInttHelper::find_segment_center(const Surface& surface, ActsGeometry* tGeometry, double location[])
0065 {
0066   TVector2 local(0.0, 0.0);
0067 
0068   TVector3 global = get_world_from_local_coords(surface, tGeometry, local);
0069   location[0] = global.X();
0070   location[1] = global.Y();
0071   location[2] = global.Z();
0072   return;
0073 }
0074 
0075 void
0076 CylinderGeomInttHelper::find_strip_center (
0077   const Surface& surface,
0078   ActsGeometry* tGeometry,
0079   const int segment_z_bin,
0080   const int segment_phi_bin,
0081   const int strip_column,
0082   const int strip_index,
0083   double* location,
0084   CylinderGeomIntt& fren
0085 ) {
0086   // Ladder
0087   find_segment_center(surface, tGeometry, location);
0088   CLHEP::Hep3Vector ladder(location[0], location[1], location[2]);
0089 
0090   // Strip
0091   const int itype = segment_z_bin % 2;
0092   const double strip_z = fren.m_StripZ[itype];
0093   const int nstrips_z_sensor = fren.m_NStripsZSensor[itype];
0094 
0095   const double strip_localpos_z = strip_z * (strip_column % nstrips_z_sensor) - strip_z / 2. * nstrips_z_sensor + strip_z / 2.;
0096   // distance from bottom of sensor = m_StripY*strip_index +m_StripY/2.0, then subtract m_NStripsPhiCell * m_StripY / 2.0
0097   const double strip_localpos_y = fren.m_StripY * strip_index + fren.m_StripY / 2. - fren.m_NStripsPhiCell * fren.m_StripY / 2.0;
0098 
0099   CLHEP::Hep3Vector strip_localpos(fren.m_StripXOffset, strip_localpos_y, strip_localpos_z);
0100 
0101   // Strip rotation
0102   const double phi = fren.m_OffsetPhi + fren.m_dPhi * segment_phi_bin;
0103   const double rotate = phi + fren.m_OffsetRot;
0104 
0105   CLHEP::HepRotation rot;
0106   rot.rotateZ(rotate);
0107   strip_localpos = rot * strip_localpos;
0108   strip_localpos += ladder;
0109 
0110   location[0] = strip_localpos.x();
0111   location[1] = strip_localpos.y();
0112   location[2] = strip_localpos.z();
0113 }
0114