CMS 3D CMS Logo

PixelCPEGeneric.cc
Go to the documentation of this file.
2 
5 
6 // this is needed to get errors from templates
9 
10 
11 // Services
14 
15 #include "boost/multi_array.hpp"
16 
17 #include <iostream>
18 using namespace std;
19 
20 namespace {
21  constexpr float micronsToCm = 1.0e-4;
22  const bool MYDEBUG = false;
23 }
24 
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29  const MagneticField * mag,
30  const TrackerGeometry& geom,
31  const TrackerTopology& ttopo,
32  const SiPixelLorentzAngle * lorentzAngle,
33  const SiPixelGenErrorDBObject * genErrorDBObject,
34  const SiPixelLorentzAngle * lorentzAngleWidth=0)
35 : PixelCPEBase(conf, mag, geom, ttopo, lorentzAngle, genErrorDBObject, 0,lorentzAngleWidth,0) {
36 
37  if (theVerboseLevel > 0)
38  LogDebug("PixelCPEGeneric")
39  << " constructing a generic algorithm for ideal pixel detector.\n"
40  << " CPEGeneric:: VerboseLevel = " << theVerboseLevel;
41 
42  // Externally settable cuts
43  the_eff_charge_cut_lowX = conf.getParameter<double>("eff_charge_cut_lowX");
44  the_eff_charge_cut_lowY = conf.getParameter<double>("eff_charge_cut_lowY");
45  the_eff_charge_cut_highX = conf.getParameter<double>("eff_charge_cut_highX");
46  the_eff_charge_cut_highY = conf.getParameter<double>("eff_charge_cut_highY");
47  the_size_cutX = conf.getParameter<double>("size_cutX");
48  the_size_cutY = conf.getParameter<double>("size_cutY");
49 
50  EdgeClusterErrorX_ = conf.getParameter<double>("EdgeClusterErrorX");
51  EdgeClusterErrorY_ = conf.getParameter<double>("EdgeClusterErrorY");
52 
53  // Externally settable flags to inflate errors
54  inflate_errors = conf.getParameter<bool>("inflate_errors");
55  inflate_all_errors_no_trk_angle = conf.getParameter<bool>("inflate_all_errors_no_trk_angle");
56 
57  UseErrorsFromTemplates_ = conf.getParameter<bool>("UseErrorsFromTemplates");
58  TruncatePixelCharge_ = conf.getParameter<bool>("TruncatePixelCharge");
59  IrradiationBiasCorrection_ = conf.getParameter<bool>("IrradiationBiasCorrection");
60  DoCosmics_ = conf.getParameter<bool>("DoCosmics");
61  //LoadTemplatesFromDB_ = conf.getParameter<bool>("LoadTemplatesFromDB");
62 
63  // no clear what upgrade means, is it phase1, phase2? Probably delete.
64  isUpgrade_= false;
65  if ( conf.exists("Upgrade") && conf.getParameter<bool>("Upgrade")) isUpgrade_=true;
66 
67  // Select the position error source
68  // For upgrde and cosmics force the use simple errors
69  if( isUpgrade_ || (DoCosmics_) ) UseErrorsFromTemplates_ = false;
70 
71  if ( !UseErrorsFromTemplates_ && ( TruncatePixelCharge_ ||
72  IrradiationBiasCorrection_ ||
74  throw cms::Exception("PixelCPEGeneric::PixelCPEGeneric: ")
75  << "\nERROR: UseErrorsFromTemplates_ is set to False in PixelCPEGeneric_cfi.py. "
76  << " In this case it does not make sense to set any of the following to True: "
77  << " TruncatePixelCharge_, IrradiationBiasCorrection_, DoCosmics_, LoadTemplatesFromDB_ !!!"
78  << "\n\n";
79  }
80 
81  // Use errors from templates or from GenError
82  if ( UseErrorsFromTemplates_ ) {
83 
84  if ( LoadTemplatesFromDB_ ) { // From DB
86  throw cms::Exception("InvalidCalibrationLoaded")
87  << "ERROR: GenErrors not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version "
88  << ( *genErrorDBObject_ ).version();
89  if(MYDEBUG) cout<<"Loaded genErrorDBObject v"<<( *genErrorDBObject_ ).version()<<endl;
90  } else { // From file
92  throw cms::Exception("InvalidCalibrationLoaded")
93  << "ERROR: GenErrors not loaded correctly from text file. Reconstruction will fail.";
94  } // if load from DB
95 
96  } else {
97  if(MYDEBUG) cout<<" Use simple parametrised errors "<<endl;
98  } // if ( UseErrorsFromTemplates_ )
99 
100 
101  // Rechit errors in case other, more correct, errors are not vailable
102  // This are constants. Maybe there is a more efficienct way to store them.
103  if(!isUpgrade_) { // normal case
104  xerr_barrel_l1_= {0.00115, 0.00120, 0.00088};
105  xerr_barrel_l1_def_=0.01030;
106  yerr_barrel_l1_= {0.00375,0.00230,0.00250,0.00250,0.00230,0.00230,0.00210,0.00210,0.00240};
107  yerr_barrel_l1_def_=0.00210;
108  xerr_barrel_ln_= {0.00115, 0.00120, 0.00088};
109  xerr_barrel_ln_def_=0.01030;
110  yerr_barrel_ln_= {0.00375,0.00230,0.00250,0.00250,0.00230,0.00230,0.00210,0.00210,0.00240};
111  yerr_barrel_ln_def_=0.00210;
112  xerr_endcap_= {0.0020, 0.0020};
113  xerr_endcap_def_=0.0020;
114  yerr_endcap_= {0.00210};
115  yerr_endcap_def_=0.00075;
116  } else { // isUpgrade=true
117  xerr_barrel_ln_= {0.00025, 0.00030, 0.00035, 0.00035};
118  xerr_barrel_ln_def_=0.00035;
119  yerr_barrel_ln_= {0.00210, 0.00115, 0.00125};
120  yerr_barrel_ln_def_=0.00125;
121  xerr_endcap_= {0.00072, 0.00025};
122  xerr_endcap_def_=0.00060;
123  yerr_endcap_= {0.00289, 0.00025};
124  yerr_endcap_def_=0.00180;
125 
126  if ( conf.exists("SmallPitch") && conf.getParameter<bool>("SmallPitch")) {
127  xerr_barrel_l1_= {0.00104, 0.000691, 0.00122};
128  xerr_barrel_l1_def_=0.00321;
129  yerr_barrel_l1_= {0.00199,0.00136,0.0015,0.00153,0.00152,0.00171,0.00154,0.00157,0.00154};
130  yerr_barrel_l1_def_=0.00164;
131  } else {
132  xerr_barrel_l1_= {0.00025, 0.00030, 0.00035, 0.00035};
133  xerr_barrel_l1_def_=0.00035;
134  yerr_barrel_l1_= {0.00210, 0.00115, 0.00125};
135  yerr_barrel_l1_def_=0.00125;
136  }
137  } // if isUpgrade
138 
139  if(MYDEBUG) {
140  cout << "From PixelCPEGeneric::PixelCPEGeneric(...)" << endl;
141  cout << "(int)UseErrorsFromTemplates_ = " << (int)UseErrorsFromTemplates_ << endl;
142  cout << "TruncatePixelCharge_ = " << (int)TruncatePixelCharge_ << endl;
143  cout << "IrradiationBiasCorrection_ = " << (int)IrradiationBiasCorrection_ << endl;
144  cout << "(int)DoCosmics_ = " << (int)DoCosmics_ << endl;
145  cout << "(int)LoadTemplatesFromDB_ = " << (int)LoadTemplatesFromDB_ << endl;
146  }
147 
148 
149 }
150 
152 {
153  return new ClusterParamGeneric(cl);
154 }
155 
156 
157 
158 //-----------------------------------------------------------------------------
162 //-----------------------------------------------------------------------------
164 PixelCPEGeneric::localPosition(DetParam const & theDetParam, ClusterParam & theClusterParamBase) const
165 {
166 
167  ClusterParamGeneric & theClusterParam = static_cast<ClusterParamGeneric &>(theClusterParamBase);
168 
169  //cout<<" in PixelCPEGeneric:localPosition - "<<endl; //dk
170 
171  float chargeWidthX = (theDetParam.lorentzShiftInCmX * theDetParam.widthLAFractionX);
172  float chargeWidthY = (theDetParam.lorentzShiftInCmY * theDetParam.widthLAFractionY);
173  float shiftX = 0.5f*theDetParam.lorentzShiftInCmX;
174  float shiftY = 0.5f*theDetParam.lorentzShiftInCmY;
175 
176  //cout<<" main la width "<<chargeWidthX<<" "<<chargeWidthY<<endl;
177 
178  if ( UseErrorsFromTemplates_ ) {
179 
180  float qclus = theClusterParam.theCluster->charge();
181  float locBz = theDetParam.bz;
182  float locBx = theDetParam.bx;
183  //cout << "PixelCPEGeneric::localPosition(...) : locBz = " << locBz << endl;
184 
185  theClusterParam.pixmx = -999.9; // max pixel charge for truncation of 2-D cluster
186  theClusterParam.sigmay = -999.9; // CPE Generic y-error for multi-pixel cluster
187  theClusterParam.deltay = -999.9; // CPE Generic y-bias for multi-pixel cluster
188  theClusterParam.sigmax = -999.9; // CPE Generic x-error for multi-pixel cluster
189  theClusterParam.deltax = -999.9; // CPE Generic x-bias for multi-pixel cluster
190  theClusterParam.sy1 = -999.9; // CPE Generic y-error for single single-pixel
191  theClusterParam.dy1 = -999.9; // CPE Generic y-bias for single single-pixel cluster
192  theClusterParam.sy2 = -999.9; // CPE Generic y-error for single double-pixel cluster
193  theClusterParam.dy2 = -999.9; // CPE Generic y-bias for single double-pixel cluster
194  theClusterParam.sx1 = -999.9; // CPE Generic x-error for single single-pixel cluster
195  theClusterParam.dx1 = -999.9; // CPE Generic x-bias for single single-pixel cluster
196  theClusterParam.sx2 = -999.9; // CPE Generic x-error for single double-pixel cluster
197  theClusterParam.dx2 = -999.9; // CPE Generic x-bias for single double-pixel cluster
198 
199 
201  int gtemplID_ = theDetParam.detTemplateId;
202 
203  //int gtemplID0 = genErrorDBObject_->getGenErrorID(theDetParam.theDet->geographicalId().rawId());
204  //if(gtemplID0!=gtemplID_) cout<<" different id "<< gtemplID_<<" "<<gtemplID0<<endl;
205 
206  theClusterParam.qBin_ = gtempl.qbin( gtemplID_, theClusterParam.cotalpha, theClusterParam.cotbeta, locBz, locBx, qclus,
207  theClusterParam.pixmx, theClusterParam.sigmay, theClusterParam.deltay,
208  theClusterParam.sigmax, theClusterParam.deltax, theClusterParam.sy1,
209  theClusterParam.dy1, theClusterParam.sy2, theClusterParam.dy2, theClusterParam.sx1,
210  theClusterParam.dx1, theClusterParam.sx2, theClusterParam.dx2 );
211 
212  // now use the charge widths stored in the new generic template headers (change to the
213  // incorrect sign convention of the base class)
214  bool useLAWidthFromGenError = false;
215  if(useLAWidthFromGenError) {
216  chargeWidthX = (-micronsToCm*gtempl.lorxwidth());
217  chargeWidthY = (-micronsToCm*gtempl.lorywidth());
218  if(MYDEBUG) cout<< " redefine la width (gen-error) "<< chargeWidthX<<" "<< chargeWidthY <<endl;
219  }
220  if(MYDEBUG) cout<<" GenError: "<<gtemplID_<<endl;
221 
222  // These numbers come in microns from the qbin(...) call. Transform them to cm.
223  theClusterParam.deltax = theClusterParam.deltax * micronsToCm;
224  theClusterParam.dx1 = theClusterParam.dx1 * micronsToCm;
225  theClusterParam.dx2 = theClusterParam.dx2 * micronsToCm;
226 
227  theClusterParam.deltay = theClusterParam.deltay * micronsToCm;
228  theClusterParam.dy1 = theClusterParam.dy1 * micronsToCm;
229  theClusterParam.dy2 = theClusterParam.dy2 * micronsToCm;
230 
231  theClusterParam.sigmax = theClusterParam.sigmax * micronsToCm;
232  theClusterParam.sx1 = theClusterParam.sx1 * micronsToCm;
233  theClusterParam.sx2 = theClusterParam.sx2 * micronsToCm;
234 
235  theClusterParam.sigmay = theClusterParam.sigmay * micronsToCm;
236  theClusterParam.sy1 = theClusterParam.sy1 * micronsToCm;
237  theClusterParam.sy2 = theClusterParam.sy2 * micronsToCm;
238 
239  } // if ( UseErrorsFromTemplates_ )
240 
241  float Q_f_X = 0.0;
242  float Q_l_X = 0.0;
243  float Q_f_Y = 0.0;
244  float Q_l_Y = 0.0;
245  collect_edge_charges( theClusterParam,
246  Q_f_X, Q_l_X,
247  Q_f_Y, Q_l_Y );
248 
249  //--- Find the inner widths along X and Y in one shot. We
250  //--- compute the upper right corner of the inner pixels
251  //--- (== lower left corner of upper right pixel) and
252  //--- the lower left corner of the inner pixels
253  //--- (== upper right corner of lower left pixel), and then
254  //--- subtract these two points in the formula.
255 
256  //--- Upper Right corner of Lower Left pixel -- in measurement frame
257  MeasurementPoint meas_URcorn_LLpix( theClusterParam.theCluster->minPixelRow()+1.0,
258  theClusterParam.theCluster->minPixelCol()+1.0 );
259 
260  //--- Lower Left corner of Upper Right pixel -- in measurement frame
261  MeasurementPoint meas_LLcorn_URpix( theClusterParam.theCluster->maxPixelRow(),
262  theClusterParam.theCluster->maxPixelCol() );
263 
264  //--- These two now converted into the local
265  LocalPoint local_URcorn_LLpix;
266  LocalPoint local_LLcorn_URpix;
267 
268  // PixelCPEGeneric can be used with or without track angles
269  // If PixelCPEGeneric is called with track angles, use them to correct for bows/kinks:
270  if ( theClusterParam.with_track_angle ) {
271  local_URcorn_LLpix = theDetParam.theTopol->localPosition(meas_URcorn_LLpix, theClusterParam.loc_trk_pred);
272  local_LLcorn_URpix = theDetParam.theTopol->localPosition(meas_LLcorn_URpix, theClusterParam.loc_trk_pred);
273  } else {
274  local_URcorn_LLpix = theDetParam.theTopol->localPosition(meas_URcorn_LLpix);
275  local_LLcorn_URpix = theDetParam.theTopol->localPosition(meas_LLcorn_URpix);
276  }
277 
278 #ifdef EDM_ML_DEBUG
279  if (theVerboseLevel > 20) {
280  cout
281  << "\n\t >>> theClusterParam.theCluster->x = " << theClusterParam.theCluster->x()
282  << "\n\t >>> theClusterParam.theCluster->y = " << theClusterParam.theCluster->y()
283  << "\n\t >>> cluster: minRow = " << theClusterParam.theCluster->minPixelRow()
284  << " minCol = " << theClusterParam.theCluster->minPixelCol()
285  << "\n\t >>> cluster: maxRow = " << theClusterParam.theCluster->maxPixelRow()
286  << " maxCol = " << theClusterParam.theCluster->maxPixelCol()
287  << "\n\t >>> meas: inner lower left = " << meas_URcorn_LLpix.x()
288  << "," << meas_URcorn_LLpix.y()
289  << "\n\t >>> meas: inner upper right = " << meas_LLcorn_URpix.x()
290  << "," << meas_LLcorn_URpix.y()
291  << endl;
292  }
293 #endif
294 
295  //--- &&& Note that the cuts below should not be hardcoded (like in Orca and
296  //--- &&& CPEFromDetPosition/PixelCPEInitial), but rather be
297  //--- &&& externally settable (but tracked) parameters.
298 
299  //--- Position, including the half lorentz shift
300 
301 #ifdef EDM_ML_DEBUG
302  if (theVerboseLevel > 20)
303  cout << "\t >>> Generic:: processing X" << endl;
304 #endif
305 
306  float xPos =
307  generic_position_formula( theClusterParam.theCluster->sizeX(),
308  Q_f_X, Q_l_X,
309  local_URcorn_LLpix.x(), local_LLcorn_URpix.x(),
310  chargeWidthX, // lorentz shift in cm
311  theDetParam.theThickness,
312  theClusterParam.cotalpha,
313  theDetParam.thePitchX,
314  theDetParam.theRecTopol->isItBigPixelInX( theClusterParam.theCluster->minPixelRow() ),
315  theDetParam.theRecTopol->isItBigPixelInX( theClusterParam.theCluster->maxPixelRow() ),
318  the_size_cutX); // cut for eff charge width &&&
319 
320 
321  // apply the lorentz offset correction
322  xPos = xPos + shiftX;
323 
324 #ifdef EDM_ML_DEBUG
325  if (theVerboseLevel > 20)
326  cout << "\t >>> Generic:: processing Y" << endl;
327 #endif
328 
329  float yPos =
330  generic_position_formula( theClusterParam.theCluster->sizeY(),
331  Q_f_Y, Q_l_Y,
332  local_URcorn_LLpix.y(), local_LLcorn_URpix.y(),
333  chargeWidthY, // lorentz shift in cm
334  theDetParam.theThickness,
335  theClusterParam.cotbeta,
336  theDetParam.thePitchY,
337  theDetParam.theRecTopol->isItBigPixelInY( theClusterParam.theCluster->minPixelCol() ),
338  theDetParam.theRecTopol->isItBigPixelInY( theClusterParam.theCluster->maxPixelCol() ),
341  the_size_cutY); // cut for eff charge width &&&
342 
343  // apply the lorentz offset correction
344  yPos = yPos + shiftY;
345 
346  // Apply irradiation corrections. NOT USED FOR NOW
348  if ( theClusterParam.theCluster->sizeX() == 1 ) { // size=1
349  // ggiurgiu@jhu.edu, 02/03/09 : for size = 1, the Lorentz shift is already accounted by the irradiation correction
350  //float tmp1 = (0.5 * theDetParam.lorentzShiftInCmX);
351  //cout << "Apply correction correction_dx1 = " << theClusterParam.dx1 << " to xPos = " << xPos;
352  xPos = xPos - (0.5 * theDetParam.lorentzShiftInCmX);
353  // Find if pixel is double (big).
354  bool bigInX = theDetParam.theRecTopol->isItBigPixelInX( theClusterParam.theCluster->maxPixelRow() );
355  if ( !bigInX ) xPos -= theClusterParam.dx1;
356  else xPos -= theClusterParam.dx2;
357  //cout<<" to "<<xPos<<" "<<(tmp1+theClusterParam.dx1)<<endl;
358  } else { // size>1
359  //cout << "Apply correction correction_deltax = " << theClusterParam.deltax << " to xPos = " << xPos;
360  xPos -= theClusterParam.deltax;
361  //cout<<" to "<<xPos<<endl;
362  }
363 
364  if ( theClusterParam.theCluster->sizeY() == 1 ) {
365  // ggiurgiu@jhu.edu, 02/03/09 : for size = 1, the Lorentz shift is already accounted by the irradiation correction
366  yPos = yPos - (0.5 * theDetParam.lorentzShiftInCmY);
367 
368  // Find if pixel is double (big).
369  bool bigInY = theDetParam.theRecTopol->isItBigPixelInY( theClusterParam.theCluster->maxPixelCol() );
370  if ( !bigInY ) yPos -= theClusterParam.dy1;
371  else yPos -= theClusterParam.dy2;
372 
373  } else {
374  //cout << "Apply correction correction_deltay = " << theClusterParam.deltay << " to yPos = " << yPos << endl;
375  yPos -= theClusterParam.deltay;
376  }
377 
378  } // if ( IrradiationBiasCorrection_ )
379 
380  //cout<<" in PixelCPEGeneric:localPosition - pos = "<<xPos<<" "<<yPos<<endl; //dk
381 
382  //--- Now put the two together
383  LocalPoint pos_in_local( xPos, yPos );
384  return pos_in_local;
385 }
386 
387 
388 
389 //-----------------------------------------------------------------------------
394 //-----------------------------------------------------------------------------
395 float
398  float Q_f,
399  float Q_l,
400  float upper_edge_first_pix,
401  float lower_edge_last_pix,
402  float lorentz_shift,
403  float theThickness, //detector thickness
404  float cot_angle,
405  float pitch,
406  bool first_is_big,
407  bool last_is_big,
408  float eff_charge_cut_low,
409  float eff_charge_cut_high,
410  float size_cut
411 ) const
412 {
413 
414  //cout<<" in PixelCPEGeneric:generic_position_formula - "<<endl; //dk
415 
416  float geom_center = 0.5f * ( upper_edge_first_pix + lower_edge_last_pix );
417 
418  //--- The case of only one pixel in this projection is separate. Note that
419  //--- here first_pix == last_pix, so the average of the two is still the
420  //--- center of the pixel.
421  if ( size == 1 ) {return geom_center;}
422 
423  //--- Width of the clusters minus the edge (first and last) pixels.
424  //--- In the note, they are denoted x_F and x_L (and y_F and y_L)
425  float W_inner = lower_edge_last_pix - upper_edge_first_pix; // in cm
426 
427  //--- Predicted charge width from geometry
428  float W_pred = theThickness * cot_angle // geometric correction (in cm)
429  - lorentz_shift; // (in cm) &&& check fpix!
430 
431  //cout<<" in PixelCPEGeneric:generic_position_formula - "<<W_inner<<" "<<W_pred<<endl; //dk
432 
433  //--- Total length of the two edge pixels (first+last)
434  float sum_of_edge = 2.0f;
435  if (first_is_big) sum_of_edge += 1.0f;
436  if (last_is_big) sum_of_edge += 1.0f;
437 
438 
439  //--- The `effective' charge width -- particle's path in first and last pixels only
440  float W_eff = std::abs( W_pred ) - W_inner;
441 
442 
443  //--- If the observed charge width is inconsistent with the expectations
444  //--- based on the track, do *not* use W_pred-W_innner. Instead, replace
445  //--- it with an *average* effective charge width, which is the average
446  //--- length of the edge pixels.
447  //
448  // bool usedEdgeAlgo = false;
449  if ( (size >= size_cut) || (
450  ( W_eff/pitch < eff_charge_cut_low ) |
451  ( W_eff/pitch > eff_charge_cut_high ) ) )
452  {
453  W_eff = pitch * 0.5f * sum_of_edge; // ave. length of edge pixels (first+last) (cm)
454  // usedEdgeAlgo = true;
455 #ifdef EDM_ML_DEBUG
456  nRecHitsUsedEdge_++;
457 #endif
458  }
459 
460 
461  //--- Finally, compute the position in this projection
462  float Qdiff = Q_l - Q_f;
463  float Qsum = Q_l + Q_f;
464 
465  //--- Temporary fix for clusters with both first and last pixel with charge = 0
466  if(Qsum==0) Qsum=1.0f;
467  //float hit_pos = geom_center + 0.5f*(Qdiff/Qsum) * W_eff + half_lorentz_shift;
468  float hit_pos = geom_center + 0.5f*(Qdiff/Qsum) * W_eff;
469 
470  //cout<<" in PixelCPEGeneric:generic_position_formula - "<<hit_pos<<" "<<lorentz_shift*0.5<<endl; //dk
471 
472 #ifdef EDM_ML_DEBUG
473  //--- Debugging output
474 #warning "Debug printouts in PixelCPEGeneric.cc has been commented because they cannot be compiled"
475  /* This part is commented because some variables used here are not defined !!
476  if (theVerboseLevel > 20) {
477  if ( theDetParam.thePart == GeomDetEnumerators::PixelBarrel || theDetParam.thePart == GeomDetEnumerators::P1PXB ) {
478  cout << "\t >>> We are in the Barrel." ;
479  } else if ( theDetParam.thePart == GeomDetEnumerators::PixelEndcap ||
480  theDetParam.thePart == GeomDetEnumerators::P1PXEC ||
481  theDetParam.thePart == GeomDetEnumerators::P2PXEC ) {
482  cout << "\t >>> We are in the Forward." ;
483  } else {
484  cout << "\t >>> We are in an unexpected subdet " << theDetParam.thePart;
485  }
486  cout
487  << "\n\t >>> cot(angle) = " << cot_angle << " pitch = " << pitch << " size = " << size
488  << "\n\t >>> upper_edge_first_pix = " << upper_edge_first_pix
489  << "\n\t >>> lower_edge_last_pix = " << lower_edge_last_pix
490  << "\n\t >>> geom_center = " << geom_center
491  << "\n\t >>> half_lorentz_shift = " << half_lorentz_shift
492  << "\n\t >>> W_inner = " << W_inner
493  << "\n\t >>> W_pred = " << W_pred
494  << "\n\t >>> W_eff(orig) = " << fabs( W_pred ) - W_inner
495  << "\n\t >>> W_eff(used) = " << W_eff
496  << "\n\t >>> sum_of_edge = " << sum_of_edge
497  << "\n\t >>> Qdiff = " << Qdiff << " Qsum = " << Qsum
498  << "\n\t >>> hit_pos = " << hit_pos
499  << "\n\t >>> RecHits: total = " << nRecHitsTotal_
500  << " used edge = " << nRecHitsUsedEdge_
501  << endl;
502  if (usedEdgeAlgo)
503  cout << "\n\t >>> Used Edge algorithm." ;
504  else
505  cout << "\n\t >>> Used angle information." ;
506  cout << endl;
507  }
508  */
509 #endif
510 
511  return hit_pos;
512 }
513 
514 
515 //-----------------------------------------------------------------------------
519 //-----------------------------------------------------------------------------
520 void
522 collect_edge_charges(ClusterParam & theClusterParamBase,
523  float & Q_f_X,
524  float & Q_l_X,
525  float & Q_f_Y,
526  float & Q_l_Y
527 ) const
528 {
529  ClusterParamGeneric & theClusterParam = static_cast<ClusterParamGeneric &>(theClusterParamBase);
530 
531  // Initialize return variables.
532  Q_f_X = Q_l_X = 0.0;
533  Q_f_Y = Q_l_Y = 0.0;
534 
535 
536  // Obtain boundaries in index units
537  int xmin = theClusterParam.theCluster->minPixelRow();
538  int xmax = theClusterParam.theCluster->maxPixelRow();
539  int ymin = theClusterParam.theCluster->minPixelCol();
540  int ymax = theClusterParam.theCluster->maxPixelCol();
541 
542 
543  // Iterate over the pixels.
544  int isize = theClusterParam.theCluster->size();
545  for (int i = 0; i != isize; ++i)
546  {
547  auto const & pixel = theClusterParam.theCluster->pixel(i);
548  // ggiurgiu@fnal.gov: add pixel charge truncation
549  float pix_adc = pixel.adc;
551  pix_adc = std::min(pix_adc, theClusterParam.pixmx );
552 
553  //
554  // X projection
555  if ( pixel.x == xmin ) Q_f_X += pix_adc;
556  if ( pixel.x == xmax ) Q_l_X += pix_adc;
557  //
558  // Y projection
559  if ( pixel.y == ymin ) Q_f_Y += pix_adc;
560  if ( pixel.y == ymax ) Q_l_Y += pix_adc;
561  }
562 
563  return;
564 }
565 
566 
567 //============== INFLATED ERROR AND ERRORS FROM DB BELOW ================
568 
569 //-------------------------------------------------------------------------
570 // Hit error in the local frame
571 //-------------------------------------------------------------------------
573 PixelCPEGeneric::localError(DetParam const & theDetParam, ClusterParam & theClusterParamBase) const
574 {
575 
576  ClusterParamGeneric & theClusterParam = static_cast<ClusterParamGeneric &>(theClusterParamBase);
577 
578  const bool localPrint = false;
579  // Default errors are the maximum error used for edge clusters.
580  // These are determined by looking at residuals for edge clusters
581  float xerr = EdgeClusterErrorX_ * micronsToCm;
582  float yerr = EdgeClusterErrorY_ * micronsToCm;
583 
584 
585  // Find if cluster is at the module edge.
586  int maxPixelCol = theClusterParam.theCluster->maxPixelCol();
587  int maxPixelRow = theClusterParam.theCluster->maxPixelRow();
588  int minPixelCol = theClusterParam.theCluster->minPixelCol();
589  int minPixelRow = theClusterParam.theCluster->minPixelRow();
590 
591  bool edgex = ( theDetParam.theRecTopol->isItEdgePixelInX( minPixelRow ) ) || ( theDetParam.theRecTopol->isItEdgePixelInX( maxPixelRow ) );
592  bool edgey = ( theDetParam.theRecTopol->isItEdgePixelInY( minPixelCol ) ) || ( theDetParam.theRecTopol->isItEdgePixelInY( maxPixelCol ) );
593 
594  unsigned int sizex = theClusterParam.theCluster->sizeX();
595  unsigned int sizey = theClusterParam.theCluster->sizeY();
596  if(MYDEBUG) {
597  if( int(sizex) != (maxPixelRow - minPixelRow+1) ) cout<<" wrong x"<<endl;
598  if( int(sizey) != (maxPixelCol - minPixelCol+1) ) cout<<" wrong y"<<endl;
599  }
600 
601  // Find if cluster contains double (big) pixels.
602  bool bigInX = theDetParam.theRecTopol->containsBigPixelInX( minPixelRow, maxPixelRow );
603  bool bigInY = theDetParam.theRecTopol->containsBigPixelInY( minPixelCol, maxPixelCol );
604 
605  if(localPrint) {
606  cout<<" edge clus "<<xerr<<" "<<yerr<<endl; //dk
607  if(bigInX || bigInY) cout<<" big "<<bigInX<<" "<<bigInY<<endl;
608  if(edgex || edgey) cout<<" edge "<<edgex<<" "<<edgey<<endl;
609  cout<<" before if "<<UseErrorsFromTemplates_<<" "<<theClusterParam.qBin_<<endl;
610  if(theClusterParam.qBin_ == 0)
611  cout<<" qbin 0! "<<edgex<<" "<<edgey<<" "<<bigInX<<" "<<bigInY<<" "
612  <<sizex<<" "<<sizey<<endl;
613  }
614 
616  //
617  // Use template errors
618  //cout << "Track angles are known. We can use either errors from templates or the error parameterization from DB." << endl;
619 
620  if ( !edgex ) { // Only use this for non-edge clusters
621  if ( sizex == 1 ) {
622  if ( !bigInX ) {xerr = theClusterParam.sx1;}
623  else {xerr = theClusterParam.sx2;}
624  } else {xerr = theClusterParam.sigmax;}
625  }
626 
627  if ( !edgey ) { // Only use for non-edge clusters
628  if ( sizey == 1 ) {
629  if ( !bigInY ) {yerr = theClusterParam.sy1;}
630  else {yerr = theClusterParam.sy2;}
631  } else {yerr = theClusterParam.sigmay;}
632  }
633 
634  if(localPrint) {
635  cout<<" in if "<<edgex<<" "<<edgey<<" "<<sizex<<" "<<sizey<<endl;
636  cout<<" errors "<<xerr<<" "<<yerr<<" "<<theClusterParam.sx1<<" "<<theClusterParam.sx2<<" "<<theClusterParam.sigmax<<endl; //dk
637  }
638 
639  } else { // simple errors
640 
641  // This are the simple errors, hardcoded in the code
642  //cout << "Track angles are not known " << endl;
643  //cout << "Default angle estimation which assumes track from PV (0,0,0) does not work." << endl;
644 
645  if ( GeomDetEnumerators::isTrackerPixel(theDetParam.thePart) ) {
646  if(GeomDetEnumerators::isBarrel(theDetParam.thePart)) {
647 
648  DetId id = (theDetParam.theDet->geographicalId());
649  int layer=ttopo_.layer(id);
650  if ( layer==1 ) {
651  if ( !edgex ) {
652  if ( sizex<=xerr_barrel_l1_.size() ) xerr=xerr_barrel_l1_[sizex-1];
653  else xerr=xerr_barrel_l1_def_;
654  }
655 
656  if ( !edgey ) {
657  if ( sizey<=yerr_barrel_l1_.size() ) yerr=yerr_barrel_l1_[sizey-1];
658  else yerr=yerr_barrel_l1_def_;
659  }
660  } else{ // layer 2,3
661  if ( !edgex ) {
662  if ( sizex<=xerr_barrel_ln_.size() ) xerr=xerr_barrel_ln_[sizex-1];
663  else xerr=xerr_barrel_ln_def_;
664  }
665 
666  if ( !edgey ) {
667  if ( sizey<=yerr_barrel_ln_.size() ) yerr=yerr_barrel_ln_[sizey-1];
668  else yerr=yerr_barrel_ln_def_;
669  }
670  }
671 
672  } else { // EndCap
673 
674  if ( !edgex ) {
675  if ( sizex<=xerr_endcap_.size() ) xerr=xerr_endcap_[sizex-1];
676  else xerr=xerr_endcap_def_;
677  }
678 
679  if ( !edgey ) {
680  if ( sizey<=yerr_endcap_.size() ) yerr=yerr_endcap_[sizey-1];
681  else yerr=yerr_endcap_def_;
682  }
683  } // end endcap
684  }
685 
686  if(inflate_errors) {
687  int n_bigx = 0;
688  int n_bigy = 0;
689 
690  for (int irow = 0; irow < 7; ++irow) {
691  if ( theDetParam.theRecTopol->isItBigPixelInX( irow+minPixelRow ) ) ++n_bigx;
692  }
693 
694  for (int icol = 0; icol < 21; ++icol) {
695  if ( theDetParam.theRecTopol->isItBigPixelInY( icol+minPixelCol ) ) ++n_bigy;
696  }
697 
698  xerr = (float)(sizex + n_bigx) * theDetParam.thePitchX / std::sqrt( 12.0f );
699  yerr = (float)(sizey + n_bigy) * theDetParam.thePitchY / std::sqrt( 12.0f );
700 
701  } // if(inflate_errors)
702 
703  } // end
704 
705 #ifdef EDM_ML_DEBUG
706  if ( !(xerr > 0.0) )
707  throw cms::Exception("PixelCPEGeneric::localError")
708  << "\nERROR: Negative pixel error xerr = " << xerr << "\n\n";
709 
710  if ( !(yerr > 0.0) )
711  throw cms::Exception("PixelCPEGeneric::localError")
712  << "\nERROR: Negative pixel error yerr = " << yerr << "\n\n";
713 #endif
714 
715  //if(localPrint) {
716  //cout<<" errors "<<xerr<<" "<<yerr<<endl; //dk
717  //if(theClusterParam.qBin_ == 0) cout<<" qbin 0 "<<xerr<<" "<<yerr<<endl;
718  //}
719 
720  auto xerr_sq = xerr*xerr;
721  auto yerr_sq = yerr*yerr;
722 
723  return LocalError( xerr_sq, 0, yerr_sq );
724 
725 }
726 
727 
728 
729 
730 
731 
#define LogDebug(id)
size
Write out results.
T getParameter(std::string const &) const
bool containsBigPixelInY(int iymin, int iymax) const
std::vector< float > xerr_barrel_l1_
float charge() const
int minPixelCol() const
bool isItEdgePixelInY(int iybin) const
float the_eff_charge_cut_highY
std::vector< float > xerr_barrel_ln_
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
virtual bool isItBigPixelInY(const int iybin) const
const SiPixelCluster * theCluster
Definition: PixelCPEBase.h:92
bool isBarrel(GeomDetEnumerators::SubDetector m)
bool isItEdgePixelInX(int ixbin) const
int qbin(int id, float cotalpha, float cotbeta, float locBz, float locBx, float qclus, float &pixmx, float &sigmay, float &deltay, float &sigmax, float &deltax, float &sy1, float &dy1, float &sy2, float &dy2, float &sx1, float &dx1, float &sx2, float &dx2)
T y() const
Definition: PV3DBase.h:63
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< SiPixelGenErrorStore > thePixelGenError_
const PixelGeomDetUnit * theDet
Definition: PixelCPEBase.h:60
GeomDetType::SubDetector thePart
Definition: PixelCPEBase.h:65
bool IrradiationBiasCorrection_
#define constexpr
const RectangularPixelTopology * theRecTopol
Definition: PixelCPEBase.h:63
std::vector< float > yerr_endcap_
int maxPixelRow() const
PixelCPEGeneric(edm::ParameterSet const &conf, const MagneticField *, const TrackerGeometry &, const TrackerTopology &, const SiPixelLorentzAngle *, const SiPixelGenErrorDBObject *, const SiPixelLorentzAngle *)
The constructor.
#define likely(x)
const PixelTopology * theTopol
Definition: PixelCPEBase.h:62
int minPixelRow() const
bool LoadTemplatesFromDB_
Definition: PixelCPEBase.h:257
float the_eff_charge_cut_lowX
T sqrt(T t)
Definition: SSEVec.h:18
bool inflate_all_errors_no_trk_angle
void collect_edge_charges(ClusterParam &theClusterParam, float &Q_f_X, float &Q_l_X, float &Q_f_Y, float &Q_l_Y) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
double f[11][100]
T min(T a, T b)
Definition: MathUtil.h:58
float lorxwidth()
signed lorentz x-width (microns)
float generic_position_formula(int size, float Q_f, float Q_l, float upper_edge_first_pix, float lower_edge_last_pix, float lorentz_shift, float theThickness, float cot_angle, float pitch, bool first_is_big, bool last_is_big, float eff_charge_cut_low, float eff_charge_cut_high, float size_cut) const
bool containsBigPixelInX(int ixmin, int ixmax) const
std::vector< float > xerr_endcap_
Definition: DetId.h:18
Topology::LocalTrackPred loc_trk_pred
Definition: PixelCPEBase.h:105
const TrackerTopology & ttopo_
Definition: PixelCPEBase.h:245
const SiPixelGenErrorDBObject * genErrorDBObject_
Definition: PixelCPEBase.h:250
float the_eff_charge_cut_lowY
int maxPixelCol() const
std::vector< float > yerr_barrel_l1_
virtual LocalPoint localPosition(const MeasurementPoint &) const =0
bool isTrackerPixel(const GeomDetEnumerators::SubDetector m)
unsigned int layer(const DetId &id) const
std::vector< float > yerr_barrel_ln_
int sizeY() const
Pixel cluster – collection of neighboring pixels above threshold.
LocalError localError(DetParam const &theDetParam, ClusterParam &theClusterParam) const
Pixel pixel(int i) const
float lorywidth()
signed lorentz y-width (microns)
virtual bool isItBigPixelInX(const int ixbin) const
float y() const
static bool pushfile(int filenum, std::vector< SiPixelGenErrorStore > &thePixelTemp_)
int sizeX() const
T x() const
Definition: PV3DBase.h:62
LocalPoint localPosition(DetParam const &theDetParam, ClusterParam &theClusterParam) const
float x() const
float the_eff_charge_cut_highX
ClusterParam * createClusterParam(const SiPixelCluster &cl) const
int size() const