CMS 3D CMS Logo

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