Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHActsVertexPropagator.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHActsVertexPropagator.cc
2 
4 
7 #include <phool/PHDataNode.h>
8 #include <phool/PHNode.h>
9 #include <phool/PHNodeIterator.h>
10 #include <phool/PHObject.h>
11 #include <phool/PHTimer.h>
12 #include <phool/getClass.h>
13 #include <phool/phool.h>
14 
17 
20 
24 
26  : SubsysReco(name)
27  , m_trajectories(nullptr)
28 {
29 }
30 
32 {
34 }
35 
37 {
38  int returnval = getNodes(topNode);
39  return returnval;
40 }
42 {
43  std::vector<unsigned int> deletedKeys;
44  for (const auto& [trackKey, trajectory] : *m_trajectories)
45  {
46  auto svtxTrack = m_trackMap->get(trackKey);
47  if (!svtxTrack)
48  {
51  deletedKeys.push_back(trackKey);
52  continue;
53  }
54 
55  if (Verbosity() > 2)
56  {
57  svtxTrack->identify();
58  }
59 
60  const auto& trackTips = trajectory.tips();
61 
62  if (trackTips.size() > 1 and Verbosity() > 0)
63  {
64  std::cout << PHWHERE
65  << "More than 1 track tip per track. Should never happen..."
66  << std::endl;
67  }
68 
69  for (const auto& trackTip : trackTips)
70  {
71  const auto& boundParams = trajectory.trackParameters(trackTip);
72 
73  auto result = propagateTrack(boundParams, svtxTrack->get_vertex_id());
74  if (result.ok())
75  {
76  updateSvtxTrack(svtxTrack, result.value().second);
77  }
78  else
79  {
80  if (Verbosity() > 1)
81  {
82  svtxTrack->identify();
83  }
84  }
85  }
86  }
87 
88  setVtxChi2();
89  if (m_vertexMap->size() == 0 && Verbosity() > 2)
90  {
91  std::cout << "Propagated tracks to PerigeeSurface at (0,0,0) as no track vertices were found" << std::endl;
92  }
94  for (auto& key : deletedKeys)
95  {
96  m_trajectories->erase(key);
97  }
98 
100 }
101 
103 {
104  for (const auto& [vtxid, vtx] : *m_vertexMap)
105  {
106  float xvtx = vtx->get_x();
107  float yvtx = vtx->get_y();
108  float zvtx = vtx->get_z();
109  float xchisqsum = 0;
110  float ychisqsum = 0;
111  float zchisqsum = 0;
112 
113  for (auto trackiter = vtx->begin_tracks(); trackiter != vtx->end_tracks();
114  ++trackiter)
115  {
116  SvtxTrack* track = m_trackMap->get(*trackiter);
117  if (!track)
118  {
119  continue;
120  }
121 
122  float trkx = track->get_x();
123  float trky = track->get_y();
124  float trkz = track->get_z();
125  float trkcovx = track->get_error(0, 0);
126  float trkcovy = track->get_error(1, 1);
127  float trkcovz = track->get_error(2, 2);
128 
129  xchisqsum += pow(trkx - xvtx, 2) / trkcovx;
130  ychisqsum += pow(trky - yvtx, 2) / trkcovy;
131  zchisqsum += pow(trkz - zvtx, 2) / trkcovz;
132  }
133 
135  vtx->set_chisq(xchisqsum + ychisqsum + zchisqsum);
138  vtx->set_ndof(vtx->size_tracks() * 3 - 3);
139  }
140 }
141 
143  const Acts::BoundTrackParameters& params)
144 {
145  auto position = params.position(m_tGeometry->geometry().getGeoContext());
146 
147  if (Verbosity() > 2)
148  {
149  std::cout << "Updating position track parameters from " << track->get_x()
150  << ", " << track->get_y() << ", " << track->get_z() << " to "
151  << position.transpose() / 10.
152  << std::endl;
153  }
154 
158 
159  track->set_px(params.momentum().x());
160  track->set_py(params.momentum().y());
161  track->set_pz(params.momentum().z());
162 
163  ActsTransformations rotater;
164  rotater.setVerbosity(Verbosity());
165  if (params.covariance())
166  {
167  auto rotatedCov = rotater.rotateActsCovToSvtxTrack(params);
168 
170  for (int i = 0; i < 3; i++)
171  {
172  for (int j = 0; j < 3; j++)
173  {
174  track->set_error(i, j, rotatedCov(i, j));
175  }
176  }
177  }
178 }
179 
182  const Acts::BoundTrackParameters& params,
183  const unsigned int vtxid)
184 {
186  auto actsVertex = getVertex(vtxid);
187  auto perigee = Acts::Surface::makeShared<Acts::PerigeeSurface>(actsVertex);
188 
189  ActsPropagator propagator(m_tGeometry);
190  propagator.verbosity(Verbosity());
191  propagator.setOverstepLimit(1 * Acts::UnitConstants::cm);
192  if (m_fieldMap.find(".root") == std::string::npos)
193  {
194  propagator.constField();
195  propagator.setConstFieldValue(std::stod(m_fieldMap));
196  }
197 
198  return propagator.propagateTrack(params, perigee);
199 }
200 
202 {
203  auto svtxVertex = m_vertexMap->get(vtxid);
205  if (svtxVertex)
206  {
207  return Acts::Vector3(svtxVertex->get_x() * Acts::UnitConstants::cm,
208  svtxVertex->get_y() * Acts::UnitConstants::cm,
209  svtxVertex->get_z() * Acts::UnitConstants::cm);
210  }
211 
212  return Acts::Vector3::Zero();
213 }
214 
216 {
218 }
219 
221 {
222  m_tGeometry = findNode::getClass<ActsGeometry>(topNode, "ActsGeometry");
223  if (!m_tGeometry)
224  {
225  std::cout << PHWHERE << "Acts tracking geometry not on node tree, exiting."
226  << std::endl;
228  }
229 
230  m_trajectories = findNode::getClass<std::map<const unsigned int, Trajectory>>(topNode, "ActsTrajectories");
231 
232  if (!m_trajectories)
233  {
234  std::cout << PHWHERE << "No acts trajectories on node tree, exiting. "
235  << std::endl;
237  }
238 
239  m_vertexMap = findNode::getClass<SvtxVertexMap>(topNode, "SvtxVertexMap");
240  if (!m_vertexMap)
241  {
242  std::cout << PHWHERE << "No svtx vertex map, exiting." << std::endl;
244  }
245 
246  m_trackMap = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
247  if (!m_trackMap)
248  {
249  std::cout << PHWHERE << "No svtx track map, exiting. " << std::endl;
251  }
252 
254 }