1 #ifndef PHASE2GMT_TRACKMUONMATCHALGO 2 #define PHASE2GMT_TRACKMUONMATCHALGO 30 ap_int<BITSSTUBETA>
eta;
39 ap_uint<BITSSTUBID>
id;
54 const std::vector<MuonROI>& rois) {
55 std::vector<PreTrackMatchedMuon> preMuons;
58 if (
mu.valid() && preMuons.size() < 16)
59 preMuons.push_back(
mu);
61 std::vector<PreTrackMatchedMuon> cleanedMuons =
clean(preMuons);
66 const std::vector<PreTrackMatchedMuon>& muonsPrevious,
67 const std::vector<PreTrackMatchedMuon>& muonsNext,
69 std::vector<PreTrackMatchedMuon>
out;
75 printf(
"-----Cleaning Up Muons in the neighbours\n");
83 ap_uint<5>
mask = 0x1f;
84 for (
uint j = 0;
j < muonsPrevious.size(); ++
j) {
87 for (
uint j = 0;
j < muonsNext.size(); ++
j) {
96 printf(
"discarded\n");
102 std::vector<l1t::TrackerMuon>
convert(std::vector<PreTrackMatchedMuon>&
muons,
uint maximum) {
103 std::vector<l1t::TrackerMuon>
out;
105 if (
out.size() == maximum)
108 muon.setMuonRef(
mu.muonRef());
109 for (
const auto& stub :
mu.stubs())
113 printf(
"Final Muon:");
126 bstart = wordconcat<wordtype>(word1, bstart,
mu.hwPt(),
BITSGTPT);
127 bstart = wordconcat<wordtype>(word1, bstart,
mu.hwPhi(),
BITSGTPHI);
128 bstart = wordconcat<wordtype>(word1, bstart,
mu.hwEta(),
BITSGTETA);
129 bstart = wordconcat<wordtype>(word1, bstart,
mu.hwZ0(),
BITSGTZ0);
130 bstart = wordconcat<wordtype>(word1, bstart, (
mu.hwD0() >> 2),
BITSGTD0);
133 bstart = wordconcat<wordtype>(word2, bstart,
mu.hwCharge(), 1);
134 bstart = wordconcat<wordtype>(word2, bstart,
mu.hwQual(),
BITSGTQUAL);
135 bstart = wordconcat<wordtype>(word2, bstart,
mu.hwIso(),
BITSGTISO);
136 bstart = wordconcat<wordtype>(word2, bstart,
mu.hwBeta(),
BITSGTBETA);
138 std::array<uint64_t, 2> wordout = {{word1, word2}};
144 std::vector<l1t::TrackerMuon>
sort(std::vector<l1t::TrackerMuon>&
muons,
uint maximum) {
145 if (
muons.size() < 2)
149 std::vector<l1t::TrackerMuon>
out;
150 for (
unsigned int i = 0;
i <
muons.size(); ++
i) {
152 if (
i == (maximum - 1))
163 ap_uint<BITSPROPCOORD> prop_coord1 = 0;
164 ap_uint<BITSPROPCOORD> prop_coord2 = 0;
165 ap_uint<BITSPROPSIGMACOORD_A> res0_coord1 = 0;
166 ap_uint<BITSPROPSIGMACOORD_B> res1_coord1 = 0;
167 ap_uint<BITSPROPSIGMACOORD_A> res0_coord2 = 0;
168 ap_uint<BITSPROPSIGMACOORD_B> res1_coord2 = 0;
169 ap_uint<BITSPROPSIGMAETA_A> res0_eta1 = 0;
170 ap_uint<BITSPROPSIGMAETA_B> res1_eta = 0;
171 ap_uint<BITSPROPSIGMAETA_A> res0_eta2 = 0;
172 ap_uint<1> is_barrel = 0;
187 }
else if (layer == 1) {
199 }
else if (layer == 2) {
211 }
else if (layer == 3) {
223 }
else if (layer == 4) {
238 ap_int<BITSPHI> phi =
track.phi();
239 ap_int<BITSPROPCOORD + BITSTTCURV> c1kFull = prop_coord1 *
curvature;
241 ap_int<BITSPHI> coord1 = phi - c1k;
245 ap_int<BITSPROPCOORD + BITSTTCURV> c2kFull = prop_coord2 *
curvature;
257 ap_uint<BITSTTCURV2> curvature2 = curvature2All / 2;
260 ap_uint<BITSPROPSIGMACOORD_B + BITSTTCURV2> rescoord1k = (res1_coord1 * curvature2) >> 23;
261 ap_ufixed<BITSSIGMACOORD, BITSSIGMACOORD, AP_TRN_ZERO, AP_SAT_SYM> sigma_coord1 = res0_coord1 + rescoord1k;
262 out.sigma_coord1 = ap_uint<BITSSIGMACOORD>(sigma_coord1);
264 ap_uint<BITSPROPSIGMACOORD_B + BITSTTCURV2> rescoord2k = (res1_coord2 * curvature2) >> 23;
265 ap_ufixed<BITSSIGMACOORD, BITSSIGMACOORD, AP_TRN_ZERO, AP_SAT_SYM> sigma_coord2 = res0_coord2 + rescoord2k;
266 out.sigma_coord2 = ap_uint<BITSSIGMACOORD>(sigma_coord2);
268 ap_uint<BITSPROPSIGMAETA_B + BITSTTCURV2> resetak = (res1_eta * curvature2) >> 23;
269 ap_ufixed<BITSSIGMAETA, BITSSIGMAETA, AP_TRN_ZERO, AP_SAT_SYM> sigma_eta1 = res0_eta1 + resetak;
270 out.sigma_eta1 = ap_uint<BITSSIGMAETA>(sigma_eta1);
271 ap_ufixed<BITSSIGMAETA, BITSSIGMAETA, AP_TRN_ZERO, AP_SAT_SYM> sigma_eta2 = res0_eta2 + resetak;
272 out.sigma_eta2 = ap_uint<BITSSIGMAETA>(sigma_eta2);
274 out.is_barrel = is_barrel;
278 printf(
"Propagating to layer %d:is barrel=%d coords=%d+-%d , %d +-%d etas = %d +- %d +-%d\n",
280 out.is_barrel.to_int(),
282 out.sigma_coord1.to_int(),
284 out.sigma_coord2.to_int(),
286 out.sigma_eta1.to_int(),
287 out.sigma_eta2.to_int());
292 ap_uint<BITSSIGMAETA + 1>
deltaEta(
const ap_int<BITSSTUBETA>&
eta1,
const ap_int<BITSSTUBETA>&
eta2) {
293 ap_fixed<BITSSIGMAETA + 2, BITSSIGMAETA + 2, AP_TRN_ZERO, AP_SAT_SYM>
dEta =
eta1 -
eta2;
295 return ap_uint<BITSSIGMAETA + 1>(-
dEta);
297 return ap_uint<BITSSIGMAETA + 1>(
dEta);
300 ap_uint<BITSSIGMACOORD + 1>
deltaCoord(
const ap_int<BITSSTUBCOORD>& phi1,
const ap_int<BITSSTUBCOORD>& phi2) {
301 ap_int<BITSSTUBCOORD> dPhiRoll = phi1 - phi2;
302 ap_ufixed<BITSSIGMACOORD + 1, BITSSIGMACOORD + 1, AP_TRN_ZERO, AP_SAT_SYM> dPhi;
304 dPhi = ap_ufixed<BITSSIGMACOORD + 1, BITSSIGMACOORD + 1, AP_TRN_ZERO, AP_SAT_SYM>(-dPhiRoll);
306 dPhi = ap_ufixed<BITSSIGMACOORD + 1, BITSSIGMACOORD + 1, AP_TRN_ZERO, AP_SAT_SYM>(dPhiRoll);
308 return ap_uint<BITSSIGMACOORD + 1>(dPhi);
313 printf(
"Matching to ");
317 ap_uint<1> coord1Matched;
318 ap_uint<BITSSIGMACOORD + 1> deltaCoord1 =
deltaCoord(prop.
coord1, stub->coord1());
319 if (deltaCoord1 <= prop.
sigma_coord1 && (stub->quality() & 0x1)) {
325 printf(
"Coord1 matched=%d delta=%d res=%d\n",
326 coord1Matched.to_int(),
327 deltaCoord1.to_int(),
331 ap_uint<1> coord2Matched;
332 ap_uint<BITSSIGMACOORD + 1> deltaCoord2 =
deltaCoord(prop.
coord2, stub->coord2());
333 if (deltaCoord2 <= prop.
sigma_coord2 && (stub->quality() & 0x2)) {
339 printf(
"Coord2 matched=%d delta=%d res=%d\n",
340 coord2Matched.to_int(),
341 deltaCoord2.to_int(),
346 ap_uint<1> eta1Matched;
350 ap_ufixed<BITSSIGMAETA, BITSSIGMAETA, AP_TRN_ZERO, AP_SAT_SYM> prop_sigma_eta1;
351 if (stub->etaQuality() == 0)
356 ap_uint<BITSSIGMAETA + 1> deltaEta1 =
deltaEta(prop.
eta, stub->eta1());
357 if (deltaEta1 <= prop_sigma_eta1 && (stub->etaQuality() == 0 || (stub->etaQuality() & 0x1)))
363 printf(
"eta1 matched=%d delta=%d res=%d\n", eta1Matched.to_int(), deltaEta1.to_int(), prop_sigma_eta1.to_int());
367 ap_uint<1> eta2Matched;
369 ap_uint<BITSSIGMAETA + 1> deltaEta2 =
deltaEta(prop.
eta, stub->eta2());
370 if (deltaEta2 <= prop.
sigma_eta2 && (stub->etaQuality() & 0x2))
378 printf(
"eta2 matched=%d delta=%d res=%d\n", eta2Matched.to_int(), deltaEta2.to_int(), prop.
sigma_eta2.to_int());
382 out.valid = (coord1Matched == 1 && (eta1Matched == 1 || eta2Matched == 1));
383 if (
out.valid == 0) {
386 out.quality = 32 - deltaCoord1;
387 if (coord2Matched == 1)
388 out.quality += 32 - deltaCoord2;
393 bool match1 = (coord1Matched == 1 && eta1Matched == 1);
394 bool match2 = (coord2Matched == 1 && eta2Matched == 1);
396 (coord1Matched == 1 && (eta1Matched || eta2Matched) && stub->etaQuality() == 3 && stub->quality() == 1);
397 out.valid = match1 || match2 || match3;
402 if (match1 || match3)
403 out.quality += 32 - deltaCoord1;
405 out.quality += 32 - deltaCoord2;
409 printf(
"GlobalMatchQuality = %d\n",
out.quality.to_int());
416 return match(prop, stub);
422 if (
m.quality > best.quality)
430 std::vector<match_t> matchInfo0;
431 std::vector<match_t> matchInfo1;
432 std::vector<match_t> matchInfo2;
433 std::vector<match_t> matchInfo3;
434 std::vector<match_t> matchInfo4;
436 if (
verbose_ == 1 && !rois.empty()) {
437 printf(
"-----------processing new track----------");
440 for (
const auto& roi : rois) {
442 printf(
"New ROI with %d stubs \n",
int(roi.stubs().size()));
444 for (
const auto& stub : roi.stubs()) {
447 if (roi.isGlobalMuon() && roi.muonRef().isNonnull()) {
449 m.muRef = roi.muonRef();
452 if (stub->tfLayer() == 0)
453 matchInfo0.push_back(
m);
454 else if (stub->tfLayer() == 1)
455 matchInfo1.push_back(
m);
456 else if (stub->tfLayer() == 2)
457 matchInfo2.push_back(
m);
458 else if (stub->tfLayer() == 3)
459 matchInfo3.push_back(
m);
460 else if (stub->tfLayer() == 4)
461 matchInfo4.push_back(
m);
466 ap_ufixed<6, 6, AP_TRN_ZERO, AP_SAT_SYM> ptPenalty = ap_ufixed<6, 6, AP_TRN_ZERO, AP_SAT_SYM>(
track.pt() / 32);
468 ap_uint<BITSMATCHQUALITY>
quality = 0;
471 if (!matchInfo0.empty()) {
474 muon.addStub(
b.stubRef);
476 muon.addMuonRef(
b.muRef);
480 if (!matchInfo1.empty()) {
483 muon.addStub(
b.stubRef);
485 muon.addMuonRef(
b.muRef);
489 if (!matchInfo2.empty()) {
492 muon.addStub(
b.stubRef);
494 muon.addMuonRef(
b.muRef);
498 if (!matchInfo3.empty()) {
501 muon.addStub(
b.stubRef);
503 muon.addMuonRef(
b.muRef);
507 if (!matchInfo4.empty()) {
510 muon.addStub(
b.stubRef);
512 muon.addMuonRef(
b.muRef);
520 ap_uint<8> etaAddr =
muon.eta() < 0 ? ap_uint<8>(-
muon.eta() / 256) : ap_uint<8>((
muon.eta()) / 256);
521 ap_uint<8> ptAddr =
muon.pt() > 4095 ? ap_uint<8>(15) : ap_uint<8>(
muon.pt() / 256);
522 ap_uint<8>
addr = ptAddr | (etaAddr << 4);
529 muon.setValid(
false);
536 if (
verbose_ == 1 && !rois.empty()) {
538 printf(
"TPS %d",
track.trkPtr()->phiSector());
541 for (
uint i = 0;
i < 16; ++
i) {
542 if (rois.size() >
i) {
543 rois[
i].printROILine();
546 printf(
"%016lx", 0x1ff000000000000);
547 printf(
"%016lx", 0x1ff000000000000);
548 printf(
"%016lx", 0x1ff000000000000);
549 printf(
"%016lx", 0x1ff000000000000);
550 printf(
"%016lx", 0x1ff000000000000);
560 ap_uint<5>
valid = 0;
562 if (
mu.stubID0() != 511) {
564 if (
mu.stubID0() ==
other.stubID0())
567 if (
mu.stubID1() != 511) {
569 if (
mu.stubID1() ==
other.stubID1())
572 if (
mu.stubID2() != 511) {
574 if (
mu.stubID2() ==
other.stubID2())
577 if (
mu.stubID3() != 511) {
579 if (
mu.stubID3() ==
other.stubID3())
582 if (
mu.stubID4() != 511) {
584 if (
mu.stubID4() ==
other.stubID4())
588 if (((
mu.quality() <
other.quality()) && (!eq)) || ((
mu.quality() <=
other.quality()) && (eq)))
594 std::vector<PreTrackMatchedMuon>
clean(std::vector<PreTrackMatchedMuon>&
muons) {
595 std::vector<PreTrackMatchedMuon>
out;
599 printf(
"-----Cleaning Up Muons in the same Nonant\n");
606 ap_uint<5>
mask = 0x1f;
618 printf(
"discarded\n");
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_3[512]
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_0[512]
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_4[512]
ap_uint< BITSSIGMACOORD > sigma_coord1
std::vector< l1t::TrackerMuon > convert(std::vector< PreTrackMatchedMuon > &muons, uint maximum)
const ap_uint< BITSPROPCOORD > lt_prop_coord1_0[512]
ProductID id() const
Accessor for product ID.
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_2[512]
const ap_uint< BITSPROPCOORD > lt_prop_coord1_2[512]
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_0[512]
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_2[512]
std::vector< l1t::TrackerMuon > sort(std::vector< l1t::TrackerMuon > &muons, uint maximum)
const int BITSMATCHQUALITY
ap_int< BITSSTUBCOORD > coord1
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_1[512]
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_4[512]
const ap_uint< BITSPROPCOORD > lt_prop_coord2_1[512]
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_3[512]
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_4[512]
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_1[512]
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_1[512]
l1t::RegionalMuonCandRef muRef
const ap_uint< BITSPROPCOORD > lt_prop_coord2_4[512]
const ap_uint< BITSPROPCOORD > lt_prop_coord2_0[512]
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_3[512]
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
ap_uint< BITSSIGMAETA > sigma_eta2
ap_uint< 5 > cleanMuon(const PreTrackMatchedMuon &mu, const PreTrackMatchedMuon &other, bool eq)
const ap_uint< BITSPROPCOORD > lt_prop_coord1_4[512]
T curvature(T InversePt, const MagneticField &field)
~TrackMuonMatchAlgorithm()
ap_uint< BITSSIGMACOORD > sigma_coord2
std::vector< PreTrackMatchedMuon > cleanNeighbor(const std::vector< PreTrackMatchedMuon > &muons, const std::vector< PreTrackMatchedMuon > &muonsPrevious, const std::vector< PreTrackMatchedMuon > &muonsNext, bool equality)
ap_uint< BITSSIGMAETA+1 > deltaEta(const ap_int< BITSSTUBETA > &eta1, const ap_int< BITSSTUBETA > &eta2)
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_2[512]
const ap_uint< BITSPROPCOORD > lt_prop_coord1_1[512]
const ap_uint< BITSPROPCOORD > lt_prop_coord2_3[512]
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_4[512]
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_2[512]
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_1[512]
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_1[512]
std::vector< PreTrackMatchedMuon > processNonant(const std::vector< ConvertedTTTrack > &convertedTracks, const std::vector< MuonROI > &rois)
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_0[512]
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_0[512]
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_0[512]
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_2[512]
bool outputGT(std::vector< l1t::TrackerMuon > &muons)
ap_uint< BITSMATCHQUALITY - 2 > quality
ap_uint< BITSSIGMAETA > sigma_eta1
match_t getBest(const std::vector< match_t > matches)
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord2_3[512]
TrackMuonMatchAlgorithm(const edm::ParameterSet &iConfig)
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_4[512]
ap_int< BITSSTUBETA > eta
ap_uint< BITSSIGMACOORD+1 > deltaCoord(const ap_int< BITSSTUBCOORD > &phi1, const ap_int< BITSSTUBCOORD > &phi2)
const unsigned int PHIDIVIDER
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_4[512]
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_2[512]
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_3[512]
const ap_uint< 8 > lt_tpsID[256]
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord1_4[512]
const ap_uint< BITSPROPCOORD > lt_prop_coord2_2[512]
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_0[512]
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta2_1[512]
propagation_t propagate(const ConvertedTTTrack &track, uint layer)
const ap_uint< BITSPROPSIGMAETA_A > lt_res0_eta1_3[512]
const ap_uint< BITSPROPSIGMAETA_B > lt_res1_eta_3[512]
match_t match(const propagation_t prop, const l1t::MuonStubRef &stub)
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_0[512]
const ap_uint< BITSPROPSIGMACOORD_A > lt_res0_coord1_2[512]
ap_int< BITSSTUBCOORD > coord2
const ap_uint< BITSPROPCOORD > lt_prop_coord1_3[512]
std::vector< PreTrackMatchedMuon > clean(std::vector< PreTrackMatchedMuon > &muons)
match_t propagateAndMatch(const ConvertedTTTrack &track, const l1t::MuonStubRef &stub)
PreTrackMatchedMuon processTrack(const ConvertedTTTrack &track, const std::vector< MuonROI > &rois)
const unsigned int ETADIVIDER
const ap_uint< BITSPROPSIGMACOORD_B > lt_res1_coord2_1[512]