24 #include "boost/multi_array.hpp"
28 using namespace SiPixelTemplateReco;
47 :
PixelCPEBase(conf, mag, geom, lorentzAngle, 0, templateDBobject, 0,1)
69 <<
"\nERROR: Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version "
70 << (*templateDBobject_).version() <<
"\n\n";
78 <<
"\nERROR: Templates 40 not loaded correctly from text file. Reconstruction will fail.\n\n";
82 <<
"\nERROR: Templates 41 not loaded correctly from text file. Reconstruction will fail.\n\n";
86 LogDebug(
"PixelCPETemplateReco::PixelCPETemplateReco:") <<
87 "Template speed = " <<
speed_ <<
"\n";
130 if(ID0!=ID)
cout<<
" different id"<< ID<<
" "<<ID0<<endl;
132 if ( !fpix ) ID = 40;
141 boost::multi_array<float, 2> clust_array_2d(boost::extents[cluster_matrix_size_x][cluster_matrix_size_y]);
152 int row_offset = theClusterParam.theCluster->minPixelRow();
153 int col_offset = theClusterParam.theCluster->minPixelCol();
158 float tmp_x = float(row_offset) + 0.5f;
159 float tmp_y = float(col_offset) + 0.5f;
167 if ( theClusterParam.with_track_angle )
172 <<
"@SUB = PixelCPETemplateReco::localPosition"
173 <<
"Should never be here. PixelCPETemplateReco should always be called with track angles. This is a bad error !!! ";
179 for (
int i=0 ;
i!=theClusterParam.theCluster->size(); ++
i )
181 auto pix = theClusterParam.theCluster->pixel(
i);
186 int irow = int(pix.x) - row_offset;
187 int icol = int(pix.y) - col_offset;
191 if ( irow<cluster_matrix_size_x && icol<cluster_matrix_size_y )
193 clust_array_2d[irow][icol] = (float)pix.adc;
197 std::vector<bool> ydouble(cluster_matrix_size_y), xdouble(cluster_matrix_size_x);
199 for (
int irow = 0; irow < cluster_matrix_size_x; ++irow)
205 for (
int icol = 0; icol < cluster_matrix_size_y; ++icol)
211 float nonsense = -99999.9f;
217 theClusterParam.hasFilledProb_ =
false;
219 float templYrec1_ = nonsense;
220 float templXrec1_ = nonsense;
221 float templYrec2_ = nonsense;
222 float templXrec2_ = nonsense;
228 float locBz = theDetParam.
bz;
230 theClusterParam.
ierr =
231 PixelTempReco2D( ID, theClusterParam.cotalpha, theClusterParam.cotbeta,
233 clust_array_2d, ydouble, xdouble,
247 LogDebug(
"PixelCPETemplateReco::localPosition") <<
248 "reconstruction failed with error " << theClusterParam.
ierr <<
"\n";
253 float lorentz_drift = -999.9;
255 lorentz_drift = 60.0f;
257 lorentz_drift = 10.0f;
260 <<
"A non-pixel detector type in here?" <<
"\n";
262 if ( theClusterParam.with_track_angle )
264 theClusterParam.
templXrec_ = theDetParam.
theTopol->
localX( theClusterParam.theCluster->x(), theClusterParam.loc_trk_pred ) - lorentz_drift * micronsToCm;
265 theClusterParam.
templYrec_ = theDetParam.
theTopol->
localY( theClusterParam.theCluster->y(), theClusterParam.loc_trk_pred );
270 <<
"@SUB = PixelCPETemplateReco::localPosition"
271 <<
"Should never be here. PixelCPETemplateReco should always be called with track angles. This is a bad error !!! ";
273 theClusterParam.
templXrec_ = theDetParam.
theTopol->
localX( theClusterParam.theCluster->x() ) - lorentz_drift * micronsToCm;
279 cout <<
" PixelCPETemplateReco : We should never be here !!!!!!!!!!!!!!!!!!!!!!" << endl;
293 std::vector< SiPixelTemplateStore2D > thePixelTemp2D_;
297 theClusterParam.
ierr =
311 if ( theClusterParam.
ierr != 0 )
313 LogDebug(
"PixelCPETemplateReco::localPosition") <<
314 "reconstruction failed with error " << theClusterParam.
ierr <<
"\n";
319 float lorentz_drift = -999.9f;
321 lorentz_drift = 60.0f;
323 lorentz_drift = 10.0f;
326 <<
"A non-pixel detector type in here?" <<
"\n";
329 if ( theClusterParam.with_track_angle )
331 theClusterParam.
templXrec_ = theDetParam.
theTopol->
localX( theClusterParam.theCluster->x(),theClusterParam.loc_trk_pred ) - lorentz_drift * micronsToCm;
332 theClusterParam.
templYrec_ = theDetParam.
theTopol->
localY( theClusterParam.theCluster->y(),theClusterParam.loc_trk_pred );
337 <<
"@SUB = PixelCPETemplateReco::localPosition"
338 <<
"Should never be here. PixelCPETemplateReco should always be called with track angles. This is a bad error !!! ";
340 theClusterParam.
templXrec_ = theDetParam.
theTopol->
localX( theClusterParam.theCluster->x() ) - 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();
361 float distance11 =
sqrt( (templXrec1_ - theClusterParam.trk_lp_x)*(templXrec1_ - theClusterParam.trk_lp_x) +
362 (templYrec1_ - theClusterParam.trk_lp_y)*(templYrec1_ - theClusterParam.trk_lp_y) );
364 float distance12 =
sqrt( (templXrec1_ - theClusterParam.trk_lp_x)*(templXrec1_ - theClusterParam.trk_lp_x) +
365 (templYrec2_ - theClusterParam.trk_lp_y)*(templYrec2_ - theClusterParam.trk_lp_y) );
367 float distance21 =
sqrt( (templXrec2_ - theClusterParam.trk_lp_x)*(templXrec2_ - theClusterParam.trk_lp_x) +
368 (templYrec1_ - theClusterParam.trk_lp_y)*(templYrec1_ - theClusterParam.trk_lp_y) );
370 float distance22 =
sqrt( (templXrec2_ - theClusterParam.trk_lp_x)*(templXrec2_ - theClusterParam.trk_lp_x) +
371 (templYrec2_ - theClusterParam.trk_lp_y)*(templYrec2_ - theClusterParam.trk_lp_y) );
373 float min_templXrec_ = -999.9;
374 float min_templYrec_ = -999.9;
375 float distance_min = 9999999999.9;
376 if ( distance11 < distance_min )
378 distance_min = distance11;
379 min_templXrec_ = templXrec1_;
380 min_templYrec_ = templYrec1_;
382 if ( distance12 < distance_min )
384 distance_min = distance12;
385 min_templXrec_ = templXrec1_;
386 min_templYrec_ = templYrec2_;
388 if ( distance21 < distance_min )
390 distance_min = distance21;
391 min_templXrec_ = templXrec2_;
392 min_templYrec_ = templYrec1_;
394 if ( distance22 < distance_min )
396 distance_min = distance22;
397 min_templXrec_ = templXrec2_;
398 min_templYrec_ = templYrec2_;
425 float templateLorbiasCmX = -micronsToCm*templ.
lorxbias();
426 float templateLorbiasCmY = -micronsToCm*templ.
lorybias();
446 theClusterParam.probabilityX_ = theClusterParam.
templProbX_;
447 theClusterParam.probabilityY_ = theClusterParam.
templProbY_;
448 theClusterParam.probabilityQ_ = theClusterParam.
templProbQ_;
449 theClusterParam.qBin_ = theClusterParam.
templQbin_;
451 if ( theClusterParam.
ierr == 0 )
452 theClusterParam.hasFilledProb_ =
true;
473 const float sig12 = 1./
sqrt(12.0);
474 float xerr = theDetParam.
thePitchX *sig12;
475 float yerr = theDetParam.
thePitchY *sig12;
478 if ( theClusterParam.theCluster->getSplitClusterErrorX() > 0.0f && theClusterParam.theCluster->getSplitClusterErrorX() < 7777.7f &&
479 theClusterParam.theCluster->getSplitClusterErrorY() > 0.0f && theClusterParam.theCluster->getSplitClusterErrorY() < 7777.7f )
481 xerr = theClusterParam.theCluster->getSplitClusterErrorX() * micronsToCm;
482 yerr = theClusterParam.theCluster->getSplitClusterErrorY() * micronsToCm;
494 int maxPixelCol = theClusterParam.theCluster->maxPixelCol();
495 int maxPixelRow = theClusterParam.theCluster->maxPixelRow();
496 int minPixelCol = theClusterParam.theCluster->minPixelCol();
497 int minPixelRow = theClusterParam.theCluster->minPixelRow();
503 if ( theClusterParam.
ierr !=0 )
513 xerr = 55.0f * micronsToCm;
514 yerr = 36.0f * micronsToCm;
518 xerr = 42.0f * micronsToCm;
519 yerr = 39.0f * micronsToCm;
522 throw cms::Exception(
"PixelCPETemplateReco::localError :") <<
"A non-pixel detector type in here?" ;
529 else if ( edgex || edgey )
532 if ( edgex && !edgey )
534 xerr = 23.0f * micronsToCm;
535 yerr = 39.0f * micronsToCm;
537 else if ( !edgex && edgey )
539 xerr = 24.0f * micronsToCm;
540 yerr = 96.0f * micronsToCm;
542 else if ( edgex && edgey )
544 xerr = 31.0f * micronsToCm;
545 yerr = 90.0f * micronsToCm;
549 throw cms::Exception(
" PixelCPETemplateReco::localError: Something wrong with pixel edge flag !!!");
573 " Sizex = " << theClusterParam.theCluster->sizeX() <<
" Sizey = " << theClusterParam.theCluster->sizeY() <<
" Edgex = " << edgex <<
" Edgey = " << edgey <<
574 " ErrX = " << xerr <<
" ErrY = " << yerr;
579 if ( !(xerr > 0.0
f) )
581 <<
"\nERROR: Negative pixel error xerr = " << xerr <<
"\n\n";
583 if ( !(yerr > 0.0
f) )
585 <<
"\nERROR: Negative pixel error yerr = " << yerr <<
"\n\n";
T getParameter(std::string const &) const
LocalError localError(DetParam const &theDetParam, ClusterParam &theClusterParam) const
bool isItEdgePixelInY(int iybin) const
virtual LocalPoint localPosition(const MeasurementPoint &) const =0
short getTemplateID(const uint32_t &detid) const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
virtual bool isItBigPixelInY(const int iybin) const
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore2D > &thePixelTemp_)
bool isItEdgePixelInX(int ixbin) const
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore > &thePixelTemp_)
const PixelGeomDetUnit * theDet
GeomDetType::SubDetector thePart
const RectangularPixelTopology * theRecTopol
std::vector< SiPixelTemplateStore > thePixelTemp_
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
const PixelTopology * theTopol
bool LoadTemplatesFromDB_
int PixelTempSplit(int id, float cotalpha, float cotbeta, array_2d &cluster, std::vector< bool > &ydouble, std::vector< bool > &xdouble, SiPixelTemplate &templ, float &yrec1, float &yrec2, float &sigmay, float &prob2y, float &xrec1, float &xrec2, float &sigmax, float &prob2x, int &q2bin, float &prob2Q, bool resolve, int speed, float &dchisq, bool deadpix, std::vector< std::pair< int, int > > &zeropix, SiPixelTemplate2D &templ2D)
const SiPixelTemplateDBObject * templateDBobject_
DetId geographicalId() const
The label of this GeomDet.
int PixelTempReco2D(int id, float cotalpha, float cotbeta, float locBz, array_2d &cluster, std::vector< bool > &ydouble, std::vector< bool > &xdouble, SiPixelTemplate &templ, float &yrec, float &sigmay, float &proby, float &xrec, float &sigmax, float &probx, int &qbin, int speed, bool deadpix, std::vector< std::pair< int, int > > &zeropix, float &probQ)
PixelCPETemplateReco(edm::ParameterSet const &conf, const MagneticField *, const TrackerGeometry &, const SiPixelLorentzAngle *, const SiPixelTemplateDBObject *)
virtual float localX(const float mpX) const =0
float lorybias()
signed lorentz y-width (microns)
ClusterParam * createClusterParam(const SiPixelCluster &cl) const
Pixel cluster – collection of neighboring pixels above threshold.
float lorxbias()
signed lorentz x-width (microns)
virtual bool isItBigPixelInX(const int ixbin) const
LocalPoint localPosition(DetParam const &theDetParam, ClusterParam &theClusterParam) const
virtual float localY(const float mpY) const =0