Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VectorMultiTrajectory.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VectorMultiTrajectory.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
14 
15 #include <iomanip>
16 #include <ostream>
17 #include <type_traits>
18 
19 #include <boost/histogram.hpp>
20 #include <boost/histogram/axis/category.hpp>
21 #include <boost/histogram/make_histogram.hpp>
22 
23 namespace Acts {
24 
25 auto VectorMultiTrajectory::addTrackState_impl(TrackStatePropMask mask,
26  IndexType iprevious)
27  -> IndexType {
28  using PropMask = TrackStatePropMask;
29 
30  m_index.emplace_back();
31  IndexData& p = m_index.back();
32  IndexType index = m_index.size() - 1;
33  m_previous.emplace_back(iprevious);
34  m_next.emplace_back(kInvalid);
35 
36  p.allocMask = mask;
37 
38  // always set, but can be null
39  m_referenceSurfaces.emplace_back(nullptr);
40 
41  assert(m_params.size() == m_cov.size());
42 
43  if (ACTS_CHECK_BIT(mask, PropMask::Predicted)) {
44  m_params.emplace_back();
45  m_cov.emplace_back();
46  p.ipredicted = m_params.size() - 1;
47  }
48 
49  if (ACTS_CHECK_BIT(mask, PropMask::Filtered)) {
50  m_params.emplace_back();
51  m_cov.emplace_back();
52  p.ifiltered = m_params.size() - 1;
53  }
54 
55  if (ACTS_CHECK_BIT(mask, PropMask::Smoothed)) {
56  m_params.emplace_back();
57  m_cov.emplace_back();
58  p.ismoothed = m_params.size() - 1;
59  }
60 
61  assert(m_params.size() == m_cov.size());
62 
64  m_jac.emplace_back();
65  p.ijacobian = m_jac.size() - 1;
66  }
67 
68  m_sourceLinks.emplace_back(std::nullopt);
69  p.iuncalibrated = m_sourceLinks.size() - 1;
70 
71  m_measOffset.push_back(kInvalid);
72  m_measCovOffset.push_back(kInvalid);
73 
74  if (ACTS_CHECK_BIT(mask, PropMask::Calibrated)) {
75  m_sourceLinks.emplace_back(std::nullopt);
76  p.icalibratedsourcelink = m_sourceLinks.size() - 1;
77 
78  m_projectors.emplace_back();
79  p.iprojector = m_projectors.size() - 1;
80  }
81 
82  // dynamic columns
83  for (auto& [key, vec] : m_dynamic) {
84  vec->add();
85  }
86 
87  return index;
88 }
89 
91  TrackStatePropMask shareSource,
92  TrackStatePropMask shareTarget) {
93  // auto other = getTrackState(iother);
94  IndexData& self = m_index[iself];
95  IndexData& other = m_index[iother];
96 
97  assert(ACTS_CHECK_BIT(getTrackState(iother).getMask(), shareSource) &&
98  "Source has incompatible allocation");
99 
100  using PM = TrackStatePropMask;
101 
102  IndexType sourceIndex{kInvalid};
103  switch (shareSource) {
104  case PM::Predicted:
105  sourceIndex = other.ipredicted;
106  break;
107  case PM::Filtered:
108  sourceIndex = other.ifiltered;
109  break;
110  case PM::Smoothed:
111  sourceIndex = other.ismoothed;
112  break;
113  case PM::Jacobian:
114  sourceIndex = other.ijacobian;
115  break;
116  default:
117  throw std::domain_error{"Unable to share this component"};
118  }
119 
120  assert(sourceIndex != kInvalid);
121 
122  switch (shareTarget) {
123  case PM::Predicted:
124  assert(shareSource != PM::Jacobian);
125  self.ipredicted = sourceIndex;
126  break;
127  case PM::Filtered:
128  assert(shareSource != PM::Jacobian);
129  self.ifiltered = sourceIndex;
130  break;
131  case PM::Smoothed:
132  assert(shareSource != PM::Jacobian);
133  self.ismoothed = sourceIndex;
134  break;
135  case PM::Jacobian:
136  assert(shareSource == PM::Jacobian);
137  self.ijacobian = sourceIndex;
138  break;
139  default:
140  throw std::domain_error{"Unable to share this component"};
141  }
142 }
143 
145  IndexType istate) {
146  using PM = TrackStatePropMask;
147 
148  switch (target) {
149  case PM::Predicted:
150  m_index[istate].ipredicted = kInvalid;
151  break;
152  case PM::Filtered:
153  m_index[istate].ifiltered = kInvalid;
154  break;
155  case PM::Smoothed:
156  m_index[istate].ismoothed = kInvalid;
157  break;
158  case PM::Jacobian:
159  m_index[istate].ijacobian = kInvalid;
160  break;
161  case PM::Calibrated:
162  m_measOffset[istate] = kInvalid;
163  m_measCovOffset[istate] = kInvalid;
164  break;
165  default:
166  throw std::domain_error{"Unable to unset this component"};
167  }
168 }
169 
171  m_index.clear();
172  m_previous.clear();
173  m_next.clear();
174  m_params.clear();
175  m_cov.clear();
176  m_meas.clear();
177  m_measOffset.clear();
178  m_measCov.clear();
179  m_measCovOffset.clear();
180  m_jac.clear();
181  m_sourceLinks.clear();
182  m_projectors.clear();
183  m_referenceSurfaces.clear();
184  for (auto& [key, vec] : m_dynamic) {
185  vec->clear();
186  }
187 }
188 
190  std::ostream& os, size_t n) {
191  using namespace boost::histogram;
192  using cat = axis::category<std::string>;
193 
194  auto& h = hist;
195 
196  auto column_axis = axis::get<cat>(h.axis(0));
197  auto type_axis = axis::get<axis::category<>>(h.axis(1));
198 
199  auto p = [&](const auto& key, const auto v, const std::string suffix = "") {
200  os << std::setw(20) << key << ": ";
201  if constexpr (std::is_same_v<std::decay_t<decltype(v)>, double>) {
202  os << std::fixed << std::setw(8) << std::setprecision(2) << v / n
203  << suffix;
204  } else {
205  os << std::fixed << std::setw(8) << double(v) / n << suffix;
206  }
207  os << std::endl;
208  };
209 
210  for (int t = 0; t < type_axis.size(); t++) {
211  os << (type_axis.bin(t) == 1 ? "meas" : "other") << ":" << std::endl;
212  double total = 0;
213  for (int c = 0; c < column_axis.size(); c++) {
214  std::string key = column_axis.bin(c);
215  auto v = h.at(c, t);
216  if (key == "count") {
217  p(key, static_cast<size_t>(v));
218  continue;
219  }
220  p(key, v / 1024 / 1024, "M");
221  total += v;
222  }
223  p("total", total / 1024 / 1024, "M");
224  }
225 }
226 
228  m_index.reserve(n);
229  m_previous.reserve(n);
230  m_next.reserve(n);
231  m_params.reserve(n * 2);
232  m_cov.reserve(n * 2);
233  m_meas.reserve(n * 2);
234  m_measOffset.reserve(n);
235  m_measCov.reserve(n * 2 * 2);
236  m_measCovOffset.reserve(n);
237  m_jac.reserve(n);
238  m_sourceLinks.reserve(n);
239  m_projectors.reserve(n);
240  m_referenceSurfaces.reserve(n);
241 
242  for (auto& [key, vec] : m_dynamic) {
243  vec->reserve(n);
244  }
245 }
246 
247 } // namespace Acts