ATLAS Offline Software
Loading...
Searching...
No Matches
PlanarModuleStepper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
5// PlanarModuleStepper.cxx, (c) ATLAS Detector software
7
8// Trk include
11#include "TrkDigEvent/DigitizationCell.h" //DigitizationStep, typedef DigitizationCell
12
14#include "TrkSurfaces/Surface.h"
15// Amg
17
18// constructor
19Trk::PlanarModuleStepper::PlanarModuleStepper(const std::string& t, const std::string& n, const IInterface* p)
20: AthAlgTool(t,n,p)
21{
22 declareInterface<IModuleStepper>(this);
23}
24
25// destructor
27= default;
28
29
30// Athena standard methods
31// initialize
33{
34
35 return StatusCode::SUCCESS;
36}
37
38// finalize
40{
41 return StatusCode::SUCCESS;
42}
43
44
46std::vector<Trk::DigitizationStep> Trk::PlanarModuleStepper::cellSteps(const Trk::DigitizationModule& dmodule,
47 const Amg::Vector3D& startPoint,
48 const Amg::Vector3D& endPoint) const
49{
50 // create the return vector
51 std::vector<Trk::DigitizationStep> cSteps;
52
53 // get the test surfaces for bin intersections
54 const auto& stepSurfaces = dmodule.stepSurfaces(startPoint,endPoint);
55
56 // the track direction
57 Amg::Vector3D trackDirection((endPoint-startPoint).unit());
58
59 // the intersections through the surfaces, start one is the first valid one
60 std::vector<Trk::Intersection> stepIntersections;
61 stepIntersections.reserve(stepSurfaces.size()+1);
62
63 // run them - and check for the fast exit
64 for (const auto& sSurface : stepSurfaces){
65 // try it out by intersecting, but do not force the direction
66 Trk::Intersection sIntersection = sSurface->straightLineIntersection(startPoint,trackDirection,true,true);
67 if (sIntersection.valid) {
68 // now record
69 stepIntersections.push_back(sIntersection);
70 ATH_MSG_VERBOSE("Boundary Surface intersected with = " << Amg::toString(sIntersection.position) );
71 }
72 }
73 // last one is also valid - now sort
74 stepIntersections.emplace_back(endPoint,(startPoint-endPoint).mag(),true);
75 std::sort(stepIntersections.begin(),stepIntersections.end());
76
77 Amg::Vector3D lastPosition = startPoint;
78 // reserve the right amount
79 cSteps.reserve(stepIntersections.size());
80 for (auto& sIntersection : stepIntersections){
81 // create the new cStep
82 cSteps.push_back( dmodule.digitizationStep(lastPosition,sIntersection.position));
83 lastPosition = sIntersection.position;
84 }
85 // return all the steps
86 return cSteps;
87}
88
89
90// calculate the steps caused by this track - fast simulation interface
91std::vector<Trk::DigitizationStep> Trk::PlanarModuleStepper::cellSteps(const Trk::DigitizationModule& dmodule,
92 const Amg::Vector2D& moduleIntersection,
93 const Amg::Vector3D& trackDirection) const
94{
95
96
97 // first, intersect the boundary surfaces
98 const auto &boundarySurfaces = dmodule.boundarySurfaces();
99 // intersect them - fast exit for cases where readout and counter readout are hit
100 Amg::Vector3D intersection3D(moduleIntersection.x(),moduleIntersection.y(),0.);
101 size_t attempts = 0;
102 // the collected intersections
103 std::vector< Trk::Intersection > boundaryIntersections;
104 // run them - and check for the fast exit
105 for (const auto& bSurface : boundarySurfaces){
106 // count as an attempt
107 ++attempts;
108 // try it out by intersecting, but do not force the direction
109 Trk::Intersection bIntersection = bSurface->straightLineIntersection(intersection3D,trackDirection,false,true);
110 if (bIntersection.valid) {
111 // now record
112 boundaryIntersections.push_back(bIntersection);
113 ATH_MSG_VERBOSE("Boundary Surface intersected with = " << Amg::toString(bIntersection.position) );
114 }
115 // fast break in case of readout/counter surface hit
116 if (attempts == 2 && boundaryIntersections.size() == attempts) break;
117 else if (attempts > 2 && boundaryIntersections.size()==3) break;
118 }
119 // post-process if we have more than 2 intersections, only first or last can be wrong after resorting
120 if (boundaryIntersections.size() > 2){
121 ATH_MSG_VERBOSE("More than 2 Boundary Surfaces intersected, this is an edge case, resolving ... ");
122 std::sort(boundaryIntersections.begin(),boundaryIntersections.end());
123 if (boundaryIntersections[0].pathLength*boundaryIntersections[1].pathLength < 0.) boundaryIntersections.pop_back();
124 else boundaryIntersections.erase(boundaryIntersections.begin());
125 }
126 // return
127 return cellSteps(dmodule, boundaryIntersections[0].position, boundaryIntersections[1].position);
128}
Scalar mag() const
mag method
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
#define ATH_MSG_VERBOSE(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Class that holds the surfaces for a planar digitization detector module.
const std::vector< std::shared_ptr< const Surface > > stepSurfaces(const Amg::Vector3D &start, const Amg::Vector3D &end) const
return the test surfaces between these points
const std::vector< std::shared_ptr< const Surface > > & boundarySurfaces() const
return the bounding surfaces at top and bottom
const DigitizationStep digitizationStep(const Amg::Vector3D &start, const Amg::Vector3D &end) const
Fill the associated digitsation cell from this start and end position, correct for lorentz effect if ...
StatusCode initialize() override
AlgTool initialize method.
virtual ~PlanarModuleStepper()
Destructor.
StatusCode finalize() override
AlgTool finalize method.
std::vector< DigitizationStep > cellSteps(const DigitizationModule &dmodule, const Amg::Vector3D &startPosition, const Amg::Vector3D &endPosition) const override
calculate the steps caused by this track - full simulation interface
PlanarModuleStepper(const std::string &, const std::string &, const IInterface *)
Constructor.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Amg::Vector3D position