Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:11:49

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2016-2018 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 ///////////////////////////////////////////////////////////////////
0010 // PlanarModuleStepper.cpp, Acts project
0011 ///////////////////////////////////////////////////////////////////
0012 
0013 #include "Acts/Digitization/PlanarModuleStepper.hpp"
0014 
0015 #include "Acts/Definitions/Algebra.hpp"
0016 #include "Acts/Digitization/DigitizationCell.hpp"
0017 #include "Acts/Digitization/DigitizationModule.hpp"
0018 #include "Acts/Surfaces/Surface.hpp"
0019 #include "Acts/Utilities/Intersection.hpp"
0020 
0021 #include <algorithm>
0022 #include <cstddef>
0023 #include <ostream>
0024 
0025 Acts::PlanarModuleStepper::PlanarModuleStepper(
0026     std::unique_ptr<const Logger> mlogger)
0027     : m_logger(std::move(mlogger)) {}
0028 
0029 std::vector<Acts::DigitizationStep> Acts::PlanarModuleStepper::cellSteps(
0030     const GeometryContext& gctx, const DigitizationModule& dmodule,
0031     const Vector3& startPoint, const Vector3& endPoint) const {
0032   // create the return vector
0033   std::vector<DigitizationStep> cSteps;
0034 
0035   // get the test surfaces for bin intersections
0036   auto stepSurfaces = dmodule.stepSurfaces(startPoint, endPoint);
0037 
0038   // the track direction
0039   Vector3 trackDirection((endPoint - startPoint).normalized());
0040 
0041   // the intersections through the surfaces, start one is the first valid one
0042   std::vector<Acts::Intersection3D> stepIntersections;
0043   stepIntersections.reserve(stepSurfaces.size() + 1);
0044 
0045   // run them - and check for the fast exit
0046   for (auto& sSurface : stepSurfaces) {
0047     // try it out by intersecting, but do not force the direction
0048     auto sIntersection =
0049         sSurface
0050             ->intersect(gctx, startPoint, trackDirection, BoundaryCheck(true))
0051             .closest();
0052     if (sIntersection) {
0053       // now record
0054       stepIntersections.push_back(sIntersection.intersection());
0055       ACTS_VERBOSE("Boundary Surface intersected with = "
0056                    << sIntersection.position().x() << ", "
0057                    << sIntersection.position().y() << ", "
0058                    << sIntersection.position().z());
0059     }
0060   }
0061   // Last one is also valid - now sort
0062   stepIntersections.push_back(
0063       Intersection3D(endPoint, (startPoint - endPoint).norm(),
0064                      Intersection3D::Status::reachable));
0065   std::sort(stepIntersections.begin(), stepIntersections.end(),
0066             Intersection3D::pathLengthOrder);
0067 
0068   Vector3 lastPosition = startPoint;
0069   // reserve the right amount
0070   cSteps.reserve(stepIntersections.size());
0071   for (auto& sIntersection : stepIntersections) {
0072     // create the new digitization step
0073     cSteps.push_back(
0074         dmodule.digitizationStep(lastPosition, sIntersection.position()));
0075     lastPosition = sIntersection.position();
0076   }
0077   // return all the steps
0078   return cSteps;
0079 }
0080 
0081 // calculate the steps caused by this track - fast simulation interface
0082 std::vector<Acts::DigitizationStep> Acts::PlanarModuleStepper::cellSteps(
0083     const GeometryContext& gctx, const Acts::DigitizationModule& dmodule,
0084     const Vector2& moduleIntersection, const Vector3& trackDirection) const {
0085   // first, intersect the boundary surfaces
0086   auto boundarySurfaces = dmodule.boundarySurfaces();
0087   // intersect them - fast exit for cases where
0088   // readout and counter readout are hit
0089   Vector3 intersection3D(moduleIntersection.x(), moduleIntersection.y(), 0.);
0090   std::size_t attempts = 0;
0091   // the collected intersections
0092   std::vector<Acts::Intersection3D> boundaryIntersections;
0093   // run them - and check for the fast exit
0094   for (auto& bSurface : boundarySurfaces) {
0095     // count as an attempt
0096     ++attempts;
0097     // try it out by intersecting, but do not force the direction
0098     auto bIntersection = bSurface
0099                              ->intersect(gctx, intersection3D, trackDirection,
0100                                          BoundaryCheck(true))
0101                              .closest();
0102     if (bIntersection) {
0103       // now record
0104       boundaryIntersections.push_back(bIntersection.intersection());
0105       ACTS_VERBOSE("Boundary Surface intersected with = "
0106                    << bIntersection.position().x() << ", "
0107                    << bIntersection.position().y() << ", "
0108                    << bIntersection.position().z());
0109     }
0110     // fast break in case of readout/counter surface hit
0111     // the first two attempts are the module faces, if they are hit,
0112     // the stepper has run ok.
0113     if (attempts == 2 && boundaryIntersections.size() == attempts) {
0114       break;
0115     }
0116   }
0117   // Post-process if we have more than 2 intersections
0118   // only first or last can be wrong after resorting
0119   if (boundaryIntersections.size() > 2) {
0120     ACTS_VERBOSE(
0121         "More than 2 Boundary Surfaces intersected, this is an edge "
0122         "case, resolving ... ");
0123     std::sort(boundaryIntersections.begin(), boundaryIntersections.end(),
0124               Intersection3D::pathLengthOrder);
0125   }
0126   // if for some reason the intersection does not work
0127   if (boundaryIntersections.empty()) {
0128     return std::vector<Acts::DigitizationStep>();
0129   }
0130   // return
0131   return cellSteps(gctx, dmodule, boundaryIntersections[0].position(),
0132                    boundaryIntersections[1].position());
0133 }