File indexing completed on 2024-04-06 12:20:52
0001 #include "L1Trigger/L1TMuonBarrel/interface/L1TMuonBarrelKalmanRegionModule.h"
0002
0003 L1TMuonBarrelKalmanRegionModule::L1TMuonBarrelKalmanRegionModule(const edm::ParameterSet& iConfig,
0004 int wheel,
0005 int sector)
0006 : verbose_(iConfig.getParameter<int>("verbose")), sector_(sector), wheel_(wheel) {
0007 if (sector == 11) {
0008 nextSector_ = 0;
0009 previousSector_ = 10;
0010 } else if (sector == 0) {
0011 nextSector_ = 1;
0012 previousSector_ = 11;
0013 } else {
0014 nextSector_ = sector + 1;
0015 previousSector_ = sector - 1;
0016 }
0017
0018 switch (wheel) {
0019 case -2:
0020 nextWheel_ = -1;
0021 break;
0022
0023 case -1:
0024 nextWheel_ = 0;
0025 break;
0026
0027 case 0:
0028 nextWheel_ = 999;
0029 break;
0030
0031 case 1:
0032 nextWheel_ = 0;
0033 break;
0034
0035 case 2:
0036 nextWheel_ = 1;
0037 break;
0038
0039 default:
0040 nextWheel_ = 999;
0041 break;
0042 }
0043 }
0044
0045 L1TMuonBarrelKalmanRegionModule::~L1TMuonBarrelKalmanRegionModule() {}
0046
0047 L1MuKBMTrackCollection L1TMuonBarrelKalmanRegionModule::process(L1TMuonBarrelKalmanAlgo* trackMaker,
0048 const L1MuKBMTCombinedStubRefVector& stubsAll,
0049 int bx) {
0050 L1MuKBMTCombinedStubRefVector stubs;
0051 L1MuKBMTCombinedStubRefVector seeds;
0052 L1MuKBMTrackCollection pretracks2;
0053 L1MuKBMTrackCollection pretracks3;
0054 L1MuKBMTrackCollection pretracks4;
0055 for (const auto& stub : stubsAll) {
0056 if (stub->bxNum() != bx)
0057 continue;
0058
0059 if ((stub->scNum() == nextSector_ && stub->phi() >= -112) ||
0060 (stub->scNum() == previousSector_ && stub->phi() <= 111))
0061 continue;
0062
0063 if (stub->whNum() == wheel_ && stub->scNum() == sector_) {
0064 seeds.push_back(stub);
0065 stubs.push_back(stub);
0066 } else if (stub->whNum() == wheel_ && (stub->scNum() == nextSector_ || stub->scNum() == previousSector_)) {
0067 stubs.push_back(stub);
0068 } else if (stub->whNum() == nextWheel_ &&
0069 (stub->scNum() == nextSector_ || stub->scNum() == previousSector_ || stub->scNum() == sector_)) {
0070 stubs.push_back(stub);
0071 }
0072 }
0073
0074
0075
0076 SeedSorter sorter;
0077 if (seeds.size() > 1) {
0078 std::sort(seeds.begin(), seeds.end(), sorter);
0079 }
0080
0081 for (const auto& seed : seeds) {
0082 std::pair<bool, L1MuKBMTrack> trackInfo = trackMaker->chain(seed, stubs);
0083
0084
0085 L1MuKBMTrack nullTrack(seed, seed->phi(), 8 * seed->phiB());
0086 nullTrack.setPtEtaPhi(0, 0, 0);
0087 nullTrack.setRank(0);
0088 if (trackInfo.first) {
0089 if (seed->stNum() == 2)
0090 pretracks2.push_back(trackInfo.second);
0091 if (seed->stNum() == 3)
0092 pretracks3.push_back(trackInfo.second);
0093 if (seed->stNum() == 4)
0094 pretracks4.push_back(trackInfo.second);
0095 } else {
0096 if (seed->stNum() == 2)
0097 pretracks2.push_back(nullTrack);
0098 if (seed->stNum() == 3)
0099 pretracks3.push_back(nullTrack);
0100 if (seed->stNum() == 4)
0101 pretracks4.push_back(nullTrack);
0102 }
0103 }
0104 L1MuKBMTrack nullTrack;
0105 nullTrack.setPtEtaPhi(0, 0, 0);
0106 nullTrack.setRank(0);
0107
0108
0109 if (pretracks2.size() < 2) {
0110 if (pretracks2.empty()) {
0111 pretracks2.push_back(nullTrack);
0112 pretracks2.push_back(nullTrack);
0113 } else {
0114 if (pretracks2[0].stubs()[0]->tag() == 0)
0115 pretracks2.push_back(nullTrack);
0116 else
0117 pretracks2.insert(pretracks2.begin(), nullTrack);
0118 }
0119 }
0120 std::swap(pretracks2[0], pretracks2[1]);
0121
0122 if (pretracks3.size() < 2) {
0123 if (pretracks3.empty()) {
0124 pretracks3.push_back(nullTrack);
0125 pretracks3.push_back(nullTrack);
0126 } else {
0127 if (pretracks3[0].stubs()[0]->tag() == 0)
0128 pretracks3.push_back(nullTrack);
0129 else
0130 pretracks3.insert(pretracks3.begin(), nullTrack);
0131 }
0132 }
0133 std::swap(pretracks3[0], pretracks3[1]);
0134
0135 if (pretracks4.size() < 2) {
0136 if (pretracks4.empty()) {
0137 pretracks4.push_back(nullTrack);
0138 pretracks4.push_back(nullTrack);
0139 } else {
0140 if (pretracks4[0].stubs()[0]->tag() == 0)
0141 pretracks4.push_back(nullTrack);
0142 else
0143 pretracks4.insert(pretracks4.begin(), nullTrack);
0144 }
0145 }
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162 L1MuKBMTrackCollection out = cleanRegion(pretracks2, pretracks3, pretracks4);
0163 if (verbose_) {
0164 printf(" -----Sector Processor Kalman Tracks-----\n");
0165 for (const auto& track1 : out)
0166 printf("Kalman Track charge=%d pt=%f eta=%f phi=%f curvature=%d curvature STA =%d stubs=%d chi2=%d pts=%f %f\n",
0167 track1.charge(),
0168 track1.pt(),
0169 track1.eta(),
0170 track1.phi(),
0171 track1.curvatureAtVertex(),
0172 track1.curvatureAtMuon(),
0173 int(track1.stubs().size()),
0174 track1.approxChi2(),
0175 track1.pt(),
0176 track1.ptUnconstrained());
0177 }
0178
0179 return out;
0180 }
0181
0182 L1MuKBMTrackCollection L1TMuonBarrelKalmanRegionModule::selfClean(const L1MuKBMTrackCollection& tracks) {
0183 L1MuKBMTrackCollection out;
0184
0185 for (uint i = 0; i < tracks.size(); ++i) {
0186
0187 L1MuKBMTrack temp = tracks[i];
0188 for (uint j = 0; j < tracks.size(); ++j) {
0189 if (i == j)
0190 continue;
0191
0192 if (tracks[i].overlapTrack(tracks[j])) {
0193 if (tracks[i].rank() < tracks[j].rank()) {
0194
0195 temp.setPtEtaPhi(0, 0, 0);
0196 temp.setRank(0);
0197 } else if (tracks[i].rank() == tracks[j].rank()) {
0198 if (!tracks[j].stubs()[0]->tag()) {
0199
0200 temp.setPtEtaPhi(0, 0, 0);
0201 temp.setRank(0);
0202 }
0203 }
0204 }
0205 }
0206 out.push_back(temp);
0207
0208
0209 }
0210
0211 return out;
0212 }
0213
0214 L1MuKBMTrackCollection L1TMuonBarrelKalmanRegionModule::cleanHigher(const L1MuKBMTrackCollection& tracks1,
0215 const L1MuKBMTrackCollection& tracks2) {
0216 L1MuKBMTrackCollection out;
0217
0218 for (uint i = 0; i < tracks1.size(); ++i) {
0219
0220 L1MuKBMTrack temp = tracks1[i];
0221 for (uint j = 0; j < tracks2.size(); ++j) {
0222 if (tracks1[i].overlapTrack(tracks2[j])) {
0223 if (tracks1[i].rank() <= tracks2[j].rank()) {
0224
0225 temp.setPtEtaPhi(0, 0, 0);
0226 temp.setRank(0);
0227 }
0228 }
0229 }
0230 out.push_back(temp);
0231
0232
0233 }
0234
0235 return out;
0236 }
0237
0238 L1MuKBMTrackCollection L1TMuonBarrelKalmanRegionModule::cleanLower(const L1MuKBMTrackCollection& tracks1,
0239 const L1MuKBMTrackCollection& tracks2) {
0240 L1MuKBMTrackCollection out;
0241
0242 for (uint i = 0; i < tracks1.size(); ++i) {
0243
0244 L1MuKBMTrack temp = tracks1[i];
0245 for (uint j = 0; j < tracks2.size(); ++j) {
0246 if (tracks1[i].overlapTrack(tracks2[j])) {
0247 if (tracks1[i].rank() < tracks2[j].rank()) {
0248
0249 temp.setPtEtaPhi(0, 0, 0);
0250 temp.setRank(0);
0251 }
0252 }
0253 }
0254 out.push_back(temp);
0255
0256
0257 }
0258
0259 return out;
0260 }
0261
0262 L1MuKBMTrackCollection L1TMuonBarrelKalmanRegionModule::sort4(const L1MuKBMTrackCollection& in) {
0263 L1MuKBMTrackCollection out;
0264
0265
0266 if (in.size() <= 2)
0267 return in;
0268 else if (in.size() == 3) {
0269
0270 L1MuKBMTrack s2_1;
0271 L1MuKBMTrack s2_3;
0272 if (in[2].pt() >= in[0].pt()) {
0273 s2_1 = in[2];
0274 s2_3 = in[0];
0275 } else {
0276 s2_1 = in[0];
0277 s2_3 = in[2];
0278 }
0279
0280 const L1MuKBMTrack& s2_2 = in[1];
0281
0282 L1MuKBMTrack s3_1 = s2_1;
0283 L1MuKBMTrack s3_2;
0284 L1MuKBMTrack s3_3;
0285
0286 if (s2_3.pt() >= s2_2.pt()) {
0287 s3_2 = s2_3;
0288 s3_3 = s2_2;
0289 } else {
0290 s3_2 = s2_2;
0291 s3_3 = s2_3;
0292 }
0293
0294 out.push_back(s3_1);
0295 out.push_back(s3_2);
0296
0297 } else {
0298
0299 L1MuKBMTrack s2_1;
0300 L1MuKBMTrack s2_2;
0301 L1MuKBMTrack s2_3;
0302 L1MuKBMTrack s2_4;
0303
0304 if (in[2].pt() >= in[0].pt()) {
0305 s2_1 = in[2];
0306 s2_3 = in[0];
0307 } else {
0308 s2_1 = in[0];
0309 s2_3 = in[2];
0310 }
0311 if (in[3].pt() >= in[1].pt()) {
0312 s2_2 = in[3];
0313 s2_4 = in[1];
0314 } else {
0315 s2_2 = in[1];
0316 s2_4 = in[3];
0317 }
0318
0319 L1MuKBMTrack s3_1;
0320 L1MuKBMTrack s3_2;
0321 L1MuKBMTrack s3_3;
0322 L1MuKBMTrack s3_4;
0323
0324 if (s2_4.pt() >= s2_1.pt()) {
0325 s3_1 = s2_4;
0326 s3_4 = s2_1;
0327 } else {
0328 s3_1 = s2_1;
0329 s3_4 = s2_4;
0330 }
0331
0332 if (s2_3.pt() >= s2_2.pt()) {
0333 s3_2 = s2_3;
0334 s3_3 = s2_2;
0335 } else {
0336 s3_2 = s2_2;
0337 s3_3 = s2_3;
0338 }
0339
0340 out.push_back(s3_1);
0341 out.push_back(s3_2);
0342 }
0343 return out;
0344 }
0345
0346 L1MuKBMTrackCollection L1TMuonBarrelKalmanRegionModule::cleanRegion(const L1MuKBMTrackCollection& tracks2,
0347 const L1MuKBMTrackCollection& tracks3,
0348 const L1MuKBMTrackCollection& tracks4) {
0349 L1MuKBMTrackCollection cleaned2 = selfClean(tracks2);
0350 L1MuKBMTrackCollection cleaned3 = selfClean(tracks3);
0351
0352 L1MuKBMTrackCollection cleaned23 = cleanHigher(cleaned2, tracks3);
0353 L1MuKBMTrackCollection cleaned32 = cleanLower(cleaned3, tracks2);
0354
0355
0356 L1MuKBMTrackCollection step1;
0357 if (!cleaned23.empty())
0358 step1.insert(step1.end(), cleaned23.begin(), cleaned23.end());
0359 if (!cleaned32.empty())
0360 step1.insert(step1.end(), cleaned32.begin(), cleaned32.end());
0361
0362
0363 L1MuKBMTrackCollection sorted23 = sort4(step1);
0364
0365
0366 L1MuKBMTrackCollection cleaned4 = selfClean(tracks4);
0367
0368
0369 L1MuKBMTrackCollection cleanedSorted23 = cleanHigher(sorted23, tracks4);
0370
0371
0372 L1MuKBMTrackCollection cleanedSorted4 = cleanLower(cleaned4, sorted23);
0373
0374
0375 L1MuKBMTrackCollection step2;
0376
0377 if (!cleanedSorted4.empty())
0378 step2.insert(step2.end(), cleanedSorted4.begin(), cleanedSorted4.end());
0379 if (!cleanedSorted23.empty())
0380 step2.insert(step2.end(), cleanedSorted23.begin(), cleanedSorted23.end());
0381
0382 L1MuKBMTrackCollection out = sort4(step2);
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401 return out;
0402 }