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