File indexing completed on 2024-04-06 12:21:52
0001 #include "FWCore/Utilities/interface/Exception.h"
0002
0003 #include "L1Trigger/TrackFindingTMTT/interface/TrkRZfilter.h"
0004 #include "L1Trigger/TrackFindingTMTT/interface/Settings.h"
0005 #include "L1Trigger/TrackFindingTMTT/interface/Stub.h"
0006 #include "L1Trigger/TrackFindingTMTT/interface/PrintL1trk.h"
0007
0008 #include <array>
0009
0010 using namespace std;
0011
0012 namespace tmtt {
0013
0014
0015
0016 TrkRZfilter::TrkRZfilter(const Settings* settings,
0017 unsigned int iPhiSec,
0018 unsigned int iEtaReg,
0019 float etaMinSector,
0020 float etaMaxSector,
0021 float phiCentreSector)
0022 :
0023 settings_(settings),
0024
0025 iPhiSec_(iPhiSec),
0026 iEtaReg_(iEtaReg) {
0027
0028 etaMinSector_ = etaMinSector;
0029 etaMaxSector_ = etaMaxSector;
0030 phiCentreSector_ = phiCentreSector;
0031
0032
0033 rzHelix_set_ = false;
0034
0035
0036 chosenRofZ_ = settings->chosenRofZ();
0037 zTrkMinSector_ = chosenRofZ_ / tan(2. * atan(exp(-etaMinSector_)));
0038 zTrkMaxSector_ = chosenRofZ_ / tan(2. * atan(exp(-etaMaxSector_)));
0039 unsigned int zbits = settings->zBits();
0040 unsigned int rtbits = settings_->rtBits();
0041 float zrange = settings_->zRange();
0042 float rtRange = settings_->rtRange();
0043 float zMultiplier = pow(2., zbits) / zrange;
0044 float rMultiplier = pow(2., rtbits) / rtRange;
0045
0046 if (settings_->enableDigitize()) {
0047 zTrkMinSector_ = floor(zTrkMinSector_ * zMultiplier) / zMultiplier;
0048 zTrkMaxSector_ = floor(zTrkMaxSector_ * zMultiplier) / zMultiplier;
0049 chosenRofZ_ = floor(chosenRofZ_ * rMultiplier) / rMultiplier;
0050 }
0051
0052
0053 beamWindowZ_ = settings->beamWindowZ();
0054
0055
0056 rzFilterName_ = settings->rzFilterName();
0057
0058
0059
0060 keepAllSeed_ = settings->keepAllSeed();
0061
0062 seedResCut_ = settings->seedResCut();
0063
0064 maxSeedCombinations_ = settings->maxSeedCombinations();
0065
0066 maxGoodSeedCombinations_ = settings->maxGoodSeedCombinations();
0067
0068 maxSeedsPerStub_ = settings->maxSeedsPerStub();
0069
0070 zTrkSectorCheck_ = settings->zTrkSectorCheck();
0071
0072
0073 minNumMatchLayers_ = settings->minNumMatchLayers();
0074 }
0075
0076
0077
0078
0079
0080 list<L1track3D> TrkRZfilter::filterTracks(const list<L1track2D>& tracks) {
0081 list<L1track3D> filteredTracks;
0082
0083 for (const L1track2D& trkIN : tracks) {
0084 const vector<Stub*>& stubs = trkIN.stubs();
0085
0086
0087 bool trackAccepted = true;
0088
0089
0090 rzHelix_set_ = false;
0091
0092
0093 if (settings_->enableDigitize()) {
0094 for (Stub* s : stubs) {
0095 s->digitize(iPhiSec_, Stub::DigiStage::SF);
0096 }
0097 }
0098
0099
0100
0101
0102 bool print = false;
0103
0104 vector<Stub*> filteredStubs = stubs;
0105 if (rzFilterName_ == "SeedFilter") {
0106 filteredStubs = this->seedFilter(filteredStubs, trkIN.qOverPt(), print);
0107 } else {
0108 throw cms::Exception("BadConfig") << "TrkRzFilter: ERROR unknown r-z track filter requested: " << rzFilterName_;
0109 }
0110
0111
0112
0113 unsigned int numLayersAfterFilters = Utility::countLayers(settings_, filteredStubs);
0114 if (numLayersAfterFilters < settings_->minFilterLayers())
0115 trackAccepted = false;
0116
0117
0118 if (trackAccepted) {
0119
0120 if (!rzHelix_set_)
0121 this->estRZhelix();
0122
0123 pair<float, float> helixRZ(rzHelix_z0_, rzHelix_tanL_);
0124
0125
0126 filteredTracks.emplace_back(settings_,
0127 filteredStubs,
0128 trkIN.cellLocationHT(),
0129 trkIN.helix2D(),
0130 helixRZ,
0131 trkIN.iPhiSec(),
0132 trkIN.iEtaReg(),
0133 trkIN.optoLinkID(),
0134 trkIN.mergedHTcell());
0135 }
0136 }
0137
0138 return filteredTracks;
0139 }
0140
0141
0142
0143
0144 vector<Stub*> TrkRZfilter::seedFilter(const std::vector<Stub*>& stubs, float trkQoverPt, bool print) {
0145 unsigned int numLayers;
0146 std::vector<Stub*> filtStubs = stubs;
0147 bool FirstSeed = true;
0148
0149 constexpr std::array<unsigned int, 8> FirstSeedLayers = {{1, 2, 11, 21, 3, 12, 22, 4}};
0150 constexpr std::array<unsigned int, 10> SecondSeedLayers = {{1, 2, 11, 3, 21, 22, 12, 23, 13, 4}};
0151 set<Stub*> uniqueFilteredStubs;
0152
0153 unsigned int numSeedCombinations = 0;
0154 unsigned int numGoodSeedCombinations = 0;
0155 vector<Stub*> filteredStubs;
0156
0157 unsigned int oldNumLay = 0;
0158
0159 auto orderByLayer = [](const Stub* a, const Stub* b) { return bool(a->layerId() < b->layerId()); };
0160 std::sort(filtStubs.begin(), filtStubs.end(), orderByLayer);
0161
0162
0163 for (Stub* s0 : filtStubs) {
0164
0165 if (s0->psModule() && std::find(std::begin(FirstSeedLayers), std::end(FirstSeedLayers), s0->layerId()) !=
0166 std::end(FirstSeedLayers)) {
0167 unsigned int numSeedsPerStub = 0;
0168
0169 for (Stub* s1 : filtStubs) {
0170 if (numGoodSeedCombinations < maxGoodSeedCombinations_ && numSeedCombinations < maxSeedCombinations_ &&
0171 numSeedsPerStub < maxSeedsPerStub_) {
0172
0173 if (s1->psModule() && s1->layerId() > s0->layerId() &&
0174 std::find(std::begin(SecondSeedLayers), std::end(SecondSeedLayers), s1->layerId()) !=
0175 std::end(SecondSeedLayers)) {
0176 numSeedsPerStub++;
0177 numSeedCombinations++;
0178 if (print)
0179 PrintL1trk() << "s0: "
0180 << "z: " << s0->z() << ", r: " << s0->r() << ", id:" << s0->layerId() << " ****** s1: "
0181 << "z: " << s1->z() << ", r: " << s1->r() << ", id:" << s1->layerId();
0182
0183
0184 vector<Stub*> tempStubs;
0185 tempStubs.push_back(s0);
0186 tempStubs.push_back(s1);
0187
0188
0189 double z0 = s1->z() + (-s1->z() + s0->z()) * s1->r() / (s1->r() - s0->r());
0190
0191
0192
0193 float zTrk = s1->z() + (-s1->z() + s0->z()) * (s1->r() - chosenRofZ_) / (s1->r() - s0->r());
0194
0195 float leftZtrk = zTrk * std::abs(s1->r() - s0->r());
0196 float rightZmin = zTrkMinSector_ * std::abs(s1->r() - s0->r());
0197 float rightZmax = zTrkMaxSector_ * std::abs(s1->r() - s0->r());
0198
0199
0200
0201 if (std::abs(z0) <= beamWindowZ_) {
0202
0203
0204 if ((!zTrkSectorCheck_) || (leftZtrk > rightZmin && leftZtrk < rightZmax)) {
0205 numGoodSeedCombinations++;
0206 unsigned int LiD = 0;
0207
0208
0209
0210 for (Stub* s : filtStubs) {
0211
0212
0213 double seedDist =
0214 (s->z() - s1->z()) * (s1->r() - s0->r()) - (s->r() - s1->r()) * (s1->z() - s0->z());
0215 double seedDistRes = (s->sigmaZ() + s1->sigmaZ()) * std::abs(s1->r() - s0->r()) +
0216 (s->sigmaR() + s1->sigmaR()) * std::abs(s1->z() - s0->z()) +
0217 (s0->sigmaZ() + s1->sigmaZ()) * std::abs(s->r() - s1->r()) +
0218 (s0->sigmaR() + s1->sigmaR()) * std::abs(s->z() - s1->z());
0219 seedDistRes *= seedResCut_;
0220
0221 if (std::abs(seedDist) <= seedDistRes) {
0222 if (s->layerId() != LiD and s->layerId() != s0->layerId() and s->layerId() != s1->layerId()) {
0223 tempStubs.push_back(s);
0224 LiD = s->layerId();
0225 }
0226 }
0227 }
0228 }
0229 }
0230
0231 numLayers = Utility::countLayers(
0232 settings_, tempStubs);
0233
0234
0235 if (keepAllSeed_ == false) {
0236 if (numLayers > oldNumLay) {
0237
0238
0239 filteredStubs =
0240 tempStubs;
0241
0242 oldNumLay = numLayers;
0243 rzHelix_z0_ = z0;
0244 rzHelix_tanL_ = (s1->z() - s0->z()) / (s1->r() - s0->r());
0245 rzHelix_set_ = true;
0246 }
0247
0248 } else {
0249
0250 if (numLayers >= Utility::numLayerCut(
0251 Utility::AlgoStep::SEED, settings_, iPhiSec_, iEtaReg_, std::abs(trkQoverPt))) {
0252 uniqueFilteredStubs.insert(tempStubs.begin(), tempStubs.end());
0253
0254
0255 if (FirstSeed) {
0256 FirstSeed = false;
0257 rzHelix_z0_ = z0;
0258 rzHelix_tanL_ = (s1->z() - s0->z()) / (s1->r() - s0->r());
0259 rzHelix_set_ = true;
0260 }
0261 }
0262 }
0263 }
0264 }
0265 }
0266 }
0267 }
0268
0269
0270 if (keepAllSeed_ == true) {
0271 for (Stub* stub : uniqueFilteredStubs) {
0272 filteredStubs.push_back(stub);
0273 }
0274 }
0275
0276
0277 numSeedCombsPerTrk_.push_back(numSeedCombinations);
0278 numGoodSeedCombsPerTrk_.push_back(numGoodSeedCombinations);
0279
0280 return filteredStubs;
0281 }
0282
0283
0284
0285 void TrkRZfilter::estRZhelix() {
0286 rzHelix_z0_ = 0.;
0287 rzHelix_tanL_ = 0.5 * (1 / tan(2 * atan(exp(-etaMinSector_))) + 1 / tan(2 * atan(exp(-etaMaxSector_))));
0288 rzHelix_set_ = true;
0289 }
0290
0291 }