CMS 3D CMS Logo

GoldenPatternBase.cc
Go to the documentation of this file.
1 /*
2  * GoldenPatternBase.cpp
3  *
4  * Created on: Oct 3, 2017
5  * Author: kbunkow
6  */
7 
10 
11 #include <iomanip>
12 
13 std::ostream& operator<<(std::ostream& out, const Key& o) {
14  out << "Key_" << std::setw(2) << o.theNumber << " hwNum " << std::setw(2) << o.getHwPatternNumber() << " group "
15  << std::setw(2) << o.theGroup << ":" << o.theIndexInGroup << " : (eta=" << o.theEtaCode << ", pt=" << std::setw(3)
16  << o.thePt << ", charge=" << setw(2) << o.theCharge << ")";
17  return out;
18 }
19 
20 GoldenPatternBase::GoldenPatternBase(const Key& aKey) : theKey(aKey), myOmtfConfig(nullptr) {}
21 
23  : theKey(aKey),
24  myOmtfConfig(omtfConfig),
25  results(boost::extents[myOmtfConfig->processorCnt()][myOmtfConfig->nTestRefHits()]) {
26  for (unsigned int iProc = 0; iProc < results.size(); iProc++) {
27  for (unsigned int iTestRefHit = 0; iTestRefHit < results[iProc].size(); iTestRefHit++) {
28  results[iProc][iTestRefHit].init(omtfConfig);
29  }
30  }
31 }
32 
34  myOmtfConfig = omtfConfig;
35  results.resize(boost::extents[myOmtfConfig->processorCnt()][myOmtfConfig->nTestRefHits()]);
36  for (unsigned int iProc = 0; iProc < results.size(); iProc++) {
37  for (unsigned int iTestRefHit = 0; iTestRefHit < results[iProc].size(); iTestRefHit++) {
38  results[iProc][iTestRefHit].init(omtfConfig);
39  }
40  }
41 }
42 
46  unsigned int iLayer,
47  MuonStubPtrs1D layerStubs,
48  const std::vector<int>& extrapolatedPhi,
49  const MuonStubPtr& refStub) {
50  //if (this->getDistPhiBitShift(iLayer, iRefLayer) != 0) LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<key()<<this->getDistPhiBitShift(iLayer, iRefLayer)<<std::endl;
51 
52  int phiMean = this->meanDistPhiValue(iLayer, iRefLayer, refStub->phiBHw);
53  int phiDistMin = myOmtfConfig->nPhiBins();
54 
57  MuonStubPtr selectedStub;
58 
59  int phiRefHit = 0;
60  if (refStub)
61  phiRefHit = refStub->phiHw;
62 
63  if (this->myOmtfConfig->isBendingLayer(iLayer)) {
64  phiRefHit = 0; //phi ref hit for the bending layer set to 0, since it should not be included in the phiDist
65  }
66 
67  for (size_t iStub = 0; iStub < layerStubs.size(); iStub++) {
68  const auto& stub = layerStubs[iStub];
69  if (!stub) //empty pointer
70  continue;
71 
72  int hitPhi = stub->phiHw;
73  if (this->myOmtfConfig->isBendingLayer(iLayer)) {
74  //rejecting phiB of the low quality DT stubs is done in the OMTFInputMaker
75  hitPhi = stub->phiBHw;
76  }
77 
78  if (hitPhi >= (int)myOmtfConfig->nPhiBins()) //TODO is this needed now? the empty hit will be empty stub
79  continue; //empty itHits are marked with nPhiBins() in OMTFProcessor::restrictInput
80 
81  int phiDist = this->myOmtfConfig->foldPhi(hitPhi - extrapolatedPhi[iStub] - phiMean - phiRefHit);
82  /*LogTrace("l1tOmtfEventPrint") <<"\n"<<__FUNCTION__<<":"<<__LINE__<<" "<<theKey<<std::endl;
83  LogTrace("l1tOmtfEventPrint") <<__FUNCTION__<<":"<<__LINE__
84  <<" iRefLayer "<<iRefLayer<<" iLayer "<<iLayer
85  <<" hitPhi "<<hitPhi<<" phiMean "<<phiMean<<" phiRefHit "<<phiRefHit<<" phiDist "<<phiDist<<std::endl;*/
86 
87  //firmware works on the sign-value, shift must be done on std::abs(phiDist)
88  int sign = phiDist < 0 ? -1 : 1;
89  phiDist = std::abs(phiDist) >> this->getDistPhiBitShift(iLayer, iRefLayer);
90  phiDist *= sign;
91  //if the shift is done here, it means that the phiMean in the xml should be the same as without shift
92  //if (this->getDistPhiBitShift(iLayer, iRefLayer) != 0) std::cout<<__FUNCTION__<<":"<<__LINE__<<" phiDist "<<phiDist<<std::endl;
93  if (std::abs(phiDist) < std::abs(phiDistMin)) {
94  phiDistMin = phiDist;
95  selectedStub = stub;
96  }
97  }
98 
99  if (!selectedStub) {
100  PdfValueType pdfVal = 0;
101  if (this->myOmtfConfig->isNoHitValueInPdf())
102  pdfVal = this->pdfValue(iLayer, iRefLayer, 0);
103  return StubResult(pdfVal, false, myOmtfConfig->nPhiBins(), iLayer, selectedStub);
104  }
105 
106  int pdfMiddle = 1 << (myOmtfConfig->nPdfAddrBits() - 1);
107 
108  /* debug
109  if(phiDistMin != 128 && iRefLayer == 0 && iLayer == 1)*/
110  /*LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" iRefLayer "<<iRefLayer<<" iLayer "<<iLayer<<" selectedStub "<<*selectedStub
111  <<" phiDistMin "<<phiDistMin<<" phiMean "<<phiMean<<" shift "<<this->getDistPhiBitShift(iLayer, iRefLayer)<<std::endl;*/
112 
115  if (std::abs(phiDistMin) > ((1 << (myOmtfConfig->nPdfAddrBits() - 1)) - 1)) {
116  return StubResult(0, false, phiDistMin + pdfMiddle, iLayer, selectedStub);
117 
118  //in some algorithms versions with thresholds we use the bin 0 to store the pdf value returned when there was no hit.
119  //in the version without thresholds, the value in the bin 0 should be 0
120  }
121 
123  phiDistMin += pdfMiddle;
124  //if (this->getDistPhiBitShift(iLayer, iRefLayer) != 0) LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" phiDistMin "<<phiDistMin<<std::endl;
125  PdfValueType pdfVal = this->pdfValue(iLayer, iRefLayer, phiDistMin);
126  if (pdfVal <= 0) {
127  return StubResult(0, false, phiDistMin, iLayer, selectedStub);
128  }
129  return StubResult(pdfVal, true, phiDistMin, iLayer, selectedStub);
130 }
131 
134 void GoldenPatternBase::finalise(unsigned int procIndx) {
135  for (auto& result : getResults()[procIndx]) {
136  result.finalise();
137  }
138 }
virtual PdfValueType pdfValue(unsigned int iLayer, unsigned int iRefLayer, unsigned int iBin, int refLayerPhiB=0) const =0
Definition: CLHEP.h:16
bool isNoHitValueInPdf() const
virtual int meanDistPhiValue(unsigned int iLayer, unsigned int iRefLayer, int refLayerPhiB=0) const =0
unsigned int nPhiBins() const
resultsArrayType results
unsigned int nPdfAddrBits() const
resultsArrayType & getResults()
virtual void setConfig(const OMTFConfiguration *omtfConfig)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< MuonStubPtr > MuonStubPtrs1D
Definition: MuonStub.h:68
virtual void finalise(unsigned int procIndx)
last step of the event processing, before sorting and ghost busting
std::shared_ptr< MuonStub > MuonStubPtr
Definition: MuonStub.h:67
GoldenPatternBase(const Key &aKey)
unsigned int processorCnt() const
virtual int getDistPhiBitShift(unsigned int iLayer, unsigned int iRefLayer) const =0
unsigned int nTestRefHits() const
virtual StubResult process1Layer1RefLayer(unsigned int iRefLayer, unsigned int iLayer, MuonStubPtrs1D layerStubs, const std::vector< int > &extrapolatedPhi, const MuonStubPtr &refStub)
float PdfValueType
std::ostream & operator<<(std::ostream &out, const Key &o)
virtual int foldPhi(int phi) const
results
Definition: mysort.py:8
const OMTFConfiguration * myOmtfConfig
bool isBendingLayer(unsigned int iLayer) const override