5 : verbose_(settings.getParameter<
bool>(
"verbose")),
7 initK_(settings.getParameter<
std::vector<double> >(
"initialK")),
8 initK2_(settings.getParameter<
std::vector<double> >(
"initialK2")),
9 eLoss_(settings.getParameter<
std::vector<double> >(
"eLoss")),
10 aPhi_(settings.getParameter<
std::vector<double> >(
"aPhi")),
11 aPhiB_(settings.getParameter<
std::vector<double> >(
"aPhiB")),
12 aPhiBNLO_(settings.getParameter<
std::vector<double> >(
"aPhiBNLO")),
13 bPhi_(settings.getParameter<
std::vector<double> >(
"bPhi")),
14 bPhiB_(settings.getParameter<
std::vector<double> >(
"bPhiB")),
15 phiAt2_(settings.getParameter<double>(
"phiAt2")),
17 chiSquare_(settings.getParameter<
std::vector<double> >(
"chiSquare")),
18 chiSquareCutPattern_(settings.getParameter<
std::vector<
int> >(
"chiSquareCutPattern")),
19 chiSquareCutCurv_(settings.getParameter<
std::vector<
int> >(
"chiSquareCutCurvMax")),
20 chiSquareCut_(settings.getParameter<
std::vector<
int> >(
"chiSquareCut")),
21 trackComp_(settings.getParameter<
std::vector<double> >(
"trackComp")),
22 trackCompErr1_(settings.getParameter<
std::vector<double> >(
"trackCompErr1")),
23 trackCompErr2_(settings.getParameter<
std::vector<double> >(
"trackCompErr2")),
24 trackCompPattern_(settings.getParameter<
std::vector<
int> >(
"trackCompCutPattern")),
25 trackCompCutCurv_(settings.getParameter<
std::vector<
int> >(
"trackCompCutCurvMax")),
26 trackCompCut_(settings.getParameter<
std::vector<
int> >(
"trackCompCut")),
27 chiSquareCutTight_(settings.getParameter<
std::vector<
int> >(
"chiSquareCutTight")),
28 combos4_(settings.getParameter<
std::vector<
int> >(
"combos4")),
29 combos3_(settings.getParameter<
std::vector<
int> >(
"combos3")),
30 combos2_(settings.getParameter<
std::vector<
int> >(
"combos2")),
31 combos1_(settings.getParameter<
std::vector<
int> >(
"combos1")),
32 useOfflineAlgo_(settings.getParameter<
bool>(
"useOfflineAlgo")),
33 mScatteringPhi_(settings.getParameter<
std::vector<double> >(
"mScatteringPhi")),
34 mScatteringPhiB_(settings.getParameter<
std::vector<double> >(
"mScatteringPhiB")),
35 pointResolutionPhi_(settings.getParameter<double>(
"pointResolutionPhi")),
36 pointResolutionPhiB_(settings.getParameter<double>(
"pointResolutionPhiB")),
37 pointResolutionVertex_(settings.getParameter<double>(
"pointResolutionVertex"))
45 return std::make_pair(
true,
i);
47 return std::make_pair(
false, 0);
56 if (
track.curvatureAtVertex() == 0) {
59 }
else if (
track.curvatureAtVertex() > 0) {
90 int phi2 =
track.phiAtMuon() >> 2;
94 int processor =
track.sector();
108 muon.setHwPtUnconstrained(
pt2);
115 word1 = word1 |
HF << 22;
118 uint32_t word2 =
sign;
119 word2 = word2 | signValid << 1;
120 word2 = word2 |
dxy << 2;
121 word2 = word2 | trackAddr << 4;
123 word2 = word2 |
pt2 << 23;
124 muon.setDataword(word2, word1);
130 std::unique_ptr<l1t::RegionalMuonCandBxCollection>&
out) {
168 std::map<uint, uint> diffInfo;
169 for (
uint i = 0;
i < 12; ++
i) {
173 std::map<uint, uint> stubInfo;
175 int sector =
seed->scNum();
176 int previousSector = sector - 1;
177 int nextSector = sector + 1;
200 for (
const auto& stub : stubs) {
203 if (stub->stNum() !=
step)
209 if (stub->scNum() == previousSector) {
210 if (stub->whNum() ==
wheel) {
218 }
else if (stub->whNum() == innerWheel) {
227 }
else if (stub->scNum() == sector) {
228 if (stub->whNum() ==
wheel) {
236 }
else if (stub->whNum() == innerWheel) {
245 }
else if (stub->scNum() == nextSector) {
246 if (stub->whNum() ==
wheel) {
254 }
else if (stub->whNum() == innerWheel) {
257 stubInfo[10] =
N - 1;
260 stubInfo[11] =
N - 1;
281 if (diffInfo[s4] != 60000)
282 return std::make_pair(
true, stubInfo[s4]);
284 return std::make_pair(
false, 0);
289 return 8 * stub->phiB();
293 if (stub->scNum() == sector) {
295 }
else if ((stub->scNum() == sector - 1) || (stub->scNum() == 11 && sector == 0)) {
296 return stub->phi() - 2144;
297 }
else if ((stub->scNum() == sector + 1) || (stub->scNum() == 0 && sector == 11)) {
298 return stub->phi() + 2144;
304 unsigned int mask = 0;
305 for (
const auto& stub :
track.stubs()) {
306 mask = mask + round(
pow(2, stub->stNum() - 1));
312 return bit1 * 1 + bit2 * 2 + bit3 * 4 + bit4 * 8;
318 int K =
track.curvature();
320 int phiB =
track.bendingAngle();
341 int addr = KBound / 2;
343 addr = (-KBound) / 2;
347 printf(
"propagate to vertex K=%d deltaK=%d addr=%d\n", K, deltaK,
addr);
359 printf(
"phi prop = %d* %f = %d, %d* %f =%d\n", K,
aPhi_[
step - 1], phi11, phiB, -
bPhi_[
step - 1], phi12);
365 int phiBNew =
wrapAround(phiB11 + phiB12, 4096);
367 printf(
"phiB prop = %d* %f = %d, %d* %f =%d\n", K,
aPhiB_[
step - 1], phiB11, phiB,
bPhiB_[
step - 1], phiB12);
372 int addr = KBound / 2;
397 ROOT::Math::SMatrix<double, 3>
P(
a, 9);
399 const std::vector<double>& covLine =
track.covariance();
401 cov = ROOT::Math::Similarity(
P, cov);
407 std::vector<double>
b(6);
420 printf(
"Covariance term for phiB = %f\n", cov(2, 2));
421 printf(
"Multiple scattering term for phiB = %f\n", MS(2, 2));
424 track.setCovariance(cov);
425 track.setCoordinates(
step - 1, KNew, phiNew, phiBNew);
431 if (mask == 3 || mask == 5 || mask == 9 || mask == 6 || mask == 10 || mask == 12)
441 int trackK =
track.curvature();
443 int trackPhiB =
track.bendingAngle();
450 residual[1] = phiB - trackPhiB;
466 const std::vector<double>& covLine =
track.covariance();
475 track.step(), fabs(trackK),
Gain(0, 0),
Gain(0, 1),
Gain(1, 0),
Gain(1, 1),
Gain(2, 0),
Gain(2, 1));
477 int KNew = (trackK +
int(
Gain(0, 0) * residual(0) +
Gain(0, 1) * residual(1)));
478 if (fabs(KNew) > 8192)
482 int phiBNew =
wrapAround(trackPhiB +
int(
Gain(2, 0) * residual(0) +
Gain(2, 1) * residual(1)), 4096);
484 track.setResidual(stub->stNum() - 1, fabs(
phi - phiNew) + fabs(phiB - phiBNew) / 8);
487 printf(
" K = %d + %f * %f + %f * %f\n", trackK,
Gain(0, 0), residual(0),
Gain(0, 1), residual(1));
488 printf(
" phiB = %d + %f * %f + %f * %f\n", trackPhiB,
Gain(2, 0), residual(0),
Gain(2, 1), residual(1));
491 track.setCoordinates(
track.step(), KNew, phiNew, phiBNew);
495 c(0, 0) = covNew(0, 0);
496 c(0, 1) = covNew(0, 1);
497 c(0, 2) = covNew(0, 2);
498 c(1, 0) = covNew(1, 0);
499 c(1, 1) = covNew(1, 1);
500 c(1, 2) = covNew(1, 2);
501 c(2, 0) = covNew(2, 0);
502 c(2, 1) = covNew(2, 1);
503 c(2, 2) = covNew(2, 2);
505 printf(
"Post Fit Covariance Matrix %f %f %f \n", cov(0, 0), cov(1, 1), cov(2, 2));
516 int trackK =
track.curvature();
518 int trackPhiB =
track.bendingAngle();
529 const std::vector<double>& covLine =
track.covariance();
538 track.setKalmanGain(
track.step(), fabs(trackK),
Gain(0, 0), 0.0,
Gain(1, 0), 0.0,
Gain(2, 0), 0.0);
542 int phiBNew =
wrapAround(trackPhiB +
int(
Gain(2, 0) * residual), 4096);
543 track.setCoordinates(
track.step(), KNew, phiNew, phiBNew);
547 c(0, 0) = covNew(0, 0);
548 c(0, 1) = covNew(0, 1);
549 c(0, 2) = covNew(0, 2);
550 c(1, 0) = covNew(1, 0);
551 c(1, 1) = covNew(1, 1);
552 c(1, 2) = covNew(1, 2);
553 c(2, 0) = covNew(2, 0);
554 c(2, 1) = covNew(2, 1);
555 c(2, 2) = covNew(2, 2);
564 int trackK =
track.curvature();
566 int trackPhiB =
track.bendingAngle();
571 if (stub->quality() < 4)
576 int residualPhiB =
wrapAround(phiB - trackPhiB, 8192);
579 printf(
"residuals %d-%d=%d %d-%d=%d\n",
phi,
trackPhi,
int(residualPhi), phiB, trackPhiB,
int(residualPhiB));
581 uint absK = fabs(trackK);
585 std::vector<float> GAIN;
587 if (!(mask == 3 || mask == 5 || mask == 9 || mask == 6 || mask == 10 || mask == 12)) {
596 printf(
"Gains:%d %f %f %f %f\n", absK / 4, GAIN[0], GAIN[1], GAIN[2], GAIN[3]);
597 track.setKalmanGain(
track.step(), fabs(trackK), GAIN[0], GAIN[1], 1, 0, GAIN[2], GAIN[3]);
599 int k_0 =
fp_product(GAIN[0], residualPhi, 3);
600 int k_1 =
fp_product(GAIN[1], residualPhiB, 5);
601 int KNew = trackK + k_0 + k_1;
602 if (fabs(KNew) >= 8191)
608 int pbdouble_0 =
fp_product(fabs(GAIN[2]), residualPhi, 9);
609 int pb_0 =
fp_product(GAIN[2], residualPhi, 9);
610 int pb_1 =
fp_product(GAIN[3], residualPhiB, 9);
613 printf(
"phiupdate: %d %d\n", pb_0, pb_1);
616 if (!(mask == 3 || mask == 5 || mask == 9 || mask == 6 || mask == 10 || mask == 12)) {
618 if (fabs(trackPhiB + pb_0) >= 4095)
621 phiBNew =
wrapAround(trackPhiB + pb_1 - pbdouble_0, 4096);
622 if (fabs(trackPhiB + pb_1 - pbdouble_0) >= 4095)
625 track.setCoordinates(
track.step(), KNew, phiNew, phiBNew);
641 double residual = -
track.dxy();
647 const std::vector<double>& covLine =
track.covariance();
656 printf(
"sigma3=%f sigma6=%f\n", cov(0, 3), cov(3, 3));
657 printf(
" K = %d + %f * %f\n",
track.curvature(),
Gain(0, 0), residual);
664 printf(
"Post fit impact parameter=%d\n", dxyNew);
665 track.setCoordinatesAtVertex(KNew, phiNew, -residual);
668 c(0, 0) = covNew(0, 0);
669 c(0, 1) = covNew(0, 1);
670 c(0, 2) = covNew(0, 2);
671 c(1, 0) = covNew(1, 0);
672 c(1, 1) = covNew(1, 1);
673 c(1, 2) = covNew(1, 2);
674 c(2, 0) = covNew(2, 0);
675 c(2, 1) = covNew(2, 1);
676 c(2, 2) = covNew(2, 2);
682 double residual = -
track.dxy();
688 track.setKalmanGain(
track.step(), fabs(
track.curvature()), GAIN.first, GAIN.second, -1);
690 int k_0 =
fp_product(GAIN.first,
int(residual), 7);
694 printf(
"VERTEX GAIN(%d)= %f * %d = %d\n", absK / 2, GAIN.first,
int(residual), k_0);
697 int p_0 =
fp_product(GAIN.second,
int(residual), 7);
699 track.setCoordinatesAtVertex(KNew, phiNew, -residual);
705 if (
track.hasFineEta())
706 etaINT =
track.fineEta();
708 etaINT =
track.coarseEta();
710 double lsb = 1.25 /
float(1 << 13);
711 double lsbEta = 0.010875;
715 if (
track.curvatureAtVertex() < 0)
717 double pt = double(
ptLUT(
track.curvatureAtVertex())) / 2.0;
721 double eta = etaINT * lsbEta;
725 K =
track.curvatureAtMuon();
730 K = 46 * K / fabs(K);
731 double pt = 1.0 / (lsb * fabs(K));
741 std::vector<int> combinatorics;
742 switch (
seed->stNum()) {
759 printf(
"Something really bad happend\n");
764 for (
const auto& mask : combinatorics) {
771 charge = phiB / fabs(phiB);
774 if (
track.step() == 4 && (fabs(
seed->phiB()) > 15))
775 address =
charge * 15 * 8;
777 if (
track.step() == 3 && (fabs(
seed->phiB()) > 30))
778 address =
charge * 30 * 8;
779 if (
track.step() == 2 && (fabs(
seed->phiB()) > 127))
780 address =
charge * 127 * 8;
788 if (
seed->quality() < 4) {
796 float DK = 512 * 512.;
797 covariance(0, 0) = DK;
798 covariance(0, 1) = 0;
799 covariance(0, 2) = 0;
800 covariance(1, 0) = 0;
802 covariance(1, 2) = 0;
803 covariance(2, 0) = 0;
804 covariance(2, 1) = 0;
806 track.setCovariance(covariance);
809 printf(
"New Kalman fit staring at step=%d, phi=%d,phiB=%d with curvature=%d\n",
811 track.positionAngle(),
812 track.bendingAngle(),
815 for (
unsigned int i = 0;
i < 4; ++
i)
818 printf(
"------------------------------------------------------\n");
819 printf(
"------------------------------------------------------\n");
820 printf(
"------------------------------------------------------\n");
822 for (
const auto& stub : stubs)
823 printf(
"station=%d phi=%d phiB=%d qual=%d tag=%d sector=%d wheel=%d fineEta= %d %d\n",
833 printf(
"------------------------------------------------------\n");
834 printf(
"------------------------------------------------------\n");
837 int phiAtStation2 = 0;
839 while (
track.step() > 0) {
841 if (
track.step() == 1) {
853 printf(
"Unconstrained PT in Muon System: pt=%f\n",
track.ptUnconstrained());
858 printf(
"propagated Coordinates step:%d,phi=%d,phiB=%d,K=%d\n",
860 track.positionAngle(),
861 track.bendingAngle(),
864 if (
track.step() > 0)
866 std::pair<bool, uint> bestStub =
match(
seed, stubs,
track.step());
867 if ((!bestStub.first) || (!
update(
track, stubs[bestStub.second], mask)))
870 printf(
"updated Coordinates step:%d,phi=%d,phiB=%d,K=%d\n",
872 track.positionAngle(),
873 track.bendingAngle(),
878 if (
track.step() == 0) {
881 printf(
" Coordinates before vertex constraint step:%d,phi=%d,dxy=%d,K=%d\n",
885 track.curvatureAtVertex());
887 printf(
"Chi Square = %d\n",
track.approxChi2());
892 printf(
" Coordinates after vertex constraint step:%d,phi=%d,dxy=%d,K=%d maximum local chi2=%d\n",
896 track.curvatureAtVertex(),
898 printf(
"------------------------------------------------------\n");
899 printf(
"------------------------------------------------------\n");
903 track.setCoordinatesAtMuon(
track.curvatureAtMuon(), phiAtStation2,
track.phiBAtMuon());
906 printf(
"Floating point coordinates at vertex: pt=%f, eta=%f phi=%f\n",
track.pt(),
track.eta(),
track.phi());
907 pretracks.push_back(
track);
914 if (!cleaned.empty()) {
915 return std::make_pair(
true, cleaned[0]);
917 return std::make_pair(
false, nullTrack);
923 int K =
track.curvatureAtMuon();
931 for (
const auto& stub :
track.stubs()) {
934 int diff1 =
wrapAround(stubCoords - coords, 1024);
938 printf(
"Chi Square stub for track with coords=%d -> AK=%d stubCoords=%d diff=%d delta=%d\n",
956 track.setApproxChi2(chi);
967 int K =
track.curvatureAtVertex() >> 4;
969 if (
track.stubs().size() != 2) {
970 track.setTrackCompatibility(0);
975 if (
track.stubs()[0]->quality() >
track.stubs()[1]->quality())
1002 return 160 + (
track.stubs().size()) * 20 - chi;
1006 if (
value > maximum - 1)
1008 if (
value < -maximum)
1020 }
else if (sector == 1) {
1039 }
else if (sector == 1) {
1056 std::map<int, int>
out;
1059 if (
track.wheel() == -2)
1061 else if (
track.wheel() == -1)
1063 else if (
track.wheel() == 0)
1065 else if (
track.wheel() == 1)
1067 else if (
track.wheel() == 2)
1081 for (
const auto& stub :
track.stubs()) {
1082 bool ownwheel = stub->whNum() ==
track.wheel();
1084 if ((stub->scNum() ==
track.sector() + 1) || (stub->scNum() == 0 &&
track.sector() == 11))
1086 if ((stub->scNum() ==
track.sector() - 1) || (stub->scNum() == 11 &&
track.sector() == 0))
1088 int addr =
encode(ownwheel, sector, stub->tag());
1090 if (stub->stNum() == 4) {
1097 if (stub->stNum() == 3) {
1100 if (stub->stNum() == 2) {
1103 if (stub->stNum() == 1) {
1126 return (
long((
a * (1 <<
bits)) *
b)) >>
bits;
1130 int charge = (K >= 0) ? +1 : -1;
1131 float lsb = 1.25 /
float(1 << 13);
1142 FK = 0.898 * FK / (1.0 - 0.6 * FK);
1144 FK = FK - 26.382 * FK * FK * FK * FK * FK;
1146 FK = FK -
charge * 1.408e-3;
1166 std::map<uint, int> infoRank;
1167 std::map<uint, L1MuKBMTrack> infoTrack;
1168 for (
uint i = 3;
i <= 15; ++
i) {
1169 if (
i == 4 ||
i == 8)
1182 int sel6 = infoRank[10] >= infoRank[12] ? 10 : 12;
1183 int sel5 = infoRank[14] >= infoRank[9] ? 14 : 9;
1184 int sel4 = infoRank[11] >= infoRank[13] ? 11 : 13;
1185 int sel3 = infoRank[sel6] >= infoRank[sel5] ? sel6 : sel5;
1186 int sel2 = infoRank[sel4] >= infoRank[sel3] ? sel4 : sel3;
1187 selected = infoRank[15] >= infoRank[sel2] ? 15 : sel2;
1191 int sel2 = infoRank[5] >= infoRank[6] ? 5 : 6;
1192 selected = infoRank[7] >= infoRank[sel2] ? 7 : sel2;
1197 auto search = infoTrack.find(selected);
1198 if (
search != infoTrack.end())
1205 if (stub->qeta1() != 0 && stub->qeta2() != 0) {
1208 if (stub->qeta1() == 0) {
1212 return (stub->qeta1());
1224 for (
unsigned int i = 0;
i <
track.stubs().size(); ++
i) {
1225 if (fabs(
track.stubs()[
i]->whNum()) != awheel)
1226 mask = mask | (1 <<
i);
1228 mask = (awheel << nstubs) | mask;
1234 for (
const auto& stub :
track.stubs()) {
1240 sums +=
rank * stub->eta1();
1245 if (sumweights == 1)
1247 else if (sumweights == 2)
1249 else if (sumweights == 3)
1251 else if (sumweights == 4)
1253 else if (sumweights == 5)
1255 else if (sumweights == 6)
1275 for (
const auto& stub :
track.stubs())
1276 if (stub->stNum() == 2)
1280 int phiB =
track.phiBAtMuon();
1284 printf(
"Phi at second station=%d\n", phiNew);