ATLAS Offline Software
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
19 Trk::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 
46 std::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
91 std::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 }
Trk::DigitizationModule::boundarySurfaces
const std::vector< std::shared_ptr< const Surface > > & boundarySurfaces() const
return the bounding surfaces at top and bottom
Definition: DigitizationModule.h:121
Trk::Intersection
Definition: Intersection.h:24
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Surface.h
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
DigitizationModule.h
Trk::PlanarModuleStepper::PlanarModuleStepper
PlanarModuleStepper(const std::string &, const std::string &, const IInterface *)
Constructor.
Definition: PlanarModuleStepper.cxx:19
Trk::DigitizationModule
Definition: DigitizationModule.h:50
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::DigitizationModule::stepSurfaces
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
Definition: DigitizationModule.cxx:58
Trk::PlanarModuleStepper::initialize
StatusCode initialize() override
AlgTool initialize method.
Definition: PlanarModuleStepper.cxx:32
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
beamspotman.n
n
Definition: beamspotman.py:731
Trk::PlanarModuleStepper::cellSteps
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
Definition: PlanarModuleStepper.cxx:46
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PlanarModuleStepper.h
Trk::Intersection::position
Amg::Vector3D position
Definition: Intersection.h:25
Trk::PlanarModuleStepper::~PlanarModuleStepper
virtual ~PlanarModuleStepper()
Destructor.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::Intersection::valid
bool valid
Definition: Intersection.h:28
DigitizationCell.h
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:20
GeoPrimitivesToStringConverter.h
Trk::DigitizationModule::digitizationStep
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 ...
Definition: DigitizationModule.h:130
AthAlgTool
Definition: AthAlgTool.h:26
Intersection.h
mag
Scalar mag() const
mag method
Definition: AmgMatrixBasePlugin.h:25
Trk::PlanarModuleStepper::finalize
StatusCode finalize() override
AlgTool finalize method.
Definition: PlanarModuleStepper.cxx:39