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 MuonStubPtr refStub) {
49  //if (this->getDistPhiBitShift(iLayer, iRefLayer) != 0) LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<key()<<this->getDistPhiBitShift(iLayer, iRefLayer)<<std::endl;
50 
51  int phiMean = this->meanDistPhiValue(iLayer, iRefLayer, refStub->phiBHw);
52  int phiDistMin = myOmtfConfig->nPhiBins(); //1<<(myOmtfConfig->nPdfAddrBits()); //"infinite" value for the beginning
53 
56  MuonStubPtr selectedStub;
57 
58  int phiRefHit = 0;
59  if (refStub)
60  phiRefHit = refStub->phiHw;
61 
62  if (this->myOmtfConfig->isBendingLayer(iLayer)) {
63  phiRefHit = 0; //phi ref hit for the bending layer set to 0, since it should not be included in the phiDist
64  }
65 
66  for (auto& stub : layerStubs) {
67  if (!stub) //empty pointer
68  continue;
69 
70  int hitPhi = stub->phiHw;
71  if (this->myOmtfConfig->isBendingLayer(iLayer)) {
72  //rejecting phiB of the low quality DT stubs is done in the OMTFInputMaker
73  hitPhi = stub->phiBHw;
74  }
75 
76  if (hitPhi >= (int)myOmtfConfig->nPhiBins()) //TODO is this needed now? the empty hit will be empty stub
77  continue; //empty itHits are marked with nPhiBins() in OMTFProcessor::restrictInput
78 
79  int phiDist = this->myOmtfConfig->foldPhi(hitPhi - phiMean - phiRefHit);
80  //for standard omtf foldPhi is not needed, but if one processor works for full phi then it is
81  //if (this->getDistPhiBitShift(iLayer, iRefLayer) != 0)
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 abs(phiDist)
88  int sign = phiDist < 0 ? -1 : 1;
89  phiDist = 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 (abs(phiDist) < abs(phiDistMin)) {
94  phiDistMin = phiDist;
95  selectedStub = stub;
96  }
97  }
98 
99  if (!selectedStub) {
100  if (this->myOmtfConfig->isNoHitValueInPdf()) {
101  PdfValueType pdfVal = this->pdfValue(iLayer, iRefLayer, 0);
102  return StubResult(pdfVal, false, myOmtfConfig->nPhiBins(), iLayer, selectedStub);
103  } else {
104  return StubResult(0, false, myOmtfConfig->nPhiBins(), iLayer, selectedStub); //2018 version
105  }
106  }
107 
108  int pdfMiddle = 1 << (myOmtfConfig->nPdfAddrBits() - 1);
109 
110  /* debug
111  if(phiDistMin != 128 && iRefLayer == 0 && iLayer == 1)*/
112  /*LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" iRefLayer "<<iRefLayer<<" iLayer "<<iLayer<<" selectedStub "<<*selectedStub
113  <<" phiDistMin "<<phiDistMin<<" phiMean "<<phiMean<<" shift "<<this->getDistPhiBitShift(iLayer, iRefLayer)<<std::endl;*/
114 
117  if (abs(phiDistMin) > ((1 << (myOmtfConfig->nPdfAddrBits() - 1)) - 1)) {
118  return StubResult(0, false, phiDistMin + pdfMiddle, iLayer, selectedStub);
119 
120  //return GoldenPatternResult::LayerResult(this->pdfValue(iLayer, iRefLayer, 0), false, phiDistMin + pdfMiddle, selHit);
121  //in some algorithms versions with thresholds we use the bin 0 to store the pdf value returned when there was no hit.
122  //in the version without thresholds, the value in the bin 0 should be 0
123  }
124 
126  phiDistMin += pdfMiddle;
127  //if (this->getDistPhiBitShift(iLayer, iRefLayer) != 0) LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" phiDistMin "<<phiDistMin<<std::endl;
128  PdfValueType pdfVal = this->pdfValue(iLayer, iRefLayer, phiDistMin);
129  if (pdfVal <= 0) {
130  return StubResult(0, false, phiDistMin, iLayer, selectedStub);
131  }
132  return StubResult(pdfVal, true, phiDistMin, iLayer, selectedStub);
133 }
134 
137 void GoldenPatternBase::finalise(unsigned int procIndx) {
138  for (auto& result : getResults()[procIndx]) {
139  result.finalise();
140  }
141 }
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:66
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:65
GoldenPatternBase(const Key &aKey)
unsigned int processorCnt() const
virtual int getDistPhiBitShift(unsigned int iLayer, unsigned int iRefLayer) const =0
unsigned int nTestRefHits() const
float PdfValueType
std::ostream & operator<<(std::ostream &out, const Key &o)
virtual int foldPhi(int phi) const
virtual StubResult process1Layer1RefLayer(unsigned int iRefLayer, unsigned int iLayer, MuonStubPtrs1D layerStubs, const MuonStubPtr refStub)
const OMTFConfiguration * myOmtfConfig
bool isBendingLayer(unsigned int iLayer) const override