13 #ifndef SI_PIXEL_TEMPLATE_STANDALONE 29 #ifndef SI_PIXEL_TEMPLATE_STANDALONE 33 #define LOGERROR(x) LogError(x) 34 #define LOGWARNING(x) LogWarning(x) 35 #define LOGINFO(x) LogInfo(x) 41 #define LOGERROR(x) std::cout << x << ": " 42 #define LOGINFO(x) std::cout << x << ": " 43 #define LOGWARNING(x) std::cout << x << ": " 44 #define ENDL std::endl 59 float costrk[3]={0,0,0};
63 const int code_version={1};
69 std::ostringstream tout;
73 #ifndef SI_PIXEL_TEMPLATE_STANDALONE 74 tout <<
"CalibTracker/SiPixelESProducers/data/generror_summary_zp" 75 << std::setw(4) << std::setfill(
'0') << std::right << filenum <<
".out" << std::ends;
78 tempfile = (
file.fullPath()).c_str();
80 tout <<
"generror_summary_zp" << std::setw(4) << std::setfill(
'0') << std::right << filenum <<
".out" << std::ends;
82 tempfile = tempf.c_str();
89 if(in_file.is_open()) {
97 for (i=0; (c=in_file.get()) !=
'\n'; ++
i) {
102 LOGINFO(
"SiPixelGenError") <<
"Loading Pixel GenError File - " << theCurrentTemp.
head.
title <<
ENDL;
112 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file, no GenError load" <<
ENDL;
return false;}
115 <<
", NTy = " << theCurrentTemp.
head.
NTy <<
", NTyx = " << theCurrentTemp.
head.
NTyx<<
", NTxx = " << theCurrentTemp.
head.
NTxx <<
", Dtype = " << theCurrentTemp.
head.
Dtype 116 <<
", Bias voltage " << theCurrentTemp.
head.
Vbias <<
", temperature " 118 <<
", 1/2 multi dcol threshold " << theCurrentTemp.
head.
s50 <<
", 1/2 single dcol threshold " << theCurrentTemp.
head.
ss50 121 <<
", Q/Q_avg fractions for Qbin defs " << theCurrentTemp.
head.
fbin[0] <<
", " << theCurrentTemp.
head.
fbin[1]
122 <<
", " << theCurrentTemp.
head.
fbin[2]
125 if(theCurrentTemp.
head.
templ_version < code_version) {
LOGERROR(
"SiPixelGenError") <<
"code expects version " << code_version <<
", no GenError load" <<
ENDL;
return false;}
127 #ifdef SI_PIXEL_TEMPLATE_USE_BOOST 131 theCurrentTemp.
enty.resize(boost::extents[theCurrentTemp.
head.
NTy]);
139 for (i=0; i < theCurrentTemp.
head.
NTy; ++
i) {
141 in_file >> theCurrentTemp.
enty[
i].
runnum >> costrk[0] >> costrk[1] >> costrk[2];
143 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 1, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
154 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 2, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
159 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 3, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
161 if(theCurrentTemp.
enty[i].
qmin <= 0.) {
LOGERROR(
"SiPixelGenError") <<
"Error in GenError ID " << theCurrentTemp.
head.
ID <<
" qmin = " << theCurrentTemp.
enty[
i].
qmin <<
", run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
164 for (j=0; j<4; ++j) {
168 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 14a, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
176 for (k=0; k < theCurrentTemp.
head.
NTyx; ++
k) {
178 for (i=0; i < theCurrentTemp.
head.
NTxx; ++
i) {
180 in_file >> theCurrentTemp.
entx[
k][
i].
runnum >> costrk[0] >> costrk[1] >> costrk[2];
182 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 17, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
193 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 18, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
199 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 19, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
202 for (j=0; j<4; ++j) {
206 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 30a, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
217 thePixelTemp_.push_back(theCurrentTemp);
219 postInit(thePixelTemp_);
227 LOGERROR(
"SiPixelGenError") <<
"Error opening File" << tempfile <<
ENDL;
235 #ifndef SI_PIXEL_TEMPLATE_STANDALONE 243 std::vector< SiPixelGenErrorStore > & thePixelTemp_) {
248 float costrk[3]={0,0,0};
250 const int code_version={1};
264 for (i=0; i<20; ++
i) {
274 LOGINFO(
"SiPixelGenError") <<
"Loading Pixel GenError File - " 286 <<
"Error reading file, no GenError load" <<
ENDL;
return false;}
289 <<
", NTy = " << theCurrentTemp.
head.
NTy <<
", NTyx = " << theCurrentTemp.
head.
NTyx<<
", NTxx = " << theCurrentTemp.
head.
NTxx <<
", Dtype = " << theCurrentTemp.
head.
Dtype 290 <<
", Bias voltage " << theCurrentTemp.
head.
Vbias <<
", temperature " 292 <<
", 1/2 multi dcol threshold " << theCurrentTemp.
head.
s50 <<
", 1/2 single dcol threshold " << theCurrentTemp.
head.
ss50 295 <<
", Q/Q_avg fractions for Qbin defs " << theCurrentTemp.
head.
fbin[0] <<
", " << theCurrentTemp.
head.
fbin[1]
296 <<
", " << theCurrentTemp.
head.
fbin[2]
299 LOGINFO(
"SiPixelGenError") <<
"Loading Pixel GenError - " 300 << theCurrentTemp.
head.
title <<
" version " 302 <<code_version<<
ENDL;
304 LOGERROR(
"SiPixelGenError") <<
"code expects version " << code_version
305 <<
", no GenError load" <<
ENDL;
return false;}
307 #ifdef SI_PIXEL_TEMPLATE_USE_BOOST 311 theCurrentTemp.
enty.resize(boost::extents[theCurrentTemp.
head.
NTy]);
319 for (i=0; i < theCurrentTemp.
head.
NTy; ++
i) {
321 db >> theCurrentTemp.
enty[
i].
runnum >> costrk[0] >> costrk[1] >> costrk[2];
323 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 1, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
334 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 2, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
339 for (j=0; j<4; ++j) {
343 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 14a, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
350 for (k=0; k < theCurrentTemp.
head.
NTyx; ++
k) {
352 for (i=0; i < theCurrentTemp.
head.
NTxx; ++
i) {
354 db >> theCurrentTemp.
entx[
k][
i].
runnum >> costrk[0] >> costrk[1] >> costrk[2];
356 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 17, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
367 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 18, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
372 for (j=0; j<4; ++j) {
376 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 30a, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
385 thePixelTemp_.push_back(theCurrentTemp);
387 postInit(thePixelTemp_);
398 for (
auto & templ : thePixelTemp_) {
399 for (
auto iy=0; iy<templ.head.NTy; ++iy ) templ.cotbetaY[iy]=templ.enty[iy].cotbeta;
400 for (
auto iy=0; iy<templ.head.NTyx; ++iy ) templ.cotbetaX[iy]= templ.entx[iy][0].cotbeta;
401 for (
auto ix=0; ix<templ.head.NTxx; ++ix ) templ.cotalphaX[ix]=templ.entx[0][ix].cotalpha;
436 if(
id != id_current_) {
439 for(
int i=0;
i<(
int)thePixelTemp_.size(); ++
i) {
440 if(
id == thePixelTemp_[
i].head.ID) {
444 lorywidth_ = thePixelTemp_[
i].head.lorywidth;
445 lorxwidth_ = thePixelTemp_[
i].head.lorxwidth;
446 lorybias_ = thePixelTemp_[
i].head.lorybias;
447 lorxbias_ = thePixelTemp_[
i].head.lorxbias;
452 xsize_ = thePixelTemp_[
i].head.xsize;
453 ysize_ = thePixelTemp_[
i].head.ysize;
454 zsize_ = thePixelTemp_[
i].head.zsize;
464 int SiPixelGenError::qbin(
int id,
float cotalpha,
float cotbeta,
float locBz,
float locBx,
float qclus,
bool irradiationCorrections,
465 int& pixmx,
float& sigmay,
float& deltay,
float& sigmax,
float& deltax,
466 float& sy1,
float& dy1,
float& sy2,
float& dy2,
float& sx1,
float& dx1,
467 float& sx2,
float& dx2)
475 if(
id != id_current_) {
478 for(
int i=0;
i<(
int)thePixelTemp_.size(); ++
i) {
479 if(
id == thePixelTemp_[
i].head.ID) {
482 lorywidth_ = thePixelTemp_[
i].head.lorywidth;
483 lorxwidth_ = thePixelTemp_[
i].head.lorxwidth;
484 lorybias_ = thePixelTemp_[
i].head.lorybias;
485 lorxbias_ = thePixelTemp_[
i].head.lorxbias;
486 for(
int j=0; j<3; ++j) {fbin_[j] = thePixelTemp_[
i].head.fbin[j];}
490 xsize_ = thePixelTemp_[
i].head.xsize;
491 ysize_ = thePixelTemp_[
i].head.ysize;
492 zsize_ = thePixelTemp_[
i].head.zsize;
499 int index = index_id_;
501 #ifndef SI_PIXEL_TEMPLATE_STANDALONE 502 if(index < 0 || index >= (
int)thePixelTemp_.size()) {
503 throw cms::Exception(
"DataCorrupt") <<
"SiPixelGenError::qbin can't find needed GenError ID = " <<
id << std::endl;
506 assert(index >= 0 && index < (
int)thePixelTemp_.size());
512 auto const & templ = thePixelTemp_[
index];
520 auto cotalpha0 = thePixelTemp_[
index].enty[0].cotalpha;
521 auto qcorrect=
std::sqrt((1.
f+cotbeta*cotbeta+cotalpha*cotalpha)/(1.
f+cotbeta*cotbeta+cotalpha0*cotalpha0));
525 float cota = cotalpha;
527 bool flip_y;
bool flip_x;
531 switch(thePixelTemp_[index_id_].head.Dtype) {
533 if(cotbeta < 0.
f) {flip_y =
true;}
546 if(locBx*locBz < 0.
f) {
558 #ifndef SI_PIXEL_TEMPLATE_STANDALONE 559 throw cms::Exception(
"DataCorrupt") <<
"SiPixelTemplate::illegal subdetector ID = " << thePixelTemp_[index_id_].head.Dtype << std::endl;
561 std::cout <<
"SiPixelTemplate::illegal subdetector ID = " << thePixelTemp_[index_id_].head.Dtype << std::endl;
568 lorybias_ = -lorybias_;
569 lorywidth_ = -lorywidth_;
572 lorxbias_ = -lorxbias_;
573 lorxwidth_ = -lorxwidth_;
577 auto qscale = thePixelTemp_[
index].head.qscale;
587 auto Ny = thePixelTemp_[
index].head.NTy;
588 auto Nyx = thePixelTemp_[
index].head.NTyx;
589 auto Nxx = thePixelTemp_[
index].head.NTxx;
591 #ifndef SI_PIXEL_TEMPLATE_STANDALONE 592 if(Ny < 2 || Nyx < 1 || Nxx < 2) {
593 throw cms::Exception(
"DataCorrupt") <<
"GenError ID = " << id_current_ <<
"has too few entries: Ny/Nyx/Nxx = " << Ny <<
"/" << Nyx <<
"/" << Nxx << std::endl;
596 assert(Ny > 1 && Nyx > 0 && Nxx > 1);
606 auto j = std::lower_bound(templ.cotbetaY,templ.cotbetaY+Ny,cotb);
607 if (j==templ.cotbetaY+Ny) { --j; yratio = 1.f; }
608 else if (j==templ.cotbetaY) { ++j; yratio = 0.f;}
609 else { yratio = (cotb - (*(j-1)) )/( (*j) - (*(j-1)) ) ; }
611 ihigh = j-templ.cotbetaY;
619 auto qavg = (1.f - yratio)*thePixelTemp_[index].enty[ilow].qavg + yratio*thePixelTemp_[index].enty[ihigh].qavg;
621 auto qmin = (1.f - yratio)*thePixelTemp_[index].enty[ilow].qmin + yratio*thePixelTemp_[index].enty[ihigh].qmin;
623 auto qmin2 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].qmin2 + yratio*thePixelTemp_[index].enty[ihigh].qmin2;
627 #ifndef SI_PIXEL_TEMPLATE_STANDALONE 628 if(qavg <= 0.
f || qmin <= 0.
f) {
629 throw cms::Exception(
"DataCorrupt") <<
"SiPixelGenError::qbin, qavg or qmin <= 0," 630 <<
" Probably someone called the generic pixel reconstruction with an illegal trajectory state" << std::endl;
633 assert(qavg > 0.
f && qmin > 0.
f);
638 auto qtotal = qscale*qclus;
642 auto fq = qtotal/qavg;
658 auto yrmsgen =(1.f - yratio)*thePixelTemp_[index].enty[ilow].yrmsgen[binq] + yratio*thePixelTemp_[index].enty[ihigh].yrmsgen[binq];
659 sy1 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].syone + yratio*thePixelTemp_[index].enty[ihigh].syone;
660 sy2 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].sytwo + yratio*thePixelTemp_[index].enty[ihigh].sytwo;
671 auto j = std::lower_bound(templ.cotbetaX,templ.cotbetaX+Nyx,acotb);
672 if (j==templ.cotbetaX+Nyx) { --j; yxratio = 1.f; }
673 else if (j==templ.cotbetaX) { ++j; yxratio = 0.f;}
674 else { yxratio = (acotb - (*(j-1)) )/( (*j) - (*(j-1)) ) ; }
676 iyhigh = j-templ.cotbetaX;
686 auto j = std::lower_bound(templ.cotalphaX,templ.cotalphaX+Nxx,cotalpha);
687 if (j==templ.cotalphaX+Nxx) { --j; xxratio = 1.f; }
688 else if (j==templ.cotalphaX) { ++j; xxratio = 0.f;}
689 else { xxratio = (cota - (*(j-1)) )/( (*j) - (*(j-1)) ) ; }
691 ihigh = j-templ.cotalphaX;
697 sx1 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].sxone + xxratio*thePixelTemp_[index].entx[0][ihigh].sxone;
698 sx2 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].sxtwo + xxratio*thePixelTemp_[index].entx[0][ihigh].sxtwo;
702 pixmx=(1.f - yxratio)*((1.
f - xxratio)*thePixelTemp_[
index].entx[iylow][ilow].pixmax + xxratio*thePixelTemp_[
index].entx[iylow][ihigh].pixmax)
703 +yxratio*((1.
f - xxratio)*thePixelTemp_[
index].entx[iyhigh][ilow].pixmax + xxratio*thePixelTemp_[
index].entx[iyhigh][ihigh].pixmax);
705 auto xrmsgen = (1.f - yxratio)*((1.
f - xxratio)*thePixelTemp_[
index].entx[iylow][ilow].xrmsgen[binq] + xxratio*thePixelTemp_[
index].entx[iylow][ihigh].xrmsgen[binq])
706 +yxratio*((1.
f - xxratio)*thePixelTemp_[
index].entx[iyhigh][ilow].xrmsgen[binq] + xxratio*thePixelTemp_[
index].entx[iyhigh][ihigh].xrmsgen[binq]);
709 if(irradiationCorrections) {
710 auto yavggen =(1.f - yratio)*thePixelTemp_[index].enty[ilow].yavggen[binq] + yratio*thePixelTemp_[index].enty[ihigh].yavggen[binq];
711 if(flip_y) {yavggen = -yavggen;}
713 dy1 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].dyone + yratio*thePixelTemp_[index].enty[ihigh].dyone;
714 if(flip_y) {dy1 = -dy1;}
715 dy2 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].dytwo + yratio*thePixelTemp_[index].enty[ihigh].dytwo;
716 if(flip_y) {dy2 = -dy2;}
718 auto xavggen = (1.f - yxratio)*((1.
f - xxratio)*thePixelTemp_[
index].entx[iylow][ilow].xavggen[binq] + xxratio*thePixelTemp_[
index].entx[iylow][ihigh].xavggen[binq])
719 +yxratio*((1.
f - xxratio)*thePixelTemp_[
index].entx[iyhigh][ilow].xavggen[binq] + xxratio*thePixelTemp_[
index].entx[iyhigh][ihigh].xavggen[binq]);
720 if(flip_x) {xavggen = -xavggen;}
722 dx1 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].dxone + xxratio*thePixelTemp_[index].entx[0][ihigh].dxone;
723 if(flip_x) {dx1 = -dx1;}
724 dx2 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].dxtwo + xxratio*thePixelTemp_[index].entx[0][ihigh].dxtwo;
725 if(flip_x) {dx2 = -dx2;}
737 if(qtotal < 0.95
f*qmin) {binq = 5;}
else {
if(qtotal < 0.95
f*qmin2) {binq = 4;}}
float qavg
average cluster charge for this set of track angles (now includes threshold effects) ...
float qmin
minimum cluster charge for valid hit (keeps 99.9% of simulated hits)
int runnum
< Basic template entry corresponding to a single set of track angles
float yrmsgen[4]
generic algorithm: average y-rms of reconstruction binned in 4 charge bins
float dxone
mean offset/correction for one pixel x-clusters
float xrmsgen[4]
generic algorithm: average x-rms of reconstruction binned in 4 charge bins
float syone
rms for one pixel y-clusters
SiPixelGenErrorEntry enty[60]
60 Barrel y templates spanning cluster lengths from 0px to +18px [28 entries for fpix] ...
float cotalpha
cot(alpha) is proportional to cluster length in x and is basis of interpolation
int qbin(int id, float cotalpha, float cotbeta, float locBz, float locBx, float qclus, bool irradiationCorrections, int &pixmx, float &sigmay, float &deltay, float &sigmax, float &deltax, float &sy1, float &dy1, float &sy2, float &dy2, float &sx1, float &dx1, float &sx2, float &dx2)
static void postInit(std::vector< SiPixelGenErrorStore > &thePixelTemp_)
float cotbeta
cot(beta) is proportional to cluster length in y and is basis of interpolation
std::vector< float > sVector() const
float sxone
rms for one pixel x-clusters
Abs< T >::type abs(const T &t)
float dytwo
mean offset/correction for one double-pixel y-clusters
float dxtwo
mean offset/correction for one double-pixel x-clusters
SiPixelGenErrorHeader head
< template storage structure
void incrementIndex(int i)
float sytwo
rms for one double-pixel y-clusters
float yavggen[4]
generic algorithm: average y-bias of reconstruction binned in 4 charge bins
float dyone
mean offset/correction for one pixel y-clusters
float xavggen[4]
generic algorithm: average x-bias of reconstruction binned in 4 charge bins
static bool pushfile(int filenum, std::vector< SiPixelGenErrorStore > &thePixelTemp_)
float pixmax
maximum charge for individual pixels in cluster
float sxtwo
rms for one double-pixel x-clusters
SiPixelGenErrorEntry entx[5][29]
29 Barrel x templates spanning cluster lengths from -6px (-1.125Rad) to +6px (+1.125Rad) in each of 5...