78 <<
" constructing PixelResolutionHistograms file " << theRegularPixelResolutionFileName
79 <<
" failed with status = " << status << std::endl;
86 <<
" constructing PixelResolutionHistograms file " << theBigPixelResolutionFileName
87 <<
" failed with status = " << status << std::endl;
94 <<
" constructing PixelResolutionHistograms file " << theEdgePixelResolutionFileName
95 <<
" failed with status = " << status << std::endl;
118 if ( config.
exists(
"templateId") ) {
124 <<
"SiPixel Template " <<
templateId <<
" Not Loaded Correctly!" << std::endl;
153 std::vector< SiPixelTemplateStore > & tempStoreRef )
191 std::vector<std::pair<unsigned int,const PSimHit*>> & simHitIdPairs = product->getSimHitIdPairs();
192 std::vector<const PSimHit*>
simHits(simHitIdPairs.size());
193 for (
unsigned int ihit = 0; ihit<simHitIdPairs.size();++ihit)
195 simHits[ihit]=simHitIdPairs[ihit].second;
203 if (pixelGeomDet ==
nullptr)
205 throw cms::Exception(
"FastSimulation/TrackingRecHitProducer") <<
"The GeomDetUnit is not a PixelGeomDetUnit. This should never happen!";
208 const Bounds& theBounds = theDetPlane.bounds();
209 const double boundX = theBounds.
width()/2.;
210 const double boundY = theBounds.
length()/2.;
213 std::vector<TrackingRecHitProduct::SimHitIdPair> listOfUnmergedHits;
214 std::vector< MergeGroup* > listOfMergeGroups;
227 listOfUnmergedHits.push_back(simHitIdPairs[0]);
234 for (
int i = 0;
i < nHits; ++
i )
237 mergeGroupByHit[
i] =
nullptr;
239 for (
int i = 0;
i < nHits-1; ++
i )
241 for (
int j =
i+1 ; j < nHits; ++j ) {
244 bool merged =
hitsMerge( *simHitIdPairs[
i].
second, *simHitIdPairs[j].second );
250 if ( mergeGroupByHit[j] !=
nullptr )
252 if (mergeGroupByHit[
i] ==
nullptr )
254 mergeGroupByHit[
i] = mergeGroupByHit[j];
255 mergeGroupByHit[
i]->
group.push_back(simHitIdPairs[
i]);
260 if (mergeGroupByHit[
i] != mergeGroupByHit[j])
262 for (
auto hit_it = mergeGroupByHit[j]->
group.begin(); hit_it != mergeGroupByHit[j]->
group.end(); ++hit_it)
264 mergeGroupByHit[
i]->
group.push_back( *hit_it );
270 for (
int k = 0;
k < nHits; ++
k )
272 if ( mgbhj == mergeGroupByHit[
k])
275 mergeGroupByHit[
k] = mergeGroupByHit[
i];
292 if ( mergeGroupByHit[
i] ==
nullptr )
297 listOfMergeGroups.push_back( mergeGroupByHit[
i] );
301 mergeGroupByHit[
i]->
group.push_back( simHitIdPairs[i] );
305 mergeGroupByHit[
i]->
group.push_back( simHitIdPairs[j] );
308 mergeGroupByHit[j] = mergeGroupByHit[
i];
322 if ( mergeGroupByHit[
i] ==
nullptr )
325 listOfUnmergedHits.push_back( simHitIdPairs[
i] );
333 for (
int i = 0;
i < nHits; ++
i )
335 listOfUnmergedHits.push_back( simHitIdPairs[
i] );
345 pixelGeomDet, boundX, boundY,
350 pixelGeomDet, boundX, boundY,
358 for (
auto mg_it = listOfMergeGroups.begin(); mg_it != listOfMergeGroups.end(); ++mg_it )
382 float locx = localDir.
x();
383 float locy = localDir.
y();
384 float locz = localDir.
z();
390 float cotalpha = locx/locz;
391 float cotbeta = locy/locz;
394 int signOfCotalpha = (cotalpha < 0) ? -1 : 1;
395 int signOfCotbeta = (cotbeta < 0) ? -1 : 1;
398 cotalpha *= signOfCotalpha;
399 cotbeta *= signOfCotbeta;
401 LogDebug (
"SmearHit") <<
"LocalVector=" << locx <<
"," << locy <<
"," << locz
402 <<
" momentum=" << localDir.
mag()
403 <<
" cotalpha=" << cotalpha <<
", cotbeta=" << cotbeta;
408 const int nrows = theSpecificTopology->
nrows();
409 const int ncolumns = theSpecificTopology->
ncolumns();
417 float pixelCenterY = 0.5 + (
int)mpy;
418 float pixelCenterX = 0.5 + (
int)mpx;
425 float xtrk = lp.
x() - lpCenter.
x();
426 float ytrk = lp.
y() - lpCenter.
y();
430 float yhit = 20. + 8.*(ytrk/
ysize);
431 float xhit = 20. + 8.*(xtrk/
xsize);
432 int ybin = (
int)yhit;
433 int xbin = (
int)xhit;
434 float yfrac= yhit - (
float)ybin;
435 float xfrac= xhit - (
float)xbin;
437 if( ybin < 0 ) ybin = 0;
438 if( ybin > 39 ) ybin = 39;
439 if( xbin < 0 ) xbin = 0;
440 if( xbin > 39 ) xbin = 39;
461 float ny1_frac, ny2_frac, nx1_frac, nx2_frac;
462 bool singlex =
false, singley =
false;
463 templ.
qbin_dist( ID, cotalpha, cotbeta, qbin_frac, ny1_frac, ny2_frac, nx1_frac, nx2_frac );
466 double xsizeProbability = random->
flatShoot();
467 double ysizeProbability = random->
flatShoot();
472 if( xsizeProbability < nx2_frac ) singlex =
true;
473 else singlex =
false;
475 if( xsizeProbability < nx1_frac ) singlex =
true;
476 else singlex =
false;
479 if( ysizeProbability < ny2_frac ) singley =
true;
480 else singley =
false;
482 if( ysizeProbability < ny1_frac ) singley =
true;
483 else singley =
false;
488 double qbinProbability = random->
flatShoot();
489 for(
int i = 0;
i<4; ++
i)
492 if (qbinProbability < qbin_frac[
i])
500 float ytempl[41][
BYSIZE] = {{0}}, xtempl[41][
BXSIZE] = {{0}} ;
501 templ.
ytemp(0, 40, ytempl);
502 templ.
xtemp(0, 40, xtempl);
504 std::vector<double> ytemp(
BYSIZE);
507 ytemp[
i]=(1.-yfrac)*ytempl[ybin][
i]+yfrac*ytempl[ybin+1][
i];
510 std::vector<double> xtemp(
BXSIZE);
513 xtemp[
i]=(1.-xfrac)*xtempl[xbin][
i]+xfrac*xtempl[xbin+1][
i];
517 const float qThreshold = templ.
s50()*2.0;
521 int offsetX1=0, offsetX2=0, offsetY1=0, offsetY2=0;
522 int firstY, lastY, firstX, lastX;
523 for( firstY = 0; firstY <
BYSIZE; ++firstY )
525 bool yCluster = ytemp[firstY] > qThreshold;
528 offsetY1 =
BHY -firstY;
532 for(lastY = firstY; lastY <
BYSIZE; ++lastY)
534 bool yCluster = ytemp[lastY] > qThreshold;
538 offsetY2 = lastY -
BHY;
543 for( firstX = 0; firstX <
BXSIZE; ++firstX )
545 bool xCluster = xtemp[firstX] > qThreshold;
548 offsetX1 =
BHX - firstX;
552 for( lastX = firstX; lastX <
BXSIZE; ++ lastX )
554 bool xCluster = xtemp[lastX] > qThreshold;
558 offsetX2 = lastX -
BHX;
578 bool edge, edgex, edgey;
581 int firstPixelInX = (
int)mpx - offsetX1 ;
582 int firstPixelInY = (
int)mpy - offsetY1 ;
583 int lastPixelInX = (
int)mpx + offsetX2 ;
584 int lastPixelInY = (
int)mpy + offsetY2 ;
585 firstPixelInX = (firstPixelInX >= 0) ? firstPixelInX : 0 ;
586 firstPixelInY = (firstPixelInY >= 0) ? firstPixelInY : 0 ;
587 lastPixelInX = (lastPixelInX < nrows ) ? lastPixelInX : nrows-1 ;
588 lastPixelInY = (lastPixelInY < ncolumns ) ? lastPixelInY : ncolumns-1;
592 edge = edgex || edgey;
596 bool hasBigPixelInX = rectPixelTopology->
containsBigPixelInX( firstPixelInX, lastPixelInX );
597 bool hasBigPixelInY = rectPixelTopology->
containsBigPixelInY( firstPixelInY, lastPixelInY );
600 float sigmay, sigmax, sy1, sy2, sx1, sx2;
602 ID, cotalpha, cotbeta, nqbin,
603 sigmay, sigmax, sy1, sy2, sx1, sx2
613 else if(!edgex && edgey)
662 if (alignmentError.
valid())
665 theErrorX*theErrorX+alignmentError.
xx(),
667 theErrorY*theErrorY+alignmentError.
yy()
686 shared_ptr<PixelResolutionHistograms> resHistsX =
nullptr;
687 shared_ptr<PixelResolutionHistograms> resHistsY =
nullptr;
692 singlex = singley =
false;
696 if ( (singlex && hitbigx) || (
isBarrel && hasBigPixelInX) ) {
703 if ( (singley && hitbigy) || (
isBarrel && hasBigPixelInY) ) {
713 = resHistsX->getGeneratorX( cotalpha, cotbeta, nqbin, singlex );
715 = resHistsY->getGeneratorY( cotalpha, cotbeta, nqbin, singley );
718 if ( !xgen || !ygen ) {
720 <<
"Histogram (cot\alpha=" << cotalpha
721 <<
", cot\beta="<< cotbeta <<
", nQbin=" << nqbin
722 <<
") was not found for PixelTemplateSmearer. Check if the smearing resolution histogram exists.";
729 unsigned int retry = 0;
734 theShiftInX = xgen->
generate(random);
735 theShiftInY = ygen->
generate(random);
738 theShiftInX *= signOfCotalpha;
739 theShiftInY *= signOfCotbeta;
760 }
while(fabs(thePosition.
x()) > boundX || fabs(thePosition.
y()) > boundY);
780 std::vector<TrackingRecHitProduct::SimHitIdPair> & unmergedHits,
783 const double boundX,
const double boundY,
787 for (
auto simHitIdPair: unmergedHits)
790 product->addRecHit( recHit ,{simHitIdPair});
802 std::vector< MergeGroup* > & mergeGroups,
805 const double boundX,
const double boundY,
809 for (
auto mg_it = mergeGroups.begin(); mg_it != mergeGroups.end(); ++mg_it)
811 if ((*mg_it)->smearIt)
814 product->addRecHit( recHit, (*mg_it)->group);
829 const double boundX,
const double boundY,
842 for (
auto hit_it = mg->
group.begin(); hit_it != mg->
group.end(); ++hit_it)
847 loccx += localDir.
x();
848 loccy += localDir.
y();
849 loccz += localDir.
z();
859 float locx = loccx/nHit;
860 float locy = loccy/nHit;
861 float locz = loccz/nHit;
867 float cotalpha = locx/locz;
868 float cotbeta = locy/locz;
871 int signOfCotalpha = (cotalpha < 0) ? -1 : 1;
872 int signOfCotbeta = (cotbeta < 0) ? -1 : 1;
875 cotalpha *= signOfCotalpha;
876 cotbeta *= signOfCotbeta;
878 float lpx = locpx/nHit;
879 float lpy = locpy/nHit;
880 float lpz = locpz/nHit;
888 float yhit = 20. + 8.*(ytrk/
ysize);
889 float xhit = 20. + 8.*(xtrk/
xsize);
890 int ybin = (
int)yhit;
891 int xbin = (
int)xhit;
892 float yfrac= yhit - (
float)ybin;
893 float xfrac= xhit - (
float)xbin;
895 if( ybin < 0 ) ybin = 0;
896 if( ybin > 39 ) ybin = 39;
897 if( xbin < 0 ) xbin = 0;
898 if( xbin > 39 ) xbin = 39;
918 float ny1_frac, ny2_frac, nx1_frac, nx2_frac;
919 bool singlex =
false, singley =
false;
920 templ.
qbin_dist( ID, cotalpha, cotbeta, qbin_frac, ny1_frac, ny2_frac, nx1_frac, nx2_frac );
925 bool hitbigx =
false;
926 bool hitbigy =
false;
932 double qbinProbability = random->
flatShoot();
933 for(
int i = 0;
i<4; ++
i)
936 if(qbinProbability < qbin_frac[
i])
break;
941 float ytempl[41][
BYSIZE] = {{0}}, xtempl[41][
BXSIZE] = {{0}} ;
942 templ.
ytemp(0, 40, ytempl);
943 templ.
xtemp(0, 40, xtempl);
945 std::vector<double> ytemp(
BYSIZE);
948 ytemp[
i]=(1.-yfrac)*ytempl[ybin][
i]+yfrac*ytempl[ybin+1][
i];
951 std::vector<double> xtemp(
BXSIZE);
954 xtemp[
i]=(1.-xfrac)*xtempl[xbin][
i]+xfrac*xtempl[xbin+1][
i];
978 float sigmay, sigmax, sy1, sy2, sx1, sx2;
979 templ.
temperrors( ID, cotalpha, cotbeta, nqbin,
980 sigmay, sigmax, sy1, sy2, sx1, sx2 );
990 else if( !edgex && edgey )
1037 theError =
LocalError( theErrorX*theErrorX, 0., theErrorY*theErrorY);
1040 unsigned int retry = 0;
1047 theShiftInX = xgen->
generate(random);
1048 theShiftInY = ygen->
generate(random);
1051 theShiftInX *= signOfCotalpha;
1052 theShiftInY *= signOfCotbeta;
1059 lpz + theShiftInZ );
1069 }
while(fabs(thePosition.
x()) > boundX || fabs(thePosition.
y()) > boundY);
1084 float locy1 = localDir.
y();
1085 float locz1 = localDir.
z();
1086 float cotbeta = locy1/locz1;
1087 float loceta = fabs(-
log((
double)(-cotbeta+
sqrt((
double)(1.+cotbeta*cotbeta)))));
1091 float lpy1 = lp1.
y();
1092 float lpx1 = lp1.
x();
1093 float lpy2 = lp2.
y();
1094 float lpx2 = lp2.
x();
1095 float locdis = 10000.*
sqrt(
pow(lpx1 - lpx2, 2) +
pow(lpy1 - lpy2, 2));
1097 float prob = probhisto->GetBinContent(probhisto->GetXaxis()->FindFixBin(locdis),probhisto->GetYaxis()->FindFixBin(loceta));
CLHEP::HepRandomEngine * randomEngine
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)
void beginRun(edm::Run const &run, const edm::EventSetup &eventSetup, const SiPixelTemplateDBObject *pixelTemplateDBObjectPtr, std::vector< SiPixelTemplateStore > &tempStoreRef) override
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.
short getTemplateID(const uint32_t &detid) const
std::string theMergedPixelResolutionYFileName
std::string theRegularPixelResolutionFileName
bool exists(std::string const ¶meterName) const
checks if a parameter exists
const TrackerGeometry & getTrackerGeometry() const
const SiPixelTemplateDBObject * pixelTemplateDBObject_
const Plane & surface() const
The nominal surface of the GeomDet.
std::string theMergedPixelResolutionXFileName
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.
std::vector< SiPixelTemplateStore > & thePixelTempRef
bool isItEdgePixelInX(int ixbin) const override
std::string theEdgePixelResolutionFileName
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.
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
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
std::string theBigPixelResolutionFileName
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)
virtual const TopologyType & specificTopology() const
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore > &pixelTemp, std::string dir="CalibTracker/SiPixelESProducers/data/")
std::shared_ptr< PixelResolutionHistograms > theBigPixelResolutions
std::vector< SiPixelTemplateStore > thePixelTemp_
virtual int ncolumns() const =0
std::string theMergingProbabilityFileName
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
std::string fullPath() const
bool containsBigPixelInY(int iymin, int iymax) const override
std::shared_ptr< PixelResolutionHistograms > theEdgePixelResolutions
bool containsBigPixelInX(int ixmin, int ixmax) const override
~PixelTemplateSmearerBase() override
std::shared_ptr< PixelResolutionHistograms > theRegularPixelResolutions
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)