CMS 3D CMS Logo

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