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 const 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;
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]);
295 product =
processUnmergedHits(listOfUnmergedHits, product, pixelGeomDet, boundX, boundY, &randomEngine);
297 product =
processMergeGroups(listOfMergeGroups, product, pixelGeomDet, boundX, boundY, &randomEngine);
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;
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;
467 bool yCluster = ytemp[
firstY] > qThreshold;
474 bool yCluster = ytemp[lastY] > qThreshold;
477 offsetY2 = lastY -
BHY;
483 bool xCluster = xtemp[
firstX] > qThreshold;
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));
LocalPoint localPosition(const MeasurementPoint &mp) const override
virtual float length() const =0
bool interpolate(int id, float cotalpha, float cotbeta, float locBz, float locBx)
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
std::string fullPath() const
virtual int ncolumns() const =0
std::string theMergedPixelResolutionYFileName
TrackingRecHitProductPtr processMergeGroups(std::vector< MergeGroup *> &mergeGroups, TrackingRecHitProductPtr product, const PixelGeomDetUnit *detUnit, const double boundX, const double boundY, RandomEngineAndDistribution const *random) const
TrackingRecHitProductPtr processUnmergedHits(std::vector< TrackingRecHitProduct::SimHitIdPair > &unmergedHits, TrackingRecHitProductPtr product, const PixelGeomDetUnit *detUnit, const double boundX, const double boundY, RandomEngineAndDistribution const *random) const
std::string theRegularPixelResolutionFileName
virtual int nrows() const =0
const SiPixelTemplateDBObject * pixelTemplateDBObject_
bool containsBigPixelInY(int iymin, int iymax) const override
std::vector< SiPixelTemplateStore > thePixelTemp_
void beginRun(edm::Run const &run, const edm::EventSetup &eventSetup, const SiPixelTemplateDBObject *pixelTemplateDBObjectPtr, const std::vector< SiPixelTemplateStore > &tempStoreRef) override
std::string theMergedPixelResolutionXFileName
bool containsBigPixelInX(int ixmin, int ixmax) const override
const RandomEngineAndDistribution & getRandomEngine() const
U second(std::pair< T, U > const &p)
void ytemp(int fybin, int lybin, float ytemplate[41][21+4])
std::string theEdgePixelResolutionFileName
bool isItBigPixelInX(const int ixbin) const override
std::unique_ptr< TFile > theMergingProbabilityFile
void temperrors(int id, float cotalpha, float cotbeta, int qBin, float &sigmay, float &sigmax, float &sy1, float &sy2, float &sx1, float &sx2)
const TrackerGeometry & getMisalignedGeometry() const
bool isItEdgePixelInY(int iybin) const override
DetId geographicalId() const
The label of this GeomDet.
const TrackerGeomDet * idToDet(DetId) const override
virtual const PixelGeomDetType & specificType() const
float s50()
1/2 of the pixel threshold signal in electrons
std::shared_ptr< TrackingRecHitProduct > TrackingRecHitProductPtr
std::unique_ptr< TFile > theMergedPixelResolutionXFile
bool hitsMerge(const PSimHit &simHit1, const PSimHit &simHit2) const
const Plane & surface() const
The nominal surface of the GeomDet.
std::string theBigPixelResolutionFileName
bool isItEdgePixelInX(int ixbin) const override
void xtemp(int fxbin, int lxbin, float xtemplate[41][13+4])
void qbin_dist(int id, float cotalpha, float cotbeta, float qbin_frac[4], float &ny1_frac, float &ny2_frac, float &nx1_frac, float &nx2_frac)
Local3DPoint localPosition() const
short getTemplateID(const uint32_t &detid) const
const std::vector< SiPixelTemplateStore > * thePixelTempRef
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore > &pixelTemp, std::string dir="CalibTracker/SiPixelESProducers/data/")
double generate(RandomEngineAndDistribution const *) const
The random generation.
const TrackerGeometry & getTrackerGeometry() const
LocalError const & localAlignmentError() const
Return local alligment error.
std::shared_ptr< PixelResolutionHistograms > theBigPixelResolutions
FastSingleTrackerRecHit smearHit(const PSimHit &simHit, const PixelGeomDetUnit *detUnit, const double boundX, const double boundY, RandomEngineAndDistribution const *) const
std::string theMergingProbabilityFileName
std::unique_ptr< TFile > theMergedPixelResolutionYFile
std::shared_ptr< PixelResolutionHistograms > theEdgePixelResolutions
FastSingleTrackerRecHit smearMergeGroup(MergeGroup *mg, const PixelGeomDetUnit *detUnit, const double boundX, const double boundY, const RandomEngineAndDistribution *random) const
Vector3DBase unit() const
bool isItBigPixelInY(const int iybin) const override
~PixelTemplateSmearerBase() override
double flatShoot(double xmin=0.0, double xmax=1.0) const
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
std::shared_ptr< PixelResolutionHistograms > theRegularPixelResolutions
std::vector< TrackingRecHitProduct::SimHitIdPair > group
LocalVector momentumAtEntry() const
The momentum of the track that produced the hit, at entry point.
virtual float width() const =0
virtual const TopologyType & specificTopology() const
Power< A, B >::type pow(const A &a, const B &b)
PixelTemplateSmearerBase(const std::string &name, const edm::ParameterSet &config, edm::ConsumesCollector &consumesCollector)
TrackingRecHitProductPtr process(TrackingRecHitProductPtr product) const override
MeasurementPoint measurementPosition(const LocalPoint &lp) const override
Point3DBase< float, LocalTag > Local3DPoint