CMS 3D CMS Logo

RectangularMTDTopology.cc
Go to the documentation of this file.
2 
6 // Modified for the large pixles.
7 // Danek Kotlinski & Michele Pioppi, 3/06.
8 // See documentation in the include file.
9 
10 //--------------------------------------------------------------------
11 // Calculate the edge of the active sensor with respect to the center,
12 // that is simply the half-size.
13 // Take into account large pixels
14 void RectangularMTDTopology::setOffset(const int& BIG_PIX_PER_ROC_X,
15  const int& BIG_PIX_PER_ROC_Y,
16  const int& ROWS_PER_ROC,
17  const int& COLS_PER_ROC) {
18  m_xoffset = -(m_nrows + BIG_PIX_PER_ROC_X * m_nrows / ROWS_PER_ROC) / 2. * m_pitchx;
19  m_yoffset = -(m_ncols + BIG_PIX_PER_ROC_Y * m_ncols / COLS_PER_ROC) / 2. * m_pitchy;
20 
21  LogDebug("RectangularMTDTopology") << "nrows " << m_nrows << ", ncols " << m_ncols << ", pitchx " << m_pitchx
22  << ", pitchy " << m_pitchy << ", xoffset " << m_xoffset << ", yoffset "
23  << m_yoffset << ", BIG_PIX_PER_ROC_X " << BIG_PIX_PER_ROC_X
24  << ", BIG_PIX_PER_ROC_Y " << BIG_PIX_PER_ROC_Y << ", ROWS_PER_ROC " << ROWS_PER_ROC
25  << ", COLS_PER_ROC " << COLS_PER_ROC << ", ROCS_X " << m_ROCS_X << ", ROCS_Y "
26  << m_ROCS_Y << "\nNROWS " << m_ROWS_PER_ROC * m_ROCS_X << ", NCOL "
28 }
29 
30 //--------------------------------------------------------------------
31 // PixelTopology interface.
32 // Transform LocalPoint in cm to measurement in pitch units.
33 std::pair<float, float> RectangularMTDTopology::pixel(const LocalPoint& p) const {
34  // check limits
35  float py = p.y();
36  float px = p.x();
37 
38  LogDebug("RectangularMTDTopology").log([&](auto& debugstr) {
39 #define EPSCM 0
40 #define EPS 0
41  // This will catch points which are outside the active sensor area.
42  // In the digitizer during the early induce_signal phase non valid
43  // location are passed here. They are cleaned later.
44  debugstr << "py = " << py << ", m_yoffset = " << m_yoffset << "px = " << px << ", m_xoffset = " << m_xoffset
45  << "\n";
46 
47  if (py < m_yoffset) // m_yoffset is negative
48  {
49  debugstr << " wrong lp y " << py << " " << m_yoffset << "\n";
50  py = m_yoffset + EPSCM; // make sure it is in, add an EPS in cm
51  }
52  if (py > -m_yoffset) {
53  debugstr << " wrong lp y " << py << " " << -m_yoffset << "\n";
54  py = -m_yoffset - EPSCM;
55  }
56  if (px < m_xoffset) // m_xoffset is negative
57  {
58  debugstr << " wrong lp x " << px << " " << m_xoffset << "\n";
59  px = m_xoffset + EPSCM;
60  }
61  if (px > -m_xoffset) {
62  debugstr << " wrong lp x " << px << " " << -m_xoffset << "\n";
63  px = -m_xoffset - EPSCM;
64  }
65  });
66 
67  float newybin = (py - m_yoffset) / m_pitchy;
68  int iybin = int(newybin);
69  float fractionY = newybin - iybin;
70 
71  // Normalize it all to 1 ROC
72  int iybin0 = 0;
73  int numROC = 0;
74  float mpY = 0.;
75 
76  if (m_upgradeGeometry) {
77  iybin0 = (iybin % m_COLS_PER_ROC); // 0-51
78  numROC = iybin / m_COLS_PER_ROC; // 0-7
79  mpY = float(numROC * m_COLS_PER_ROC + iybin0) + fractionY;
80 
81 #ifdef EDM_ML_DEBUG
82 
83  if (iybin0 > m_COLS_PER_ROC) {
84  LogDebug("RectangularMTDTopology") << " very bad, newbiny " << iybin0 << "\n"
85  << py << " " << m_yoffset << " " << m_pitchy << " " << newybin << " " << iybin
86  << " " << fractionY << " " << iybin0 << " " << numROC;
87  }
88 #endif // EDM_ML_DEBUG
89 
90  } else {
91  iybin0 = (iybin % 54); // 0-53
92  numROC = iybin / 54; // 0-7
93 
94  if (iybin0 == 53) { // inside big pixel
95  iybin0 = 51;
96  fractionY = (fractionY + 1.) / 2.;
97  } else if (iybin0 == 52) { // inside big pixel
98  iybin0 = 51;
99  fractionY = fractionY / 2.;
100  } else if (iybin0 > 1) { // inside normal pixel
101  iybin0 = iybin0 - 1;
102  } else if (iybin0 == 1) { // inside big pixel
103  iybin0 = 0;
104  fractionY = (fractionY + 1.) / 2.;
105  } else if (iybin0 == 0) { // inside big pixel
106  iybin0 = 0;
107  fractionY = fractionY / 2.;
108  }
109 
110  mpY = float(numROC * 52. + iybin0) + fractionY;
111  }
112 
113 #ifdef EDM_ML_DEBUG
114 
115  if (mpY < 0. || mpY >= 416.) {
116  LogDebug("RectangularMTDTopology") << " bad pix y " << mpY << "\n"
117  << py << " " << m_yoffset << " " << m_pitchy << " " << newybin << " " << iybin
118  << " " << fractionY << " " << iybin0 << " " << numROC;
119  }
120 #endif // EDM_ML_DEBUG
121 
122  // In X
123  float newxbin = (px - m_xoffset) / m_pitchx;
124  int ixbin = int(newxbin);
125  float fractionX = newxbin - ixbin;
126 
127 #ifdef EDM_ML_DEBUG
128 
129  if (ixbin > 161 || ixbin < 0) // ixbin < 0 outside range
130  {
131  LogDebug("RectangularMTDTopology") << " very bad, newbinx " << ixbin << "\n"
132  << px << " " << m_xoffset << " " << m_pitchx << " " << newxbin << " " << ixbin
133  << " " << fractionX;
134  }
135 #endif // EDM_ML_DEBUG
136 
137  if (!m_upgradeGeometry) {
138  if (ixbin > 82) { // inside normal pixel, ROC 1
139  ixbin = ixbin - 2;
140  } else if (ixbin == 82) { // inside bin pixel
141  ixbin = 80;
142  fractionX = (fractionX + 1.) / 2.;
143  } else if (ixbin == 81) { // inside big pixel
144  ixbin = 80;
145  fractionX = fractionX / 2.;
146  } else if (ixbin == 80) { // inside bin pixel, ROC 0
147  ixbin = 79;
148  fractionX = (fractionX + 1.) / 2.;
149  } else if (ixbin == 79) { // inside big pixel
150  ixbin = 79;
151  fractionX = fractionX / 2.;
152  }
153  }
154 
155  float mpX = float(ixbin) + fractionX;
156 
157 #ifdef EDM_ML_DEBUG
158 
159  if (mpX < 0. || mpX >= 160.) {
160  LogDebug("RectangularMTDTopology") << " bad pix x " << mpX << "\n"
161  << px << " " << m_xoffset << " " << m_pitchx << " " << newxbin << " " << ixbin
162  << " " << fractionX;
163  }
164 #endif // EDM_ML_DEBUG
165 
166  return std::pair<float, float>(mpX, mpY);
167 }
168 
169 //----------------------------------------------------------------------
170 // Topology interface, go from Measurement to Local corrdinates
171 // pixel coordinates (mp) -> cm (LocalPoint)
173  float mpy = mp.y(); // measurements
174  float mpx = mp.x();
175 
176 #ifdef EDM_ML_DEBUG
177 #define EPS 0
178  // check limits
179  std::ostringstream debugstr;
180 
181  if (mpy < 0.) {
182  debugstr << " wrong mp y, fix " << mpy << " " << 0 << "\n";
183  mpy = 0.;
184  }
185  if (mpy >= m_ncols) {
186  debugstr << " wrong mp y, fix " << mpy << " " << m_ncols << "\n";
187  mpy = float(m_ncols) - EPS; // EPS is a small number
188  }
189  if (mpx < 0.) {
190  debugstr << " wrong mp x, fix " << mpx << " " << 0 << "\n";
191  mpx = 0.;
192  }
193  if (mpx >= m_nrows) {
194  debugstr << " wrong mp x, fix " << mpx << " " << m_nrows << "\n";
195  mpx = float(m_nrows) - EPS; // EPS is a small number
196  }
197  if (!debugstr.str().empty())
198  LogDebug("RectangularMTDTopology") << debugstr.str();
199 #endif // EDM_ML_DEBUG
200 
201  float lpY = localY(mpy);
202  float lpX = localX(mpx);
203 
204  // Return it as a LocalPoint
205  return LocalPoint(lpX, lpY);
206 }
207 
208 //--------------------------------------------------------------------
209 //
210 // measuremet to local transformation for X coordinate
211 // X coordinate is in the ROC row number direction
212 float RectangularMTDTopology::localX(const float mpx) const {
213  int binoffx = int(mpx); // truncate to int
214  float fractionX = mpx - float(binoffx); // find the fraction
215  float local_pitchx = m_pitchx; // defaultpitch
216 
217  if
219 #ifdef EDM_ML_DEBUG
220  if (binoffx > m_ROWS_PER_ROC * m_ROCS_X) // too large
221  {
222  LogDebug("RectangularMTDTopology")
223  << " very bad, binx " << binoffx << "\n"
224  << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " " << m_xoffset << "\n";
225  }
226 #endif
227  }
228  else {
229  if (binoffx > 80) { // ROC 1 - handles x on edge cluster
230  binoffx = binoffx + 2;
231  } else if (binoffx == 80) { // ROC 1
232  binoffx = binoffx + 1;
233  local_pitchx *= 2;
234  } else if (binoffx == 79) { // ROC 0
235  binoffx = binoffx + 0;
236  local_pitchx *= 2;
237  }
238  // else if (binoffx>=0) { // ROC 0
239  // binoffx=binoffx+0;
240  // }
241 
242 #ifdef EDM_ML_DEBUG
243  if (binoffx < 0) // too small
244  LogDebug("RectangularMTDTopology") << " very bad, binx " << binoffx << "\n"
245  << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " "
246  << m_xoffset;
247 #endif
248  }
249 
250  // The final position in local coordinates
251  float lpX = float(binoffx * m_pitchx) + fractionX * local_pitchx + m_xoffset;
252 
253 #ifdef EDM_ML_DEBUG
254 
255  if (lpX < m_xoffset || lpX > (-m_xoffset)) {
256  LogDebug("RectangularMTDTopology") << " bad lp x " << lpX << "\n"
257  << mpx << " " << binoffx << " " << fractionX << " " << local_pitchx << " "
258  << m_xoffset;
259  }
260 #endif // EDM_ML_DEBUG
261 
262  return lpX;
263 }
264 
265 // measuremet to local transformation for Y coordinate
266 // Y is in the ROC column number direction
267 float RectangularMTDTopology::localY(const float mpy) const {
268  int binoffy = int(mpy); // truncate to int
269  float fractionY = mpy - float(binoffy); // find the fraction
270  float local_pitchy = m_pitchy; // defaultpitch
271 
272  if
274 #ifdef EDM_ML_DEBUG
275  if (binoffy > m_ROCS_Y * m_COLS_PER_ROC) // too large
276  {
277  LogDebug("RectangularMTDTopology")
278  << " very bad, biny " << binoffy << "\n"
279  << mpy << " " << binoffy << " " << fractionY << " " << local_pitchy << " " << m_yoffset;
280  }
281 #endif
282  }
283  else { // 415 is last big pixel, 416 and above do not exists!
284  constexpr int bigYIndeces[]{0, 51, 52, 103, 104, 155, 156, 207, 208, 259, 260, 311, 312, 363, 364, 415, 416, 511};
285  auto const j = std::lower_bound(std::begin(bigYIndeces), std::end(bigYIndeces), binoffy);
286  if (*j == binoffy)
287  local_pitchy *= 2;
288  binoffy += (j - bigYIndeces);
289  }
290 
291  // The final position in local coordinates
292  float lpY = float(binoffy * m_pitchy) + fractionY * local_pitchy + m_yoffset;
293 
294 #ifdef EDM_ML_DEBUG
295 
296  if (lpY < m_yoffset || lpY > (-m_yoffset)) {
297  LogDebug("RectangularMTDTopology") << " bad lp y " << lpY << "\n"
298  << mpy << " " << binoffy << " " << fractionY << " " << local_pitchy << " "
299  << m_yoffset;
300  }
301 #endif // EDM_ML_DEBUG
302 
303  return lpY;
304 }
305 
307 // Get hit errors in LocalPoint coordinates (cm)
309  float pitchy = m_pitchy;
310  int binoffy = int(mp.y());
311  if (isItBigPixelInY(binoffy))
312  pitchy = 2. * m_pitchy;
313 
314  float pitchx = m_pitchx;
315  int binoffx = int(mp.x());
316  if (isItBigPixelInX(binoffx))
317  pitchx = 2. * m_pitchx;
318 
319  return LocalError(me.uu() * float(pitchx * pitchx), 0, me.vv() * float(pitchy * pitchy));
320 }
321 
323 // Get errors in pixel pitch units.
325  float pitchy = m_pitchy;
326  float pitchx = m_pitchx;
327 
328  if
330  int iybin = int((lp.y() - m_yoffset) / m_pitchy); //get bin for equal picth
331  int iybin0 = iybin % 54; //This is just to avoid many ifs by using the periodicy
332  //quasi bins 0,1,52,53 fall into larger pixels
333  if ((iybin0 <= 1) | (iybin0 >= 52))
334  pitchy = 2.f * m_pitchy;
335 
336  int ixbin = int((lp.x() - m_xoffset) / m_pitchx); //get bin for equal pitch
337  //quasi bins 79,80,81,82 fall into the 2 larger pixels
338  if ((ixbin >= 79) & (ixbin <= 82))
339  pitchx = 2.f * m_pitchx;
340  }
341 
342  return MeasurementError(le.xx() / float(pitchx * pitchx), 0, le.yy() / float(pitchy * pitchy));
343 }
Point2DBase
Definition: Point2DBase.h:9
RectangularMTDTopology::m_ROCS_Y
int m_ROCS_Y
Definition: RectangularMTDTopology.h:189
RectangularMTDTopology::m_pitchy
float m_pitchy
Definition: RectangularMTDTopology.h:181
RectangularMTDTopology::m_ncols
int m_ncols
Definition: RectangularMTDTopology.h:185
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
RectangularMTDTopology::isItBigPixelInX
bool isItBigPixelInX(const int ixbin) const override
Definition: RectangularMTDTopology.h:126
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
EPSCM
#define EPSCM
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
RectangularMTDTopology::pixel
std::pair< float, float > pixel(const LocalPoint &p) const override
Definition: RectangularMTDTopology.cc:33
hcal_dqm_sourceclient-live_cfg.debugstr
debugstr
Definition: hcal_dqm_sourceclient-live_cfg.py:18
RectangularMTDTopology::localY
float localY(const float mpY) const override
Definition: RectangularMTDTopology.cc:267
align::LocalPoint
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
EPS
#define EPS
RectangularMTDTopology::localPosition
LocalPoint localPosition(const MeasurementPoint &mp) const override
Definition: RectangularMTDTopology.cc:172
end
#define end
Definition: vmac.h:39
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
LocalError::xx
float xx() const
Definition: LocalError.h:22
RectangularMTDTopology::m_xoffset
float m_xoffset
Definition: RectangularMTDTopology.h:182
MeasurementError
Definition: MeasurementError.h:8
RectangularMTDTopology.h
Point3DBase< float, LocalTag >
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
RectangularMTDTopology::setOffset
void setOffset(const int &BIG_PIX_PER_ROC_X, const int &BIG_PIX_PER_ROC_Y, const int &ROWS_PER_ROC, const int &COLS_PER_ROC)
Definition: RectangularMTDTopology.cc:14
RectangularMTDTopology::m_upgradeGeometry
bool m_upgradeGeometry
Definition: RectangularMTDTopology.h:190
RectangularMTDTopology::localError
LocalError localError(const MeasurementPoint &, const MeasurementError &) const override
Definition: RectangularMTDTopology.cc:308
RectangularMTDTopology::m_pitchx
float m_pitchx
Definition: RectangularMTDTopology.h:180
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
LocalError
Definition: LocalError.h:12
PV2DBase::y
T y() const
Definition: PV2DBase.h:44
PV2DBase::x
T x() const
Definition: PV2DBase.h:43
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
createfilelist.int
int
Definition: createfilelist.py:10
RectangularMTDTopology::m_ROCS_X
int m_ROCS_X
Definition: RectangularMTDTopology.h:188
RectangularMTDTopology::isItBigPixelInY
bool isItBigPixelInY(const int iybin) const override
Definition: RectangularMTDTopology.h:130
RectangularMTDTopology::measurementError
MeasurementError measurementError(const LocalPoint &, const LocalError &) const override
Definition: RectangularMTDTopology.cc:324
RectangularMTDTopology::localX
float localX(const float mpX) const override
Definition: RectangularMTDTopology.cc:212
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
RectangularMTDTopology::m_nrows
int m_nrows
Definition: RectangularMTDTopology.h:184
LIKELY
#define LIKELY(x)
Definition: Likely.h:20
RectangularMTDTopology::m_yoffset
float m_yoffset
Definition: RectangularMTDTopology.h:183
RectangularMTDTopology::m_ROWS_PER_ROC
int m_ROWS_PER_ROC
Definition: RectangularMTDTopology.h:186
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:56
LocalError::yy
float yy() const
Definition: LocalError.h:24
begin
#define begin
Definition: vmac.h:32
RectangularMTDTopology::m_COLS_PER_ROC
int m_COLS_PER_ROC
Definition: RectangularMTDTopology.h:187