CMS 3D CMS Logo

MicroGMTCancelOutUnit.cc
Go to the documentation of this file.
4 
5 namespace l1t {
7 
9 
11  int fwVersion = microGMTParamsHelper->fwVersion();
13  microGMTParamsHelper->bOPosMatchQualLUT(), cancel_t::omtf_bmtf_pos, fwVersion);
15  microGMTParamsHelper->bONegMatchQualLUT(), cancel_t::omtf_bmtf_neg, fwVersion);
17  microGMTParamsHelper->fOPosMatchQualLUT(), cancel_t::omtf_emtf_pos, fwVersion);
19  microGMTParamsHelper->fONegMatchQualLUT(), cancel_t::omtf_emtf_neg, fwVersion);
28 
37  }
38 
40  std::vector<std::shared_ptr<GMTInternalMuon>> coll1;
41  coll1.reserve(3);
42  std::vector<std::shared_ptr<GMTInternalMuon>> coll2;
43  coll2.reserve(3);
44  int maxWedges = 6;
45  if (trackFinder == bmtf) {
46  maxWedges = 12;
47  }
48  for (int currentWedge = 0; currentWedge < maxWedges; ++currentWedge) {
49  for (const auto& mu : wedges.at(currentWedge)) {
50  coll1.push_back(mu);
51  }
52  // handle wrap around: max "wedge" has to be compared to first "wedge"
53  int neighbourWedge = (currentWedge + 1) % maxWedges;
54  for (const auto& mu : wedges.at(neighbourWedge)) {
55  coll2.push_back(mu);
56  }
57  if (mode == cancelmode::coordinate) {
58  getCoordinateCancelBits(coll2, coll1); // in case of a tie coll1 muon wins
59  } else {
60  getTrackAddrCancelBits(coll1, coll2);
61  }
62 
63  coll1.clear();
64  coll2.clear();
65  }
66  }
67 
69  GMTInternalWedges& bmtfWedges,
70  cancelmode mode) {
71  // overlap sector collection
72  std::vector<std::shared_ptr<GMTInternalMuon>> coll1;
73  coll1.reserve(3);
74  // barrel wedge collection with 4 wedges
75  std::vector<std::shared_ptr<GMTInternalMuon>> coll2;
76  coll2.reserve(12);
77 
78  for (int currentSector = 0; currentSector < 6; ++currentSector) {
79  for (const auto& omtfMuon : omtfSectors.at(currentSector)) {
80  coll1.push_back(omtfMuon);
81  }
82  // BMTF | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 0 |
83  // OMTF | 0 | 1 | 2 | 3 | 4 | 5 |
84  // cancel OMTF sector x with corresponding BMTF wedge + the two on either side;
85  // e.g. OMTF 0 with BMTF 0, 1, 2, 3, OMTF 2 with BMTF 4, 5, 6, 7 etc.
86  for (int i = 0; i < 4; ++i) {
87  int currentWedge = (currentSector * 2 + i) % 12;
88  for (const auto& bmtfMuon : bmtfWedges.at(currentWedge)) {
89  coll2.push_back(bmtfMuon);
90  }
91  }
92  if (mode == cancelmode::coordinate) {
93  getCoordinateCancelBits(coll1, coll2);
94  } else {
95  getTrackAddrCancelBits(coll1, coll2);
96  }
97  coll1.clear();
98  coll2.clear();
99  }
100  }
101 
103  GMTInternalWedges& emtfSectors,
104  cancelmode mode) {
105  // overlap sector collection
106  std::vector<std::shared_ptr<GMTInternalMuon>> coll1;
107  coll1.reserve(3);
108  // endcap sector collection with 3 sectors
109  std::vector<std::shared_ptr<GMTInternalMuon>> coll2;
110  coll2.reserve(9);
111 
112  for (int curOmtfSector = 0; curOmtfSector < 6; ++curOmtfSector) {
113  for (const auto& omtfMuon : omtfSectors.at(curOmtfSector)) {
114  coll1.push_back(omtfMuon);
115  }
116  // OMTF | 0 | 1 | 2 | 3 | 4 | 5 |
117  // EMTF | 0 | 1 | 2 | 3 | 4 | 5 |
118  // cancel OMTF sector x with corresponding EMTF sector + the ones on either side;
119  // e.g. OMTF 1 with EMTF 0, 1, 2; OMTF 0 with EMTF 5, 0, 1 etc.
120  for (int i = 0; i < 3; ++i) {
121  // handling the wrap around: adding 5 because 0 has to be compared to 5
122  int curEmtfSector = ((curOmtfSector + 5) + i) % 6;
123  for (const auto& emtfMuon : emtfSectors.at(curEmtfSector)) {
124  coll2.push_back(emtfMuon);
125  }
126  }
127  if (mode == cancelmode::coordinate) {
128  getCoordinateCancelBits(coll1, coll2);
129  } else {
130  getTrackAddrCancelBits(coll1, coll2);
131  }
132  coll1.clear();
133  coll2.clear();
134  }
135  }
136 
137  void MicroGMTCancelOutUnit::getCoordinateCancelBits(std::vector<std::shared_ptr<GMTInternalMuon>>& coll1,
138  std::vector<std::shared_ptr<GMTInternalMuon>>& coll2) {
139  if (coll1.empty() || coll2.empty()) {
140  return;
141  }
142  tftype coll1TfType = (*coll1.begin())->trackFinderType();
143  tftype coll2TfType = (*coll2.begin())->trackFinderType();
144  if (coll2TfType != tftype::bmtf && coll1TfType % 2 != coll2TfType % 2) {
145  edm::LogError("Detector side mismatch")
146  << "Overlap-Endcap cancel out between positive and negative detector side attempted. Check eta assignment. "
147  "OMTF candidate: TF type: "
148  << coll1TfType << ", hwEta: " << (*coll1.begin())->hwEta() << ". EMTF candidate: TF type: " << coll2TfType
149  << ", hwEta: " << (*coll2.begin())->hwEta() << ". TF type even: pos. side; odd: neg. side." << std::endl;
150  return;
151  }
152 
153  MicroGMTMatchQualLUT* matchLUT = m_lutDict.at(coll1TfType + coll2TfType * 10).get();
154 
155  for (auto mu_w1 = coll1.begin(); mu_w1 != coll1.end(); ++mu_w1) {
156  int etaFine1 = (*mu_w1)->hwHF();
157  // for EMTF muons set eta fine bit to true since hwHF is the halo bit
158  if (coll1TfType == tftype::emtf_pos || coll1TfType == tftype::emtf_neg) {
159  etaFine1 = 1;
160  }
161  for (auto mu_w2 = coll2.begin(); mu_w2 != coll2.end(); ++mu_w2) {
162  int etaFine2 = (*mu_w2)->hwHF();
163  // for EMTF muons set eta fine bit to true since hwHF is the halo bit
164  if (coll2TfType == tftype::emtf_pos || coll2TfType == tftype::emtf_neg) {
165  etaFine2 = 1;
166  }
167  // both muons must have the eta fine bit set in order to use the eta fine part of the LUT
168  int etaFine = (int)(etaFine1 > 0 && etaFine2 > 0);
169 
170  // The LUT for cancellation takes reduced width phi and eta, we need the LSBs
171  int dPhiMask = (1 << matchLUT->getDeltaPhiWidth()) - 1;
172  int dEtaMask = (1 << matchLUT->getDeltaEtaWidth()) - 1;
173 
174  int dPhi = (*mu_w1)->hwGlobalPhi() - (*mu_w2)->hwGlobalPhi();
175  dPhi = std::abs(dPhi);
176  if (dPhi > 338)
177  dPhi -= 576; // shifts dPhi to [-pi, pi) in integer scale
178  dPhi = std::abs(dPhi);
179  int dEta = std::abs((*mu_w1)->hwEta() - (*mu_w2)->hwEta());
180  // check first if the delta is within the LSBs that the LUT takes, otherwise the distance
181  // is greater than what we want to cancel -> e.g. 31(int) is max => 31*0.01 = 0.31 (rad)
182  // LUT takes 5 LSB for dEta and 3 LSB for dPhi
183  if (dEta <= dEtaMask && dPhi <= dPhiMask) {
184  int match = matchLUT->lookup(etaFine, dEta & dEtaMask, dPhi & dPhiMask);
185  if (match == 1) {
186  if ((*mu_w1)->hwQual() > (*mu_w2)->hwQual()) {
187  (*mu_w2)->setHwCancelBit(1);
188  } else {
189  (*mu_w1)->setHwCancelBit(1);
190  }
191  }
192  }
193  }
194  }
195  }
196 
197  void MicroGMTCancelOutUnit::getTrackAddrCancelBits(std::vector<std::shared_ptr<GMTInternalMuon>>& coll1,
198  std::vector<std::shared_ptr<GMTInternalMuon>>& coll2) {
199  if (coll1.empty() || coll2.empty()) {
200  return;
201  }
202  // Address based cancel out for BMTF
203  if ((*coll1.begin())->trackFinderType() == tftype::bmtf && (*coll2.begin())->trackFinderType() == tftype::bmtf) {
204  for (auto mu_w1 = coll1.begin(); mu_w1 != coll1.end(); ++mu_w1) {
205  std::map<int, int> trkAddr_w1 = (*mu_w1)->origin().trackAddress();
206  int wheelNum_w1 = trkAddr_w1[l1t::RegionalMuonCand::bmtfAddress::kWheelNum];
207  int wheelSide_w1 = trkAddr_w1[l1t::RegionalMuonCand::bmtfAddress::kWheelSide];
208  std::vector<int> stations_w1;
209  stations_w1.push_back(trkAddr_w1[l1t::RegionalMuonCand::bmtfAddress::kStat1]);
210  stations_w1.push_back(trkAddr_w1[l1t::RegionalMuonCand::bmtfAddress::kStat2]);
211  stations_w1.push_back(trkAddr_w1[l1t::RegionalMuonCand::bmtfAddress::kStat3]);
212  stations_w1.push_back(trkAddr_w1[l1t::RegionalMuonCand::bmtfAddress::kStat4]);
213  //std::cout << "Track address 1: wheelSide (1 == negative side): " << wheelSide_w1 << ", wheelNum: " << wheelNum_w1 << ", stations1234: 0x" << hex << stations_w1[0] << stations_w1[1] << stations_w1[2] << stations_w1[3] << dec << std::endl;
214 
215  for (auto mu_w2 = coll2.begin(); mu_w2 != coll2.end(); ++mu_w2) {
216  std::map<int, int> trkAddr_w2 = (*mu_w2)->origin().trackAddress();
217  int wheelNum_w2 = trkAddr_w2[l1t::RegionalMuonCand::bmtfAddress::kWheelNum];
218  int wheelSide_w2 = trkAddr_w2[l1t::RegionalMuonCand::bmtfAddress::kWheelSide];
219  std::vector<int> stations_w2;
220  stations_w2.push_back(trkAddr_w2[l1t::RegionalMuonCand::bmtfAddress::kStat1]);
221  stations_w2.push_back(trkAddr_w2[l1t::RegionalMuonCand::bmtfAddress::kStat2]);
222  stations_w2.push_back(trkAddr_w2[l1t::RegionalMuonCand::bmtfAddress::kStat3]);
223  stations_w2.push_back(trkAddr_w2[l1t::RegionalMuonCand::bmtfAddress::kStat4]);
224  //std::cout << "Track address 2: wheelSide (1 == negative side): " << wheelSide_w2 << ", wheelNum: " << wheelNum_w2 << ", stations1234: 0x" << hex << stations_w2[0] << stations_w2[1] << stations_w2[2] << stations_w2[3] << dec << std::endl;
225 
226  int nMatchedStations = 0;
227  // search for duplicates in stations 2-4
228  for (int i = 1; i < 4; ++i) {
229  if (wheelSide_w1 == wheelSide_w2) { // both tracks are on the same detector side
230  if (wheelNum_w1 == wheelNum_w2) { // both tracks have the same reference wheel
231  if ((stations_w1[i] == 0x0 && stations_w2[i] == 0x2) ||
232  (stations_w1[i] == 0x1 && stations_w2[i] == 0x3) ||
233  (stations_w1[i] == 0x4 && stations_w2[i] == 0x0) ||
234  (stations_w1[i] == 0x5 && stations_w2[i] == 0x1) ||
235  (stations_w1[i] == 0x8 && stations_w2[i] == 0xA) ||
236  (stations_w1[i] == 0x9 && stations_w2[i] == 0xB) ||
237  (stations_w1[i] == 0xC && stations_w2[i] == 0x8) ||
238  (stations_w1[i] == 0xD && stations_w2[i] == 0x9)) {
239  ++nMatchedStations;
240  }
241  } else if (wheelNum_w1 == wheelNum_w2 - 1) { // track 2 is one wheel higher than track 1
242  if ((stations_w1[i] == 0x0 && stations_w2[i] == 0xA) ||
243  (stations_w1[i] == 0x1 && stations_w2[i] == 0xB) ||
244  (stations_w1[i] == 0x4 && stations_w2[i] == 0x8) ||
245  (stations_w1[i] == 0x5 && stations_w2[i] == 0x9)) {
246  ++nMatchedStations;
247  }
248  } else if (wheelNum_w1 == wheelNum_w2 + 1) { // track 2 is one wheel lower than track 1
249  if ((stations_w1[i] == 0x8 && stations_w2[i] == 0x2) ||
250  (stations_w1[i] == 0x9 && stations_w2[i] == 0x3) ||
251  (stations_w1[i] == 0xC && stations_w2[i] == 0x0) ||
252  (stations_w1[i] == 0xD && stations_w2[i] == 0x1)) {
253  ++nMatchedStations;
254  }
255  }
256  } else {
257  if (wheelNum_w1 == 0 &&
258  wheelNum_w2 == 0) { // both tracks are on either side of the central wheel (+0 and -0)
259  if ((stations_w1[i] == 0x8 && stations_w2[i] == 0xA) ||
260  (stations_w1[i] == 0x9 && stations_w2[i] == 0xB) ||
261  (stations_w1[i] == 0xC && stations_w2[i] == 0x8) ||
262  (stations_w1[i] == 0xD && stations_w2[i] == 0x9)) {
263  ++nMatchedStations;
264  }
265  }
266  }
267  }
268  //std::cout << "Shared hits found: " << nMatchedStations << std::endl;
269  if (nMatchedStations > 0) {
270  if ((*mu_w1)->origin().hwQual() >= (*mu_w2)->origin().hwQual()) {
271  (*mu_w2)->setHwCancelBit(1);
272  } else {
273  (*mu_w1)->setHwCancelBit(1);
274  }
275  }
276  }
277  }
278  // Address based cancel out for EMTF
279  } else if (((*coll1.begin())->trackFinderType() == tftype::emtf_pos &&
280  (*coll2.begin())->trackFinderType() == tftype::emtf_pos) ||
281  ((*coll1.begin())->trackFinderType() == tftype::emtf_neg &&
282  (*coll2.begin())->trackFinderType() == tftype::emtf_neg)) {
283  for (auto mu_s1 = coll1.begin(); mu_s1 != coll1.end(); ++mu_s1) {
284  std::map<int, int> trkAddr_s1 = (*mu_s1)->origin().trackAddress();
285  int me1_ch_s1 = trkAddr_s1[l1t::RegionalMuonCand::emtfAddress::kME1Ch];
286  int me2_ch_s1 = trkAddr_s1[l1t::RegionalMuonCand::emtfAddress::kME2Ch];
287  int me3_ch_s1 = trkAddr_s1[l1t::RegionalMuonCand::emtfAddress::kME3Ch];
288  int me4_ch_s1 = trkAddr_s1[l1t::RegionalMuonCand::emtfAddress::kME4Ch];
289  if (me1_ch_s1 + me2_ch_s1 + me3_ch_s1 + me4_ch_s1 == 0) {
290  continue;
291  }
292  int me1_seg_s1 = trkAddr_s1[l1t::RegionalMuonCand::emtfAddress::kME1Seg];
293  int me2_seg_s1 = trkAddr_s1[l1t::RegionalMuonCand::emtfAddress::kME2Seg];
294  int me3_seg_s1 = trkAddr_s1[l1t::RegionalMuonCand::emtfAddress::kME3Seg];
295  int me4_seg_s1 = trkAddr_s1[l1t::RegionalMuonCand::emtfAddress::kME4Seg];
296  for (auto mu_s2 = coll2.begin(); mu_s2 != coll2.end(); ++mu_s2) {
297  std::map<int, int> trkAddr_s2 = (*mu_s2)->origin().trackAddress();
298  int me1_ch_s2 = trkAddr_s2[l1t::RegionalMuonCand::emtfAddress::kME1Ch];
299  int me2_ch_s2 = trkAddr_s2[l1t::RegionalMuonCand::emtfAddress::kME2Ch];
300  int me3_ch_s2 = trkAddr_s2[l1t::RegionalMuonCand::emtfAddress::kME3Ch];
301  int me4_ch_s2 = trkAddr_s2[l1t::RegionalMuonCand::emtfAddress::kME4Ch];
302  if (me1_ch_s2 + me2_ch_s2 + me3_ch_s2 + me4_ch_s2 == 0) {
303  continue;
304  }
305  int me1_seg_s2 = trkAddr_s2[l1t::RegionalMuonCand::emtfAddress::kME1Seg];
306  int me2_seg_s2 = trkAddr_s2[l1t::RegionalMuonCand::emtfAddress::kME2Seg];
307  int me3_seg_s2 = trkAddr_s2[l1t::RegionalMuonCand::emtfAddress::kME3Seg];
308  int me4_seg_s2 = trkAddr_s2[l1t::RegionalMuonCand::emtfAddress::kME4Seg];
309 
310  int nMatchedStations = 0;
311  if (me1_ch_s2 != 0 && me1_ch_s1 == me1_ch_s2 + 3 && me1_seg_s1 == me1_seg_s2) {
312  ++nMatchedStations;
313  }
314  if (me2_ch_s2 != 0 && me2_ch_s1 == me2_ch_s2 + 2 && me2_seg_s1 == me2_seg_s2) {
315  ++nMatchedStations;
316  }
317  if (me3_ch_s2 != 0 && me3_ch_s1 == me3_ch_s2 + 2 && me3_seg_s1 == me3_seg_s2) {
318  ++nMatchedStations;
319  }
320  if (me4_ch_s2 != 0 && me4_ch_s1 == me4_ch_s2 + 2 && me4_seg_s1 == me4_seg_s2) {
321  ++nMatchedStations;
322  }
323 
324  //std::cout << "Shared hits found: " << nMatchedStations << std::endl;
325  if (nMatchedStations > 0) {
326  if ((*mu_s1)->origin().hwQual() >= (*mu_s2)->origin().hwQual()) {
327  (*mu_s2)->setHwCancelBit(1);
328  } else {
329  (*mu_s1)->setHwCancelBit(1);
330  }
331  }
332  }
333  }
334  } else {
335  edm::LogError("Cancel out not implemented")
336  << "Address based cancel out is currently only implemented for the barrel track finder.";
337  }
338  }
339 
340 } // namespace l1t
void setCancelOutBitsOverlapEndcap(GMTInternalWedges &, GMTInternalWedges &, cancelmode)
Cancel-out between overlap and endcap track finders.
void initialise(L1TMuonGlobalParamsHelper *)
Initialisation from ES record.
void setCancelOutBitsOverlapBarrel(GMTInternalWedges &, GMTInternalWedges &, cancelmode)
Cancel-out between overlap and barrel track finders.
void getTrackAddrCancelBits(std::vector< std::shared_ptr< GMTInternalMuon >> &, std::vector< std::shared_ptr< GMTInternalMuon >> &)
Compares all muons from coll1 with all muons from coll2 and sets the cancel-bits based on track addre...
std::shared_ptr< MicroGMTMatchQualLUT > m_ovlNegSingleMatchQualLUT
delete x;
Definition: CaloConfig.h:22
void getCoordinateCancelBits(std::vector< std::shared_ptr< GMTInternalMuon >> &, std::vector< std::shared_ptr< GMTInternalMuon >> &)
Compares all muons from coll1 with all muons from coll2 and sets the cancel-bits based on eta/phi coo...
std::shared_ptr< MicroGMTMatchQualLUT > m_foPosMatchQualLUT
std::shared_ptr< MicroGMTMatchQualLUT > m_fwdNegSingleMatchQualLUT
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::shared_ptr< MicroGMTMatchQualLUT > m_fwdPosSingleMatchQualLUT
std::shared_ptr< MicroGMTMatchQualLUT > m_boPosMatchQualLUT
virtual int lookup(int etaFine, int dEta, int dPhi) const =0
void setCancelOutBits(GMTInternalWedges &, tftype, cancelmode)
Cancel out between sectors/wedges in one track finder.
std::shared_ptr< MicroGMTMatchQualLUT > m_boNegMatchQualLUT
std::shared_ptr< MicroGMTMatchQualLUT > m_ovlPosSingleMatchQualLUT
std::shared_ptr< MicroGMTMatchQualLUT > m_foNegMatchQualLUT
static ReturnType create(const std::string &filename, const double maxDR, const double fEta, const double fEtaCoarse, const double fPhi, cancel_t cancelType, const int fwVersion)
std::map< int, std::vector< std::shared_ptr< GMTInternalMuon > > > GMTInternalWedges
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
std::map< int, std::shared_ptr< MicroGMTMatchQualLUT > > m_lutDict