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";
103 return std::make_unique<ClusterParamTemplate>(
cl);
114 ClusterParamTemplate& theClusterParam = static_cast<ClusterParamTemplate&>(theClusterParamBase);
117 throw cms::Exception(
"PixelCPETemplateReco::localPosition :") <<
"A non-pixel detector type in here?";
126 edm::LogError(
"PixelCPETemplateReco") <<
" different id" <<
ID <<
" " << ID0 << endl;
146 int row_offset = theClusterParam.theCluster->minPixelRow();
147 int col_offset = theClusterParam.theCluster->minPixelCol();
152 float tmp_x =
float(row_offset) + 0.5f;
153 float tmp_y =
float(col_offset) + 0.5f;
161 if (theClusterParam.with_track_angle)
164 edm::LogError(
"PixelCPETemplateReco") <<
"@SUB = PixelCPETemplateReco::localPosition"
165 <<
"Should never be here. PixelCPETemplateReco should always be called with "
166 "track angles. This is a bad error !!! ";
172 int mrow = 0, mcol = 0;
173 for (
int i = 0;
i != theClusterParam.theCluster->size(); ++
i) {
174 auto pix = theClusterParam.theCluster->pixel(
i);
175 int irow =
int(pix.x);
176 int icol =
int(pix.y);
182 mrow =
std::min(mrow, cluster_matrix_size_x);
185 mcol =
std::min(mcol, cluster_matrix_size_y);
189 float clustMatrix[mrow][mcol];
190 memset(clustMatrix, 0,
sizeof(
float) * mrow * mcol);
193 for (
int i = 0;
i != theClusterParam.theCluster->size(); ++
i) {
194 auto pix = theClusterParam.theCluster->pixel(
i);
195 int irow =
int(pix.x) - row_offset;
196 int icol =
int(pix.y) - col_offset;
200 if ((irow < mrow) & (icol < mcol))
201 clustMatrix[irow][icol] =
float(pix.adc);
205 bool xdouble[mrow], ydouble[mcol];
207 for (
int irow = 0; irow < mrow; ++irow)
211 for (
int icol = 0; icol < mcol; ++icol)
217 float nonsense = -99999.9f;
224 theClusterParam.hasFilledProb_ =
false;
226 float templYrec1_ = nonsense;
227 float templXrec1_ = nonsense;
228 float templYrec2_ = nonsense;
229 float templXrec2_ = nonsense;
234 float locBz = theDetParam.
bz;
235 float locBx = theDetParam.
bx;
238 theClusterParam.cotalpha,
239 theClusterParam.cotbeta,
258 LogDebug(
"PixelCPETemplateReco::localPosition")
259 <<
"reconstruction failed with error " << theClusterParam.
ierr <<
"\n";
264 float lorentz_drift = -999.9;
266 lorentz_drift = 60.0f;
268 lorentz_drift = 10.0f;
270 if (theClusterParam.with_track_angle) {
272 theDetParam.
theTopol->
localX(theClusterParam.theCluster->x(), theClusterParam.loc_trk_pred) -
273 lorentz_drift * micronsToCm;
275 theDetParam.
theTopol->
localY(theClusterParam.theCluster->y(), theClusterParam.loc_trk_pred);
277 edm::LogError(
"PixelCPETemplateReco") <<
"@SUB = PixelCPETemplateReco::localPosition"
278 <<
"Should never be here. PixelCPETemplateReco should always be called "
279 "with track angles. This is a bad error !!! ";
282 lorentz_drift * micronsToCm;
286 edm::LogError(
"PixelCPETemplateReco") <<
" PixelCPETemplateReco: Qbin = 0 but using cluster splitter, we should "
287 "never be here !!!!!!!!!!!!!!!!!!!!!! \n"
303 theClusterParam.
ierr = -123;
320 if (theClusterParam.
ierr != 0) {
321 LogDebug(
"PixelCPETemplateReco::localPosition")
322 <<
"reconstruction failed with error " << theClusterParam.
ierr <<
"\n";
327 float lorentz_drift = -999.9f;
329 lorentz_drift = 60.0f;
331 lorentz_drift = 10.0f;
334 if (theClusterParam.with_track_angle) {
336 theDetParam.
theTopol->
localX(theClusterParam.theCluster->x(), theClusterParam.loc_trk_pred) -
337 lorentz_drift * micronsToCm;
339 theDetParam.
theTopol->
localY(theClusterParam.theCluster->y(), theClusterParam.loc_trk_pred);
341 edm::LogError(
"PixelCPETemplateReco") <<
"@SUB = PixelCPETemplateReco::localPosition"
342 <<
"Should never be here. PixelCPETemplateReco should always be called "
343 "with track angles. This is a bad error !!! ";
346 lorentz_drift * micronsToCm;
351 templXrec1_ *= micronsToCm;
352 templYrec1_ *= micronsToCm;
353 templXrec2_ *= micronsToCm;
354 templYrec2_ *= micronsToCm;
357 templXrec1_ += lp.
x();
358 templYrec1_ += lp.
y();
359 templXrec2_ += lp.
x();
360 templYrec2_ += lp.
y();
363 float distX1 =
std::abs(templXrec1_ - theClusterParam.trk_lp_x);
364 float distX2 =
std::abs(templXrec2_ - theClusterParam.trk_lp_x);
365 float distY1 =
std::abs(templYrec1_ - theClusterParam.trk_lp_y);
366 float distY2 =
std::abs(templYrec2_ - theClusterParam.trk_lp_y);
367 theClusterParam.
templXrec_ = (distX1 < distX2 ? templXrec1_ : templXrec2_);
368 theClusterParam.
templYrec_ = (distY1 < distY2 ? templYrec1_ : templYrec2_);
391 float templateLorbiasCmX = -micronsToCm * templ.
lorxbias();
392 float templateLorbiasCmY = -micronsToCm * templ.
lorybias();
411 theClusterParam.probabilityX_ = theClusterParam.
templProbX_;
412 theClusterParam.probabilityY_ = theClusterParam.
templProbY_;
413 theClusterParam.probabilityQ_ = theClusterParam.
templProbQ_;
414 theClusterParam.qBin_ = theClusterParam.
templQbin_;
416 if (theClusterParam.
ierr == 0)
417 theClusterParam.hasFilledProb_ =
true;
426 ClusterParamTemplate& theClusterParam = static_cast<ClusterParamTemplate&>(theClusterParamBase);
441 if (theClusterParam.theCluster->getSplitClusterErrorX() > 0.0f &&
443 theClusterParam.theCluster->getSplitClusterErrorY() > 0.0f &&
445 xerr = theClusterParam.theCluster->getSplitClusterErrorX() * micronsToCm;
446 yerr = theClusterParam.theCluster->getSplitClusterErrorY() * micronsToCm;
456 int maxPixelCol = theClusterParam.theCluster->maxPixelCol();
457 int maxPixelRow = theClusterParam.theCluster->maxPixelRow();
458 int minPixelCol = theClusterParam.theCluster->minPixelCol();
459 int minPixelRow = theClusterParam.theCluster->minPixelRow();
467 if (theClusterParam.
ierr != 0) {
474 throw cms::Exception(
"PixelCPETemplateReco::localPosition :") <<
"A non-pixel detector type in here?";
478 xerr = 55.0f * micronsToCm;
479 yerr = 36.0f * micronsToCm;
481 xerr = 42.0f * micronsToCm;
482 yerr = 39.0f * micronsToCm;
489 }
else if (edgex || edgey) {
491 if (edgex && !edgey) {
494 }
else if (!edgex && edgey) {
497 }
else if (edgex && edgey) {
501 throw cms::Exception(
" PixelCPETemplateReco::localError: Something wrong with pixel edge flag !!!");
521 LogDebug(
"PixelCPETemplateReco") <<
" Sizex = " << theClusterParam.theCluster->sizeX()
522 <<
" Sizey = " << theClusterParam.theCluster->sizeY() <<
" Edgex = " << edgex
523 <<
" Edgey = " << edgey <<
" ErrX = " << xerr <<
" ErrY = " << yerr;
530 <<
"\nERROR: Negative pixel error xerr = " << xerr <<
"\n\n";
534 <<
"\nERROR: Negative pixel error yerr = " << yerr <<
"\n\n";
542 return LocalError(xerr * xerr, 0, yerr * yerr);
546 desc.add<
int>(
"barrelTemplateID", 0);
547 desc.add<
int>(
"forwardTemplateID", 0);
548 desc.add<
int>(
"directoryWithTemplates", 0);
549 desc.add<
int>(
"speed", -2);
550 desc.add<
bool>(
"UseClusterSplitter",
false);