73 <<
" failed with status = " <<
status << std::endl;
81 <<
" failed with status = " <<
status << std::endl;
89 <<
" failed with status = " <<
status << std::endl;
109 if (
config.exists(
"templateId")) {
115 <<
"SiPixel Template " <<
templateId <<
" Not Loaded Correctly!" << std::endl;
139 std::vector<SiPixelTemplateStore>& tempStoreRef) {
172 std::vector<std::pair<unsigned int, const PSimHit*>>& simHitIdPairs = product->getSimHitIdPairs();
173 std::vector<const PSimHit*>
simHits(simHitIdPairs.size());
174 for (
unsigned int ihit = 0; ihit < simHitIdPairs.size(); ++ihit) {
175 simHits[ihit] = simHitIdPairs[ihit].second;
181 const PixelGeomDetUnit* pixelGeomDet = dynamic_cast<const PixelGeomDetUnit*>(geomDet);
182 if (pixelGeomDet ==
nullptr) {
184 <<
"The GeomDetUnit is not a PixelGeomDetUnit. This should never happen!";
187 const Bounds& theBounds = theDetPlane.bounds();
188 const double boundX = theBounds.
width() / 2.;
189 const double boundY = theBounds.
length() / 2.;
191 std::vector<TrackingRecHitProduct::SimHitIdPair> listOfUnmergedHits;
192 std::vector<MergeGroup*> listOfMergeGroups;
200 }
else if (
nHits == 1) {
201 listOfUnmergedHits.push_back(simHitIdPairs[0]);
206 mergeGroupByHit[
i] =
nullptr;
208 for (
int i = 0;
i <
nHits - 1; ++
i) {
215 if (mergeGroupByHit[
j] !=
nullptr) {
216 if (mergeGroupByHit[
i] ==
nullptr) {
217 mergeGroupByHit[
i] = mergeGroupByHit[
j];
218 mergeGroupByHit[
i]->
group.push_back(simHitIdPairs[
i]);
221 if (mergeGroupByHit[
i] != mergeGroupByHit[
j]) {
222 for (
auto hit_it = mergeGroupByHit[
j]->
group.begin(); hit_it != mergeGroupByHit[
j]->
group.end();
224 mergeGroupByHit[
i]->
group.push_back(*hit_it);
231 if (mgbhj == mergeGroupByHit[
k]) {
233 mergeGroupByHit[
k] = mergeGroupByHit[
i];
248 if (mergeGroupByHit[
i] ==
nullptr) {
252 listOfMergeGroups.push_back(mergeGroupByHit[
i]);
256 mergeGroupByHit[
i]->
group.push_back(simHitIdPairs[
i]);
260 mergeGroupByHit[
i]->
group.push_back(simHitIdPairs[
j]);
263 mergeGroupByHit[
j] = mergeGroupByHit[
i];
277 if (mergeGroupByHit[
i] ==
nullptr) {
279 listOfUnmergedHits.push_back(simHitIdPairs[
i]);
287 listOfUnmergedHits.push_back(simHitIdPairs[
i]);
304 for (
auto mg_it = listOfMergeGroups.begin(); mg_it != listOfMergeGroups.end(); ++mg_it) {
323 float locx = localDir.
x();
324 float locy = localDir.
y();
325 float locz = localDir.
z();
331 float cotalpha = locx / locz;
332 float cotbeta = locy / locz;
335 int signOfCotalpha = (cotalpha < 0) ? -1 : 1;
336 int signOfCotbeta = (cotbeta < 0) ? -1 : 1;
339 cotalpha *= signOfCotalpha;
340 cotbeta *= signOfCotbeta;
342 LogDebug(
"SmearHit") <<
"LocalVector=" << locx <<
"," << locy <<
"," << locz <<
" momentum=" << localDir.
mag()
343 <<
" cotalpha=" << cotalpha <<
", cotbeta=" << cotbeta;
346 const RectangularPixelTopology* rectPixelTopology = static_cast<const RectangularPixelTopology*>(theSpecificTopology);
348 const int nrows = theSpecificTopology->
nrows();
349 const int ncolumns = theSpecificTopology->
ncolumns();
357 float pixelCenterY = 0.5 + (
int)mpy;
358 float pixelCenterX = 0.5 + (
int)mpx;
365 float xtrk = lp.
x() - lpCenter.
x();
366 float ytrk = lp.
y() - lpCenter.
y();
370 float yhit = 20. + 8. * (ytrk /
ysize);
371 float xhit = 20. + 8. * (xtrk /
xsize);
372 int ybin = (
int)yhit;
373 int xbin = (
int)xhit;
374 float yfrac = yhit - (
float)ybin;
375 float xfrac = xhit - (
float)xbin;
404 float ny1_frac, ny2_frac, nx1_frac, nx2_frac;
405 bool singlex =
false, singley =
false;
406 templ.
qbin_dist(
ID, cotalpha, cotbeta, qbin_frac, ny1_frac, ny2_frac, nx1_frac, nx2_frac);
409 double xsizeProbability = random->
flatShoot();
410 double ysizeProbability = random->
flatShoot();
415 if (xsizeProbability < nx2_frac)
419 else if (xsizeProbability < nx1_frac)
425 if (ysizeProbability < ny2_frac)
429 else if (ysizeProbability < ny1_frac)
435 double qbinProbability = random->
flatShoot();
436 for (
int i = 0;
i < 4; ++
i) {
438 if (qbinProbability < qbin_frac[
i]) {
445 float ytempl[41][
BYSIZE] = {{0}}, xtempl[41][
BXSIZE] = {{0}};
446 templ.
ytemp(0, 40, ytempl);
447 templ.
xtemp(0, 40, xtempl);
449 std::vector<double> ytemp(
BYSIZE);
451 ytemp[
i] = (1. - yfrac) * ytempl[ybin][
i] + yfrac * ytempl[ybin + 1][
i];
454 std::vector<double> xtemp(
BXSIZE);
456 xtemp[
i] = (1. - xfrac) * xtempl[xbin][
i] + xfrac * xtempl[xbin + 1][
i];
460 const float qThreshold = templ.
s50() * 2.0;
464 int offsetX1 = 0, offsetX2 = 0, offsetY1 = 0, offsetY2 = 0;
465 int firstY, lastY, firstX, lastX;
466 for (firstY = 0; firstY <
BYSIZE; ++firstY) {
467 bool yCluster = ytemp[firstY] > qThreshold;
469 offsetY1 =
BHY - firstY;
473 for (lastY = firstY; lastY <
BYSIZE; ++lastY) {
474 bool yCluster = ytemp[lastY] > qThreshold;
477 offsetY2 = lastY -
BHY;
482 for (firstX = 0; firstX <
BXSIZE; ++firstX) {
483 bool xCluster = xtemp[firstX] > qThreshold;
485 offsetX1 =
BHX - firstX;
489 for (lastX = firstX; lastX <
BXSIZE; ++lastX) {
490 bool xCluster = xtemp[lastX] > qThreshold;
493 offsetX2 = lastX -
BHX;
512 bool edge, edgex, edgey;
515 int firstPixelInX = (
int)mpx - offsetX1;
516 int firstPixelInY = (
int)mpy - offsetY1;
517 int lastPixelInX = (
int)mpx + offsetX2;
518 int lastPixelInY = (
int)mpy + offsetY2;
519 firstPixelInX = (firstPixelInX >= 0) ? firstPixelInX : 0;
520 firstPixelInY = (firstPixelInY >= 0) ? firstPixelInY : 0;
521 lastPixelInX = (lastPixelInX < nrows) ? lastPixelInX : nrows - 1;
522 lastPixelInY = (lastPixelInY < ncolumns) ? lastPixelInY : ncolumns - 1;
526 edge = edgex || edgey;
534 float sigmay, sigmax, sy1, sy2, sx1, sx2;
548 if (edgex && !edgey) {
551 }
else if (!edgex && edgey) {
582 if (alignmentError.
valid()) {
584 theErrorX * theErrorX + alignmentError.
xx(), alignmentError.
xy(), theErrorY * theErrorY + alignmentError.
yy());
586 theError =
LocalError(theErrorX * theErrorX, 0.0, theErrorY * theErrorY);
596 shared_ptr<PixelResolutionHistograms> resHistsX =
nullptr;
597 shared_ptr<PixelResolutionHistograms> resHistsY =
nullptr;
601 singlex = singley =
false;
604 if ((singlex && hitbigx) || (
isBarrel && hasBigPixelInX)) {
610 if ((singley && hitbigy) || (
isBarrel && hasBigPixelInY)) {
622 if (!xgen || !ygen) {
624 <<
"Histogram (cot\alpha=" << cotalpha <<
", cot\beta=" << cotbeta <<
", nQbin=" << nqbin
625 <<
") was not found for PixelTemplateSmearer. Check if the smearing resolution histogram exists.";
631 unsigned int retry = 0;
635 theShiftInX = xgen->
generate(random);
636 theShiftInY = ygen->
generate(random);
639 theShiftInX *= signOfCotalpha;
640 theShiftInY *= signOfCotbeta;
645 simHit.localPosition().y() + theShiftInY,
646 simHit.localPosition().z() + theShiftInZ);
654 }
while (fabs(thePosition.
x()) > boundX || fabs(thePosition.
y()) > boundY);
664 std::vector<TrackingRecHitProduct::SimHitIdPair>& unmergedHits,
670 for (
auto simHitIdPair : unmergedHits) {
672 product->addRecHit(
recHit, {simHitIdPair});
686 for (
auto mg_it = mergeGroups.begin(); mg_it != mergeGroups.end(); ++mg_it) {
687 if ((*mg_it)->smearIt) {
689 product->addRecHit(
recHit, (*mg_it)->group);
711 for (
auto hit_it = mg->
group.begin(); hit_it != mg->
group.end(); ++hit_it) {
715 loccx += localDir.
x();
716 loccy += localDir.
y();
717 loccz += localDir.
z();
727 float locx = loccx / nHit;
728 float locy = loccy / nHit;
729 float locz = loccz / nHit;
735 float cotalpha = locx / locz;
736 float cotbeta = locy / locz;
739 int signOfCotalpha = (cotalpha < 0) ? -1 : 1;
740 int signOfCotbeta = (cotbeta < 0) ? -1 : 1;
743 cotalpha *= signOfCotalpha;
744 cotbeta *= signOfCotbeta;
746 float lpx = locpx / nHit;
747 float lpy = locpy / nHit;
748 float lpz = locpz / nHit;
756 float yhit = 20. + 8. * (ytrk /
ysize);
757 float xhit = 20. + 8. * (xtrk /
xsize);
758 int ybin = (
int)yhit;
759 int xbin = (
int)xhit;
760 float yfrac = yhit - (
float)ybin;
761 float xfrac = xhit - (
float)xbin;
790 float ny1_frac, ny2_frac, nx1_frac, nx2_frac;
791 bool singlex =
false, singley =
false;
792 templ.
qbin_dist(
ID, cotalpha, cotbeta, qbin_frac, ny1_frac, ny2_frac, nx1_frac, nx2_frac);
797 bool hitbigx =
false;
798 bool hitbigy =
false;
802 double qbinProbability = random->
flatShoot();
803 for (
int i = 0;
i < 4; ++
i) {
805 if (qbinProbability < qbin_frac[
i])
811 float ytempl[41][
BYSIZE] = {{0}}, xtempl[41][
BXSIZE] = {{0}};
812 templ.
ytemp(0, 40, ytempl);
813 templ.
xtemp(0, 40, xtempl);
815 std::vector<double> ytemp(
BYSIZE);
817 ytemp[
i] = (1. - yfrac) * ytempl[ybin][
i] + yfrac * ytempl[ybin + 1][
i];
820 std::vector<double> xtemp(
BXSIZE);
822 xtemp[
i] = (1. - xfrac) * xtempl[xbin][
i] + xfrac * xtempl[xbin + 1][
i];
844 float sigmay, sigmax, sy1, sy2, sx1, sx2;
858 if (edgex && !edgey) {
861 }
else if (!edgex && edgey) {
891 theError =
LocalError(theErrorX * theErrorX, 0., theErrorY * theErrorY);
893 unsigned int retry = 0;
901 theShiftInX = xgen->
generate(random);
902 theShiftInY = ygen->generate(random);
905 theShiftInX *= signOfCotalpha;
906 theShiftInY *= signOfCotbeta;
910 thePosition =
Local3DPoint(lpx + theShiftInX, lpy + theShiftInY, lpz + theShiftInZ);
919 }
while (fabs(thePosition.
x()) > boundX || fabs(thePosition.
y()) > boundY);
927 float locy1 = localDir.
y();
928 float locz1 = localDir.
z();
929 float cotbeta = locy1 / locz1;
930 float loceta = fabs(-
log((
double)(-cotbeta +
sqrt((
double)(1. + cotbeta * cotbeta)))));
934 float lpy1 = lp1.
y();
935 float lpx1 = lp1.
x();
936 float lpy2 = lp2.
y();
937 float lpx2 = lp2.
x();
938 float locdis = 10000. *
sqrt(
pow(lpx1 - lpx2, 2) +
pow(lpy1 - lpy2, 2));
941 probhisto->GetBinContent(probhisto->GetXaxis()->FindFixBin(locdis), probhisto->GetYaxis()->FindFixBin(loceta));