Analysis Software
Documentation for sPHENIX simulation 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>
68 
72  struct this_result {
73  std::vector<VolumeHit> collected;
74  };
75 
77 
92  template <typename propagator_state_t, typename stepper_t,
93  typename navigator_t>
94  void operator()(propagator_state_t& state, const stepper_t& stepper,
95  const navigator_t& navigator, result_type& result,
96  const Logger& logger) const {
97  auto currentVolume = navigator.currentVolume(state.navigation);
98 
99  // The current volume has been assigned by the navigator
100  if (currentVolume && selector(*currentVolume)) {
101  // Create for recording
102  VolumeHit volume_hit;
103  volume_hit.volume = currentVolume;
104  volume_hit.position = stepper.position(state.stepping);
105  volume_hit.direction = stepper.direction(state.stepping);
106  bool save = true;
107  // Check if the Volume ws already encountered
108  for (auto const& res : result.collected) {
109  if (res.volume == volume_hit.volume) {
110  save = false;
111  break;
112  }
113  }
114  // Save if in the result if it does not already exist
115  if (save) {
116  result.collected.push_back(volume_hit);
117  // Screen output
118  ACTS_VERBOSE("Collect volume " << currentVolume->geometryId());
119  }
120  }
121  }
122 };
123 
124 } // namespace Acts