ATLAS Offline Software
TrapezoidSegmentation.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TrapezoidSegmentation.cxx, ATLAS Detector software
8 
9 // Trk includes
10 #include <memory>
11 
12 
13 
19 // Amg includes
21 
22 Trk::TrapezoidSegmentation::TrapezoidSegmentation(std::shared_ptr<const Trk::TrapezoidBounds> mBounds,
23  size_t numCellsX, size_t numCellsY) :
24  m_activeBounds(std::move(mBounds)),
25  m_binUtility(nullptr),
26  m_binsX(numCellsX),
27  m_binsY(numCellsY)
28 {
29  // first the x dimension if needed
30  if (numCellsX > 1) {
31  m_binUtility = new Trk::BinUtility(numCellsX, -0.5*(m_activeBounds->minHalflengthX()+m_activeBounds->maxHalflengthX()), 0.5*(m_activeBounds->minHalflengthX()+m_activeBounds->maxHalflengthX()), Trk::open, Trk::binX);
32  }
33  // use y dimension if needed
34  if (numCellsY > 1){
35  Trk::BinUtility yBinUtility(numCellsY, -m_activeBounds->halflengthY(), m_activeBounds->halflengthY(), Trk::open, Trk::binY);
36  if (m_binUtility)
37  (*m_binUtility) += yBinUtility;
38  else
39  m_binUtility = new Trk::BinUtility(yBinUtility);
40  }
41 }
42 
44 {
45  delete m_binUtility;
46 }
47 
48 void Trk::TrapezoidSegmentation::createSegmenationSurfaces(std::vector< std::shared_ptr< const Trk::Surface> >& boundarySurfaces,
49  std::vector< std::shared_ptr< const Trk::Surface> >& segmentationSurfacesX,
50  std::vector< std::shared_ptr< const Trk::Surface> >& segmentationSurfacesY,
51  double halfThickness,
52  int readoutDirection,
53  double) const
54 {
55  // The Lorentz angle is not taken into account for trapezoidal segmentation
56  // (A) --- top/bottom surfaces -----------------------------------------------------------
57  // let's create the top/botten surfaces first - we call them readout / counter readout
58  // there are some things to consider
59  // - they share only the readout surface, then the segmentation surfaces are tilted and cannot be shared on the same module
60  std::unique_ptr<Trk::TrapezoidBounds> moduleTrapBounds(new Trk::TrapezoidBounds(m_activeBounds->minHalflengthX(),m_activeBounds->maxHalflengthX(),m_activeBounds->halflengthY()));
61  Trk::SharedObject<const Trk::SurfaceBounds> moduleBounds(&*moduleTrapBounds);
62  // - they are separated by half a thickness in z
63  Amg::Transform3D readoutPlaneTransform(Amg::Transform3D::Identity());
64  Amg::Transform3D counterPlaneTransform(Amg::Transform3D::Identity());
65  // readout and counter readout bounds, the bounds of the readout plane are like the active ones
66  const Trk::SharedObject<const Trk::SurfaceBounds>& readoutPlaneBounds = moduleBounds;
67  Trk::SharedObject<const Trk::SurfaceBounds> counterPlaneBounds(nullptr);
68  // the transform of the readout plane is always centric
69  readoutPlaneTransform.translation() = Amg::Vector3D(0.,0.,readoutDirection*halfThickness);
70  // no lorentz angle and everything is straight-forward
71  counterPlaneBounds = moduleBounds;
72  counterPlaneTransform.translation() = Amg::Vector3D(0.,0.,-readoutDirection*halfThickness);
73 
74  // - build the readout & counter readout surfaces
75  boundarySurfaces.push_back(std::shared_ptr<const Trk::PlaneSurface>(new Trk::PlaneSurface(readoutPlaneTransform,readoutPlaneBounds)));
76  boundarySurfaces.push_back(std::shared_ptr<const Trk::PlaneSurface>(new Trk::PlaneSurface(counterPlaneTransform,counterPlaneBounds)));
77 
78  // (B) - bin X -----------------------------------------------------------
79  // easy stuff first, constant pitch size and
80  double pitchX = 2.*(m_activeBounds->maxHalflengthX()+m_activeBounds->minHalflengthX())*0.5/m_binsX;
81 
82  // now the rotation matrix for the xBins
83  Amg::RotationMatrix3D xBinRotationMatrix;
84  xBinRotationMatrix.col(0) = Amg::Vector3D::UnitY();
85  xBinRotationMatrix.col(1) = Amg::Vector3D::UnitZ();
86  xBinRotationMatrix.col(2) = Amg::Vector3D::UnitX();
87 
88  // reserve, it's always (number of bins-1) as the boundaries are within the boundarySurfaces
89  segmentationSurfacesX.reserve(m_binsX);
90  for (size_t ibinx = 0; ibinx <= m_binsX; ++ibinx){
91  // the current step x position
92  double cPosX = -(m_activeBounds->minHalflengthX()+m_activeBounds->maxHalflengthX())*0.5+ibinx*pitchX;
93 
94  // set position & rotation for all (boundaries and segmentations) --> Then you separate between them
95  Amg::Vector3D xPosition = Amg::Vector3D(cPosX, 0.,0.);
96  double stereoLocal = asin(sinStereoLocal(Amg::Vector2D(cPosX, 0.)));
97  const Amg::RotationMatrix3D xRotation = xBinRotationMatrix*Amg::AngleAxis3D(stereoLocal, Amg::Vector3D::UnitY());
98  // build the rotation from it
99  Amg::Transform3D binTransform(Amg::getTransformFromRotTransl(xRotation, xPosition));
100  // the correct bounds for this
101  std::unique_ptr<Trk::RectangleBounds> xBinBounds(new Trk::RectangleBounds(m_activeBounds->halflengthY()/cos(stereoLocal),halfThickness));
102  // these are the boundaries
103  if (ibinx==0 || ibinx == m_binsX) // (i) this is the low/high boundary --- ( ibin == 0/m_binsX )
104  boundarySurfaces.push_back(std::shared_ptr<const Trk::PlaneSurface>(new Trk::PlaneSurface(binTransform,&*xBinBounds)));
105  else // these are the bin boundaries
106  segmentationSurfacesX.push_back(std::shared_ptr<const Trk::PlaneSurface>(new Trk::PlaneSurface(binTransform,&*xBinBounds)));
107  }
108 
109  // (C) - bin Y surfaces - everything is defined -----------------------------------------------------------
110  // now the rotation matrix for the yBins - anticyclic
111  Amg::RotationMatrix3D yBinRotationMatrix;
112  yBinRotationMatrix.col(0) = Amg::Vector3D::UnitX();
113  yBinRotationMatrix.col(1) = Amg::Vector3D::UnitZ();
114  yBinRotationMatrix.col(2) = Amg::Vector3D(0.,-1.,0.);
115  // easy stuff first, constant pitch in Y
116  double pitchY = 2.*m_activeBounds->halflengthY()/m_binsY;
117  // reserve, it's always (number of bins-1) as the boundaries are within the boundarySurfaces
118  segmentationSurfacesY.reserve(m_binsY);
119  for (size_t ibiny = 0; ibiny <= m_binsY; ++ibiny){
120  // the position of the bin surface
121  double binPosY = -m_activeBounds->halflengthY()+ibiny*pitchY;
122  Amg::Vector3D binSurfaceCenter(0.,binPosY,0.);
123  double localPitchX = PitchX(Amg::Vector2D(0., binPosY));
124  std::unique_ptr<Trk::RectangleBounds> yBinBounds(new Trk::RectangleBounds(localPitchX*m_binsX*0.5,halfThickness));
125  Amg::Transform3D binTransform(Amg::getTransformFromRotTransl(yBinRotationMatrix,binSurfaceCenter));
126  // these are the boundaries
127  if (ibiny == 0 || ibiny == m_binsY)
128  boundarySurfaces.push_back(std::make_shared<Trk::PlaneSurface>(binTransform,&*yBinBounds));
129  else // these are the bin boundaries
130  segmentationSurfacesY.push_back(std::make_shared<Trk::PlaneSurface>(binTransform,&*yBinBounds));
131  }
132 }
133 
134 
136 {
137  // use the bin utility for this job
138  double bX = (m_binsX>1) ? m_binUtility->binPosition(projectLocX(Amg::Vector2D(dCell.first, dCell.second)),0.,0) : 0.;
139  double bY = (m_binsY>1) ? m_binUtility->binPosition(dCell.second,0.,1) : 0.;
140  return Amg::Vector2D(bX,bY);
141 }
142 
143 
146  const Amg::Vector3D& endStep,
147  double halfThickness,
148  int readoutDirection,
149  double lorentzAngle) const
150 {
151 
152  Amg::Vector3D stepCenter = 0.5*(startStep+endStep);
153  // project to parameter surface
154  double lorentzDeltaX = -readoutDirection*stepCenter.z()*std::tan(lorentzAngle);
155  // take the full drift length
156  double driftInZ = (halfThickness-readoutDirection*stepCenter.z());
157  double driftLength = std::abs(driftInZ/std::cos(lorentzAngle));
158  // the projected center
159  Amg::Vector2D stepCenterProjected(stepCenter.x()+lorentzDeltaX,stepCenter.y());
160  // the cell & its center
161  Trk::DigitizationCell dCell = cell(stepCenterProjected);
162  Amg::Vector2D cellCenter = cellPosition(dCell);
163  // we are ready to return what we have
164  return Trk::DigitizationStep((endStep-startStep).mag(),driftLength,dCell,startStep,endStep,stepCenterProjected,cellCenter);
165 }
166 
167 
168 
169 
170 
Trk::TrapezoidSegmentation::numCellsY
size_t numCellsY() const
Return the simple binning parameters.
Definition: TrapezoidSegmentation.h:113
TrapezoidBounds.h
Trk::RectangleBounds
Definition: RectangleBounds.h:38
Trk::TrapezoidSegmentation::m_activeBounds
std::shared_ptr< const TrapezoidBounds > m_activeBounds
Definition: TrapezoidSegmentation.h:102
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
RectangleBounds.h
Trk::TrapezoidSegmentation::~TrapezoidSegmentation
virtual ~TrapezoidSegmentation()
Virtual Destructor.
Definition: TrapezoidSegmentation.cxx:43
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Trk::TrapezoidSegmentation::numCellsX
size_t numCellsX() const
Return the simple binning parameters.
Definition: TrapezoidSegmentation.h:111
Trk::TrapezoidSegmentation::cellPosition
const Amg::Vector2D cellPosition(const DigitizationCell &cId) const override
calculate the cell Position from the Id
Definition: TrapezoidSegmentation.cxx:135
Trk::TrapezoidSegmentation::m_binUtility
BinUtility * m_binUtility
Definition: TrapezoidSegmentation.h:103
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
TrapezoidSegmentation.h
Trk::DigitizationCell
std::pair< size_t, size_t > DigitizationCell
Definition: DigitizationCell.h:18
Amg::getTransformFromRotTransl
Amg::Transform3D getTransformFromRotTransl(Amg::RotationMatrix3D rot, Amg::Vector3D transl_vec)
Definition: GeoPrimitivesHelpers.h:172
Trk::binY
@ binY
Definition: BinningType.h:48
Trk::TrapezoidSegmentation::TrapezoidSegmentation
TrapezoidSegmentation(std::shared_ptr< const Trk::TrapezoidBounds >, size_t numCellsX, size_t numCellsY=1)
Constructor for all same-size pixels or strips (in case numCellsY is set to 1)
Definition: TrapezoidSegmentation.cxx:22
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
Trk::binX
@ binX
Definition: BinningType.h:47
SharedObject.h
Trk::DigitizationStep
Definition: DigitizationCell.h:21
Trk::BinUtility
Definition: BinUtility.h:39
Trk::TrapezoidSegmentation::createSegmenationSurfaces
void createSegmenationSurfaces(std::vector< std::shared_ptr< const Surface > > &boundarySurfaces, std::vector< std::shared_ptr< const Surface > > &segmentationSurfacesX, std::vector< std::shared_ptr< const Surface > > &segmentationSurfacesY, double halfThickness, int readoutDirection=1., double lorentzAngle=0.) const override
Create the segmentation surfaces in X.
Definition: TrapezoidSegmentation.cxx:48
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::TrapezoidBounds
Definition: TrapezoidBounds.h:43
Trk::open
@ open
Definition: BinningType.h:40
Trk::TrapezoidSegmentation::digitizationStep
const DigitizationStep digitizationStep(const Amg::Vector3D &start, const Amg::Vector3D &end, double halfThickness, int readoutDirection=1, double lorentzAngle=0.) const override
Fill the associated digitisation cell from this start and end position, correct for lorentz effect if...
Definition: TrapezoidSegmentation.cxx:145
Trk::SharedObject
std::shared_ptr< T > SharedObject
Definition: SharedObject.h:24
Trk::PlaneSurface
Definition: PlaneSurface.h:64
Amg::RotationMatrix3D
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Definition: GeoPrimitives.h:49
PlaneSurface.h
GeoPrimitivesHelpers.h
Amg::AngleAxis3D
Eigen::AngleAxisd AngleAxis3D
Definition: GeoPrimitives.h:45
mag
Scalar mag() const
mag method
Definition: AmgMatrixBasePlugin.h:26