37 const double PI = 3.14159265358979323;
47 thePixelPart(pixelPart),
64 throw cms::Exception(
"SiPixelGaussianSmearingRecHitConverterAlgorithm:")
65 <<
"SiPixel Barrel Template Not Loaded Correctly!"<<endl;
79 throw cms::Exception(
"SiPixelGaussianSmearingRecHitConverterAlgorithm:")
80 <<
"SiPixel Forward Template Not Loaded Correctly!"<<endl;
86 throw cms::Exception(
"SiPixelGaussianSmearingRecHitConverterAlgorithm :")
87 <<
"Not a pixel detector"<<endl;
93 std::map<unsigned,const SimpleHistogramGenerator*>::const_iterator it;
119 float locx = localDir.
x();
120 float locy = localDir.
y();
121 float locz = localDir.
z();
124 float cotalpha = locx/locz;
131 float cotbeta = locy/locz;
134 if( cotbeta < 0 ) sign=-1.;
135 cotbeta = sign*cotbeta;
142 <<
" cotalpha(x) = " << cotalpha
143 <<
" cotbeta(y) = " << cotbeta
148 const RectangularPixelTopology *rectPixelTopology =
static_cast<const RectangularPixelTopology*
>(theSpecificTopology);
150 const int nrows = theSpecificTopology->
nrows();
151 const int ncolumns = theSpecificTopology->
ncolumns();
159 float pixelCenterY = 0.5 + (int)mpy;
160 float pixelCenterX = 0.5 + (int)mpx;
162 cout<<
"Struck pixel center at pitch units x: "<<pixelCenterX<<
" y: "<<pixelCenterY<<endl;
167 const Local3DPoint lpCenter = rectPixelTopology->localPosition( mpCenter );
169 cout<<
"Struck point at cm x: "<<lp.
x()<<
" y: "<<lp.
y()<<endl;
170 cout<<
"Struck pixel center at cm x: "<<lpCenter.
x()<<
" y: "<<lpCenter.
y()<<endl;
171 cout<<
"The boundX is "<<boundX<<
" boundY is "<<boundY<<endl;
175 float xtrk = lp.
x() - lpCenter.
x();
176 float ytrk = lp.
y() - lpCenter.
y();
178 const float ysize={0.015}, xsize={0.01};
180 float yhit = 20. + 8.*(ytrk/ysize);
181 float xhit = 20. + 8.*(xtrk/xsize);
182 int ybin = (int)yhit;
183 int xbin = (int)xhit;
184 float yfrac= yhit - (float)ybin;
185 float xfrac= xhit - (float)xbin;
187 if( ybin < 0 ) ybin = 0;
188 if( ybin > 39 ) ybin = 39;
189 if( xbin < 0 ) xbin = 0;
190 if( xbin > 39 ) xbin = 39;
196 float ny1_frac, ny2_frac, nx1_frac, nx2_frac;
197 bool singlex =
false, singley =
false;
204 bool hitbigx = rectPixelTopology->isItBigPixelInX( (
int)mpx );
205 bool hitbigy = rectPixelTopology->isItBigPixelInY( (
int)mpy );
208 if( xsizeProbability < nx2_frac ) singlex =
true;
209 else singlex =
false;
211 if( xsizeProbability < nx1_frac ) singlex =
true;
212 else singlex =
false;
215 if( ysizeProbability < ny2_frac ) singley =
true;
216 else singley =
false;
218 if( ysizeProbability < ny1_frac ) singley =
true;
219 else singley =
false;
225 for(
int i = 0;
i<4; ++
i) {
227 if(qbinProbability < qbin_frac[
i])
break;
232 float ytempl[41][
BYSIZE] = {{0}}, xtempl[41][
BXSIZE] = {{0}} ;
236 std::vector<double> ytemp(
BYSIZE);
238 ytemp[
i]=(1.-yfrac)*ytempl[ybin][
i]+yfrac*ytempl[ybin+1][
i];
241 std::vector<double> xtemp(
BXSIZE);
243 xtemp[
i]=(1.-xfrac)*xtempl[xbin][
i]+xfrac*xtempl[xbin+1][
i];
247 const float qThreshold =
templ.
s50()*2.0;
251 int offsetX1=0, offsetX2=0, offsetY1=0, offsetY2=0;
252 int firstY, lastY, firstX, lastX;
253 for( firstY = 0; firstY <
BYSIZE; ++firstY ) {
254 bool yCluster = ytemp[firstY] > qThreshold ;
257 offsetY1 =
BHY -firstY;
261 for( lastY = firstY; lastY <
BYSIZE; ++lastY )
263 bool yCluster = ytemp[lastY] > qThreshold ;
267 offsetY2 = lastY -
BHY;
272 for( firstX = 0; firstX <
BXSIZE; ++firstX ) {
273 bool xCluster = xtemp[firstX] > qThreshold ;
275 offsetX1 =
BHX - firstX;
279 for( lastX = firstX; lastX <
BXSIZE; ++ lastX ) {
280 bool xCluster = xtemp[lastX] > qThreshold ;
283 offsetX2 = lastX -
BHX;
288 bool edge, edgex, edgey;
290 unsigned int clslenx = offsetX1 + offsetX2 + 1;
291 unsigned int clsleny = offsetY1 + offsetY2 + 1;
296 int firstPixelInX = (int)mpx - offsetX1 ;
297 int firstPixelInY = (int)mpy - offsetY1 ;
298 int lastPixelInX = (int)mpx + offsetX2 ;
299 int lastPixelInY = (int)mpy + offsetY2 ;
300 firstPixelInX = (firstPixelInX >= 0) ? firstPixelInX : 0 ;
301 firstPixelInY = (firstPixelInY >= 0) ? firstPixelInY : 0 ;
302 lastPixelInX = (lastPixelInX < nrows ) ? lastPixelInX : nrows-1 ;
303 lastPixelInY = (lastPixelInY < ncolumns ) ? lastPixelInY : ncolumns-1;
305 edgex = rectPixelTopology->isItEdgePixelInX( firstPixelInX ) || rectPixelTopology->isItEdgePixelInX( lastPixelInX );
306 edgey = rectPixelTopology->isItEdgePixelInY( firstPixelInY ) || rectPixelTopology->isItEdgePixelInY( lastPixelInY );
307 edge = edgex || edgey;
311 bool hasBigPixelInX = rectPixelTopology->containsBigPixelInX( firstPixelInX, lastPixelInX );
312 bool hasBigPixelInY = rectPixelTopology->containsBigPixelInY( firstPixelInY, lastPixelInY );
315 float sigmay, sigmax, sy1, sy2, sx1, sx2;
320 if( edgex && !edgey ) {
324 else if( !edgex && edgey ) {
356 <<
"\talpha(x) = " << theErrorX
357 <<
"\tbeta(y) = " << theErrorY
365 if( cotalphaHistBin < 1 ) cotalphaHistBin = 1;
366 if( cotbetaHistBin < 1 ) cotbetaHistBin = 1;
370 unsigned int theXHistN;
371 unsigned int theYHistN;
375 theXHistN = cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
376 theYHistN = theXHistN;
382 if(hitbigx) theXHistN = 1 * 100000 + cotalphaHistBin * 100 + cotbetaHistBin ;
383 else theXHistN = 1 * 100000 + 1 * 1000 + cotalphaHistBin * 100 + cotbetaHistBin ;
387 if(hasBigPixelInX) theXHistN = 1 * 1000000 + 1 * 100000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
388 else theXHistN = 1 * 1000000 + 1 * 100000 + 1 * 10000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
392 if(hitbigy) theYHistN = 1 * 100000 + cotalphaHistBin * 100 + cotbetaHistBin ;
393 else theYHistN = 1 * 100000 + 1 * 1000 + cotalphaHistBin * 100 + cotbetaHistBin ;
397 if(hasBigPixelInY) theYHistN = 1 * 1000000 + 1 * 100000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
398 else theYHistN = 1 * 1000000 + 1 * 100000 + 1 * 10000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
406 theXHistN = cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
407 theYHistN = theXHistN;
413 theXHistN = 100000 + cotalphaHistBin * 100 + cotbetaHistBin;
415 theXHistN = 100000 + 1000 + cotalphaHistBin * 100 + cotbetaHistBin;
417 theXHistN = 100000 + 10000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
420 theYHistN = 100000 + cotalphaHistBin * 100 + cotbetaHistBin;
422 theYHistN = 100000 + 1000 + cotalphaHistBin * 100 + cotbetaHistBin;
424 theYHistN = 100000 + 10000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + (nqbin+1);
427 unsigned int counter = 0;
444 <<
"\t\tx = " << boundX
445 <<
"\ty = " << boundY
447 std::cout <<
" Generated local position "
481 if ( tmp2<tmp1 )
return true;
499 for (
unsigned cotalphaHistBin=1; cotalphaHistBin<=
rescotAlpha_binN; ++cotalphaHistBin )
500 for (
unsigned cotbetaHistBin=1; cotbetaHistBin<=
rescotBeta_binN; ++cotbetaHistBin ) {
501 unsigned int singleBigPixelHistN = 1 * 100000
502 + cotalphaHistBin * 100
510 unsigned int singlePixelHistN = 1 * 100000 + 1 * 1000
511 + cotalphaHistBin * 100
519 for(
unsigned qbinBin=1; qbinBin<=
resqbin_binN; ++qbinBin ) {
520 unsigned int edgePixelHistN = cotalphaHistBin * 1000
521 + cotbetaHistBin * 10
527 unsigned int multiPixelBigHistN = 1 * 1000000 + 1 * 100000
528 + cotalphaHistBin * 1000
529 + cotbetaHistBin * 10
535 unsigned int multiPixelHistN = 1 * 1000000 + 1 * 100000 + 1 * 10000
536 + cotalphaHistBin * 1000
537 + cotbetaHistBin * 10
563 for (
unsigned cotalphaHistBin=1; cotalphaHistBin<=
rescotAlpha_binN; ++cotalphaHistBin )
564 for (
unsigned cotbetaHistBin=1; cotbetaHistBin<=
rescotBeta_binN; ++cotbetaHistBin )
565 for(
unsigned qbinBin=1; qbinBin<=
resqbin_binN; ++qbinBin ) {
566 unsigned int edgePixelHistN = cotalphaHistBin * 1000 + cotbetaHistBin * 10 + qbinBin;
571 unsigned int PixelHistN = 100000 + 10000 + cotalphaHistBin * 1000 + cotbetaHistBin * 10 + qbinBin;
578 for (
unsigned cotalphaHistBin=1; cotalphaHistBin<=
rescotAlpha_binN; ++cotalphaHistBin )
579 for (
unsigned cotbetaHistBin=1; cotbetaHistBin<=
rescotBeta_binN; ++cotbetaHistBin )
581 unsigned int SingleBigPixelHistN = 100000 + cotalphaHistBin * 100 + cotbetaHistBin;
586 unsigned int SinglePixelHistN = 100000 + 1000 + cotalphaHistBin * 100 + cotbetaHistBin;
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
T getParameter(std::string const &) const
SiPixelGaussianSmearingRecHitConverterAlgorithm(const edm::ParameterSet &pset, GeomDetType::SubDetector pixelPart, const RandomEngine *engine)
double rescotAlpha_binMin
bool isFlipped(const PixelGeomDetUnit *theDet) const
std::string thePixelResolutionFileName2
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])
const RandomEngine * random
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
double flatShoot(double xmin=0.0, double xmax=1.0) const
virtual ~SiPixelGaussianSmearingRecHitConverterAlgorithm()
void smearHit(const PSimHit &simHit, const PixelGeomDetUnit *detUnit, const double boundX, const double boundY)
TFile * thePixelResolutionFile1
TFile * thePixelResolutionFile2