Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:23:27

0001 #include <iostream>
0002 #include <algorithm>
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/ParameterSet/interface/FileInPath.h"
0006 
0007 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0008 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0009 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0010 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
0011 
0012 #include "L1Trigger/L1TMuonOverlap/interface/OMTFConfiguration.h"
0013 
0014 ///////////////////////////////////////////////
0015 ///////////////////////////////////////////////
0016 RefHitDef::RefHitDef(unsigned int aInput, int aPhiMin, int aPhiMax, unsigned int aRegion, unsigned int aRefLayer)
0017     : iInput(aInput), iRegion(aRegion), iRefLayer(aRefLayer), range(std::pair<int, int>(aPhiMin, aPhiMax)) {}
0018 ///////////////////////////////////////////////
0019 ///////////////////////////////////////////////
0020 bool RefHitDef::fitsRange(int iPhi) const { return iPhi >= range.first && iPhi <= range.second; }
0021 ///////////////////////////////////////////////
0022 ///////////////////////////////////////////////
0023 std::ostream &operator<<(std::ostream &out, const RefHitDef &aRefHitDef) {
0024   out << "iRefLayer: " << aRefHitDef.iRefLayer << " iInput: " << aRefHitDef.iInput << " iRegion: " << aRefHitDef.iRegion
0025       << " range: (" << aRefHitDef.range.first << ", " << aRefHitDef.range.second << std::endl;
0026 
0027   return out;
0028 }
0029 ///////////////////////////////////////////////
0030 ///////////////////////////////////////////////
0031 void OMTFConfiguration::initCounterMatrices() {
0032   ///Vector of all inputs
0033   std::vector<int> aLayer1D(nInputs(), 0);
0034 
0035   ///Vector of all layers
0036   vector2D aLayer2D;
0037   aLayer2D.assign(nLayers(), aLayer1D);
0038 
0039   ///Vector of all logic cones
0040   vector3D aLayer3D;
0041   aLayer3D.assign(nLogicRegions(), aLayer2D);
0042 
0043   ///Vector of all processors
0044   measurements4D.assign(nProcessors(), aLayer3D);
0045   measurements4Dref.assign(nProcessors(), aLayer3D);
0046 }
0047 ///////////////////////////////////////////////
0048 ///////////////////////////////////////////////
0049 void OMTFConfiguration::configure(const L1TMuonOverlapParams *omtfParams) {
0050   rawParams = *omtfParams;
0051 
0052   ///Set chamber sectors connections to logic processros.
0053   barrelMin.resize(nProcessors());
0054   endcap10DegMin.resize(nProcessors());
0055   endcap20DegMin.resize(nProcessors());
0056 
0057   barrelMax.resize(nProcessors());
0058   endcap10DegMax.resize(nProcessors());
0059   endcap20DegMax.resize(nProcessors());
0060 
0061   const std::vector<int> *connectedSectorsStartVec = omtfParams->connectedSectorsStart();
0062   const std::vector<int> *connectedSectorsEndVec = omtfParams->connectedSectorsEnd();
0063 
0064   std::copy(connectedSectorsStartVec->begin(), connectedSectorsStartVec->begin() + 6, barrelMin.begin());
0065   std::copy(connectedSectorsStartVec->begin() + 6, connectedSectorsStartVec->begin() + 12, endcap10DegMin.begin());
0066   std::copy(connectedSectorsStartVec->begin() + 12, connectedSectorsStartVec->end(), endcap20DegMin.begin());
0067 
0068   std::copy(connectedSectorsEndVec->begin(), connectedSectorsEndVec->begin() + 6, barrelMax.begin());
0069   std::copy(connectedSectorsEndVec->begin() + 6, connectedSectorsEndVec->begin() + 12, endcap10DegMax.begin());
0070   std::copy(connectedSectorsEndVec->begin() + 12, connectedSectorsEndVec->end(), endcap20DegMax.begin());
0071 
0072   ///Set connections tables
0073   const std::vector<L1TMuonOverlapParams::LayerMapNode> *layerMap = omtfParams->layerMap();
0074 
0075   for (unsigned int iLayer = 0; iLayer < nLayers(); ++iLayer) {
0076     L1TMuonOverlapParams::LayerMapNode aNode = layerMap->at(iLayer);
0077     hwToLogicLayer[aNode.hwNumber] = aNode.logicNumber;
0078     logicToHwLayer[aNode.logicNumber] = aNode.hwNumber;
0079     logicToLogic[aNode.logicNumber] = aNode.connectedToLayer;
0080     if (aNode.bendingLayer)
0081       bendingLayers.insert(aNode.logicNumber);
0082   }
0083   /////
0084   refToLogicNumber.resize(nRefLayers());
0085 
0086   const std::vector<L1TMuonOverlapParams::RefLayerMapNode> *refLayerMap = omtfParams->refLayerMap();
0087   for (unsigned int iRefLayer = 0; iRefLayer < nRefLayers(); ++iRefLayer) {
0088     L1TMuonOverlapParams::RefLayerMapNode aNode = refLayerMap->at(iRefLayer);
0089     refToLogicNumber[aNode.refLayer] = aNode.logicNumber;
0090   }
0091   /////
0092   std::vector<int> vector1D(nRefLayers(), nPhiBins());
0093   processorPhiVsRefLayer.assign(nProcessors(), vector1D);
0094 
0095   ///connections tables for each processor each logic cone
0096   ///Vector of all layers
0097   vector1D_pair aLayer1D(nLayers());
0098   ///Vector of all logic cones
0099   vector2D_pair aLayer2D;
0100   aLayer2D.assign(nLogicRegions(), aLayer1D);
0101   ///Vector of all processors
0102   connections.assign(nProcessors(), aLayer2D);
0103 
0104   ///Starting phis of each region
0105   ///Vector of all regions in one processor
0106   std::vector<std::pair<int, int> > aRefHit1D(nLogicRegions(), std::pair<int, int>(9999, 9999));
0107   ///Vector of all reflayers
0108   std::vector<std::vector<std::pair<int, int> > > aRefHit2D;
0109   aRefHit2D.assign(nRefLayers(), aRefHit1D);
0110   ///Vector of all inputs
0111   regionPhisVsRefLayerVsInput.assign(nInputs(), aRefHit2D);
0112 
0113   //Vector of ref hit definitions
0114   std::vector<RefHitDef> aRefHitsDefs(nRefHits());
0115   ///Vector of all processros
0116   refHitsDefs.assign(nProcessors(), aRefHitsDefs);
0117 
0118   const std::vector<int> *phiStartMap = omtfParams->globalPhiStartMap();
0119   const std::vector<L1TMuonOverlapParams::RefHitNode> *refHitMap = omtfParams->refHitMap();
0120   const std::vector<L1TMuonOverlapParams::LayerInputNode> *layerInputMap = omtfParams->layerInputMap();
0121   unsigned int tmpIndex = 0;
0122   for (unsigned int iProcessor = 0; iProcessor < nProcessors(); ++iProcessor) {
0123     for (unsigned int iRefLayer = 0; iRefLayer < nRefLayers(); ++iRefLayer) {
0124       int iPhiStart = phiStartMap->at(iRefLayer + iProcessor * nRefLayers());
0125       processorPhiVsRefLayer[iProcessor][iRefLayer] = iPhiStart;
0126     }
0127     for (unsigned int iRefHit = 0; iRefHit < nRefHits(); ++iRefHit) {
0128       int iPhiMin = refHitMap->at(iRefHit + iProcessor * nRefHits()).iPhiMin;
0129       int iPhiMax = refHitMap->at(iRefHit + iProcessor * nRefHits()).iPhiMax;
0130       unsigned int iInput = refHitMap->at(iRefHit + iProcessor * nRefHits()).iInput;
0131       unsigned int iRegion = refHitMap->at(iRefHit + iProcessor * nRefHits()).iRegion;
0132       unsigned int iRefLayer = refHitMap->at(iRefHit + iProcessor * nRefHits()).iRefLayer;
0133       regionPhisVsRefLayerVsInput[iInput][iRefLayer][iRegion] = std::pair<int, int>(iPhiMin, iPhiMax);
0134       refHitsDefs[iProcessor][iRefHit] = RefHitDef(iInput, iPhiMin, iPhiMax, iRegion, iRefLayer);
0135     }
0136     for (unsigned int iLogicRegion = 0; iLogicRegion < nLogicRegions(); ++iLogicRegion) {
0137       for (unsigned int iLayer = 0; iLayer < nLayers(); ++iLayer) {
0138         tmpIndex = iLayer + iLogicRegion * nLayers() + iProcessor * nLogicRegions() * nLayers();
0139         unsigned int iFirstInput = layerInputMap->at(tmpIndex).iFirstInput;
0140         unsigned int nInputsInRegion = layerInputMap->at(tmpIndex).nInputs;
0141         connections[iProcessor][iLogicRegion][iLayer] =
0142             std::pair<unsigned int, unsigned int>(iFirstInput, nInputsInRegion);
0143         ///Symetrize connections. Use th same connections for all processors
0144         if (iProcessor != 0)
0145           connections[iProcessor][iLogicRegion][iLayer] = connections[0][iLogicRegion][iLayer];
0146       }
0147     }
0148   }
0149 
0150   initCounterMatrices();
0151 }
0152 ///////////////////////////////////////////////
0153 ///////////////////////////////////////////////
0154 std::ostream &operator<<(std::ostream &out, const OMTFConfiguration &aConfig) {
0155   out << "nLayers(): " << aConfig.nLayers() << " nHitsPerLayer(): " << aConfig.nHitsPerLayer()
0156       << " nRefLayers(): " << aConfig.nRefLayers() << " nPdfAddrBits: " << aConfig.nPdfAddrBits()
0157       << " nPdfValBits: " << aConfig.nPdfValBits() << std::endl;
0158 
0159   for (unsigned int iProcessor = 0; iProcessor < aConfig.nProcessors(); ++iProcessor) {
0160     out << "Processor: " << iProcessor;
0161     for (unsigned int iRefLayer = 0; iRefLayer < aConfig.nRefLayers(); ++iRefLayer) {
0162       out << " " << aConfig.processorPhiVsRefLayer[iProcessor][iRefLayer];
0163     }
0164     out << std::endl;
0165   }
0166 
0167   return out;
0168 }
0169 ///////////////////////////////////////////////
0170 ///////////////////////////////////////////////
0171 bool OMTFConfiguration::isInRegionRange(int iPhiStart, unsigned int coneSize, int iPhi) const {
0172   if (iPhi < 0)
0173     iPhi += nPhiBins();
0174   if (iPhiStart < 0)
0175     iPhiStart += nPhiBins();
0176 
0177   if (iPhiStart + (int)coneSize < (int)nPhiBins()) {
0178     return iPhiStart <= iPhi && iPhiStart + (int)coneSize > iPhi;
0179   } else if (iPhi > (int)nPhiBins() / 2) {
0180     return iPhiStart <= iPhi;
0181   } else if (iPhi < (int)nPhiBins() / 2) {
0182     return iPhi < iPhiStart + (int)coneSize - (int)nPhiBins();
0183   }
0184   return false;
0185 }
0186 ///////////////////////////////////////////////
0187 ///////////////////////////////////////////////
0188 unsigned int OMTFConfiguration::getRegionNumberFromMap(unsigned int iInput, unsigned int iRefLayer, int iPhi) const {
0189   for (unsigned int iRegion = 0; iRegion < nLogicRegions(); ++iRegion) {
0190     if (iPhi >= regionPhisVsRefLayerVsInput[iInput][iRefLayer][iRegion].first &&
0191         iPhi <= regionPhisVsRefLayerVsInput[iInput][iRefLayer][iRegion].second)
0192       return iRegion;
0193   }
0194 
0195   return 99;
0196 }
0197 ///////////////////////////////////////////////
0198 ///////////////////////////////////////////////
0199 int OMTFConfiguration::globalPhiStart(unsigned int iProcessor) const {
0200   return *std::min_element(processorPhiVsRefLayer[iProcessor].begin(), processorPhiVsRefLayer[iProcessor].end());
0201 }
0202 ///////////////////////////////////////////////
0203 ///////////////////////////////////////////////
0204 uint32_t OMTFConfiguration::getLayerNumber(uint32_t rawId) const {
0205   uint32_t aLayer = 0;
0206 
0207   DetId detId(rawId);
0208   if (detId.det() != DetId::Muon) {
0209     std::cout << "PROBLEM: hit in unknown Det, detID: " << detId.det() << std::endl;
0210     return rawId;
0211   }
0212 
0213   switch (detId.subdetId()) {
0214     case MuonSubdetId::RPC: {
0215       RPCDetId aId(rawId);
0216       bool isBarrel = (aId.region() == 0);
0217       if (isBarrel)
0218         aLayer = aId.station() <= 2 ? 2 * (aId.station() - 1) + aId.layer() : aId.station() + 2;
0219       else
0220         aLayer = aId.station();
0221       aLayer += 10 * (!isBarrel);
0222       break;
0223     }
0224     case MuonSubdetId::DT: {
0225       DTChamberId dt(rawId);
0226       aLayer = dt.station();
0227       break;
0228     }
0229     case MuonSubdetId::CSC: {
0230       CSCDetId csc(rawId);
0231       aLayer = csc.station();
0232       if (csc.ring() == 2 && csc.station() == 1)
0233         aLayer = 1811;  //1811 = 2011 - 200, as we want to get 2011 for this chamber.
0234       if (csc.station() == 4)
0235         aLayer = 4;
0236       break;
0237     }
0238   }
0239 
0240   int hwNumber = aLayer + 100 * detId.subdetId();
0241 
0242   return hwNumber;
0243 }
0244 ///////////////////////////////////////////////
0245 ///////////////////////////////////////////////