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