18 #include "boost/multi_array.hpp" 19 #include <boost/regex.hpp> 43 const std::vector<SiPixelTemplateStore>* templateStore,
46 :
PixelCPEBase(conf,
mag,
geom, ttopo, lorentzAngle, nullptr, templateDBobject, nullptr, 1) {
47 LogDebug(
"PixelCPEClusterRepair::(constructor)") << endl;
55 <<
"\nERROR: Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject2D version " 56 << (*templateDBobject2D).version() <<
"\n\n";
58 LogDebug(
"PixelCPEClusterRepair") <<
"Loading templates for barrel and forward from ASCII files." << endl;
69 <<
" not loaded correctly from text file. Reconstruction will fail.\n\n";
74 <<
" not loaded correctly from text file. Reconstruction will fail.\n\n";
78 LogDebug(
"PixelCPEClusterRepair::PixelCPEClusterRepair:") <<
"Template speed = " <<
speed_ <<
"\n";
81 int theMagField =
mag->nominalValue();
83 if (theMagField >= 36 && theMagField < 39) {
84 LogDebug(
"PixelCPEClusterRepair::PixelCPEClusterRepair:")
85 <<
"Magnetic field value is: " << theMagField <<
" kgauss. Algorithm is being run \n";
100 std::vector<std::string> str_recommend2D = conf.
getParameter<std::vector<std::string>>(
"Recommend2D");
102 for (
auto&
str : str_recommend2D) {
107 if (theMagField < 36 || theMagField > 39) {
120 unsigned m_detectors = dus.size();
121 for (
unsigned int i = 1;
i < 7; ++
i) {
122 LogDebug(
"PixelCPEClusterRepair:: LookingForFirstStrip")
134 LogDebug(
"LookingForFirstStrip") <<
" Chosen offset: " << m_detectors;
137 LogDebug(
"PixelCPEClusterRepair::fillDetParams():") <<
"caching " << m_detectors <<
" pixel detectors" << endl;
139 bool printed_info =
false;
140 for (
unsigned i = 0;
i != m_detectors; ++
i) {
144 if (
p.detTemplateId !=
p.detTemplateId2D && !printed_info) {
146 <<
"different template ID between 1D and 2D " <<
p.detTemplateId <<
" " <<
p.detTemplateId2D << endl;
158 return std::make_unique<ClusterParamTemplate>(
cl);
170 bool filled_from_2d =
false;
173 throw cms::Exception(
"PixelCPEClusterRepair::localPosition :") <<
"A non-pixel detector type in here?";
200 float tmp_x =
float(row_offset) + 0.5f;
201 float tmp_y =
float(col_offset) + 0.5f;
210 edm::LogError(
"PixelCPEClusterRepair") <<
"@SUB = PixelCPEClusterRepair::localPosition" 211 <<
"Should never be here. PixelCPEClusterRepair should always be called " 212 "with track angles. This is a bad error !!! ";
218 int mrow = 0, mcol = 0;
221 int irow =
int(pix.x);
222 int icol =
int(pix.y);
228 mrow =
std::min(mrow, cluster_matrix_size_x);
231 mcol =
std::min(mcol, cluster_matrix_size_y);
236 bool xdouble[mrow], ydouble[mcol];
238 for (
int irow = 0; irow < mrow; ++irow)
242 for (
int icol = 0; icol < mcol; ++icol)
246 float clustMatrix[mrow][mcol];
247 float clustMatrix2[mrow][mcol];
254 memset(clustMatrix, 0,
sizeof(
float) * mrow * mcol);
257 int irow =
int(pix.x) - row_offset;
258 int icol =
int(pix.y) - col_offset;
260 if ((irow < mrow) & (icol < mcol))
261 clustMatrix[irow][icol] =
float(pix.adc);
266 memcpy(clustMatrix2, clustMatrix,
sizeof(
float) * mrow * mcol);
269 theClusterParam.
ierr = 0;
270 theClusterParam.
ierr2 = 0;
276 filled_from_2d =
true;
277 callTempReco2D(theDetParam, theClusterParam, clusterPayload2d, ID2, lp);
280 callTempReco1D(theDetParam, theClusterParam, clusterPayload, ID1, lp);
281 filled_from_2d =
false;
290 theClusterParamBase.
qBin_ = theClusterParam.
qBin_;
293 if (filled_from_2d) {
315 float nonsense = -99999.9f;
320 theClusterParam.
qBin_ = 0;
332 float locBz = theDetParam.
bz;
333 float locBx = theDetParam.
bx;
335 const bool deadpix =
false;
336 std::vector<std::pair<int, int>> zeropix;
337 int nypix = 0, nxpix = 0;
352 theClusterParam.
qBin_,
363 LogDebug(
"PixelCPEClusterRepair::localPosition")
364 <<
"reconstruction failed with error " << theClusterParam.
ierr <<
"\n";
367 theClusterParam.
qBin_ = 0;
378 edm::LogError(
"PixelCPEClusterRepair") <<
"@SUB = PixelCPEClusterRepair::localPosition" 379 <<
"Should never be here. PixelCPEClusterRepair should always be called " 380 "with track angles. This is a bad error !!! ";
411 float nonsense = -99999.9f;
416 theClusterParam.
qBin_ = 0;
428 float locBz = theDetParam.
bz;
429 float locBx = theDetParam.
bx;
450 if (clusterPayload.
mrow > 4) {
453 theClusterParam.
ierr2 = 8;
471 theClusterParam.
qBin_,
479 LogDebug(
"PixelCPEClusterRepair::localPosition")
480 <<
"2D reconstruction failed with error " << theClusterParam.
ierr2 <<
"\n";
483 theClusterParam.
qBin_ = 0;
494 edm::LogError(
"PixelCPEClusterRepair") <<
"@SUB = PixelCPEClusterRepair::localPosition" 495 <<
"Should never be here. PixelCPEClusterRepair should always be called " 496 "with track angles. This is a bad error !!! ";
531 bool recommend =
false;
533 recommend = rec.recommend(
id,
ttopo_);
559 float nypix = clusterPayload.
mcol;
560 for (
int i = 0;
i < clusterPayload.
mcol;
i++) {
568 float nydiff = templ.
clsleny() - nypix;
596 if (min_col % 2 == 0) {
617 float xerr = 0.0f, yerr = 0.0f;
639 throw cms::Exception(
"PixelCPEClusterRepair::localPosition :") <<
"A non-pixel detector type in here?";
676 <<
" Edgey = " << theClusterParam.
edgeTypeY_ <<
" ErrX = " << xerr
677 <<
" ErrY = " << yerr;
682 <<
"\nERROR: Negative pixel error xerr = " << xerr <<
"\n\n";
686 <<
"\nERROR: Negative pixel error yerr = " << yerr <<
"\n\n";
688 return LocalError(xerr * xerr, 0, yerr * yerr);
692 static const boost::regex rule(
"([A-Z]+)(\\s+(\\d+))?");
695 if (!regex_match(
str.c_str(),
match, rule))
696 throw cms::Exception(
"Configuration") <<
"Rule '" <<
str <<
"' not understood.\n";
702 else if (strncmp(
match[1].
first,
"PXE", 3) == 0)
706 <<
"Detector '" <<
match[1].first <<
"' not understood. Should be PXB, PXE.\n";
717 desc.add<
int>(
"barrelTemplateID", 0);
718 desc.add<
int>(
"forwardTemplateID", 0);
719 desc.add<
int>(
"directoryWithTemplates", 0);
720 desc.add<
int>(
"speed", -2);
721 desc.add<
bool>(
"UseClusterSplitter",
false);
722 desc.add<
double>(
"MaxSizeMismatchInY", 0.3);
723 desc.add<
double>(
"MinChargeRatio", 0.8);
724 desc.add<std::vector<std::string>>(
"Recommend2D", {
"PXB 2",
"PXB 3",
"PXB 4"});
725 desc.add<
bool>(
"RunDamagedClusters",
false);
float getSplitClusterErrorX() const
static constexpr float xEdgeYError_
std::vector< SiPixelTemplateStore > thePixelTempCache_
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)
std::vector< SiPixelTemplateStore > const * thePixelTemp_
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< Rule > recommend2D_
PixelCPEClusterRepair(edm::ParameterSet const &conf, const MagneticField *, const TrackerGeometry &, const TrackerTopology &, const SiPixelLorentzAngle *, const std::vector< SiPixelTemplateStore > *, const SiPixelTemplateDBObject *, const SiPixel2DTemplateDBObject *)
virtual float localX(float mpX) const =0
U second(std::pair< T, U > const &p)
constexpr float micronsToCm
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
const PixelTopology * theTopol
bool LoadTemplatesFromDB_
const SiPixel2DTemplateDBObject * templateDBobject2D_
virtual bool isItBigPixelInX(int ixbin) const =0
float clsleny()
y-size of smaller interpolated template in pixels
virtual bool isItBigPixelInY(int iybin) const =0
LocalError localError(DetParam const &theDetParam, ClusterParam &theClusterParam) const override
~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.
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]