16 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
26 #include "Math/DistFunc.h"
31 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
35 #define LOGERROR(x) edm::LogError(x)
36 #define LOGDEBUG(x) LogDebug(x)
45 #define LOGERROR(x) std::cout << x << ": "
46 #define LOGDEBUG(x) std::cout << x << ": "
47 #define ENDL std::endl
50 using namespace SiStripTemplateSplit;
77 float& xrec1,
float& xrec2,
float& sigmax,
float& prob2x,
int& q2bin,
float& prob2Q)
81 int i,
j,
k, binq, binqerr, midpix;
82 int fxpix, nxpix, lxpix, logxpx, shiftx;
84 int nxbin, xcbin, minbinj, minbink;
85 int deltaj, jmin, jmax, kmin, kmax, km, fxbin, lxbin, djx;
86 float sxthr,
delta, sigma, pseudopix,
xsize, qscale;
87 float ss2, ssa, sa2, rat, fq, qtotal, qavg;
88 float originx, bias,
maxpix;
89 double chi2x, meanx, chi2xmin, chi21max;
91 double prvav, mpv, sigmaQ,
kappa, xvav, beta2;
95 const float sqrt2x={2.00000};
96 const float sqrt12={3.4641};
97 const float probmin={1.110223e-16};
98 const float prob2Qmin={1.e-5};
105 const double mean1pix={0.100}, chi21min={0.160};
110 if(!templ.
interpolate(
id, cotalpha, cotbeta, locBy)) {
111 LOGDEBUG(
"SiStripTemplateReco") <<
"input cluster direction cot(alpha) = " << cotalpha <<
", cot(beta) = " << cotbeta
112 <<
" is not within the acceptance of template ID = " <<
id <<
", no reconstruction performed" <<
ENDL;
118 xsize = templ.
xsize();
122 pseudopix = templ.
s50();
130 nclusx = (int)cluster.size();
137 for(i=0; i<
BSXSIZE; ++
i) {xsum[
i] = 0.f;}
138 maxpix = 2.f*templ.
sxmax();
139 for(j=0; j<nclusx; ++
j) {
140 xsum[
j] = qscale*cluster[
j];
142 if(xsum[j] > maxpix) {xsum[
j] =
maxpix;}
153 if(fxpix == -1) {fxpix =
i;}
165 if((lxpix-fxpix+1) != nxpix) {
167 LOGDEBUG(
"SiStripTemplateReco") <<
"x-length of pixel cluster doesn't agree with number of pixels above threshold" <<
ENDL;
169 LOGDEBUG(
"SiStripTemplateReco") <<
"xsum[] = ";
170 for(i=0; i<BSXSIZE-1; ++
i) {
LOGDEBUG(
"SiStripTemplateReco") << xsum[
i] <<
", ";}
181 LOGDEBUG(
"SiStripTemplateReco") <<
"x-length of pixel cluster is larger than maximum template size" <<
ENDL;
183 LOGDEBUG(
"SiStripTemplateReco") <<
"xsum[] = ";
184 for(i=0; i<BSXSIZE-1; ++
i) {
LOGDEBUG(
"SiStripTemplateReco") << xsum[
i] <<
", ";}
193 midpix = (fxpix+lxpix)/2;
194 shiftx = templ.
cxtemp() - midpix;
196 for(i=lxpix; i>=fxpix; --
i) {
197 xsum[i+shiftx] = xsum[
i];
200 }
else if (shiftx < 0) {
201 for(i=fxpix; i<=lxpix; ++
i) {
202 xsum[i+shiftx] = xsum[
i];
211 if(fxpix > 1 && fxpix <
BSXM2) {
212 xsum[fxpix-1] = pseudopix;
213 xsum[fxpix-2] = 0.2f*pseudopix;
215 if(lxpix > 1 && lxpix <
BSXM2) {
216 xsum[lxpix+1] = pseudopix;
217 xsum[lxpix+2] = 0.2f*pseudopix;
245 if(qtotal < 1.9
f*templ.
qmin()) {q2bin = 5;}
else {
246 if(qtotal < 1.9
f*templ.
qmin(1)) {q2bin = 4;}
251 " cot(alpha) = " << cotalpha <<
" cot(beta) = " << cotbeta <<
252 " nclusx = " << nclusx <<
ENDL;
258 if(binqerr > 2) binqerr = 2;
264 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
265 if((sigmaQ <=0.) || (mpv <= 0.) || (kappa < 0.01) || (kappa > 9.9)) {
266 throw cms::Exception(
"DataCorrupt") <<
"SiStripTemplateSplit::Vavilov parameters mpv/sigmaQ/kappa = " << mpv <<
"/" << sigmaQ <<
"/" << kappa << std::endl;
269 assert((sigmaQ > 0.) && (mpv > 0.) && (kappa > 0.01) && (kappa < 10.));
271 xvav = ((double)qtotal-mpv)/sigmaQ;
275 prvav = vvidist.
fcn(xvav);
277 if(prob2Q < prob2Qmin) {prob2Q = prob2Qmin;}
293 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
294 if(speed < -1 || speed > 2) {
295 throw cms::Exception(
"DataCorrupt") <<
"SiStripTemplateReco::PixelTempReco2D called with illegal speed = " << speed << std::endl;
298 assert(speed >= -1 && speed < 3);
300 fxbin = 0; lxbin = nxbin-1; djx = 1;
303 if(speed > 1) {djx = 4;}
313 templ.
xsigma2(fxpix, lxpix, sxthr, xsum, xsig2);
319 for(i=fxpix-2; i<=lxpix+2; ++
i) {
320 xw2[
i] = 1.f/xsig2[
i];
321 xsw[
i] = xsum[
i]*xw2[
i];
322 ss2 += xsum[
i]*xsw[
i];
331 std::vector<float> xtemp(BSXSIZE);
333 for(j=jmin; j<jmax; j+=deltaj) {
335 for(k=kmin; k<=km; k+=deltaj) {
343 for(i=fxpix-2; i<=lxpix+2; ++
i) {
344 ssa += xsw[
i]*xtemp[
i];
345 sa2 += xtemp[
i]*xtemp[
i]*xw2[
i];
348 if(rat <= 0.
f) {
LOGERROR(
"SiStripTemplateSplit") <<
"illegal chi2xmin normalization = " << rat <<
ENDL; rat = 1.;}
349 chi2x=ss2-2.f*ssa/rat+sa2/(rat*rat);
350 if(chi2x < chi2xmin) {
358 if(minbinj > fxbin) {jmin = minbinj - deltaj;}
else {jmin = fxbin;}
359 if(minbinj < lxbin) {jmax = minbinj + deltaj;}
else {jmax = lxbin;}
360 if(minbink > fxbin) {kmin = minbink - deltaj;}
else {kmin = fxbin;}
361 if(minbink < lxbin) {kmax = minbink + deltaj;}
else {kmax = lxbin;}
366 "minbinj/minbink " << minbinj<<
"/" << minbink <<
" chi2xmin = " << chi2xmin <<
ENDL;
373 delta = templ.
dxone();
374 sigma = templ.
sxone();
375 xrec1 = 0.5f*(fxpix+lxpix-2*shiftx+2.f*originx)*xsize-delta;
378 sigmax = xsize/sqrt12;
385 chi21max = fmax(chi21min, (
double)templ.
chi2xminone());
387 if(chi2xmin < 0.) {chi2xmin = 0.;}
388 meanx = fmax(mean1pix, (
double)templ.
chi2xavgone());
389 hchi2 = chi2xmin/2.; hndof = meanx/2.;
400 xrec1 = (0.125f*(minbink-xcbin)+
BSHX-(
float)shiftx+originx)*xsize - bias;
401 xrec2 = (0.125f*(minbinj-xcbin)+
BSHX-(
float)shiftx+originx)*xsize - bias;
402 sigmax = sqrt2x*templ.
xrmsc2m(binqerr);
407 if(chi2xmin < 0.0) {chi2xmin = 0.0;}
409 if(meanx < 0.01) {meanx = 0.01;}
410 hchi2 = chi2xmin/2.; hndof = meanx/2.;
416 if(prob2x < probmin) {prob2x = probmin;}
442 float& xrec1,
float& xrec2,
float& sigmax,
float& prob2x,
int& q2bin,
float& prob2Q)
448 return SiStripTemplateSplit::StripTempSplit(
id, cotalpha, cotbeta, locBy, speed, cluster, templ, xrec1, xrec2, sigmax, prob2x, q2bin, prob2Q);
float xavgc2m(int i)
1st pass chi2 min search: average x-bias of reconstruction binned in 4 charge bins ...
float chi2xavgc2m(int i)
1st pass chi2 min search: average x-chisq for merged clusters
void vavilov2_pars(double &mpv, double &sigma, double &kappa)
float xsize()
strip x-size (microns)
void xtemp3d(int j, int k, std::vector< float > &xtemplate)
void xsigma2(int fxstrp, int lxstrp, float sxthr, float xsum[17+4], float xsig2[17+4])
float qavg()
average cluster charge for this set of track angles
float chi2xminone()
//!< minimum of x chi^2 for 1 strip clusters
float qmin()
minimum cluster charge for valid hit (keeps 99.9% of simulated hits)
double fcn(double x) const
static int theVerboseLevel
void xtemp3d_int(int nxpix, int &nxbins)
int cxtemp()
Return central pixel of x-template pixels above readout threshold.
float dxone()
mean offset/correction for one strip x-clusters
float qscale()
charge scaling factor
float chi2xavgone()
//!< average x chi^2 for 1 strip clusters
float s50()
1/2 of the strip threshold signal in electrons
float xrmsc2m(int i)
1st pass chi2 min search: average x-rms of reconstruction binned in 4 charge bins ...
float sxone()
rms for one strip x-clusters
int StripTempSplit(int id, float cotalpha, float cotbeta, float locBy, int speed, std::vector< float > &cluster, SiStripTemplate &templ, float &xrec1, float &xrec2, float &sigmax, float &prob2x, int &q2bin, float &prob2Q)
float sxmax()
average strip signal for x-projection of cluster
static const G4double kappa
bool interpolate(int id, float cotalpha, float cotbeta, float locBy)