Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:12:52

0001 /*
0002  * GoldenPatternBase.cpp
0003  *
0004  *  Created on: Oct 3, 2017
0005  *      Author: kbunkow
0006  */
0007 
0008 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/GoldenPatternBase.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 #include <iomanip>
0012 
0013 std::ostream& operator<<(std::ostream& out, const Key& o) {
0014   out << "Key_" << std::setw(2) << o.theNumber << " hwNum " << std::setw(2) << o.getHwPatternNumber() << " group "
0015       << std::setw(2) << o.theGroup << ":" << o.theIndexInGroup << " : (eta=" << o.theEtaCode << ", pt=" << std::setw(3)
0016       << o.thePt << ", charge=" << setw(2) << o.theCharge << ")";
0017   return out;
0018 }
0019 
0020 GoldenPatternBase::GoldenPatternBase(const Key& aKey) : theKey(aKey), myOmtfConfig(nullptr) {}
0021 
0022 GoldenPatternBase::GoldenPatternBase(const Key& aKey, const OMTFConfiguration* omtfConfig)
0023     : theKey(aKey),
0024       myOmtfConfig(omtfConfig),
0025       results(boost::extents[myOmtfConfig->processorCnt()][myOmtfConfig->nTestRefHits()]) {
0026   for (unsigned int iProc = 0; iProc < results.size(); iProc++) {
0027     for (unsigned int iTestRefHit = 0; iTestRefHit < results[iProc].size(); iTestRefHit++) {
0028       results[iProc][iTestRefHit].init(omtfConfig);
0029     }
0030   }
0031 }
0032 
0033 void GoldenPatternBase::setConfig(const OMTFConfiguration* omtfConfig) {
0034   myOmtfConfig = omtfConfig;
0035   results.resize(boost::extents[myOmtfConfig->processorCnt()][myOmtfConfig->nTestRefHits()]);
0036   for (unsigned int iProc = 0; iProc < results.size(); iProc++) {
0037     for (unsigned int iTestRefHit = 0; iTestRefHit < results[iProc].size(); iTestRefHit++) {
0038       results[iProc][iTestRefHit].init(omtfConfig);
0039     }
0040   }
0041 }
0042 
0043 ////////////////////////////////////////////////////
0044 ////////////////////////////////////////////////////
0045 StubResult GoldenPatternBase::process1Layer1RefLayer(unsigned int iRefLayer,
0046                                                      unsigned int iLayer,
0047                                                      MuonStubPtrs1D layerStubs,
0048                                                      const MuonStubPtr refStub) {
0049   //if (this->getDistPhiBitShift(iLayer, iRefLayer) != 0) LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<key()<<this->getDistPhiBitShift(iLayer, iRefLayer)<<std::endl;
0050 
0051   int phiMean = this->meanDistPhiValue(iLayer, iRefLayer, refStub->phiBHw);
0052   int phiDistMin = myOmtfConfig->nPhiBins();  //1<<(myOmtfConfig->nPdfAddrBits()); //"infinite" value for the beginning
0053 
0054   ///Select hit closest to the mean of probability
0055   ///distribution in given layer
0056   MuonStubPtr selectedStub;
0057 
0058   int phiRefHit = 0;
0059   if (refStub)
0060     phiRefHit = refStub->phiHw;
0061 
0062   if (this->myOmtfConfig->isBendingLayer(iLayer)) {
0063     phiRefHit = 0;  //phi ref hit for the bending layer set to 0, since it should not be included in the phiDist
0064   }
0065 
0066   for (auto& stub : layerStubs) {
0067     if (!stub)  //empty pointer
0068       continue;
0069 
0070     int hitPhi = stub->phiHw;
0071     if (this->myOmtfConfig->isBendingLayer(iLayer)) {
0072       //rejecting phiB of the low quality DT stubs is done in the OMTFInputMaker
0073       hitPhi = stub->phiBHw;
0074     }
0075 
0076     if (hitPhi >= (int)myOmtfConfig->nPhiBins())  //TODO is this needed now? the empty hit will be empty stub
0077       continue;  //empty itHits are marked with nPhiBins() in OMTFProcessor::restrictInput
0078 
0079     int phiDist = this->myOmtfConfig->foldPhi(hitPhi - phiMean - phiRefHit);
0080     //for standard omtf foldPhi is not needed, but if one processor works for full phi then it is
0081     //if (this->getDistPhiBitShift(iLayer, iRefLayer) != 0)
0082     /*LogTrace("l1tOmtfEventPrint") <<"\n"<<__FUNCTION__<<":"<<__LINE__<<" "<<theKey<<std::endl;
0083     LogTrace("l1tOmtfEventPrint") <<__FUNCTION__<<":"<<__LINE__
0084             <<"  iRefLayer "<<iRefLayer<<" iLayer "<<iLayer
0085             <<" hitPhi "<<hitPhi<<" phiMean "<<phiMean<<" phiRefHit "<<phiRefHit<<" phiDist "<<phiDist<<std::endl;*/
0086 
0087     //firmware works on the sign-value, shift must be done on abs(phiDist)
0088     int sign = phiDist < 0 ? -1 : 1;
0089     phiDist = abs(phiDist) >> this->getDistPhiBitShift(iLayer, iRefLayer);
0090     phiDist *= sign;
0091     //if the shift is done here, it means that the phiMean in the xml should be the same as without shift
0092     //if (this->getDistPhiBitShift(iLayer, iRefLayer) != 0) std::cout<<__FUNCTION__<<":"<<__LINE__<<" phiDist "<<phiDist<<std::endl;
0093     if (abs(phiDist) < abs(phiDistMin)) {
0094       phiDistMin = phiDist;
0095       selectedStub = stub;
0096     }
0097   }
0098 
0099   if (!selectedStub) {
0100     if (this->myOmtfConfig->isNoHitValueInPdf()) {
0101       PdfValueType pdfVal = this->pdfValue(iLayer, iRefLayer, 0);
0102       return StubResult(pdfVal, false, myOmtfConfig->nPhiBins(), iLayer, selectedStub);
0103     } else {
0104       return StubResult(0, false, myOmtfConfig->nPhiBins(), iLayer, selectedStub);  //2018 version
0105     }
0106   }
0107 
0108   int pdfMiddle = 1 << (myOmtfConfig->nPdfAddrBits() - 1);
0109 
0110   /*  debug
0111   if(phiDistMin != 128 && iRefLayer == 0 && iLayer == 1)*/
0112   /*LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" iRefLayer "<<iRefLayer<<" iLayer "<<iLayer<<" selectedStub "<<*selectedStub
0113           <<" phiDistMin "<<phiDistMin<<" phiMean "<<phiMean<<" shift "<<this->getDistPhiBitShift(iLayer, iRefLayer)<<std::endl;*/
0114 
0115   ///Check if phiDistMin is within pdf range -63 +63
0116   ///in firmware here the arithmetic "value and sign" is used, therefore the range is -63 +63, and not -64 +63
0117   if (abs(phiDistMin) > ((1 << (myOmtfConfig->nPdfAddrBits() - 1)) - 1)) {
0118     return StubResult(0, false, phiDistMin + pdfMiddle, iLayer, selectedStub);
0119 
0120     //return GoldenPatternResult::LayerResult(this->pdfValue(iLayer, iRefLayer, 0), false, phiDistMin + pdfMiddle, selHit);
0121     //in some algorithms versions with thresholds we use the bin 0 to store the pdf value returned when there was no hit.
0122     //in the version without thresholds, the value in the bin 0 should be 0
0123   }
0124 
0125   ///Shift phidist, so 0 is at the middle of the range
0126   phiDistMin += pdfMiddle;
0127   //if (this->getDistPhiBitShift(iLayer, iRefLayer) != 0) LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" phiDistMin "<<phiDistMin<<std::endl;
0128   PdfValueType pdfVal = this->pdfValue(iLayer, iRefLayer, phiDistMin);
0129   if (pdfVal <= 0) {
0130     return StubResult(0, false, phiDistMin, iLayer, selectedStub);
0131   }
0132   return StubResult(pdfVal, true, phiDistMin, iLayer, selectedStub);
0133 }
0134 
0135 ////////////////////////////////////////////////////
0136 ////////////////////////////////////////////////////
0137 void GoldenPatternBase::finalise(unsigned int procIndx) {
0138   for (auto& result : getResults()[procIndx]) {
0139     result.finalise();
0140   }
0141 }