Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Interactor.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Interactor.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 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 
13 #include "Acts/Material/MaterialProperties.hpp"
18 #include <climits>
19 #include <cmath>
20 #include <sstream>
21 #include <utility>
22 
23 namespace Fatras {
24 
25 struct VoidSelector {
26 
27  bool operator()(const Acts::Surface &) const { return false; }
28 };
29 
48 template <typename generator_t, typename particle_t, typename hit_t,
49  typename hit_creator_t, typename sensitive_selector_t = VoidSelector,
50  typename physics_list_t = PhysicsList<>>
51 struct Interactor {
52  using PhysicsList_t = physics_list_t;
53 
55  generator_t *generator = nullptr;
56 
58  sensitive_selector_t sensitiveSelector;
59 
61  physics_list_t physicsList;
62 
64  particle_t initialParticle;
65 
67  hit_creator_t hitCreator;
68 
71  struct this_result {
72 
74  bool initialized = false;
75 
77  particle_t particle;
78 
80  std::vector<particle_t> outgoing;
81 
83  std::vector<hit_t> simulatedHits;
84  };
85 
87 
105  template <typename propagator_state_t, typename stepper_t>
106  void operator()(propagator_state_t &state, stepper_t &stepper,
107  result_type &result) const {
108 
109  // If we are on target, everything should have been done
110  if (state.navigation.targetReached)
111  return;
112 
113  // Initialize the result, the state is thread local
114  if (!result.initialized) {
115  // set the initial particle parameters
116  result.particle = initialParticle;
117  result.initialized = true;
118  }
119  // get position and momentum presetp
120  auto position = stepper.position(state.stepping);
121  auto direction = stepper.direction(state.stepping);
122  auto p = stepper.momentum(state.stepping);
123 
124  // set the stepping position to the particle
125  result.particle.update(position, p * direction, 0., 0.,
126  stepper.time(state.stepping));
127 
128  // Check if the current surrface a senstive one
129  bool sensitive = state.navigation.currentSurface
130  ? sensitiveSelector(*state.navigation.currentSurface)
131  : false;
132  double depositedEnergy = 0.;
133 
134  // a current surface has been assigned by the navigator
135  if (state.navigation.currentSurface &&
136  state.navigation.currentSurface->surfaceMaterial()) {
137  // get the surface material and the corresponding material properties
138  auto sMaterial = state.navigation.currentSurface->surfaceMaterial();
139  const Acts::MaterialProperties &mProperties =
140  sMaterial->materialProperties(position);
141  bool breakIndicator = false;
142  if (mProperties) {
143  // run the Fatras physics list - only when there's material
144  breakIndicator = physicsList(*generator, mProperties, result.particle,
145  result.outgoing);
146  }
147  }
148  // Update the stepper cache with the current particle parameters
149  position = result.particle.position();
150  direction = result.particle.momentum().normalized();
151  stepper.update(state.stepping, position, direction, result.particle.p(),
152  result.particle.time());
153  // create the hit on a senstive element
154  if (sensitive) {
155  // create and fill the hit
156  double htime =
157  stepper.time(state.stepping);
158  hit_t simHit =
159  hitCreator(*state.navigation.currentSurface, position, direction,
160  depositedEnergy, htime, result.particle);
161  result.simulatedHits.push_back(std::move(simHit));
162  }
163  }
164 
167  template <typename propagator_state_t, typename stepper_t>
168  void operator()(propagator_state_t &, stepper_t &) const {}
169 };
170 } // namespace Fatras