Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-06 02:54:10

0001 /*
0002  * ProcessorBase.cpp
0003  *
0004  *  Created on: Jul 28, 2017
0005  *      Author: kbunkow
0006  */
0007 
0008 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/ProcessorBase.h"
0009 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/GoldenPattern.h"
0010 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/GoldenPatternWithStat.h"
0011 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/XMLConfigWriter.h"
0012 
0013 #include "CondFormats/L1TObjects/interface/L1TMuonOverlapParams.h"
0014 #include "SimDataFormats/Track/interface/SimTrack.h"
0015 
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/Utilities/interface/Exception.h"
0019 
0020 template <class GoldenPatternType>
0021 ProcessorBase<GoldenPatternType>::ProcessorBase(OMTFConfiguration* omtfConfig,
0022                                                 GoldenPatternVec<GoldenPatternType>&& gps)
0023     : myOmtfConfig(omtfConfig), theGPs(std::move(gps)) {
0024   for (auto& gp : theGPs) {
0025     gp->setConfig(myOmtfConfig);
0026   }
0027 
0028   initPatternPtRange(true);
0029 
0030   omtfConfig->setPatternPtRange(getPatternPtRange());
0031 };
0032 
0033 template <class GoldenPatternType>
0034 void ProcessorBase<GoldenPatternType>::resetConfiguration() {
0035   theGPs.clear();
0036 }
0037 
0038 ///////////////////////////////////////////////
0039 ///////////////////////////////////////////////
0040 template <class GoldenPatternType>
0041 bool ProcessorBase<GoldenPatternType>::configure(OMTFConfiguration* omtfConfig,
0042                                                  const L1TMuonOverlapParams* omtfPatterns) {
0043   resetConfiguration();
0044 
0045   myOmtfConfig = omtfConfig;
0046 
0047   const l1t::LUT* chargeLUT = omtfPatterns->chargeLUT();
0048   const l1t::LUT* etaLUT = omtfPatterns->etaLUT();
0049   const l1t::LUT* ptLUT = omtfPatterns->ptLUT();
0050   const l1t::LUT* pdfLUT = omtfPatterns->pdfLUT();
0051   const l1t::LUT* meanDistPhiLUT = omtfPatterns->meanDistPhiLUT();
0052   const l1t::LUT* distPhiShiftLUT = omtfPatterns->distPhiShiftLUT();
0053 
0054   unsigned int nGPs = myOmtfConfig->nGoldenPatterns();
0055   edm::LogVerbatim("OMTFReconstruction")
0056       << "ProcessorBase<>::configure. Building patterns from L1TMuonOverlapParams (LUTs). nGoldenPatterns() " << nGPs
0057       << std::endl;
0058 
0059   unsigned int address = 0;
0060   unsigned int iEta, iPt;
0061   int iCharge;
0062   //int meanDistPhiSize = myOmtfConfig->nLayers() * myOmtfConfig->nRefLayers() * myOmtfConfig->nGoldenPatterns();
0063 
0064   unsigned int group = 0;
0065   unsigned int indexInGroup = 0;
0066   for (unsigned int iGP = 0; iGP < nGPs; ++iGP) {
0067     address = iGP;
0068     iEta = etaLUT->data(address);
0069     iCharge = chargeLUT->data(address) == 0 ? -1 : 1;
0070     iPt = ptLUT->data(address);
0071 
0072     //the patterns in the LUTs should contain the empty patterns, only then the group and indexInGroup calculation works
0073     group = iGP / myOmtfConfig->patternsInGroup;
0074     indexInGroup = iGP % myOmtfConfig->patternsInGroup + 1;
0075     Key aKey(iEta, iPt, iCharge, theGPs.size(), group, indexInGroup);
0076     if (iPt == 0) {
0077       LogTrace("OMTFReconstruction") << "skipping empty pattern " << aKey << " " << std::endl;
0078       //<<myOmtfConfig->getPatternPtRange(iGP).ptFrom<<" - "<<myOmtfConfig->getPatternPtRange(iGP).ptTo<<" GeV"<<std::endl; PatternPtRange is not initialized here yet, so do not use it!!!!
0079       continue;
0080     }
0081 
0082     LogTrace("OMTFReconstruction") << "adding pattern " << aKey << " " << std::endl;
0083     //<<myOmtfConfig->getPatternPtRange(iGP).ptFrom<<" - "<<myOmtfConfig->getPatternPtRange(iGP).ptTo<<" GeV"<<std::endl; PatternPtRange is not initialized here yet, so do not use it!!!!
0084 
0085     GoldenPatternType* aGP = new GoldenPatternType(aKey, myOmtfConfig);
0086 
0087     for (unsigned int iLayer = 0; iLayer < myOmtfConfig->nLayers(); ++iLayer) {
0088       for (unsigned int iRefLayer = 0; iRefLayer < myOmtfConfig->nRefLayers(); ++iRefLayer) {
0089         address = iRefLayer + iLayer * myOmtfConfig->nRefLayers() +
0090                   iGP * (myOmtfConfig->nRefLayers() * myOmtfConfig->nLayers());
0091 
0092         ///Mean dist phi data
0093         //LUT values are only positive, therefore to have negative  meanDistPh half of the max LUT value is subtracted
0094         int value = meanDistPhiLUT->data(address) - (1 << (meanDistPhiLUT->nrBitsData() - 1));
0095         aGP->setMeanDistPhiValue(value, iLayer, iRefLayer, 0);
0096 
0097         /* uncomment this if you need  meanDistPhi1 in the LUTs (and set useMeanDistPhi1 in XMLConfigReader::readLUTs)
0098         if ( (1 << meanDistPhiLUT->nrBitsAddress()) > 2 * meanDistPhiSize ) {
0099           //for the  version of the meanDistPhi which have two values for each gp,iLayer,iRefLayer, FIXME: do it a better way
0100           value = meanDistPhiLUT->data(address + meanDistPhiSize) - (1 << (meanDistPhiLUT->nrBitsData() - 1));
0101           //the second meanDistPhi is in the LUT at the position (address+meanDistPhiSize)
0102           aGP->setMeanDistPhiValue(value, iLayer, iRefLayer, 1);
0103         }*/
0104 
0105         //selDistPhiShift, if the distPhiShiftLUT is nullptr, it means it was not present in the L1TMuonOverlapParamsRcd
0106         if (distPhiShiftLUT) {
0107           value = distPhiShiftLUT->data(address);  //distPhiShiftLUT values are only positive
0108           aGP->setDistPhiBitShift(value, iLayer, iRefLayer);
0109         }
0110       }
0111       ///Pdf data
0112       for (unsigned int iRefLayer = 0; iRefLayer < myOmtfConfig->nRefLayers(); ++iRefLayer) {
0113         for (unsigned int iPdf = 0; iPdf < (unsigned int)(1 << myOmtfConfig->nPdfAddrBits()); ++iPdf) {
0114           address = iPdf + iRefLayer * (1 << myOmtfConfig->nPdfAddrBits()) +
0115                     iLayer * myOmtfConfig->nRefLayers() * (1 << myOmtfConfig->nPdfAddrBits()) +
0116                     iGP * myOmtfConfig->nLayers() * myOmtfConfig->nRefLayers() * (1 << myOmtfConfig->nPdfAddrBits());
0117           int value = pdfLUT->data(address);  //here only int is possible
0118           aGP->setPdfValue(value, iLayer, iRefLayer, iPdf);
0119 
0120           //LogTrace("OMTFReconstruction") <<" iLayer "<<iLayer<<" iRefLayer "<<iRefLayer<<" iPdf "<<iPdf << " address "<<address<<" value "<<value<<std::endl;
0121         }
0122       }
0123     }
0124 
0125     addGP(aGP);
0126   }
0127 
0128   initPatternPtRange(true);
0129 
0130   omtfConfig->setPatternPtRange(getPatternPtRange());
0131 
0132   return true;
0133 }
0134 
0135 ///////////////////////////////////////////////
0136 ///////////////////////////////////////////////
0137 template <class GoldenPatternType>
0138 void ProcessorBase<GoldenPatternType>::addGP(GoldenPatternType* aGP) {
0139   theGPs.emplace_back(std::unique_ptr<GoldenPatternType>(aGP));
0140 }
0141 
0142 ////////////////////////////////////////////
0143 ////////////////////////////////////////////
0144 template <class GoldenPatternType>
0145 MuonStubPtrs1D ProcessorBase<GoldenPatternType>::restrictInput(unsigned int iProcessor,
0146                                                                unsigned int iRegion,
0147                                                                unsigned int iLayer,
0148                                                                const OMTFinput& input) {
0149   MuonStubPtrs1D layerStubs;
0150 
0151   unsigned int iStart = myOmtfConfig->getConnections()[iProcessor][iRegion][iLayer].first;
0152   unsigned int iEnd = iStart + myOmtfConfig->getConnections()[iProcessor][iRegion][iLayer].second - 1;
0153 
0154   for (unsigned int iInput = 0; iInput < input.getMuonStubs()[iLayer].size(); ++iInput) {
0155     if (iInput >= iStart && iInput <= iEnd) {
0156       if (this->myOmtfConfig->isBendingLayer(iLayer)) {
0157         layerStubs.push_back(input.getMuonStub(iLayer - 1, iInput));
0158       } else
0159         layerStubs.push_back(input.getMuonStub(iLayer, iInput));  //input.getHitPhi(iLayer, iInput)
0160     }
0161   }
0162   //LogTrace("OMTFReconstruction") <<__FUNCTION__<<":"<<__LINE__<<" layerHits.size() "<<layerHits.size()<<std::endl;
0163   return layerStubs;
0164 }
0165 
0166 ////////////////////////////////////////////
0167 ////////////////////////////////////////////
0168 template <class GoldenPatternType>
0169 void ProcessorBase<GoldenPatternType>::initPatternPtRange(bool firstPatFrom0) {
0170   patternPts.clear();
0171 
0172   bool firstPos = firstPatFrom0;
0173   bool firstNeg = firstPatFrom0;
0174   for (unsigned int iPat = 0; iPat < theGPs.size(); iPat++) {
0175     OMTFConfiguration::PatternPt patternPt;
0176     int charge = theGPs[iPat]->key().theCharge;
0177     if (theGPs[iPat] == nullptr || theGPs[iPat]->key().thePt == 0) {
0178       patternPts.push_back(patternPt);
0179       continue;
0180     }
0181 
0182     patternPt.ptFrom = myOmtfConfig->hwPtToGev(theGPs[iPat]->key().thePt);
0183     if (firstPos && theGPs[iPat]->key().theCharge == 1) {
0184       patternPt.ptFrom = 0;
0185       firstPos = false;
0186     }
0187     if (firstNeg && theGPs[iPat]->key().theCharge == -1) {
0188       patternPt.ptFrom = 0;
0189       firstNeg = false;
0190     }
0191 
0192     unsigned int iPat1 = iPat;
0193     while (true) {  //to skip the empty patterns with pt=0 and patterns with opposite charge
0194       iPat1++;
0195       if (iPat1 == theGPs.size())
0196         break;
0197       if (theGPs[iPat1]->key().thePt != 0 && theGPs[iPat1]->key().theCharge == charge)
0198         break;
0199     }
0200 
0201     if (iPat1 == theGPs.size())
0202       patternPt.ptTo = 10000;  //inf
0203     else
0204       patternPt.ptTo = myOmtfConfig->hwPtToGev(theGPs[iPat1]->key().thePt);
0205 
0206     patternPt.charge = charge;
0207     patternPts.push_back(patternPt);
0208   }
0209 
0210   //debug
0211   /*  for(unsigned int iPat = 0; iPat < theGPs.size(); iPat++) {
0212     LogTrace("OMTFReconstruction") <<theGPs[iPat]->key()<<" ptFrom "<<patternPts[iPat].ptFrom<<" ptFrom "<<patternPts[iPat].ptTo<<std::endl;
0213   }*/
0214 
0215   edm::LogTrace_("OMTFReconstruction") << __FUNCTION__ << ":" << __LINE__ << " patternPts.size() " << patternPts.size()
0216                                        << endl;
0217 }
0218 
0219 template <class GoldenPatternType>
0220 void ProcessorBase<GoldenPatternType>::printInfo() const {
0221   myOmtfConfig->printConfig();
0222 
0223   edm::LogVerbatim("OMTFReconstruction") << "\npatterns:" << std::endl;
0224   unsigned int patNum = 0;
0225   for (auto& gp : theGPs) {
0226     edm::LogVerbatim("OMTFReconstruction")
0227         << std::setw(2) << patNum << " " << gp->key() << " " << myOmtfConfig->getPatternPtRange(patNum).ptFrom << " - "
0228         << myOmtfConfig->getPatternPtRange(patNum).ptTo << " GeV" << std::endl;
0229     patNum++;
0230   }
0231 
0232   /* //can be useful for debug, uncomment if needed
0233   XMLConfigWriter xmlWriter(this->myOmtfConfig, false, false);
0234   xmlWriter.writeGPs(this->theGPs, "patternsAsInTheProcessor.xml");*/
0235 }
0236 
0237 //to force compiler to compile the above methods with needed GoldenPatterns types
0238 template class ProcessorBase<GoldenPattern>;
0239 template class ProcessorBase<GoldenPatternWithThresh>;
0240 template class ProcessorBase<GoldenPatternWithStat>;