CMS 3D CMS Logo

OMTFSorter.cc
Go to the documentation of this file.
1 #include <cassert>
2 #include <iostream>
3 #include <strstream>
4 #include <algorithm>
5 #include <bitset>
6 
7 
9 
12 
17 
18  OMTFResult::vector1D pdfValsVec = aResult.getSummaryVals();
19  OMTFResult::vector1D nHitsVec = aResult.getSummaryHits();
20  OMTFResult::vector1D refPhiVec = aResult.getRefPhis();
21  OMTFResult::vector1D refEtaVec = aResult.getRefEtas();
22  OMTFResult::vector1D hitsVec = aResult.getHitsWord();
23  OMTFResult::vector1D refPhiRHitVec = aResult.getRefPhiRHits();
24 
25  assert(pdfValsVec.size()==nHitsVec.size());
26 
27  unsigned int nHitsMax = 0;
28  unsigned int pdfValMax = 0;
29  unsigned int hitsWord = 0;
30  int refPhi = 1024;
31  int refEta = -10;
32  int refLayer = -1;
33  int refPhiRHit = 1024;
34 
35  AlgoMuon sortedResult(pdfValMax, refPhi, refEta, refLayer, hitsWord, nHitsMax);
36 
38  for(auto itHits: nHitsVec){
39  if(itHits>nHitsMax) nHitsMax = itHits;
40  }
41 
42  if(!nHitsMax) return sortedResult;
43 
44  for(unsigned int ipdfVal=0;ipdfVal<pdfValsVec.size();++ipdfVal){
45  if(nHitsVec[ipdfVal] == nHitsMax){
46  if(pdfValsVec[ipdfVal]>pdfValMax){
47  pdfValMax = pdfValsVec[ipdfVal];
48  refPhi = refPhiVec[ipdfVal];
49  refEta = refEtaVec[ipdfVal];
50  refLayer = ipdfVal;
51  hitsWord = hitsVec[ipdfVal];
52  refPhiRHit = refPhiRHitVec[ipdfVal];
53  }
54  }
55  }
56 
57  sortedResult.setDisc(pdfValMax);
58  sortedResult.setPhi(refPhi);
59  sortedResult.setEta(refEta);
60  sortedResult.setRefLayer(refLayer);
61  sortedResult.setHits(hitsWord);
62  sortedResult.setQ(nHitsMax);
63  sortedResult.setPhiRHit(refPhiRHit);
64 
65  return sortedResult;
66 }
70  int charge){
71 
72  unsigned int pdfValMax = 0;
73  unsigned int nHitsMax = 0;
74  unsigned int hitsWord = 0;
75  int refPhi = 9999;
76  int refEta = 999;
77  int refLayer = -1;
78  int refPhiRHit = 9999;
79  Key bestKey;
80 
81 // std::cout <<" ====== sortRefHitResults: " << std::endl;
82  for(auto itKey: aResultsMap){
83  if(charge!=0 && itKey.first.theCharge!=charge) continue; //charge==0 means ignore charge
84  AlgoMuon val = sortSingleResult(itKey.second);
86  if(val.getQ() < 3) continue;
87 
88  if(val.getQ() > (int)nHitsMax){
89  nHitsMax = val.getQ();
90  pdfValMax = val.getDisc();
91  refPhi = val.getPhi();
92  refEta = val.getEta();
93  refLayer = val.getRefLayer();
94  hitsWord = val.getHits();
95  refPhiRHit = val.getPhiRHit();
96  bestKey = itKey.first;
97 // std::cout <<" sorter, byQual, now best is: "<<bestKey << std::endl;
98  }
99  else if(val.getQ() == (int)nHitsMax && val.getDisc() > (int)pdfValMax){
100  pdfValMax = val.getDisc();
101  refPhi = val.getPhi();
102  refEta = val.getEta();
103  refLayer = val.getRefLayer();
104  hitsWord = val.getHits();
105  refPhiRHit = val.getPhiRHit();
106  bestKey = itKey.first;
107 // std::cout <<" sorter, byDisc, now best is: "<<bestKey << std::endl;
108  }
109  else if(val.getQ() == (int)nHitsMax && val.getDisc() == (int)pdfValMax && itKey.first.number() < bestKey.number()) {
110 // itKey.first.thePtCode < bestKey.thePtCode){
111  pdfValMax = val.getDisc();
112  refPhi = val.getPhi();
113  refEta = val.getEta();
114  refLayer = val.getRefLayer();
115  hitsWord = val.getHits();
116  refPhiRHit = val.getPhiRHit();
117  bestKey = itKey.first;
118 // std::cout <<" sorter, byNumb, now best is: "<<bestKey << std::endl;
119  }
120  }
121 
122  AlgoMuon candidate(pdfValMax, refPhi, refEta, refLayer,
123  hitsWord, nHitsMax, 0,
124  bestKey.thePtCode, bestKey.theCharge);
125 
126  candidate.setPhiRHit(refPhiRHit); // for backward compatibility
127  candidate.setPatternNumber(bestKey.number());
128 
129 // std::cout <<" return: " << candidate << std::endl;
130  return candidate;
131 }
134 void OMTFSorter::sortRefHitResults(const std::vector<OMTFProcessor::resultsMap> & procResults,
135  std::vector<AlgoMuon> & refHitCands,
136  int charge){
137 
138 // for(auto itRefHit: procResults) refHitCands.push_back(sortRefHitResults(itRefHit,charge));
139  for (unsigned int iRefHit = 0 ; iRefHit < procResults.size(); iRefHit++) {
140  AlgoMuon mu = sortRefHitResults( procResults[iRefHit],charge);
141  mu.setRefHitNumber(iRefHit);
142  refHitCands.push_back(mu);
143  }
144 }
148 
150  std::vector<unsigned int> badPatterns = {99840, 34304, 3075, 36928, 12300, 98816, 98944, 33408, 66688, 66176, 7171, 20528, 33856, 35840, 4156, 34880};
151 
152  for(auto aHitPattern: badPatterns){
153  if(hits==aHitPattern) return false;
154  }
155 
156  return true;
157 }
160 std::vector<l1t::RegionalMuonCand> OMTFSorter::candidates(unsigned int iProcessor, l1t::tftype mtfType, const std::vector<AlgoMuon> & algoCands)
161 {
162 
163  std::vector<l1t::RegionalMuonCand> result;
164 
165  for(auto myCand: algoCands){
166  l1t::RegionalMuonCand candidate;
167  candidate.setHwPt(myCand.getPt());
168  candidate.setHwEta(myCand.getEta());
169 
170  int phiValue = myCand.getPhi();
171  if(phiValue>= int(nPhiBins) ) phiValue-=nPhiBins;
173  phiValue = floor(phiValue*437./pow(2,12)); // ie. use as in hw: 9.3729977
174  candidate.setHwPhi(phiValue);
175 
176  candidate.setHwSign(myCand.getCharge()<0 ? 1:0 );
177  candidate.setHwSignValid(1);
178 
179  unsigned int quality = checkHitPatternValidity(myCand.getHits()) ? 0 | (1 << 2) | (1 << 3)
180  : 0 | (1 << 2);
181  if ( abs(myCand.getEta()) == 115
182  && ( static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000001110000000").to_ulong()
183  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000001110000000").to_ulong()
184  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000000110000000").to_ulong()
185  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000001100000000").to_ulong()
186  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000001010000000").to_ulong()
187  )
188  ) quality = 4;
189  if( myOmtfConfig->fwVersion() >= 5 ) {
190  if ( static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000010000000011").to_ulong()
191  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000100000000011").to_ulong()
192  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000001000000000011").to_ulong()
193  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000010000000000011").to_ulong()
194  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000100000000000011").to_ulong()
195  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("001000000000000011").to_ulong()
196  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("010000000000000011").to_ulong()
197  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000000000000011").to_ulong()
198  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000010000001100").to_ulong()
199  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000100000001100").to_ulong()
200  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000001000000001100").to_ulong()
201  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000010000000001100").to_ulong()
202  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000100000000001100").to_ulong()
203  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("001000000000001100").to_ulong()
204  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("010000000000001100").to_ulong()
205  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000000000001100").to_ulong()
206  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000010000110000").to_ulong()
207  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000000100000110000").to_ulong()
208  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000001000000110000").to_ulong()
209  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000010000000110000").to_ulong()
210  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("000100000000110000").to_ulong()
211  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("001000000000110000").to_ulong()
212  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("010000000000110000").to_ulong()
213  || static_cast<unsigned int>(myCand.getHits()) == std::bitset<18>("100000000000110000").to_ulong()
214  ) quality = 1;
215  }
216 
217 // if (abs(myCand.getEta()) == 121) quality = 4;
218  if (abs(myCand.getEta()) == 121) quality = 0; // changed on request from HI
219 
220  candidate.setHwQual (quality);
221 
222  std::map<int, int> trackAddr;
223  trackAddr[0] = myCand.getHits();
224  trackAddr[1] = myCand.getRefLayer();
225  trackAddr[2] = myCand.getDisc();
226  candidate.setTrackAddress(trackAddr);
227  candidate.setTFIdentifiers(iProcessor,mtfType);
228  if (candidate.hwPt()) result.push_back(candidate);
229  }
230  return result;
231 }
int getEta() const
Definition: AlgoMuon.h:22
unsigned int number() const
Definition: GoldenPattern.h:31
int getQ() const
Definition: AlgoMuon.h:25
void setQ(int q)
Definition: AlgoMuon.h:38
void setHwPhi(int bits)
Set compressed relative phi as transmitted by hardware LSB = 2*pi/576 (8 bits)
unsigned int nPhiBins
Definition: OMTFSorter.h:60
const OMTFResult::vector1D & getRefPhiRHits() const
Definition: OMTFResult.h:32
unsigned int fwVersion() const
int theCharge
Definition: GoldenPattern.h:35
std::map< Key, OMTFResult > resultsMap
Definition: OMTFProcessor.h:24
const OMTFResult::vector1D & getRefPhis() const
Definition: OMTFResult.h:26
const OMTFConfiguration * myOmtfConfig
Definition: OMTFSorter.h:61
void setTrackAddress(const std::map< int, int > &address)
Set the whole track address.
unsigned int thePtCode
Definition: GoldenPattern.h:34
int getDisc() const
Definition: AlgoMuon.h:20
const OMTFResult::vector1D & getSummaryVals() const
Definition: OMTFResult.h:22
void setRefLayer(int refLayer)
Definition: AlgoMuon.h:36
const OMTFResult::vector1D & getHitsWord() const
Definition: OMTFResult.h:30
void setTFIdentifiers(int processor, tftype trackFinder)
Set the processor ID, track-finder type. From these two, the link is set.
const OMTFResult::vector1D & getSummaryHits() const
Definition: OMTFResult.h:24
void setDisc(int disc)
Definition: AlgoMuon.h:33
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const int mu
Definition: Constants.h:22
int getRefLayer() const
Definition: AlgoMuon.h:23
void setPatternNumber(unsigned int aPatNum)
Definition: AlgoMuon.h:43
void setHwQual(int bits)
Set compressed quality code as transmitted by hardware (4 bits)
void setHwPt(int bits)
Set compressed pT as transmitted by hardware LSB = 0.5 (9 bits)
void setHwEta(int bits)
Set compressed eta as transmitted by hardware LSB = 0.010875 (9 bits)
std::vector< unsigned int > vector1D
Definition: OMTFResult.h:13
void setHits(int hits)
Definition: AlgoMuon.h:37
int getHits() const
Definition: AlgoMuon.h:24
const OMTFResult::vector1D & getRefEtas() const
Definition: OMTFResult.h:28
void sortRefHitResults(const std::vector< OMTFProcessor::resultsMap > &procResults, std::vector< AlgoMuon > &refHitCleanCands, int charge=0)
Definition: OMTFSorter.cc:134
void setEta(int eta)
Definition: AlgoMuon.h:35
const int hwPt() const
Get compressed pT (returned int * 0.5 = pT (GeV))
void setHwSignValid(int bits)
Set whether charge measurement is valid (0 for high pT muons)
void setPhi(int phi)
Definition: AlgoMuon.h:34
AlgoMuon sortSingleResult(const OMTFResult &aResult)
Definition: OMTFSorter.cc:16
void setPhiRHit(int phiRHit)
Definition: AlgoMuon.h:42
std::vector< l1t::RegionalMuonCand > candidates(unsigned int iProcessor, l1t::tftype mtfType, const std::vector< AlgoMuon > &algoCands)
Definition: OMTFSorter.cc:160
void setRefHitNumber(unsigned int aRefHitNum)
Definition: AlgoMuon.h:44
int getPhi() const
Definition: AlgoMuon.h:21
int getPhiRHit() const
Definition: AlgoMuon.h:29
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
bool checkHitPatternValidity(unsigned int hits)
Definition: OMTFSorter.cc:147
void setHwSign(int bits)
Set charge sign bit (charge = (-1)^(sign))