CMS 3D CMS Logo

PixelCPEClusterRepair.cc
Go to the documentation of this file.
1 // Include our own header first
3 
4 // Geometry services
7 
8 // MessageLogger
10 
11 // Magnetic field
13 
14 
15 // Commented for now (3/10/17) until we figure out how to resuscitate 2D template splitter
17 
19 
20 #include <vector>
21 #include "boost/multi_array.hpp"
22 
23 #include <iostream>
24 
25 using namespace SiPixelTemplateReco;
26 //using namespace SiPixelTemplateSplit;
27 using namespace std;
28 
29 namespace {
30  constexpr float micronsToCm = 1.0e-4;
31  constexpr int cluster_matrix_size_x = 13;
32  constexpr int cluster_matrix_size_y = 21;
33 }
34 
35 //-----------------------------------------------------------------------------
36 // Constructor.
37 //
38 //-----------------------------------------------------------------------------
40  const MagneticField * mag,
41  const TrackerGeometry& geom,
42  const TrackerTopology& ttopo,
43  const SiPixelLorentzAngle * lorentzAngle,
44  const SiPixelTemplateDBObject * templateDBobject,
45  const SiPixel2DTemplateDBObject * templateDBobject2D )
46 : PixelCPEBase(conf, mag, geom, ttopo, lorentzAngle, nullptr, templateDBobject, nullptr,1)
47 {
48  LogDebug("PixelCPEClusterRepair::(constructor)") << endl;
49 
50  //--- Parameter to decide between DB or text file template access
52  {
53  // Initialize template store to the selected ID [Morris, 6/25/08]
55  throw cms::Exception("PixelCPEClusterRepair")
56  << "\nERROR: Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version "
57  << (*templateDBobject_).version() << "\n\n";
58 
59  // Initialize template store to the selected ID [Morris, 6/25/08]
60  if ( !SiPixelTemplate2D::pushfile( *templateDBobject2D , thePixelTemp2D_) )
61  throw cms::Exception("PixelCPEClusterRepair")
62  << "\nERROR: Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version "
63  << (*templateDBobject_).version() << "\n\n";
64  }
65  else
66  {
67  LogDebug("PixelCPEClusterRepair") << "Loading templates for barrel and forward from ASCII files." << endl;
68  //--- (Archaic) Get configurable template IDs. This code executes only if we loading pixels from ASCII
69  // files, and then they are mandatory.
70  barrelTemplateID_ = conf.getParameter<int>( "barrelTemplateID" );
71  forwardTemplateID_ = conf.getParameter<int>( "forwardTemplateID" );
72  templateDir_ = conf.getParameter<int>( "directoryWithTemplates" );
73 
75  throw cms::Exception("PixelCPEClusterRepair")
76  << "\nERROR: Template ID " << barrelTemplateID_ << " not loaded correctly from text file. Reconstruction will fail.\n\n";
77 
78  if ( !SiPixelTemplate::pushfile( forwardTemplateID_ , thePixelTemp_ , templateDir_ ) )
79  throw cms::Exception("PixelCPEClusterRepair")
80  << "\nERROR: Template ID " << forwardTemplateID_ << " not loaded correctly from text file. Reconstruction will fail.\n\n";
81  }
82 
83  speed_ = conf.getParameter<int>( "speed");
84  LogDebug("PixelCPEClusterRepair::PixelCPEClusterRepair:") <<
85  "Template speed = " << speed_ << "\n";
86 
87  UseClusterSplitter_ = conf.getParameter<bool>("UseClusterSplitter");
88 
89 
90  //--- Configure 3D reco.
91  if ( conf.exists("MinProbY") )
92  minProbY_ = conf.getParameter<double>("MinProbY");
93  else
94  minProbY_ = 0.001; // probabilityY < 0.001
95 
96  if ( conf.exists("MaxSizeMismatchInY") )
97  maxSizeMismatchInY_ = conf.getParameter<int>("MaxSizeMismatchInY");
98  else
99  maxSizeMismatchInY_ = 1; // ( templ.clsleny() - nypix > 1)
100 
101 }
102 
103 
104 
105 //-----------------------------------------------------------------------------
106 // Clean up.
107 //-----------------------------------------------------------------------------
109 {
110  for (auto x : thePixelTemp_) x.destroy();
111  for (auto x : thePixelTemp2D_) x.destroy();
112 }
113 
115 {
116  return new ClusterParamTemplate(cl);
117 }
118 
119 
120 
121 //------------------------------------------------------------------
122 // Public methods mandated by the base class.
123 //------------------------------------------------------------------
124 
125 //------------------------------------------------------------------
126 // The main call to the template code.
127 //------------------------------------------------------------------
129 PixelCPEClusterRepair::localPosition(DetParam const & theDetParam, ClusterParam & theClusterParamBase) const
130 {
131 
132  ClusterParamTemplate & theClusterParam = static_cast<ClusterParamTemplate &>(theClusterParamBase);
133  bool filled_from_2d = false;
134 
136  throw cms::Exception("PixelCPEClusterRepair::localPosition :")
137  << "A non-pixel detector type in here?";
138 
139  int ID = -9999;
140  if ( LoadTemplatesFromDB_ ) {
141  int ID0 = templateDBobject_->getTemplateID(theDetParam.theDet->geographicalId()); // just to comapre
142  ID = theDetParam.detTemplateId;
143  if(ID0!=ID) edm::LogError("PixelCPEClusterRepair") <<" different id"<< ID<<" "<<ID0<<endl;
144  } else { // from asci file
145  if ( ! GeomDetEnumerators::isEndcap(theDetParam.thePart) )
146  ID = barrelTemplateID_ ; // barrel
147  else
148  ID = forwardTemplateID_ ; // forward
149  }
150  //cout << "PixelCPEClusterRepair : ID = " << ID << endl;
151 
152  // &&& PM, note for later: PixelCPEBase calculates minInX,Y, and maxInX,Y
153  // Why can't we simply use that and save time with row_offset, col_offset
154  // and mrow = maxInX-minInX, mcol = maxInY-minInY ... Except that we
155  // also need to take into account cluster_matrix_size_x,y.
156 
157 
158  //--- Preparing to retrieve ADC counts from the SiPixeltheClusterParam.theCluster
159  // The pixels from minPixelRow() will go into clust_array_2d[0][*],
160  // and the pixels from minPixelCol() will go into clust_array_2d[*][0].
161  int row_offset = theClusterParam.theCluster->minPixelRow();
162  int col_offset = theClusterParam.theCluster->minPixelCol();
163 
164  //--- Store the coordinates of the center of the (0,0) pixel of the array that
165  // gets passed to PixelTempReco2D. Will add these values to the output of TemplReco2D
166  float tmp_x = float(row_offset) + 0.5f;
167  float tmp_y = float(col_offset) + 0.5f;
168 
169 
170  //--- Store these offsets (to be added later) in a LocalPoint after tranforming
171  // them from measurement units (pixel units) to local coordinates (cm)
172  LocalPoint lp;
173  if ( theClusterParam.with_track_angle )
174  //--- Update call with trk angles needed for bow/kink corrections // Gavril
175  lp = theDetParam.theTopol->localPosition( MeasurementPoint(tmp_x, tmp_y), theClusterParam.loc_trk_pred );
176  else
177  {
178  edm::LogError("PixelCPEClusterRepair")
179  << "@SUB = PixelCPEClusterRepair::localPosition"
180  << "Should never be here. PixelCPEClusterRepair should always be called with track angles. This is a bad error !!! ";
181  lp = theDetParam.theTopol->localPosition( MeasurementPoint(tmp_x, tmp_y) );
182  }
183 
184  //--- Compute the size of the matrix which will be passed to TemplateReco.
185  // We'll later make clustMatrix[ mrow ][ mcol ]
186  int mrow=0, mcol=0;
187  for (int i=0 ; i!=theClusterParam.theCluster->size(); ++i )
188  {
189  auto pix = theClusterParam.theCluster->pixel(i);
190  int irow = int(pix.x);
191  int icol = int(pix.y);
192  mrow = std::max(mrow,irow);
193  mcol = std::max(mcol,icol);
194  }
195  mrow -= row_offset; mrow+=1; mrow = std::min(mrow,cluster_matrix_size_x);
196  mcol -= col_offset; mcol+=1; mcol = std::min(mcol,cluster_matrix_size_y);
197  assert(mrow>0); assert(mcol>0);
198 
199 
200  //--- Make and fill the bool arrays flagging double pixels
201  bool xdouble[mrow], ydouble[mcol];
202  // x directions (shorter), rows
203  for (int irow = 0; irow < mrow; ++irow)
204  xdouble[irow] = theDetParam.theRecTopol->isItBigPixelInX( irow+row_offset );
205  //
206  // y directions (longer), columns
207  for (int icol = 0; icol < mcol; ++icol)
208  ydouble[icol] = theDetParam.theRecTopol->isItBigPixelInY( icol+col_offset );
209 
210  //--- C-style matrix. We'll need it in either case.
211  float clustMatrix[mrow][mcol];
212  float clustMatrix2[mrow][mcol];
213 
214  //--- Prepare struct that passes pointers to TemplateReco. It doesn't own anything.
215  SiPixelTemplateReco::ClusMatrix clusterPayload { &clustMatrix[0][0], xdouble, ydouble, mrow,mcol};
216  SiPixelTemplateReco2D::ClusMatrix clusterPayload2d{ &clustMatrix2[0][0], xdouble, ydouble, mrow,mcol};
217 
218 
219  //--- Copy clust's pixels (calibrated in electrons) into clustMatrix;
220  memset( clustMatrix, 0, sizeof(float)*mrow*mcol ); // Wipe it clean.
221  for (int i=0 ; i!=theClusterParam.theCluster->size(); ++i )
222  {
223  auto pix = theClusterParam.theCluster->pixel(i);
224  int irow = int(pix.x) - row_offset;
225  int icol = int(pix.y) - col_offset;
226  // &&& Do we ever get pixels that are out of bounds ??? Need to check.
227  if ( (irow<mrow) & (icol<mcol) ) clustMatrix[irow][icol] = float(pix.adc);
228  }
229  // &&& Save for later: fillClustMatrix( float * clustMatrix );
230 
231  //--- Save a copy of clustMatrix into clustMatrix2
232  memcpy( clustMatrix2, clustMatrix, sizeof(float)*mrow*mcol);
233 
234  //--- Set both return statuses, since we may call only one.
235  theClusterParam.ierr = 0;
236  theClusterParam.ierr2 = 0;
237 
238 
239 
240  //--- Are we on edge?
241  if ( theClusterParam.isOnEdge_ ) {
242  //--- Call the Template Reco 2d with cluster repair.0
243  filled_from_2d = true;
244  callTempReco3D( theDetParam, theClusterParam, clusterPayload2d, ID, lp );
245  }
246  else {
247  theClusterParam.recommended3D_ = false;
248  //--- Call the vanilla Template Reco
249  callTempReco2D( theDetParam, theClusterParam, clusterPayload, ID, lp );
250 
251  //--- Did we find a cluster which has bad probability and not enough charge?
252  if ( theClusterParam.recommended3D_ ) {
253  //--- Yes. So run Template Reco 2d with cluster repair.
254 
255  // //--- Once again (!) copy clust's pixels (calibrated in electrons) into
256  // // clustMatrix. We need to do that because the vanilla template reco
257  // // will modify the ADC counts in situ (during decapitation)
258  // memset( clustMatrix, 0, sizeof(float)*mrow*mcol ); // Wipe it clean.
259  // for (int i=0 ; i!=theClusterParam.theCluster->size(); ++i )
260  // {
261  // auto pix = theClusterParam.theCluster->pixel(i);
262  // int irow = int(pix.x) - row_offset;
263  // int icol = int(pix.y) - col_offset;
264  // // &&& Do we ever get pixels that are out of bounds ??? Need to check.
265  // if ( (irow<mrow) & (icol<mcol) ) clustMatrix[irow][icol] = float(pix.adc);
266  // }
267  // // fillClustMatrix( float * clustMatrix );
268 
269 
270  //--- Call the Template Reco 2d with cluster repair
271  callTempReco3D( theDetParam, theClusterParam, clusterPayload2d, ID, lp );
272  filled_from_2d = true;
273  }
274 
275  }
276 
277  //--- Make sure cluster repair returns all info about the hit back up to caller
278  //--- Necessary because it copied the base class so it does not modify it
279  theClusterParamBase.isOnEdge_ = theClusterParam.isOnEdge_;
280  theClusterParamBase.hasBadPixels_ = theClusterParam.hasBadPixels_;
281  theClusterParamBase.spansTwoROCs_ = theClusterParam.spansTwoROCs_;
282  theClusterParamBase.hasFilledProb_ = theClusterParam.hasFilledProb_;
283  theClusterParamBase.qBin_ = theClusterParam.qBin_;
284  theClusterParamBase.probabilityQ_ = theClusterParam.probabilityQ_;
285  theClusterParamBase.filled_from_2d = filled_from_2d;
286  if(filled_from_2d){
287  theClusterParamBase.probabilityX_ = theClusterParam.templProbXY_;
288  theClusterParamBase.probabilityY_ = 0.;
289  }
290  else{
291  theClusterParamBase.probabilityX_ = theClusterParam.probabilityX_;
292  theClusterParamBase.probabilityY_ = theClusterParam.probabilityY_;
293  }
294 
295 
296 
297  return LocalPoint( theClusterParam.templXrec_, theClusterParam.templYrec_ );
298 }
299 
300 
301 //------------------------------------------------------------------
302 // Helper function to aggregate call & handling of Template Reco
303 //------------------------------------------------------------------
304 void
306  ClusterParamTemplate & theClusterParam,
307  SiPixelTemplateReco::ClusMatrix & clusterPayload,
308  int ID, LocalPoint & lp ) const
309 {
311 
312  // Output:
313  float nonsense = -99999.9f; // nonsense init value
314  theClusterParam.templXrec_ = theClusterParam.templYrec_ = theClusterParam.templSigmaX_ = theClusterParam.templSigmaY_ = nonsense;
315  // If the template recontruction fails, we want to return 1.0 for now
316  theClusterParam.probabilityX_ = theClusterParam.probabilityY_ = theClusterParam.probabilityQ_ = 1.f;
317  theClusterParam.qBin_ = 0;
318  // We have a boolean denoting whether the reco failed or not
319  theClusterParam.hasFilledProb_ = false;
320 
321  // ******************************************************************
322  //--- Call normal TemplateReco
323  //
324  float locBz = theDetParam.bz;
325  float locBx = theDetParam.bx;
326  //
327  const bool deadpix = false;
328  std::vector<std::pair<int, int> > zeropix;
329  int nypix =0, nxpix = 0;
330  //
331  theClusterParam.ierr =
332  PixelTempReco2D( ID, theClusterParam.cotalpha, theClusterParam.cotbeta,
333  locBz, locBx,
334  clusterPayload,
335  templ,
336  theClusterParam.templYrec_, theClusterParam.templSigmaY_, theClusterParam.probabilityY_,
337  theClusterParam.templXrec_, theClusterParam.templSigmaX_, theClusterParam.probabilityX_,
338  theClusterParam.qBin_,
339  speed_, deadpix, zeropix,
340  theClusterParam.probabilityQ_, nypix, nxpix
341  );
342  // ******************************************************************
343 
344  //--- Check exit status
345  if UNLIKELY( theClusterParam.ierr != 0 )
346  {
347  LogDebug("PixelCPEClusterRepair::localPosition") <<
348  "reconstruction failed with error " << theClusterParam.ierr << "\n";
349 
350  theClusterParam.probabilityX_ = theClusterParam.probabilityY_ = theClusterParam.probabilityQ_ = 0.f;
351  theClusterParam.qBin_ = 0;
352 
353  // Gavril: what do we do in this case ? For now, just return the cluster center of gravity in microns
354  // In the x case, apply a rough Lorentz drift average correction
355  // To do: call PixelCPEGeneric whenever PixelTempReco2D fails
356  float lorentz_drift = -999.9;
357  if ( ! GeomDetEnumerators::isEndcap(theDetParam.thePart) )
358  lorentz_drift = 60.0f; // in microns
359  else
360  lorentz_drift = 10.0f; // in microns
361  // GG: trk angles needed to correct for bows/kinks
362  if ( theClusterParam.with_track_angle )
363  {
364  theClusterParam.templXrec_ = theDetParam.theTopol->localX( theClusterParam.theCluster->x(), theClusterParam.loc_trk_pred ) - lorentz_drift * micronsToCm; // rough Lorentz drift correction
365  theClusterParam.templYrec_ = theDetParam.theTopol->localY( theClusterParam.theCluster->y(), theClusterParam.loc_trk_pred );
366  }
367  else
368  {
369  edm::LogError("PixelCPEClusterRepair")
370  << "@SUB = PixelCPEClusterRepair::localPosition"
371  << "Should never be here. PixelCPEClusterRepair should always be called with track angles. This is a bad error !!! ";
372 
373  theClusterParam.templXrec_ = theDetParam.theTopol->localX( theClusterParam.theCluster->x() ) - lorentz_drift * micronsToCm; // rough Lorentz drift correction
374  theClusterParam.templYrec_ = theDetParam.theTopol->localY( theClusterParam.theCluster->y() );
375  }
376  }
377  else
378  {
379  //--- Template Reco succeeded. The probabilities are filled.
380  theClusterParam.hasFilledProb_ = true;
381 
382  //--- templ.clsleny() is the expected length of the cluster along y axis.
383  if ( (theClusterParam.probabilityY_ < minProbY_ ) && (templ.clsleny() - nypix > 1) ) {
384  theClusterParam.recommended3D_ = true;
385  }
386 
387  //--- Go from microns to centimeters
388  theClusterParam.templXrec_ *= micronsToCm;
389  theClusterParam.templYrec_ *= micronsToCm;
390 
391  //--- Go back to the module coordinate system
392  theClusterParam.templXrec_ += lp.x();
393  theClusterParam.templYrec_ += lp.y();
394 
395  }
396  return;
397 }
398 
399 
400 
401 
402 //------------------------------------------------------------------
403 // Helper function to aggregate call & handling of Template 2D fit
404 //------------------------------------------------------------------
405 void
407  ClusterParamTemplate & theClusterParam,
408  SiPixelTemplateReco2D::ClusMatrix & clusterPayload,
409  int ID, LocalPoint & lp ) const
410 {
412 
413  // Output:
414  float nonsense = -99999.9f; // nonsense init value
415  theClusterParam.templXrec_ = theClusterParam.templYrec_ = theClusterParam.templSigmaX_ = theClusterParam.templSigmaY_ = nonsense;
416  // If the template recontruction fails, we want to return 1.0 for now
417  theClusterParam.probabilityX_ = theClusterParam.probabilityY_ = theClusterParam.probabilityQ_ = 1.f;
418  theClusterParam.qBin_ = 0;
419  // We have a boolean denoting whether the reco failed or not
420  theClusterParam.hasFilledProb_ = false;
421 
422  // ******************************************************************
423  //--- Call 2D TemplateReco
424  //
425  float locBz = theDetParam.bz;
426  float locBx = theDetParam.bx;
427 
428  //--- Input:
429  // edgeflagy - (input) flag to indicate the present of edges in y:
430  // 0=none (or interior gap),1=edge at small y, 2=edge at large y, 3=edge at either end
431  //
432  // edgeflagx - (input) flag to indicate the present of edges in x:
433  // 0=none, 1=edge at small x, 2=edge at large x
434  //
435  // These two variables are calculated in setTheClu() and stored in edgeTypeX_ and edgeTypeY_
436  //
437  //--- Output:
438  // deltay - (output) template y-length - cluster length [when > 0, possibly missing end]
439  // npixels - ??? &&& Ask Morris
440 
441  float edgeTypeY = theClusterParam.edgeTypeY_ ; // the default, from PixelCPEBase
442  if ( theClusterParam.recommended3D_ ) {
443  // Cluster is not on edge, but instead the normal TemplateReco discovered that it is
444  // shorter than expected. So let the 3D algorithm try extending it on both sides, in case
445  // there is a dead double-column on either side. (We don't know which.)
446  edgeTypeY = 3;
447  }
448 
449  float deltay = 0; // return param
450  int npixels = 0; // return param
451 
452  if(clusterPayload.mrow > 4){
453  // The cluster is too big, the 2D reco will perform horribly.
454  // Better to return immediately in error
455  theClusterParam.ierr2 = 8;
456 
457  }
458  else{
459  theClusterParam.ierr2 =
460  PixelTempReco3D( ID, theClusterParam.cotalpha, theClusterParam.cotbeta,
461  locBz, locBx,
462  edgeTypeY , theClusterParam.edgeTypeX_ ,
463  clusterPayload,
464  templ2d,
465  theClusterParam.templYrec_, theClusterParam.templSigmaY_,
466  theClusterParam.templXrec_, theClusterParam.templSigmaX_,
467  theClusterParam.templProbXY_,
468  theClusterParam.probabilityQ_,
469  theClusterParam.qBin_,
470  deltay, npixels
471  );
472  }
473  // ******************************************************************
474 
475  //--- Check exit status
476  if UNLIKELY( theClusterParam.ierr2 != 0 )
477  {
478  LogDebug("PixelCPEClusterRepair::localPosition") <<
479  "3D reconstruction failed with error " << theClusterParam.ierr2 << "\n";
480 
481  theClusterParam.probabilityX_ = theClusterParam.probabilityY_ = theClusterParam.probabilityQ_ = 0.f;
482  theClusterParam.qBin_ = 0;
483  // GG: what do we do in this case? For now, just return the cluster center of gravity in microns
484  // In the x case, apply a rough Lorentz drift average correction
485  float lorentz_drift = -999.9;
486  if ( ! GeomDetEnumerators::isEndcap(theDetParam.thePart) )
487  lorentz_drift = 60.0f; // in microns // &&& replace with a constant (globally)
488  else
489  lorentz_drift = 10.0f; // in microns
490  // GG: trk angles needed to correct for bows/kinks
491  if ( theClusterParam.with_track_angle )
492  {
493  theClusterParam.templXrec_ = theDetParam.theTopol->localX( theClusterParam.theCluster->x(), theClusterParam.loc_trk_pred ) - lorentz_drift * micronsToCm; // rough Lorentz drift correction
494  theClusterParam.templYrec_ = theDetParam.theTopol->localY( theClusterParam.theCluster->y(), theClusterParam.loc_trk_pred );
495  }
496  else
497  {
498  edm::LogError("PixelCPEClusterRepair")
499  << "@SUB = PixelCPEClusterRepair::localPosition"
500  << "Should never be here. PixelCPEClusterRepair should always be called with track angles. This is a bad error !!! ";
501 
502  theClusterParam.templXrec_ = theDetParam.theTopol->localX( theClusterParam.theCluster->x() ) - lorentz_drift * micronsToCm; // rough Lorentz drift correction
503  theClusterParam.templYrec_ = theDetParam.theTopol->localY( theClusterParam.theCluster->y() );
504  }
505  }
506  else
507  {
508  //--- Template Reco succeeded.
509  theClusterParam.hasFilledProb_ = true;
510 
511  //--- Go from microns to centimeters
512  theClusterParam.templXrec_ *= micronsToCm;
513  theClusterParam.templYrec_ *= micronsToCm;
514 
515  //--- Go back to the module coordinate system
516  theClusterParam.templXrec_ += lp.x();
517  theClusterParam.templYrec_ += lp.y();
518  }
519  return;
520 }
521 
522 
523 
524 
525 //------------------------------------------------------------------
526 // localError() relies on localPosition() being called FIRST!!!
527 //------------------------------------------------------------------
529 PixelCPEClusterRepair::localError(DetParam const & theDetParam, ClusterParam & theClusterParamBase) const
530 {
531 
532  ClusterParamTemplate & theClusterParam = static_cast<ClusterParamTemplate &>(theClusterParamBase);
533 
534  //--- Default is the maximum error used for edge clusters.
535  //--- (never used, in fact: let comment it out, shut up the complains of the static analyzer, and save a few CPU cycles)
536  float xerr = 0.0f, yerr = 0.0f;
537 
538  //--- Check status of both template calls.
539  if UNLIKELY ( (theClusterParam.ierr !=0) || (theClusterParam.ierr2 !=0) ) {
540  // If reconstruction fails the hit position is calculated from cluster center of gravity
541  // corrected in x by average Lorentz drift. Assign huge errors.
542  //
544  throw cms::Exception("PixelCPEClusterRepair::localPosition :")
545  << "A non-pixel detector type in here?";
546 
547  // Assign better errors based on the residuals for failed template cases
548  if ( GeomDetEnumerators::isBarrel(theDetParam.thePart)) {
549  xerr = 55.0f * micronsToCm; // &&& get errors from elsewhere?
550  yerr = 36.0f * micronsToCm;
551  }
552  else {
553  xerr = 42.0f * micronsToCm;
554  yerr = 39.0f * micronsToCm;
555  }
556  }
557  // Leave commented for now, until we study the interplay of failure modes
558  // of 1D template reco and edges. For edge hits we run 3D reco by default!
559  //
560  // else if ( theClusterParam.edgeTypeX_ || theClusterParam.edgeTypeY_ ) {
561  // // for edge pixels assign errors according to observed residual RMS
562  // if ( theClusterParam.edgeTypeX_ && !theClusterParam.edgeTypeY_ ) {
563  // xerr = 23.0f * micronsToCm;
564  // yerr = 39.0f * micronsToCm;
565  // }
566  // else if ( !theClusterParam.edgeTypeX_ && theClusterParam.edgeTypeY_ ) {
567  // xerr = 24.0f * micronsToCm;
568  // yerr = 96.0f * micronsToCm;
569  // }
570  // else if ( theClusterParam.edgeTypeX_ && theClusterParam.edgeTypeY_ ) {
571  // xerr = 31.0f * micronsToCm;
572  // yerr = 90.0f * micronsToCm;
573  // }
574  // }
575  else {
576  xerr = theClusterParam.templSigmaX_ * micronsToCm;
577  yerr = theClusterParam.templSigmaY_ * micronsToCm;
578  // &&& should also check ierr (saved as class variable) and return
579  // &&& nonsense (another class static) if the template fit failed.
580  }
581 
582  if (theVerboseLevel > 9) {
583  LogDebug("PixelCPEClusterRepair")
584  << " Sizex = " << theClusterParam.theCluster->sizeX()
585  << " Sizey = " << theClusterParam.theCluster->sizeY()
586  << " Edgex = " << theClusterParam.edgeTypeX_
587  << " Edgey = " << theClusterParam.edgeTypeY_
588  << " ErrX = " << xerr << " ErrY = " << yerr;
589  }
590 
591 
592  if ( !(xerr > 0.0f) )
593  throw cms::Exception("PixelCPEClusterRepair::localError")
594  << "\nERROR: Negative pixel error xerr = " << xerr << "\n\n";
595 
596  if ( !(yerr > 0.0f) )
597  throw cms::Exception("PixelCPEClusterRepair::localError")
598  << "\nERROR: Negative pixel error yerr = " << yerr << "\n\n";
599 
600  return LocalError(xerr*xerr, 0, yerr*yerr);
601 }
602 
#define LogDebug(id)
LocalError localError(DetParam const &theDetParam, ClusterParam &theClusterParam) const override
T getParameter(std::string const &) const
int minPixelCol() const
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:32
std::vector< SiPixelTemplateStore > thePixelTemp_
short getTemplateID(const uint32_t &detid) const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const SiPixelCluster * theCluster
Definition: PixelCPEBase.h:87
uint32_t ID
Definition: Definitions.h:26
bool isBarrel(GeomDetEnumerators::SubDetector m)
T y() const
Definition: PV3DBase.h:63
bool exists(std::string const &parameterName) const
checks if a parameter exists
ClusterParam * createClusterParam(const SiPixelCluster &cl) const override
int PixelTempReco2D(int id, float cotalpha, float cotbeta, float locBz, float locBx, ClusMatrix &cluster, SiPixelTemplate &templ, float &yrec, float &sigmay, float &proby, float &xrec, float &sigmax, float &probx, int &qbin, int speed, bool deadpix, std::vector< std::pair< int, int > > &zeropix, float &probQ, int &nypix, int &nxpix)
#define nullptr
const PixelGeomDetUnit * theDet
Definition: PixelCPEBase.h:60
GeomDetType::SubDetector thePart
Definition: PixelCPEBase.h:65
#define constexpr
const RectangularPixelTopology * theRecTopol
Definition: PixelCPEBase.h:63
PixelCPEClusterRepair(edm::ParameterSet const &conf, const MagneticField *, const TrackerGeometry &, const TrackerTopology &, const SiPixelLorentzAngle *, const SiPixelTemplateDBObject *, const SiPixel2DTemplateDBObject *)
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
const PixelTopology * theTopol
Definition: PixelCPEBase.h:62
int minPixelRow() const
bool LoadTemplatesFromDB_
Definition: PixelCPEBase.h:257
void callTempReco3D(DetParam const &theDetParam, ClusterParamTemplate &theClusterParam, SiPixelTemplateReco2D::ClusMatrix &clusterPayload, int ID, LocalPoint &lp) const
float clsleny()
y-size of smaller interpolated template in pixels
int PixelTempReco3D(int id, float cotalpha, float cotbeta, float locBz, float locBx, int edgeflagy, int edgeflagx, ClusMatrix &cluster, SiPixelTemplate2D &templ, float &yrec, float &sigmay, float &xrec, float &sigmax, float &probxy, float &probQ, int &qbin, float &deltay, int &npixel)
const SiPixelTemplateDBObject * templateDBobject_
Definition: PixelCPEBase.h:253
virtual float localX(float mpX) const =0
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
double f[11][100]
void callTempReco2D(DetParam const &theDetParam, ClusterParamTemplate &theClusterParam, SiPixelTemplateReco::ClusMatrix &clusterPayload, int ID, LocalPoint &lp) const
std::vector< SiPixelTemplateStore2D > thePixelTemp2D_
T min(T a, T b)
Definition: MathUtil.h:58
bool isEndcap(GeomDetEnumerators::SubDetector m)
bool isItBigPixelInY(const int iybin) const override
bool isItBigPixelInX(const int ixbin) const override
Topology::LocalTrackPred loc_trk_pred
Definition: PixelCPEBase.h:101
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore2D > &pixelTemp, std::string dir="")
virtual LocalPoint localPosition(const MeasurementPoint &) const =0
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore > &pixelTemp, std::string dir="CalibTracker/SiPixelESProducers/data/")
int sizeY() const
Pixel cluster – collection of neighboring pixels above threshold.
Pixel pixel(int i) const
float y() const
virtual float localY(float mpY) const =0
int sizeX() const
T x() const
Definition: PV3DBase.h:62
float x() const
bool isTrackerPixel(GeomDetEnumerators::SubDetector m)
LocalPoint localPosition(DetParam const &theDetParam, ClusterParam &theClusterParam) const override
#define UNLIKELY(x)
int size() const