File indexing completed on 2024-04-06 12:21:58
0001 #include "L1Trigger/TrackFindingTracklet/interface/ChannelAssignment.h"
0002 #include "L1Trigger/TrackFindingTracklet/interface/Settings.h"
0003
0004 #include <vector>
0005 #include <array>
0006 #include <set>
0007 #include <algorithm>
0008 #include <numeric>
0009 #include <iterator>
0010
0011 using namespace std;
0012 using namespace edm;
0013 using namespace tt;
0014
0015 namespace trklet {
0016
0017 ChannelAssignment::ChannelAssignment(const edm::ParameterSet& iConfig, const Setup* setup)
0018 : setup_(setup),
0019 pSetDRin_(iConfig.getParameter<ParameterSet>("DRin")),
0020 widthLayerId_(pSetDRin_.getParameter<int>("WidthLayerId")),
0021 widthStubId_(pSetDRin_.getParameter<int>("WidthStubId")),
0022 widthSeedStubId_(pSetDRin_.getParameter<int>("WidthSeedStubId")),
0023 widthPSTilt_(pSetDRin_.getParameter<int>("WidthPSTilt")),
0024 depthMemory_(pSetDRin_.getParameter<int>("DepthMemory")),
0025 ptBoundaries_(pSetDRin_.getParameter<vector<double>>("PtBoundaries")),
0026 pSetDR_(iConfig.getParameter<ParameterSet>("DR")),
0027 numComparisonModules_(pSetDR_.getParameter<int>("NumComparisonModules")),
0028 minIdenticalStubs_(pSetDR_.getParameter<int>("MinIdenticalStubs")),
0029 numNodesDR_(2 * (ptBoundaries_.size() + 1)),
0030 seedTypeNames_(iConfig.getParameter<vector<string>>("SeedTypes")),
0031 numSeedTypes_(seedTypeNames_.size()),
0032 numChannelsTrack_(numSeedTypes_),
0033 channelEncoding_(iConfig.getParameter<vector<int>>("IRChannelsIn")) {
0034 const ParameterSet& pSetSeedTypesSeedLayers = iConfig.getParameter<ParameterSet>("SeedTypesSeedLayers");
0035 const ParameterSet& pSetSeedTypesProjectionLayers = iConfig.getParameter<ParameterSet>("SeedTypesProjectionLayers");
0036 seedTypesSeedLayers_.reserve(numSeedTypes_);
0037 seedTypesProjectionLayers_.reserve(numSeedTypes_);
0038 for (const string& s : seedTypeNames_) {
0039 seedTypesSeedLayers_.emplace_back(pSetSeedTypesSeedLayers.getParameter<vector<int>>(s));
0040 seedTypesProjectionLayers_.emplace_back(pSetSeedTypesProjectionLayers.getParameter<vector<int>>(s));
0041 }
0042
0043 const int offsetBarrel = setup_->offsetLayerId();
0044 const int numBarrelLayer = setup_->numBarrelLayer();
0045 const int offsetDisk = setup_->offsetLayerDisks() + offsetBarrel;
0046 static constexpr int invalidSeedLayer = -1;
0047 static constexpr int invalidLayerDisk = 0;
0048 const Settings settings;
0049 const auto& seedlayers = settings.seedlayers();
0050 const auto& projlayers = settings.projlayers();
0051 const auto& projdisks = settings.projdisks();
0052
0053 vector<set<int>> allSeedingLayer(seedlayers.size());
0054 vector<set<int>> allProjectionLayer(seedlayers.size());
0055 for (int iSeed = 0; iSeed < (int)seedlayers.size(); iSeed++)
0056 for (const auto& layer : seedlayers[iSeed])
0057 if (layer != invalidSeedLayer)
0058 allSeedingLayer[iSeed].insert(layer < numBarrelLayer ? layer + offsetBarrel
0059 : layer + offsetDisk - numBarrelLayer);
0060 for (int iSeed = 0; iSeed < (int)projlayers.size(); iSeed++)
0061 for (const auto& layer : projlayers[iSeed])
0062 if (layer != invalidLayerDisk)
0063 allProjectionLayer[iSeed].insert(layer);
0064 for (int iSeed = 0; iSeed < (int)projdisks.size(); iSeed++)
0065 for (const auto& disk : projdisks[iSeed])
0066 if (disk != invalidLayerDisk)
0067 allProjectionLayer[iSeed].insert(disk - offsetBarrel + offsetDisk);
0068
0069 for (int iSubSeed = 0; iSubSeed < numSeedTypes_; iSubSeed++) {
0070 const vector<int>& seedLayers = seedTypesSeedLayers_[iSubSeed];
0071 bool subset(false);
0072 for (int iAllSeed = 0; iAllSeed < (int)seedlayers.size(); iAllSeed++) {
0073
0074 const set<int>& asl = allSeedingLayer[iAllSeed];
0075 set<int> sl(seedLayers.begin(), seedLayers.end());
0076 set<int> intersect;
0077 set_intersection(sl.begin(), sl.end(), asl.begin(), asl.end(), inserter(intersect, intersect.begin()));
0078 if (intersect == sl) {
0079 subset = true;
0080
0081 const vector<int>& projectionLayers = seedTypesProjectionLayers_[iSubSeed];
0082 const set<int>& apl = allProjectionLayer[iAllSeed];
0083 set<int> pl(projectionLayers.begin(), projectionLayers.end());
0084 set<int> intersect;
0085 set_intersection(pl.begin(), pl.end(), apl.begin(), apl.end(), inserter(intersect, intersect.begin()));
0086 if (intersect == pl)
0087 break;
0088 set<int> difference;
0089 set_difference(
0090 pl.begin(), pl.end(), intersect.begin(), intersect.end(), inserter(difference, difference.begin()));
0091 cms::Exception exception("LogicError.");
0092 exception << "ProjectionLayers ( ";
0093 for (int layer : difference)
0094 exception << layer << " ";
0095 exception << ") are not supported with seed type ( ";
0096 for (int layer : seedLayers)
0097 exception << layer << " ";
0098 exception << ")";
0099 exception.addContext("trklet::ChannelAssignment::ChannelAssignment");
0100 throw exception;
0101 }
0102 }
0103 if (subset)
0104 continue;
0105 cms::Exception exception("LogicError.");
0106 exception << "SeedLayers ( ";
0107 for (int layer : seedLayers)
0108 exception << layer << " ";
0109 exception << ") are not supported";
0110 exception.addContext("trklet::ChannelAssignment::ChannelAssignment");
0111 throw exception;
0112 }
0113 auto bigger = [](const vector<int>& lhs, const vector<int>& rhs) { return lhs.size() < rhs.size(); };
0114 numSeedingLayers_ = max_element(seedTypesSeedLayers_.begin(), seedTypesSeedLayers_.end(), bigger)->size();
0115 maxNumProjectionLayers_ =
0116 max_element(seedTypesProjectionLayers_.begin(), seedTypesProjectionLayers_.end(), bigger)->size();
0117 auto acc = [](int sum, vector<int> ints) { return sum += (int)ints.size(); };
0118 offsetsStubs_.reserve(numSeedTypes_);
0119 numChannelsStub_ = accumulate(
0120 seedTypesProjectionLayers_.begin(), seedTypesProjectionLayers_.end(), numSeedingLayers_ * numSeedTypes_, acc);
0121 for (int seed = 0; seed < numSeedTypes_; seed++) {
0122 const auto it = next(seedTypesProjectionLayers_.begin(), seed);
0123 offsetsStubs_.emplace_back(accumulate(seedTypesProjectionLayers_.begin(), it, numSeedingLayers_ * seed, acc));
0124 }
0125 }
0126
0127
0128 int ChannelAssignment::channelId(const TTTrackRef& ttTrackRef) const {
0129 const int seedType = ttTrackRef->trackSeedType();
0130 if (seedType >= numSeedTypes_) {
0131 cms::Exception exception("logic_error");
0132 exception << "TTTracks form seed type" << seedType << " not in supported list: (";
0133 for (const auto& s : seedTypeNames_)
0134 exception << s << " ";
0135 exception << ").";
0136 exception.addContext("trklet:ChannelAssignment:channelId");
0137 throw exception;
0138 }
0139 return ttTrackRef->phiSector() * numSeedTypes_ + seedType;
0140 }
0141
0142
0143 bool ChannelAssignment::layerId(int seedType, const TTStubRef& ttStubRef, int& layerId) const {
0144 layerId = -1;
0145 if (seedType < 0 || seedType >= numSeedTypes_) {
0146 cms::Exception exception("logic_error");
0147 exception.addContext("trklet::ChannelAssignment::layerId");
0148 exception << "TTTracks with with seed type " << seedType << " not supported.";
0149 throw exception;
0150 }
0151 const int layer = setup_->layerId(ttStubRef);
0152 const vector<int>& seedingLayers = seedTypesSeedLayers_[seedType];
0153 if (find(seedingLayers.begin(), seedingLayers.end(), layer) != seedingLayers.end())
0154 return false;
0155 const vector<int>& projectingLayers = seedTypesProjectionLayers_[seedType];
0156 const auto pos = find(projectingLayers.begin(), projectingLayers.end(), layer);
0157 if (pos == projectingLayers.end()) {
0158 const string& name = seedTypeNames_[seedType];
0159 cms::Exception exception("logic_error");
0160 exception.addContext("trklet::ChannelAssignment::layerId");
0161 exception << "TTStub from layer " << layer << " (barrel: 1-6; discs: 11-15) from seed type " << name
0162 << " not supported.";
0163 throw exception;
0164 }
0165 layerId = distance(projectingLayers.begin(), pos);
0166 return true;
0167 }
0168
0169
0170 int ChannelAssignment::offsetStub(int channelTrack) const {
0171 const int region = channelTrack / numChannelsTrack_;
0172 const int channel = channelTrack % numChannelsTrack_;
0173 return region * numChannelsStub_ + offsetsStubs_[channel];
0174 }
0175
0176
0177 int ChannelAssignment::channelId(int seedType, int layerId) const {
0178 const vector<int>& projections = seedTypesProjectionLayers_.at(seedType);
0179 const auto itp = find(projections.begin(), projections.end(), layerId);
0180 if (itp != projections.end())
0181 return distance(projections.begin(), itp);
0182 const vector<int>& seeds = seedTypesSeedLayers_.at(seedType);
0183 const auto its = find(seeds.begin(), seeds.end(), layerId);
0184 if (its != seeds.end())
0185 return (int)projections.size() + distance(seeds.begin(), its);
0186 return -1;
0187 }
0188
0189
0190 int ChannelAssignment::nodeDR(const TTTrackRef& ttTrackRef) const {
0191 const double pt = ttTrackRef->momentum().perp();
0192 int bin(0);
0193 for (double b : ptBoundaries_) {
0194 if (pt < b)
0195 break;
0196 bin++;
0197 }
0198 if (ttTrackRef->rInv() >= 0.)
0199 bin += numNodesDR_ / 2;
0200 else
0201 bin = numNodesDR_ / 2 - 1 - bin;
0202 return bin;
0203 }
0204
0205
0206 int ChannelAssignment::layerId(int seedType, int channel) const {
0207 if (channel < numProjectionLayers(seedType))
0208 return seedTypesProjectionLayers_.at(seedType).at(channel);
0209 return seedTypesSeedLayers_.at(seedType).at(channel - numProjectionLayers(seedType));
0210 }
0211
0212 }