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  layerStubs.push_back(input.getMuonStub(iLayer - 1, iInput));
158  } else
159  layerStubs.push_back(input.getMuonStub(iLayer, iInput)); //input.getHitPhi(iLayer, iInput)
160  }
161  }
162  //LogTrace("OMTFReconstruction") <<__FUNCTION__<<":"<<__LINE__<<" layerHits.size() "<<layerHits.size()<<std::endl;
163  return layerStubs;
164 }
165 
168 template <class GoldenPatternType>
170  patternPts.clear();
171 
172  bool firstPos = firstPatFrom0;
173  bool firstNeg = firstPatFrom0;
174  for (unsigned int iPat = 0; iPat < theGPs.size(); iPat++) {
176  int charge = theGPs[iPat]->key().theCharge;
177  if (theGPs[iPat] == nullptr || theGPs[iPat]->key().thePt == 0) {
178  patternPts.push_back(patternPt);
179  continue;
180  }
181 
182  patternPt.ptFrom = myOmtfConfig->hwPtToGev(theGPs[iPat]->key().thePt);
183  if (firstPos && theGPs[iPat]->key().theCharge == 1) {
184  patternPt.ptFrom = 0;
185  firstPos = false;
186  }
187  if (firstNeg && theGPs[iPat]->key().theCharge == -1) {
188  patternPt.ptFrom = 0;
189  firstNeg = false;
190  }
191 
192  unsigned int iPat1 = iPat;
193  while (true) { //to skip the empty patterns with pt=0 and patterns with opposite charge
194  iPat1++;
195  if (iPat1 == theGPs.size())
196  break;
197  if (theGPs[iPat1]->key().thePt != 0 && theGPs[iPat1]->key().theCharge == charge)
198  break;
199  }
200 
201  if (iPat1 == theGPs.size())
202  patternPt.ptTo = 10000; //inf
203  else
204  patternPt.ptTo = myOmtfConfig->hwPtToGev(theGPs[iPat1]->key().thePt);
205 
206  patternPt.charge = charge;
207  patternPts.push_back(patternPt);
208  }
209 
210  //debug
211  /* for(unsigned int iPat = 0; iPat < theGPs.size(); iPat++) {
212  LogTrace("OMTFReconstruction") <<theGPs[iPat]->key()<<" ptFrom "<<patternPts[iPat].ptFrom<<" ptFrom "<<patternPts[iPat].ptTo<<std::endl;
213  }*/
214 
215  edm::LogTrace_("OMTFReconstruction") << __FUNCTION__ << ":" << __LINE__ << " patternPts.size() " << patternPts.size()
216  << endl;
217 }
218 
219 template <class GoldenPatternType>
221  myOmtfConfig->printConfig();
222 
223  edm::LogVerbatim("OMTFReconstruction") << "\npatterns:" << std::endl;
224  unsigned int patNum = 0;
225  for (auto& gp : theGPs) {
226  edm::LogVerbatim("OMTFReconstruction")
227  << std::setw(2) << patNum << " " << gp->key() << " " << myOmtfConfig->getPatternPtRange(patNum).ptFrom << " - "
228  << myOmtfConfig->getPatternPtRange(patNum).ptTo << " GeV" << std::endl;
229  patNum++;
230  }
231 
232  /* //can be useful for debug, uncomment if needed
233  XMLConfigWriter xmlWriter(this->myOmtfConfig, false, false);
234  xmlWriter.writeGPs(this->theGPs, "patternsAsInTheProcessor.xml");*/
235 }
236 
237 //to force compiler to compile the above methods with needed GoldenPatterns types
238 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:66
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