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 
17 
19 
23 OMTFProcessor::OMTFProcessor(const edm::ParameterSet & theConfig, OMTFConfiguration * omtf_config) : m_omtf_config(omtf_config) {
24 
25  if(theConfig.getParameter<bool>("configFromXML")){
26  if ( !theConfig.exists("patternsXMLFiles") ) return;
27  std::vector<std::string> fileNames;
28  for(auto it: theConfig.getParameter<std::vector<edm::ParameterSet> >("patternsXMLFiles")){
29  fileNames.push_back(it.getParameter<edm::FileInPath>("patternsXMLFile").fullPath());
30  }
33  for(auto it: fileNames){
34  myReader.setPatternsFile(it);
35  configure(&myReader);
36  }
37  }
38 }
42 
43  for(auto it: theGPs) delete it.second;
44 
45 }
49 
50  myResults.clear();
51  theGPs.clear();
52 }
56 
58 
60 
61  const std::vector<GoldenPattern *> & aGPs = aReader->readPatterns();
62  for(auto it: aGPs){
63  if(!addGP(it)) return false;
64  }
65 
66  return true;
67 }
71 
73 
75 
76  const l1t::LUT* chargeLUT = omtfParams->chargeLUT();
77  const l1t::LUT* etaLUT = omtfParams->etaLUT();
78  const l1t::LUT* ptLUT = omtfParams->ptLUT();
79  const l1t::LUT* pdfLUT = omtfParams->pdfLUT();
80  const l1t::LUT* meanDistPhiLUT = omtfParams->meanDistPhiLUT();
81 
82  unsigned int nGPs = OMTFConfiguration::instance()->nGoldenPatterns;
83  unsigned int address = 0;
84  unsigned int iEta, iPt, iCharge;
85  for(unsigned int iGP=0;iGP<nGPs;++iGP){
86  address = iGP;
87  iEta = etaLUT->data(address);
88  iCharge = chargeLUT->data(address)==0? -1:1;
89  iPt = ptLUT->data(address);
90  GoldenPattern::vector2D meanDistPhi2D(OMTFConfiguration::instance()->nLayers);
91  GoldenPattern::vector1D pdf1D(exp2(OMTFConfiguration::instance()->nPdfAddrBits));
95  for(unsigned int iLayer=0;iLayer<OMTFConfiguration::instance()->nLayers;++iLayer){
96  GoldenPattern::vector1D meanDistPhi1D(OMTFConfiguration::instance()->nRefLayers);
97  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::instance()->nRefLayers;++iRefLayer){
99  meanDistPhi1D[iRefLayer] = meanDistPhiLUT->data(address) - (1<<(meanDistPhiLUT->nrBitsData() -1));
100  }
101  meanDistPhi2D[iLayer] = meanDistPhi1D;
103  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::instance()->nRefLayers;++iRefLayer){
104  pdf1D.assign(1<<OMTFConfiguration::instance()->nPdfAddrBits,0);
105  for(unsigned int iPdf=0;iPdf<(unsigned int)(1<<OMTFConfiguration::instance()->nPdfAddrBits);++iPdf){
106  address = iPdf + iRefLayer*(1<<OMTFConfiguration::instance()->nPdfAddrBits) +
109  pdf1D[iPdf] = pdfLUT->data(address);
110  }
111  pdf2D[iRefLayer] = pdf1D;
112  }
113  pdf3D[iLayer] = pdf2D;
114  }
115  Key aKey(iEta,iPt,iCharge);
116 
117  GoldenPattern *aGP = new GoldenPattern(aKey);
118  aGP->setMeanDistPhi(meanDistPhi2D);
119  aGP->setPdf(pdf3D);
120  addGP(aGP);
121  }
122  return true;
123 }
127 
128  if(theGPs.find(aGP->key())!=theGPs.end()){
129  throw cms::Exception("Corrupted Golden Patterns data")
130  <<"OMTFProcessor::addGP(...) "
131  <<" Reading two Golden Patterns with the same key: "
132  <<aGP->key()<<std::endl;
133  }
134  else theGPs[aGP->key()] = new GoldenPattern(*aGP);
135 
136  for(auto & itRegion: myResults) itRegion[aGP->key()] = OMTFResult();
137 
138  return true;
139 }
143 
144  Key aKey(0, 9, charge);
145 
146  while(theGPs.find(aKey)!=theGPs.end()){
147 
148  GoldenPattern *aGP1 = theGPs.find(aKey)->second;
149  GoldenPattern *aGP2 = aGP1;
150  GoldenPattern *aGP3 = aGP1;
151  GoldenPattern *aGP4 = aGP1;
152 
153  ++aKey.thePtCode;
154  while(theGPs.find(aKey)==theGPs.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
155  if(aKey.thePtCode<=401 && theGPs.find(aKey)!=theGPs.end()) aGP2 = theGPs.find(aKey)->second;
156 
157  if(aKey.thePtCode>71){
158  ++aKey.thePtCode;
159  while(theGPs.find(aKey)==theGPs.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
160  if(aKey.thePtCode<=401 && theGPs.find(aKey)!=theGPs.end()) aGP3 = theGPs.find(aKey)->second;
161 
162  ++aKey.thePtCode;
163  while(theGPs.find(aKey)==theGPs.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
164  if(aKey.thePtCode<=401 && theGPs.find(aKey)!=theGPs.end()) aGP4 = theGPs.find(aKey)->second;
165  }
166  else{
167  aGP3 = aGP1;
168  aGP4 = aGP2;
169  }
170  //HACK. Have to clean this up.
172  ++aKey.thePtCode;
173  while(theGPs.find(aKey)==theGPs.end() && aKey.thePtCode<=401) ++aKey.thePtCode;
175 
176 
177  GoldenPattern::vector2D meanDistPhi = aGP1->getMeanDistPhi();
178 
179  GoldenPattern::vector2D meanDistPhi1 = aGP1->getMeanDistPhi();
180  GoldenPattern::vector2D meanDistPhi2 = aGP2->getMeanDistPhi();
181  GoldenPattern::vector2D meanDistPhi3 = aGP3->getMeanDistPhi();
182  GoldenPattern::vector2D meanDistPhi4 = aGP4->getMeanDistPhi();
183 
184  for(unsigned int iLayer=0;iLayer<OMTFConfiguration::instance()->nLayers;++iLayer){
185  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::instance()->nRefLayers;++iRefLayer){
186  meanDistPhi[iLayer][iRefLayer]+=meanDistPhi2[iLayer][iRefLayer];
187  meanDistPhi[iLayer][iRefLayer]+=meanDistPhi3[iLayer][iRefLayer];
188  meanDistPhi[iLayer][iRefLayer]+=meanDistPhi4[iLayer][iRefLayer];
189  meanDistPhi[iLayer][iRefLayer]/=4;
190  }
191  }
192 
193  aGP1->setMeanDistPhi(meanDistPhi);
194  aGP2->setMeanDistPhi(meanDistPhi);
195 
196 
197  shiftGP(aGP1,meanDistPhi, meanDistPhi1);
198  shiftGP(aGP2,meanDistPhi, meanDistPhi2);
199  if(aGP3!=aGP1 && aGP4!=aGP2){
200  aGP3->setMeanDistPhi(meanDistPhi);
201  aGP4->setMeanDistPhi(meanDistPhi);
202  shiftGP(aGP3,meanDistPhi, meanDistPhi3);
203  shiftGP(aGP4,meanDistPhi, meanDistPhi4);
204  }
205  }
206 
207 }
211  const GoldenPattern::vector2D & meanDistPhiNew,
212  const GoldenPattern::vector2D & meanDistPhiOld){
213 
216  unsigned int nPdfBins = exp2(OMTFConfiguration::instance()->nPdfAddrBits);
217 
218  GoldenPattern::vector3D pdfAllRef = aGP->getPdf();
219 
220  int indexShift = 0;
221  for(unsigned int iLayer=0;iLayer<OMTFConfiguration::instance()->nLayers;++iLayer){
222  for(unsigned int iRefLayer=0;iRefLayer<OMTFConfiguration::instance()->nRefLayers;++iRefLayer){
223  indexShift = meanDistPhiOld[iLayer][iRefLayer] - meanDistPhiNew[iLayer][iRefLayer];
224  for(unsigned int iPdfBin=0;iPdfBin<nPdfBins;++iPdfBin) pdfAllRef[iLayer][iRefLayer][iPdfBin] = 0;
225  for(unsigned int iPdfBin=0;iPdfBin<nPdfBins;++iPdfBin){
226  if((int)(iPdfBin)+indexShift>=0 && iPdfBin+indexShift<nPdfBins)
227  pdfAllRef[iLayer][iRefLayer][iPdfBin+indexShift] = aGP->pdfValue(iLayer, iRefLayer, iPdfBin);
228  }
229  }
230  }
231  aGP->setPdf(pdfAllRef);
232 }
235 const std::map<Key,GoldenPattern*> & OMTFProcessor::getPatterns() const{ return theGPs; }
238 const std::vector<OMTFProcessor::resultsMap> & OMTFProcessor::processInput(unsigned int iProcessor,
239  const OMTFinput & aInput){
240 
241  for(auto & itRegion: myResults) for(auto & itKey: itRegion) itKey.second.clear();
242 
245  std::bitset<128> refHitsBits = aInput.getRefHits(iProcessor);
246  if(refHitsBits.none()) return myResults;
247 
248  for(unsigned int iLayer=0;iLayer<OMTFConfiguration::instance()->nLayers;++iLayer){
249  const OMTFinput::vector1D & layerHits = aInput.getLayerData(iLayer);
250  if(!layerHits.size()) continue;
253  unsigned int nTestedRefHits = OMTFConfiguration::instance()->nTestRefHits;
254  for(unsigned int iRefHit=0;iRefHit<OMTFConfiguration::instance()->nRefHits;++iRefHit){
255  if(!refHitsBits[iRefHit]) continue;
256  if(nTestedRefHits--==0) break;
257  const RefHitDef & aRefHitDef = OMTFConfiguration::instance()->refHitsDefs[iProcessor][iRefHit];
258 
259  int phiRef = aInput.getLayerData(OMTFConfiguration::instance()->refToLogicNumber[aRefHitDef.iRefLayer])[aRefHitDef.iInput];
260  int etaRef = aInput.getLayerData(OMTFConfiguration::instance()->refToLogicNumber[aRefHitDef.iRefLayer],true)[aRefHitDef.iInput];
261  unsigned int iRegion = aRefHitDef.iRegion;
262 
263  if(OMTFConfiguration::instance()->bendingLayers.count(iLayer)) phiRef = 0;
264  const OMTFinput::vector1D restrictedLayerHits = restrictInput(iProcessor, iRegion, iLayer,layerHits);
265  for(auto itGP: theGPs){
266  GoldenPattern::layerResult aLayerResult = itGP.second->process1Layer1RefLayer(aRefHitDef.iRefLayer,iLayer,
267  phiRef,
268  restrictedLayerHits);
269 
270  // if(itGP.second->pdfValue(1,0,0))
271  // std::cout << itGP.second->pdfValue(1,0,0) << std::endl;
272 
273  int phiRefSt2 = itGP.second->propagateRefPhi(phiRef, etaRef, aRefHitDef.iRefLayer);
274  myResults[OMTFConfiguration::instance()->nTestRefHits-nTestedRefHits-1][itGP.second->key()].setRefPhiRHits(aRefHitDef.iRefLayer, phiRef);
275  myResults[OMTFConfiguration::instance()->nTestRefHits-nTestedRefHits-1][itGP.second->key()].addResult(aRefHitDef.iRefLayer,iLayer,
276  aLayerResult.first,
277  phiRefSt2,etaRef);
278  }
279  }
280  }
283  for(auto & itRefHit: myResults) for(auto & itKey: itRefHit) itKey.second.finalise();
284 
285  std::ostringstream myStr;
286  myStr<<"iProcessor: "<<iProcessor<<std::endl;
287  myStr<<"Input: ------------"<<std::endl;
288  myStr<<aInput<<std::endl;
289  edm::LogInfo("OMTF processor")<<myStr.str();
290 
291  return myResults;
292 }
296  unsigned int iRegion,
297  unsigned int iLayer,
298  const OMTFinput::vector1D & layerHits){
299 
300  OMTFinput::vector1D myHits = layerHits;
301 
302  unsigned int iStart = OMTFConfiguration::instance()->connections[iProcessor][iRegion][iLayer].first;
303  unsigned int iEnd = iStart + OMTFConfiguration::instance()->connections[iProcessor][iRegion][iLayer].second -1;
304 
305  for(unsigned int iInput=0;iInput<14;++iInput){
306  if(iInput<iStart || iInput>iEnd) myHits[iInput] = OMTFConfiguration::instance()->nPhiBins;
307  }
308 
309  return myHits;
310 }
313 void OMTFProcessor::fillCounts(unsigned int iProcessor,
314  const OMTFinput & aInput,
315  const SimTrack* aSimMuon){
316 
317  int theCharge = abs(aSimMuon->type()) == 13 ? -1 : 1;
318  unsigned int iPt = RPCConst::iptFromPt(aSimMuon->momentum().pt());
321  iPt+=1;
322  if(iPt>31) iPt=200*2+1;
323  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
325 
327  std::bitset<128> refHitsBits = aInput.getRefHits(iProcessor);
328  if(refHitsBits.none()) return;
329 
330  std::ostringstream myStr;
331  myStr<<"iProcessor: "<<iProcessor<<std::endl;
332  myStr<<"Input: ------------"<<std::endl;
333  myStr<<aInput<<std::endl;
334  edm::LogInfo("OMTF processor")<<myStr.str();
335 
336  for(unsigned int iLayer=0;iLayer<OMTFConfiguration::instance()->nLayers;++iLayer){
337  const OMTFinput::vector1D & layerHits = aInput.getLayerData(iLayer);
338  if(!layerHits.size()) continue;
341  for(unsigned int iRefHit=0;iRefHit<OMTFConfiguration::instance()->nRefHits;++iRefHit){
342  if(!refHitsBits[iRefHit]) continue;
343  const RefHitDef & aRefHitDef = OMTFConfiguration::instance()->refHitsDefs[iProcessor][iRefHit];
344  int phiRef = aInput.getLayerData(OMTFConfiguration::instance()->refToLogicNumber[aRefHitDef.iRefLayer])[aRefHitDef.iInput];
345  unsigned int iRegion = aRefHitDef.iRegion;
346  if(OMTFConfiguration::instance()->bendingLayers.count(iLayer)) phiRef = 0;
347  const OMTFinput::vector1D restrictedLayerHits = restrictInput(iProcessor, iRegion, iLayer,layerHits);
348  for(auto itGP: theGPs){
349  if(itGP.first.theCharge!=theCharge) continue;
350  if(itGP.first.thePtCode!=iPt) continue;
351  itGP.second->addCount(aRefHitDef.iRefLayer,iLayer,phiRef,restrictedLayerHits);
352  }
353  }
354  }
355 }
Key key() const
Definition: GoldenPattern.h:59
T getParameter(std::string const &) const
unsigned int nLayers
void fillCounts(unsigned int iProcessor, const OMTFinput &aInput, const SimTrack *aSimMuon)
void averagePatterns(int charge)
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
unsigned int iInput
Hit input number within a cone.
std::map< Key, GoldenPattern * > theGPs
Map holding Golden Patterns.
Definition: OMTFProcessor.h:93
std::map< Key, OMTFResult > resultsMap
Definition: OMTFProcessor.h:25
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
OMTFConfiguration * m_omtf_config
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:18
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
unsigned int nTestRefHits
tuple omtfParams
OMTF ESProducer.
std::vector< std::vector< RefHitDef > > refHitsDefs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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 double ptFromIpt(const int ipt)
Definition: RPCConst.cc:28
void setPatternsFile(const std::string &fName)
void resetConfiguration()
Reset all configuration parameters.
const l1t::LUT * etaLUT() const
const l1t::LUT * pdfLUT() const
OMTFProcessor(const edm::ParameterSet &cfg, OMTFConfiguration *omtf_config)
Definition: LUT.h:29
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)
unsigned int nRefHits
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:61
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.
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.
const l1t::LUT * meanDistPhiLUT() const
std::vector< OMTFProcessor::resultsMap > myResults
Definition: OMTFProcessor.h:98
static const OMTFConfiguration * instance()
const vector3D & getPdf() const
Definition: GoldenPattern.h:65