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 
12 
13 #include <sstream>
14 
15 namespace Acts {
16 
19  bool selectMaterial = true;
20  bool selectLayer = false;
21  bool selectPassive = false;
22 
28  VolumeSelector(bool sMaterial = true, bool sLayer = false,
29  bool sPassive = false)
30  : selectMaterial(sMaterial),
31  selectLayer(sLayer),
32  selectPassive(sPassive) {}
33 
37  bool operator()(const Acts::TrackingVolume& volume) const {
38  if (selectMaterial && volume.volumeMaterial() != nullptr) {
39  return true;
40  }
41  if (selectLayer && volume.confinedLayers() != nullptr) {
42  return true;
43  }
44  if (selectPassive) {
45  return true;
46  }
47  return false;
48  }
49 };
50 
52 struct VolumeHit {
53  const TrackingVolume* volume = nullptr;
56 };
57 
64 template <typename Selector = VolumeSelector>
67  Selector selector;
68 
72  struct this_result {
73  std::vector<VolumeHit> collected;
74  };
75 
77 
89  template <typename propagator_state_t, typename stepper_t>
90  void operator()(propagator_state_t& state, const stepper_t& stepper,
91  result_type& result) const {
92  const auto& logger = state.options.logger;
93  // The current volume has been assigned by the navigator
94  if (state.navigation.currentVolume &&
95  selector(*state.navigation.currentVolume)) {
96  // Create for recording
97  VolumeHit volume_hit;
98  volume_hit.volume = state.navigation.currentVolume;
99  volume_hit.position = stepper.position(state.stepping);
100  volume_hit.direction = stepper.direction(state.stepping);
101  bool save = true;
102  // Check if the Volume ws already encountered
103  for (auto const& res : result.collected) {
104  if (res.volume == volume_hit.volume) {
105  save = false;
106  break;
107  }
108  }
109  // Save if in the result if it does not already exist
110  if (save) {
111  result.collected.push_back(volume_hit);
112  // Screen output
113  ACTS_VERBOSE("Collect volume "
114  << state.navigation.currentVolume->geometryId());
115  }
116  }
117  }
118 
121  template <typename propagator_state_t, typename stepper_t>
122  void operator()(propagator_state_t& /*state*/,
123  const stepper_t& /*unused*/) const {}
124 };
125 
126 } // namespace Acts