Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHActsGSF.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHActsGSF.cc
1 #include "PHActsGSF.h"
2 #include "MakeSourceLinks.h"
3 
6 #include <phool/PHDataNode.h>
7 #include <phool/PHNode.h>
8 #include <phool/PHNodeIterator.h>
9 #include <phool/PHObject.h>
10 #include <phool/PHTimer.h>
11 #include <phool/getClass.h>
12 #include <phool/phool.h>
13 
14 #include <trackbase/ActsGeometry.h>
16 #include <trackbase/TpcDefs.h>
17 #include <trackbase/TrkrCluster.h>
19 #include <trackbase/TrkrDefs.h>
20 
25 
28 
39 
40 #include <TDatabasePDG.h>
41 
42 //____________________________________________________________________________..
44  : SubsysReco(name)
45 {
46 }
47 
48 //____________________________________________________________________________..
50 {
51 }
52 
53 //____________________________________________________________________________..
55 {
56  if (Verbosity() > 1)
57  {
58  std::cout << "PHActsGSF::InitRun begin" << std::endl;
59  }
60 
61  if (getNodes(topNode) != Fun4AllReturnCodes::EVENT_OK)
62  {
64  }
65 
71  bha,
72  12, 1e-4, Acts::MixtureReductionMethod::eMaxWeight, false, false);
73 
75 }
76 
77 //____________________________________________________________________________..
79 {
81  if (Verbosity() > 4)
82  {
84  }
85 
86  auto logger = Acts::getDefaultLogger("PHActsGSF", logLevel);
87 
88  for (const auto& [key, track] : *m_trackMap)
89  {
90  auto pSurface = makePerigee(track);
91  if(!pSurface)
92  {
94  continue;
95  }
96  const auto seed = makeSeed(track, pSurface);
97 
99  TrackSeed* tpcseed = track->get_tpc_seed();
100  TrackSeed* silseed = track->get_silicon_seed();
101 
103  if (!silseed or !tpcseed)
104  {
105  continue;
106  }
107 
108  auto crossing = silseed->get_crossing();
109  if (crossing == SHRT_MAX)
110  {
111  continue;
112  }
113 
114  /*
115  auto sourceLinks = getSourceLinks(tpcseed, measurements, crossing);
116  auto silSourceLinks = getSourceLinks(silseed, measurements, crossing);
117  */
118 
119  // loop over modifiedTransformSet and replace transient elements modified for the previous track with the default transforms
120  MakeSourceLinks makeSourceLinks;
121  makeSourceLinks.setVerbosity(Verbosity());
122  makeSourceLinks.set_pp_mode(m_pp_mode);
123 
124  makeSourceLinks.resetTransientTransformMap(
127  m_tGeometry);
128 
129  auto sourceLinks = makeSourceLinks.getSourceLinks(
130  tpcseed,
131  measurements,
133  m_tGeometry,
136  crossing);
137  auto silSourceLinks = makeSourceLinks.getSourceLinks(
138  silseed,
139  measurements,
141  m_tGeometry,
144  crossing);
145  // copy transient map for this track into transient geoContext
147 
148 
149  for (auto& siSL : silSourceLinks)
150  {
151  sourceLinks.push_back(siSL);
152  }
153 
154  auto calibptr = std::make_unique<Calibrator>();
155  CalibratorAdapter calibrator(*calibptr, measurements);
156  auto magcontext = m_tGeometry->geometry().magFieldContext;
157  auto calcontext = m_tGeometry->geometry().calibContext;
158 
159  auto ppoptions = Acts::PropagatorPlainOptions();
160 
163  magcontext,
164  calcontext,
165  &(*pSurface),
166  ppoptions};
167  if (Verbosity() > 2)
168  {
169  std::cout << "calling gsf with position "
170  << seed.position(m_transient_geocontext).transpose()
171  << " and momentum " << seed.momentum().transpose()
172  << std::endl;
173  }
174  auto trackContainer = std::make_shared<Acts::VectorTrackContainer>();
175  auto trackStateContainer = std::make_shared<Acts::VectorMultiTrajectory>();
176  ActsTrackFittingAlgorithm::TrackContainer tracks(trackContainer, trackStateContainer);
177  auto result = fitTrack(sourceLinks, seed, options, calibrator, tracks);
178 
179  if (result.ok())
180  {
181  updateTrack(result, track, tracks);
182  }
183  }
184 
186 }
187 
188 std::shared_ptr<Acts::PerigeeSurface> PHActsGSF::makePerigee(SvtxTrack* track) const
189 {
191  if(!vertex)
192  {
193  return nullptr;
194  }
195 
196  Acts::Vector3 vertexpos(vertex->get_x() * Acts::UnitConstants::cm,
197  vertex->get_y() * Acts::UnitConstants::cm,
198  vertex->get_z() * Acts::UnitConstants::cm);
199 
200  return Acts::Surface::makeShared<Acts::PerigeeSurface>(
201  vertexpos);
202 }
203 
205  std::shared_ptr<Acts::PerigeeSurface> psurf) const
206 {
207  Acts::Vector4 fourpos(track->get_x() * Acts::UnitConstants::cm,
208  track->get_y() * Acts::UnitConstants::cm,
209  track->get_z() * Acts::UnitConstants::cm,
211 
212  int charge = track->get_charge();
213  Acts::Vector3 momentum(track->get_px(),
214  track->get_py(),
215  track->get_pz());
216 
217  ActsTransformations transformer;
218  auto cov = transformer.rotateSvtxTrackCovToActs(track);
219 
222  fourpos,
223  momentum,
224  charge / momentum.norm(),
225  cov,
228  .value();
229 }
230 
232  const std::vector<Acts::SourceLink>& sourceLinks,
235  const CalibratorAdapter& calibrator,
237 {
238  return (*m_fitCfg.fit)(sourceLinks, seed, options, calibrator, tracks);
239 }
240 
243 {
244  std::vector<Acts::MultiTrajectoryTraits::IndexType> trackTips;
245  trackTips.reserve(1);
246  auto& outtrack = result.value();
247  trackTips.emplace_back(outtrack.tipIndex());
249 
250  indexedParams.emplace(std::pair{outtrack.tipIndex(),
252  outtrack.parameters(), outtrack.covariance(), Acts::ParticleHypothesis::electron()}});
253 
254  updateSvtxTrack(trackTips, indexedParams, tracks, track);
255 }
256 
257 void PHActsGSF::updateSvtxTrack(std::vector<Acts::MultiTrajectoryTraits::IndexType>& tips,
260  SvtxTrack* track)
261 {
262  const auto& mj = tracks.trackStateContainer();
263  const auto& tracktip = tips.front();
264  const auto& params = paramsMap.find(tracktip)->second;
265  const auto trajState =
267 
268  if (Verbosity() > 1)
269  {
270  std::cout << "Old track parameters: " << std::endl
271  << " (" << track->get_x()
272  << ", " << track->get_y() << ", " << track->get_z()
273  << ")" << std::endl
274  << " (" << track->get_px() << ", " << track->get_py()
275  << ", " << track->get_pz() << ")" << std::endl;
276  std::cout << "New GSF track parameters: " << std::endl
277  << " " << params.position(m_transient_geocontext).transpose()
278  << std::endl
279  << " " << params.momentum().transpose()
280  << std::endl;
281  }
282 
284  track->clear_states();
285 
286  // create a state at pathlength = 0.0
287  // This state holds the track parameters, which will be updated below
288  float pathlength = 0.0;
289  SvtxTrackState_v1 out(pathlength);
290  out.set_x(0.0);
291  out.set_y(0.0);
292  out.set_z(0.0);
293  track->insert_state(&out);
294 
295  track->set_x(params.position(m_transient_geocontext)(0) / Acts::UnitConstants::cm);
296  track->set_y(params.position(m_transient_geocontext)(1) / Acts::UnitConstants::cm);
297  track->set_z(params.position(m_transient_geocontext)(2) / Acts::UnitConstants::cm);
298 
299  track->set_px(params.momentum()(0));
300  track->set_py(params.momentum()(1));
301  track->set_pz(params.momentum()(2));
302  track->set_charge(params.charge());
303  track->set_chisq(trajState.chi2Sum);
304  track->set_ndf(trajState.NDF);
305 
306  ActsTransformations transformer;
307  transformer.setVerbosity(Verbosity());
308 
309  if (params.covariance())
310  {
311  auto rotatedCov = transformer.rotateActsCovToSvtxTrack(params);
312  for (int i = 0; i < 6; i++)
313  {
314  for (int j = 0; j < 6; j++)
315  {
316  track->set_error(i, j, rotatedCov(i, j));
317  }
318  }
319  }
320 
321  transformer.fillSvtxTrackStates(mj, tracktip, track, m_transient_geocontext);
322 }
323 
324 //____________________________________________________________________________..
326 {
328 }
329 
331 {
332  m_trackMap = findNode::getClass<SvtxTrackMap>(topNode, m_trackMapName);
333  if (!m_trackMap)
334  {
335  std::cout << PHWHERE << " The input track map is not available. Exiting PHActsGSF" << std::endl;
337  }
338 
339  m_clusterContainer = findNode::getClass<TrkrClusterContainer>(topNode, "TRKR_CLUSTER");
340  if (!m_clusterContainer)
341  {
342  std::cout << PHWHERE << "The input cluster container is not available. Exiting PHActsGSF" << std::endl;
344  }
345 
346  m_tGeometry = findNode::getClass<ActsGeometry>(topNode, "ActsGeometry");
347  if (!m_tGeometry)
348  {
349  std::cout << PHWHERE << "The input Acts tracking geometry is not available. Exiting PHActsGSF" << std::endl;
351  }
352 
353  // tpc distortion corrections
354  m_dccStatic = findNode::getClass<TpcDistortionCorrectionContainer>(topNode, "TpcDistortionCorrectionContainerStatic");
355  if (m_dccStatic)
356  {
357  std::cout << PHWHERE << " found static TPC distortion correction container" << std::endl;
358  }
359 
360  m_dccAverage = findNode::getClass<TpcDistortionCorrectionContainer>(topNode, "TpcDistortionCorrectionContainerAverage");
361  if (m_dccAverage)
362  {
363  std::cout << PHWHERE << " found average TPC distortion correction container" << std::endl;
364  }
365 
366  m_dccFluctuation = findNode::getClass<TpcDistortionCorrectionContainer>(topNode, "TpcDistortionCorrectionContainerFluctuation");
367  if (m_dccFluctuation)
368  {
369  std::cout << PHWHERE << " found fluctuation TPC distortion correction container" << std::endl;
370  }
371 
372  m_vertexMap = findNode::getClass<SvtxVertexMap>(topNode, "SvtxVertexMap");
373  if (!m_vertexMap)
374  {
375  std::cout << PHWHERE << "Vertex map unavailable, exiting PHActsGSF" << std::endl;
377  }
378 
379  m_alignmentTransformationMapTransient = findNode::getClass<alignmentTransformationContainer>(topNode, "alignmentTransformationContainerTransient");
381  {
382  std::cout << PHWHERE << "alignmentTransformationContainerTransient not on node tree. Bailing"
383  << std::endl;
385  }
386 
388 }