File indexing completed on 2024-04-06 12:21:04
0001 #include <cassert>
0002 #include <iostream>
0003 #include <cmath>
0004
0005 #include "L1Trigger/L1TMuonOverlap/interface/OMTFinput.h"
0006 #include "L1Trigger/L1TMuonOverlap/interface/OMTFConfiguration.h"
0007 #include "L1Trigger/L1TMuonOverlap/interface/XMLConfigReader.h"
0008
0009
0010
0011 OMTFinput::OMTFinput(const OMTFConfiguration *omtfConfig) {
0012 myOmtfConfig = omtfConfig;
0013 clear();
0014 }
0015
0016
0017 const OMTFinput::vector1D &OMTFinput::getLayerData(unsigned int iLayer, bool giveEta) const {
0018 assert(iLayer < measurementsPhi.size());
0019
0020 if (giveEta)
0021 return measurementsEta[iLayer];
0022 return measurementsPhi[iLayer];
0023 }
0024
0025
0026 std::bitset<128> OMTFinput::getRefHits(unsigned int iProcessor) const {
0027 std::bitset<128> refHits;
0028
0029 unsigned int iRefHit = 0;
0030 for (auto iRefHitDef : myOmtfConfig->getRefHitsDefs()[iProcessor]) {
0031 int iPhi = getLayerData(myOmtfConfig->getRefToLogicNumber()[iRefHitDef.iRefLayer])[iRefHitDef.iInput];
0032 int iEta = getLayerData(myOmtfConfig->getRefToLogicNumber()[iRefHitDef.iRefLayer], true)[iRefHitDef.iInput];
0033 if (iPhi < (int)myOmtfConfig->nPhiBins()) {
0034 refHits.set(iRefHit, iRefHitDef.fitsRange(iPhi));
0035 refHitsEta[iRefHit] = iEta;
0036 }
0037 iRefHit++;
0038 }
0039
0040 return refHits;
0041 }
0042
0043
0044 bool OMTFinput::addLayerHit(unsigned int iLayer, unsigned int iInput, int iPhi, int iEta, bool allowOverwrite) {
0045 bool overwrite = false;
0046 assert(iLayer < myOmtfConfig->nLayers());
0047 assert(iInput < 14);
0048
0049 if (iPhi >= (int)myOmtfConfig->nPhiBins())
0050 return true;
0051
0052 if (allowOverwrite && measurementsPhi[iLayer][iInput] == iPhi && measurementsEta[iLayer][iInput] == iEta)
0053 return true;
0054
0055 if (measurementsPhi[iLayer][iInput] != (int)myOmtfConfig->nPhiBins())
0056 ++iInput;
0057 if (measurementsPhi[iLayer][iInput] != (int)myOmtfConfig->nPhiBins())
0058 overwrite = true;
0059
0060 if (iInput > 13)
0061 return true;
0062
0063 measurementsPhi[iLayer][iInput] = iPhi;
0064 measurementsEta[iLayer][iInput] = iEta;
0065
0066 return overwrite;
0067 }
0068
0069
0070 void OMTFinput::readData(XMLConfigReader *aReader, unsigned int iEvent, unsigned int iProcessor) {
0071 measurementsPhi = aReader->readEvent(iEvent, iProcessor);
0072 measurementsEta = aReader->readEvent(iEvent, iProcessor, true);
0073 }
0074
0075
0076 void OMTFinput::mergeData(const OMTFinput *aInput) {
0077 for (unsigned int iLayer = 0; iLayer < myOmtfConfig->nLayers(); ++iLayer) {
0078 const OMTFinput::vector1D &aPhiVec = aInput->getLayerData(iLayer, false);
0079 const OMTFinput::vector1D &aEtaVec = aInput->getLayerData(iLayer, true);
0080 if (aPhiVec.empty())
0081 continue;
0082
0083 OMTFinput::vector1D layerData = getLayerData(iLayer, false);
0084 for (unsigned int iInput = 0; iInput < 14; ++iInput) {
0085 addLayerHit(iLayer, iInput, aPhiVec[iInput], aEtaVec[iInput]);
0086 }
0087 }
0088 }
0089
0090
0091 void OMTFinput::clear() {
0092 vector1D aLayer1D(14, myOmtfConfig->nPhiBins());
0093 measurementsPhi.assign(myOmtfConfig->nLayers(), aLayer1D);
0094 measurementsEta.assign(myOmtfConfig->nLayers(), aLayer1D);
0095 refHitsEta.assign(128, myOmtfConfig->nPhiBins());
0096 }
0097
0098
0099 void OMTFinput::shiftMyPhi(int phiShift) {
0100 int lowScaleEnd = std::pow(2, myOmtfConfig->nPhiBits() - 1);
0101 int highScaleEnd = lowScaleEnd - 1;
0102
0103 for (unsigned int iLogicLayer = 0; iLogicLayer < measurementsPhi.size(); ++iLogicLayer) {
0104 for (unsigned int iHit = 0; iHit < measurementsPhi[iLogicLayer].size(); ++iHit) {
0105 if (!myOmtfConfig->getBendingLayers().count(iLogicLayer) &&
0106 measurementsPhi[iLogicLayer][iHit] < (int)myOmtfConfig->nPhiBins()) {
0107 if (measurementsPhi[iLogicLayer][iHit] < 0)
0108 measurementsPhi[iLogicLayer][iHit] += myOmtfConfig->nPhiBins();
0109 measurementsPhi[iLogicLayer][iHit] -= phiShift;
0110 if (measurementsPhi[iLogicLayer][iHit] < 0)
0111 measurementsPhi[iLogicLayer][iHit] += myOmtfConfig->nPhiBins();
0112 measurementsPhi[iLogicLayer][iHit] += -lowScaleEnd;
0113 if (measurementsPhi[iLogicLayer][iHit] < -lowScaleEnd || measurementsPhi[iLogicLayer][iHit] > highScaleEnd)
0114 measurementsPhi[iLogicLayer][iHit] = (int)myOmtfConfig->nPhiBins();
0115 }
0116 }
0117 }
0118 }
0119
0120
0121 std::ostream &operator<<(std::ostream &out, const OMTFinput &aInput) {
0122 for (unsigned int iLogicLayer = 0; iLogicLayer < aInput.measurementsPhi.size(); ++iLogicLayer) {
0123 out << "Logic layer: " << iLogicLayer << " Hits: ";
0124 for (unsigned int iHit = 0; iHit < aInput.measurementsPhi[iLogicLayer].size(); ++iHit) {
0125 out << aInput.measurementsPhi[iLogicLayer][iHit] << "\t";
0126 }
0127 out << std::endl;
0128 }
0129 return out;
0130 }
0131
0132