ECCE @ EIC 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 
5 
6 #include <algorithm>
7 #include <cmath>
8 
9 using namespace std;
10 
12  : m_Layer(-1)
13  , m_NStripsPhiCell(-1)
14  , m_StripX(NAN)
15  , m_StripY(NAN)
16  , m_SensorRadius(NAN)
17  , m_StripXOffset(NAN)
18  , m_OffsetPhi(NAN)
19  , m_OffsetRot(NAN)
20  , m_dPhi(NAN)
21 {
22  fill_n(m_StripZ, sizeof(m_StripZ) / sizeof(double), NAN);
23  fill_n(m_LadderZ, sizeof(m_LadderZ) / sizeof(double), NAN);
24  fill_n(m_NStripsZSensor, sizeof(m_NStripsZSensor), -1);
25  return;
26 }
27 
28 void CylinderGeomIntt::identify(std::ostream &os) const
29 {
30  os << "CylinderGeomIntt Object" << endl;
31  os << "layer: " << get_layer() << endl;
32  os << "Radius: " << get_radius() << endl;
33 }
34 
36 {
37  return true;
38 }
39 
40 TVector3 CylinderGeomIntt::get_local_from_world_coords(const int segment_z_bin, const int segment_phi_bin, TVector3 world)
41 {
42  TVector3 local(0,0,0);
43 
44  double center[3] = {0,0,0};
45  find_segment_center(segment_z_bin, segment_phi_bin, center);
46  TVector3 cent(center[0], center[1], center[2]);
47 
48  // subtract center location of sensor from world coords
49  local = world - cent;
50 
51  // rotate the residual into local coords
52  const double phi = m_OffsetPhi + m_dPhi * segment_phi_bin;
53  const double rotate = phi + m_OffsetRot;
54  local.RotateZ(-rotate);
55 
56  return local;
57 }
58 
59 void CylinderGeomIntt::find_segment_center(const int segment_z_bin, const int segment_phi_bin, double location[])
60 {
61  const double signz = (segment_z_bin > 1) ? 1. : -1.;
62  const int itype = segment_z_bin % 2;
63 
64  // Ladder
65  const double phi = m_OffsetPhi + m_dPhi * segment_phi_bin;
66  location[0] = m_SensorRadius * cos(phi);
67  location[1] = m_SensorRadius * sin(phi);
68  location[2] = signz * m_LadderZ[itype];
69 
70  //cout << "radius " << m_SensorRadius << " offsetphi " << m_OffsetPhi << " rad dphi_ " << m_dPhi << " rad segment_phi_bin " << segment_phi_bin << " phi " << phi << " rad " << endl;
71 }
72 
73 void CylinderGeomIntt::find_indices_from_world_location(int &segment_z_bin, int &segment_phi_bin, double location[])
74 {
75  double signz = (location[2] > 0)? 1. : -1;
76  double phi = atan2(location[1], location[0]);
77  if(phi < 0) phi += 2.0*M_PI;
78  double segment_phi_bin_tmp = (phi - m_OffsetPhi)/m_dPhi;
79  segment_phi_bin = round(segment_phi_bin_tmp);
80 
81  double z_tmp = location[2] / signz;
82 
83  // decide if this is a type A (0) or type B (1) sensor
84  int itype;
85  if( fabs((z_tmp / m_LadderZ[0])) < 1.0)
86  itype = 0;
87  else
88  itype = 1;
89 
90  if(signz <0)
91  segment_z_bin = itype; // 0 = itype 0 +z, 1 = itype 1 +z, 2 = itupe 0 -z, 3 = itype 1 -z
92  else
93  segment_z_bin = itype + 2;
94 }
95 
96 void CylinderGeomIntt::find_indices_from_segment_center(int &segment_z_bin, int &segment_phi_bin, double location[])
97 {
98  double signz = (location[2] > 0)? 1. : -1;
99  double phi = atan2(location[1], location[0]);
100  if(phi < 0) phi += 2.0*M_PI;
101  double segment_phi_bin_tmp = (phi - m_OffsetPhi)/m_dPhi;
102  segment_phi_bin = lround(segment_phi_bin_tmp);
103 
104  double z_tmp = location[2] / signz;
105 
106  // decide if this is a type A (0) or type B (1) sensor
107  int itype;
108  if( fabs((1.0 - z_tmp / m_LadderZ[0])) < 0.01)
109  itype = 0;
110  else
111  itype = 1;
112 
113  if(signz <0)
114  segment_z_bin = itype; // 0 = itype 0 +z, 1 = itype 1 +z, 2 = itupe 1 -z, 3 = itype 1 -z
115  else
116  segment_z_bin = itype + 2;
117 
118  //cout << " world coords: " << location[0] << " " << location[1] << " " << location[2] << " signz " << signz << " itype " << itype << " z_tmp " << z_tmp << " m_LadderZ " << m_LadderZ[itype] << endl;
119  //cout << "radius " << m_SensorRadius << " offsetphi " << m_OffsetPhi << " rad dphi_ " << m_dPhi << " rad segment_phi_bin " << segment_phi_bin << " phi " << phi << endl;
120 }
121 
122 void CylinderGeomIntt::find_strip_center(const int segment_z_bin, const int segment_phi_bin, const int strip_column, const int strip_index, double location[])
123 {
124  // Ladder
125  find_segment_center(segment_z_bin, segment_phi_bin, location);
126  CLHEP::Hep3Vector ladder(location[0], location[1], location[2]);
127 
128  // Strip
129  const int itype = segment_z_bin % 2;
130  const double strip_z = m_StripZ[itype];
131  const int nstrips_z_sensor = m_NStripsZSensor[itype];
132 
133  const double strip_localpos_z = strip_z * (strip_column % nstrips_z_sensor) - strip_z / 2. * nstrips_z_sensor + strip_z / 2.;
134  // distance from bottom of sensor = m_StripY*strip_index +m_StripY/2.0, then subtract m_NStripsPhiCell * m_StripY / 2.0
135  const double strip_localpos_y = m_StripY * strip_index + m_StripY / 2. - m_NStripsPhiCell * m_StripY / 2.0;
136 
137  CLHEP::Hep3Vector strip_localpos(m_StripXOffset, strip_localpos_y, strip_localpos_z);
138 
139  // Strip rotation
140  const double phi = m_OffsetPhi + m_dPhi * segment_phi_bin;
141  const double rotate = phi + m_OffsetRot;
142 
143  CLHEP::HepRotation rot;
144  rot.rotateZ(rotate);
145  strip_localpos = rot * strip_localpos;
146  strip_localpos += ladder;
147 
148  location[0] = strip_localpos.x();
149  location[1] = strip_localpos.y();
150  location[2] = strip_localpos.z();
151 
152 }
153 
154 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)
155 {
156  // Given the location in y and z in sensor local coordinates, find the strip y and z index values
157 
158  // find the sensor type (inner or outer) from the segment_z_bin (location of sensor on ladder)
159  const int itype = segment_z_bin % 2;
160  if (itype != 0 && itype != 1)
161  {
162  cout << "Problem: itype = " << itype << endl;
163  return;
164  }
165 
166  // expect cm
167  double zpos = zin;
168  double ypos = yin;
169 
170  const double strip_z = m_StripZ[itype];
171  const int nstrips_z_sensor = m_NStripsZSensor[itype];
172  const int nstrips_y_sensor = m_NStripsPhiCell;
173 
174  // get the strip z index
175  double zup = (double) nstrips_z_sensor * strip_z / 2.0 + zpos;
176  strip_z_index = (int) (zup / strip_z);
177 
178  // get the strip y index
179  double yup = (double) nstrips_y_sensor * m_StripY / 2.0 + ypos;
180  strip_y_index = (int) (yup / m_StripY);
181 
182  /*
183  cout << "segment_z_bin " << segment_z_bin << " ypos " << ypos << " zpos " << zpos << " zup " << zup << " yup " << yup << endl;
184  cout << " -- itype " << itype << " strip_y " << m_StripY << " strip_z " << strip_z << " nstrips_z_sensor " << nstrips_z_sensor
185  << " nstrips_y_sensor " << nstrips_y_sensor << endl;
186  cout << " -- strip_z_index " << strip_z_index << " strip_y_index " << strip_y_index << endl;
187  */
188 }
189 
190 void CylinderGeomIntt::find_strip_center_localcoords(const int segment_z_bin, const int strip_y_index, const int strip_z_index, double location[])
191 {
192  // find the sensor type (inner or outer) from the segment_z_bin (location of sensor on ladder)
193  const int itype = segment_z_bin % 2;
194  if (itype != 0 && itype != 1)
195  {
196  cout << "Problem: itype = " << itype << endl;
197  return;
198  }
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  // center of strip in y
205  double ypos = (double) strip_y_index * m_StripY + m_StripY / 2.0 - (double) nstrips_y_sensor * m_StripY / 2.0;
206 
207  // center of strip in z
208  double zpos = (double) strip_z_index * strip_z + strip_z / 2.0 - (double) nstrips_z_sensor * strip_z / 2.0;
209 
210  location[0] = 0.0;
211  location[1] = ypos;
212  location[2] = zpos;
213 }