ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VolumeCollector.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VolumeCollector.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 selectMaterial = true;
19  bool selectLayer = false;
20  bool selectPassive = false;
21 
27  VolumeSelector(bool sMaterial = true, bool sLayer = false,
28  bool sPassive = false)
29  : selectMaterial(sMaterial),
30  selectLayer(sLayer),
31  selectPassive(sPassive) {}
32 
36  bool operator()(const Acts::TrackingVolume& volume) const {
37  if (selectMaterial && volume.volumeMaterial() != nullptr) {
38  return true;
39  }
40  if (selectLayer && volume.confinedLayers() != nullptr) {
41  return true;
42  }
43  if (selectPassive) {
44  return true;
45  }
46  return false;
47  }
48 };
49 
51 struct VolumeHit {
52  const TrackingVolume* volume = nullptr;
55 };
56 
63 template <typename Selector = VolumeSelector>
66  Selector selector;
67 
71  struct this_result {
72  std::vector<VolumeHit> 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 volume has been assigned by the navigator
92  if (state.navigation.currentVolume &&
93  selector(*state.navigation.currentVolume)) {
94  // Create for recording
95  VolumeHit volume_hit;
96  volume_hit.volume = state.navigation.currentVolume;
97  volume_hit.position = stepper.position(state.stepping);
98  volume_hit.direction = stepper.direction(state.stepping);
99  // Save if in the result
100  result.collected.push_back(volume_hit);
101  // Screen output
102  debugLog(state, [&] {
103  std::stringstream dstream;
104  dstream << "Collect volume "
105  << state.navigation.currentVolume->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 << "volume collector"
136  << " | ";
137  dstream << std::setw(state.options.debugMsgWidth) << logAction() << '\n';
138  state.options.debugString += dstream.str();
139  }
140  }
141 };
142 
143 } // namespace Acts