10 TrackDerTable::TrackDerTable(
Settings const& settings) : settings_(settings) {
25 for (
int i = 0;
i < (1 <<
Nlay_);
i++) {
29 for (
int i = 0;
i < (1 << (2 *
Ndisk_));
i++) {
39 unsigned int diskmask,
40 unsigned int alphaindex,
41 unsigned int rinvindex)
const {
57 if (diskcode < 0 || layercode < 0) {
59 edm::LogPrint(
"Tracklet") <<
"layermask diskmask : " << layermask <<
" " << diskmask;
69 int layerdiskaddress = layercode + (diskcode <<
LayerMemBits_);
71 assert(layerdiskaddress >= 0);
78 edm::LogVerbatim(
"Tracklet") <<
"layermask diskmask : " << layermask <<
" " << diskmask;
111 int layerdiskaddress = layercode + (diskcode <<
LayerMemBits_);
113 assert(layerdiskaddress >= 0);
119 edm::LogPrint(
"Tracklet") <<
"Duplicate entry: layermask=" << layermask <<
" diskmaks=" << diskmask;
130 for (
int i = 0;
i < multiplicity;
i++) {
131 for (
int irinv = 0; irinv < nrinv; irinv++) {
133 tmp.setIndex(layermask, diskmask,
i, irinv);
143 edm::LogVerbatim(
"Tracklet") <<
" flags (good/eof/fail/bad): " <<
in.good() <<
" " <<
in.eof() <<
" " <<
in.fail()
151 in >> layerstr >> diskstr >> multiplicity;
155 if (multiplicity == 8)
157 if (multiplicity == 64)
159 if (multiplicity == 512)
164 if (multiplicity == 8)
166 if (multiplicity == 64)
168 if (multiplicity == 512)
175 char** tmpptr =
nullptr;
177 int layers = strtol(layerstr.c_str(), tmpptr, 2);
178 int disks = strtol(diskstr.c_str(), tmpptr, 2);
187 for (
int i = 0;
i < nentries;
i++) {
192 int irinv = der.
irinv();
200 edm::LogVerbatim(
"Tracklet") <<
"PRINT i " <<
i <<
" " << layermask <<
" " << diskmask <<
" " << alphamask <<
" "
208 if (layermask & (1 << (
N_LAYER - 1 -
l))) {
221 if (diskmask & (3 << (2 * (
N_DISK - 1 -
d)))) {
226 if (diskmask & (1 << (2 * (
N_DISK - 1 -
d)))) {
228 int ialpha = alphamask & 7;
229 alphamask = alphamask >> 3;
235 int ialpha = alphamask & 3;
236 alphamask = alphamask >> 2;
240 int ialpha = alphamask & 1;
241 alphamask = alphamask >> 1;
260 edm::LogVerbatim(
"Tracklet") <<
"PRINT ndisks alpha[0] z[0] t: " << ndisks <<
" " <<
alpha[0] <<
" " << z[0]
262 for (
int iii = 0; iii <
nlayers; iii++) {
267 calculateDerivatives(
settings_,
nlayers,
r, ndisks, z,
alpha,
t,
rinv,
D, iD, MinvDt, iMinvDt, sigma, kfactor);
278 settings_,
nlayers,
r, ndisks, z,
alpha,
t,
rinv,
D, iD, MinvDtDelta, iMinvDt, sigma, kfactor);
283 double tder = (MinvDtDelta[2][2 *
ii + 1] - MinvDt[2][2 *
ii + 1]) /
delta;
286 double zder = (MinvDtDelta[3][2 *
ii + 1] - MinvDt[3][2 *
ii + 1]) /
delta;
299 edm::LogVerbatim(
"Tracklet") <<
"iMinvDt table build : " << iMinvDt[0][10] <<
" " << iMinvDt[1][10] <<
" "
300 << iMinvDt[2][10] <<
" " << iMinvDt[3][10] <<
" " <<
t <<
" " <<
nlayers <<
" "
304 for (
int iii = 0; iii < ndisks; iii++) {
306 oss += std::to_string(
alpha[iii]);
310 for (
int iii = 0; iii < ndisks; iii++) {
312 oss += std::to_string(z[iii]);
335 edm::LogVerbatim(
"Tracklet") <<
"PRINT i " <<
i <<
" " <<
j <<
" " << iMinvDt[1][2 *
j] <<
" "
360 ofstream outL(
"FitDerTableNew_LayerMem.txt");
367 tmp.set(tmp1, 6,
true, __LINE__, __FILE__);
368 outL <<
tmp.str() << endl;
372 ofstream outD(
"FitDerTableNew_DiskMem.txt");
377 tmp.set(tmp1, 7,
true, __LINE__, __FILE__);
378 outD <<
tmp.str() << endl;
382 ofstream outLD(
"FitDerTableNew_LayerDiskMem.txt");
385 tmp1 = (1 << 10) - 1;
387 tmp.set(tmp1, 10,
true, __LINE__, __FILE__);
388 outLD <<
tmp.str() << endl;
395 const std::array<string, N_TRKLSEED> seedings = {{
"L1L2",
"L3L4",
"L5L6",
"D1D2",
"D3D4",
"D1L1",
"D1L2"}};
396 const string prefix =
"FitDerTableNew_";
401 const string fname =
prefix +
"Rinvdphi_" + seedings[
i] +
".txt";
402 outrinvdphi[
i].open(
fname.c_str());
407 const string fname =
prefix +
"Rinvdzordr_" + seedings[
i] +
".txt";
408 outrinvdzordr[
i].open(
fname.c_str());
413 const string fname =
prefix +
"Phi0dphi_" + seedings[
i] +
".txt";
414 outphi0dphi[
i].open(
fname.c_str());
419 const string fname =
prefix +
"Phi0dzordr_" + seedings[
i] +
".txt";
420 outphi0dzordr[
i].open(
fname.c_str());
425 const string fname =
prefix +
"Tdphi_" + seedings[
i] +
".txt";
426 outtdphi[
i].open(
fname.c_str());
431 const string fname =
prefix +
"Tdzordr_" + seedings[
i] +
".txt";
432 outtdzordr[
i].open(
fname.c_str());
437 const string fname =
prefix +
"Z0dphi_" + seedings[
i] +
".txt";
438 outz0dphi[
i].open(
fname.c_str());
443 string fname =
prefix +
"Z0dzordr_" + seedings[
i] +
".txt";
444 outz0dzordr[
i].open(
fname.c_str());
448 unsigned int layerhits = der.layerMask();
449 unsigned int diskmask = der.diskMask();
450 unsigned int diskhits = 0;
451 if (diskmask & (3 << 8))
453 if (diskmask & (3 << 6))
455 if (diskmask & (3 << 4))
457 if (diskmask & (3 << 2))
459 if (diskmask & (3 << 0))
462 unsigned int hits = (layerhits << 5) + diskhits;
467 for (
const string&
seed : seedings) {
468 unsigned int iseed1 = 0;
469 unsigned int iseed2 = 0;
471 if (
seed ==
"L1L2") {
475 if (
seed ==
"L3L4") {
479 if (
seed ==
"L5L6") {
483 if (
seed ==
"D1D2") {
487 if (
seed ==
"D3D4") {
491 if (
seed ==
"D1L1") {
495 if (
seed ==
"D1L2") {
500 bool goodseed = (
hits & (1 << (11 - iseed1))) and (
hits & (1 << (11 - iseed2)));
502 int itmprinvdphi[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
503 int itmprinvdzordr[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
504 int itmpphi0dphi[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
505 int itmpphi0dzordr[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
506 int itmptdphi[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
507 int itmptdzordr[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
508 int itmpz0dphi[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
509 int itmpz0dzordr[
N_PROJ] = {9999999, 9999999, 9999999, 9999999};
514 for (
unsigned int ihit = 1; ihit <
N_FITSTUB * 2; ++ihit) {
516 if (ihit == iseed1
or ihit == iseed2) {
521 if (not(
hits & (1 << (11 - ihit))))
525 if (
seed ==
"L1L2") {
526 if (ihit == 3
or ihit == 10)
528 if (ihit == 4
or ihit == 9)
530 if (ihit == 5
or ihit == 8)
532 if (ihit == 6
or ihit == 7)
534 }
else if (
seed ==
"L3L4") {
539 if (ihit == 5
or ihit == 8)
541 if (ihit == 6
or ihit == 7)
543 }
else if (
seed ==
"L5L6") {
552 }
else if (
seed ==
"D1D2") {
559 if (ihit == 2
or ihit == 11)
561 }
else if (
seed ==
"D3D4") {
568 if (ihit == 2
or ihit == 11)
570 }
else if (
seed ==
"D1L1" or "D1L2") {
580 if (inputI >= 0 and inputI < (
int)
N_PROJ) {
581 itmprinvdphi[inputI] = der.irinvdphi(ider);
582 itmprinvdzordr[inputI] = der.irinvdzordr(ider);
583 itmpphi0dphi[inputI] = der.iphi0dphi(ider);
584 itmpphi0dzordr[inputI] = der.iphi0dzordr(ider);
585 itmptdphi[inputI] = der.itdphi(ider);
586 itmptdzordr[inputI] = der.itdzordr(ider);
587 itmpz0dphi[inputI] = der.iz0dphi(ider);
588 itmpz0dzordr[inputI] = der.iz0dzordr(ider);
597 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
598 if (itmprinvdphi[
j] > (1 << 13))
599 itmprinvdphi[
j] = (1 << 13) - 1;
600 tmprinvdphi[
j].
set(itmprinvdphi[
j], 14,
false, __LINE__, __FILE__);
602 outrinvdphi[
i] << tmprinvdphi[0].
str() << tmprinvdphi[1].
str() << tmprinvdphi[2].
str() << tmprinvdphi[3].
str()
606 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
607 if (itmprinvdzordr[
j] > (1 << 15))
608 itmprinvdzordr[
j] = (1 << 15) - 1;
609 tmprinvdzordr[
j].
set(itmprinvdzordr[
j], 16,
false, __LINE__, __FILE__);
611 outrinvdzordr[
i] << tmprinvdzordr[0].
str() << tmprinvdzordr[1].
str() << tmprinvdzordr[2].
str()
612 << tmprinvdzordr[3].
str() << endl;
615 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
616 if (itmpphi0dphi[
j] > (1 << 13))
617 itmpphi0dphi[
j] = (1 << 13) - 1;
618 tmpphi0dphi[
j].
set(itmpphi0dphi[
j], 14,
false, __LINE__, __FILE__);
620 outphi0dphi[
i] << tmpphi0dphi[0].
str() << tmpphi0dphi[1].
str() << tmpphi0dphi[2].
str() << tmpphi0dphi[3].
str()
624 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
625 if (itmpphi0dzordr[
j] > (1 << 15))
626 itmpphi0dzordr[
j] = (1 << 15) - 1;
627 tmpphi0dzordr[
j].
set(itmpphi0dzordr[
j], 16,
false, __LINE__, __FILE__);
629 outphi0dzordr[
i] << tmpphi0dzordr[0].
str() << tmpphi0dzordr[1].
str() << tmpphi0dzordr[2].
str()
630 << tmpphi0dzordr[3].
str() << endl;
633 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
634 if (itmptdphi[
j] > (1 << 13))
635 itmptdphi[
j] = (1 << 13) - 1;
636 tmptdphi[
j].
set(itmptdphi[
j], 14,
false, __LINE__, __FILE__);
638 outtdphi[
i] << tmptdphi[0].
str() << tmptdphi[1].
str() << tmptdphi[2].
str() << tmptdphi[3].
str() << endl;
641 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
642 if (itmptdzordr[
j] > (1 << 15))
643 itmptdzordr[
j] = (1 << 15) - 1;
644 tmptdzordr[
j].
set(itmptdzordr[
j], 16,
false, __LINE__, __FILE__);
646 outtdzordr[
i] << tmptdzordr[0].
str() << tmptdzordr[1].
str() << tmptdzordr[2].
str() << tmptdzordr[3].
str()
650 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
651 if (itmpz0dphi[
j] > (1 << 13))
652 itmpz0dphi[
j] = (1 << 13) - 1;
653 tmpz0dphi[
j].
set(itmpz0dphi[
j], 14,
false, __LINE__, __FILE__);
655 outz0dphi[
i] << tmpz0dphi[0].
str() << tmpz0dphi[1].
str() << tmpz0dphi[2].
str() << tmpz0dphi[3].
str() << endl;
658 for (
unsigned int j = 0;
j <
N_PROJ; ++
j) {
659 if (itmpz0dzordr[
j] > (1 << 15))
660 itmpz0dzordr[
j] = (1 << 15) - 1;
661 tmpz0dzordr[
j].
set(itmpz0dzordr[
j], 16,
false, __LINE__, __FILE__);
663 outz0dzordr[
i] << tmpz0dzordr[0].
str() << tmpz0dzordr[1].
str() << tmpz0dzordr[2].
str() << tmpz0dzordr[3].
str()
673 outrinvdphi[
i].close();
674 outrinvdzordr[
i].close();
675 outphi0dphi[
i].close();
676 outphi0dzordr[
i].close();
678 outtdzordr[
i].close();
679 outz0dphi[
i].close();
680 outz0dzordr[
i].close();
689 unsigned int i,
j,
k;
692 for (
i = 0;
i <
n;
i++) {
693 for (
j =
n;
j < 2 *
n;
j++) {
701 for (
i = 0;
i <
n;
i++) {
702 for (
j = 0;
j <
n;
j++) {
705 for (
k = 0;
k < 2 *
n;
k++) {
712 for (
i = 0;
i <
n;
i++) {
714 for (
j = 0;
j < 2 *
n;
j++) {
724 unsigned int i,
j,
k;
727 for (
i = 0;
i <
n;
i++) {
728 for (
j =
n;
j < 2 *
n;
j++) {
736 for (
i = 0;
i <
n;
i++) {
737 for (
j = 0;
j <
n;
j++) {
740 for (
k = 0;
k < 2 *
n;
k++) {
747 for (
i = 0;
i <
n;
i++) {
749 for (
j = 0;
j < 2 *
n;
j++) {
773 double sigmazpsbarrel = sigmaz;
775 sigmazpsbarrel = sigmaz *
std::abs(
t) / 2.0;
800 D[0][
j] = -0.5 * ri * ri /
sqrt(1 - 0.25 * ri * ri *
rinv *
rinv) / sigmax;
801 D[1][
j] = ri / sigmax;
805 kfactor[
j] = settings.
kphi1();
810 if (ri < settings.
rPS2S()) {
811 D[2][
j] = (2 /
rinv) * asin(0.5 * ri *
rinv) / sigmazpsbarrel;
812 D[3][
j] = 1.0 / sigmazpsbarrel;
813 sigma[
j] = sigmazpsbarrel;
814 kfactor[
j] = settings.
kz();
816 D[2][
j] = (2 /
rinv) * asin(0.5 * ri *
rinv) / sigmaz2;
817 D[3][
j] = 1.0 / sigmaz2;
819 kfactor[
j] = settings.
kz();
825 for (
unsigned int i = 0;
i < ndisks;
i++) {
830 double rmultiplier =
alpha[
i] * zi /
t;
832 double phimultiplier = zi /
t;
837 double drdt = -(zi -
z0) *
cos(0.5 *
rinv * (zi -
z0) /
t) / (
t *
t);
838 double drdz0 = -
cos(0.5 *
rinv * (zi -
z0) /
t) /
t;
840 double dphidrinv = -0.5 * (zi -
z0) /
t;
841 double dphidphi0 = 1.0;
842 double dphidt = 0.5 *
rinv * (zi -
z0) / (
t *
t);
843 double dphidz0 = 0.5 *
rinv /
t;
845 double r = (zi -
z0) /
t;
849 sigma[
j] = sigmax2sdisk;
851 sigma[
j] = sigmaxpsdisk;
854 D[0][
j] = (phimultiplier * dphidrinv + rmultiplier * drdrinv) / sigma[
j];
855 D[1][
j] = (phimultiplier * dphidphi0 + rmultiplier * drdphi0) / sigma[
j];
856 D[2][
j] = (phimultiplier * dphidt + rmultiplier * drdt) / sigma[
j];
857 D[3][
j] = (phimultiplier * dphidz0 + rmultiplier * drdz0) / sigma[
j];
858 kfactor[
j] = settings.
kphi();
863 D[0][
j] = drdrinv / sigmazpsdisk;
864 D[1][
j] = drdphi0 / sigmazpsdisk;
865 D[2][
j] = drdt / sigmazpsdisk;
866 D[3][
j] = drdz0 / sigmazpsdisk;
867 sigma[
j] = sigmazpsdisk;
868 kfactor[
j] = settings.
kr();
870 D[0][
j] = drdrinv / sigmaz2sdisk;
871 D[1][
j] = drdphi0 / sigmaz2sdisk;
872 D[2][
j] = drdt / sigmaz2sdisk;
873 D[3][
j] = drdz0 / sigmaz2sdisk;
874 sigma[
j] = sigmaz2sdisk;
875 kfactor[
j] = settings.
kr();
883 for (
unsigned int i1 = 0;
i1 < 4;
i1++) {
884 for (
unsigned int i2 = 0;
i2 < 4;
i2++) {
886 for (
unsigned int j = 0;
j < 2 *
n;
j++) {
901 for (
unsigned int j = 0;
j < 2 *
n;
j++) {
902 for (
unsigned int i1 = 0;
i1 < 4;
i1++) {
903 for (
unsigned int i2 = 0;
i2 < 4;
i2++) {
909 for (
unsigned int i = 0;
i <
n;
i++) {
930 MinvDt[0][2 *
i] *= rnew[
i] / sigmax;
931 MinvDt[1][2 *
i] *= rnew[
i] / sigmax;
932 MinvDt[2][2 *
i] *= rnew[
i] / sigmax;
933 MinvDt[3][2 *
i] *= rnew[
i] / sigmax;
942 if (rnew[
i] < settings.
rPS2S()) {
943 MinvDt[0][2 *
i + 1] /= sigmazpsbarrel;
944 MinvDt[1][2 *
i + 1] /= sigmazpsbarrel;
945 MinvDt[2][2 *
i + 1] /= sigmazpsbarrel;
946 MinvDt[3][2 *
i + 1] /= sigmazpsbarrel;
948 iMinvDt[0][2 *
i + 1] =
950 iMinvDt[1][2 *
i + 1] =
952 iMinvDt[2][2 *
i + 1] =
954 iMinvDt[3][2 *
i + 1] =
957 MinvDt[0][2 *
i + 1] /= sigmaz2;
958 MinvDt[1][2 *
i + 1] /= sigmaz2;
959 MinvDt[2][2 *
i + 1] /= sigmaz2;
960 MinvDt[3][2 *
i + 1] /= sigmaz2;
964 iMinvDt[0][2 *
i + 1] =
966 iMinvDt[1][2 *
i + 1] =
968 iMinvDt[2][2 *
i + 1] =
970 iMinvDt[3][2 *
i + 1] =
979 MinvDt[0][2 *
i] *= (rnew[
i] /
denom);
980 MinvDt[1][2 *
i] *= (rnew[
i] /
denom);
981 MinvDt[2][2 *
i] *= (rnew[
i] /
denom);
982 MinvDt[3][2 *
i] *= (rnew[
i] /
denom);
984 assert(MinvDt[0][2 *
i] == MinvDt[0][2 *
i]);
989 iMinvDt[3][2 *
i] = (1 << settings.
fitz0bitshift()) * MinvDt[3][2 *
i] * settings.
kphi() / settings.
kz();
993 MinvDt[0][2 *
i + 1] /=
denom;
994 MinvDt[1][2 *
i + 1] /=
denom;
995 MinvDt[2][2 *
i + 1] /=
denom;
996 MinvDt[3][2 *
i + 1] /=
denom;
998 iMinvDt[0][2 *
i + 1] =
1000 iMinvDt[1][2 *
i + 1] =
1002 iMinvDt[2][2 *
i + 1] =
1004 iMinvDt[3][2 *
i + 1] =
1014 double tmax = 1000.0;
1018 if (diskmask & (1 << (2 * (5 -
d) + 1))) {
1019 double dmax = settings.
zmean(
d - 1) / 22.0;
1020 if (dmax > sinh(2.4))
1022 double dmin = settings.
zmean(
d - 1) / 65.0;
1029 if (diskmask & (1 << (2 * (5 -
d)))) {
1030 double dmax = settings.
zmean(
d - 1) / 65.0;
1031 double dmin = settings.
zmean(
d - 1) / 105.0;
1040 if (layermask & (1 << (6 -
l))) {