Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MakeSourceLinks.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MakeSourceLinks.cc
1 #include "MakeSourceLinks.h"
2 
4 #include <trackbase/InttDefs.h>
5 #include <trackbase/MvtxDefs.h>
6 #include <trackbase/TpcDefs.h>
10 #include <trackbase/ActsGeometry.h>
12 
18 
21 
22 #include <phool/PHTimer.h>
23 #include <phool/phool.h>
24 
25 namespace
26 {
27  template <class T>
28  inline T square(const T& x)
29  {
30  return x * x;
31  }
32 
33 }
34 
35  //___________________________________________________________________________________
38  TrkrClusterContainer* clusterContainer,
40  alignmentTransformationContainer* transformMapTransient,
41  std::set< Acts::GeometryIdentifier> transient_id_set,
42  short int crossing)
43 {
44  if(m_verbosity > 1) { std::cout << "Entering MakeSourceLinks::getSourceLinks " << std::endl; }
45 
46  SourceLinkVec sourcelinks;
47 
48  if (m_pp_mode && crossing == SHRT_MAX)
49  {
50  // Need to skip this in the pp case, for AuAu it should not happen
51  return sourcelinks;
52  }
53 
54  PHTimer SLTrackTimer("SLTrackTimer");
55  SLTrackTimer.stop();
56  SLTrackTimer.restart();
57 
58  // loop over all clusters
59  std::vector<TrkrDefs::cluskey> cluster_vec;
60 
61  for (auto clusIter = track->begin_cluster_keys();
62  clusIter != track->end_cluster_keys();
63  ++clusIter)
64  {
65  auto key = *clusIter;
66  auto cluster = clusterContainer->findCluster(key);
67  if (!cluster)
68  {
69  if (m_verbosity > 0)
70  std::cout << "MakeSourceLinks: Failed to get cluster with key " << key << " for track seed" << std::endl;
71  else
72  std::cout << "MakeSourceLinks: Key " << key << " for track seed " << std::endl;
73  continue;
74  }
75 
77  auto surf = tGeometry->maps().getSurface(key, cluster);
78  if (!surf)
79  {
80  continue;
81  }
82 
83  const unsigned int trkrid = TrkrDefs::getTrkrId(key);
84  const unsigned int side = TpcDefs::getSide(key);
85 
86  if(m_verbosity > 1) { std::cout << " Cluster key " << key << " trkrid " << trkrid << " crossing " << crossing << std::endl; }
87 
88  // For the TPC, cluster z has to be corrected for the crossing z offset, distortion, and TOF z offset
89  // we do this by modifying the fake surface transform, to move the cluster to the corrected position
90  if (trkrid == TrkrDefs::tpcId)
91  {
92  Acts::Vector3 global = tGeometry->getGlobalPosition(key, cluster);
93  Acts::Vector3 global_in = global;
94 
95  // make all corrections to global position of TPC cluster
96  float z = _clusterCrossingCorrection.correctZ(global[2], side, crossing);
97  global[2] = z;
98 
99  // apply distortion corrections
100  if (_dcc_static)
101  {
103  }
104  if (_dcc_average)
105  {
107  }
108  if (_dcc_fluctuation)
109  {
111  }
112 
113  // Make an afine transform that implements the correction as a translation
114  auto correction_translation = (global - global_in) * 10.0; // need mm
115  Acts::Vector3 correction_rotation(0,0,0); // null rotation
116  Acts::Transform3 tcorr = tGeometry->makeAffineTransform(correction_rotation, correction_translation);
117 
118  auto this_surf = tGeometry->maps().getSurface(key, cluster);
119  Acts::GeometryIdentifier id = this_surf->geometryId();
120 
121  // replace the the default alignment transform with the corrected one
122  auto ctxt = tGeometry->geometry().getGeoContext();
124  auto corrected_transform = tcorr * transformMap->getTransform(id);
125  transformMapTransient->replaceTransform(id, corrected_transform);
126  transient_id_set.insert(id);
127 
128  } // end TPC specific treatment
129 
130  // corrected TPC transforms are installed, capture the cluster key
131  cluster_vec.push_back(key);
132 
133  } // end loop over clusters here
134 
135  // loop over cluster_vec and make source links
136  for (unsigned int i = 0; i < cluster_vec.size(); ++i)
137  {
138  TrkrDefs::cluskey cluskey = cluster_vec[i];
139 
140  if (m_ignoreLayer.find(TrkrDefs::getLayer(cluskey)) != m_ignoreLayer.end())
141  {
142  if (m_verbosity > 3)
143  {
144  std::cout << PHWHERE << "skipping cluster in layer "
145  << (unsigned int) TrkrDefs::getLayer(cluskey) << std::endl;
146  }
147  continue;
148  }
149 
150  // get local coordinates (TPC time needs conversion to cm)
151  auto cluster = clusterContainer->findCluster(cluskey);
152  Acts::Vector2 localPos = tGeometry->getLocalCoords(cluskey, cluster);
153 
154  Surface surf = tGeometry->maps().getSurface(cluskey, cluster);
155 
157  loc[Acts::eBoundLoc0] = localPos(0) * Acts::UnitConstants::cm;
158  loc[Acts::eBoundLoc1] = localPos(1) * Acts::UnitConstants::cm;
159 
160  std::array<Acts::BoundIndices, 2> indices;
161  indices[0] = Acts::BoundIndices::eBoundLoc0;
162  indices[1] = Acts::BoundIndices::eBoundLoc1;
164 
165  // get errors
166  Acts::Vector3 global = tGeometry->getGlobalPosition(cluskey, cluster);
167  double clusRadius = sqrt(global[0] * global[0] + global[1] * global[1]);
168  auto para_errors = _ClusErrPara.get_clusterv5_modified_error(cluster, clusRadius, cluskey);
173 
174  ActsSourceLink::Index index = measurements.size();
175 
176  SourceLink sl(surf->geometryId(), index, cluskey);
177  Acts::SourceLink actsSL{sl};
178  Acts::Measurement<Acts::BoundIndices, 2> meas(actsSL, indices, loc, cov);
179  if (m_verbosity > 3)
180  {
181  std::cout << "source link " << sl.index() << ", loc : "
182  << loc.transpose() << std::endl
183  << ", cov : " << cov.transpose() << std::endl
184  << " geo id " << sl.geometryId() << std::endl;
185  std::cout << "Surface : " << std::endl;
186  surf.get()->toStream(tGeometry->geometry().getGeoContext(), std::cout);
187  std::cout << std::endl;
188  std::cout << "Corrected surface transform:" << std::endl;
189  std::cout << transformMapTransient->getTransform(surf->geometryId()).matrix() << std::endl;
190  std::cout << "Cluster error " << cluster->getRPhiError() << " , " << cluster->getZError() << std::endl;
191  std::cout << "For key " << cluskey << " with local pos " << std::endl
192  << localPos(0) << ", " << localPos(1)
193  << std::endl << std::endl;
194  }
195 
196  sourcelinks.push_back(actsSL);
197  measurements.push_back(meas);
198  }
199 
200  SLTrackTimer.stop();
201  auto SLTime = SLTrackTimer.get_accumulated_time();
202 
203  if (m_verbosity > 1)
204  std::cout << "PHActsTrkFitter Source Links generation time: "
205  << SLTime << std::endl;
206 
207  return sourcelinks;
208 }
209 
211  alignmentTransformationContainer* transformMapTransient,
212  std::set< Acts::GeometryIdentifier>& transient_id_set,
214 {
215  // loop over modifiedTransformSet and replace transient elements modified for the last track with the default transforms
216  for(auto it = transient_id_set.begin(); it != transient_id_set.end(); ++it)
217  {
219  auto ctxt = tGeometry->geometry().getGeoContext();
221  auto transform = transformMap->getTransform(id);
222  transformMapTransient->replaceTransform(id, transform);
223  }
224  transient_id_set.clear();
225  }
226