Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:07

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 std::vector<int>& extrapolatedPhi,
0049                                                      const MuonStubPtr& refStub) {
0050   //if (this->getDistPhiBitShift(iLayer, iRefLayer) != 0) LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<key()<<this->getDistPhiBitShift(iLayer, iRefLayer)<<std::endl;
0051 
0052   int phiMean = this->meanDistPhiValue(iLayer, iRefLayer, refStub->phiBHw);
0053   int phiDistMin = myOmtfConfig->nPhiBins();
0054 
0055   ///Select hit closest to the mean of probability
0056   ///distribution in given layer
0057   MuonStubPtr selectedStub;
0058 
0059   int phiRefHit = 0;
0060   if (refStub)
0061     phiRefHit = refStub->phiHw;
0062 
0063   if (this->myOmtfConfig->isBendingLayer(iLayer)) {
0064     phiRefHit = 0;  //phi ref hit for the bending layer set to 0, since it should not be included in the phiDist
0065   }
0066 
0067   for (size_t iStub = 0; iStub < layerStubs.size(); iStub++) {
0068     const auto& stub = layerStubs[iStub];
0069     if (!stub)  //empty pointer
0070       continue;
0071 
0072     int hitPhi = stub->phiHw;
0073     if (this->myOmtfConfig->isBendingLayer(iLayer)) {
0074       //rejecting phiB of the low quality DT stubs is done in the OMTFInputMaker
0075       hitPhi = stub->phiBHw;
0076     }
0077 
0078     if (hitPhi >= (int)myOmtfConfig->nPhiBins())  //TODO is this needed now? the empty hit will be empty stub
0079       continue;  //empty itHits are marked with nPhiBins() in OMTFProcessor::restrictInput
0080 
0081     int phiDist = this->myOmtfConfig->foldPhi(hitPhi - extrapolatedPhi[iStub] - phiMean - phiRefHit);
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 std::abs(phiDist)
0088     int sign = phiDist < 0 ? -1 : 1;
0089     phiDist = std::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 (std::abs(phiDist) < std::abs(phiDistMin)) {
0094       phiDistMin = phiDist;
0095       selectedStub = stub;
0096     }
0097   }
0098 
0099   if (!selectedStub) {
0100     PdfValueType pdfVal = 0;
0101     if (this->myOmtfConfig->isNoHitValueInPdf())
0102       pdfVal = this->pdfValue(iLayer, iRefLayer, 0);
0103     return StubResult(pdfVal, false, myOmtfConfig->nPhiBins(), iLayer, selectedStub);
0104   }
0105 
0106   int pdfMiddle = 1 << (myOmtfConfig->nPdfAddrBits() - 1);
0107 
0108   /*  debug
0109   if(phiDistMin != 128 && iRefLayer == 0 && iLayer == 1)*/
0110   /*LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" iRefLayer "<<iRefLayer<<" iLayer "<<iLayer<<" selectedStub "<<*selectedStub
0111                  <<" phiDistMin "<<phiDistMin<<" phiMean "<<phiMean<<" shift "<<this->getDistPhiBitShift(iLayer, iRefLayer)<<std::endl;*/
0112 
0113   ///Check if phiDistMin is within pdf range -63 +63
0114   ///in firmware here the arithmetic "value and sign" is used, therefore the range is -63 +63, and not -64 +63
0115   if (std::abs(phiDistMin) > ((1 << (myOmtfConfig->nPdfAddrBits() - 1)) - 1)) {
0116     return StubResult(0, false, phiDistMin + pdfMiddle, iLayer, selectedStub);
0117 
0118     //in some algorithms versions with thresholds we use the bin 0 to store the pdf value returned when there was no hit.
0119     //in the version without thresholds, the value in the bin 0 should be 0
0120   }
0121 
0122   ///Shift phidist, so 0 is at the middle of the range
0123   phiDistMin += pdfMiddle;
0124   //if (this->getDistPhiBitShift(iLayer, iRefLayer) != 0) LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" phiDistMin "<<phiDistMin<<std::endl;
0125   PdfValueType pdfVal = this->pdfValue(iLayer, iRefLayer, phiDistMin);
0126   if (pdfVal <= 0) {
0127     return StubResult(0, false, phiDistMin, iLayer, selectedStub);
0128   }
0129   return StubResult(pdfVal, true, phiDistMin, iLayer, selectedStub);
0130 }
0131 
0132 ////////////////////////////////////////////////////
0133 ////////////////////////////////////////////////////
0134 void GoldenPatternBase::finalise(unsigned int procIndx) {
0135   for (auto& result : getResults()[procIndx]) {
0136     result.finalise();
0137   }
0138 }