Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "CylinderGeomIntt.h"
0002 
0003 #include <algorithm>
0004 #include <cmath>
0005 #include <memory>  // for __shared_ptr_access
0006 #include <utility>
0007 
0008 void CylinderGeomIntt::identify(std::ostream& os) const
0009 {
0010   os << "CylinderGeomIntt Object" << std::endl;
0011   os << "layer: " << get_layer() << std::endl;
0012   os << "Radius: " << get_radius() << std::endl;
0013 }
0014 
0015 void CylinderGeomIntt::find_indices_from_world_location(int& segment_z_bin, int& segment_phi_bin, double location[])
0016 {
0017   double signz = (location[2] > 0) ? 1. : -1;
0018   double phi = atan2(location[1], location[0]);
0019   double tolerance_phi = 0.05;
0020   double tolerance_z = 0.5;
0021 
0022   if (fabs(phi - m_OffsetPhi) > tolerance_phi && phi < 0)
0023   {
0024     phi += 2.0 * M_PI;
0025   }
0026   double segment_phi_bin_tmp = (phi - m_OffsetPhi) / m_dPhi;
0027   segment_phi_bin = round(segment_phi_bin_tmp);
0028 
0029   double z_tmp = location[2] / signz;
0030 
0031   // decide if this is a type A (0) or type B (1) sensor
0032   int itype;
0033   // if (fabs((z_tmp / m_LadderZ[0])) < 1.0)
0034   if (fabs((1.0 - z_tmp / m_LadderZ[0])) < tolerance_z)
0035   {
0036     itype = 0;
0037   }
0038   else
0039   {
0040     itype = 1;
0041   }
0042 
0043   if (signz < 0)
0044   {
0045     segment_z_bin = itype;  // 0 = itype 0 +z,  1 = itype 1 +z,  2 = itupe 0 -z, 3 = itype 1 -z
0046   }
0047   else
0048   {
0049     segment_z_bin = itype + 2;
0050   }
0051 }
0052 
0053 void CylinderGeomIntt::find_indices_from_segment_center(int& segment_z_bin, int& segment_phi_bin, double location[])
0054 {
0055   double signz = (location[2] > 0) ? 1. : -1;
0056   double phi = atan2(location[1], location[0]);
0057   // std::cout << "phi before 2pi shift=" << phi << " offset " << m_OffsetPhi << " fabs(phi - m_OffsetPhi)=" << fabs(phi - m_OffsetPhi) << std::endl;
0058   double tolerance_phi = 0.05;
0059   double tolerance_z = 0.5;
0060   if (fabs(phi - m_OffsetPhi) > tolerance_phi && phi < 0)
0061   {
0062     phi += 2.0 * M_PI;
0063   }
0064   double segment_phi_bin_tmp = (phi - m_OffsetPhi) / m_dPhi;
0065   segment_phi_bin = lround(segment_phi_bin_tmp);
0066 
0067   // std::cout << "     phi " <<phi << " segment_phi_bin_tmp " <<  segment_phi_bin_tmp << " segment_phi_bin " << segment_phi_bin << " location " << location[0] << "  " << location[1] << "  " << location[2] << std::endl;
0068 
0069   double z_tmp = location[2] / signz;
0070 
0071   // decide if this is a type A (0) or type B (1) sensor
0072   int itype;
0073   if (fabs((1.0 - z_tmp / m_LadderZ[0])) < tolerance_z)
0074   {
0075     itype = 0;
0076   }
0077   else
0078   {
0079     itype = 1;
0080   }
0081 
0082   if (signz < 0)
0083   {
0084     segment_z_bin = itype;  // 0 = itype 0 +z,  1 = itype 1 +z,  2 = itupe 1 -z, 3 = itype 1 -z
0085   }
0086   else
0087   {
0088     segment_z_bin = itype + 2;
0089   }
0090 
0091   // std::cout << " world coords: " <<  location[0] << " " << location[1] << " " << location[2] <<  " signz " << signz << " itype " << itype << " z_tmp " << z_tmp <<  " m_LadderZ " << m_LadderZ[itype] << std::endl;
0092   // std::cout << "radius " << m_SensorRadius << " offsetphi " << m_OffsetPhi << " rad  dphi_ " << m_dPhi << " rad  segment_phi_bin " << segment_phi_bin << " phi " << phi  << std::endl;
0093 }
0094 
0095 void CylinderGeomIntt::find_strip_index_values(const int segment_z_bin, const double yin, const double zin, int& strip_y_index, int& strip_z_index)
0096 {
0097   // Given the location in y and z in sensor local coordinates, find the strip y and z index values
0098 
0099   // find the sensor type (inner or outer) from the segment_z_bin (location of sensor on ladder)
0100   const int itype = segment_z_bin % 2;
0101   if (itype != 0 && itype != 1)
0102   {
0103     std::cout << "Problem: itype = " << itype << std::endl;
0104     return;
0105   }
0106 
0107   // expect cm
0108   double zpos = zin;
0109   double ypos = yin;
0110 
0111   const double strip_z = m_StripZ[itype];
0112   const int nstrips_z_sensor = m_NStripsZSensor[itype];
0113   const int nstrips_y_sensor = m_NStripsPhiCell;
0114 
0115   // get the strip z index
0116   double zup = (double) nstrips_z_sensor * strip_z / 2.0 + zpos;
0117   strip_z_index = floor(zup / strip_z);
0118 
0119   // get the strip y index
0120   double yup = (double) nstrips_y_sensor * m_StripY / 2.0 + ypos;
0121   strip_y_index = floor(yup / m_StripY);
0122 
0123   /*
0124   std::cout << "segment_z_bin " << segment_z_bin << " ypos " << ypos << " zpos " << zpos << " zup " << zup << " yup " << yup << std::endl;
0125   std::cout << "      -- itype " << itype << " strip_y " << m_StripY << " strip_z " << strip_z << " nstrips_z_sensor " << nstrips_z_sensor
0126        << " nstrips_y_sensor " << nstrips_y_sensor << std::endl;
0127   std::cout << "      --  strip_z_index " << strip_z_index << " strip_y_index " << strip_y_index << std::endl;
0128   */
0129 }
0130 
0131 // this name is a really bad idea whcih ticks off clang-tidy (justifiably) but it seems intentional
0132 // NOLINTNEXTLINE(bugprone-virtual-near-miss)
0133 void CylinderGeomIntt::find_strip_center_localcoords(const int segment_z_bin, const int strip_y_index, const int strip_z_index, double location[])
0134 {
0135   // find the sensor type (inner or outer) from the segment_z_bin (location of sensor on ladder)
0136   const int itype = segment_z_bin % 2;
0137   if (itype != 0 && itype != 1)
0138   {
0139     std::cout << "Problem: itype = " << itype << std::endl;
0140     return;
0141   }
0142 
0143   const double strip_z = m_StripZ[itype];
0144   const int nstrips_z_sensor = m_NStripsZSensor[itype];
0145   const int nstrips_y_sensor = m_NStripsPhiCell;
0146 
0147   // center of strip in y
0148   double ypos = (double) strip_y_index * m_StripY + m_StripY / 2.0 - (double) nstrips_y_sensor * m_StripY / 2.0;
0149 
0150   // center of strip in z
0151   double zpos = (double) strip_z_index * strip_z + strip_z / 2.0 - (double) nstrips_z_sensor * strip_z / 2.0;
0152 
0153   location[0] = 0.0;
0154   location[1] = ypos;
0155   location[2] = zpos;
0156 }