54 #ifndef SI_PIXEL_TEMPLATE_STANDALONE 65 #include "Math/DistFunc.h" 70 #ifndef SI_PIXEL_TEMPLATE_STANDALONE 74 #define LOGERROR(x) edm::LogError(x) 75 #define LOGDEBUG(x) LogDebug(x) 81 #define LOGERROR(x) std::cout << x << ": " 82 #define LOGDEBUG(x) std::cout << x << ": " 83 #define ENDL std::endl 158 int i,
j,
k, minbin, binl, binh, binq, midpix, fypix, lypix, logypx;
159 int fxpix, lxpix, logxpx, shifty, shiftx, nyzero[
TYSIZE];
161 int deltaj, jmin, jmax, fxbin, lxbin, fybin, lybin, djy, djx;
163 float sythr, sxthr, rnorm,
delta, sigma, sigavg, pseudopix, qscale, q50;
164 float ss2, ssa, sa2, ssba, saba, sba2, rat, fq, qtotal, qpixel, fbin[3];
165 float originx, originy, qfy, qly, qfx, qlx, bias,
maxpix, minmax;
166 double chi2x, meanx, chi2y, meany, chi2ymin, chi2xmin, chi21max;
167 double hchi2, hndof, prvav, mpv, sigmaQ,
kappa, xvav, beta2;
169 float chi2ybin[41], chi2xbin[41], ysig2[
BYSIZE], xsig2[
BXSIZE];
171 bool yd[
BYSIZE], xd[
BXSIZE], anyyd, anyxd, calc_probQ, use_VVIObj;
173 const float probmin = {1.110223e-16};
174 const float probQmin = {1.e-5};
178 const double mean1pix = {0.100};
179 #ifdef SI_PIXEL_TEMPLATE_STANDALONE 180 const double chi21min = {0.};
182 const double chi21min = {0.160};
189 if (!templ.
interpolate(
id, cotalpha, cotbeta, locBz, locBx)) {
191 LOGDEBUG(
"SiPixelTemplateReco") <<
"input cluster direction cot(alpha) = " << cotalpha
192 <<
", cot(beta) = " << cotbeta <<
", local B_z = " << locBz
193 <<
", local B_x = " << locBx <<
", template ID = " <<
id 194 <<
", no reconstruction performed" <<
ENDL;
225 for (
i = 0;
i < 3; ++
i) {
232 pseudopix = 0.2f * q50;
240 nclusx = cluster.
mrow;
242 auto const xdouble = cluster.
xdouble;
243 auto const ydouble = cluster.
ydouble;
247 for (
i = 0;
i < nclusx * nclusy; ++
i) {
253 for (
j = 0;
j < nclusx; ++
j)
254 for (
i = 0;
i < nclusy; ++
i) {
269 memset(nyzero, 0,
TYSIZE *
sizeof(
int));
270 memset(ysum, 0,
BYSIZE *
sizeof(
float));
271 for (
i = 0;
i < nclusy; ++
i) {
273 for (
j = 0;
j < nclusx; ++
j) {
274 ysum[
i] += cluster(
j,
i);
291 std::vector<std::pair<int, int> >::const_iterator zeroIter = zeropix.begin(), zeroEnd = zeropix.end();
292 for (; zeroIter != zeroEnd; ++zeroIter) {
293 i = zeroIter->second;
294 if (i < 0 || i >
TYSIZE - 1) {
295 LOGERROR(
"SiPixelTemplateReco") <<
"dead pixel column y-index " <<
i <<
", no reconstruction performed" <<
ENDL;
310 nypix = lypix - fypix + 1;
314 for (zeroIter = zeropix.begin(); zeroIter != zeroEnd; ++zeroIter) {
315 i = zeroIter->second;
317 if (j < 0 || j >
TXSIZE - 1) {
318 LOGERROR(
"SiPixelTemplateReco") <<
"dead pixel column x-index " <<
j <<
", no reconstruction performed" <<
ENDL;
321 if ((
i == fypix ||
i == lypix) && nypix > 1) {
329 if (nyzero[
i] > 0 && nyzero[
i] < 3) {
330 qpixel = (
maxpix - ysum[
i]) / (
float)nyzero[
i];
337 cluster(
j,
i) = qpixel;
352 for (
i = 0;
i < nclusy; ++
i) {
353 for (
j = 0;
j < nclusx; ++
j) {
354 ysum[
k] += cluster(
j,
i);
361 ysum[
k + 1] = ysum[
k];
383 for (
j = 0;
j < nclusx; ++
j) {
384 for (
i = 0;
i < nclusy; ++
i) {
385 xsum[
k] += cluster(
j,
i);
392 xsum[
k + 1] = xsum[
k];
418 ysort[logypx] = ysum[
i];
430 if ((lypix - fypix + 1) != nypix || nypix == 0) {
431 LOGDEBUG(
"SiPixelTemplateReco") <<
"y-length of pixel cluster doesn't agree with number of pixels above threshold" 434 LOGDEBUG(
"SiPixelTemplateReco") <<
"ysum[] = ";
436 LOGDEBUG(
"SiPixelTemplateReco") << ysum[
i] <<
", ";
447 LOGDEBUG(
"SiPixelTemplateReco") <<
"y-length of pixel cluster is larger than maximum template size" <<
ENDL;
449 LOGDEBUG(
"SiPixelTemplateReco") <<
"ysum[] = ";
451 LOGDEBUG(
"SiPixelTemplateReco") << ysum[
i] <<
", ";
466 midpix = (fypix + lypix) / 2;
467 shifty = templ.
cytemp() - midpix;
471 int lytmp = lypix + shifty;
472 int fytmp = fypix + shifty;
486 for (
i = lypix;
i >= fypix; --
i) {
487 ysum[
i + shifty] = ysum[
i];
489 yd[
i + shifty] = yd[
i];
492 }
else if (shifty < 0) {
493 for (
i = fypix;
i <= lypix; ++
i) {
494 ysum[
i + shifty] = ysum[
i];
496 yd[
i + shifty] = yd[
i];
506 ysum[fypix - 1] = pseudopix;
507 ysum[fypix - 2] = pseudopix;
508 ysum[lypix + 1] = pseudopix;
509 ysum[lypix + 2] = pseudopix;
531 xsort[logxpx] = xsum[
i];
543 if ((lxpix - fxpix + 1) != nxpix) {
544 LOGDEBUG(
"SiPixelTemplateReco") <<
"x-length of pixel cluster doesn't agree with number of pixels above threshold" 547 LOGDEBUG(
"SiPixelTemplateReco") <<
"xsum[] = ";
549 LOGDEBUG(
"SiPixelTemplateReco") << xsum[
i] <<
", ";
560 LOGDEBUG(
"SiPixelTemplateReco") <<
"x-length of pixel cluster is larger than maximum template size" <<
ENDL;
562 LOGDEBUG(
"SiPixelTemplateReco") <<
"xsum[] = ";
564 LOGDEBUG(
"SiPixelTemplateReco") << xsum[
i] <<
", ";
579 midpix = (fxpix + lxpix) / 2;
580 shiftx = templ.
cxtemp() - midpix;
584 int lxtmp = lxpix + shiftx;
585 int fxtmp = fxpix + shiftx;
599 for (
i = lxpix;
i >= fxpix; --
i) {
600 xsum[
i + shiftx] = xsum[
i];
602 xd[
i + shiftx] = xd[
i];
605 }
else if (shiftx < 0) {
606 for (
i = fxpix;
i <= lxpix; ++
i) {
607 xsum[
i + shiftx] = xsum[
i];
609 xd[
i + shiftx] = xd[
i];
617 xsum[fxpix - 1] = pseudopix;
618 xsum[fxpix - 2] = pseudopix;
619 xsum[lxpix + 1] = pseudopix;
620 xsum[lxpix + 2] = pseudopix;
632 fq = qtotal / templ.
qavg();
650 if (!deadpix && qtotal < 0.95
f * templ.
qmin()) {
653 if (!deadpix && qtotal < 0.95
f * templ.
qmin(1)) {
658 LOGDEBUG(
"SiPixelTemplateReco") <<
"ID = " <<
id <<
" cot(alpha) = " << cotalpha <<
" cot(beta) = " << cotbeta
659 <<
" nclusx = " << nclusx <<
" nclusy = " << nclusy <<
ENDL;
666 #ifndef SI_PIXEL_TEMPLATE_STANDALONE 667 if (speed < 0 || speed > 3) {
668 throw cms::Exception(
"DataCorrupt") <<
"SiPixelTemplateReco::PixelTempReco1D called with illegal speed = " <<
speed 721 LOGDEBUG(
"SiPixelTemplateReco") <<
"fypix " << fypix <<
" lypix = " << lypix <<
" fybin = " << fybin
722 <<
" lybin = " << lybin <<
" djy = " << djy <<
" logypx = " << logypx <<
ENDL;
723 LOGDEBUG(
"SiPixelTemplateReco") <<
"fxpix " << fxpix <<
" lxpix = " << lxpix <<
" fxbin = " << fxbin
724 <<
" lxbin = " << lxbin <<
" djx = " << djx <<
" logxpx = " << logxpx <<
ENDL;
729 templ.
ytemp(fybin, lybin, ytemp);
731 templ.
xtemp(fxbin, lxbin, xtemp);
739 if (nypix > logypx) {
742 if (yd[
i] && !yd[
i + 1]) {
743 for (
j = fybin;
j <= lybin; ++
j) {
746 sigavg = (ytemp[
j][
i] + ytemp[
j][
i + 1]) / 2.
f;
747 ytemp[
j][
i] = sigavg;
748 ytemp[
j][
i + 1] = sigavg;
759 sythr = 1.1 * (templ.
symax());
765 sythr = 1.01f * ysort[0];
767 if (ysort[1] > sythr) {
768 sythr = 1.01f * ysort[1];
775 templ.
ysigma2(fypix, lypix, sythr, ysum, ysig2);
780 for (
i = fybin;
i <= lybin; ++
i) {
781 chi2ybin[
i] = -1.e15f;
784 for (
i = fypix - 2;
i <= lypix + 2; ++
i) {
785 yw2[
i] = 1.f / ysig2[
i];
786 ysw[
i] = ysum[
i] * yw2[
i];
787 ss2 += ysum[
i] * ysw[
i];
795 for (
j = jmin;
j <= jmax;
j += deltaj) {
796 if (chi2ybin[
j] < -100.
f) {
799 for (
i = fypix - 2;
i <= lypix + 2; ++
i) {
800 ssa += ysw[
i] * ytemp[
j][
i];
801 sa2 += ytemp[
j][
i] * ytemp[
j][
i] * yw2[
i];
805 LOGERROR(
"SiPixelTemplateReco") <<
"illegal chi2ymin normalization (1) = " << rat <<
ENDL;
808 chi2ybin[
j] = ss2 - 2.f * ssa / rat + sa2 / (rat * rat);
810 if (chi2ybin[
j] < chi2ymin) {
811 chi2ymin = chi2ybin[
j];
816 if (minbin > fybin) {
817 jmin = minbin - deltaj;
821 if (minbin < lybin) {
822 jmax = minbin + deltaj;
829 LOGDEBUG(
"SiPixelTemplateReco") <<
"minbin " << minbin <<
" chi2ymin = " << chi2ymin <<
ENDL;
837 sigma = templ.
syone();
840 sigma = templ.
sytwo();
843 yrec = 0.5f * (fypix + lypix - 2 * shifty + 2.f * originy) *
ysize -
delta;
852 chi21max = fmax(chi21min, (
double)templ.
chi2yminone());
853 chi2ymin -= chi21max;
858 meany = fmax(mean1pix, (
double)templ.
chi2yavgone());
859 hchi2 = chi2ymin / 2.;
861 proby = 1. - TMath::Gamma(hndof, hchi2);
879 for (
i = fypix - 2;
i <= lypix + 2; ++
i) {
880 ssa += ysw[
i] * ytemp[binl][
i];
881 sa2 += ytemp[binl][
i] * ytemp[binl][
i] * yw2[
i];
882 ssba += ysw[
i] * (ytemp[binh][
i] - ytemp[binl][
i]);
883 saba += ytemp[binl][
i] * (ytemp[binh][
i] - ytemp[binl][
i]) * yw2[
i];
884 sba2 += (ytemp[binh][
i] - ytemp[binl][
i]) * (ytemp[binh][
i] - ytemp[binl][
i]) * yw2[
i];
889 rat = (ssba * ssa - ss2 * saba) / (ss2 * sba2 - ssba * ssba);
896 rnorm = (ssa + rat * ssba) / ss2;
902 qfy += ysum[fypix + 1];
907 qly += ysum[lypix - 1];
915 float qyfrac = (qfy - qly) / (qfy + qly);
916 bias = templ.
yflcorr(binq, qyfrac) + templ.
yavg(binq);
920 yrec = (0.125f * binl +
BHY - 2.5f + rat * (binh - binl) * 0.125
f - (
float)shifty + originy) *
ysize - bias;
921 sigmay = templ.
yrms(binq);
926 LOGERROR(
"SiPixelTemplateReco") <<
"illegal chi2y normalization (2) = " << rnorm <<
ENDL;
929 chi2y = ss2 - 2. / rnorm * ssa - 2. / rnorm * rat * ssba +
930 (sa2 + 2. * rat * saba + rat * rat * sba2) / (rnorm * rnorm) - templ.
chi2ymin(binq);
943 proby = 1. - TMath::Gamma(hndof, hchi2);
952 if (nxpix > logxpx) {
955 if (xd[
i] && !xd[
i + 1]) {
956 for (
j = fxbin;
j <= lxbin; ++
j) {
959 sigavg = (xtemp[
j][
i] + xtemp[
j][
i + 1]) / 2.
f;
960 xtemp[
j][
i] = sigavg;
961 xtemp[
j][
i + 1] = sigavg;
972 sxthr = 1.1f * templ.
sxmax();
977 sxthr = 1.01f * xsort[0];
979 if (xsort[1] > sxthr) {
980 sxthr = 1.01f * xsort[1];
987 templ.
xsigma2(fxpix, lxpix, sxthr, xsum, xsig2);
992 for (
i = fxbin;
i <= lxbin; ++
i) {
993 chi2xbin[
i] = -1.e15f;
996 for (
i = fxpix - 2;
i <= lxpix + 2; ++
i) {
997 xw2[
i] = 1.f / xsig2[
i];
998 xsw[
i] = xsum[
i] * xw2[
i];
999 ss2 += xsum[
i] * xsw[
i];
1005 while (deltaj > 0) {
1006 for (
j = jmin;
j <= jmax;
j += deltaj) {
1007 if (chi2xbin[
j] < -100.
f) {
1011 for (
i = fxpix - 2;
i <= lxpix + 2; ++
i) {
1013 ssa += xsw[
i] * xtemp[
j][
i];
1014 sa2 += xtemp[
j][
i] * xtemp[
j][
i] * xw2[
i];
1019 LOGERROR(
"SiPixelTemplateReco") <<
"illegal chi2xmin normalization (1) = " << rat <<
ENDL;
1022 chi2xbin[
j] = ss2 - 2.f * ssa / rat + sa2 / (rat * rat);
1024 if (chi2xbin[
j] < chi2xmin) {
1025 chi2xmin = chi2xbin[
j];
1030 if (minbin > fxbin) {
1031 jmin = minbin - deltaj;
1035 if (minbin < lxbin) {
1036 jmax = minbin + deltaj;
1043 LOGDEBUG(
"SiPixelTemplateReco") <<
"minbin " << minbin <<
" chi2xmin = " << chi2xmin <<
ENDL;
1051 sigma = templ.
sxone();
1054 sigma = templ.
sxtwo();
1056 xrec = 0.5 * (fxpix + lxpix - 2 * shiftx + 2. * originx) *
xsize -
delta;
1065 chi21max = fmax(chi21min, (
double)templ.
chi2xminone());
1066 chi2xmin -= chi21max;
1067 if (chi2xmin < 0.) {
1070 meanx = fmax(mean1pix, (
double)templ.
chi2xavgone());
1071 hchi2 = chi2xmin / 2.;
1073 probx = 1. - TMath::Gamma(hndof, hchi2);
1091 for (
i = fxpix - 2;
i <= lxpix + 2; ++
i) {
1092 ssa += xsw[
i] * xtemp[binl][
i];
1093 sa2 += xtemp[binl][
i] * xtemp[binl][
i] * xw2[
i];
1094 ssba += xsw[
i] * (xtemp[binh][
i] - xtemp[binl][
i]);
1095 saba += xtemp[binl][
i] * (xtemp[binh][
i] - xtemp[binl][
i]) * xw2[
i];
1096 sba2 += (xtemp[binh][
i] - xtemp[binl][
i]) * (xtemp[binh][
i] - xtemp[binl][
i]) * xw2[
i];
1101 rat = (ssba * ssa - ss2 * saba) / (ss2 * sba2 - ssba * ssba);
1108 rnorm = (ssa + rat * ssba) / ss2;
1114 qfx += xsum[fxpix + 1];
1118 if (xd[lxpix - 1]) {
1119 qlx += xsum[lxpix - 1];
1127 float qxfrac = (qfx - qlx) / (qfx + qlx);
1128 bias = templ.
xflcorr(binq, qxfrac) + templ.
xavg(binq);
1132 xrec = (0.125f * binl +
BHX - 2.5f + rat * (binh - binl) * 0.125
f - (
float)shiftx + originx) *
xsize - bias;
1133 sigmax = templ.
xrms(binq);
1138 LOGERROR(
"SiPixelTemplateReco") <<
"illegal chi2x normalization (2) = " << rnorm <<
ENDL;
1141 chi2x = ss2 - 2. / rnorm * ssa - 2. / rnorm * rat * ssba +
1142 (sa2 + 2. * rat * saba + rat * rat * sba2) / (rnorm * rnorm) - templ.
chi2xmin(binq);
1155 probx = 1. - TMath::Gamma(hndof, hchi2);
1160 if (proby < probmin) {
1163 if (probx < probmin) {
1173 #ifndef SI_PIXEL_TEMPLATE_STANDALONE 1174 if ((sigmaQ <= 0.) || (mpv <= 0.) || (
kappa < 0.01) || (
kappa > 9.9)) {
1175 throw cms::Exception(
"DataCorrupt") <<
"SiPixelTemplateReco::Vavilov parameters mpv/sigmaQ/kappa = " << mpv <<
"/" 1176 << sigmaQ <<
"/" <<
kappa << std::endl;
1181 xvav = ((double)qtotal - mpv) / sigmaQ;
1186 prvav = vvidist.
fcn(xvav);
1189 prvav = TMath::VavilovI(xvav,
kappa, beta2);
1195 if (probQ < probQmin) {
1258 const bool deadpix =
false;
1259 std::vector<std::pair<int, int> > zeropix;
1330 const bool deadpix =
false;
1331 std::vector<std::pair<int, int> > zeropix;
1335 if (cotbeta < 0.
f) {
1339 if (cotalpha < 0.
f) {
1407 const bool deadpix =
false;
1408 std::vector<std::pair<int, int> > zeropix;
1412 if (cotbeta < 0.
f) {
1416 if (cotalpha < 0.
f) {
float fbin(int i)
Return lower bound of Qbin definition.
float chi2xminone()
//!< minimum of x chi^2 for 1 pixel clusters
bool interpolate(int id, float cotalpha, float cotbeta, float locBz, float locBx)
float symax()
average pixel signal for y-projection of cluster
float yavg(int i)
average y-bias of reconstruction binned in 4 charge bins
int cytemp()
Return central pixel of y template pixels above readout threshold.
void xsigma2(int fxpix, int lxpix, float sxthr, float xsum[13+4], float xsig2[13+4])
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)
float chi2xmin(int i)
minimum y chi^2 in 4 charge bins
float chi2ymin(int i)
minimum y chi^2 in 4 charge bins
float xrms(int i)
average x-rms of reconstruction binned in 4 charge bins
float qmin()
minimum cluster charge for valid hit (keeps 99.9% of simulated hits)
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)
float xflcorr(int binq, float qflx)
float sytwo()
rms for one double-pixel y-clusters
float chi2yminone()
//!< minimum of y chi^2 for 1 pixel clusters
float sxone()
rms for one pixel x-clusters
void ytemp(int fybin, int lybin, float ytemplate[41][21+4])
int cxtemp()
Return central pixel of x-template pixels above readout threshold.
float qscale()
charge scaling factor
float dxone()
mean offset/correction for one pixel x-clusters
float chi2yavg(int i)
average y chi^2 in 4 charge bins
void vavilov_pars(double &mpv, double &sigma, double &kappa)
float yrms(int i)
average y-rms of reconstruction binned in 4 charge bins
float yflcorr(int binq, float qfly)
float xsize()
pixel x-size (microns)
void ysigma2(int fypix, int lypix, float sythr, float ysum[21+4], float ysig2[21+4])
float sxtwo()
rms for one double-pixel x-clusters
float dytwo()
mean offset/correction for one double-pixel y-clusters
float s50()
1/2 of the pixel threshold signal in electrons
void xtemp(int fxbin, int lxbin, float xtemplate[41][13+4])
float syone()
rms for one pixel y-clusters
static const int theVerboseLevel
float chi2yavgone()
//!< average y chi^2 for 1 pixel clusters
float qavg()
average cluster charge for this set of track angles
float sxmax()
average pixel signal for x-projection of cluster
float chi2xavgone()
//!< average x chi^2 for 1 pixel clusters
float pixmax()
maximum pixel charge
float chi2xavg(int i)
averaage x chi^2 in 4 charge bins
float dyone()
mean offset/correction for one pixel y-clusters
float xavg(int i)
average x-bias of reconstruction binned in 4 charge bins
float dxtwo()
mean offset/correction for one double-pixel x-clusters
float ysize()
pixel y-size (microns)