CMS 3D CMS Logo

ProcessorBase.cc
Go to the documentation of this file.
1 /*
2  * ProcessorBase.cpp
3  *
4  * Created on: Jul 28, 2017
5  * Author: kbunkow
6  */
7 
12 
15 
19 
20 template <class GoldenPatternType>
23  : myOmtfConfig(omtfConfig), theGPs(std::move(gps)) {
24  for (auto& gp : theGPs) {
25  gp->setConfig(myOmtfConfig);
26  }
27 
28  initPatternPtRange(true);
29 
30  omtfConfig->setPatternPtRange(getPatternPtRange());
31 };
32 
33 template <class GoldenPatternType>
35  theGPs.clear();
36 }
37 
40 template <class GoldenPatternType>
42  const L1TMuonOverlapParams* omtfPatterns) {
43  resetConfiguration();
44 
45  myOmtfConfig = omtfConfig;
46 
47  const l1t::LUT* chargeLUT = omtfPatterns->chargeLUT();
48  const l1t::LUT* etaLUT = omtfPatterns->etaLUT();
49  const l1t::LUT* ptLUT = omtfPatterns->ptLUT();
50  const l1t::LUT* pdfLUT = omtfPatterns->pdfLUT();
51  const l1t::LUT* meanDistPhiLUT = omtfPatterns->meanDistPhiLUT();
52  const l1t::LUT* distPhiShiftLUT = omtfPatterns->distPhiShiftLUT();
53 
54  unsigned int nGPs = myOmtfConfig->nGoldenPatterns();
55  edm::LogVerbatim("OMTFReconstruction")
56  << "ProcessorBase<>::configure. Building patterns from L1TMuonOverlapParams (LUTs). nGoldenPatterns() " << nGPs
57  << std::endl;
58 
59  unsigned int address = 0;
60  unsigned int iEta, iPt;
61  int iCharge;
62  //int meanDistPhiSize = myOmtfConfig->nLayers() * myOmtfConfig->nRefLayers() * myOmtfConfig->nGoldenPatterns();
63 
64  unsigned int group = 0;
65  unsigned int indexInGroup = 0;
66  for (unsigned int iGP = 0; iGP < nGPs; ++iGP) {
67  address = iGP;
68  iEta = etaLUT->data(address);
69  iCharge = chargeLUT->data(address) == 0 ? -1 : 1;
70  iPt = ptLUT->data(address);
71 
72  //the patterns in the LUTs should contain the empty patterns, only then the group and indexInGroup calculation works
73  group = iGP / myOmtfConfig->patternsInGroup;
74  indexInGroup = iGP % myOmtfConfig->patternsInGroup + 1;
75  Key aKey(iEta, iPt, iCharge, theGPs.size(), group, indexInGroup);
76  if (iPt == 0) {
77  LogTrace("OMTFReconstruction") << "skipping empty pattern " << aKey << " " << std::endl;
78  //<<myOmtfConfig->getPatternPtRange(iGP).ptFrom<<" - "<<myOmtfConfig->getPatternPtRange(iGP).ptTo<<" GeV"<<std::endl; PatternPtRange is not initialized here yet, so do not use it!!!!
79  continue;
80  }
81 
82  LogTrace("OMTFReconstruction") << "adding pattern " << aKey << " " << std::endl;
83  //<<myOmtfConfig->getPatternPtRange(iGP).ptFrom<<" - "<<myOmtfConfig->getPatternPtRange(iGP).ptTo<<" GeV"<<std::endl; PatternPtRange is not initialized here yet, so do not use it!!!!
84 
85  GoldenPatternType* aGP = new GoldenPatternType(aKey, myOmtfConfig);
86 
87  for (unsigned int iLayer = 0; iLayer < myOmtfConfig->nLayers(); ++iLayer) {
88  for (unsigned int iRefLayer = 0; iRefLayer < myOmtfConfig->nRefLayers(); ++iRefLayer) {
89  address = iRefLayer + iLayer * myOmtfConfig->nRefLayers() +
90  iGP * (myOmtfConfig->nRefLayers() * myOmtfConfig->nLayers());
91 
93  //LUT values are only positive, therefore to have negative meanDistPh half of the max LUT value is subtracted
94  int value = meanDistPhiLUT->data(address) - (1 << (meanDistPhiLUT->nrBitsData() - 1));
95  aGP->setMeanDistPhiValue(value, iLayer, iRefLayer, 0);
96 
97  /* uncomment this if you need meanDistPhi1 in the LUTs (and set useMeanDistPhi1 in XMLConfigReader::readLUTs)
98  if ( (1 << meanDistPhiLUT->nrBitsAddress()) > 2 * meanDistPhiSize ) {
99  //for the version of the meanDistPhi which have two values for each gp,iLayer,iRefLayer, FIXME: do it a better way
100  value = meanDistPhiLUT->data(address + meanDistPhiSize) - (1 << (meanDistPhiLUT->nrBitsData() - 1));
101  //the second meanDistPhi is in the LUT at the position (address+meanDistPhiSize)
102  aGP->setMeanDistPhiValue(value, iLayer, iRefLayer, 1);
103  }*/
104 
105  //selDistPhiShift, if the distPhiShiftLUT is nullptr, it means it was not present in the L1TMuonOverlapParamsRcd
106  if (distPhiShiftLUT) {
107  value = distPhiShiftLUT->data(address); //distPhiShiftLUT values are only positive
108  aGP->setDistPhiBitShift(value, iLayer, iRefLayer);
109  }
110  }
112  for (unsigned int iRefLayer = 0; iRefLayer < myOmtfConfig->nRefLayers(); ++iRefLayer) {
113  for (unsigned int iPdf = 0; iPdf < (unsigned int)(1 << myOmtfConfig->nPdfAddrBits()); ++iPdf) {
114  address = iPdf + iRefLayer * (1 << myOmtfConfig->nPdfAddrBits()) +
115  iLayer * myOmtfConfig->nRefLayers() * (1 << myOmtfConfig->nPdfAddrBits()) +
116  iGP * myOmtfConfig->nLayers() * myOmtfConfig->nRefLayers() * (1 << myOmtfConfig->nPdfAddrBits());
117  int value = pdfLUT->data(address); //here only int is possible
118  aGP->setPdfValue(value, iLayer, iRefLayer, iPdf);
119 
120  //LogTrace("OMTFReconstruction") <<" iLayer "<<iLayer<<" iRefLayer "<<iRefLayer<<" iPdf "<<iPdf << " address "<<address<<" value "<<value<<std::endl;
121  }
122  }
123  }
124 
125  addGP(aGP);
126  }
127 
128  initPatternPtRange(true);
129 
130  omtfConfig->setPatternPtRange(getPatternPtRange());
131 
132  return true;
133 }
134 
137 template <class GoldenPatternType>
138 void ProcessorBase<GoldenPatternType>::addGP(GoldenPatternType* aGP) {
139  theGPs.emplace_back(std::unique_ptr<GoldenPatternType>(aGP));
140 }
141 
144 template <class GoldenPatternType>
146  unsigned int iRegion,
147  unsigned int iLayer,
148  const OMTFinput& input) {
149  MuonStubPtrs1D layerStubs;
150 
151  unsigned int iStart = myOmtfConfig->getConnections()[iProcessor][iRegion][iLayer].first;
152  unsigned int iEnd = iStart + myOmtfConfig->getConnections()[iProcessor][iRegion][iLayer].second - 1;
153 
154  for (unsigned int iInput = 0; iInput < input.getMuonStubs()[iLayer].size(); ++iInput) {
155  if (iInput >= iStart && iInput <= iEnd) {
156  if (this->myOmtfConfig->isBendingLayer(iLayer)) {
157  if (input.getMuonStub(iLayer - 1, iInput) &&
158  input.getMuonStub(iLayer - 1, iInput)->qualityHw >= myOmtfConfig->getMinDtPhiBQuality())
159  layerStubs.push_back(input.getMuonStub(iLayer - 1, iInput));
160  } else
161  layerStubs.push_back(input.getMuonStub(iLayer, iInput));
162  }
163  }
164  //LogTrace("OMTFReconstruction") <<__FUNCTION__<<":"<<__LINE__<<" layerHits.size() "<<layerHits.size()<<std::endl;
165  return layerStubs;
166 }
167 
170 template <class GoldenPatternType>
172  patternPts.clear();
173 
174  bool firstPos = firstPatFrom0;
175  bool firstNeg = firstPatFrom0;
176  for (unsigned int iPat = 0; iPat < theGPs.size(); iPat++) {
178  int charge = theGPs[iPat]->key().theCharge;
179  if (theGPs[iPat] == nullptr || theGPs[iPat]->key().thePt == 0) {
180  patternPts.push_back(patternPt);
181  continue;
182  }
183 
184  patternPt.ptFrom = myOmtfConfig->hwPtToGev(theGPs[iPat]->key().thePt);
185  if (firstPos && theGPs[iPat]->key().theCharge == 1) {
186  patternPt.ptFrom = 0;
187  firstPos = false;
188  }
189  if (firstNeg && theGPs[iPat]->key().theCharge == -1) {
190  patternPt.ptFrom = 0;
191  firstNeg = false;
192  }
193 
194  unsigned int iPat1 = iPat;
195  while (true) { //to skip the empty patterns with pt=0 and patterns with opposite charge
196  iPat1++;
197  if (iPat1 == theGPs.size())
198  break;
199  if (theGPs[iPat1]->key().thePt != 0 && theGPs[iPat1]->key().theCharge == charge)
200  break;
201  }
202 
203  if (iPat1 == theGPs.size())
204  patternPt.ptTo = 10000; //inf
205  else
206  patternPt.ptTo = myOmtfConfig->hwPtToGev(theGPs[iPat1]->key().thePt);
207 
208  patternPt.charge = charge;
209  patternPts.push_back(patternPt);
210  }
211 
212  //debug
213  /* for(unsigned int iPat = 0; iPat < theGPs.size(); iPat++) {
214  LogTrace("OMTFReconstruction") <<theGPs[iPat]->key()<<" ptFrom "<<patternPts[iPat].ptFrom<<" ptFrom "<<patternPts[iPat].ptTo<<std::endl;
215  }*/
216 
217  edm::LogTrace_("OMTFReconstruction") << __FUNCTION__ << ":" << __LINE__ << " patternPts.size() " << patternPts.size()
218  << endl;
219 }
220 
221 template <class GoldenPatternType>
223  myOmtfConfig->printConfig();
224 
225  edm::LogVerbatim("OMTFReconstruction") << "\npatterns:" << std::endl;
226  unsigned int patNum = 0;
227  for (auto& gp : theGPs) {
228  edm::LogVerbatim("OMTFReconstruction")
229  << std::setw(2) << patNum << " " << gp->key() << " " << myOmtfConfig->getPatternPtRange(patNum).ptFrom << " - "
230  << myOmtfConfig->getPatternPtRange(patNum).ptTo << " GeV" << std::endl;
231  patNum++;
232  }
233 
234  /* //can be useful for debug, uncomment if needed
235  XMLConfigWriter xmlWriter(this->myOmtfConfig, false, false);
236  xmlWriter.writeGPs(this->theGPs, "patternsAsInTheProcessor.xml");*/
237 }
238 
239 //to force compiler to compile the above methods with needed GoldenPatterns types
240 template class ProcessorBase<GoldenPattern>;
GoldenPatternVec< GoldenPatternType > theGPs
vector holding Golden Patterns
Definition: ProcessorBase.h:57
virtual bool configure(OMTFConfiguration *omtfParams, const L1TMuonOverlapParams *omtfPatterns)
Fill GP vec with patterns from CondFormats object.
Log< level::Info, true > LogVerbatim
virtual void printInfo() const
const l1t::LUT * chargeLUT() const
Golden Patterns definitions.
unsigned int nrBitsData() const
Definition: LUT.h:53
virtual void addGP(GoldenPatternType *aGP)
Add GoldenPattern to pattern vec.
const std::vector< OMTFConfiguration::PatternPt > & getPatternPtRange() const
Definition: ProcessorBase.h:47
const l1t::LUT * distPhiShiftLUT() const
#define LogTrace(id)
static std::string const input
Definition: EdmProvDump.cc:50
ProcessorBase(OMTFConfiguration *omtfConfig, const L1TMuonOverlapParams *omtfPatterns)
Definition: ProcessorBase.h:23
const OMTFConfiguration * myOmtfConfig
Definition: ProcessorBase.h:54
void setPatternPtRange(const std::vector< PatternPt > &patternPts)
virtual MuonStubPtrs1D restrictInput(unsigned int iProcessor, unsigned int iCone, unsigned int iLayer, const OMTFinput &input)
int data(unsigned int address) const
Definition: LUT.h:46
pattern pt range in Gev
const l1t::LUT * pdfLUT() const
std::vector< MuonStubPtr > MuonStubPtrs1D
Definition: MuonStub.h:68
key
prepare the HTCondor submission files and eventually submit them
Definition: value.py:1
Definition: LUT.h:29
virtual void initPatternPtRange(bool firstPatFrom0)
const ap_uint< BITSPT > ptLUT[1858]
Definition: Constants.h:18
std::vector< std::unique_ptr< GoldenPatternType > > GoldenPatternVec
const l1t::LUT * meanDistPhiLUT() const
const l1t::LUT * ptLUT() const
const l1t::LUT * etaLUT() const
virtual void resetConfiguration()
Reset all configuration parameters.
const uint etaLUT[4082]
Definition: Constants.h:121
def move(src, dest)
Definition: eostools.py:511