Analysis Software
Documentation for sPHENIX simulation 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 
63  template <typename propagator_state_t, typename stepper_t,
64  typename navigator_t>
65  void operator()(propagator_state_t& state, const stepper_t& stepper,
66  const navigator_t& navigator, result_type& result,
67  const Logger& logger) const {
68  if (navigator.currentSurface(state.navigation)) {
69  if (navigator.currentSurface(state.navigation) ==
70  navigator.targetSurface(state.navigation) and
71  not navigator.targetReached(state.navigation)) {
72  return;
73  }
74 
75  ACTS_VERBOSE("Material check on surface "
76  << navigator.currentSurface(state.navigation)->geometryId());
77 
78  if (navigator.currentSurface(state.navigation)->surfaceMaterial()) {
79  // get the material propertices and only continue
80  const MaterialSlab* mProperties =
81  navigator.currentSurface(state.navigation)
82  ->surfaceMaterial()
83  ->material(stepper.position(state.stepping));
84  if (mProperties) {
85  // pre/post/full update
86  double prepofu = 1.;
87  if (navigator.startSurface(state.navigation) ==
88  navigator.currentSurface(state.navigation)) {
89  ACTS_VERBOSE("Update on start surface: post-update mode.");
90  prepofu = navigator.currentSurface(state.navigation)
91  ->surfaceMaterial()
92  ->factor(state.options.direction,
93  MaterialUpdateStage::PostUpdate);
94  } else if (navigator.targetSurface(state.navigation) ==
95  navigator.currentSurface(state.navigation)) {
96  ACTS_VERBOSE("Update on target surface: pre-update mode");
97  prepofu = navigator.currentSurface(state.navigation)
98  ->surfaceMaterial()
99  ->factor(state.options.direction,
100  MaterialUpdateStage::PreUpdate);
101  } else {
102  ACTS_VERBOSE("Update while pass through: full mode.");
103  }
104 
105  // the pre/post factor has been applied
106  // now check if there's still something to do
107  if (prepofu == 0.) {
108  ACTS_VERBOSE("Pre/Post factor set material to zero.");
109  return;
110  }
111  // more debugging output to the screen
112  ACTS_VERBOSE("Material properties found for this surface.");
113 
114  // the path correction from the surface intersection
115  double pCorrection =
116  prepofu * navigator.currentSurface(state.navigation)
117  ->pathCorrection(stepper.position(state.stepping),
118  stepper.direction(state.stepping));
119  // the full material
120  result.materialInX0 += pCorrection * mProperties->thicknessInX0();
121  result.materialInL0 += pCorrection * mProperties->thicknessInL0();
122 
123  ACTS_VERBOSE("t/X0 (t/L0) increased to "
124  << result.materialInX0 << " (" << result.materialInL0
125  << " )");
126 
127  // if configured, record the individual material hits
128  if (detailedCollection) {
129  // create for recording
130  MaterialHit mHit;
131  mHit.surface = navigator.currentSurface(state.navigation);
132  mHit.position = stepper.position(state.stepping);
133  mHit.direction = stepper.direction(state.stepping);
134  // get the material & path length
135  mHit.material = mProperties->material();
136  mHit.pathLength = pCorrection * mProperties->thickness();
137  // save if in the result
138  result.collected.push_back(mHit);
139  }
140  }
141  }
142  }
143  }
144 }; // namespace Acts
145 } // namespace Acts