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 
18 
20 
22 
26 
27  if(theConfig.getParameter<bool>("configFromXML")){
28  if ( !theConfig.exists("patternsXMLFiles") ) return;
29  std::vector<std::string> fileNames;
30  for(auto it: theConfig.getParameter<std::vector<edm::ParameterSet> >("patternsXMLFiles")){
31  fileNames.push_back(it.getParameter<edm::FileInPath>("patternsXMLFile").fullPath());
32  }
33 
35  XMLConfigReader myReader;
36  for(auto it: fileNames){
37  myReader.setPatternsFile(it);
38  configure(&myReader);
39  }
40  }
41 }
45 
46  for(auto it: theGPs) delete it.second;
47 
48 }
52 
53  myResults.clear();
54  theGPs.clear();
55 }
59 
61 
63 
64  const std::vector<GoldenPattern *> & aGPs = aReader->readPatterns();
65  for(auto it: aGPs){
66  if(!addGP(it)) return false;
67  }
68 
69  return true;
70 }
73 bool OMTFProcessor::configure( std::shared_ptr<L1TMuonOverlapParams> omtfParams){
74 
76 
78 
79  l1t::LUT* chargeLUT = omtfParams->chargeLUT();
80  l1t::LUT* etaLUT = omtfParams->etaLUT();
81  l1t::LUT* ptLUT = omtfParams->ptLUT();
82  l1t::LUT* pdfLUT = omtfParams->pdfLUT();
83  l1t::LUT* meanDistPhiLUT = omtfParams->meanDistPhiLUT();
84 
85  unsigned int nGPs = OMTFConfiguration::nGoldenPatterns;
86  unsigned int address = 0;
87  unsigned int iEta, iPt, iCharge;
88  for(unsigned int iGP=0;iGP<nGPs;++iGP){
89  address = iGP;
90  iEta = etaLUT->data(address);
91  iCharge = chargeLUT->data(address);
92  if(iCharge==0) iCharge = -1;//FIXME: Standarise to 0,1
93  iPt = ptLUT->data(address);
94 
100  for(unsigned int iLayer=0;iLayer<OMTFConfiguration::nLayers;++iLayer){
102  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::nRefLayers;++iRefLayer){
103  address = iRefLayer + iLayer*OMTFConfiguration::nRefLayers + iGP*(OMTFConfiguration::nRefLayers*OMTFConfiguration::nLayers);
104  meanDistPhi1D[iRefLayer] = meanDistPhiLUT->data(address) - (1<<(meanDistPhiLUT->nrBitsData() -1));
105  }
106  meanDistPhi2D[iLayer] = meanDistPhi1D;
108  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::nRefLayers;++iRefLayer){
109  pdf1D.assign(1<<OMTFConfiguration::nPdfAddrBits,0);
110  for(unsigned int iPdf=0;iPdf<(unsigned int)(1<<OMTFConfiguration::nPdfAddrBits);++iPdf){
111  address = iPdf + iRefLayer*(1<<OMTFConfiguration::nPdfAddrBits) +
112  iLayer*OMTFConfiguration::nRefLayers*(1<<OMTFConfiguration::nPdfAddrBits) +
113  iGP*OMTFConfiguration::nLayers*OMTFConfiguration::nRefLayers*(1<<OMTFConfiguration::nPdfAddrBits);
114  pdf1D[iPdf] = pdfLUT->data(address);
115  }
116  pdf2D[iRefLayer] = pdf1D;
117  }
118  pdf3D[iLayer] = pdf2D;
119  }
120  Key aKey(iEta,iPt,iCharge);
121  GoldenPattern *aGP = new GoldenPattern(aKey);
122  aGP->setMeanDistPhi(meanDistPhi2D);
123  aGP->setPdf(pdf3D);
124  addGP(aGP);
125  }
126  return true;
127 }
131 
132  if(theGPs.find(aGP->key())!=theGPs.end()){
133  throw cms::Exception("Corrupted Golden Patterns data")
134  <<"OMTFProcessor::addGP(...) "
135  <<" Reading two Golden Patterns with the same key: "
136  <<aGP->key()<<std::endl;
137  }
138  else theGPs[aGP->key()] = new GoldenPattern(*aGP);
139 
140  for(auto & itRegion: myResults) itRegion[aGP->key()] = OMTFResult();
141 
142  return true;
143 }
147 
148  Key aKey(1, 4, charge);
149 
150  while(theGPs.find(aKey)!=theGPs.end()){
151 
152  GoldenPattern *aGP1 = theGPs.find(aKey)->second;
153  GoldenPattern *aGP2 = aGP1;
154  GoldenPattern *aGP3 = aGP1;
155  GoldenPattern *aGP4 = aGP1;
156 
157  ++aKey.thePtCode;
158  if(aKey.thePtCode<=31 && theGPs.find(aKey)!=theGPs.end()) aGP2 = theGPs.find(aKey)->second;
159 
160  if(aKey.thePtCode>19){
161  ++aKey.thePtCode;
162  if(aKey.thePtCode<=31 && theGPs.find(aKey)!=theGPs.end()) aGP3 = theGPs.find(aKey)->second;
163 
164  ++aKey.thePtCode;
165  if(aKey.thePtCode<=31 && theGPs.find(aKey)!=theGPs.end()) aGP4 = theGPs.find(aKey)->second;
166  }
167  else{
168  aGP3 = aGP1;
169  aGP4 = aGP2;
170  }
171  ++aKey.thePtCode;
172 
173 
174  GoldenPattern::vector2D meanDistPhi = aGP1->getMeanDistPhi();
175 
176  GoldenPattern::vector2D meanDistPhi1 = aGP1->getMeanDistPhi();
177  GoldenPattern::vector2D meanDistPhi2 = aGP2->getMeanDistPhi();
178  GoldenPattern::vector2D meanDistPhi3 = aGP3->getMeanDistPhi();
179  GoldenPattern::vector2D meanDistPhi4 = aGP4->getMeanDistPhi();
180  /*
181  std::cout<<"Key: "
182  <<aGP1->key()
183  <<" "<<aGP2->key()
184  <<" "<<aGP3->key()
185  <<" "<<aGP4->key()<<std::endl;
186  */
187  for(unsigned int iLayer=0;iLayer<OMTFConfiguration::nLayers;++iLayer){
188  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::nRefLayers;++iRefLayer){
189  meanDistPhi[iLayer][iRefLayer]+=meanDistPhi2[iLayer][iRefLayer];
190  meanDistPhi[iLayer][iRefLayer]+=meanDistPhi3[iLayer][iRefLayer];
191  meanDistPhi[iLayer][iRefLayer]+=meanDistPhi4[iLayer][iRefLayer];
192  meanDistPhi[iLayer][iRefLayer]/=4;
193  /*
194  std::cout<<"Mean distPhi: "<<meanDistPhi[iLayer][iRefLayer]
195  <<" "<<meanDistPhi1[iLayer][iRefLayer]
196  <<" "<<meanDistPhi2[iLayer][iRefLayer]
197  <<" "<<meanDistPhi3[iLayer][iRefLayer]
198  <<" "<<meanDistPhi4[iLayer][iRefLayer]<<std::endl;
199  */
200  }
201  }
202 
203  aGP1->setMeanDistPhi(meanDistPhi);
204  aGP2->setMeanDistPhi(meanDistPhi);
205 
206 
207  shiftGP(aGP1,meanDistPhi, meanDistPhi1);
208  shiftGP(aGP2,meanDistPhi, meanDistPhi2);
209  if(aGP3!=aGP1 && aGP4!=aGP2){
210  aGP3->setMeanDistPhi(meanDistPhi);
211  aGP4->setMeanDistPhi(meanDistPhi);
212  shiftGP(aGP3,meanDistPhi, meanDistPhi3);
213  shiftGP(aGP4,meanDistPhi, meanDistPhi4);
214  }
215  }
216 
217 }
221  const GoldenPattern::vector2D & meanDistPhiNew,
222  const GoldenPattern::vector2D & meanDistPhiOld){
223 
226  unsigned int nPdfBins = exp2(OMTFConfiguration::nPdfAddrBits);
227 
228  GoldenPattern::vector3D pdfAllRef = aGP->getPdf();
229 
230  int indexShift = 0;
231  for(unsigned int iLayer=0;iLayer<OMTFConfiguration::nLayers;++iLayer){
232  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::nRefLayers;++iRefLayer){
233  indexShift = meanDistPhiOld[iLayer][iRefLayer] - meanDistPhiNew[iLayer][iRefLayer];
234  for(unsigned int iPdfBin=0;iPdfBin<nPdfBins;++iPdfBin) pdfAllRef[iLayer][iRefLayer][iPdfBin] = 0;
235  for(unsigned int iPdfBin=0;iPdfBin<nPdfBins;++iPdfBin){
236  if((int)(iPdfBin)+indexShift>=0 && iPdfBin+indexShift<nPdfBins)
237  pdfAllRef[iLayer][iRefLayer][iPdfBin+indexShift] = aGP->pdfValue(iLayer, iRefLayer, iPdfBin);
238  }
239  }
240  }
241  aGP->setPdf(pdfAllRef);
242 }
245 const std::map<Key,GoldenPattern*> & OMTFProcessor::getPatterns() const{ return theGPs; }
248 const std::vector<OMTFProcessor::resultsMap> & OMTFProcessor::processInput(unsigned int iProcessor,
249  const OMTFinput & aInput){
250 
251  for(auto & itRegion: myResults) for(auto & itKey: itRegion) itKey.second.clear();
252 
255  std::bitset<128> refHitsBits = aInput.getRefHits(iProcessor);
256  if(refHitsBits.none()) return myResults;
257 
258  for(unsigned int iLayer=0;iLayer<OMTFConfiguration::nLayers;++iLayer){
259  const OMTFinput::vector1D & layerHits = aInput.getLayerData(iLayer);
260  if(!layerHits.size()) continue;
263  unsigned int nTestedRefHits = OMTFConfiguration::nTestRefHits;
264  for(unsigned int iRefHit=0;iRefHit<OMTFConfiguration::nRefHits;++iRefHit){
265  if(!refHitsBits[iRefHit]) continue;
266  if(nTestedRefHits--==0) break;
267  const RefHitDef & aRefHitDef = OMTFConfiguration::refHitsDefs[iProcessor][iRefHit];
268  int phiRef = aInput.getLayerData(OMTFConfiguration::refToLogicNumber[aRefHitDef.iRefLayer])[aRefHitDef.iInput];
269  int etaRef = aInput.getLayerData(OMTFConfiguration::refToLogicNumber[aRefHitDef.iRefLayer],true)[aRefHitDef.iInput];
270  unsigned int iRegion = aRefHitDef.iRegion;
271  if(OMTFConfiguration::bendingLayers.count(iLayer)) phiRef = 0;
272  const OMTFinput::vector1D restrictedLayerHits = restrictInput(iProcessor, iRegion, iLayer,layerHits);
273  for(auto itGP: theGPs){
274  GoldenPattern::layerResult aLayerResult = itGP.second->process1Layer1RefLayer(aRefHitDef.iRefLayer,iLayer,
275  phiRef,
276  restrictedLayerHits);
277 
278  int phiRefSt2 = itGP.second->propagateRefPhi(phiRef, etaRef, aRefHitDef.iRefLayer);
279  myResults[OMTFConfiguration::nTestRefHits-nTestedRefHits-1][itGP.second->key()].addResult(aRefHitDef.iRefLayer,iLayer,
280  aLayerResult.first,
281  phiRefSt2,etaRef);
282  }
283  }
284  }
287  for(auto & itRefHit: myResults) for(auto & itKey: itRefHit) itKey.second.finalise();
288 
289  //#ifndef NDEBUG
290  std::ostringstream myStr;
291  myStr<<"iProcessor: "<<iProcessor<<std::endl;
292  myStr<<"Input: ------------"<<std::endl;
293  myStr<<aInput<<std::endl;
294  /*
295  for(auto itRefHit: myResults){
296  myStr<<"--- Reference hit ---"<<std::endl;
297  for(auto itKey: itRefHit){
298  if(itKey.second.empty()) continue;
299  myStr<<itKey.first<<std::endl;
300  myStr<<itKey.second<<std::endl;
301  }
302  myStr<<"--------------------"<<std::endl;
303  }
304  */
305  //LogDebug("OMTF processor")<<myStr.str();
306  edm::LogInfo("OMTF processor")<<myStr.str();
307  //#endif
308 
309  return myResults;
310 }
313 OMTFinput OMTFProcessor::shiftInput(unsigned int iProcessor,
314  const OMTFinput & aInput){
315 
316  int minPhi = OMTFConfiguration::globalPhiStart(iProcessor);
317 
319  if(minPhi<0) minPhi+=OMTFConfiguration::nPhiBins;
320 
321  OMTFinput myCopy = aInput;
322  myCopy.shiftMyPhi(minPhi);
323 
324  return myCopy;
325 }
329  unsigned int iRegion,
330  unsigned int iLayer,
331  const OMTFinput::vector1D & layerHits){
332 
333  OMTFinput::vector1D myHits = layerHits;
334 
335  unsigned int iStart = OMTFConfiguration::connections[iProcessor][iRegion][iLayer].first;
336  unsigned int iEnd = iStart + OMTFConfiguration::connections[iProcessor][iRegion][iLayer].second -1;
337 
338  for(unsigned int iInput=0;iInput<14;++iInput){
339  if(iInput<iStart || iInput>iEnd) myHits[iInput] = OMTFConfiguration::nPhiBins;
340  }
341 
342  return myHits;
343 }
346 void OMTFProcessor::fillCounts(unsigned int iProcessor,
347  const OMTFinput & aInput,
348  const SimTrack* aSimMuon){
349 
350  int theCharge = (abs(aSimMuon->type()) == 13) ? aSimMuon->type()/-13 : 0;
351  unsigned int iPt = RPCConst::iptFromPt(aSimMuon->momentum().pt());
352 
354  std::bitset<128> refHitsBits = aInput.getRefHits(iProcessor);
355  if(refHitsBits.none()) return;
356 
357  std::ostringstream myStr;
358  myStr<<"iProcessor: "<<iProcessor<<std::endl;
359  myStr<<"Input: ------------"<<std::endl;
360  myStr<<aInput<<std::endl;
361  edm::LogInfo("OMTF processor")<<myStr.str();
362 
363  for(unsigned int iLayer=0;iLayer<OMTFConfiguration::nLayers;++iLayer){
364  const OMTFinput::vector1D & layerHits = aInput.getLayerData(iLayer);
365  if(!layerHits.size()) continue;
368  for(unsigned int iRefHit=0;iRefHit<OMTFConfiguration::nRefHits;++iRefHit){
369  if(!refHitsBits[iRefHit]) continue;
370  const RefHitDef & aRefHitDef = OMTFConfiguration::refHitsDefs[iProcessor][iRefHit];
371  int phiRef = aInput.getLayerData(OMTFConfiguration::refToLogicNumber[aRefHitDef.iRefLayer])[aRefHitDef.iInput];
372  unsigned int iRegion = aRefHitDef.iRegion;
373  if(OMTFConfiguration::bendingLayers.count(iLayer)) phiRef = 0;
374  const OMTFinput::vector1D restrictedLayerHits = restrictInput(iProcessor, iRegion, iLayer,layerHits);
375  for(auto itGP: theGPs){
376  if(itGP.first.theCharge!=theCharge) continue;
377  if(itGP.first.thePtCode!=iPt) continue;
378  itGP.second->addCount(aRefHitDef.iRefLayer,iLayer,phiRef,restrictedLayerHits);
379  }
380  }
381  }
382 }
Key key() const
Definition: GoldenPattern.h:59
T getParameter(std::string const &) const
static unsigned int nLayers
void fillCounts(unsigned int iProcessor, const OMTFinput &aInput, const SimTrack *aSimMuon)
void averagePatterns(int charge)
void shiftMyPhi(int phiShift)
Apply shift to all data.
Definition: OMTFinput.cc:105
static vector3D_A connections
std::vector< int > vector1D
Definition: GoldenPattern.h:49
bool exists(std::string const &parameterName) const
checks if a parameter exists
const vector2D & getMeanDistPhi() const
Definition: GoldenPattern.h:63
static int globalPhiStart(unsigned int iProcessor)
unsigned int iInput
Hit input number within a cone.
std::map< Key, GoldenPattern * > theGPs
Map holding Golden Patterns.
Definition: OMTFProcessor.h:98
std::map< Key, OMTFResult > resultsMap
Definition: OMTFProcessor.h:24
std::vector< int > vector1D
Definition: OMTFinput.h:14
bool configure(XMLConfigReader *aReader)
Fill GP map with patterns from XML file.
unsigned int thePtCode
Definition: GoldenPattern.h:36
bool addGP(GoldenPattern *aGP)
const OMTFinput::vector1D & getLayerData(unsigned int iLayer, bool giveEta=false) const
Definition: OMTFinput.cc:18
static unsigned int nPdfAddrBits
unsigned int nrBitsData() const
Definition: LUT.h:51
std::vector< vector1D > vector2D
Definition: GoldenPattern.h:50
std::vector< vector2D > vector3D
Definition: GoldenPattern.h:51
void setPdf(const vector3D &aPdf)
Definition: GoldenPattern.h:67
static unsigned int nTestRefHits
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static unsigned int nPhiBins
std::bitset< 128 > getRefHits(unsigned int iProcessor) const
Definition: OMTFinput.cc:26
std::pair< int, bool > layerResult
Definition: GoldenPattern.h:52
static std::vector< int > refToLogicNumber
void setPatternsFile(const std::string &fName)
void resetConfiguration()
Reset all configuration parameters.
Definition: LUT.h:29
static unsigned int nRefLayers
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:71
std::vector< GoldenPattern * > readPatterns()
void shiftGP(GoldenPattern *aGP, const GoldenPattern::vector2D &meanDistPhiNew, const GoldenPattern::vector2D &meanDistPhiOld)
static unsigned int nRefHits
static std::set< int > bendingLayers
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:25
OMTFProcessor(const edm::ParameterSet &cfg)
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:22
void setMeanDistPhi(const vector2D &aMeanDistPhi)
Definition: GoldenPattern.h:61
unsigned int iRefLayer
Reference layer logic number (0-7)
const std::vector< OMTFProcessor::resultsMap > & processInput(unsigned int iProcessor, const OMTFinput &aInput)
OMTFinput shiftInput(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 unsigned int nGoldenPatterns
tuple fileNames
Definition: LaserDQM_cfg.py:34
std::string fullPath() const
Definition: FileInPath.cc:184
static int iptFromPt(const double pt)
Definition: RPCConst.cc:10
const std::map< Key, GoldenPattern * > & getPatterns() const
Return map of GoldenPatterns.
std::vector< OMTFProcessor::resultsMap > myResults
const vector3D & getPdf() const
Definition: GoldenPattern.h:65
static std::vector< std::vector< RefHitDef > > refHitsDefs