Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-02 23:43:34

0001 /*
0002  * OMTFProcessor.cpp
0003  *
0004  *  Created on: Oct 7, 2017
0005  *      Author: kbunkow
0006  */
0007 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/OMTFProcessor.h"
0008 #include "L1Trigger/L1TMuonOverlapPhase1/interface/MuonStub.h"
0009 #include "L1Trigger/L1TMuonOverlapPhase1/interface/MuonStubsInput.h"
0010 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/GhostBuster.h"
0011 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/GhostBusterPreferRefDt.h"
0012 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/GoldenPatternWithStat.h"
0013 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/IOMTFEmulationObserver.h"
0014 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/OMTFinput.h"
0015 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/OMTFSorter.h"
0016 #include "L1Trigger/L1TMuonOverlapPhase1/interface/StubResult.h"
0017 
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 
0020 #include <bitset>
0021 #include <cmath>
0022 #include <cstdlib>
0023 #include <iostream>
0024 #include <map>
0025 #include <string>
0026 #include <vector>
0027 
0028 ///////////////////////////////////////////////
0029 ///////////////////////////////////////////////
0030 template <class GoldenPatternType>
0031 OMTFProcessor<GoldenPatternType>::OMTFProcessor(OMTFConfiguration* omtfConfig,
0032                                                 const edm::ParameterSet& edmCfg,
0033                                                 edm::EventSetup const& evSetup,
0034                                                 const L1TMuonOverlapParams* omtfPatterns)
0035     : ProcessorBase<GoldenPatternType>(omtfConfig, omtfPatterns) {
0036   init(edmCfg, evSetup);
0037 };
0038 
0039 template <class GoldenPatternType>
0040 OMTFProcessor<GoldenPatternType>::OMTFProcessor(OMTFConfiguration* omtfConfig,
0041                                                 const edm::ParameterSet& edmCfg,
0042                                                 edm::EventSetup const& evSetup,
0043                                                 GoldenPatternVec<GoldenPatternType>&& gps)
0044     : ProcessorBase<GoldenPatternType>(omtfConfig, std::forward<GoldenPatternVec<GoldenPatternType> >(gps)) {
0045   init(edmCfg, evSetup);
0046 };
0047 
0048 template <class GoldenPatternType>
0049 OMTFProcessor<GoldenPatternType>::~OMTFProcessor() {}
0050 
0051 template <class GoldenPatternType>
0052 void OMTFProcessor<GoldenPatternType>::init(const edm::ParameterSet& edmCfg, edm::EventSetup const& evSetup) {
0053   setSorter(new OMTFSorter<GoldenPatternType>(this->myOmtfConfig->getSorterType()));
0054   //initialize with the default sorter
0055 
0056   if (this->myOmtfConfig->getGhostBusterType() == "GhostBusterPreferRefDt" ||
0057       this->myOmtfConfig->getGhostBusterType() == "byLLH") {
0058     setGhostBuster(new GhostBusterPreferRefDt(this->myOmtfConfig));
0059     edm::LogVerbatim("OMTFReconstruction") << "setting " << this->myOmtfConfig->getGhostBusterType() << std::endl;
0060   } else {
0061     setGhostBuster(new GhostBuster(this->myOmtfConfig));  //initialize with the default sorter
0062     edm::LogVerbatim("OMTFReconstruction") << "setting GhostBuster" << std::endl;
0063   }
0064 
0065   edm::LogVerbatim("OMTFReconstruction") << "fwVersion 0x" << hex << this->myOmtfConfig->fwVersion() << std::endl;
0066 }
0067 
0068 template <class GoldenPatternType>
0069 std::vector<l1t::RegionalMuonCand> OMTFProcessor<GoldenPatternType>::getFinalcandidates(unsigned int iProcessor,
0070                                                                                         l1t::tftype mtfType,
0071                                                                                         const AlgoMuons& algoCands) {
0072   std::vector<l1t::RegionalMuonCand> result;
0073 
0074   for (auto& myCand : algoCands) {
0075     l1t::RegionalMuonCand candidate;
0076     candidate.setHwPt(myCand->getPt());
0077     candidate.setHwEta(myCand->getEtaHw());
0078 
0079     int phiValue = myCand->getPhi();
0080     if (phiValue >= int(this->myOmtfConfig->nPhiBins()))
0081       phiValue -= this->myOmtfConfig->nPhiBins();
0082     phiValue = this->myOmtfConfig->procPhiToGmtPhi(phiValue);
0083     candidate.setHwPhi(phiValue);
0084 
0085     candidate.setHwSign(myCand->getCharge() < 0 ? 1 : 0);
0086     candidate.setHwSignValid(1);
0087 
0088     unsigned int quality = 12;
0089     if (this->myOmtfConfig->fwVersion() <= 6)
0090       quality = checkHitPatternValidity(myCand->getFiredLayerBits()) ? 0 | (1 << 2) | (1 << 3) : 0 | (1 << 2);
0091 
0092     if (abs(myCand->getEtaHw()) == 115 &&
0093         (static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("100000001110000000").to_ulong() ||
0094          static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000001110000000").to_ulong() ||
0095          static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("100000000110000000").to_ulong() ||
0096          static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("100000001100000000").to_ulong() ||
0097          static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("100000001010000000").to_ulong())) {
0098       if (this->myOmtfConfig->fwVersion() <= 6)
0099         quality = 4;
0100       else
0101         quality = 1;
0102     }
0103 
0104     if (this->myOmtfConfig->fwVersion() >= 5 && this->myOmtfConfig->fwVersion() <= 6) {
0105       if (static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000010000000011").to_ulong() ||
0106           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000100000000011").to_ulong() ||
0107           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001000000000011").to_ulong() ||
0108           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000010000000000011").to_ulong() ||
0109           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000100000000000011").to_ulong() ||
0110           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000000000000011").to_ulong() ||
0111           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("010000000000000011").to_ulong() ||
0112           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("100000000000000011").to_ulong() ||
0113           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000010000001100").to_ulong() ||
0114           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000100000001100").to_ulong() ||
0115           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001000000001100").to_ulong() ||
0116           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000010000000001100").to_ulong() ||
0117           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000100000000001100").to_ulong() ||
0118           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000000000001100").to_ulong() ||
0119           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("010000000000001100").to_ulong() ||
0120           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("100000000000001100").to_ulong() ||
0121           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000010000110000").to_ulong() ||
0122           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000100000110000").to_ulong() ||
0123           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001000000110000").to_ulong() ||
0124           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000010000000110000").to_ulong() ||
0125           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000100000000110000").to_ulong() ||
0126           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000000000110000").to_ulong() ||
0127           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("010000000000110000").to_ulong() ||
0128           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("100000000000110000").to_ulong())
0129         quality = 1;
0130     } else if (this->myOmtfConfig->fwVersion() >= 8) {  //TODO fix the fwVersion
0131       if (static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000110000000011").to_ulong() ||
0132           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000100000000011").to_ulong() ||
0133           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000010000000011").to_ulong() ||
0134           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000110000000001").to_ulong() ||
0135 
0136           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001000000001100").to_ulong() ||
0137           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000011000000001100").to_ulong() ||
0138           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000010000000001100").to_ulong() ||
0139           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000011000000000100").to_ulong() ||
0140 
0141           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000011000000001").to_ulong() ||
0142           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000010000000001").to_ulong())
0143         quality = 1;
0144       else if (
0145           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000010000000101").to_ulong() ||
0146           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000010001000001").to_ulong() ||
0147           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000011000000001").to_ulong() ||
0148           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000011000000011").to_ulong() ||
0149           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000011100000001").to_ulong() ||
0150           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000100000000011").to_ulong() ||
0151           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000100001000100").to_ulong() ||
0152           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000100100000001").to_ulong() ||
0153           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000110100000001").to_ulong() ||
0154           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000111000000000").to_ulong() ||
0155           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000111000000001").to_ulong() ||
0156           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000111000000011").to_ulong() ||
0157           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001000001000100").to_ulong() ||
0158           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001010000000001").to_ulong() ||
0159           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001010000000011").to_ulong() ||
0160           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001010000000100").to_ulong() ||
0161           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001100000000001").to_ulong() ||
0162           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001100000000100").to_ulong() ||
0163           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001100000000111").to_ulong() ||
0164           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001100001000000").to_ulong() ||
0165           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001110000000100").to_ulong() ||
0166           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001110000000101").to_ulong() ||
0167           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000010000000000101").to_ulong() ||
0168           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000010010000000001").to_ulong() ||
0169           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000010010000000100").to_ulong() ||
0170           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000010010000000101").to_ulong() ||
0171           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000010100000000001").to_ulong() ||
0172           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000010100000000101").to_ulong() ||
0173           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000011110000000100").to_ulong() ||
0174           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000011110000000101").to_ulong() ||
0175           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000101000000010101").to_ulong() ||
0176           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000010000000001").to_ulong() ||
0177           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000011000000000").to_ulong() ||
0178           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000011000000001").to_ulong() ||
0179           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000100000000001").to_ulong() ||
0180           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000110000000000").to_ulong() ||
0181           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001001000000000100").to_ulong() ||
0182           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001001100000000100").to_ulong() ||
0183           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001010000000000100").to_ulong() ||
0184           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("010000000010000001").to_ulong() ||
0185           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("010000000011000100").to_ulong() ||
0186           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("010000010000000001").to_ulong() ||
0187           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("010000100000000001").to_ulong() ||
0188           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("100000011000000000").to_ulong() ||
0189           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000110000000001").to_ulong() ||
0190           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000010000000011").to_ulong() ||
0191           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000110000000011").to_ulong() ||
0192           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000011000000001100").to_ulong() ||
0193           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000011000000000100").to_ulong() ||
0194           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000010010000001").to_ulong() ||
0195           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000010000000001100").to_ulong() ||
0196           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001001000001000100").to_ulong() ||
0197           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001100000000101").to_ulong() ||
0198           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000100000000101").to_ulong() ||
0199           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001100000000011").to_ulong() ||
0200           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001110000000111").to_ulong() ||
0201           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000110001000001").to_ulong() ||
0202           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001110000000011").to_ulong() ||
0203           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000000001000100").to_ulong() ||
0204           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000110001000001").to_ulong() ||
0205           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001000000000101").to_ulong() ||
0206           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001010000001000000").to_ulong() ||
0207           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001100000001000000").to_ulong() ||
0208           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("100000010000000001").to_ulong() ||
0209           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("010000010010000000").to_ulong() ||
0210           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000010100000001100").to_ulong() ||
0211           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000110000000011").to_ulong() ||
0212           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001000000001100").to_ulong() ||
0213           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000000000000111101").to_ulong() ||
0214           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000001100000110001").to_ulong() ||
0215           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000100000000010100").to_ulong() ||
0216           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000100000000011").to_ulong() ||
0217           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("001000110000000001").to_ulong() ||
0218           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("010000100010000001").to_ulong() ||
0219           static_cast<unsigned int>(myCand->getFiredLayerBits()) == std::bitset<18>("000100000000110000").to_ulong())
0220         quality = 8;
0221     }  //  if (abs(myCand->getEta()) == 121) quality = 4;
0222     if (abs(myCand->getEtaHw()) == 121)
0223       quality = 0;  // changed from 4 on request from HI
0224 
0225     candidate.setHwQual(quality);
0226 
0227     std::map<int, int> trackAddr;
0228     trackAddr[0] = myCand->getFiredLayerBits();
0229     trackAddr[1] = myCand->getRefLayer();
0230     trackAddr[2] = myCand->getDisc();
0231     if (candidate.hwPt() > 0) {
0232       if (ptAssignment) {
0233         auto pts = ptAssignment->getPts(myCand);
0234         for (unsigned int i = 0; i < pts.size(); i++) {
0235           trackAddr[10 + i] = this->myOmtfConfig->ptGevToHw(pts[i]);
0236         }
0237       }
0238 
0239       candidate.setTrackAddress(trackAddr);
0240       candidate.setTFIdentifiers(iProcessor, mtfType);
0241       result.push_back(candidate);
0242     }
0243   }
0244   return result;
0245 }
0246 ///////////////////////////////////////////////////////
0247 ///////////////////////////////////////////////////////
0248 
0249 ///////////////////////////////////////////////////////
0250 ///////////////////////////////////////////////////////
0251 template <class GoldenPatternType>
0252 bool OMTFProcessor<GoldenPatternType>::checkHitPatternValidity(unsigned int hits) {
0253   ///FIXME: read the list from configuration so this can be controlled at runtime.
0254   std::vector<unsigned int> badPatterns = {
0255       99840, 34304, 3075, 36928, 12300, 98816, 98944, 33408, 66688, 66176, 7171, 20528, 33856, 35840, 4156, 34880};
0256 
0257   /*
0258 99840 01100001 1000 000000      011000011000000000
0259 34304 00100001 1000 000000      001000011000000000
0260  3075 00000011 0000 000011      000000110000000011
0261 36928 00100100 0001 000000      001001000001000000
0262 12300 00001100 0000 001100      000011000000001100
0263 98816 01100000 1000 000000      011000001000000000
0264 98944 01100000 1010 000000      011000001010000000
0265 33408 00100000 1010 000000      001000001010000000
0266 66688 01000001 0010 000000      010000010010000000
0267 66176 01000000 1010 000000      010000001010000000
0268  7171 00000111 0000 000011      000001110000000011
0269 20528 00010100 0000 110000      000101000000110000
0270 33856 00100001 0001 000000      001000010001000000
0271 35840 00100011 0000 000000      001000110000000000
0272  4156 00000100 0000 111100      000001000000111100
0273 34880 00100010 0001 000000      001000100001000000
0274    */
0275   for (auto aHitPattern : badPatterns) {
0276     if (hits == aHitPattern)
0277       return false;
0278   }
0279 
0280   return true;
0281 }
0282 ///////////////////////////////////////////////////////
0283 ///////////////////////////////////////////////////////
0284 template <class GoldenPatternType>
0285 AlgoMuons OMTFProcessor<GoldenPatternType>::sortResults(unsigned int iProcessor, l1t::tftype mtfType, int charge) {
0286   unsigned int procIndx = this->myOmtfConfig->getProcIndx(iProcessor, mtfType);
0287   return sorter->sortResults(procIndx, this->getPatterns(), charge);
0288 }
0289 ///////////////////////////////////////////////
0290 ///////////////////////////////////////////////
0291 //const std::vector<OMTFProcessor::resultsMap> &
0292 template <class GoldenPatternType>
0293 void OMTFProcessor<GoldenPatternType>::processInput(unsigned int iProcessor,
0294                                                     l1t::tftype mtfType,
0295                                                     const OMTFinput& aInput) {
0296   unsigned int procIndx = this->myOmtfConfig->getProcIndx(iProcessor, mtfType);
0297   for (auto& itGP : this->theGPs) {
0298     for (auto& result : itGP->getResults()[procIndx]) {
0299       result.reset();
0300     }
0301   }
0302 
0303   //////////////////////////////////////
0304   //////////////////////////////////////
0305   std::bitset<128> refHitsBits = aInput.getRefHits(iProcessor);
0306   if (refHitsBits.none())
0307     return;  // myResults;
0308 
0309   for (unsigned int iLayer = 0; iLayer < this->myOmtfConfig->nLayers(); ++iLayer) {
0310     //debug
0311     /*for(auto& h : layerHits) {
0312       if(h != 5400)
0313         LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<" "<<__LINE__<<" iLayer "<<iLayer<<" layerHit "<<h<<std::endl;
0314     }*/
0315     ///Number of reference hits to be checked.
0316     unsigned int nTestedRefHits = this->myOmtfConfig->nTestRefHits();
0317     for (unsigned int iRefHit = 0; iRefHit < this->myOmtfConfig->nRefHits();
0318          ++iRefHit) {  //loop over all possible refHits, i.e. 128
0319       if (!refHitsBits[iRefHit])
0320         continue;
0321       if (nTestedRefHits-- == 0)
0322         break;
0323 
0324       const RefHitDef& aRefHitDef = this->myOmtfConfig->getRefHitsDefs()[iProcessor][iRefHit];
0325 
0326       unsigned int refLayerLogicNum = this->myOmtfConfig->getRefToLogicNumber()[aRefHitDef.iRefLayer];
0327       const MuonStubPtr refStub = aInput.getMuonStub(refLayerLogicNum, aRefHitDef.iInput);
0328       int phiRef = refStub->phiHw;
0329       int etaRef = refStub->etaHw;
0330 
0331       unsigned int iRegion = aRefHitDef.iRegion;
0332 
0333       if (this->myOmtfConfig->getBendingLayers().count(iLayer))  //this iLayer is a bending layer
0334         phiRef = 0;  //then in the delta_phi in process1Layer1RefLayer one obtains simply the iLayer phi
0335 
0336       MuonStubPtrs1D restrictedLayerStubs = this->restrictInput(iProcessor, iRegion, iLayer, aInput);
0337 
0338       //LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<" "<<__LINE__<<" iLayer "<<iLayer<<" iRefLayer "<<aRefHitDef.iRefLayer<<" hits.size "<<restrictedLayerHits.size()<<std::endl;
0339       //LogTrace("l1tOmtfEventPrint")<<"iLayer "<<iLayer<<" refHitNum "<<myOmtfConfig->nTestRefHits()-nTestedRefHits-1<<" iRefHit "<<iRefHit;
0340       //LogTrace("l1tOmtfEventPrint")<<" nTestedRefHits "<<nTestedRefHits<<" aRefHitDef "<<aRefHitDef<<std::endl;
0341 
0342       unsigned int refHitNumber = this->myOmtfConfig->nTestRefHits() - nTestedRefHits - 1;
0343       for (auto& itGP : this->theGPs) {
0344         if (itGP->key().thePt == 0)  //empty pattern
0345           continue;
0346 
0347         StubResult stubResult =
0348             itGP->process1Layer1RefLayer(aRefHitDef.iRefLayer, iLayer, restrictedLayerStubs, refStub);
0349 
0350         //fixme this unnecessary repeated  for every layer - but in this layout of loops must be like that
0351         int phiRefSt2 = itGP->propagateRefPhi(phiRef, etaRef, aRefHitDef.iRefLayer);
0352 
0353         //LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" layerResult: valid"<<layerResult.valid<<" pdfVal "<<layerResult.pdfVal<<std::endl;
0354         itGP->getResults()[procIndx][refHitNumber].setStubResult(iLayer, stubResult);
0355         //fixme this unnecessary repeated  for every layer - but in this layout of loops must be like that
0356         itGP->getResults()[procIndx][refHitNumber].set(aRefHitDef.iRefLayer, phiRefSt2, etaRef, phiRef);
0357       }
0358     }
0359   }
0360   //////////////////////////////////////
0361   //////////////////////////////////////
0362   {
0363     for (auto& itGP : this->theGPs) {
0364       itGP->finalise(procIndx);
0365       //debug
0366       /*for(unsigned int iRefHit = 0; iRefHit < itGP->getResults()[procIndx].size(); ++iRefHit) {
0367         if(itGP->getResults()[procIndx][iRefHit].isValid()) {
0368           LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<"__LINE__"<<itGP->getResults()[procIndx][iRefHit]<<std::endl;
0369         }
0370       }*/
0371     }
0372   }
0373 
0374   return;
0375 }
0376 ///////////////////////////////////////////////////////
0377 ///////////////////////////////////////////////////////
0378 
0379 template <class GoldenPatternType>
0380 std::vector<l1t::RegionalMuonCand> OMTFProcessor<GoldenPatternType>::run(
0381     unsigned int iProcessor,
0382     l1t::tftype mtfType,
0383     int bx,
0384     OMTFinputMaker* inputMaker,
0385     std::vector<std::unique_ptr<IOMTFEmulationObserver> >& observers) {
0386   //uncomment if you want to check execution time of each method
0387   //boost::timer::auto_cpu_timer t("%ws wall, %us user in getProcessorCandidates\n");
0388 
0389   //input is shared_ptr because the observers may need them after the run() method execution is finished
0390   std::shared_ptr<OMTFinput> input = std::make_shared<OMTFinput>(this->myOmtfConfig);
0391   inputMaker->buildInputForProcessor(input->getMuonStubs(), iProcessor, mtfType, bx, bx);
0392 
0393   //LogTrace("l1tOmtfEventPrint")<<"buildInputForProce "; t.report();
0394   processInput(iProcessor, mtfType, *(input.get()));
0395 
0396   //LogTrace("l1tOmtfEventPrint")<<"processInput       "; t.report();
0397   AlgoMuons algoCandidates = sortResults(iProcessor, mtfType);
0398 
0399   //LogTrace("l1tOmtfEventPrint")<<"sortResults        "; t.report();
0400   // perform GB
0401   AlgoMuons gbCandidates = ghostBust(algoCandidates);
0402 
0403   //LogTrace("l1tOmtfEventPrint")<<"ghostBust"; t.report();
0404   // fill RegionalMuonCand colleciton
0405   std::vector<l1t::RegionalMuonCand> candMuons = getFinalcandidates(iProcessor, mtfType, gbCandidates);
0406 
0407   //LogTrace("l1tOmtfEventPrint")<<"getFinalcandidates "; t.report();
0408   //fill outgoing collection
0409   for (auto& candMuon : candMuons) {
0410     candMuon.setHwQual(candMuon.hwQual());
0411   }
0412 
0413   for (auto& obs : observers) {
0414     obs->observeProcesorEmulation(iProcessor, mtfType, input, algoCandidates, gbCandidates, candMuons);
0415   }
0416 
0417   return candMuons;
0418 }
0419 
0420 template <class GoldenPatternType>
0421 void OMTFProcessor<GoldenPatternType>::printInfo() const {
0422   edm::LogVerbatim("OMTFReconstruction") << __PRETTY_FUNCTION__ << std::endl;
0423 
0424   ProcessorBase<GoldenPatternType>::printInfo();
0425 }
0426 
0427 /////////////////////////////////////////////////////////
0428 
0429 template class OMTFProcessor<GoldenPattern>;
0430 template class OMTFProcessor<GoldenPatternWithStat>;
0431 template class OMTFProcessor<GoldenPatternWithThresh>;