Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CylinderGeomIntt.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CylinderGeomIntt.cc
1 #include "CylinderGeomIntt.h"
2 
3 #include <trackbase/ActsGeometry.h> // for ActsGeometry
4 #include <trackbase/ActsTrackingGeometry.h> // for ActsTrackingGeometry
5 
7 
8 #include <CLHEP/Vector/Rotation.h>
9 #include <CLHEP/Vector/ThreeVector.h>
10 
11 #include <algorithm>
12 #include <cmath>
13 #include <memory> // for __shared_ptr_access
14 #include <utility>
15 
16 void CylinderGeomIntt::identify(std::ostream& os) const
17 {
18  os << "CylinderGeomIntt Object" << std::endl;
19  os << "layer: " << get_layer() << std::endl;
20  os << "Radius: " << get_radius() << std::endl;
21 }
22 
24 {
25  Acts::Vector3 loc(local.x(), local.y(), local.z());
27 
28  Acts::Vector3 glob = surface->transform(tGeometry->geometry().getGeoContext()) * loc;
30  return TVector3(glob(0), glob(1), glob(2));
31 }
33 {
34  Acts::Vector2 actslocal;
35  actslocal(0) = local.X();
36  actslocal(1) = local.Y();
37  actslocal *= Acts::UnitConstants::cm;
38 
40  auto global = surface->localToGlobal(tGeometry->geometry().getGeoContext(),
41  actslocal,
42  Acts::Vector3(1, 1, 1));
43 
44  global /= Acts::UnitConstants::cm;
45 
46  TVector3 ret;
47  ret[0] = global(0);
48  ret[1] = global(1);
49  ret[2] = global(2);
50 
51  return ret;
52 }
54 {
55  Acts::Vector3 global;
56  global(0) = world[0];
57  global(1) = world[1];
58  global(2) = world[2];
59  global *= Acts::UnitConstants::cm;
60 
61  Acts::Vector3 local = surface->transform(tGeometry->geometry().getGeoContext()).inverse() * global;
62 
63  local /= Acts::UnitConstants::cm;
64 
66  return TVector3(local(2), local(0), local(1));
67 }
68 
70 {
71  TVector2 local(0.0, 0.0);
72 
73  TVector3 global = get_world_from_local_coords(surface, tGeometry, local);
74  location[0] = global.X();
75  location[1] = global.Y();
76  location[2] = global.Z();
77  return;
78 }
79 
80 void CylinderGeomIntt::find_indices_from_world_location(int& segment_z_bin, int& segment_phi_bin, double location[])
81 {
82  double signz = (location[2] > 0) ? 1. : -1;
83  double phi = atan2(location[1], location[0]);
84  if (fabs(phi - m_OffsetPhi) > 0.01 && phi < 0)
85  {
86  phi += 2.0 * M_PI;
87  }
88  double segment_phi_bin_tmp = (phi - m_OffsetPhi) / m_dPhi;
89  segment_phi_bin = round(segment_phi_bin_tmp);
90 
91  double z_tmp = location[2] / signz;
92 
93  // decide if this is a type A (0) or type B (1) sensor
94  int itype;
95  if (fabs((z_tmp / m_LadderZ[0])) < 1.0)
96  {
97  itype = 0;
98  }
99  else
100  {
101  itype = 1;
102  }
103 
104  if (signz < 0)
105  {
106  segment_z_bin = itype; // 0 = itype 0 +z, 1 = itype 1 +z, 2 = itupe 0 -z, 3 = itype 1 -z
107  }
108  else
109  {
110  segment_z_bin = itype + 2;
111  }
112 }
113 
114 void CylinderGeomIntt::find_indices_from_segment_center(int& segment_z_bin, int& segment_phi_bin, double location[])
115 {
116  double signz = (location[2] > 0) ? 1. : -1;
117  double phi = atan2(location[1], location[0]);
118  if (fabs(phi - m_OffsetPhi) > 0.01 && phi < 0)
119  {
120  phi += 2.0 * M_PI;
121  }
122  double segment_phi_bin_tmp = (phi - m_OffsetPhi) / m_dPhi;
123  segment_phi_bin = lround(segment_phi_bin_tmp);
124 
125  // 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;
126 
127  double z_tmp = location[2] / signz;
128 
129  // decide if this is a type A (0) or type B (1) sensor
130  int itype;
131  if (fabs((1.0 - z_tmp / m_LadderZ[0])) < 0.01)
132  {
133  itype = 0;
134  }
135  else
136  {
137  itype = 1;
138  }
139 
140  if (signz < 0)
141  {
142  segment_z_bin = itype; // 0 = itype 0 +z, 1 = itype 1 +z, 2 = itupe 1 -z, 3 = itype 1 -z
143  }
144  else
145  {
146  segment_z_bin = itype + 2;
147  }
148 
149  // 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;
150  // std::cout << "radius " << m_SensorRadius << " offsetphi " << m_OffsetPhi << " rad dphi_ " << m_dPhi << " rad segment_phi_bin " << segment_phi_bin << " phi " << phi << std::endl;
151 }
152 
153 void CylinderGeomIntt::find_strip_center(const Surface& surface, ActsGeometry* tGeometry, const int segment_z_bin, const int segment_phi_bin, const int strip_column, const int strip_index, double location[])
154 {
155  // Ladder
156  find_segment_center(surface, tGeometry, location);
157  CLHEP::Hep3Vector ladder(location[0], location[1], location[2]);
158 
159  // Strip
160  const int itype = segment_z_bin % 2;
161  const double strip_z = m_StripZ[itype];
162  const int nstrips_z_sensor = m_NStripsZSensor[itype];
163 
164  const double strip_localpos_z = strip_z * (strip_column % nstrips_z_sensor) - strip_z / 2. * nstrips_z_sensor + strip_z / 2.;
165  // distance from bottom of sensor = m_StripY*strip_index +m_StripY/2.0, then subtract m_NStripsPhiCell * m_StripY / 2.0
166  const double strip_localpos_y = m_StripY * strip_index + m_StripY / 2. - m_NStripsPhiCell * m_StripY / 2.0;
167 
168  CLHEP::Hep3Vector strip_localpos(m_StripXOffset, strip_localpos_y, strip_localpos_z);
169 
170  // Strip rotation
171  const double phi = m_OffsetPhi + m_dPhi * segment_phi_bin;
172  const double rotate = phi + m_OffsetRot;
173 
174  CLHEP::HepRotation rot;
175  rot.rotateZ(rotate);
176  strip_localpos = rot * strip_localpos;
177  strip_localpos += ladder;
178 
179  location[0] = strip_localpos.x();
180  location[1] = strip_localpos.y();
181  location[2] = strip_localpos.z();
182 }
183 
184 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)
185 {
186  // Given the location in y and z in sensor local coordinates, find the strip y and z index values
187 
188  // find the sensor type (inner or outer) from the segment_z_bin (location of sensor on ladder)
189  const int itype = segment_z_bin % 2;
190  if (itype != 0 && itype != 1)
191  {
192  std::cout << "Problem: itype = " << itype << std::endl;
193  return;
194  }
195 
196  // expect cm
197  double zpos = zin;
198  double ypos = yin;
199 
200  const double strip_z = m_StripZ[itype];
201  const int nstrips_z_sensor = m_NStripsZSensor[itype];
202  const int nstrips_y_sensor = m_NStripsPhiCell;
203 
204  // get the strip z index
205  double zup = (double) nstrips_z_sensor * strip_z / 2.0 + zpos;
206  strip_z_index = (int) (zup / strip_z);
207 
208  // get the strip y index
209  double yup = (double) nstrips_y_sensor * m_StripY / 2.0 + ypos;
210  strip_y_index = (int) (yup / m_StripY);
211 
212  /*
213  std::cout << "segment_z_bin " << segment_z_bin << " ypos " << ypos << " zpos " << zpos << " zup " << zup << " yup " << yup << std::endl;
214  std::cout << " -- itype " << itype << " strip_y " << m_StripY << " strip_z " << strip_z << " nstrips_z_sensor " << nstrips_z_sensor
215  << " nstrips_y_sensor " << nstrips_y_sensor << std::endl;
216  std::cout << " -- strip_z_index " << strip_z_index << " strip_y_index " << strip_y_index << std::endl;
217  */
218 }
219 
220 // this name is a really bad idea whcih ticks off clang-tidy (justifiably) but it seems intentional
221 // NOLINTNEXTLINE(bugprone-virtual-near-miss)
222 void CylinderGeomIntt::find_strip_center_localcoords(const int segment_z_bin, const int strip_y_index, const int strip_z_index, double location[])
223 {
224  // find the sensor type (inner or outer) from the segment_z_bin (location of sensor on ladder)
225  const int itype = segment_z_bin % 2;
226  if (itype != 0 && itype != 1)
227  {
228  std::cout << "Problem: itype = " << itype << std::endl;
229  return;
230  }
231 
232  const double strip_z = m_StripZ[itype];
233  const int nstrips_z_sensor = m_NStripsZSensor[itype];
234  const int nstrips_y_sensor = m_NStripsPhiCell;
235 
236  // center of strip in y
237  double ypos = (double) strip_y_index * m_StripY + m_StripY / 2.0 - (double) nstrips_y_sensor * m_StripY / 2.0;
238 
239  // center of strip in z
240  double zpos = (double) strip_z_index * strip_z + strip_z / 2.0 - (double) nstrips_z_sensor * strip_z / 2.0;
241 
242  location[0] = 0.0;
243  location[1] = ypos;
244  location[2] = zpos;
245 }