25 #include "boost/multi_array.hpp"
34 constexpr
float micronsToCm = 1.0e-4;
35 constexpr
int cluster_matrix_size_x = 13;
36 constexpr
int cluster_matrix_size_y = 21;
49 :
PixelCPEBase(conf,
mag,
geom, ttopo, lorentzAngle, nullptr, templateDBobject, nullptr, 1) {
69 <<
"\nERROR: Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version "
70 << (*templateDBobject_).version() <<
"\n\n";
80 <<
" not loaded correctly from text file. Reconstruction will fail.\n\n";
85 <<
" not loaded correctly from text file. Reconstruction will fail.\n\n";
89 LogDebug(
"PixelCPETemplateReco::PixelCPETemplateReco:") <<
"Template speed = " <<
speed_ <<
"\n";
100 return std::make_unique<ClusterParamTemplate>(
cl);
111 ClusterParamTemplate& theClusterParam = static_cast<ClusterParamTemplate&>(theClusterParamBase);
114 throw cms::Exception(
"PixelCPETemplateReco::localPosition :") <<
"A non-pixel detector type in here?";
123 edm::LogError(
"PixelCPETemplateReco") <<
" different id" <<
ID <<
" " << ID0 << endl;
143 int row_offset = theClusterParam.theCluster->minPixelRow();
144 int col_offset = theClusterParam.theCluster->minPixelCol();
149 float tmp_x =
float(row_offset) + 0.5f;
150 float tmp_y =
float(col_offset) + 0.5f;
158 if (theClusterParam.with_track_angle)
161 edm::LogError(
"PixelCPETemplateReco") <<
"@SUB = PixelCPETemplateReco::localPosition"
162 <<
"Should never be here. PixelCPETemplateReco should always be called with "
163 "track angles. This is a bad error !!! ";
169 int mrow = 0, mcol = 0;
170 for (
int i = 0;
i != theClusterParam.theCluster->size(); ++
i) {
171 auto pix = theClusterParam.theCluster->pixel(
i);
172 int irow =
int(pix.x);
173 int icol =
int(pix.y);
179 mrow =
std::min(mrow, cluster_matrix_size_x);
182 mcol =
std::min(mcol, cluster_matrix_size_y);
186 float clustMatrix[mrow][mcol];
187 memset(clustMatrix, 0,
sizeof(
float) * mrow * mcol);
190 for (
int i = 0;
i != theClusterParam.theCluster->size(); ++
i) {
191 auto pix = theClusterParam.theCluster->pixel(
i);
192 int irow =
int(pix.x) - row_offset;
193 int icol =
int(pix.y) - col_offset;
197 if ((irow < mrow) & (icol < mcol))
198 clustMatrix[irow][icol] =
float(pix.adc);
202 bool xdouble[mrow], ydouble[mcol];
204 for (
int irow = 0; irow < mrow; ++irow)
208 for (
int icol = 0; icol < mcol; ++icol)
214 float nonsense = -99999.9f;
221 theClusterParam.hasFilledProb_ =
false;
223 float templYrec1_ = nonsense;
224 float templXrec1_ = nonsense;
225 float templYrec2_ = nonsense;
226 float templXrec2_ = nonsense;
231 float locBz = theDetParam.
bz;
232 float locBx = theDetParam.
bx;
235 theClusterParam.cotalpha,
236 theClusterParam.cotbeta,
255 LogDebug(
"PixelCPETemplateReco::localPosition")
256 <<
"reconstruction failed with error " << theClusterParam.
ierr <<
"\n";
261 float lorentz_drift = -999.9;
263 lorentz_drift = 60.0f;
265 lorentz_drift = 10.0f;
267 if (theClusterParam.with_track_angle) {
269 theDetParam.
theTopol->
localX(theClusterParam.theCluster->x(), theClusterParam.loc_trk_pred) -
270 lorentz_drift * micronsToCm;
272 theDetParam.
theTopol->
localY(theClusterParam.theCluster->y(), theClusterParam.loc_trk_pred);
274 edm::LogError(
"PixelCPETemplateReco") <<
"@SUB = PixelCPETemplateReco::localPosition"
275 <<
"Should never be here. PixelCPETemplateReco should always be called "
276 "with track angles. This is a bad error !!! ";
279 lorentz_drift * micronsToCm;
283 edm::LogError(
"PixelCPETemplateReco") <<
" PixelCPETemplateReco: Qbin = 0 but using cluster splitter, we should "
284 "never be here !!!!!!!!!!!!!!!!!!!!!! \n"
300 theClusterParam.
ierr = -123;
317 if (theClusterParam.
ierr != 0) {
318 LogDebug(
"PixelCPETemplateReco::localPosition")
319 <<
"reconstruction failed with error " << theClusterParam.
ierr <<
"\n";
324 float lorentz_drift = -999.9f;
326 lorentz_drift = 60.0f;
328 lorentz_drift = 10.0f;
331 if (theClusterParam.with_track_angle) {
333 theDetParam.
theTopol->
localX(theClusterParam.theCluster->x(), theClusterParam.loc_trk_pred) -
334 lorentz_drift * micronsToCm;
336 theDetParam.
theTopol->
localY(theClusterParam.theCluster->y(), theClusterParam.loc_trk_pred);
338 edm::LogError(
"PixelCPETemplateReco") <<
"@SUB = PixelCPETemplateReco::localPosition"
339 <<
"Should never be here. PixelCPETemplateReco should always be called "
340 "with track angles. This is a bad error !!! ";
343 lorentz_drift * micronsToCm;
348 templXrec1_ *= micronsToCm;
349 templYrec1_ *= micronsToCm;
350 templXrec2_ *= micronsToCm;
351 templYrec2_ *= micronsToCm;
354 templXrec1_ += lp.
x();
355 templYrec1_ += lp.
y();
356 templXrec2_ += lp.
x();
357 templYrec2_ += lp.
y();
360 float distX1 =
std::abs(templXrec1_ - theClusterParam.trk_lp_x);
361 float distX2 =
std::abs(templXrec2_ - theClusterParam.trk_lp_x);
362 float distY1 =
std::abs(templYrec1_ - theClusterParam.trk_lp_y);
363 float distY2 =
std::abs(templYrec2_ - theClusterParam.trk_lp_y);
364 theClusterParam.
templXrec_ = (distX1 < distX2 ? templXrec1_ : templXrec2_);
365 theClusterParam.
templYrec_ = (distY1 < distY2 ? templYrec1_ : templYrec2_);
388 float templateLorbiasCmX = -micronsToCm * templ.
lorxbias();
389 float templateLorbiasCmY = -micronsToCm * templ.
lorybias();
408 theClusterParam.probabilityX_ = theClusterParam.
templProbX_;
409 theClusterParam.probabilityY_ = theClusterParam.
templProbY_;
410 theClusterParam.probabilityQ_ = theClusterParam.
templProbQ_;
411 theClusterParam.qBin_ = theClusterParam.
templQbin_;
413 if (theClusterParam.
ierr == 0)
414 theClusterParam.hasFilledProb_ =
true;
423 ClusterParamTemplate& theClusterParam = static_cast<ClusterParamTemplate&>(theClusterParamBase);
438 if (theClusterParam.theCluster->getSplitClusterErrorX() > 0.0f &&
440 theClusterParam.theCluster->getSplitClusterErrorY() > 0.0f &&
442 xerr = theClusterParam.theCluster->getSplitClusterErrorX() * micronsToCm;
443 yerr = theClusterParam.theCluster->getSplitClusterErrorY() * micronsToCm;
453 int maxPixelCol = theClusterParam.theCluster->maxPixelCol();
454 int maxPixelRow = theClusterParam.theCluster->maxPixelRow();
455 int minPixelCol = theClusterParam.theCluster->minPixelCol();
456 int minPixelRow = theClusterParam.theCluster->minPixelRow();
464 if (theClusterParam.
ierr != 0) {
471 throw cms::Exception(
"PixelCPETemplateReco::localPosition :") <<
"A non-pixel detector type in here?";
475 xerr = 55.0f * micronsToCm;
476 yerr = 36.0f * micronsToCm;
478 xerr = 42.0f * micronsToCm;
479 yerr = 39.0f * micronsToCm;
486 }
else if (edgex || edgey) {
488 if (edgex && !edgey) {
491 }
else if (!edgex && edgey) {
494 }
else if (edgex && edgey) {
498 throw cms::Exception(
" PixelCPETemplateReco::localError: Something wrong with pixel edge flag !!!");
518 LogDebug(
"PixelCPETemplateReco") <<
" Sizex = " << theClusterParam.theCluster->sizeX()
519 <<
" Sizey = " << theClusterParam.theCluster->sizeY() <<
" Edgex = " << edgex
520 <<
" Edgey = " << edgey <<
" ErrX = " << xerr <<
" ErrY = " << yerr;
527 <<
"\nERROR: Negative pixel error xerr = " << xerr <<
"\n\n";
531 <<
"\nERROR: Negative pixel error yerr = " << yerr <<
"\n\n";
539 return LocalError(xerr * xerr, 0, yerr * yerr);
543 desc.add<
int>(
"barrelTemplateID", 0);
544 desc.add<
int>(
"forwardTemplateID", 0);
545 desc.add<
int>(
"directoryWithTemplates", 0);
546 desc.add<
int>(
"speed", -2);
547 desc.add<
bool>(
"UseClusterSplitter",
false);