CMS 3D CMS Logo

OMTFProcessor.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <algorithm>
3 
8 
10 
15 
17 
22  for (auto it : theGPs)
23  delete it.second;
24 }
28  myResults.clear();
29  for (auto it : theGPs)
30  delete it.second;
31  theGPs.clear();
32 }
35 bool OMTFProcessor::configure(const OMTFConfiguration *omtfConfig, const L1TMuonOverlapParams *omtfPatterns) {
37 
38  myOmtfConfig = omtfConfig;
39 
41 
42  const l1t::LUT *chargeLUT = omtfPatterns->chargeLUT();
43  const l1t::LUT *etaLUT = omtfPatterns->etaLUT();
44  const l1t::LUT *ptLUT = omtfPatterns->ptLUT();
45  const l1t::LUT *pdfLUT = omtfPatterns->pdfLUT();
46  const l1t::LUT *meanDistPhiLUT = omtfPatterns->meanDistPhiLUT();
47 
48  unsigned int nGPs = myOmtfConfig->nGoldenPatterns();
49  unsigned int address = 0;
50  unsigned int iEta, iPt;
51  int iCharge;
52  for (unsigned int iGP = 0; iGP < nGPs; ++iGP) {
53  address = iGP;
54  iEta = etaLUT->data(address);
55  iCharge = chargeLUT->data(address) == 0 ? -1 : 1;
56  iPt = ptLUT->data(address);
57 
63  for (unsigned int iLayer = 0; iLayer < myOmtfConfig->nLayers(); ++iLayer) {
65  for (unsigned int iRefLayer = 0; iRefLayer < myOmtfConfig->nRefLayers(); ++iRefLayer) {
66  address = iRefLayer + iLayer * myOmtfConfig->nRefLayers() +
68  meanDistPhi1D[iRefLayer] = meanDistPhiLUT->data(address) - (1 << (meanDistPhiLUT->nrBitsData() - 1));
69  }
70  meanDistPhi2D[iLayer] = meanDistPhi1D;
72  for (unsigned int iRefLayer = 0; iRefLayer < myOmtfConfig->nRefLayers(); ++iRefLayer) {
73  pdf1D.assign(1 << myOmtfConfig->nPdfAddrBits(), 0);
74  for (unsigned int iPdf = 0; iPdf < (unsigned int)(1 << myOmtfConfig->nPdfAddrBits()); ++iPdf) {
75  address = iPdf + iRefLayer * (1 << myOmtfConfig->nPdfAddrBits()) +
76  iLayer * myOmtfConfig->nRefLayers() * (1 << myOmtfConfig->nPdfAddrBits()) +
78  pdf1D[iPdf] = pdfLUT->data(address);
79  }
80  pdf2D[iRefLayer] = pdf1D;
81  }
82  pdf3D[iLayer] = pdf2D;
83  }
84  Key aKey(iEta, iPt, iCharge, iGP);
85 
86  GoldenPattern *aGP = new GoldenPattern(aKey, myOmtfConfig);
87  aGP->setMeanDistPhi(meanDistPhi2D);
88  aGP->setPdf(pdf3D);
89  addGP(aGP);
90  }
91  return true;
92 }
96  if (theGPs.find(aGP->key()) != theGPs.end()) {
97  throw cms::Exception("Corrupted Golden Patterns data")
98  << "OMTFProcessor::addGP(...) "
99  << " Reading two Golden Patterns with the same key: " << aGP->key() << std::endl;
100  } else
101  theGPs[aGP->key()] = aGP;
102 
103  for (auto &itRegion : myResults) {
104  OMTFResult aResult;
105  aResult.configure(myOmtfConfig);
106  itRegion[aGP->key()] = aResult;
107  }
108 
109  return true;
110 }
114  Key aKey(0, 9, charge);
115 
116  while (theGPs.find(aKey) != theGPs.end()) {
117  GoldenPattern *aGP1 = theGPs.find(aKey)->second;
118  GoldenPattern *aGP2 = aGP1;
119  GoldenPattern *aGP3 = aGP1;
120  GoldenPattern *aGP4 = aGP1;
121 
122  ++aKey.thePtCode;
123  while (theGPs.find(aKey) == theGPs.end() && aKey.thePtCode <= 401)
124  ++aKey.thePtCode;
125  if (aKey.thePtCode <= 401 && theGPs.find(aKey) != theGPs.end())
126  aGP2 = theGPs.find(aKey)->second;
127 
128  if (aKey.thePtCode > 71) {
129  ++aKey.thePtCode;
130  while (theGPs.find(aKey) == theGPs.end() && aKey.thePtCode <= 401)
131  ++aKey.thePtCode;
132  if (aKey.thePtCode <= 401 && theGPs.find(aKey) != theGPs.end())
133  aGP3 = theGPs.find(aKey)->second;
134 
135  ++aKey.thePtCode;
136  while (theGPs.find(aKey) == theGPs.end() && aKey.thePtCode <= 401)
137  ++aKey.thePtCode;
138  if (aKey.thePtCode <= 401 && theGPs.find(aKey) != theGPs.end())
139  aGP4 = theGPs.find(aKey)->second;
140  } else {
141  aGP3 = aGP1;
142  aGP4 = aGP2;
143  }
144  //HACK. Have to clean this up.
146  ++aKey.thePtCode;
147  while (theGPs.find(aKey) == theGPs.end() && aKey.thePtCode <= 401)
148  ++aKey.thePtCode;
150 
151  GoldenPattern::vector2D meanDistPhi = aGP1->getMeanDistPhi();
152 
153  GoldenPattern::vector2D meanDistPhi1 = aGP1->getMeanDistPhi();
154  GoldenPattern::vector2D meanDistPhi2 = aGP2->getMeanDistPhi();
155  GoldenPattern::vector2D meanDistPhi3 = aGP3->getMeanDistPhi();
156  GoldenPattern::vector2D meanDistPhi4 = aGP4->getMeanDistPhi();
157 
158  for (unsigned int iLayer = 0; iLayer < myOmtfConfig->nLayers(); ++iLayer) {
159  for (unsigned int iRefLayer = 0; iRefLayer < myOmtfConfig->nRefLayers(); ++iRefLayer) {
160  meanDistPhi[iLayer][iRefLayer] += meanDistPhi2[iLayer][iRefLayer];
161  meanDistPhi[iLayer][iRefLayer] += meanDistPhi3[iLayer][iRefLayer];
162  meanDistPhi[iLayer][iRefLayer] += meanDistPhi4[iLayer][iRefLayer];
163  meanDistPhi[iLayer][iRefLayer] /= 4;
164  }
165  }
166 
167  aGP1->setMeanDistPhi(meanDistPhi);
168  aGP2->setMeanDistPhi(meanDistPhi);
169 
170  shiftGP(aGP1, meanDistPhi, meanDistPhi1);
171  shiftGP(aGP2, meanDistPhi, meanDistPhi2);
172  if (aGP3 != aGP1 && aGP4 != aGP2) {
173  aGP3->setMeanDistPhi(meanDistPhi);
174  aGP4->setMeanDistPhi(meanDistPhi);
175  shiftGP(aGP3, meanDistPhi, meanDistPhi3);
176  shiftGP(aGP4, meanDistPhi, meanDistPhi4);
177  }
178  }
179 }
183  const GoldenPattern::vector2D &meanDistPhiNew,
184  const GoldenPattern::vector2D &meanDistPhiOld) {
187  unsigned int nPdfBins = exp2(myOmtfConfig->nPdfAddrBits());
188  GoldenPattern::vector3D pdfAllRef = aGP->getPdf();
189 
190  int indexShift = 0;
191  for (unsigned int iLayer = 0; iLayer < myOmtfConfig->nLayers(); ++iLayer) {
192  for (unsigned int iRefLayer = 0; iRefLayer < myOmtfConfig->nRefLayers(); ++iRefLayer) {
193  indexShift = meanDistPhiOld[iLayer][iRefLayer] - meanDistPhiNew[iLayer][iRefLayer];
194  for (unsigned int iPdfBin = 0; iPdfBin < nPdfBins; ++iPdfBin)
195  pdfAllRef[iLayer][iRefLayer][iPdfBin] = 0;
196  for (unsigned int iPdfBin = 0; iPdfBin < nPdfBins; ++iPdfBin) {
197  if ((int)(iPdfBin) + indexShift >= 0 && iPdfBin + indexShift < nPdfBins)
198  pdfAllRef[iLayer][iRefLayer][iPdfBin + indexShift] = aGP->pdfValue(iLayer, iRefLayer, iPdfBin);
199  }
200  }
201  }
202  aGP->setPdf(pdfAllRef);
203 }
206 const std::map<Key, GoldenPattern *> &OMTFProcessor::getPatterns() const { return theGPs; }
209 const std::vector<OMTFProcessor::resultsMap> &OMTFProcessor::processInput(unsigned int iProcessor,
210  const OMTFinput &aInput) {
211  for (auto &itRegion : myResults)
212  for (auto &itKey : itRegion)
213  itKey.second.clear();
214 
217  std::bitset<128> refHitsBits = aInput.getRefHits(iProcessor);
218  if (refHitsBits.none())
219  return myResults;
220 
221  for (unsigned int iLayer = 0; iLayer < myOmtfConfig->nLayers(); ++iLayer) {
222  const OMTFinput::vector1D &layerHits = aInput.getLayerData(iLayer);
223  if (layerHits.empty())
224  continue;
226  unsigned int nTestedRefHits = myOmtfConfig->nTestRefHits();
227  for (unsigned int iRefHit = 0; iRefHit < myOmtfConfig->nRefHits(); ++iRefHit) {
228  if (!refHitsBits[iRefHit])
229  continue;
230  if (nTestedRefHits-- == 0)
231  break;
232  const RefHitDef &aRefHitDef = myOmtfConfig->getRefHitsDefs()[iProcessor][iRefHit];
233 
234  int phiRef = aInput.getLayerData(myOmtfConfig->getRefToLogicNumber()[aRefHitDef.iRefLayer])[aRefHitDef.iInput];
235  int etaRef =
236  aInput.getLayerData(myOmtfConfig->getRefToLogicNumber()[aRefHitDef.iRefLayer], true)[aRefHitDef.iInput];
237  unsigned int iRegion = aRefHitDef.iRegion;
238 
239  if (myOmtfConfig->getBendingLayers().count(iLayer))
240  phiRef = 0;
241  const OMTFinput::vector1D restrictedLayerHits = restrictInput(iProcessor, iRegion, iLayer, layerHits);
242  for (auto itGP : theGPs) {
243  GoldenPattern::layerResult aLayerResult =
244  itGP.second->process1Layer1RefLayer(aRefHitDef.iRefLayer, iLayer, phiRef, restrictedLayerHits);
245  int phiRefSt2 = itGP.second->propagateRefPhi(phiRef, etaRef, aRefHitDef.iRefLayer);
246  myResults[myOmtfConfig->nTestRefHits() - nTestedRefHits - 1][itGP.second->key()].setRefPhiRHits(
247  aRefHitDef.iRefLayer, phiRef);
248  myResults[myOmtfConfig->nTestRefHits() - nTestedRefHits - 1][itGP.second->key()].addResult(
249  aRefHitDef.iRefLayer, iLayer, aLayerResult.first, phiRefSt2, etaRef);
250  }
251  }
252  }
255  for (auto &itRefHit : myResults)
256  for (auto &itKey : itRefHit)
257  itKey.second.finalise();
258 
259  std::ostringstream myStr;
260  myStr << "iProcessor: " << iProcessor << std::endl;
261  myStr << "Input: ------------" << std::endl;
262  myStr << aInput << std::endl;
263  edm::LogInfo("OMTF processor") << myStr.str();
264 
265  return myResults;
266 }
270  unsigned int iRegion,
271  unsigned int iLayer,
272  const OMTFinput::vector1D &layerHits) {
273  OMTFinput::vector1D myHits = layerHits;
274 
275  unsigned int iStart = myOmtfConfig->getConnections()[iProcessor][iRegion][iLayer].first;
276  unsigned int iEnd = iStart + myOmtfConfig->getConnections()[iProcessor][iRegion][iLayer].second - 1;
277 
278  for (unsigned int iInput = 0; iInput < 14; ++iInput) {
279  if (iInput < iStart || iInput > iEnd)
280  myHits[iInput] = myOmtfConfig->nPhiBins();
281  }
282  return myHits;
283 }
286 void OMTFProcessor::fillCounts(unsigned int iProcessor, const OMTFinput &aInput, const SimTrack *aSimMuon) {
287  int theCharge = (abs(aSimMuon->type()) == 13) ? aSimMuon->type() / -13 : 0;
288  unsigned int iPt = RPCConst::iptFromPt(aSimMuon->momentum().pt());
291  iPt += 1;
292  if (iPt > 31)
293  iPt = 200 * 2 + 1;
294  else
295  iPt = RPCConst::ptFromIpt(iPt) * 2.0 +
296  1; //MicroGMT has 0.5 GeV step size, with lower bin edge (uGMT_pt_code - 1)*step_size
298 
300  std::bitset<128> refHitsBits = aInput.getRefHits(iProcessor);
301  if (refHitsBits.none())
302  return;
303 
304  std::ostringstream myStr;
305  myStr << "iProcessor: " << iProcessor << std::endl;
306  myStr << "Input: ------------" << std::endl;
307  myStr << aInput << std::endl;
308  edm::LogInfo("OMTF processor") << myStr.str();
309 
310  for (unsigned int iLayer = 0; iLayer < myOmtfConfig->nLayers(); ++iLayer) {
311  const OMTFinput::vector1D &layerHits = aInput.getLayerData(iLayer);
312  if (layerHits.empty())
313  continue;
315  for (unsigned int iRefHit = 0; iRefHit < myOmtfConfig->nRefHits(); ++iRefHit) {
316  if (!refHitsBits[iRefHit])
317  continue;
318  const RefHitDef &aRefHitDef = myOmtfConfig->getRefHitsDefs()[iProcessor][iRefHit];
319  int phiRef = aInput.getLayerData(myOmtfConfig->getRefToLogicNumber()[aRefHitDef.iRefLayer])[aRefHitDef.iInput];
320  unsigned int iRegion = aRefHitDef.iRegion;
321  if (myOmtfConfig->getBendingLayers().count(iLayer))
322  phiRef = 0;
323  const OMTFinput::vector1D restrictedLayerHits = restrictInput(iProcessor, iRegion, iLayer, layerHits);
324  for (auto itGP : theGPs) {
325  if (itGP.first.theCharge != theCharge)
326  continue;
327  if (itGP.first.thePtCode != iPt)
328  continue;
329  itGP.second->addCount(aRefHitDef.iRefLayer, iLayer, phiRef, restrictedLayerHits);
330  }
331  }
332  }
333 }
void fillCounts(unsigned int iProcessor, const OMTFinput &aInput, const SimTrack *aSimMuon)
std::bitset< 128 > getRefHits(unsigned int iProcessor) const
Definition: OMTFinput.cc:26
std::vector< OMTFProcessor::resultsMap > myResults
Definition: OMTFProcessor.h:82
const l1t::LUT * chargeLUT() const
Golden Patterns definitions.
const ap_uint< BITSPT > ptLUT[2251]
Definition: TPSLUTs.h:18
std::vector< int > vector1D
Definition: GoldenPattern.h:46
unsigned int nrBitsData() const
Definition: LUT.h:53
bool addGP(GoldenPattern *aGP)
void averagePatterns(int charge)
unsigned int iInput
Hit input number within a cone.
const std::vector< std::vector< RefHitDef > > & getRefHitsDefs() const
std::vector< int > vector1D
Definition: OMTFinput.h:13
std::pair< int, bool > layerResult
Definition: GoldenPattern.h:49
const std::map< Key, GoldenPattern * > & getPatterns() const
Return map of GoldenPatterns.
unsigned int thePtCode
Definition: GoldenPattern.h:35
std::map< Key, OMTFResult > resultsMap
Definition: OMTFProcessor.h:21
unsigned int nGoldenPatterns() const
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
unsigned int nRefHits() const
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:22
int pdfValue(unsigned int iLayer, unsigned int iRefLayer, unsigned int iBin) const
Definition: GoldenPattern.h:68
const vector3D_pair & getConnections() const
std::map< Key, GoldenPattern * > theGPs
Map holding Golden Patterns.
Definition: OMTFProcessor.h:77
const OMTFinput::vector1D & getLayerData(unsigned int iLayer, bool giveEta=false) const
Definition: OMTFinput.cc:17
const vector2D & getMeanDistPhi() const
Definition: GoldenPattern.h:60
unsigned int nPhiBins() const
std::vector< vector1D > vector2D
Definition: GoldenPattern.h:47
std::vector< vector2D > vector3D
Definition: GoldenPattern.h:48
void setPdf(const vector3D &aPdf)
Definition: GoldenPattern.h:64
Key key() const
Definition: GoldenPattern.h:56
unsigned int nPdfAddrBits() const
void configure(const OMTFConfiguration *omtfConfig)
Definition: OMTFResult.cc:10
int data(unsigned int address) const
Definition: LUT.h:46
void shiftGP(GoldenPattern *aGP, const GoldenPattern::vector2D &meanDistPhiNew, const GoldenPattern::vector2D &meanDistPhiOld)
const std::vector< OMTFProcessor::resultsMap > & processInput(unsigned int iProcessor, const OMTFinput &aInput)
const l1t::LUT * pdfLUT() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int nLayers() const
const std::vector< int > & getRefToLogicNumber() const
OMTFinput::vector1D restrictInput(unsigned int iProcessor, unsigned int iCone, unsigned int iLayer, const OMTFinput::vector1D &layerHits)
static double ptFromIpt(const int ipt)
Definition: RPCConst.cc:29
unsigned int nRefLayers() const
unsigned int nTestRefHits() const
Log< level::Info, false > LogInfo
Definition: LUT.h:29
const std::set< int > & getBendingLayers() const
bool configure(const OMTFConfiguration *omtfParams, const L1TMuonOverlapParams *omtfPatterns)
Fill GP map with patterns from CondFormats object.
const OMTFConfiguration * myOmtfConfig
Definition: OMTFProcessor.h:86
void resetConfiguration()
Reset all configuration parameters.
const vector3D & getPdf() const
Definition: GoldenPattern.h:62
void setMeanDistPhi(const vector2D &aMeanDistPhi)
Definition: GoldenPattern.h:58
unsigned int iRefLayer
Reference layer logic number (0-7)
const l1t::LUT * meanDistPhiLUT() const
unsigned int iRegion
Region number assigned to this referecne hit.
const l1t::LUT * ptLUT() const
static int iptFromPt(const double pt)
Definition: RPCConst.cc:10
const l1t::LUT * etaLUT() const
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
const uint etaLUT[4082]
Definition: TPSLUTs.h:142