ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SurfaceCollector.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SurfaceCollector.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 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
10 
11 #include <sstream>
13 
14 namespace Acts {
15 
18  bool selectSensitive = true;
19  bool selectMaterial = false;
20  bool selectPassive = false;
21 
27  SurfaceSelector(bool sSensitive = true, bool sMaterial = false,
28  bool sPassive = false)
29  : selectSensitive(sSensitive),
30  selectMaterial(sMaterial),
31  selectPassive(sPassive) {}
32 
36  bool operator()(const Acts::Surface& surface) const {
37  if (selectSensitive && surface.associatedDetectorElement() != nullptr) {
38  return true;
39  }
40  if (selectMaterial && surface.surfaceMaterial() != nullptr) {
41  return true;
42  }
43  if (selectPassive) {
44  return true;
45  }
46  return false;
47  }
48 };
49 
51 struct SurfaceHit {
52  const Surface* surface = nullptr;
55 };
56 
63 template <typename Selector = SurfaceSelector>
66  Selector selector;
67 
71  struct this_result {
72  std::vector<SurfaceHit> collected;
73  };
74 
76 
88  template <typename propagator_state_t, typename stepper_t>
89  void operator()(propagator_state_t& state, const stepper_t& stepper,
90  result_type& result) const {
91  // The current surface has been assigned by the navigator
92  if (state.navigation.currentSurface &&
93  selector(*state.navigation.currentSurface)) {
94  // Create for recording
95  SurfaceHit surface_hit;
96  surface_hit.surface = state.navigation.currentSurface;
97  surface_hit.position = stepper.position(state.stepping);
98  surface_hit.direction = stepper.direction(state.stepping);
99  // Save if in the result
100  result.collected.push_back(surface_hit);
101  // Screen output
102  debugLog(state, [&] {
103  std::stringstream dstream;
104  dstream << "Collect surface "
105  << state.navigation.currentSurface->geoID();
106  return dstream.str();
107  });
108  }
109  }
110 
113  template <typename propagator_state_t, typename stepper_t>
114  void operator()(propagator_state_t& /*state*/,
115  const stepper_t& /*unused*/) const {}
116 
117  private:
129  template <typename propagator_state_t>
130  void debugLog(propagator_state_t& state,
131  const std::function<std::string()>& logAction) const {
132  if (state.options.debug) {
133  std::stringstream dstream;
134  dstream << " " << std::setw(state.options.debugPfxWidth);
135  dstream << "surface collector"
136  << " | ";
137  dstream << std::setw(state.options.debugMsgWidth) << logAction() << '\n';
138  state.options.debugString += dstream.str();
139  }
140  }
141 };
142 
143 } // namespace Acts