File indexing completed on 2024-04-06 12:21:08
0001
0002
0003
0004
0005
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
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
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
0079 continue;
0080 }
0081
0082 LogTrace("OMTFReconstruction") << "adding pattern " << aKey << " " << std::endl;
0083
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
0093
0094 int value = meanDistPhiLUT->data(address) - (1 << (meanDistPhiLUT->nrBitsData() - 1));
0095 aGP->setMeanDistPhiValue(value, iLayer, iRefLayer, 0);
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106 if (distPhiShiftLUT) {
0107 value = distPhiShiftLUT->data(address);
0108 aGP->setDistPhiBitShift(value, iLayer, iRefLayer);
0109 }
0110 }
0111
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);
0118 aGP->setPdfValue(value, iLayer, iRefLayer, iPdf);
0119
0120
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 if (input.getMuonStub(iLayer - 1, iInput) &&
0158 input.getMuonStub(iLayer - 1, iInput)->qualityHw >= myOmtfConfig->getMinDtPhiBQuality())
0159 layerStubs.push_back(input.getMuonStub(iLayer - 1, iInput));
0160 } else
0161 layerStubs.push_back(input.getMuonStub(iLayer, iInput));
0162 }
0163 }
0164
0165 return layerStubs;
0166 }
0167
0168
0169
0170 template <class GoldenPatternType>
0171 void ProcessorBase<GoldenPatternType>::initPatternPtRange(bool firstPatFrom0) {
0172 patternPts.clear();
0173
0174 bool firstPos = firstPatFrom0;
0175 bool firstNeg = firstPatFrom0;
0176 for (unsigned int iPat = 0; iPat < theGPs.size(); iPat++) {
0177 OMTFConfiguration::PatternPt patternPt;
0178 int charge = theGPs[iPat]->key().theCharge;
0179 if (theGPs[iPat] == nullptr || theGPs[iPat]->key().thePt == 0) {
0180 patternPts.push_back(patternPt);
0181 continue;
0182 }
0183
0184 patternPt.ptFrom = myOmtfConfig->hwPtToGev(theGPs[iPat]->key().thePt);
0185 if (firstPos && theGPs[iPat]->key().theCharge == 1) {
0186 patternPt.ptFrom = 0;
0187 firstPos = false;
0188 }
0189 if (firstNeg && theGPs[iPat]->key().theCharge == -1) {
0190 patternPt.ptFrom = 0;
0191 firstNeg = false;
0192 }
0193
0194 unsigned int iPat1 = iPat;
0195 while (true) {
0196 iPat1++;
0197 if (iPat1 == theGPs.size())
0198 break;
0199 if (theGPs[iPat1]->key().thePt != 0 && theGPs[iPat1]->key().theCharge == charge)
0200 break;
0201 }
0202
0203 if (iPat1 == theGPs.size())
0204 patternPt.ptTo = 10000;
0205 else
0206 patternPt.ptTo = myOmtfConfig->hwPtToGev(theGPs[iPat1]->key().thePt);
0207
0208 patternPt.charge = charge;
0209 patternPts.push_back(patternPt);
0210 }
0211
0212
0213
0214
0215
0216
0217 edm::LogTrace_("OMTFReconstruction") << __FUNCTION__ << ":" << __LINE__ << " patternPts.size() " << patternPts.size()
0218 << endl;
0219 }
0220
0221 template <class GoldenPatternType>
0222 void ProcessorBase<GoldenPatternType>::printInfo() const {
0223 myOmtfConfig->printConfig();
0224
0225 edm::LogVerbatim("OMTFReconstruction") << "\npatterns:" << std::endl;
0226 unsigned int patNum = 0;
0227 for (auto& gp : theGPs) {
0228 edm::LogVerbatim("OMTFReconstruction")
0229 << std::setw(2) << patNum << " " << gp->key() << " " << myOmtfConfig->getPatternPtRange(patNum).ptFrom << " - "
0230 << myOmtfConfig->getPatternPtRange(patNum).ptTo << " GeV" << std::endl;
0231 patNum++;
0232 }
0233
0234
0235
0236
0237 }
0238
0239
0240 template class ProcessorBase<GoldenPattern>;
0241 template class ProcessorBase<GoldenPatternWithThresh>;
0242 template class ProcessorBase<GoldenPatternWithStat>;