CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MicroGMTCancelOutUnit.cc
Go to the documentation of this file.
1 #include "../interface/MicroGMTCancelOutUnit.h"
4 
5 namespace l1t {
7 {
8 }
9 
11 {
12 
13 }
14 
15 void
17  int fwVersion = microGMTParams->fwVersion();
22  //m_brlSingleMatchQualLUT = l1t::MicroGMTMatchQualLUTFactory::create(microGMTParams->brlSingleMatchQualLUTPath(), microGMTParams->brlSingleMatchQualLUTMaxDR(), cancel_t::bmtf_bmtf, fwVersion);
27 
28  //m_lutDict[tftype::bmtf+tftype::bmtf*10] = m_brlSingleMatchQualLUT;
37 }
38 
39 void
41 {
42  std::vector<std::shared_ptr<GMTInternalMuon>> coll1;
43  coll1.reserve(3);
44  std::vector<std::shared_ptr<GMTInternalMuon>> coll2;
45  coll2.reserve(3);
46  int maxWedges = 6;
47  if (trackFinder == bmtf) {
48  maxWedges = 12;
49  }
50  for (int currentWedge = 0; currentWedge < maxWedges; ++currentWedge) {
51  for (auto mu : wedges.at(currentWedge)) {
52  coll1.push_back(mu);
53  }
54  // handle wrap around: max "wedge" has to be compared to first "wedge"
55  int neighbourWedge = (currentWedge + 1) % maxWedges;
56  for (auto mu : wedges.at(neighbourWedge)) {
57  coll2.push_back(mu);
58  }
59  if (mode == cancelmode::coordinate) {
60  getCoordinateCancelBits(coll1, coll2);
61  } else {
62  getTrackAddrCancelBits(coll1, coll2);
63  }
64 
65  coll1.clear();
66  coll2.clear();
67  }
68 }
69 
70 void
72 {
73  // overlap sector collection
74  std::vector<std::shared_ptr<GMTInternalMuon>> coll1;
75  coll1.reserve(3);
76  // barrel wedge collection with 4 wedges
77  std::vector<std::shared_ptr<GMTInternalMuon>> coll2;
78  coll2.reserve(12);
79 
80  for (int currentSector = 0; currentSector < 6; ++currentSector) {
81  for (auto omtfMuon : omtfSectors.at(currentSector)) {
82  coll1.push_back(omtfMuon);
83  }
84  // BMTF | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 0 |
85  // OMTF | 0 | 1 | 2 | 3 | 4 | 5 |
86  // cancel OMTF sector x with corresponding BMTF wedge + the two on either side;
87  // e.g. OMTF 0 with BMTF 0, 1, 2, 3, OMTF 2 with BMTF 4, 5, 6, 7 etc.
88  for (int i = 0; i < 4; ++i) {
89  int currentWedge = (currentSector * 2 + i) % 12;
90  for (auto bmtfMuon : bmtfWedges.at(currentWedge)) {
91  coll2.push_back(bmtfMuon);
92  }
93  }
94  if (mode == cancelmode::coordinate) {
95  getCoordinateCancelBits(coll1, coll2);
96  } else {
97  getTrackAddrCancelBits(coll1, coll2);
98  }
99  coll1.clear();
100  coll2.clear();
101  }
102 }
103 
104 void
106 {
107  // overlap sector collection
108  std::vector<std::shared_ptr<GMTInternalMuon>> coll1;
109  coll1.reserve(3);
110  // endcap sector collection with 3 sectors
111  std::vector<std::shared_ptr<GMTInternalMuon>> coll2;
112  coll2.reserve(9);
113 
114  for (int curOmtfSector = 0; curOmtfSector < 6; ++curOmtfSector) {
115  for (auto omtfMuon : omtfSectors.at(curOmtfSector)) {
116  coll1.push_back(omtfMuon);
117  }
118  // OMTF | 0 | 1 | 2 | 3 | 4 | 5 |
119  // EMTF | 0 | 1 | 2 | 3 | 4 | 5 |
120  // cancel OMTF sector x with corresponding EMTF sector + the ones on either side;
121  // e.g. OMTF 1 with EMTF 0, 1, 2; OMTF 0 with EMTF 5, 0, 1 etc.
122  for (int i = 0; i < 3; ++i) {
123  // handling the wrap around: adding 5 because 0 has to be compared to 5
124  int curEmtfSector = ((curOmtfSector + 5) + i) % 6;
125  for (auto emtfMuon : emtfSectors.at(curEmtfSector)) {
126  coll2.push_back(emtfMuon);
127  }
128  }
129  if (mode == cancelmode::coordinate) {
130  getCoordinateCancelBits(coll1, coll2);
131  } else {
132  getTrackAddrCancelBits(coll1, coll2);
133  }
134  coll1.clear();
135  coll2.clear();
136  }
137 }
138 
139 void
140 MicroGMTCancelOutUnit::getCoordinateCancelBits(std::vector<std::shared_ptr<GMTInternalMuon>>& coll1, std::vector<std::shared_ptr<GMTInternalMuon>>& coll2)
141 {
142  if (coll1.size() == 0 || coll2.size() == 0) {
143  return;
144  }
145  tftype coll2TfType = (*coll2.begin())->trackFinderType();
146  if (coll2TfType != tftype::bmtf && (*coll1.begin())->trackFinderType() % 2 != coll2TfType % 2) {
147  edm::LogError("Detector side mismatch") << "Overlap-Endcap cancel out between positive and negative detector side attempted. Check eta assignment. OMTF candidate: TF type: " << (*coll1.begin())->trackFinderType() << ", hwEta: " << (*coll1.begin())->hwEta() << ". EMTF candidate: TF type: " << coll2TfType << ", hwEta: " << (*coll2.begin())->hwEta() << ". TF type even: pos. side; odd: neg. side." << std::endl;
148  return;
149  }
150 
151  MicroGMTMatchQualLUT* matchLUT = m_lutDict.at((*coll1.begin())->trackFinderType()+(*coll2.begin())->trackFinderType()*10).get();
152 
153  for (auto mu_w1 = coll1.begin(); mu_w1 != coll1.end(); ++mu_w1) {
154  for (auto mu_w2 = coll2.begin(); mu_w2 != coll2.end(); ++mu_w2) {
155  // The LUT for cancellation takes reduced width phi and eta, we need the LSBs
156  int dPhiMask = (1 << matchLUT->getDeltaPhiWidth()) - 1;
157  int dEtaMask = (1 << matchLUT->getDeltaEtaWidth()) - 1;
158 
159  // temporary fix to take processor offset into account...
160  int dPhi = (*mu_w1)->hwGlobalPhi() - (*mu_w2)->hwGlobalPhi();
161  if (dPhi > 338) dPhi -= 576; // shifts dPhi to [-pi, pi) in integer scale
162  dPhi = std::abs(dPhi);
163  int dEta = std::abs((*mu_w1)->hwEta() - (*mu_w2)->hwEta());
164  // check first if the delta is within the LSBs that the LUT takes, otherwise the distance
165  // is greater than what we want to cancel -> 15(int) is max => 15*0.01 = 0.15 (rad)
166  // LUT takes 4 LSB for dEta and 3 LSB for dPhi
167  if (dEta < 16 && dPhi < 8) {
168  int match = matchLUT->lookup(dEta & dEtaMask, dPhi & dPhiMask);
169  if((*mu_w1)->hwPt() < (*mu_w2)->hwPt() && match == 1) {
170  (*mu_w2)->setHwCancelBit(1);
171  } else if (match == 1) {
172  (*mu_w1)->setHwCancelBit(1);
173  }
174  }
175  }
176  }
177 }
178 
179 void
180 MicroGMTCancelOutUnit::getTrackAddrCancelBits(std::vector<std::shared_ptr<GMTInternalMuon>>& coll1, std::vector<std::shared_ptr<GMTInternalMuon>>& coll2)
181 {
182  if (coll1.size() == 0 || coll2.size() == 0) {
183  return;
184  }
185  // Address based cancel out is implemented for BMTF only
186  if ((*coll1.begin())->trackFinderType() == tftype::bmtf && (*coll2.begin())->trackFinderType() == tftype::bmtf) {
187  for (auto mu_w1 = coll1.begin(); mu_w1 != coll1.end(); ++mu_w1) {
188  std::map<int, int> trkAddr_w1 = (*mu_w1)->origin().trackAddress();
189  int wheelNum_w1 = trkAddr_w1[l1t::RegionalMuonCand::bmtfAddress::kWheelNum];
190  int wheelSide_w1 = trkAddr_w1[l1t::RegionalMuonCand::bmtfAddress::kWheelSide];
191  std::vector<int> stations_w1;
192  stations_w1.push_back(trkAddr_w1[l1t::RegionalMuonCand::bmtfAddress::kStat1]);
193  stations_w1.push_back(trkAddr_w1[l1t::RegionalMuonCand::bmtfAddress::kStat2]);
194  stations_w1.push_back(trkAddr_w1[l1t::RegionalMuonCand::bmtfAddress::kStat3]);
195  stations_w1.push_back(trkAddr_w1[l1t::RegionalMuonCand::bmtfAddress::kStat4]);
196  //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;
197 
198  for (auto mu_w2 = coll2.begin(); mu_w2 != coll2.end(); ++mu_w2) {
199  std::map<int, int> trkAddr_w2 = (*mu_w2)->origin().trackAddress();
200  int wheelNum_w2 = trkAddr_w2[l1t::RegionalMuonCand::bmtfAddress::kWheelNum];
201  int wheelSide_w2 = trkAddr_w2[l1t::RegionalMuonCand::bmtfAddress::kWheelSide];
202  std::vector<int> stations_w2;
203  stations_w2.push_back(trkAddr_w2[l1t::RegionalMuonCand::bmtfAddress::kStat1]);
204  stations_w2.push_back(trkAddr_w2[l1t::RegionalMuonCand::bmtfAddress::kStat2]);
205  stations_w2.push_back(trkAddr_w2[l1t::RegionalMuonCand::bmtfAddress::kStat3]);
206  stations_w2.push_back(trkAddr_w2[l1t::RegionalMuonCand::bmtfAddress::kStat4]);
207  //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;
208 
209  int nMatchedStations = 0;
210  // search for duplicates in stations 2-4
211  for (int i = 1; i < 4; ++i) {
212  if (wheelSide_w1 == wheelSide_w2) { // both tracks are on the same detector side
213  if (wheelNum_w1 == wheelNum_w2) { // both tracks have the same reference wheel
214  if ((stations_w1[i] == 0x0 && stations_w2[i] == 0x2) ||
215  (stations_w1[i] == 0x1 && stations_w2[i] == 0x3) ||
216  (stations_w1[i] == 0x4 && stations_w2[i] == 0x0) ||
217  (stations_w1[i] == 0x5 && stations_w2[i] == 0x1) ||
218  (stations_w1[i] == 0x8 && stations_w2[i] == 0xA) ||
219  (stations_w1[i] == 0x9 && stations_w2[i] == 0xB) ||
220  (stations_w1[i] == 0xC && stations_w2[i] == 0x8) ||
221  (stations_w1[i] == 0xD && stations_w2[i] == 0x9))
222  {
223  ++nMatchedStations;
224  }
225  } else if (wheelNum_w1 == wheelNum_w2 - 1) { // track 2 is one wheel higher than track 1
226  if ((stations_w1[i] == 0x0 && stations_w2[i] == 0xA) ||
227  (stations_w1[i] == 0x1 && stations_w2[i] == 0xB) ||
228  (stations_w1[i] == 0x4 && stations_w2[i] == 0x8) ||
229  (stations_w1[i] == 0x5 && stations_w2[i] == 0x9))
230  {
231  ++nMatchedStations;
232  }
233  } else if (wheelNum_w1 == wheelNum_w2 + 1) { // track 2 is one wheel lower than track 1
234  if ((stations_w1[i] == 0x8 && stations_w2[i] == 0x2) ||
235  (stations_w1[i] == 0x9 && stations_w2[i] == 0x3) ||
236  (stations_w1[i] == 0xC && stations_w2[i] == 0x0) ||
237  (stations_w1[i] == 0xD && stations_w2[i] == 0x1))
238  {
239  ++nMatchedStations;
240  }
241  }
242  } else {
243  if (wheelNum_w1 == 0 && wheelNum_w2 == 0) { // both tracks are on either side of the central wheel (+0 and -0)
244  if ((stations_w1[i] == 0x8 && stations_w2[i] == 0xA) ||
245  (stations_w1[i] == 0x9 && stations_w2[i] == 0xB) ||
246  (stations_w1[i] == 0xC && stations_w2[i] == 0x8) ||
247  (stations_w1[i] == 0xD && stations_w2[i] == 0x9))
248  {
249  ++nMatchedStations;
250  }
251  }
252  }
253  }
254  //std::cout << "Shared hits found: " << nMatchedStations << std::endl;
255  if (nMatchedStations > 0) {
256  if ((*mu_w1)->origin().hwQual() > (*mu_w2)->origin().hwQual()) {
257  (*mu_w2)->setHwCancelBit(1);
258  } else {
259  (*mu_w1)->setHwCancelBit(1);
260  }
261  }
262  }
263  }
264  } else {
265  edm::LogError("Cancel out not implemented") << "Address based cancel out is currently only implemented for the barrel track finder.";
266  }
267 }
268 
269 } // namespace l1t
std::string fOPosMatchQualLUTPath() const
double fOPosMatchQualLUTMaxDR() const
int i
Definition: DBlmapReader.cc:9
void setCancelOutBitsOverlapEndcap(GMTInternalWedges &, GMTInternalWedges &, cancelmode)
Cancel-out between overlap and endcap track finders.
std::string fwdPosSingleMatchQualLUTPath() const
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
double ovlPosSingleMatchQualLUTMaxDR() const
void initialise(L1TMuonGlobalParams *)
Initialisation from ES record.
std::string fONegMatchQualLUTPath() const
std::string ovlPosSingleMatchQualLUTPath() const
double bOPosMatchQualLUTMaxDR() const
double ovlNegSingleMatchQualLUTMaxDR() const
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...
static ReturnType create(const std::string &filename, const double maxDR, cancel_t cancelType, const int fwVersion)
std::shared_ptr< MicroGMTMatchQualLUT > m_foPosMatchQualLUT
unsigned fwVersion() const
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
std::shared_ptr< MicroGMTMatchQualLUT > m_fwdNegSingleMatchQualLUT
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double fwdPosSingleMatchQualLUTMaxDR() const
std::shared_ptr< MicroGMTMatchQualLUT > m_fwdPosSingleMatchQualLUT
std::shared_ptr< MicroGMTMatchQualLUT > m_boPosMatchQualLUT
const int mu
Definition: Constants.h:22
std::string fwdNegSingleMatchQualLUTPath() const
int lookup(int dEta, int dPhi) const
void setCancelOutBits(GMTInternalWedges &, tftype, cancelmode)
Cancel out between sectors/wedges in one track finder.
std::string ovlNegSingleMatchQualLUTPath() const
std::shared_ptr< MicroGMTMatchQualLUT > m_boNegMatchQualLUT
std::string bONegMatchQualLUTPath() const
std::shared_ptr< MicroGMTMatchQualLUT > m_ovlPosSingleMatchQualLUT
double fwdNegSingleMatchQualLUTMaxDR() const
std::shared_ptr< MicroGMTMatchQualLUT > m_foNegMatchQualLUT
double bONegMatchQualLUTMaxDR() const
double fONegMatchQualLUTMaxDR() const
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::string bOPosMatchQualLUTPath() const
std::map< int, std::shared_ptr< MicroGMTMatchQualLUT > > m_lutDict