68 std::vector<std::pair<unsigned int,const PSimHit*>> & simHitIdPairs = product->getSimHitIdPairs();
69 std::vector<const PSimHit*>
simHits(simHitIdPairs.size());
70 for (
unsigned int ihit = 0; ihit<simHitIdPairs.size();++ihit)
72 simHits[ihit]=simHitIdPairs[ihit].second;
80 if (pixelGeomDet ==
nullptr)
82 throw cms::Exception(
"FastSimulation/TrackingRecHitProducer") <<
"The GeomDetUnit is not a PixelGeomDetUnit. This should never happen!";
85 const Bounds& theBounds = theDetPlane.bounds();
86 const double boundX = theBounds.
width()/2.;
87 const double boundY = theBounds.
length()/2.;
90 std::vector<TrackingRecHitProduct::SimHitIdPair> listOfUnmergedHits;
91 std::vector< MergeGroup* > listOfMergeGroups;
104 listOfUnmergedHits.push_back(simHitIdPairs[0]);
111 for (
int i = 0;
i < nHits; ++
i )
114 mergeGroupByHit[
i] =
nullptr;
116 for (
int i = 0;
i < nHits-1; ++
i )
118 for (
int j =
i+1 ; j < nHits; ++j ) {
121 bool merged =
hitsMerge( *simHitIdPairs[
i].
second, *simHitIdPairs[j].second );
127 if ( mergeGroupByHit[j] !=
nullptr )
129 if (mergeGroupByHit[
i] ==
nullptr )
131 mergeGroupByHit[
i] = mergeGroupByHit[j];
132 mergeGroupByHit[
i]->
group.push_back(simHitIdPairs[
i]);
137 if (mergeGroupByHit[
i] != mergeGroupByHit[j])
139 for (
auto hit_it = mergeGroupByHit[j]->
group.begin(); hit_it != mergeGroupByHit[j]->
group.end(); ++hit_it)
141 mergeGroupByHit[
i]->
group.push_back( *hit_it );
147 for (
int k = 0;
k < nHits; ++
k )
149 if ( mgbhj == mergeGroupByHit[
k])
152 mergeGroupByHit[
k] = mergeGroupByHit[
i];
169 if ( mergeGroupByHit[
i] ==
nullptr )
174 listOfMergeGroups.push_back( mergeGroupByHit[
i] );
180 mergeGroupByHit[
i]->
group.push_back( simHitIdPairs[i] );
184 mergeGroupByHit[
i]->
group.push_back( simHitIdPairs[j] );
187 mergeGroupByHit[j] = mergeGroupByHit[
i];
201 if ( mergeGroupByHit[
i] ==
nullptr )
204 listOfUnmergedHits.push_back( simHitIdPairs[
i] );
213 for (
int i = 0;
i < nHits; ++
i )
215 listOfUnmergedHits.push_back( simHitIdPairs[
i] );
225 pixelGeomDet, boundX, boundY,
230 pixelGeomDet, boundX, boundY,
238 for (
auto mg_it = listOfMergeGroups.begin(); mg_it != listOfMergeGroups.end(); ++mg_it )
261 float locx = localDir.
x();
262 float locy = localDir.
y();
263 float locz = localDir.
z();
265 float cotalpha = locx/locz;
266 float cotbeta = locy/locz;
275 cotbeta = sign*cotbeta;
281 const int nrows = theSpecificTopology->
nrows();
282 const int ncolumns = theSpecificTopology->
ncolumns();
290 float pixelCenterY = 0.5 + (
int)mpy;
291 float pixelCenterX = 0.5 + (
int)mpx;
298 float xtrk = lp.
x() - lpCenter.
x();
299 float ytrk = lp.
y() - lpCenter.
y();
303 float yhit = 20. + 8.*(ytrk/
ysize);
304 float xhit = 20. + 8.*(xtrk/
xsize);
305 int ybin = (
int)yhit;
306 int xbin = (
int)xhit;
307 float yfrac= yhit - (
float)ybin;
308 float xfrac= xhit - (
float)xbin;
310 if( ybin < 0 ) ybin = 0;
311 if( ybin > 39 ) ybin = 39;
312 if( xbin < 0 ) xbin = 0;
313 if( xbin > 39 ) xbin = 39;
319 float ny1_frac, ny2_frac, nx1_frac, nx2_frac;
320 bool singlex =
false, singley =
false;
323 templ.
qbin_dist(
templateId, cotalpha, cotbeta, qbin_frac, ny1_frac, ny2_frac, nx1_frac, nx2_frac );
326 double xsizeProbability = random->
flatShoot();
327 double ysizeProbability = random->
flatShoot();
332 if( xsizeProbability < nx2_frac ) singlex =
true;
333 else singlex =
false;
335 if( xsizeProbability < nx1_frac ) singlex =
true;
336 else singlex =
false;
339 if( ysizeProbability < ny2_frac ) singley =
true;
340 else singley =
false;
342 if( ysizeProbability < ny1_frac ) singley =
true;
343 else singley =
false;
348 double qbinProbability = random->
flatShoot();
349 for(
int i = 0;
i<4; ++
i)
352 if (qbinProbability < qbin_frac[
i])
360 float ytempl[41][
BYSIZE] = {{0}}, xtempl[41][
BXSIZE] = {{0}} ;
361 templ.
ytemp(0, 40, ytempl);
362 templ.
xtemp(0, 40, xtempl);
364 std::vector<double> ytemp(
BYSIZE);
367 ytemp[
i]=(1.-yfrac)*ytempl[ybin][
i]+yfrac*ytempl[ybin+1][
i];
370 std::vector<double> xtemp(
BXSIZE);
373 xtemp[
i]=(1.-xfrac)*xtempl[xbin][
i]+xfrac*xtempl[xbin+1][
i];
377 const float qThreshold = templ.
s50()*2.0;
381 int offsetX1=0, offsetX2=0, offsetY1=0, offsetY2=0;
382 int firstY, lastY, firstX, lastX;
383 for( firstY = 0; firstY <
BYSIZE; ++firstY )
385 bool yCluster = ytemp[firstY] > qThreshold;
388 offsetY1 =
BHY -firstY;
392 for(lastY = firstY; lastY <
BYSIZE; ++lastY)
394 bool yCluster = ytemp[lastY] > qThreshold;
398 offsetY2 = lastY -
BHY;
403 for( firstX = 0; firstX <
BXSIZE; ++firstX )
405 bool xCluster = xtemp[firstX] > qThreshold;
408 offsetX1 =
BHX - firstX;
412 for( lastX = firstX; lastX <
BXSIZE; ++ lastX )
414 bool xCluster = xtemp[lastX] > qThreshold;
418 offsetX2 = lastX -
BHX;
438 bool edge, edgex, edgey;
441 int firstPixelInX = (
int)mpx - offsetX1 ;
442 int firstPixelInY = (
int)mpy - offsetY1 ;
443 int lastPixelInX = (
int)mpx + offsetX2 ;
444 int lastPixelInY = (
int)mpy + offsetY2 ;
445 firstPixelInX = (firstPixelInX >= 0) ? firstPixelInX : 0 ;
446 firstPixelInY = (firstPixelInY >= 0) ? firstPixelInY : 0 ;
447 lastPixelInX = (lastPixelInX < nrows ) ? lastPixelInX : nrows-1 ;
448 lastPixelInY = (lastPixelInY < ncolumns ) ? lastPixelInY : ncolumns-1;
452 edge = edgex || edgey;
456 bool hasBigPixelInX = rectPixelTopology->
containsBigPixelInX( firstPixelInX, lastPixelInX );
457 bool hasBigPixelInY = rectPixelTopology->
containsBigPixelInY( firstPixelInY, lastPixelInY );
460 float sigmay, sigmax, sy1, sy2, sx1, sx2;
463 sigmay, sigmax, sy1, sy2, sx1, sx2
473 else if(!edgex && edgey)
522 if (alignmentError.
valid())
525 theErrorX*theErrorX+alignmentError.
xx(),
527 theErrorY*theErrorY+alignmentError.
yy()
546 if (cotalphaHistBin < 1) cotalphaHistBin = 1;
547 if (cotbetaHistBin < 1) cotbetaHistBin = 1;
551 unsigned int theXHistN;
552 unsigned int theYHistN;
558 theXHistN = cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
559 theYHistN = theXHistN;
565 if (hitbigx) theXHistN = 1 * 100000 + cotalphaHistBin * 100 + cotbetaHistBin ;
566 else theXHistN = 1 * 10000 + cotbetaHistBin * 10 + cotalphaHistBin ;
570 if (hasBigPixelInX) theXHistN = 1 * 1000000 + 1 * 100000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
571 else theXHistN = 1 * 100000 + 1 * 10000 + cotbetaHistBin * 100 + cotalphaHistBin * 10 + (nqbin+1);
576 if (hitbigy) theYHistN = 1 * 100000 + cotalphaHistBin * 100 + cotbetaHistBin ;
577 else theYHistN = 1 * 10000 + cotbetaHistBin * 10 + cotalphaHistBin ;
581 if (hasBigPixelInY) theYHistN = 1 * 1000000 + 1 * 100000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
582 else theYHistN = 1 * 100000 + 1 * 10000 + cotbetaHistBin * 100 + cotalphaHistBin * 10 + (nqbin+1);
590 theXHistN = cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
591 theYHistN = theXHistN;
597 if (hitbigx) theXHistN = 100000 + cotalphaHistBin * 100 + cotbetaHistBin;
598 else theXHistN = cotbetaHistBin * 10 + cotalphaHistBin;
602 theXHistN = 10000 + cotbetaHistBin * 100 + cotalphaHistBin * 10 + (nqbin+1);
607 if (hitbigy) theYHistN = 100000 + cotalphaHistBin * 100 + cotbetaHistBin;
608 else theYHistN = cotbetaHistBin * 10 + cotalphaHistBin;
612 theYHistN = 10000 + cotbetaHistBin * 100 + cotalphaHistBin * 10 + (nqbin+1);
618 unsigned int retry = 0;
625 std::map<unsigned int, const SimpleHistogramGenerator*>::const_iterator xgenIt =
theXHistos.find(theXHistN);
626 std::map<unsigned int, const SimpleHistogramGenerator*>::const_iterator ygenIt =
theYHistos.find(theYHistN);
629 throw cms::Exception(
"FastSimulation/TrackingRecHitProducer") <<
"Histogram ("<<theXHistN<<
","<<theYHistN<<
") was not found for PixelTemplateSmearer. Check if the smearing template exists.";
636 thePositionX = xgen->
generate(random);
637 thePositionY = ygen->
generate(random);
642 thePositionY *=
sign;
663 }
while(fabs(thePosition.
x()) > boundX || fabs(thePosition.
y()) > boundY);
678 std::vector<TrackingRecHitProduct::SimHitIdPair> & unmergedHits,
681 const double boundX,
const double boundY,
685 for (
auto simHitIdPair: unmergedHits)
688 product->addRecHit( recHit ,{simHitIdPair});
696 std::vector< MergeGroup* > & mergeGroups,
699 const double boundX,
const double boundY,
703 for (
auto mg_it = mergeGroups.begin(); mg_it != mergeGroups.end(); ++mg_it)
705 if ((*mg_it)->smearIt)
708 product->addRecHit( recHit, (*mg_it)->group);
719 const double boundX,
const double boundY,
732 for (
auto hit_it = mg->
group.begin(); hit_it != mg->
group.end(); ++hit_it)
737 loccx += localDir.
x();
738 loccy += localDir.
y();
739 loccz += localDir.
z();
749 float locx = loccx/nHit;
750 float locy = loccy/nHit;
751 float locz = loccz/nHit;
754 float cotalpha = locx/locz;
756 float cotbeta = locy/locz;
765 cotbeta = sign*cotbeta;
769 float lpx = locpx/nHit;
770 float lpy = locpy/nHit;
771 float lpz = locpz/nHit;
779 float yhit = 20. + 8.*(ytrk/
ysize);
780 float xhit = 20. + 8.*(xtrk/
xsize);
781 int ybin = (
int)yhit;
782 int xbin = (
int)xhit;
783 float yfrac= yhit - (
float)ybin;
784 float xfrac= xhit - (
float)xbin;
786 if( ybin < 0 ) ybin = 0;
787 if( ybin > 39 ) ybin = 39;
788 if( xbin < 0 ) xbin = 0;
789 if( xbin > 39 ) xbin = 39;
795 float ny1_frac, ny2_frac, nx1_frac, nx2_frac;
796 bool singlex =
false, singley =
false;
799 templ.
qbin_dist(
templateId, cotalpha, cotbeta, qbin_frac, ny1_frac, ny2_frac, nx1_frac, nx2_frac );
804 bool hitbigx =
false;
805 bool hitbigy =
false;
810 double qbinProbability = random->
flatShoot();
811 for(
int i = 0;
i<4; ++
i)
814 if(qbinProbability < qbin_frac[
i])
break;
819 float ytempl[41][
BYSIZE] = {{0}}, xtempl[41][
BXSIZE] = {{0}} ;
820 templ.
ytemp(0, 40, ytempl);
821 templ.
xtemp(0, 40, xtempl);
823 std::vector<double> ytemp(
BYSIZE);
826 ytemp[
i]=(1.-yfrac)*ytempl[ybin][
i]+yfrac*ytempl[ybin+1][
i];
829 std::vector<double> xtemp(
BXSIZE);
832 xtemp[
i]=(1.-xfrac)*xtempl[xbin][
i]+xfrac*xtempl[xbin+1][
i];
858 float sigmay, sigmax, sy1, sy2, sx1, sx2;
860 sigmay, sigmax, sy1, sy2, sx1, sx2 );
870 else if( !edgex && edgey )
917 theError =
LocalError( theErrorX*theErrorX, 0., theErrorY*theErrorY);
920 unsigned int retry = 0;
926 thePositionX = xgen->
generate(random);
927 thePositionY = ygen->
generate(random);
931 thePositionY *=
sign;
937 lpz + thePositionZ );
947 }
while(fabs(thePosition.
x()) > boundX || fabs(thePosition.
y()) > boundY);
962 float locy1 = localDir.
y();
963 float locz1 = localDir.
z();
964 float cotbeta = locy1/locz1;
965 float loceta = fabs(-
log((
double)(-cotbeta+
sqrt((
double)(1.+cotbeta*cotbeta)))));
969 float lpy1 = lp1.
y();
970 float lpx1 = lp1.
x();
971 float lpy2 = lp2.
y();
972 float lpx2 = lp2.
x();
973 float locdis = 10000.*
sqrt(
pow(lpx1 - lpx2, 2) +
pow(lpy1 - lpy2, 2));
975 float prob = probhisto->GetBinContent(probhisto->GetXaxis()->FindFixBin(locdis),probhisto->GetYaxis()->FindFixBin(loceta));
CLHEP::HepRandomEngine * randomEngine
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
T getParameter(std::string const &) const
virtual int nrows() const =0
virtual float length() const =0
TrackingRecHitProductPtr process(TrackingRecHitProductPtr product) const override
bool interpolate(int id, float cotalpha, float cotbeta, float locBz, float locBx)
double flatShoot(double xmin=0.0, double xmax=1.0) const
LocalVector momentumAtEntry() const
The momentum of the track that produced the hit, at entry point.
unsigned int rescotAlpha_binN
const TrackerGeometry & getTrackerGeometry() const
double rescotAlpha_binMin
bool isFlipped(const PixelGeomDetUnit *theDet) const
const Plane & surface() const
The nominal surface of the GeomDet.
U second(std::pair< T, U > const &p)
void ytemp(int fybin, int lybin, float ytemplate[41][21+4])
virtual float width() const =0
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
bool isItEdgePixelInX(int ixbin) const override
Local3DPoint localPosition() const
FastSingleTrackerRecHit smearMergeGroup(MergeGroup *mg, const PixelGeomDetUnit *detUnit, const double boundX, const double boundY, const RandomEngineAndDistribution *random) const
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)
DetId geographicalId() const
The label of this GeomDet.
double rescotBeta_binWidth
TrackingRecHitProductPtr processUnmergedHits(std::vector< TrackingRecHitProduct::SimHitIdPair > &unmergedHits, TrackingRecHitProductPtr product, const PixelGeomDetUnit *detUnit, const double boundX, const double boundY, RandomEngineAndDistribution const *random) const
bool hitsMerge(const PSimHit &simHit1, const PSimHit &simHit2) const
double rescotAlpha_binWidth
const RandomEngineAndDistribution & getRandomEngine() const
double generate(RandomEngineAndDistribution const *) const
The random generation.
bool isItBigPixelInY(const int iybin) const override
MeasurementPoint measurementPosition(const LocalPoint &lp) const override
float s50()
1/2 of the pixel threshold signal in electrons
std::shared_ptr< TrackingRecHitProduct > TrackingRecHitProductPtr
std::unique_ptr< TFile > theMergedPixelResolutionXFile
bool isItBigPixelInX(const int ixbin) const override
Point3DBase< float, LocalTag > Local3DPoint
Vector3DBase unit() const
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)
std::map< unsigned int, const SimpleHistogramGenerator * > theYHistos
virtual const TopologyType & specificTopology() const
unsigned int rescotBeta_binN
std::map< unsigned int, const SimpleHistogramGenerator * > theXHistos
std::vector< SiPixelTemplateStore > thePixelTemp_
virtual int ncolumns() const =0
const TrackerGeometry & getMisalignedGeometry() const
const TrackerGeomDet * idToDet(DetId) const override
FastSingleTrackerRecHit smearHit(const PSimHit &simHit, const PixelGeomDetUnit *detUnit, const double boundX, const double boundY, RandomEngineAndDistribution const *) const
std::unique_ptr< TFile > theMergedPixelResolutionYFile
bool containsBigPixelInY(int iymin, int iymax) const override
bool containsBigPixelInX(int ixmin, int ixmax) const override
~PixelTemplateSmearerBase() override
std::vector< TrackingRecHitProduct::SimHitIdPair > group
TrackingRecHitProductPtr processMergeGroups(std::vector< MergeGroup * > &mergeGroups, TrackingRecHitProductPtr product, const PixelGeomDetUnit *detUnit, const double boundX, const double boundY, RandomEngineAndDistribution const *random) const
bool isItEdgePixelInY(int iybin) const override
LocalError const & localAlignmentError() const
Return local alligment error.
Power< A, B >::type pow(const A &a, const B &b)
LocalPoint localPosition(const MeasurementPoint &mp) const override
virtual const PixelGeomDetType & specificType() const
PixelTemplateSmearerBase(const std::string &name, const edm::ParameterSet &config, edm::ConsumesCollector &consumesCollector)