37 const double PI = 3.14159265358979323;
46 thePixelPart(pixelPart)
62 throw cms::Exception(
"SiPixelGaussianSmearingRecHitConverterAlgorithm:")
63 <<
"SiPixel Barrel Template Not Loaded Correctly!"<<endl;
77 throw cms::Exception(
"SiPixelGaussianSmearingRecHitConverterAlgorithm:")
78 <<
"SiPixel Forward Template Not Loaded Correctly!"<<endl;
84 throw cms::Exception(
"SiPixelGaussianSmearingRecHitConverterAlgorithm :")
85 <<
"Not a pixel detector"<<endl;
91 std::map<unsigned,const SimpleHistogramGenerator*>::const_iterator it;
118 float locx = localDir.
x();
119 float locy = localDir.
y();
120 float locz = localDir.
z();
123 float cotalpha = locx/locz;
130 float cotbeta = locy/locz;
133 if( cotbeta < 0 ) sign=-1.;
134 cotbeta = sign*cotbeta;
141 <<
" cotalpha(x) = " << cotalpha
142 <<
" cotbeta(y) = " << cotbeta
147 const RectangularPixelTopology *rectPixelTopology =
static_cast<const RectangularPixelTopology*
>(theSpecificTopology);
149 const int nrows = theSpecificTopology->
nrows();
150 const int ncolumns = theSpecificTopology->
ncolumns();
158 float pixelCenterY = 0.5 + (int)mpy;
159 float pixelCenterX = 0.5 + (int)mpx;
161 cout<<
"Struck pixel center at pitch units x: "<<pixelCenterX<<
" y: "<<pixelCenterY<<endl;
166 const Local3DPoint lpCenter = rectPixelTopology->localPosition( mpCenter );
168 cout<<
"Struck point at cm x: "<<lp.
x()<<
" y: "<<lp.
y()<<endl;
169 cout<<
"Struck pixel center at cm x: "<<lpCenter.
x()<<
" y: "<<lpCenter.
y()<<endl;
170 cout<<
"The boundX is "<<boundX<<
" boundY is "<<boundY<<endl;
174 float xtrk = lp.
x() - lpCenter.
x();
175 float ytrk = lp.
y() - lpCenter.
y();
177 const float ysize={0.015}, xsize={0.01};
179 float yhit = 20. + 8.*(ytrk/ysize);
180 float xhit = 20. + 8.*(xtrk/xsize);
181 int ybin = (int)yhit;
182 int xbin = (int)xhit;
183 float yfrac= yhit - (float)ybin;
184 float xfrac= xhit - (float)xbin;
186 if( ybin < 0 ) ybin = 0;
187 if( ybin > 39 ) ybin = 39;
188 if( xbin < 0 ) xbin = 0;
189 if( xbin > 39 ) xbin = 39;
195 float ny1_frac, ny2_frac, nx1_frac, nx2_frac;
196 bool singlex =
false, singley =
false;
201 double xsizeProbability = random->
flatShoot();
202 double ysizeProbability = random->
flatShoot();
203 bool hitbigx = rectPixelTopology->isItBigPixelInX( (
int)mpx );
204 bool hitbigy = rectPixelTopology->isItBigPixelInY( (
int)mpy );
207 if( xsizeProbability < nx2_frac ) singlex =
true;
208 else singlex =
false;
210 if( xsizeProbability < nx1_frac ) singlex =
true;
211 else singlex =
false;
214 if( ysizeProbability < ny2_frac ) singley =
true;
215 else singley =
false;
217 if( ysizeProbability < ny1_frac ) singley =
true;
218 else singley =
false;
223 double qbinProbability = random->
flatShoot();
224 for(
int i = 0;
i<4; ++
i) {
226 if(qbinProbability < qbin_frac[
i])
break;
231 float ytempl[41][
BYSIZE] = {{0}}, xtempl[41][
BXSIZE] = {{0}} ;
235 std::vector<double> ytemp(
BYSIZE);
237 ytemp[
i]=(1.-yfrac)*ytempl[ybin][
i]+yfrac*ytempl[ybin+1][
i];
240 std::vector<double> xtemp(
BXSIZE);
242 xtemp[
i]=(1.-xfrac)*xtempl[xbin][
i]+xfrac*xtempl[xbin+1][
i];
246 const float qThreshold =
templ.
s50()*2.0;
250 int offsetX1=0, offsetX2=0, offsetY1=0, offsetY2=0;
251 int firstY, lastY, firstX, lastX;
252 for( firstY = 0; firstY <
BYSIZE; ++firstY ) {
253 bool yCluster = ytemp[firstY] > qThreshold ;
256 offsetY1 =
BHY -firstY;
260 for( lastY = firstY; lastY <
BYSIZE; ++lastY )
262 bool yCluster = ytemp[lastY] > qThreshold ;
266 offsetY2 = lastY -
BHY;
271 for( firstX = 0; firstX <
BXSIZE; ++firstX ) {
272 bool xCluster = xtemp[firstX] > qThreshold ;
274 offsetX1 =
BHX - firstX;
278 for( lastX = firstX; lastX <
BXSIZE; ++ lastX ) {
279 bool xCluster = xtemp[lastX] > qThreshold ;
282 offsetX2 = lastX -
BHX;
287 bool edge, edgex, edgey;
289 unsigned int clslenx = offsetX1 + offsetX2 + 1;
290 unsigned int clsleny = offsetY1 + offsetY2 + 1;
295 int firstPixelInX = (int)mpx - offsetX1 ;
296 int firstPixelInY = (int)mpy - offsetY1 ;
297 int lastPixelInX = (int)mpx + offsetX2 ;
298 int lastPixelInY = (int)mpy + offsetY2 ;
299 firstPixelInX = (firstPixelInX >= 0) ? firstPixelInX : 0 ;
300 firstPixelInY = (firstPixelInY >= 0) ? firstPixelInY : 0 ;
301 lastPixelInX = (lastPixelInX < nrows ) ? lastPixelInX : nrows-1 ;
302 lastPixelInY = (lastPixelInY < ncolumns ) ? lastPixelInY : ncolumns-1;
304 edgex = rectPixelTopology->isItEdgePixelInX( firstPixelInX ) || rectPixelTopology->isItEdgePixelInX( lastPixelInX );
305 edgey = rectPixelTopology->isItEdgePixelInY( firstPixelInY ) || rectPixelTopology->isItEdgePixelInY( lastPixelInY );
306 edge = edgex || edgey;
310 bool hasBigPixelInX = rectPixelTopology->containsBigPixelInX( firstPixelInX, lastPixelInX );
311 bool hasBigPixelInY = rectPixelTopology->containsBigPixelInY( firstPixelInY, lastPixelInY );
314 float sigmay, sigmax, sy1, sy2, sx1, sx2;
319 if( edgex && !edgey ) {
323 else if( !edgex && edgey ) {
355 <<
"\talpha(x) = " << theErrorX
356 <<
"\tbeta(y) = " << theErrorY
364 if( cotalphaHistBin < 1 ) cotalphaHistBin = 1;
365 if( cotbetaHistBin < 1 ) cotbetaHistBin = 1;
369 unsigned int theXHistN;
370 unsigned int theYHistN;
374 theXHistN = cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
375 theYHistN = theXHistN;
381 if(hitbigx) theXHistN = 1 * 100000 + cotalphaHistBin * 100 + cotbetaHistBin ;
382 else theXHistN = 1 * 100000 + 1 * 1000 + cotalphaHistBin * 100 + cotbetaHistBin ;
386 if(hasBigPixelInX) theXHistN = 1 * 1000000 + 1 * 100000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
387 else theXHistN = 1 * 1000000 + 1 * 100000 + 1 * 10000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
391 if(hitbigy) theYHistN = 1 * 100000 + cotalphaHistBin * 100 + cotbetaHistBin ;
392 else theYHistN = 1 * 100000 + 1 * 1000 + cotalphaHistBin * 100 + cotbetaHistBin ;
396 if(hasBigPixelInY) theYHistN = 1 * 1000000 + 1 * 100000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
397 else theYHistN = 1 * 1000000 + 1 * 100000 + 1 * 10000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
405 theXHistN = cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
406 theYHistN = theXHistN;
412 theXHistN = 100000 + cotalphaHistBin * 100 + cotbetaHistBin;
414 theXHistN = 100000 + 1000 + cotalphaHistBin * 100 + cotbetaHistBin;
416 theXHistN = 100000 + 10000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
419 theYHistN = 100000 + cotalphaHistBin * 100 + cotbetaHistBin;
421 theYHistN = 100000 + 1000 + cotalphaHistBin * 100 + cotbetaHistBin;
423 theYHistN = 100000 + 10000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
443 <<
"\t\tx = " << boundX
444 <<
"\ty = " << boundY
446 std::cout <<
" Generated local position "
480 if ( tmp2<tmp1 )
return true;
498 for (
unsigned cotalphaHistBin=1; cotalphaHistBin<=
rescotAlpha_binN; ++cotalphaHistBin )
499 for (
unsigned cotbetaHistBin=1; cotbetaHistBin<=
rescotBeta_binN; ++cotbetaHistBin ) {
500 unsigned int singleBigPixelHistN = 1 * 100000
501 + cotalphaHistBin * 100
507 unsigned int singlePixelHistN = 1 * 100000 + 1 * 1000
508 + cotalphaHistBin * 100
514 for(
unsigned qbinBin=1; qbinBin<=
resqbin_binN; ++qbinBin ) {
515 unsigned int edgePixelHistN = cotalphaHistBin * 1000
516 + cotbetaHistBin * 10
522 unsigned int multiPixelBigHistN = 1 * 1000000 + 1 * 100000
523 + cotalphaHistBin * 1000
524 + cotbetaHistBin * 10
530 unsigned int multiPixelHistN = 1 * 1000000 + 1 * 100000 + 1 * 10000
531 + cotalphaHistBin * 1000
532 + cotbetaHistBin * 10
556 for (
unsigned cotalphaHistBin=1; cotalphaHistBin<=
rescotAlpha_binN; ++cotalphaHistBin )
557 for (
unsigned cotbetaHistBin=1; cotbetaHistBin<=
rescotBeta_binN; ++cotbetaHistBin )
558 for(
unsigned qbinBin=1; qbinBin<=
resqbin_binN; ++qbinBin ) {
559 unsigned int edgePixelHistN = cotalphaHistBin * 1000 + cotbetaHistBin * 10 + qbinBin;
564 unsigned int PixelHistN = 100000 + 10000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + qbinBin;
571 for (
unsigned cotalphaHistBin=1; cotalphaHistBin<=
rescotAlpha_binN; ++cotalphaHistBin )
572 for (
unsigned cotbetaHistBin=1; cotbetaHistBin<=
rescotBeta_binN; ++cotbetaHistBin )
574 unsigned int SingleBigPixelHistN = 100000 + cotalphaHistBin * 100 + cotbetaHistBin;
579 unsigned int SinglePixelHistN = 100000 + 1000 + cotalphaHistBin * 100 + cotbetaHistBin;
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
T getParameter(std::string const &) const
double rescotAlpha_binMin
bool isFlipped(const PixelGeomDetUnit *theDet) const
std::string thePixelResolutionFileName2
double flatShoot(double xmin=0.0, double xmax=1.0) const
virtual int ncolumns() const =0
LocalVector momentumAtEntry() const
The momentum of the track that produced the hit, at entry point.
double rescotBeta_binWidth
virtual int nrows() const =0
unsigned int rescotBeta_binN
std::string thePixelResolutionFileName1
const Plane & surface() const
The nominal surface of the GeomDet.
std::map< unsigned, const SimpleHistogramGenerator * > theXHistos
bool interpolate(int id, float cotalpha, float cotbeta, float locBz)
unsigned int resqbin_binN
unsigned int rescotAlpha_binN
virtual PixelGeomDetType & specificType() const
Local3DPoint localPosition() const
void xtemp(int fxbin, int lxbin, float xtemplate[41][BXSIZE])
void temperrors(int id, float cotalpha, float cotbeta, int qBin, float &sigmay, float &sigmax, float &sy1, float &sy2, float &sx1, float &sx2)
GeomDetType::SubDetector thePixelPart
void ytemp(int fybin, int lybin, float ytemplate[41][BYSIZE])
bool useCMSSWPixelParameterization
float s50()
1/2 of the pixel threshold signal in electrons
LocalVector localDirection() const
Obsolete. Same as momentumAtEntry().unit(), for backward compatibility.
Point3DBase< float, LocalTag > Local3DPoint
Vector3DBase unit() const
bool pushfile(int filenum)
double rescotAlpha_binWidth
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, const SimpleHistogramGenerator * > theYHistos
void smearHit(const PSimHit &simHit, const PixelGeomDetUnit *detUnit, const double boundX, const double boundY, RandomEngineAndDistribution const *)
virtual ~SiPixelGaussianSmearingRecHitConverterAlgorithm()
static std::atomic< unsigned int > counter
SiPixelGaussianSmearingRecHitConverterAlgorithm(const edm::ParameterSet &pset, GeomDetType::SubDetector pixelPart)
TFile * thePixelResolutionFile1
TFile * thePixelResolutionFile2