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