ATLAS Offline Software
PixelDiodeMap.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // PixelDiodeMap.cxx
7 // Implementation file for class PixelDiodeMap
9 // (c) ATLAS Pixel Detector software
11 // Version 4.2 14/08/2001 David Calvet
12 // Modified: Grant Gorfine
14 
18 
19 #include <algorithm>
20 #include <cmath>
21 #include <utility>
22 
23 namespace InDetDD {
24 
25 
26 
27 // Implicit constructor:
28 PixelDiodeMap::PixelDiodeMap(std::shared_ptr<const PixelDiodeMatrix> matrix) :
29  m_matrix(std::move(matrix)),
30  m_generalLayout(false)
31 {
32 }
33 
35 = default;
36 
37 
39 {
40  using std::abs;
41  using Trk::distPhi;
42  using Trk::distEta;
43 
44  // Check that we are in the bounds of the top level matrix
45  // NB. edge is included in bounds.
46 
47  double halfWidth = 0.5*width();
48  double halfLength = 0.5*length();
49  if ( (abs(localPos[distPhi]) > halfWidth) ||
50  (abs(localPos[distEta]) > halfLength) ) {
51  return {}; // Invalid Id.
52  }
53 
54  // position relative to bottom left corner.
55  Amg::Vector2D relativePos = localPos + Amg::Vector2D(halfWidth, halfLength);
56 
57  // The cellId returned will be added to this so we must start with 0,0.
58  SiCellId cellId(0,0);
59 
60  const PixelDiodeMatrix *cell = m_matrix->cellIdOfPosition(relativePos, cellId);
61  // return invalid Id if there was a problem (don't expect this to be the case).
62  if (cell==nullptr) {
63  return {}; // Invalid id.
64  }
65 
66  return cellId;
67 
68 }
69 
70 
71 // Get diodes parameters (position and size):
73 PixelDiodeMap::parameters(const SiCellId & cellId) const
74 {
75 
76  // Check we are in range
77 
78  if (!cellId.isValid() ||
79  (cellId.phiIndex() < 0) ||
80  (cellId.phiIndex() >= m_matrix->phiCells()) ||
81  (cellId.etaIndex() < 0) ||
82  (cellId.etaIndex() >= m_matrix->etaCells())) {
83  return {};
84  }
85 
86  double halfWidth = 0.5*width();
87  double halfLength = 0.5*length();
88 
89  //
90  // Position is relative to left bottom corner.
91  //
92  Amg::Vector2D position(-halfWidth, -halfLength);
93  const PixelDiodeMatrix *cell = m_matrix->positionOfCell(cellId, position);
94  if (cell != nullptr) {
95 
96  // get size
97  Amg::Vector2D size(cell->phiWidth(), cell->etaWidth());
98 
99  // return parameters
100  return SiDiodesParameters(position,size);
101  }
102 
103  // return something in case of failure.
104  return {};
105 }
106 
108  std::vector<SiCellId> &neighbours) const
109 {
110  neighbours.clear();
111 
112  if (!cellId.isValid()) return;
113 
114  // If non regular layout revert to slower method
115  if (m_generalLayout) return neighboursOfCellGeneral(cellId, neighbours);
116 
117  neighbours.reserve(8);
118  // neighbours easily determined from cell number
119  // normally 8 neighbours 4 edge and 4 corners
120 
121  int phiIndex = cellId.phiIndex();
122  int etaIndex = cellId.etaIndex();
123 
124  // M = minus
125  // P = plus
126  int phiM = phiIndex-1;
127  int phiP = phiIndex+1;
128  int etaM = etaIndex-1;
129  int etaP = etaIndex+1;
130 
131  // -,0
132  if (phiM >= 0) neighbours.emplace_back(phiM,etaIndex);
133  // -,-
134  if (phiM >= 0 && etaM >= 0) neighbours.emplace_back(phiM,etaM);
135  // 0,-
136  if (etaM >= 0) neighbours.emplace_back(phiIndex,etaM);
137  // +,-
138  if (phiP < phiDiodes() && etaM >= 0) neighbours.emplace_back(phiP,etaM);
139  // +,0
140  if (phiP < phiDiodes()) neighbours.emplace_back(phiP,etaIndex);
141  // -,+
142  if (phiM >= 0 && etaP < etaDiodes()) neighbours.emplace_back(phiM,etaP);
143  // 0,+
144  if (etaP < etaDiodes()) neighbours.emplace_back(phiIndex,etaP);
145  // +,+
146  if (phiP < phiDiodes() && etaP < etaDiodes()) neighbours.emplace_back(phiP,etaP);
147 }
148 
149 // Get the neighbouring PixelDiodes of a given PixelDiode:
150 // This will work for more complex layouts such as bricking. Probably never really needed but
151 // since the code was here I keep it available.
153  std::vector<SiCellId> &neighbours) const
154 {
155  // extract the diode spatial parameters
156  const SiDiodesParameters params=parameters(cellId);
157  const SiLocalPosition diodeCenter=params.centre();
158  const SiLocalPosition diodeSize=params.width();
159  const double &centerColumn=diodeCenter.xColumn();
160  const double &centerRow=diodeCenter.xRow();
161  const double halfSizeColumn=diodeSize.xColumn()/2;
162  const double halfSizeRow=diodeSize.xRow()/2;
163 
164  // parameter
165  const double epsilon=0.01;
166 
167  // compute the points to check
168  const double left1=centerColumn-halfSizeColumn*(1+epsilon);
169  const double right1=centerColumn+halfSizeColumn*(1+epsilon);
170  const double left2=centerColumn-halfSizeColumn*(1-epsilon);
171  const double right2=centerColumn+halfSizeColumn*(1-epsilon);
172  const double top1=centerRow+halfSizeRow*(1+epsilon);
173  const double bot1=centerRow-halfSizeRow*(1+epsilon);
174  const double top2=centerRow+halfSizeRow*(1-epsilon);
175  const double bot2=centerRow-halfSizeRow*(1-epsilon);
176 
177  // build the list of positions to check
178  std::vector<SiLocalPosition> positions;
179  positions.reserve(12);
180  SiLocalPosition position;
181  position.xRow(bot1); position.xColumn(left2); positions.push_back(position);
182  position.xRow(bot1); position.xColumn(left1); positions.push_back(position);
183  position.xRow(bot2); position.xColumn(left1); positions.push_back(position);
184  position.xRow(top2); position.xColumn(left1); positions.push_back(position);
185  position.xRow(top1); position.xColumn(left1); positions.push_back(position);
186  position.xRow(top1); position.xColumn(left2); positions.push_back(position);
187  position.xRow(bot1); position.xColumn(right2); positions.push_back(position);
188  position.xRow(bot1); position.xColumn(right1); positions.push_back(position);
189  position.xRow(bot2); position.xColumn(right1); positions.push_back(position);
190  position.xRow(top2); position.xColumn(right1); positions.push_back(position);
191  position.xRow(top1); position.xColumn(right1); positions.push_back(position);
192  position.xRow(top1); position.xColumn(right2); positions.push_back(position);
193 
194  // build the list of neighbours
195  neighbours.reserve(8);
196 
197  // loop on all positions to check
198  for(const auto & position : positions) {
199 
200  // get the PixelDiode for this position
201  SiCellId cellId_neighb = cellIdOfPosition(position);
202 
203  if (cellId.isValid()) {
204  // check if the diode is already in the list
205  //bool found=false;
206  std::vector<SiCellId>::const_iterator foundIter
207  = std::find(neighbours.begin(), neighbours.end(), cellId_neighb );
208 
209  // If not found add this diode to the list
210  if (foundIter == neighbours.end()) neighbours.push_back(cellId_neighb);
211 
212  }
213  }
214 }
215 
216 
217 // Compute the intersection length of two diodes:
219  const SiCellId &diode2) const
220 {
221  if(!diode1.isValid() || !diode2.isValid()) return 0;
222  // If non regular layout revert to slower method
223  if (m_generalLayout) return intersectionLengthGeneral(diode1, diode2);
224 
225  const SiLocalPosition size = parameters(diode1).width();
226 
227  int phiIndexDelta = std::abs(diode1.phiIndex() - diode2.phiIndex());
228  int etaIndexDelta = std::abs(diode1.etaIndex() - diode2.etaIndex());
229 
230  // Intersection length is just the length or width of the diode depending on which neighbour.
231  if (phiIndexDelta == 1 && etaIndexDelta == 0) return size.xEta();
232  if (phiIndexDelta == 0 && etaIndexDelta == 1) return size.xPhi();
233  // Will return 0 if it is a corner neighbour or if its not a neighbour or if they are oth the same diode.
234  return 0;
235 }
236 
237 // Compute the intersection length of two diodes:
238 // This will work for more complex layouts such as bricking. Probably never really needed but
239 // since the code was here I keep it available.
241  const SiCellId &diode2) const
242 
243 {
244  const SiDiodesParameters params1=parameters(diode1);
245  const SiDiodesParameters params2=parameters(diode2);
246  const SiLocalPosition center1=params1.centre();
247  const SiLocalPosition center2=params2.centre();
248  const SiLocalPosition size1=params1.width();
249  const SiLocalPosition size2=params2.width();
250 
251  // compute intersection length on column direction
252  const double intersectionColumn=intersectionLength1D(center1.xColumn(),
253  size1.xColumn(),
254  center2.xColumn(),
255  size2.xColumn());
256  // compute intersection length on row direction
257  const double intersectionRow=intersectionLength1D(center1.xRow(),
258  size1.xRow(),
259  center2.xRow(),
260  size2.xRow());
261 
262  // return the real intersection
263  // (if both directions intersect, there is a problem)
264  if (intersectionColumn>0) {
265  if (intersectionRow>0) return 0;
266  return intersectionColumn;
267  } else {
268  return intersectionRow;
269  }
270 }
271 
272 // Compute the intersection length along one direction:
273 double PixelDiodeMap::intersectionLength1D(const double x1,const double dx1,
274  const double x2,const double dx2)
275 {
276  // compute distance between the two centers
277  double distance=std::abs(x1-x2);
278 
279  // compute theoretical intersection
280  double intersection=(dx1+dx2)/2-distance;
281 
282  // if intersection if negative, no intersection
283  if (intersection<-1e-10) return intersection;
284  else if (intersection<1e-10) return 0;
285  else {
286  // intersection cannot exceed size
287  if (intersection>dx1) intersection=dx1;
288  if (intersection>dx2) intersection=dx2;
289  return intersection;
290  }
291 }
292 
293 } // namespace InDetDD
294 
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
InDetDD::PixelDiodeMap::intersectionLength
double intersectionLength(const SiCellId &diode1, const SiCellId &diode2) const
Compute the intersection length of two diodes: return: the intersection length when the two diodes ar...
Definition: PixelDiodeMap.cxx:218
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
InDetDD::PixelDiodeMap::parameters
SiDiodesParameters parameters(const SiCellId &diodeId) const
Get diodes parameters (position and size):
Definition: PixelDiodeMap.cxx:73
InDetDD::PixelDiodeMap::m_matrix
std::shared_ptr< const PixelDiodeMatrix > m_matrix
diode matrix
Definition: PixelDiodeMap.h:136
InDetDD::PixelDiodeMap::width
double width() const
Definition: PixelDiodeMap.h:149
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
InDetDD::SiCellId::isValid
bool isValid() const
Test if its in a valid state.
Definition: SiCellId.h:136
InDetDD::PixelDiodeMap::intersectionLength1D
static double intersectionLength1D(const double x1, const double dx1, const double x2, const double dx2)
Compute the intersection length along one direction: return 0 if no intersection x1,...
Definition: PixelDiodeMap.cxx:273
InDetDD::PixelDiodeMap::m_generalLayout
bool m_generalLayout
Flag set to allow for dealing wth more general layouts.
Definition: PixelDiodeMap.h:137
InDetDD::SiCellId::phiIndex
int phiIndex() const
Get phi index. Equivalent to strip().
Definition: SiCellId.h:122
intersection
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
Definition: compareFlatTrees.cxx:25
InDetDD::PixelDiodeMap::~PixelDiodeMap
~PixelDiodeMap()
Destructor.
InDetDD::SiLocalPosition::xColumn
double xColumn() const
positions for Pixel:
Definition: SiLocalPosition.h:143
InDetDD::SiLocalPosition
Definition: SiLocalPosition.h:31
InDetDD::PixelDiodeMap::etaDiodes
int etaDiodes() const
Definition: PixelDiodeMap.h:184
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
InDetDD::SiCellId::etaIndex
int etaIndex() const
Get eta index.
Definition: SiCellId.h:114
InDetDD::SiDiodesParameters::centre
SiLocalPosition centre() const
position of the diodes centre:
Definition: SiDiodesParameters.h:91
Trk::distEta
@ distEta
readout for silicon
Definition: ParamDefs.h:57
InDetDD::SiLocalPosition::xRow
double xRow() const
Definition: SiLocalPosition.h:148
InDetDD::PixelDiodeMap::phiDiodes
int phiDiodes() const
Definition: PixelDiodeMap.h:179
Trk::distPhi
@ distPhi
Definition: ParamDefs.h:56
PixelDiodeMap.h
InDetDD::PixelDiodeMap::neighboursOfCellGeneral
void neighboursOfCellGeneral(const SiCellId &cellId, std::vector< SiCellId > &neighbours) const
Slower method.
Definition: PixelDiodeMap.cxx:152
InDetDD::PixelDiodeMap::PixelDiodeMap
PixelDiodeMap(std::shared_ptr< const PixelDiodeMatrix > diodeMatrix)
Constructor from Diode matrix description.
Definition: PixelDiodeMap.cxx:28
InDetDD::SiCellId
Definition: SiCellId.h:29
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
InDetDD::PixelDiodeMap::length
double length() const
Definition: PixelDiodeMap.h:144
PixelDiodeMatrix.h
python.testIfMatch.matrix
matrix
Definition: testIfMatch.py:66
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
InDetDD
Message Stream Member.
Definition: FakeTrackBuilder.h:8
InDetDD::PixelDiodeMap::neighboursOfCell
void neighboursOfCell(const SiCellId &cellId, std::vector< SiCellId > &neighbours) const
Get the neighbouring PixelDiodes of a given PixelDiode: Cell for which the neighbours must be found L...
Definition: PixelDiodeMap.cxx:107
InDetDD::PixelDiodeMap::intersectionLengthGeneral
double intersectionLengthGeneral(const SiCellId &diode1, const SiCellId &diode2) const
Slower method.
Definition: PixelDiodeMap.cxx:240
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
SiCellId.h
InDetDD::PixelDiodeMap::cellIdOfPosition
SiCellId cellIdOfPosition(const Amg::Vector2D &localPosition) const
cell id for a given local position
Definition: PixelDiodeMap.cxx:38
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
InDetDD::SiDiodesParameters::width
SiLocalPosition width() const
width of the diodes:
Definition: SiDiodesParameters.h:96
InDetDD::PixelDiodeMatrix
Definition: PixelDiodeMatrix.h:93
InDetDD::SiDiodesParameters
Definition: SiDiodesParameters.h:25