18 #include "boost/multi_array.hpp" 19 #include <boost/regex.hpp> 29 constexpr
float micronsToCm = 1.0e-4;
30 constexpr
int cluster_matrix_size_x = 13;
31 constexpr
int cluster_matrix_size_y = 21;
45 :
PixelCPEBase(conf,
mag,
geom, ttopo, lorentzAngle, nullptr, templateDBobject, nullptr, 1) {
46 LogDebug(
"PixelCPEClusterRepair::(constructor)") << endl;
53 <<
"\nERROR: Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version " 54 << (*templateDBobject_).version() <<
"\n\n";
59 <<
"\nERROR: Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject2D version " 60 << (*templateDBobject2D).version() <<
"\n\n";
62 LogDebug(
"PixelCPEClusterRepair") <<
"Loading templates for barrel and forward from ASCII files." << endl;
72 <<
" not loaded correctly from text file. Reconstruction will fail.\n\n";
77 <<
" not loaded correctly from text file. Reconstruction will fail.\n\n";
81 LogDebug(
"PixelCPEClusterRepair::PixelCPEClusterRepair:") <<
"Template speed = " <<
speed_ <<
"\n";
84 int theMagField =
mag->nominalValue();
86 if (theMagField >= 36 && theMagField < 39) {
87 LogDebug(
"PixelCPEClusterRepair::PixelCPEClusterRepair:")
88 <<
"Magnetic field value is: " << theMagField <<
" kgauss. Algorithm is being run \n";
103 std::vector<std::string> str_recommend2D = conf.
getParameter<std::vector<std::string>>(
"Recommend2D");
105 for (
auto&
str : str_recommend2D) {
110 if (theMagField < 36 || theMagField > 39) {
123 unsigned m_detectors = dus.size();
124 for (
unsigned int i = 1;
i < 7; ++
i) {
125 LogDebug(
"PixelCPEClusterRepair:: LookingForFirstStrip")
137 LogDebug(
"LookingForFirstStrip") <<
" Chosen offset: " << m_detectors;
140 LogDebug(
"PixelCPEClusterRepair::fillDetParams():") <<
"caching " << m_detectors <<
" pixel detectors" << endl;
142 bool printed_info =
false;
143 for (
unsigned i = 0;
i != m_detectors; ++
i) {
147 if (
p.detTemplateId !=
p.detTemplateId2D && !printed_info) {
149 <<
"different template ID between 1D and 2D " <<
p.detTemplateId <<
" " <<
p.detTemplateId2D << endl;
161 return std::make_unique<ClusterParamTemplate>(
cl);
173 bool filled_from_2d =
false;
176 throw cms::Exception(
"PixelCPEClusterRepair::localPosition :") <<
"A non-pixel detector type in here?";
203 float tmp_x =
float(row_offset) + 0.5f;
204 float tmp_y =
float(col_offset) + 0.5f;
213 edm::LogError(
"PixelCPEClusterRepair") <<
"@SUB = PixelCPEClusterRepair::localPosition" 214 <<
"Should never be here. PixelCPEClusterRepair should always be called " 215 "with track angles. This is a bad error !!! ";
221 int mrow = 0, mcol = 0;
224 int irow =
int(pix.x);
225 int icol =
int(pix.y);
231 mrow =
std::min(mrow, cluster_matrix_size_x);
234 mcol =
std::min(mcol, cluster_matrix_size_y);
239 bool xdouble[mrow], ydouble[mcol];
241 for (
int irow = 0; irow < mrow; ++irow)
245 for (
int icol = 0; icol < mcol; ++icol)
249 float clustMatrix[mrow][mcol];
250 float clustMatrix2[mrow][mcol];
257 memset(clustMatrix, 0,
sizeof(
float) * mrow * mcol);
260 int irow =
int(pix.x) - row_offset;
261 int icol =
int(pix.y) - col_offset;
263 if ((irow < mrow) & (icol < mcol))
264 clustMatrix[irow][icol] =
float(pix.adc);
269 memcpy(clustMatrix2, clustMatrix,
sizeof(
float) * mrow * mcol);
272 theClusterParam.
ierr = 0;
273 theClusterParam.
ierr2 = 0;
279 filled_from_2d =
true;
280 callTempReco2D(theDetParam, theClusterParam, clusterPayload2d, ID2, lp);
283 callTempReco1D(theDetParam, theClusterParam, clusterPayload, ID1, lp);
284 filled_from_2d =
false;
293 theClusterParamBase.
qBin_ = theClusterParam.
qBin_;
296 if (filled_from_2d) {
318 float nonsense = -99999.9f;
323 theClusterParam.
qBin_ = 0;
335 float locBz = theDetParam.
bz;
336 float locBx = theDetParam.
bx;
338 const bool deadpix =
false;
339 std::vector<std::pair<int, int>> zeropix;
340 int nypix = 0, nxpix = 0;
355 theClusterParam.
qBin_,
366 LogDebug(
"PixelCPEClusterRepair::localPosition")
367 <<
"reconstruction failed with error " << theClusterParam.
ierr <<
"\n";
370 theClusterParam.
qBin_ = 0;
381 edm::LogError(
"PixelCPEClusterRepair") <<
"@SUB = PixelCPEClusterRepair::localPosition" 382 <<
"Should never be here. PixelCPEClusterRepair should always be called " 383 "with track angles. This is a bad error !!! ";
414 float nonsense = -99999.9f;
419 theClusterParam.
qBin_ = 0;
431 float locBz = theDetParam.
bz;
432 float locBx = theDetParam.
bx;
453 if (clusterPayload.
mrow > 4) {
456 theClusterParam.
ierr2 = 8;
474 theClusterParam.
qBin_,
482 LogDebug(
"PixelCPEClusterRepair::localPosition")
483 <<
"2D reconstruction failed with error " << theClusterParam.
ierr2 <<
"\n";
486 theClusterParam.
qBin_ = 0;
497 edm::LogError(
"PixelCPEClusterRepair") <<
"@SUB = PixelCPEClusterRepair::localPosition" 498 <<
"Should never be here. PixelCPEClusterRepair should always be called " 499 "with track angles. This is a bad error !!! ";
534 bool recommend =
false;
536 recommend = rec.recommend(
id,
ttopo_);
562 float nypix = clusterPayload.
mcol;
563 for (
int i = 0;
i < clusterPayload.
mcol;
i++) {
571 float nydiff = templ.
clsleny() - nypix;
599 if (min_col % 2 == 0) {
620 float xerr = 0.0f, yerr = 0.0f;
642 throw cms::Exception(
"PixelCPEClusterRepair::localPosition :") <<
"A non-pixel detector type in here?";
646 xerr = 55.0f * micronsToCm;
647 yerr = 36.0f * micronsToCm;
649 xerr = 42.0f * micronsToCm;
650 yerr = 39.0f * micronsToCm;
679 <<
" Edgey = " << theClusterParam.
edgeTypeY_ <<
" ErrX = " << xerr
680 <<
" ErrY = " << yerr;
685 <<
"\nERROR: Negative pixel error xerr = " << xerr <<
"\n\n";
689 <<
"\nERROR: Negative pixel error yerr = " << yerr <<
"\n\n";
691 return LocalError(xerr * xerr, 0, yerr * yerr);
695 static const boost::regex rule(
"([A-Z]+)(\\s+(\\d+))?");
698 if (!regex_match(
str.c_str(),
match, rule))
699 throw cms::Exception(
"Configuration") <<
"Rule '" <<
str <<
"' not understood.\n";
705 else if (strncmp(
match[1].
first,
"PXE", 3) == 0)
709 <<
"Detector '" <<
match[1].first <<
"' not understood. Should be PXB, PXE.\n";
720 desc.add<
int>(
"barrelTemplateID", 0);
721 desc.add<
int>(
"forwardTemplateID", 0);
722 desc.add<
int>(
"directoryWithTemplates", 0);
723 desc.add<
int>(
"speed", -2);
724 desc.add<
bool>(
"UseClusterSplitter",
false);
725 desc.add<
double>(
"MaxSizeMismatchInY", 0.3);
726 desc.add<
double>(
"MinChargeRatio", 0.8);
727 desc.add<std::vector<std::string>>(
"Recommend2D", {
"PXB 2",
"PXB 3",
"PXB 4"});
728 desc.add<
bool>(
"RunDamagedClusters",
false);
float getSplitClusterErrorX() const
static constexpr float xEdgeYError_
T getParameter(std::string const &) const
Point3DBase< Scalar, LocalTag > LocalPoint
bool interpolate(int id, float cotalpha, float cotbeta, float locBz, float locBx)
float getSplitClusterErrorY() const
virtual LocalPoint localPosition(const MeasurementPoint &) const =0
std::unique_ptr< ClusterParam > createClusterParam(const SiPixelCluster &cl) const override
int PixelTempReco2D(int id, float cotalpha, float cotbeta, float locBz, float locBx, int edgeflagy, int edgeflagx, ClusMatrix &cluster, SiPixelTemplate2D &templ, float &yrec, float &sigmay, float &xrec, float &sigmax, float &probxy, float &probQ, int &qbin, float &deltay, int &npixel)
const SiPixelCluster * theCluster
bool isBarrel(GeomDetEnumerators::SubDetector m)
unsigned int offsetDU(SubDetector sid) const
LocalPoint localPosition(DetParam const &theDetParam, ClusterParam &theClusterParam) const override
std::vector< SiPixelTemplateStore2D > thePixelTemp2D_
int PixelTempReco1D(int id, float cotalpha, float cotbeta, float locBz, float locBx, ClusMatrix &cluster, 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, int &nypix, int &nxpix)
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
Rule(const std::string &str)
Log< level::Error, false > LogError
static constexpr float bothEdgeYError_
const PixelGeomDetUnit * theDet
GeomDetType::SubDetector thePart
static constexpr float yEdgeYError_
std::vector< SiPixelTemplateStore > thePixelTemp_
const RectangularPixelTopology * theRecTopol
std::vector< Rule > recommend2D_
virtual float localX(float mpX) const =0
U second(std::pair< T, U > const &p)
PixelCPEClusterRepair(edm::ParameterSet const &conf, const MagneticField *, const TrackerGeometry &, const TrackerTopology &, const SiPixelLorentzAngle *, const SiPixelTemplateDBObject *, const SiPixel2DTemplateDBObject *)
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
const PixelTopology * theTopol
bool LoadTemplatesFromDB_
bool isItBigPixelInX(const int ixbin) const override
const SiPixel2DTemplateDBObject * templateDBobject2D_
float clsleny()
y-size of smaller interpolated template in pixels
LocalError localError(DetParam const &theDetParam, ClusterParam &theClusterParam) const override
const SiPixelTemplateDBObject * templateDBobject_
~PixelCPEClusterRepair() override
float maxSizeMismatchInY_
static void fillPSetDescription(edm::ParameterSetDescription &desc)
DetId geographicalId() const
The label of this GeomDet.
bool isEndcap(GeomDetEnumerators::SubDetector m)
Topology::LocalTrackPred loc_trk_pred
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
static constexpr float xEdgeXError_
virtual float localY(float mpY) const =0
const TrackerTopology & ttopo_
static constexpr float clusterSplitMaxError_
float qavg()
average cluster charge for this set of track angles
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore > &pixelTemp, std::string dir="CalibTracker/SiPixelESProducers/data/")
short getTemplateID(const uint32_t &detid) const
Pixel cluster – collection of neighboring pixels above threshold.
const TrackerGeometry & geom_
static constexpr float bothEdgeXError_
void checkRecommend2D(DetParam const &theDetParam, ClusterParamTemplate &theClusterParam, SiPixelTemplateReco::ClusMatrix &clusterPayload, int ID) const
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
bool isItBigPixelInY(const int iybin) const override
static constexpr float yEdgeXError_
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore2D > &pixelTemp, std::string dir="CalibTracker/SiPixelESProducers/data/")
Log< level::Warning, false > LogWarning
void callTempReco1D(DetParam const &theDetParam, ClusterParamTemplate &theClusterParam, SiPixelTemplateReco::ClusMatrix &clusterPayload, int ID, LocalPoint &lp) const
void callTempReco2D(DetParam const &theDetParam, ClusterParamTemplate &theClusterParam, SiPixelTemplateReco2D::ClusMatrix &clusterPayload, int ID, LocalPoint &lp) const
bool isTrackerPixel(GeomDetEnumerators::SubDetector m)
constexpr SubDetector tkDetEnum[8]