12 TrackDerTable::TrackDerTable(
Settings const& settings) : settings_(settings) {
27 for (
int i = 0;
i < (1 <<
Nlay_);
i++) {
31 for (
int i = 0;
i < (1 << (2 *
Ndisk_));
i++) {
41 unsigned int diskmask,
42 unsigned int alphaindex,
43 unsigned int rinvindex)
const {
59 if (diskcode < 0 || layercode < 0) {
61 edm::LogPrint(
"Tracklet") <<
"layermask diskmask : " << layermask <<
" " << diskmask;
71 int layerdiskaddress = layercode + (diskcode <<
LayerMemBits_);
73 assert(layerdiskaddress >= 0);
80 edm::LogVerbatim(
"Tracklet") <<
"layermask diskmask : " << layermask <<
" " << diskmask;
113 int layerdiskaddress = layercode + (diskcode <<
LayerMemBits_);
115 assert(layerdiskaddress >= 0);
121 edm::LogPrint(
"Tracklet") <<
"Duplicate entry: layermask=" << layermask <<
" diskmaks=" << diskmask;
132 for (
int i = 0;
i < multiplicity;
i++) {
133 for (
int irinv = 0; irinv < nrinv; irinv++) {
135 tmp.setIndex(layermask, diskmask,
i, irinv);
145 edm::LogVerbatim(
"Tracklet") <<
" flags (good/eof/fail/bad): " <<
in.good() <<
" " <<
in.eof() <<
" " <<
in.fail()
153 in >> layerstr >> diskstr >> multiplicity;
157 if (multiplicity == 8)
159 if (multiplicity == 64)
161 if (multiplicity == 512)
166 if (multiplicity == 8)
168 if (multiplicity == 64)
170 if (multiplicity == 512)
177 char** tmpptr =
nullptr;
179 int layers = strtol(layerstr.c_str(), tmpptr, 2);
180 int disks = strtol(diskstr.c_str(), tmpptr, 2);
189 for (
int i = 0;
i < nentries;
i++) {
194 int irinv = der.
irinv();
202 edm::LogVerbatim(
"Tracklet") <<
"PRINT i " <<
i <<
" " << layermask <<
" " << diskmask <<
" " << alphamask <<
" "
210 if (layermask & (1 << (
N_LAYER - 1 -
l))) {
223 if (diskmask & (3 << (2 * (
N_DISK - 1 -
d)))) {
228 if (diskmask & (1 << (2 * (
N_DISK - 1 -
d)))) {
230 int ialpha = alphamask & 7;
231 alphamask = alphamask >> 3;
237 int ialpha = alphamask & 3;
238 alphamask = alphamask >> 2;
242 int ialpha = alphamask & 1;
243 alphamask = alphamask >> 1;
262 edm::LogVerbatim(
"Tracklet") <<
"PRINT ndisks alpha[0] z[0] t: " << ndisks <<
" " <<
alpha[0] <<
" " << z[0]
264 for (
int iii = 0; iii <
nlayers; iii++) {
269 calculateDerivatives(
settings_,
nlayers,
r, ndisks, z,
alpha,
t,
rinv,
D, iD, MinvDt, iMinvDt, sigma,
kfactor);
280 settings_,
nlayers,
r, ndisks, z,
alpha,
t,
rinv,
D, iD, MinvDtDelta, iMinvDt, sigma,
kfactor);
285 double tder = (MinvDtDelta[2][2 *
ii + 1] - MinvDt[2][2 *
ii + 1]) /
delta;
288 double zder = (MinvDtDelta[3][2 *
ii + 1] - MinvDt[3][2 *
ii + 1]) /
delta;
301 edm::LogVerbatim(
"Tracklet") <<
"iMinvDt table build : " << iMinvDt[0][10] <<
" " << iMinvDt[1][10] <<
" "
302 << iMinvDt[2][10] <<
" " << iMinvDt[3][10] <<
" " <<
t <<
" " <<
nlayers <<
" "
306 for (
int iii = 0; iii < ndisks; iii++) {
308 oss += std::to_string(
alpha[iii]);
312 for (
int iii = 0; iii < ndisks; iii++) {
314 oss += std::to_string(z[iii]);
337 edm::LogVerbatim(
"Tracklet") <<
"PRINT i " <<
i <<
" " <<
j <<
" " << iMinvDt[1][2 *
j] <<
" "
365 throw cms::Exception(
"BadDir") << __FILE__ <<
" " << __LINE__ <<
" could not create directory "
370 ofstream outL(fnameL);
372 throw cms::Exception(
"BadFile") << __FILE__ <<
" " << __LINE__ <<
" could not create file " << fnameL;
379 tmp1 = (1 << nbits) - 1;
380 tmp.set(tmp1, nbits,
true, __LINE__, __FILE__);
381 outL <<
tmp.str() << endl;
386 ofstream outD(fnameD);
388 throw cms::Exception(
"BadFile") << __FILE__ <<
" " << __LINE__ <<
" could not create file " << fnameD;
393 tmp1 = (1 << nbits) - 1;
395 tmp.set(tmp1, nbits,
true, __LINE__, __FILE__);
396 outD <<
tmp.str() << endl;
401 ofstream outLD(fnameLD);
403 throw cms::Exception(
"BadFile") << __FILE__ <<
" " << __LINE__ <<
" could not create file " << fnameLD;
408 tmp1 = (1 << nbits) - 1;
410 tmp.set(tmp1, nbits,
true, __LINE__, __FILE__);
411 outLD <<
tmp.str() << endl;
415 const std::array<string, N_TRKLSEED> seedings = {{
"L1L2",
"L3L4",
"L5L6",
"D1D2",
"D3D4",
"D1L1",
"D1L2"}};
422 const string fname =
prefix +
"Rinvdphi_" + seedings[
i] +
".tab";
423 outrinvdphi[
i].open(
fname);
424 if (outrinvdphi[
i].fail())
425 throw cms::Exception(
"BadFile") << __FILE__ <<
" " << __LINE__ <<
" could not create file " <<
fname;
430 const string fname =
prefix +
"Rinvdzordr_" + seedings[
i] +
".tab";
431 outrinvdzordr[
i].open(
fname);
432 if (outrinvdzordr[
i].fail())
433 throw cms::Exception(
"BadFile") << __FILE__ <<
" " << __LINE__ <<
" could not create file " <<
fname;
438 const string fname =
prefix +
"Phi0dphi_" + seedings[
i] +
".tab";
439 outphi0dphi[
i].open(
fname);
440 if (outphi0dphi[
i].fail())
441 throw cms::Exception(
"BadFile") << __FILE__ <<
" " << __LINE__ <<
" could not create file " <<
fname;
446 const string fname =
prefix +
"Phi0dzordr_" + seedings[
i] +
".tab";
447 outphi0dzordr[
i].open(
fname);
448 if (outphi0dzordr[
i].fail())
449 throw cms::Exception(
"BadFile") << __FILE__ <<
" " << __LINE__ <<
" could not create file " <<
fname;
454 const string fname =
prefix +
"Tdphi_" + seedings[
i] +
".tab";
456 if (outtdphi[
i].fail())
457 throw cms::Exception(
"BadFile") << __FILE__ <<
" " << __LINE__ <<
" could not create file " <<
fname;
462 const string fname =
prefix +
"Tdzordr_" + seedings[
i] +
".tab";
463 outtdzordr[
i].open(
fname);
464 if (outtdzordr[
i].fail())
465 throw cms::Exception(
"BadFile") << __FILE__ <<
" " << __LINE__ <<
" could not create file " <<
fname;
470 const string fname =
prefix +
"Z0dphi_" + seedings[
i] +
".tab";
472 if (outz0dphi[
i].fail())
473 throw cms::Exception(
"BadFile") << __FILE__ <<
" " << __LINE__ <<
" could not create file " <<
fname;
478 string fname =
prefix +
"Z0dzordr_" + seedings[
i] +
".tab";
479 outz0dzordr[
i].open(
fname);
480 if (outz0dzordr[
i].fail())
481 throw cms::Exception(
"BadFile") << __FILE__ <<
" " << __LINE__ <<
" could not create file " <<
fname;
485 unsigned int layerhits = der.layerMask();
486 unsigned int diskmask = der.diskMask();
487 unsigned int diskhits = 0;
488 if (diskmask & (3 << 8))
490 if (diskmask & (3 << 6))
492 if (diskmask & (3 << 4))
494 if (diskmask & (3 << 2))
496 if (diskmask & (3 << 0))
499 unsigned int hits = (layerhits << 5) + diskhits;
504 for (
const string&
seed : seedings) {
505 unsigned int iseed1 = 0;
506 unsigned int iseed2 = 0;
508 if (
seed ==
"L1L2") {
512 if (
seed ==
"L3L4") {
516 if (
seed ==
"L5L6") {
520 if (
seed ==
"D1D2") {
524 if (
seed ==
"D3D4") {
528 if (
seed ==
"D1L1") {
532 if (
seed ==
"D1L2") {
537 bool goodseed = (
hits & (1 << (11 - iseed1))) and (
hits & (1 << (11 - iseed2)));
539 int itmprinvdphi[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
540 int itmprinvdzordr[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
541 int itmpphi0dphi[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
542 int itmpphi0dzordr[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
543 int itmptdphi[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
544 int itmptdzordr[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
545 int itmpz0dphi[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
546 int itmpz0dzordr[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
551 for (
unsigned int ihit = 1; ihit <
N_FITSTUB * 2; ++ihit) {
553 if (ihit == iseed1
or ihit == iseed2) {
558 if (not(
hits & (1 << (11 - ihit))))
562 if (
seed ==
"L1L2") {
563 if (ihit == 3
or ihit == 10)
565 if (ihit == 4
or ihit == 9)
567 if (ihit == 5
or ihit == 8)
569 if (ihit == 6
or ihit == 7)
571 }
else if (
seed ==
"L3L4") {
576 if (ihit == 5
or ihit == 8)
578 if (ihit == 6
or ihit == 7)
580 }
else if (
seed ==
"L5L6") {
589 }
else if (
seed ==
"D1D2") {
596 if (ihit == 2
or ihit == 11)
598 }
else if (
seed ==
"D3D4") {
605 if (ihit == 2
or ihit == 11)
607 }
else if (
seed ==
"D1L1" or "D1L2") {
617 if (inputI >= 0 and inputI < (
int)
N_PROJ) {
618 itmprinvdphi[inputI] = der.irinvdphi(ider);
619 itmprinvdzordr[inputI] = der.irinvdzordr(ider);
620 itmpphi0dphi[inputI] = der.iphi0dphi(ider);
621 itmpphi0dzordr[inputI] = der.iphi0dzordr(ider);
622 itmptdphi[inputI] = der.itdphi(ider);
623 itmptdzordr[inputI] = der.itdzordr(ider);
624 itmpz0dphi[inputI] = der.iz0dphi(ider);
625 itmpz0dzordr[inputI] = der.iz0dzordr(ider);
635 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
636 if (itmprinvdphi[
j] > (1 << nbits))
637 itmprinvdphi[
j] = (1 << nbits) - 1;
638 tmprinvdphi[
j].
set(itmprinvdphi[
j], nbits + 1,
false, __LINE__, __FILE__);
640 outrinvdphi[
i] << tmprinvdphi[0].
str() << tmprinvdphi[1].
str() << tmprinvdphi[2].
str() << tmprinvdphi[3].
str()
645 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
646 if (itmprinvdzordr[
j] > (1 << nbits))
647 itmprinvdzordr[
j] = (1 << nbits) - 1;
648 tmprinvdzordr[
j].
set(itmprinvdzordr[
j], nbits + 1,
false, __LINE__, __FILE__);
650 outrinvdzordr[
i] << tmprinvdzordr[0].
str() << tmprinvdzordr[1].
str() << tmprinvdzordr[2].
str()
651 << tmprinvdzordr[3].
str() << endl;
655 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
656 if (itmpphi0dphi[
j] > (1 << nbits))
657 itmpphi0dphi[
j] = (1 << nbits) - 1;
658 tmpphi0dphi[
j].
set(itmpphi0dphi[
j], nbits + 1,
false, __LINE__, __FILE__);
660 outphi0dphi[
i] << tmpphi0dphi[0].
str() << tmpphi0dphi[1].
str() << tmpphi0dphi[2].
str() << tmpphi0dphi[3].
str()
665 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
666 if (itmpphi0dzordr[
j] > (1 << nbits))
667 itmpphi0dzordr[
j] = (1 << nbits) - 1;
668 tmpphi0dzordr[
j].
set(itmpphi0dzordr[
j], nbits + 1,
false, __LINE__, __FILE__);
670 outphi0dzordr[
i] << tmpphi0dzordr[0].
str() << tmpphi0dzordr[1].
str() << tmpphi0dzordr[2].
str()
671 << tmpphi0dzordr[3].
str() << endl;
675 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
676 if (itmptdphi[
j] > (1 << nbits))
677 itmptdphi[
j] = (1 << nbits) - 1;
678 tmptdphi[
j].
set(itmptdphi[
j], nbits + 1,
false, __LINE__, __FILE__);
680 outtdphi[
i] << tmptdphi[0].
str() << tmptdphi[1].
str() << tmptdphi[2].
str() << tmptdphi[3].
str() << endl;
684 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
685 if (itmptdzordr[
j] > (1 << nbits))
686 itmptdzordr[
j] = (1 << nbits) - 1;
687 tmptdzordr[
j].
set(itmptdzordr[
j], nbits + 1,
false, __LINE__, __FILE__);
689 outtdzordr[
i] << tmptdzordr[0].
str() << tmptdzordr[1].
str() << tmptdzordr[2].
str() << tmptdzordr[3].
str()
694 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
695 if (itmpz0dphi[
j] > (1 << nbits))
696 itmpz0dphi[
j] = (1 << nbits) - 1;
697 tmpz0dphi[
j].
set(itmpz0dphi[
j], nbits + 1,
false, __LINE__, __FILE__);
699 outz0dphi[
i] << tmpz0dphi[0].
str() << tmpz0dphi[1].
str() << tmpz0dphi[2].
str() << tmpz0dphi[3].
str() << endl;
703 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
704 if (itmpz0dzordr[
j] > (1 << nbits))
705 itmpz0dzordr[
j] = (1 << nbits) - 1;
706 tmpz0dzordr[
j].
set(itmpz0dzordr[
j], nbits + 1,
false, __LINE__, __FILE__);
708 outz0dzordr[
i] << tmpz0dzordr[0].
str() << tmpz0dzordr[1].
str() << tmpz0dzordr[2].
str() << tmpz0dzordr[3].
str()
718 outrinvdphi[
i].close();
719 outrinvdzordr[
i].close();
720 outphi0dphi[
i].close();
721 outphi0dzordr[
i].close();
723 outtdzordr[
i].close();
724 outz0dphi[
i].close();
725 outz0dzordr[
i].close();
734 unsigned int i,
j,
k;
737 for (
i = 0;
i <
n;
i++) {
738 for (
j =
n;
j < 2 *
n;
j++) {
746 for (
i = 0;
i <
n;
i++) {
747 for (
j = 0;
j <
n;
j++) {
750 for (
k = 0;
k < 2 *
n;
k++) {
757 for (
i = 0;
i <
n;
i++) {
759 for (
j = 0;
j < 2 *
n;
j++) {
769 unsigned int i,
j,
k;
772 for (
i = 0;
i <
n;
i++) {
773 for (
j =
n;
j < 2 *
n;
j++) {
781 for (
i = 0;
i <
n;
i++) {
782 for (
j = 0;
j <
n;
j++) {
785 for (
k = 0;
k < 2 *
n;
k++) {
792 for (
i = 0;
i <
n;
i++) {
794 for (
j = 0;
j < 2 *
n;
j++) {
818 double sigmazpsbarrel = sigmaz;
820 sigmazpsbarrel = sigmaz *
std::abs(
t) / 2.0;
845 D[0][
j] = -0.5 * ri * ri /
sqrt(1 - 0.25 * ri * ri *
rinv *
rinv) / sigmax;
846 D[1][
j] = ri / sigmax;
855 if (ri < settings.
rPS2S()) {
856 D[2][
j] = (2 /
rinv) * asin(0.5 * ri *
rinv) / sigmazpsbarrel;
857 D[3][
j] = 1.0 / sigmazpsbarrel;
858 sigma[
j] = sigmazpsbarrel;
861 D[2][
j] = (2 /
rinv) * asin(0.5 * ri *
rinv) / sigmaz2;
862 D[3][
j] = 1.0 / sigmaz2;
870 for (
unsigned int i = 0;
i < ndisks;
i++) {
875 double rmultiplier =
alpha[
i] * zi /
t;
877 double phimultiplier = zi /
t;
882 double drdt = -(zi -
z0) *
cos(0.5 *
rinv * (zi -
z0) /
t) / (
t *
t);
883 double drdz0 = -
cos(0.5 *
rinv * (zi -
z0) /
t) /
t;
885 double dphidrinv = -0.5 * (zi -
z0) /
t;
886 double dphidphi0 = 1.0;
887 double dphidt = 0.5 *
rinv * (zi -
z0) / (
t *
t);
888 double dphidz0 = 0.5 *
rinv /
t;
890 double r = (zi -
z0) /
t;
894 sigma[
j] = sigmax2sdisk;
896 sigma[
j] = sigmaxpsdisk;
899 D[0][
j] = (phimultiplier * dphidrinv + rmultiplier * drdrinv) / sigma[
j];
900 D[1][
j] = (phimultiplier * dphidphi0 + rmultiplier * drdphi0) / sigma[
j];
901 D[2][
j] = (phimultiplier * dphidt + rmultiplier * drdt) / sigma[
j];
902 D[3][
j] = (phimultiplier * dphidz0 + rmultiplier * drdz0) / sigma[
j];
908 D[0][
j] = drdrinv / sigmazpsdisk;
909 D[1][
j] = drdphi0 / sigmazpsdisk;
910 D[2][
j] = drdt / sigmazpsdisk;
911 D[3][
j] = drdz0 / sigmazpsdisk;
912 sigma[
j] = sigmazpsdisk;
915 D[0][
j] = drdrinv / sigmaz2sdisk;
916 D[1][
j] = drdphi0 / sigmaz2sdisk;
917 D[2][
j] = drdt / sigmaz2sdisk;
918 D[3][
j] = drdz0 / sigmaz2sdisk;
919 sigma[
j] = sigmaz2sdisk;
928 for (
unsigned int i1 = 0;
i1 < 4;
i1++) {
929 for (
unsigned int i2 = 0;
i2 < 4;
i2++) {
931 for (
unsigned int j = 0;
j < 2 *
n;
j++) {
946 for (
unsigned int j = 0;
j < 2 *
n;
j++) {
947 for (
unsigned int i1 = 0;
i1 < 4;
i1++) {
948 for (
unsigned int i2 = 0;
i2 < 4;
i2++) {
954 for (
unsigned int i = 0;
i <
n;
i++) {
975 MinvDt[0][2 *
i] *= rnew[
i] / sigmax;
976 MinvDt[1][2 *
i] *= rnew[
i] / sigmax;
977 MinvDt[2][2 *
i] *= rnew[
i] / sigmax;
978 MinvDt[3][2 *
i] *= rnew[
i] / sigmax;
987 if (rnew[
i] < settings.
rPS2S()) {
988 MinvDt[0][2 *
i + 1] /= sigmazpsbarrel;
989 MinvDt[1][2 *
i + 1] /= sigmazpsbarrel;
990 MinvDt[2][2 *
i + 1] /= sigmazpsbarrel;
991 MinvDt[3][2 *
i + 1] /= sigmazpsbarrel;
993 iMinvDt[0][2 *
i + 1] =
995 iMinvDt[1][2 *
i + 1] =
997 iMinvDt[2][2 *
i + 1] =
999 iMinvDt[3][2 *
i + 1] =
1002 MinvDt[0][2 *
i + 1] /= sigmaz2;
1003 MinvDt[1][2 *
i + 1] /= sigmaz2;
1004 MinvDt[2][2 *
i + 1] /= sigmaz2;
1005 MinvDt[3][2 *
i + 1] /= sigmaz2;
1009 iMinvDt[0][2 *
i + 1] =
1011 iMinvDt[1][2 *
i + 1] =
1013 iMinvDt[2][2 *
i + 1] =
1015 iMinvDt[3][2 *
i + 1] =
1024 MinvDt[0][2 *
i] *= (rnew[
i] /
denom);
1025 MinvDt[1][2 *
i] *= (rnew[
i] /
denom);
1026 MinvDt[2][2 *
i] *= (rnew[
i] /
denom);
1027 MinvDt[3][2 *
i] *= (rnew[
i] /
denom);
1029 assert(MinvDt[0][2 *
i] == MinvDt[0][2 *
i]);
1034 iMinvDt[3][2 *
i] = (1 << settings.
fitz0bitshift()) * MinvDt[3][2 *
i] * settings.
kphi() / settings.
kz();
1038 MinvDt[0][2 *
i + 1] /=
denom;
1039 MinvDt[1][2 *
i + 1] /=
denom;
1040 MinvDt[2][2 *
i + 1] /=
denom;
1041 MinvDt[3][2 *
i + 1] /=
denom;
1043 iMinvDt[0][2 *
i + 1] =
1045 iMinvDt[1][2 *
i + 1] =
1047 iMinvDt[2][2 *
i + 1] =
1049 iMinvDt[3][2 *
i + 1] =
1059 double tmax = 1000.0;
1063 if (diskmask & (1 << (2 * (5 -
d) + 1))) {
1064 double dmax = settings.
zmean(
d - 1) / 22.0;
1065 if (dmax > sinh(2.4))
1067 double dmin = settings.
zmean(
d - 1) / 65.0;
1074 if (diskmask & (1 << (2 * (5 -
d)))) {
1075 double dmax = settings.
zmean(
d - 1) / 65.0;
1076 double dmin = settings.
zmean(
d - 1) / 105.0;
1085 if (layermask & (1 << (6 -
l))) {