Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ActsGeometry.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ActsGeometry.cc
1 #include "ActsGeometry.h"
2 #include "TrkrCluster.h"
3 #include "TpcDefs.h"
6 
7 namespace
8 {
10  template<class T> inline constexpr T square(const T& x) {return x*x;}
11 
13  template<class T> T radius(const T& x, const T& y)
14  { return std::sqrt(square(x) + square(y));}
15 }
16 
17 Eigen::Matrix<float,3,1> ActsGeometry::getGlobalPositionF(
18  TrkrDefs:: cluskey key,
19  TrkrCluster* cluster)
20 {
21  Acts::Vector3 doublePos = getGlobalPosition(key, cluster);
22  return Eigen::Matrix<float,3,1>(doublePos(0), doublePos(1), doublePos(2));
23 }
24 
25 
27 {
28  Acts::Vector3 glob;
29 
30  const auto trkrid = TrkrDefs::getTrkrId(key);
31  if(trkrid == TrkrDefs::tpcId)
32  {
33  return getGlobalPositionTpc(key, cluster);
34  }
35 
37 
38  auto surface = maps().getSurface(key, cluster);
39 
40  if(!surface)
41  {
42 
43  std::cerr << "Couldn't identify cluster surface. Returning NAN"
44  << std::endl;
45  glob(0) = NAN;
46  glob(1) = NAN;
47  glob(2) = NAN;
48  return glob;
49  }
50 
51  Acts::Vector2 local(cluster->getLocalX(), cluster->getLocalY());
52  Acts::Vector3 global;
53  global = surface->localToGlobal(geometry().getGeoContext(),
55  Acts::Vector3(1,1,1));
56  global /= Acts::UnitConstants::cm;
57 
58 
59  return global;
60 }
61 
63 {
64  Acts::Vector3 glob;
65 
66  // This method is for the TPC only
67  const auto trkrid = TrkrDefs::getTrkrId(key);
68  if(trkrid != TrkrDefs::tpcId)
69  {
70  std::cout << "ActsGeometry::getGlobalPositionTpc - this is the wrong global transform for silicon or MM's clusters! Returning zero" << std::endl;
71  return glob;
72  }
73 
74  auto surface = maps().getSurface(key, cluster);
75 
76  if(!surface)
77  {
78 
79  std::cerr << "Couldn't identify cluster surface. Returning NAN"
80  << std::endl;
81  glob(0) = NAN;
82  glob(1) = NAN;
83  glob(2) = NAN;
84  return glob;
85  }
86 
87  double surfaceZCenter = 52.89; // this is where G4 thinks the surface center is in cm
88  double zdriftlength = cluster->getLocalY() * _drift_velocity; // cm
89  double zloc = surfaceZCenter - zdriftlength; // local z relative to surface center (for north side):
90  unsigned int side = TpcDefs::getSide(key);
91  if(side == 0) zloc = -zloc;
92 
93  Acts::Vector2 local(cluster->getLocalX(), zloc);
94  glob = surface->localToGlobal(geometry().getGeoContext(),
96  Acts::Vector3(1,1,1));
98 
99  return glob;
100 }
101 
102 
105  Acts::Vector3 world,
107 {
108  unsigned int layer = TrkrDefs::getLayer(hitsetkey);
109  auto mapIter = maps().m_tpcSurfaceMap.find(layer);
110 
111  if(mapIter == maps().m_tpcSurfaceMap.end())
112  {
113  std::cout << "Error: hitsetkey not found in ActsGeometry::get_tpc_surface_from_coords, hitsetkey = "
114  << hitsetkey << std::endl;
115  return nullptr;
116  }
117 
118  double world_phi = atan2(world[1], world[0]);
119  double world_z = world[2];
120 
121  std::vector<Surface>& surf_vec = mapIter->second;
122  unsigned int surf_index = 999;
123 
124  // Predict which surface index this phi and z will correspond to
125  // assumes that the vector elements are ordered positive z, -pi to pi, then negative z, -pi to pi
126  double fraction = (world_phi + M_PI) / (2.0 * M_PI);
127  double rounded_nsurf = round( (double) (surf_vec.size()/2) * fraction - 0.5);
128  unsigned int nsurfm = (unsigned int) rounded_nsurf;
129 
130  if(world_z < 0)
131  { nsurfm += surf_vec.size()/2; }
132 
133  unsigned int nsurf = nsurfm % surf_vec.size();
134 
135  Surface this_surf = surf_vec[nsurf];
136 
137  auto vec3d = this_surf->center(geometry().getGeoContext());
138  std::vector<double> surf_center = {vec3d(0) / 10.0, vec3d(1) / 10.0, vec3d(2) / 10.0}; // convert from mm to cm
139  double surf_z = surf_center[2];
140  double surf_phi = atan2(surf_center[1], surf_center[0]);
141  double surfStepPhi = geometry().tpcSurfStepPhi;
142  double surfStepZ = geometry().tpcSurfStepZ;
143 
144  if( (world_phi > surf_phi - surfStepPhi / 2.0 && world_phi < surf_phi + surfStepPhi / 2.0 ) &&
145  (world_z > surf_z - surfStepZ / 2.0 && world_z < surf_z + surfStepZ / 2.0) )
146  {
147  surf_index = nsurf;
148  subsurfkey = nsurf;
149  }
150  else
151  {
152  return nullptr;
153  }
154 
155  return surf_vec[surf_index];
156 
157 }
158 
160 {
161 
162  Acts::Transform3 actsAffine;
163 
164  Eigen::AngleAxisd alpha(rot(0), Eigen::Vector3d::UnitX());
165  Eigen::AngleAxisd beta(rot(1), Eigen::Vector3d::UnitY());
166  Eigen::AngleAxisd gamma(rot(2), Eigen::Vector3d::UnitZ());
167  Eigen::Quaternion<double> q = gamma*beta*alpha;
168  actsAffine.linear() = q.matrix();
169 
170  Eigen::Vector3d translation(trans(0),trans(1),trans(2));
171  actsAffine.translation() = translation;
172 
173  return actsAffine;
174 }
175 
177 {
178  Acts::Vector2 local;
179 
180  const auto trkrid = TrkrDefs::getTrkrId(key);
181  if(trkrid == TrkrDefs::tpcId)
182  {
183  double surfaceZCenter = 52.89; // this is where G4 thinks the surface center is in cm
184  double zdriftlength = cluster->getLocalY() * _drift_velocity; // cm
185  double zloc = surfaceZCenter - zdriftlength; // local z relative to surface center (for north side):
186  unsigned int side = TpcDefs::getSide(key);
187  if(side == 0) zloc = -zloc;
188 
189  local(0) = cluster->getLocalX();
190  local(1) = zloc;
191  }
192  else
193  {
194  local(0) = cluster->getLocalX();
195  local(1) = cluster->getLocalY();
196  }
197 
198  return local;
199 }