EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaterialCollector.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MaterialCollector.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-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
10 
15 
16 #include <sstream>
17 
18 namespace Acts {
19 
21 struct MaterialHit {
22  const Surface* surface = nullptr;
26  double pathLength;
27 };
28 
34  bool detailedCollection = false;
35 
41  struct this_result {
42  std::vector<MaterialHit> collected;
43  double materialInX0 = 0.;
44  double materialInL0 = 0.;
45  };
46 
48 
60  template <typename propagator_state_t, typename stepper_t>
61  void operator()(propagator_state_t& state, const stepper_t& stepper,
62  result_type& result) const {
63  const auto& logger = state.options.logger;
64  if (state.navigation.currentSurface) {
65  if (state.navigation.currentSurface == state.navigation.targetSurface and
66  not state.navigation.targetReached) {
67  return;
68  }
69 
70  ACTS_VERBOSE("Material check on surface "
71  << state.navigation.currentSurface->geometryId());
72 
73  if (state.navigation.currentSurface->surfaceMaterial()) {
74  // get the material propertices and only continue
75  const MaterialSlab* mProperties =
76  state.navigation.currentSurface->surfaceMaterial()->material(
77  stepper.position(state.stepping));
78  if (mProperties) {
79  // pre/post/full update
80  double prepofu = 1.;
81  if (state.navigation.startSurface ==
82  state.navigation.currentSurface) {
83  ACTS_VERBOSE("Update on start surface: post-update mode.");
84  prepofu =
85  state.navigation.currentSurface->surfaceMaterial()->factor(
86  state.stepping.navDir, postUpdate);
87  } else if (state.navigation.targetSurface ==
88  state.navigation.currentSurface) {
89  ACTS_VERBOSE("Update on target surface: pre-update mode");
90  prepofu =
91  state.navigation.currentSurface->surfaceMaterial()->factor(
92  state.stepping.navDir, preUpdate);
93  } else {
94  ACTS_VERBOSE("Update while pass through: full mode.");
95  }
96 
97  // the pre/post factor has been applied
98  // now check if there's still something to do
99  if (prepofu == 0.) {
100  ACTS_VERBOSE("Pre/Post factor set material to zero.");
101  return;
102  }
103  // more debugging output to the screen
104  ACTS_VERBOSE("Material properties found for this surface.");
105 
106  // the path correction from the surface intersection
107  double pCorrection =
108  prepofu * state.navigation.currentSurface->pathCorrection(
109  stepper.position(state.stepping),
110  stepper.direction(state.stepping));
111  // the full material
112  result.materialInX0 += pCorrection * mProperties->thicknessInX0();
113  result.materialInL0 += pCorrection * mProperties->thicknessInL0();
114 
115  ACTS_VERBOSE("t/X0 (t/L0) increased to "
116  << result.materialInX0 << " (" << result.materialInL0
117  << " )");
118 
119  // if configured, record the individual material hits
120  if (detailedCollection) {
121  // create for recording
122  MaterialHit mHit;
123  mHit.surface = state.navigation.currentSurface;
124  mHit.position = stepper.position(state.stepping);
125  mHit.direction = stepper.direction(state.stepping);
126  // get the material & path length
127  mHit.material = mProperties->material();
128  mHit.pathLength = pCorrection * mProperties->thickness();
129  // save if in the result
130  result.collected.push_back(mHit);
131  }
132  }
133  }
134  }
135  }
136 
139  template <typename propagator_state_t>
140  void operator()(propagator_state_t& /*state*/) const {}
141 }; // namespace Acts
142 } // namespace Acts