12 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
28 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
32 #define LOGERROR(x) LogError(x)
33 #define LOGINFO(x) LogInfo(x)
39 #define LOGERROR(x) std::cout << x << ": "
40 #define LOGINFO(x) std::cout << x << ": "
41 #define ENDL std::endl
56 float costrk[3]={0,0,0};
60 const int code_version={1};
66 std::ostringstream tout;
70 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
71 tout <<
"CalibTracker/SiPixelESProducers/data/generror_summary_zp"
72 << std::setw(4) << std::setfill(
'0') << std::right << filenum <<
".out" << std::ends;
75 tempfile = (
file.fullPath()).c_str();
77 tout <<
"generror_summary_zp" << std::setw(4) << std::setfill(
'0') << std::right << filenum <<
".out" << std::ends;
79 tempfile = tempf.c_str();
86 if(in_file.is_open()) {
94 for (i=0; (c=in_file.get()) !=
'\n'; ++
i) {
99 LOGINFO(
"SiPixelGenError") <<
"Loading Pixel GenError File - " << theCurrentTemp.
head.
title <<
ENDL;
109 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file, no GenError load" <<
ENDL;
return false;}
112 <<
", NTy = " << theCurrentTemp.
head.
NTy <<
", NTyx = " << theCurrentTemp.
head.
NTyx<<
", NTxx = " << theCurrentTemp.
head.
NTxx <<
", Dtype = " << theCurrentTemp.
head.
Dtype
113 <<
", Bias voltage " << theCurrentTemp.
head.
Vbias <<
", temperature "
115 <<
", 1/2 multi dcol threshold " << theCurrentTemp.
head.
s50 <<
", 1/2 single dcol threshold " << theCurrentTemp.
head.
ss50
118 <<
", Q/Q_avg fractions for Qbin defs " << theCurrentTemp.
head.
fbin[0] <<
", " << theCurrentTemp.
head.
fbin[1]
119 <<
", " << theCurrentTemp.
head.
fbin[2]
122 if(theCurrentTemp.
head.
templ_version < code_version) {
LOGERROR(
"SiPixelGenError") <<
"code expects version " << code_version <<
", no GenError load" <<
ENDL;
return false;}
124 #ifdef SI_PIXEL_TEMPLATE_USE_BOOST
128 theCurrentTemp.
enty.resize(boost::extents[theCurrentTemp.
head.
NTy]);
136 for (i=0; i < theCurrentTemp.
head.
NTy; ++
i) {
138 in_file >> theCurrentTemp.
enty[
i].
runnum >> costrk[0] >> costrk[1] >> costrk[2];
140 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 1, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
151 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 2, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
156 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 3, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
158 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;}
161 for (j=0; j<4; ++
j) {
165 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 14a, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
173 for (k=0; k < theCurrentTemp.
head.
NTyx; ++
k) {
175 for (i=0; i < theCurrentTemp.
head.
NTxx; ++
i) {
177 in_file >> theCurrentTemp.
entx[
k][
i].
runnum >> costrk[0] >> costrk[1] >> costrk[2];
179 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 17, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
190 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 18, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
196 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 19, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
199 for (j=0; j<4; ++
j) {
203 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 30a, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
214 thePixelTemp_.push_back(theCurrentTemp);
216 postInit(thePixelTemp_);
224 LOGERROR(
"SiPixelGenError") <<
"Error opening File" << tempfile <<
ENDL;
232 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
245 float costrk[3]={0,0,0};
247 const int code_version={1};
262 for (i=0; i<20; ++
i) {
271 LOGINFO(
"SiPixelGenError") <<
"Loading Pixel GenError File - " << theCurrentTemp.
head.
title <<
ENDL;
282 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file, no GenError load" <<
ENDL;
return false;}
285 <<
", NTy = " << theCurrentTemp.
head.
NTy <<
", NTyx = " << theCurrentTemp.
head.
NTyx<<
", NTxx = " << theCurrentTemp.
head.
NTxx <<
", Dtype = " << theCurrentTemp.
head.
Dtype
286 <<
", Bias voltage " << theCurrentTemp.
head.
Vbias <<
", temperature "
288 <<
", 1/2 multi dcol threshold " << theCurrentTemp.
head.
s50 <<
", 1/2 single dcol threshold " << theCurrentTemp.
head.
ss50
291 <<
", Q/Q_avg fractions for Qbin defs " << theCurrentTemp.
head.
fbin[0] <<
", " << theCurrentTemp.
head.
fbin[1]
292 <<
", " << theCurrentTemp.
head.
fbin[2]
295 if(theCurrentTemp.
head.
templ_version < code_version) {
LOGERROR(
"SiPixelGenError") <<
"code expects version " << code_version <<
", no GenError load" <<
ENDL;
return false;}
298 #ifdef SI_PIXEL_TEMPLATE_USE_BOOST
302 theCurrentTemp.
enty.resize(boost::extents[theCurrentTemp.
head.
NTy]);
310 for (i=0; i < theCurrentTemp.
head.
NTy; ++
i) {
312 db >> theCurrentTemp.
enty[
i].
runnum >> costrk[0] >> costrk[1] >> costrk[2];
314 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 1, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
325 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 2, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
330 for (j=0; j<4; ++
j) {
334 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 14a, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
341 for (k=0; k < theCurrentTemp.
head.
NTyx; ++
k) {
343 for (i=0; i < theCurrentTemp.
head.
NTxx; ++
i) {
345 db >> theCurrentTemp.
entx[
k][
i].
runnum >> costrk[0] >> costrk[1] >> costrk[2];
347 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 17, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
358 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 18, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
363 for (j=0; j<4; ++
j) {
367 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 30a, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
376 thePixelTemp_.push_back(theCurrentTemp);
378 postInit(thePixelTemp_);
391 for (
auto & templ : thePixelTemp_) {
392 for (
auto iy=0; iy<templ.head.NTy; ++iy ) templ.cotbetaY[iy]=templ.enty[iy].cotbeta;
393 for (
auto iy=0; iy<templ.head.NTyx; ++iy ) templ.cotbetaX[iy]= templ.entx[iy][0].cotbeta;
394 for (
auto ix=0; ix<templ.head.NTxx; ++ix ) templ.cotalphaX[ix]=templ.entx[0][ix].cotalpha;
429 if(
id != id_current_) {
432 for(
int i=0;
i<(int)thePixelTemp_.size(); ++
i) {
433 if(
id == thePixelTemp_[
i].head.ID) {
437 lorywidth_ = thePixelTemp_[
i].head.lorywidth;
438 lorxwidth_ = thePixelTemp_[
i].head.lorxwidth;
439 lorybias_ = thePixelTemp_[
i].head.lorybias;
440 lorxbias_ = thePixelTemp_[
i].head.lorxbias;
445 xsize_ = thePixelTemp_[
i].head.xsize;
446 ysize_ = thePixelTemp_[
i].head.ysize;
447 zsize_ = thePixelTemp_[
i].head.zsize;
458 float& pixmx,
float& sigmay,
float& deltay,
float& sigmax,
float& deltax,
459 float& sy1,
float& dy1,
float& sy2,
float& dy2,
float& sx1,
float& dx1,
460 float& sx2,
float& dx2)
468 if(
id != id_current_) {
471 for(
int i=0;
i<(int)thePixelTemp_.size(); ++
i) {
472 if(
id == thePixelTemp_[
i].head.ID) {
475 lorywidth_ = thePixelTemp_[
i].head.lorywidth;
476 lorxwidth_ = thePixelTemp_[
i].head.lorxwidth;
477 lorybias_ = thePixelTemp_[
i].head.lorybias;
478 lorxbias_ = thePixelTemp_[
i].head.lorxbias;
479 for(
int j=0;
j<3; ++
j) {fbin_[
j] = thePixelTemp_[
i].head.fbin[
j];}
483 xsize_ = thePixelTemp_[
i].head.xsize;
484 ysize_ = thePixelTemp_[
i].head.ysize;
485 zsize_ = thePixelTemp_[
i].head.zsize;
492 int index = index_id_;
494 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
495 if(index < 0 || index >= (
int)thePixelTemp_.size()) {
496 throw cms::Exception(
"DataCorrupt") <<
"SiPixelGenError::qbin can't find needed GenError ID = " <<
id << std::endl;
499 assert(index >= 0 && index < (
int)thePixelTemp_.size());
505 auto const & templ = thePixelTemp_[
index];
513 auto cotalpha0 = thePixelTemp_[
index].enty[0].cotalpha;
514 auto qcorrect=
std::sqrt((1.
f+cotbeta*cotbeta+cotalpha*cotalpha)/(1.
f+cotbeta*cotbeta+cotalpha0*cotalpha0));
518 float cotb;
bool flip_y;
519 if(thePixelTemp_[index].head.Dtype == 0) {
522 if(cotbeta < 0.
f) {flip_y =
true;}
535 auto qscale = thePixelTemp_[
index].head.qscale;
545 auto Ny = thePixelTemp_[
index].head.NTy;
546 auto Nyx = thePixelTemp_[
index].head.NTyx;
547 auto Nxx = thePixelTemp_[
index].head.NTxx;
549 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
550 if(Ny < 2 || Nyx < 1 || Nxx < 2) {
551 throw cms::Exception(
"DataCorrupt") <<
"GenError ID = " << id_current_ <<
"has too few entries: Ny/Nyx/Nxx = " << Ny <<
"/" << Nyx <<
"/" << Nxx << std::endl;
554 assert(Ny > 1 && Nyx > 0 && Nxx > 1);
564 auto j = std::lower_bound(templ.cotbetaY,templ.cotbetaY+Ny,cotb);
565 if (
j==templ.cotbetaY+Ny) { --
j; yratio = 1.f; }
566 else if (
j==templ.cotbetaY) { ++
j; yratio = 0.f;}
567 else { yratio = (cotb - (*(
j-1)) )/( (*
j) - (*(
j-1)) ) ; }
569 ihigh =
j-templ.cotbetaY;
577 dy1 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].dyone + yratio*thePixelTemp_[index].enty[ihigh].dyone;
578 if(flip_y) {dy1 = -dy1;}
579 sy1 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].syone + yratio*thePixelTemp_[index].enty[ihigh].syone;
580 dy2 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].dytwo + yratio*thePixelTemp_[index].enty[ihigh].dytwo;
581 if(flip_y) {dy2 = -dy2;}
582 sy2 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].sytwo + yratio*thePixelTemp_[index].enty[ihigh].sytwo;
584 auto qavg = (1.f - yratio)*thePixelTemp_[index].enty[ilow].qavg + yratio*thePixelTemp_[index].enty[ihigh].qavg;
586 auto qmin = (1.f - yratio)*thePixelTemp_[index].enty[ilow].qmin + yratio*thePixelTemp_[index].enty[ihigh].qmin;
588 auto qmin2 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].qmin2 + yratio*thePixelTemp_[index].enty[ihigh].qmin2;
592 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
593 if(qavg <= 0.
f || qmin <= 0.
f) {
594 throw cms::Exception(
"DataCorrupt") <<
"SiPixelGenError::qbin, qavg or qmin <= 0,"
595 <<
" Probably someone called the generic pixel reconstruction with an illegal trajectory state" << std::endl;
598 assert(qavg > 0.
f && qmin > 0.
f);
603 auto qtotal = qscale*qclus;
607 auto fq = qtotal/qavg;
623 auto yavggen =(1.f - yratio)*thePixelTemp_[index].enty[ilow].yavggen[binq] + yratio*thePixelTemp_[index].enty[ihigh].yavggen[binq];
624 if(flip_y) {yavggen = -yavggen;}
625 auto yrmsgen =(1.f - yratio)*thePixelTemp_[index].enty[ilow].yrmsgen[binq] + yratio*thePixelTemp_[index].enty[ihigh].yrmsgen[binq];
636 auto j = std::lower_bound(templ.cotbetaX,templ.cotbetaX+Nyx,acotb);
637 if (
j==templ.cotbetaX+Nyx) { --
j; yxratio = 1.f; }
638 else if (
j==templ.cotbetaX) { ++
j; yxratio = 0.f;}
639 else { yxratio = (acotb - (*(
j-1)) )/( (*
j) - (*(
j-1)) ) ; }
641 iyhigh =
j-templ.cotbetaX;
651 auto j = std::lower_bound(templ.cotalphaX,templ.cotalphaX+Nxx,cotalpha);
652 if (
j==templ.cotalphaX+Nxx) { --
j; xxratio = 1.f; }
653 else if (
j==templ.cotalphaX) { ++
j; xxratio = 0.f;}
654 else { xxratio = (cotalpha - (*(
j-1)) )/( (*
j) - (*(
j-1)) ) ; }
656 ihigh =
j-templ.cotalphaX;
662 dx1 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].dxone + xxratio*thePixelTemp_[index].entx[0][ihigh].dxone;
663 sx1 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].sxone + xxratio*thePixelTemp_[index].entx[0][ihigh].sxone;
664 dx2 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].dxtwo + xxratio*thePixelTemp_[index].entx[0][ihigh].dxtwo;
665 sx2 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].sxtwo + xxratio*thePixelTemp_[index].entx[0][ihigh].sxtwo;
669 pixmx=(1.f - yxratio)*((1.
f - xxratio)*thePixelTemp_[
index].entx[iylow][ilow].pixmax + xxratio*thePixelTemp_[
index].entx[iylow][ihigh].pixmax)
670 +yxratio*((1.
f - xxratio)*thePixelTemp_[
index].entx[iyhigh][ilow].pixmax + xxratio*thePixelTemp_[
index].entx[iyhigh][ihigh].pixmax);
672 auto xavggen = (1.f - yxratio)*((1.
f - xxratio)*thePixelTemp_[
index].entx[iylow][ilow].xavggen[binq] + xxratio*thePixelTemp_[
index].entx[iylow][ihigh].xavggen[binq])
673 +yxratio*((1.
f - xxratio)*thePixelTemp_[
index].entx[iyhigh][ilow].xavggen[binq] + xxratio*thePixelTemp_[
index].entx[iyhigh][ihigh].xavggen[binq]);
675 auto xrmsgen = (1.f - yxratio)*((1.
f - xxratio)*thePixelTemp_[
index].entx[iylow][ilow].xrmsgen[binq] + xxratio*thePixelTemp_[
index].entx[iylow][ihigh].xrmsgen[binq])
676 +yxratio*((1.
f - xxratio)*thePixelTemp_[
index].entx[iyhigh][ilow].xrmsgen[binq] + xxratio*thePixelTemp_[
index].entx[iyhigh][ihigh].xrmsgen[binq]);
682 sigmay = yrmsgen; deltay = yavggen;
684 sigmax = xrmsgen; deltax = xavggen;
688 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
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)
for(const auto &pset:thresholds)
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
int qbin(int id, float cotalpha, float cotbeta, float locBz, float qclus, float &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)
SiPixelGenErrorEntry entx[5][29]
29 Barrel x templates spanning cluster lengths from -6px (-1.125Rad) to +6px (+1.125Rad) in each of 5...