Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiTrajectoryHelpers.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MultiTrajectoryHelpers.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 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 
9 #pragma once
13 #include "Acts/Geometry/Layer.hpp"
16 
17 #include <functional>
18 #include <unordered_map>
19 
20 namespace Acts {
21 
22 namespace MultiTrajectoryHelpers {
23 
27  size_t nStates = 0;
28  size_t nMeasurements = 0;
29  size_t nOutliers = 0;
30  size_t nHoles = 0;
31  double chi2Sum = 0;
32  std::vector<double> measurementChi2 = {};
33  std::vector<double> outlierChi2 = {};
34  size_t NDF = 0;
35  std::vector<unsigned int> measurementVolume = {};
36  std::vector<unsigned int> measurementLayer = {};
37  std::vector<unsigned int> outlierVolume = {};
38  std::vector<unsigned int> outlierLayer = {};
39  size_t nSharedHits = 0;
40 };
41 
42 // Container for trajectory summary info at a specific volume
44  std::unordered_map<GeometryIdentifier::Value, TrajectoryState>;
45 
52 template <typename traj_t>
53 TrajectoryState trajectoryState(const traj_t& multiTraj, size_t entryIndex) {
54  TrajectoryState trajState;
55  multiTraj.visitBackwards(entryIndex, [&](const auto& state) {
56  // Get the volume Id of this surface
57  const auto& geoID = state.referenceSurface().geometryId();
58  const auto& volume = geoID.volume();
59  const auto& layer = geoID.layer();
60  trajState.nStates++;
61  auto typeFlags = state.typeFlags();
62  if (typeFlags.test(Acts::TrackStateFlag::MeasurementFlag)) {
63  if (typeFlags.test(Acts::TrackStateFlag::SharedHitFlag)) {
64  trajState.nSharedHits++;
65  }
66  trajState.nMeasurements++;
67  trajState.measurementChi2.push_back(state.chi2());
68  trajState.measurementVolume.push_back(volume);
69  trajState.measurementLayer.push_back(layer);
70  trajState.chi2Sum += state.chi2();
71  trajState.NDF += state.calibratedSize();
72  } else if (typeFlags.test(Acts::TrackStateFlag::OutlierFlag)) {
73  trajState.nOutliers++;
74  trajState.outlierChi2.push_back(state.chi2());
75  trajState.outlierVolume.push_back(volume);
76  trajState.outlierLayer.push_back(layer);
77  } else if (typeFlags.test(Acts::TrackStateFlag::HoleFlag)) {
78  trajState.nHoles++;
79  }
80  });
81  return trajState;
82 }
83 
95 template <typename traj_t>
97  const traj_t& multiTraj, size_t entryIndex,
98  const std::vector<GeometryIdentifier::Value>& volumeIds) {
99  VolumeTrajectoryStateContainer trajStateContainer;
100  multiTraj.visitBackwards(entryIndex, [&](const auto& state) {
101  // Get the volume Id of this surface
102  const auto& geoID = state.referenceSurface().geometryId();
103  const auto& volume = geoID.volume();
104  const auto& layer = geoID.layer();
105  // Check if the track info for this sub-detector is requested
106  auto it = std::find(volumeIds.begin(), volumeIds.end(), volume);
107  if (it == volumeIds.end()) {
108  return true;
109  }
110  // The trajectory state for this volume
111  auto& trajState = trajStateContainer[volume];
112  trajState.nStates++;
113  trajState.NDF += state.calibratedSize();
114  auto typeFlags = state.typeFlags();
115  if (typeFlags.test(Acts::TrackStateFlag::MeasurementFlag)) {
116  if (typeFlags.test(Acts::TrackStateFlag::SharedHitFlag)) {
117  trajState.nSharedHits++;
118  }
119  trajState.nMeasurements++;
120  trajState.measurementChi2.push_back(state.chi2());
121  trajState.measurementVolume.push_back(volume);
122  trajState.measurementLayer.push_back(layer);
123  trajState.chi2Sum += state.chi2();
124  } else if (typeFlags.test(Acts::TrackStateFlag::OutlierFlag)) {
125  trajState.nOutliers++;
126  trajState.outlierChi2.push_back(state.chi2());
127  trajState.outlierVolume.push_back(volume);
128  trajState.outlierLayer.push_back(layer);
129  } else if (typeFlags.test(Acts::TrackStateFlag::HoleFlag)) {
130  trajState.nHoles++;
131  }
132  return true;
133  });
134  return trajStateContainer;
135 }
136 
145 template <typename track_state_proxy_t>
147  const track_state_proxy_t& trackStateProxy) {
149  trackStateProxy.referenceSurface(), gctx, trackStateProxy.filtered());
150 }
151 
160 template <typename track_state_proxy_t>
162  const track_state_proxy_t& trackStateProxy) {
164  trackStateProxy.referenceSurface(), gctx, trackStateProxy.smoothed());
165 }
166 } // namespace MultiTrajectoryHelpers
167 
168 } // namespace Acts