Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlanarModuleStepper.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PlanarModuleStepper.cpp
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 
10 // PlanarModuleStepper.cpp, Acts project
12 
14 
20 
21 #include <algorithm>
22 #include <cstddef>
23 #include <ostream>
24 
26  std::unique_ptr<const Logger> mlogger)
27  : m_logger(std::move(mlogger)) {}
28 
29 std::vector<Acts::DigitizationStep> Acts::PlanarModuleStepper::cellSteps(
30  const GeometryContext& gctx, const DigitizationModule& dmodule,
31  const Vector3& startPoint, const Vector3& endPoint) const {
32  // create the return vector
33  std::vector<DigitizationStep> cSteps;
34 
35  // get the test surfaces for bin intersections
36  auto stepSurfaces = dmodule.stepSurfaces(startPoint, endPoint);
37 
38  // the track direction
39  Vector3 trackDirection((endPoint - startPoint).normalized());
40 
41  // the intersections through the surfaces, start one is the first valid one
42  std::vector<Acts::Intersection3D> stepIntersections;
43  stepIntersections.reserve(stepSurfaces.size() + 1);
44 
45  // run them - and check for the fast exit
46  for (auto& sSurface : stepSurfaces) {
47  // try it out by intersecting, but do not force the direction
48  auto sIntersection =
49  sSurface->intersect(gctx, startPoint, trackDirection, true).closest();
50  if (sIntersection) {
51  // now record
52  stepIntersections.push_back(sIntersection.intersection());
53  ACTS_VERBOSE("Boundary Surface intersected with = "
54  << sIntersection.position().x() << ", "
55  << sIntersection.position().y() << ", "
56  << sIntersection.position().z());
57  }
58  }
59  // Last one is also valid - now sort
60  stepIntersections.push_back(
61  Intersection3D(endPoint, (startPoint - endPoint).norm(),
62  Intersection3D::Status::reachable));
63  std::sort(stepIntersections.begin(), stepIntersections.end(),
65 
66  Vector3 lastPosition = startPoint;
67  // reserve the right amount
68  cSteps.reserve(stepIntersections.size());
69  for (auto& sIntersection : stepIntersections) {
70  // create the new digitization step
71  cSteps.push_back(
72  dmodule.digitizationStep(lastPosition, sIntersection.position()));
73  lastPosition = sIntersection.position();
74  }
75  // return all the steps
76  return cSteps;
77 }
78 
79 // calculate the steps caused by this track - fast simulation interface
80 std::vector<Acts::DigitizationStep> Acts::PlanarModuleStepper::cellSteps(
81  const GeometryContext& gctx, const Acts::DigitizationModule& dmodule,
82  const Vector2& moduleIntersection, const Vector3& trackDirection) const {
83  // first, intersect the boundary surfaces
84  auto boundarySurfaces = dmodule.boundarySurfaces();
85  // intersect them - fast exit for cases where
86  // readout and counter readout are hit
87  Vector3 intersection3D(moduleIntersection.x(), moduleIntersection.y(), 0.);
88  size_t attempts = 0;
89  // the collected intersections
90  std::vector<Acts::Intersection3D> boundaryIntersections;
91  // run them - and check for the fast exit
92  for (auto& bSurface : boundarySurfaces) {
93  // count as an attempt
94  ++attempts;
95  // try it out by intersecting, but do not force the direction
96  auto bIntersection =
97  bSurface->intersect(gctx, intersection3D, trackDirection, true)
98  .closest();
99  if (bIntersection) {
100  // now record
101  boundaryIntersections.push_back(bIntersection.intersection());
102  ACTS_VERBOSE("Boundary Surface intersected with = "
103  << bIntersection.position().x() << ", "
104  << bIntersection.position().y() << ", "
105  << bIntersection.position().z());
106  }
107  // fast break in case of readout/counter surface hit
108  // the first two attempts are the module faces, if they are hit,
109  // the stepper has run ok.
110  if (attempts == 2 && boundaryIntersections.size() == attempts) {
111  break;
112  }
113  }
114  // Post-process if we have more than 2 intersections
115  // only first or last can be wrong after resorting
116  if (boundaryIntersections.size() > 2) {
117  ACTS_VERBOSE(
118  "More than 2 Boundary Surfaces intersected, this is an edge "
119  "case, resolving ... ");
120  std::sort(boundaryIntersections.begin(), boundaryIntersections.end(),
122  }
123  // if for some reason the intersection does not work
124  if (boundaryIntersections.empty()) {
125  return std::vector<Acts::DigitizationStep>();
126  }
127  // return
128  return cellSteps(gctx, dmodule, boundaryIntersections[0].position(),
129  boundaryIntersections[1].position());
130 }