12 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
28 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
32 #define LOGERROR(x) LogError(x)
33 #define LOGWARNING(x) LogWarning(x)
34 #define LOGINFO(x) LogInfo(x)
40 #define LOGERROR(x) std::cout << x << ": "
41 #define LOGINFO(x) std::cout << x << ": "
42 #define LOGWARNING(x) std::cout << x << ": "
43 #define ENDL std::endl
58 float costrk[3]={0,0,0};
62 const int code_version={1};
68 std::ostringstream tout;
72 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
73 tout <<
"CalibTracker/SiPixelESProducers/data/generror_summary_zp"
74 << std::setw(4) << std::setfill(
'0') << std::right << filenum <<
".out" << std::ends;
77 tempfile = (
file.fullPath()).c_str();
79 tout <<
"generror_summary_zp" << std::setw(4) << std::setfill(
'0') << std::right << filenum <<
".out" << std::ends;
81 tempfile = tempf.c_str();
88 if(in_file.is_open()) {
96 for (i=0; (c=in_file.get()) !=
'\n'; ++
i) {
101 LOGINFO(
"SiPixelGenError") <<
"Loading Pixel GenError File - " << theCurrentTemp.
head.
title <<
ENDL;
111 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file, no GenError load" <<
ENDL;
return false;}
114 <<
", NTy = " << theCurrentTemp.
head.
NTy <<
", NTyx = " << theCurrentTemp.
head.
NTyx<<
", NTxx = " << theCurrentTemp.
head.
NTxx <<
", Dtype = " << theCurrentTemp.
head.
Dtype
115 <<
", Bias voltage " << theCurrentTemp.
head.
Vbias <<
", temperature "
117 <<
", 1/2 multi dcol threshold " << theCurrentTemp.
head.
s50 <<
", 1/2 single dcol threshold " << theCurrentTemp.
head.
ss50
120 <<
", Q/Q_avg fractions for Qbin defs " << theCurrentTemp.
head.
fbin[0] <<
", " << theCurrentTemp.
head.
fbin[1]
121 <<
", " << theCurrentTemp.
head.
fbin[2]
124 if(theCurrentTemp.
head.
templ_version < code_version) {
LOGERROR(
"SiPixelGenError") <<
"code expects version " << code_version <<
", no GenError load" <<
ENDL;
return false;}
126 #ifdef SI_PIXEL_TEMPLATE_USE_BOOST
130 theCurrentTemp.
enty.resize(boost::extents[theCurrentTemp.
head.
NTy]);
138 for (i=0; i < theCurrentTemp.
head.
NTy; ++
i) {
140 in_file >> theCurrentTemp.
enty[
i].
runnum >> costrk[0] >> costrk[1] >> costrk[2];
142 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 1, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
153 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 2, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
158 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 3, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
160 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;}
163 for (j=0; j<4; ++
j) {
167 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 14a, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
175 for (k=0; k < theCurrentTemp.
head.
NTyx; ++
k) {
177 for (i=0; i < theCurrentTemp.
head.
NTxx; ++
i) {
179 in_file >> theCurrentTemp.
entx[
k][
i].
runnum >> costrk[0] >> costrk[1] >> costrk[2];
181 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 17, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
192 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 18, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
198 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 19, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
201 for (j=0; j<4; ++
j) {
205 if(in_file.fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 30a, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
216 thePixelTemp_.push_back(theCurrentTemp);
218 postInit(thePixelTemp_);
226 LOGERROR(
"SiPixelGenError") <<
"Error opening File" << tempfile <<
ENDL;
234 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
242 std::vector< SiPixelGenErrorStore > & thePixelTemp_) {
247 float costrk[3]={0,0,0};
249 const int code_version={1};
263 for (i=0; i<20; ++
i) {
273 LOGINFO(
"SiPixelGenError") <<
"Loading Pixel GenError File - "
285 <<
"Error reading file, no GenError load" <<
ENDL;
return false;}
288 <<
", NTy = " << theCurrentTemp.
head.
NTy <<
", NTyx = " << theCurrentTemp.
head.
NTyx<<
", NTxx = " << theCurrentTemp.
head.
NTxx <<
", Dtype = " << theCurrentTemp.
head.
Dtype
289 <<
", Bias voltage " << theCurrentTemp.
head.
Vbias <<
", temperature "
291 <<
", 1/2 multi dcol threshold " << theCurrentTemp.
head.
s50 <<
", 1/2 single dcol threshold " << theCurrentTemp.
head.
ss50
294 <<
", Q/Q_avg fractions for Qbin defs " << theCurrentTemp.
head.
fbin[0] <<
", " << theCurrentTemp.
head.
fbin[1]
295 <<
", " << theCurrentTemp.
head.
fbin[2]
298 LOGINFO(
"SiPixelGenError") <<
"Loading Pixel GenError - "
299 << theCurrentTemp.
head.
title <<
" version "
301 <<code_version<<
ENDL;
303 LOGERROR(
"SiPixelGenError") <<
"code expects version " << code_version
304 <<
", no GenError load" <<
ENDL;
return false;}
306 #ifdef SI_PIXEL_TEMPLATE_USE_BOOST
310 theCurrentTemp.
enty.resize(boost::extents[theCurrentTemp.
head.
NTy]);
318 for (i=0; i < theCurrentTemp.
head.
NTy; ++
i) {
320 db >> theCurrentTemp.
enty[
i].
runnum >> costrk[0] >> costrk[1] >> costrk[2];
322 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 1, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
333 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 2, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
338 for (j=0; j<4; ++
j) {
342 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 14a, no GenError load, run # " << theCurrentTemp.
enty[
i].
runnum <<
ENDL;
return false;}
349 for (k=0; k < theCurrentTemp.
head.
NTyx; ++
k) {
351 for (i=0; i < theCurrentTemp.
head.
NTxx; ++
i) {
353 db >> theCurrentTemp.
entx[
k][
i].
runnum >> costrk[0] >> costrk[1] >> costrk[2];
355 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 17, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
366 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 18, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
371 for (j=0; j<4; ++
j) {
375 if(db.
fail()) {
LOGERROR(
"SiPixelGenError") <<
"Error reading file 30a, no GenError load, run # " << theCurrentTemp.
entx[
k][
i].
runnum <<
ENDL;
return false;}
384 thePixelTemp_.push_back(theCurrentTemp);
386 postInit(thePixelTemp_);
397 for (
auto & templ : thePixelTemp_) {
398 for (
auto iy=0; iy<templ.head.NTy; ++iy ) templ.cotbetaY[iy]=templ.enty[iy].cotbeta;
399 for (
auto iy=0; iy<templ.head.NTyx; ++iy ) templ.cotbetaX[iy]= templ.entx[iy][0].cotbeta;
400 for (
auto ix=0; ix<templ.head.NTxx; ++ix ) templ.cotalphaX[ix]=templ.entx[0][ix].cotalpha;
435 if(
id != id_current_) {
438 for(
int i=0;
i<(int)thePixelTemp_.size(); ++
i) {
439 if(
id == thePixelTemp_[
i].head.ID) {
443 lorywidth_ = thePixelTemp_[
i].head.lorywidth;
444 lorxwidth_ = thePixelTemp_[
i].head.lorxwidth;
445 lorybias_ = thePixelTemp_[
i].head.lorybias;
446 lorxbias_ = thePixelTemp_[
i].head.lorxbias;
451 xsize_ = thePixelTemp_[
i].head.xsize;
452 ysize_ = thePixelTemp_[
i].head.ysize;
453 zsize_ = thePixelTemp_[
i].head.zsize;
464 float& pixmx,
float& sigmay,
float& deltay,
float& sigmax,
float& deltax,
465 float& sy1,
float& dy1,
float& sy2,
float& dy2,
float& sx1,
float& dx1,
466 float& sx2,
float& dx2)
474 if(
id != id_current_) {
477 for(
int i=0;
i<(int)thePixelTemp_.size(); ++
i) {
478 if(
id == thePixelTemp_[
i].head.ID) {
481 lorywidth_ = thePixelTemp_[
i].head.lorywidth;
482 lorxwidth_ = thePixelTemp_[
i].head.lorxwidth;
483 lorybias_ = thePixelTemp_[
i].head.lorybias;
484 lorxbias_ = thePixelTemp_[
i].head.lorxbias;
485 for(
int j=0;
j<3; ++
j) {fbin_[
j] = thePixelTemp_[
i].head.fbin[
j];}
489 xsize_ = thePixelTemp_[
i].head.xsize;
490 ysize_ = thePixelTemp_[
i].head.ysize;
491 zsize_ = thePixelTemp_[
i].head.zsize;
498 int index = index_id_;
500 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
501 if(index < 0 || index >= (
int)thePixelTemp_.size()) {
502 throw cms::Exception(
"DataCorrupt") <<
"SiPixelGenError::qbin can't find needed GenError ID = " <<
id << std::endl;
505 assert(index >= 0 && index < (
int)thePixelTemp_.size());
511 auto const & templ = thePixelTemp_[
index];
519 auto cotalpha0 = thePixelTemp_[
index].enty[0].cotalpha;
520 auto qcorrect=
std::sqrt((1.
f+cotbeta*cotbeta+cotalpha*cotalpha)/(1.
f+cotbeta*cotbeta+cotalpha0*cotalpha0));
524 float cotb;
bool flip_y;
525 if(thePixelTemp_[index].head.Dtype == 0) {
528 if(cotbeta < 0.
f) {flip_y =
true;}
541 auto qscale = thePixelTemp_[
index].head.qscale;
551 auto Ny = thePixelTemp_[
index].head.NTy;
552 auto Nyx = thePixelTemp_[
index].head.NTyx;
553 auto Nxx = thePixelTemp_[
index].head.NTxx;
555 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
556 if(Ny < 2 || Nyx < 1 || Nxx < 2) {
557 throw cms::Exception(
"DataCorrupt") <<
"GenError ID = " << id_current_ <<
"has too few entries: Ny/Nyx/Nxx = " << Ny <<
"/" << Nyx <<
"/" << Nxx << std::endl;
560 assert(Ny > 1 && Nyx > 0 && Nxx > 1);
570 auto j = std::lower_bound(templ.cotbetaY,templ.cotbetaY+Ny,cotb);
571 if (
j==templ.cotbetaY+Ny) { --
j; yratio = 1.f; }
572 else if (
j==templ.cotbetaY) { ++
j; yratio = 0.f;}
573 else { yratio = (cotb - (*(
j-1)) )/( (*
j) - (*(
j-1)) ) ; }
575 ihigh =
j-templ.cotbetaY;
583 dy1 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].dyone + yratio*thePixelTemp_[index].enty[ihigh].dyone;
584 if(flip_y) {dy1 = -dy1;}
585 sy1 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].syone + yratio*thePixelTemp_[index].enty[ihigh].syone;
586 dy2 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].dytwo + yratio*thePixelTemp_[index].enty[ihigh].dytwo;
587 if(flip_y) {dy2 = -dy2;}
588 sy2 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].sytwo + yratio*thePixelTemp_[index].enty[ihigh].sytwo;
590 auto qavg = (1.f - yratio)*thePixelTemp_[index].enty[ilow].qavg + yratio*thePixelTemp_[index].enty[ihigh].qavg;
592 auto qmin = (1.f - yratio)*thePixelTemp_[index].enty[ilow].qmin + yratio*thePixelTemp_[index].enty[ihigh].qmin;
594 auto qmin2 = (1.f - yratio)*thePixelTemp_[index].enty[ilow].qmin2 + yratio*thePixelTemp_[index].enty[ihigh].qmin2;
598 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
599 if(qavg <= 0.
f || qmin <= 0.
f) {
600 throw cms::Exception(
"DataCorrupt") <<
"SiPixelGenError::qbin, qavg or qmin <= 0,"
601 <<
" Probably someone called the generic pixel reconstruction with an illegal trajectory state" << std::endl;
604 assert(qavg > 0.
f && qmin > 0.
f);
609 auto qtotal = qscale*qclus;
613 auto fq = qtotal/qavg;
629 auto yavggen =(1.f - yratio)*thePixelTemp_[index].enty[ilow].yavggen[binq] + yratio*thePixelTemp_[index].enty[ihigh].yavggen[binq];
630 if(flip_y) {yavggen = -yavggen;}
631 auto yrmsgen =(1.f - yratio)*thePixelTemp_[index].enty[ilow].yrmsgen[binq] + yratio*thePixelTemp_[index].enty[ihigh].yrmsgen[binq];
642 auto j = std::lower_bound(templ.cotbetaX,templ.cotbetaX+Nyx,acotb);
643 if (
j==templ.cotbetaX+Nyx) { --
j; yxratio = 1.f; }
644 else if (
j==templ.cotbetaX) { ++
j; yxratio = 0.f;}
645 else { yxratio = (acotb - (*(
j-1)) )/( (*
j) - (*(
j-1)) ) ; }
647 iyhigh =
j-templ.cotbetaX;
657 auto j = std::lower_bound(templ.cotalphaX,templ.cotalphaX+Nxx,cotalpha);
658 if (
j==templ.cotalphaX+Nxx) { --
j; xxratio = 1.f; }
659 else if (
j==templ.cotalphaX) { ++
j; xxratio = 0.f;}
660 else { xxratio = (cotalpha - (*(
j-1)) )/( (*
j) - (*(
j-1)) ) ; }
662 ihigh =
j-templ.cotalphaX;
668 dx1 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].dxone + xxratio*thePixelTemp_[index].entx[0][ihigh].dxone;
669 sx1 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].sxone + xxratio*thePixelTemp_[index].entx[0][ihigh].sxone;
670 dx2 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].dxtwo + xxratio*thePixelTemp_[index].entx[0][ihigh].dxtwo;
671 sx2 = (1.f - xxratio)*thePixelTemp_[index].entx[0][ilow].sxtwo + xxratio*thePixelTemp_[index].entx[0][ihigh].sxtwo;
675 pixmx=(1.f - yxratio)*((1.
f - xxratio)*thePixelTemp_[
index].entx[iylow][ilow].pixmax + xxratio*thePixelTemp_[
index].entx[iylow][ihigh].pixmax)
676 +yxratio*((1.
f - xxratio)*thePixelTemp_[
index].entx[iyhigh][ilow].pixmax + xxratio*thePixelTemp_[
index].entx[iyhigh][ihigh].pixmax);
678 auto xavggen = (1.f - yxratio)*((1.
f - xxratio)*thePixelTemp_[
index].entx[iylow][ilow].xavggen[binq] + xxratio*thePixelTemp_[
index].entx[iylow][ihigh].xavggen[binq])
679 +yxratio*((1.
f - xxratio)*thePixelTemp_[
index].entx[iyhigh][ilow].xavggen[binq] + xxratio*thePixelTemp_[
index].entx[iyhigh][ihigh].xavggen[binq]);
681 auto xrmsgen = (1.f - yxratio)*((1.
f - xxratio)*thePixelTemp_[
index].entx[iylow][ilow].xrmsgen[binq] + xxratio*thePixelTemp_[
index].entx[iylow][ihigh].xrmsgen[binq])
682 +yxratio*((1.
f - xxratio)*thePixelTemp_[
index].entx[iyhigh][ilow].xrmsgen[binq] + xxratio*thePixelTemp_[
index].entx[iyhigh][ihigh].xrmsgen[binq]);
688 sigmay = yrmsgen; deltay = yavggen;
690 sigmax = xrmsgen; deltax = xavggen;
694 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)
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
for(const auto &isodef:isoDefs)
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...