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