22 if (
output ==
"trackout") {
29 throw cms::Exception(
"BadConfig") << __FILE__ <<
" " << __LINE__ <<
" addOutput, output = " <<
output <<
" not known";
37 if (
input.substr(0, 4) ==
"tpar") {
38 auto*
tmp = dynamic_cast<TrackletParametersMemory*>(
memory);
43 if (
input.substr(0, 10) ==
"fullmatch1") {
44 auto*
tmp = dynamic_cast<FullMatchMemory*>(
memory);
49 if (
input.substr(0, 10) ==
"fullmatch2") {
50 auto*
tmp = dynamic_cast<FullMatchMemory*>(
memory);
55 if (
input.substr(0, 10) ==
"fullmatch3") {
56 auto*
tmp = dynamic_cast<FullMatchMemory*>(
memory);
61 if (
input.substr(0, 10) ==
"fullmatch4") {
62 auto*
tmp = dynamic_cast<FullMatchMemory*>(
memory);
68 throw cms::Exception(
"BadConfig") << __FILE__ <<
" " << __LINE__ <<
" input = " <<
input <<
" not found";
73 std::vector<const Stub*>& trackstublist,
86 for (
unsigned int j = 0;
j <
i->nMatches();
j++) {
87 if (
i->getTracklet(
j)->TCID() == tracklet->
TCID()) {
88 trackstublist.push_back(
i->getMatch(
j).second);
94 for (
unsigned int j = 0;
j <
i->nMatches();
j++) {
95 if (
i->getTracklet(
j)->TCID() == tracklet->
TCID()) {
96 trackstublist.push_back(
i->getMatch(
j).second);
102 for (
unsigned int j = 0;
j <
i->nMatches();
j++) {
103 if (
i->getTracklet(
j)->TCID() == tracklet->
TCID()) {
104 trackstublist.push_back(
i->getMatch(
j).second);
110 for (
unsigned int j = 0;
j <
i->nMatches();
j++) {
111 if (
i->getTracklet(
j)->TCID() == tracklet->
TCID()) {
112 trackstublist.push_back(
i->getMatch(
j).second);
119 for (
const auto& it : trackstublist) {
120 int layer = it->layer().value() + 1;
121 if (it->layer().value() < 0) {
122 layer = it->disk().value() + 10 * it->disk().value() /
abs(it->disk().value());
124 stubidslist.push_back(std::make_pair(layer, it->phiregionaddress()));
132 hybridFitter.Fit(tracklet, trackstublist);
160 unsigned int ndisks = 0;
178 phiresidexact[
i] = 0.0;
179 zresidexact[
i] = 0.0;
182 std::bitset<N_LAYER> lmatches;
183 std::bitset<N_DISK * 2> dmatches;
187 unsigned int layermask = 0;
188 unsigned int diskmask = 0;
189 unsigned int alphaindex = 0;
190 unsigned int power = 1;
192 double t = tracklet->
t();
197 if (
l == (
unsigned int)tracklet->
layer() ||
l == (
unsigned int)tracklet->
layer() + 1) {
217 for (
unsigned int d = 1;
d <=
N_DISK;
d++) {
218 if (layermask & (1 << (
d - 1)))
228 dmatches.set(2 *
d - 1);
229 diskmask |= (1 << (2 * (
N_DISK -
d) + 1));
236 alphaindex += ialpha * power;
238 dmatches.set(2 * (
N_DISK -
d));
239 diskmask |= (1 << (2 * (
N_DISK -
d)));
257 << lmatches.to_string() <<
" " << dmatches.to_string() <<
" " <<
mult << endl;
263 for (
unsigned int l = 1;
l <= 2;
l++) {
284 if (
d == 5 and layermask & (1 << 4))
290 dmatches.set(2 *
d1 - 1);
291 diskmask |= (1 << (2 * (
N_DISK -
d1) + 1));
301 dmatches.set(2 *
d1 - 1);
302 diskmask |= (1 << (2 * (
N_DISK -
d1) + 1));
309 alphaindex += ialpha * power;
312 diskmask |= (1 << (2 * (
N_DISK -
d1)));
332 for (
unsigned int l = 1;
l <= 2;
l++) {
333 if (
l == (
unsigned int)tracklet->
layer()) {
361 if (
d == tracklet->
disk()) {
363 dmatches.set(2 *
d1 - 1);
364 diskmask |= (1 << (2 * (
N_DISK -
d1) + 1));
374 diskmask |= (1 << (2 * (
N_DISK -
d1) + 1));
376 tmp.set(diskmask, 10);
383 alphaindex += ialpha * power;
386 diskmask |= (1 << (2 * (
N_DISK -
d1)));
388 tmp.set(diskmask, 10);
416 if (derivatives ==
nullptr) {
419 tmpl.
set(layermask, 6);
420 tmpd.
set(diskmask, 10);
421 edm::LogVerbatim(
"Tracklet") <<
"No derivative for layermask, diskmask : " << layermask <<
" " << tmpl.
str()
422 <<
" " << diskmask <<
" " << tmpd.
str() <<
" eta = " << asinh(
t);
466 for (
unsigned i = 0;
i < ndisks;
i++) {
482 settings_,
nlayers,
r, ndisks, z,
alpha,
t,
rinv,
D, iD, MinvDt, iMinvDt, sigma,
kfactor);
488 settings_,
nlayers,
r, ndisks, z,
alpha,
t,
rinv,
D, iD, MinvDt, iMinvDt, sigma,
kfactor);
491 derivatives->
fill(tracklet->
fpgat().
value(), MinvDtDummy, iMinvDt);
509 double dr = realrstub[
i] -
r[
i];
511 MinvDt[2][2 *
ii + 1] +=
dr * tder;
512 MinvDt[3][2 *
ii + 1] +=
dr * zder;
527 double tseed = tracklet->
tapprox();
528 double z0seed = tracklet->
z0approx();
530 double rinvseedexact = tracklet->
rinv();
531 double phi0seedexact = tracklet->
phi0();
532 double tseedexact = tracklet->
t();
533 double z0seedexact = tracklet->
z0();
535 double chisqseed = 0.0;
536 double chisqseedexact = 0.0;
550 for (
unsigned int i = 0;
i <
n;
i++) {
552 iphiresid[
i] *= (
t / ttabi);
553 phiresid[
i] *= (
t / ttab);
554 phiresidexact[
i] *= (
t / ttab);
557 idelta[
j] = iphiresid[
i];
565 deltaexact[
j++] = phiresidexact[
i];
567 idelta[
j] = izresid[
i];
569 deltaexact[
j++] = zresidexact[
i];
572 chisqseedexact += (deltaexact[
j - 2] * deltaexact[
j - 2] + deltaexact[
j - 1] * deltaexact[
j - 1]);
581 double drinvexact = 0.0;
582 double dphi0exact = 0.0;
583 double dtexact = 0.0;
584 double dz0exact = 0.0;
591 double drinv_cov = 0.0;
592 double dphi0_cov = 0.0;
594 double dz0_cov = 0.0;
596 double drinv_covexact = 0.0;
597 double dphi0_covexact = 0.0;
598 double dt_covexact = 0.0;
599 double dz0_covexact = 0.0;
601 for (
unsigned int j = 0;
j < 2 *
n;
j++) {
602 drinv -= MinvDt[0][
j] *
delta[
j];
603 dphi0 -= MinvDt[1][
j] *
delta[
j];
605 dz0 -= MinvDt[3][
j] *
delta[
j];
612 drinvexact -= MinvDt[0][
j] * deltaexact[
j];
613 dphi0exact -= MinvDt[1][
j] * deltaexact[
j];
614 dtexact -= MinvDt[2][
j] * deltaexact[
j];
615 dz0exact -= MinvDt[3][
j] * deltaexact[
j];
617 drinv_covexact +=
D[0][
j] * deltaexact[
j];
618 dphi0_covexact +=
D[1][
j] * deltaexact[
j];
619 dt_covexact +=
D[2][
j] * deltaexact[
j];
620 dz0_covexact +=
D[3][
j] * deltaexact[
j];
622 idrinv += ((iMinvDt[0][
j] * idelta[
j]));
623 idphi0 += ((iMinvDt[1][
j] * idelta[
j]));
624 idt += ((iMinvDt[2][
j] * idelta[
j]));
625 idz0 += ((iMinvDt[3][
j] * idelta[
j]));
627 if (
false &&
j % 2 == 0) {
629 <<
" " << MinvDt[0][
j] <<
" " <<
delta[
j] * rstub[
j / 2] * 10000 <<
" \n"
637 double deltaChisqexact =
638 drinvexact * drinv_covexact + dphi0exact * dphi0_covexact + dtexact * dt_covexact + dz0exact * dz0_covexact;
653 double rinvfit = rinvseed - drinv;
654 double phi0fit = phi0seed - dphi0;
656 double tfit = tseed -
dt;
657 double z0fit = z0seed - dz0;
659 double rinvfitexact = rinvseedexact - drinvexact;
660 double phi0fitexact = phi0seedexact - dphi0exact;
662 double tfitexact = tseedexact - dtexact;
663 double z0fitexact = z0seedexact - dz0exact;
665 double chisqfitexact = chisqseedexact + deltaChisqexact;
668 bool NewChisqDebug =
false;
669 double chisqfit = 0.0;
680 <<
"drinv/cov = " << drinv <<
"/" << drinv_cov <<
" \n"
681 <<
"dphi0/cov = " << drinv <<
"/" << dphi0_cov <<
" \n"
682 <<
"dt/cov = " << drinv <<
"/" << dt_cov <<
" \n"
683 <<
"dz0/cov = " << drinv <<
"/" << dz0_cov <<
"\n";
685 for (
unsigned int i = 0;
i < 2 *
n;
i++) {
686 myout += std::to_string(
D[0][
i]);
692 for (
unsigned int i = 0;
i <
n;
i++) {
694 phifactor = rstub[
k / 2] *
delta[
k] / sigma[
k] +
D[0][
k] * drinv +
D[1][
k] * dphi0 +
D[2][
k] *
dt +
D[3][
k] * dz0;
696 iD[0][
k] * idrinv - iD[1][
k] * idphi0 - iD[2][
k] * idt - iD[3][
k] * idz0;
700 <<
"sum = " << phifactor -
delta[
k] / sigma[
k] <<
" drinvterm = " <<
D[0][
k] * drinv
701 <<
" dphi0term = " <<
D[1][
k] * dphi0 <<
" dtterm = " <<
D[2][
k] *
dt
702 <<
" dz0term = " <<
D[3][
k] * dz0 <<
"\n phifactor = " << phifactor;
705 chisqfit += phifactor * phifactor;
710 rzfactor =
delta[
k] / sigma[
k] +
D[0][
k] * drinv +
D[1][
k] * dphi0 +
D[2][
k] *
dt +
D[3][
k] * dz0;
712 iD[1][
k] * idphi0 - iD[2][
k] * idt - iD[3][
k] * idz0;
716 <<
"sum = " << rzfactor -
delta[
k] / sigma[
k] <<
" drinvterm = " <<
D[0][
k] * drinv
717 <<
" dphi0term = " <<
D[1][
k] * dphi0 <<
" dtterm = " <<
D[2][
k] *
dt
718 <<
" dz0term = " <<
D[3][
k] * dz0 <<
"\n rzfactor = " << rzfactor;
721 chisqfit += rzfactor * rzfactor;
733 if (ichisqfit >= (1 << 15)) {
735 edm::LogVerbatim(
"Tracklet") <<
"CHISQUARE (" << ichisqfit <<
") LARGER THAN 11 BITS!";
737 ichisqfit = (1 << 15) - 1;
741 ichisqfit = ichisqfit >> 7;
743 if (ichisqfit >= (1 << 8))
744 ichisqfit = (1 << 8) - 1;
746 double phicrit = phi0fit - asin(0.5 *
settings_.
rcrit() * rinvfit);
809 std::vector<Tracklet*>
tmp;
811 std::vector<unsigned int> indexArray;
812 for (
auto& imatch : fullmatch) {
814 if (imatch->nMatches() > 1) {
815 for (
unsigned int j = 0;
j < imatch->nMatches() - 1;
j++) {
816 assert(imatch->getTracklet(
j)->TCID() <= imatch->getTracklet(
j + 1)->TCID());
821 edm::LogVerbatim(
"Tracklet") <<
"orderedMatches: " << imatch->getName() <<
" " << imatch->nMatches();
824 indexArray.push_back(0);
829 int bestTCID = (1 << 16);
831 for (
unsigned int i = 0;
i < fullmatch.size();
i++) {
832 if (indexArray[
i] >= fullmatch[
i]->nMatches()) {
836 int TCID = fullmatch[
i]->getTracklet(indexArray[
i])->TCID();
837 if (TCID < bestTCID) {
842 if (bestIndex != -1) {
843 tmp.push_back(fullmatch[bestIndex]->getTracklet(indexArray[bestIndex]));
844 indexArray[bestIndex]++;
846 }
while (bestIndex != -1);
848 for (
unsigned int i = 0;
i <
tmp.size();
i++) {
852 if (
tmp[
i - 1]->TCID() >
tmp[
i]->TCID()) {
869 if (
settings_.
debugTracklet() && (matches1.size() + matches2.size() + matches3.size() + matches4.size()) > 0) {
871 edm::LogVerbatim(
"Tracklet") << imatch->getName() <<
" " << imatch->nMatches();
874 << matches2.size() <<
" " << matches3.size() <<
" " << matches4.size();
877 unsigned int indexArray[4];
878 for (
unsigned int i = 0;
i < 4;
i++) {
888 bestTracklet =
nullptr;
890 if (indexArray[0] < matches1.size()) {
891 if (bestTracklet ==
nullptr) {
892 bestTracklet = matches1[indexArray[0]];
894 if (matches1[indexArray[0]]->TCID() < bestTracklet->
TCID())
895 bestTracklet = matches1[indexArray[0]];
899 if (indexArray[1] < matches2.size()) {
900 if (bestTracklet ==
nullptr) {
901 bestTracklet = matches2[indexArray[1]];
903 if (matches2[indexArray[1]]->TCID() < bestTracklet->
TCID())
904 bestTracklet = matches2[indexArray[1]];
908 if (indexArray[2] < matches3.size()) {
909 if (bestTracklet ==
nullptr) {
910 bestTracklet = matches3[indexArray[2]];
912 if (matches3[indexArray[2]]->TCID() < bestTracklet->
TCID())
913 bestTracklet = matches3[indexArray[2]];
917 if (indexArray[3] < matches4.size()) {
918 if (bestTracklet ==
nullptr) {
919 bestTracklet = matches4[indexArray[3]];
921 if (matches4[indexArray[3]]->TCID() < bestTracklet->
TCID())
922 bestTracklet = matches4[indexArray[3]];
926 if (bestTracklet ==
nullptr)
933 int nMatchesUniq = 0;
936 while (indexArray[0] < matches1.size() && matches1[indexArray[0]] == bestTracklet) {
946 while (indexArray[1] < matches2.size() && matches2[indexArray[1]] == bestTracklet) {
956 while (indexArray[2] < matches3.size() && matches3[indexArray[2]] == bestTracklet) {
966 while (indexArray[3] < matches4.size() && matches4[indexArray[3]] == bestTracklet) {
976 edm::LogVerbatim(
"Tracklet") <<
getName() <<
" : nMatches = " << nMatches <<
" nMatchesUniq = " << nMatchesUniq
977 <<
" " << asinh(bestTracklet->
t());
980 std::vector<const Stub*> trackstublist;
981 std::vector<std::pair<int, int>> stubidslist;
982 if ((bestTracklet->
getISeed() >= 8 && nMatchesUniq >= 1) ||
987 trackFitKF(bestTracklet, trackstublist, stubidslist);
1000 }
else if (bestTracklet->
fit()) {
1003 ofstream
fout(
"seeds.txt", ofstream::app);
1012 }
while (bestTracklet !=
nullptr);