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;
143 std::vector<SiPixelTemplateStore>& tempStoreRef) {
176 std::vector<std::pair<unsigned int, const PSimHit*>>& simHitIdPairs = product->getSimHitIdPairs();
177 std::vector<const PSimHit*>
simHits(simHitIdPairs.size());
178 for (
unsigned int ihit = 0; ihit < simHitIdPairs.size(); ++ihit) {
179 simHits[ihit] = simHitIdPairs[ihit].second;
185 const PixelGeomDetUnit* pixelGeomDet = dynamic_cast<const PixelGeomDetUnit*>(geomDet);
186 if (pixelGeomDet ==
nullptr) {
188 <<
"The GeomDetUnit is not a PixelGeomDetUnit. This should never happen!";
191 const Bounds& theBounds = theDetPlane.bounds();
192 const double boundX = theBounds.
width() / 2.;
193 const double boundY = theBounds.
length() / 2.;
195 std::vector<TrackingRecHitProduct::SimHitIdPair> listOfUnmergedHits;
196 std::vector<MergeGroup*> listOfMergeGroups;
204 }
else if (nHits == 1) {
205 listOfUnmergedHits.push_back(simHitIdPairs[0]);
208 for (
int i = 0;
i < nHits; ++
i) {
210 mergeGroupByHit[
i] =
nullptr;
212 for (
int i = 0;
i < nHits - 1; ++
i) {
213 for (
int j =
i + 1;
j < nHits; ++
j) {
219 if (mergeGroupByHit[
j] !=
nullptr) {
220 if (mergeGroupByHit[
i] ==
nullptr) {
221 mergeGroupByHit[
i] = mergeGroupByHit[
j];
222 mergeGroupByHit[
i]->
group.push_back(simHitIdPairs[
i]);
225 if (mergeGroupByHit[
i] != mergeGroupByHit[
j]) {
226 for (
auto hit_it = mergeGroupByHit[
j]->
group.begin(); hit_it != mergeGroupByHit[
j]->
group.end();
228 mergeGroupByHit[
i]->
group.push_back(*hit_it);
234 for (
int k = 0;
k < nHits; ++
k) {
235 if (mgbhj == mergeGroupByHit[
k]) {
237 mergeGroupByHit[
k] = mergeGroupByHit[
i];
252 if (mergeGroupByHit[
i] ==
nullptr) {
256 listOfMergeGroups.push_back(mergeGroupByHit[
i]);
260 mergeGroupByHit[
i]->
group.push_back(simHitIdPairs[
i]);
264 mergeGroupByHit[
i]->
group.push_back(simHitIdPairs[
j]);
267 mergeGroupByHit[
j] = mergeGroupByHit[
i];
281 if (mergeGroupByHit[
i] ==
nullptr) {
283 listOfUnmergedHits.push_back(simHitIdPairs[
i]);
290 for (
int i = 0;
i < nHits; ++
i) {
291 listOfUnmergedHits.push_back(simHitIdPairs[
i]);
308 for (
auto mg_it = listOfMergeGroups.begin(); mg_it != listOfMergeGroups.end(); ++mg_it) {
327 float locx = localDir.
x();
328 float locy = localDir.
y();
329 float locz = localDir.
z();
335 float cotalpha = locx / locz;
336 float cotbeta = locy / locz;
339 int signOfCotalpha = (cotalpha < 0) ? -1 : 1;
340 int signOfCotbeta = (cotbeta < 0) ? -1 : 1;
343 cotalpha *= signOfCotalpha;
344 cotbeta *= signOfCotbeta;
346 LogDebug(
"SmearHit") <<
"LocalVector=" << locx <<
"," << locy <<
"," << locz <<
" momentum=" << localDir.
mag()
347 <<
" cotalpha=" << cotalpha <<
", cotbeta=" << cotbeta;
350 const RectangularPixelTopology* rectPixelTopology = static_cast<const RectangularPixelTopology*>(theSpecificTopology);
352 const int nrows = theSpecificTopology->
nrows();
353 const int ncolumns = theSpecificTopology->
ncolumns();
361 float pixelCenterY = 0.5 + (
int)mpy;
362 float pixelCenterX = 0.5 + (
int)mpx;
369 float xtrk = lp.
x() - lpCenter.
x();
370 float ytrk = lp.
y() - lpCenter.
y();
374 float yhit = 20. + 8. * (ytrk /
ysize);
375 float xhit = 20. + 8. * (xtrk /
xsize);
376 int ybin = (
int)yhit;
377 int xbin = (
int)xhit;
378 float yfrac = yhit - (
float)ybin;
379 float xfrac = xhit - (
float)xbin;
408 float ny1_frac, ny2_frac, nx1_frac, nx2_frac;
409 bool singlex =
false, singley =
false;
410 templ.
qbin_dist(
ID, cotalpha, cotbeta, qbin_frac, ny1_frac, ny2_frac, nx1_frac, nx2_frac);
413 double xsizeProbability = random->
flatShoot();
414 double ysizeProbability = random->
flatShoot();
419 if (xsizeProbability < nx2_frac)
423 else if (xsizeProbability < nx1_frac)
429 if (ysizeProbability < ny2_frac)
433 else if (ysizeProbability < ny1_frac)
439 double qbinProbability = random->
flatShoot();
440 for (
int i = 0;
i < 4; ++
i) {
442 if (qbinProbability < qbin_frac[
i]) {
449 float ytempl[41][
BYSIZE] = {{0}}, xtempl[41][
BXSIZE] = {{0}};
450 templ.
ytemp(0, 40, ytempl);
451 templ.
xtemp(0, 40, xtempl);
453 std::vector<double> ytemp(
BYSIZE);
455 ytemp[
i] = (1. - yfrac) * ytempl[ybin][
i] + yfrac * ytempl[ybin + 1][
i];
458 std::vector<double> xtemp(
BXSIZE);
460 xtemp[
i] = (1. - xfrac) * xtempl[xbin][
i] + xfrac * xtempl[xbin + 1][
i];
464 const float qThreshold = templ.
s50() * 2.0;
468 int offsetX1 = 0, offsetX2 = 0, offsetY1 = 0, offsetY2 = 0;
469 int firstY, lastY, firstX, lastX;
470 for (firstY = 0; firstY <
BYSIZE; ++firstY) {
471 bool yCluster = ytemp[firstY] > qThreshold;
473 offsetY1 =
BHY - firstY;
477 for (lastY = firstY; lastY <
BYSIZE; ++lastY) {
478 bool yCluster = ytemp[lastY] > qThreshold;
481 offsetY2 = lastY -
BHY;
486 for (firstX = 0; firstX <
BXSIZE; ++firstX) {
487 bool xCluster = xtemp[firstX] > qThreshold;
489 offsetX1 =
BHX - firstX;
493 for (lastX = firstX; lastX <
BXSIZE; ++lastX) {
494 bool xCluster = xtemp[lastX] > qThreshold;
497 offsetX2 = lastX -
BHX;
516 bool edge, edgex, edgey;
519 int firstPixelInX = (
int)mpx - offsetX1;
520 int firstPixelInY = (
int)mpy - offsetY1;
521 int lastPixelInX = (
int)mpx + offsetX2;
522 int lastPixelInY = (
int)mpy + offsetY2;
523 firstPixelInX = (firstPixelInX >= 0) ? firstPixelInX : 0;
524 firstPixelInY = (firstPixelInY >= 0) ? firstPixelInY : 0;
525 lastPixelInX = (lastPixelInX < nrows) ? lastPixelInX : nrows - 1;
526 lastPixelInY = (lastPixelInY < ncolumns) ? lastPixelInY : ncolumns - 1;
530 edge = edgex || edgey;
538 float sigmay, sigmax, sy1, sy2, sx1, sx2;
552 if (edgex && !edgey) {
555 }
else if (!edgex && edgey) {
586 if (alignmentError.
valid()) {
588 theErrorX * theErrorX + alignmentError.
xx(), alignmentError.
xy(), theErrorY * theErrorY + alignmentError.
yy());
590 theError =
LocalError(theErrorX * theErrorX, 0.0, theErrorY * theErrorY);
600 shared_ptr<PixelResolutionHistograms> resHistsX =
nullptr;
601 shared_ptr<PixelResolutionHistograms> resHistsY =
nullptr;
605 singlex = singley =
false;
608 if ((singlex && hitbigx) || (
isBarrel && hasBigPixelInX)) {
614 if ((singley && hitbigy) || (
isBarrel && hasBigPixelInY)) {
626 if (!xgen || !ygen) {
628 <<
"Histogram (cot\alpha=" << cotalpha <<
", cot\beta=" << cotbeta <<
", nQbin=" << nqbin
629 <<
") was not found for PixelTemplateSmearer. Check if the smearing resolution histogram exists.";
635 unsigned int retry = 0;
639 theShiftInX = xgen->
generate(random);
640 theShiftInY = ygen->
generate(random);
643 theShiftInX *= signOfCotalpha;
644 theShiftInY *= signOfCotbeta;
649 simHit.localPosition().y() + theShiftInY,
650 simHit.localPosition().z() + theShiftInZ);
658 }
while (fabs(thePosition.
x()) > boundX || fabs(thePosition.
y()) > boundY);
668 std::vector<TrackingRecHitProduct::SimHitIdPair>& unmergedHits,
674 for (
auto simHitIdPair : unmergedHits) {
676 product->addRecHit(
recHit, {simHitIdPair});
690 for (
auto mg_it = mergeGroups.begin(); mg_it != mergeGroups.end(); ++mg_it) {
691 if ((*mg_it)->smearIt) {
693 product->addRecHit(
recHit, (*mg_it)->group);
715 for (
auto hit_it = mg->
group.begin(); hit_it != mg->
group.end(); ++hit_it) {
719 loccx += localDir.
x();
720 loccy += localDir.
y();
721 loccz += localDir.
z();
731 float locx = loccx / nHit;
732 float locy = loccy / nHit;
733 float locz = loccz / nHit;
739 float cotalpha = locx / locz;
740 float cotbeta = locy / locz;
743 int signOfCotalpha = (cotalpha < 0) ? -1 : 1;
744 int signOfCotbeta = (cotbeta < 0) ? -1 : 1;
747 cotalpha *= signOfCotalpha;
748 cotbeta *= signOfCotbeta;
750 float lpx = locpx / nHit;
751 float lpy = locpy / nHit;
752 float lpz = locpz / nHit;
760 float yhit = 20. + 8. * (ytrk /
ysize);
761 float xhit = 20. + 8. * (xtrk /
xsize);
762 int ybin = (
int)yhit;
763 int xbin = (
int)xhit;
764 float yfrac = yhit - (
float)ybin;
765 float xfrac = xhit - (
float)xbin;
794 float ny1_frac, ny2_frac, nx1_frac, nx2_frac;
795 bool singlex =
false, singley =
false;
796 templ.
qbin_dist(
ID, cotalpha, cotbeta, qbin_frac, ny1_frac, ny2_frac, nx1_frac, nx2_frac);
801 bool hitbigx =
false;
802 bool hitbigy =
false;
806 double qbinProbability = random->
flatShoot();
807 for (
int i = 0;
i < 4; ++
i) {
809 if (qbinProbability < qbin_frac[
i])
815 float ytempl[41][
BYSIZE] = {{0}}, xtempl[41][
BXSIZE] = {{0}};
816 templ.
ytemp(0, 40, ytempl);
817 templ.
xtemp(0, 40, xtempl);
819 std::vector<double> ytemp(
BYSIZE);
821 ytemp[
i] = (1. - yfrac) * ytempl[ybin][
i] + yfrac * ytempl[ybin + 1][
i];
824 std::vector<double> xtemp(
BXSIZE);
826 xtemp[
i] = (1. - xfrac) * xtempl[xbin][
i] + xfrac * xtempl[xbin + 1][
i];
848 float sigmay, sigmax, sy1, sy2, sx1, sx2;
862 if (edgex && !edgey) {
865 }
else if (!edgex && edgey) {
895 theError =
LocalError(theErrorX * theErrorX, 0., theErrorY * theErrorY);
897 unsigned int retry = 0;
905 theShiftInX = xgen->
generate(random);
906 theShiftInY = ygen->generate(random);
909 theShiftInX *= signOfCotalpha;
910 theShiftInY *= signOfCotbeta;
914 thePosition =
Local3DPoint(lpx + theShiftInX, lpy + theShiftInY, lpz + theShiftInZ);
923 }
while (fabs(thePosition.
x()) > boundX || fabs(thePosition.
y()) > boundY);
931 float locy1 = localDir.
y();
932 float locz1 = localDir.
z();
933 float cotbeta = locy1 / locz1;
934 float loceta = fabs(-
log((
double)(-cotbeta +
sqrt((
double)(1. + cotbeta * cotbeta)))));
938 float lpy1 = lp1.
y();
939 float lpx1 = lp1.
x();
940 float lpy2 = lp2.
y();
941 float lpx2 = lp2.
x();
942 float locdis = 10000. *
sqrt(
pow(lpx1 - lpx2, 2) +
pow(lpy1 - lpy2, 2));
945 probhisto->GetBinContent(probhisto->GetXaxis()->FindFixBin(locdis), probhisto->GetYaxis()->FindFixBin(loceta));