File indexing completed on 2024-09-07 04:37:07
0001 #include "L1Trigger/TrackFindingTMTT/interface/HTrphi.h"
0002 #include "L1Trigger/TrackFindingTMTT/interface/InputData.h"
0003 #include "L1Trigger/TrackFindingTMTT/interface/TP.h"
0004 #include "L1Trigger/TrackFindingTMTT/interface/L1fittedTrack.h"
0005 #include "L1Trigger/TrackFindingTMTT/interface/Settings.h"
0006 #include "L1Trigger/TrackFindingTMTT/interface/PrintL1trk.h"
0007 #include "FWCore/ServiceRegistry/interface/Service.h"
0008
0009 #include "DataFormats/Math/interface/deltaPhi.h"
0010 #include "FWCore/Utilities/interface/Exception.h"
0011
0012 #include <vector>
0013 #include <limits>
0014 #include <atomic>
0015 #include <sstream>
0016 #include <mutex>
0017
0018 using namespace std;
0019
0020 namespace tmtt {
0021
0022
0023
0024
0025
0026
0027
0028
0029 HTrphi::HTrphi(const Settings* settings,
0030 unsigned int iPhiSec,
0031 unsigned int iEtaReg,
0032 float etaMinSector,
0033 float etaMaxSector,
0034 float phiCentreSector,
0035 HTrphi::ErrorMonitor* errMon)
0036 : HTbase(settings, iPhiSec, iEtaReg, settings->houghNbinsPt(), settings->houghNbinsPhi()),
0037 invPtToDphi_((settings->invPtToDphi())),
0038 shape_(static_cast<HTshape>(settings->shape())),
0039
0040
0041 maxAbsQoverPtAxis_(1. / settings->houghMinPt()),
0042 nBinsQoverPtAxis_(settings->houghNbinsPt()),
0043 binSizeQoverPtAxis_(2 * maxAbsQoverPtAxis_ / nBinsQoverPtAxis_),
0044
0045
0046
0047 chosenRofPhi_(settings->chosenRofPhi()),
0048 phiCentreSector_(phiCentreSector),
0049 maxAbsPhiTrkAxis_(M_PI / float(settings->numPhiSectors())),
0050 nBinsPhiTrkAxis_(settings->houghNbinsPhi()),
0051 binSizePhiTrkAxis_(2 * maxAbsPhiTrkAxis_ / nBinsPhiTrkAxis_),
0052 errMon_(errMon) {
0053
0054 if (shape_ != HTshape::square)
0055 binSizeQoverPtAxis_ = 2. * maxAbsQoverPtAxis_ / (nBinsQoverPtAxis_ - 1.);
0056 if (shape_ == HTshape::hexagon)
0057 binSizePhiTrkAxis_ = 2. * maxAbsPhiTrkAxis_ / (nBinsPhiTrkAxis_ - 1. / 6.);
0058 else if (shape_ == HTshape::diamond)
0059 binSizePhiTrkAxis_ = 2. * maxAbsPhiTrkAxis_ / (nBinsPhiTrkAxis_ - 1. / 2.);
0060
0061
0062
0063
0064 enableMerge2x2_ = (settings->enableMerge2x2() || settings->miniHTstage());
0065 if (settings->miniHTstage()) {
0066
0067 minInvPtToMerge2x2_ = 0.;
0068 } else {
0069
0070 minInvPtToMerge2x2_ = 1. / (settings->maxPtToMerge2x2());
0071 if (minInvPtToMerge2x2_ > maxAbsQoverPtAxis_)
0072 enableMerge2x2_ = false;
0073 }
0074
0075
0076
0077
0078
0079 if (enableMerge2x2_ && (nBinsQoverPtAxis_ % 2 != 0 || nBinsPhiTrkAxis_ % 2 != 0))
0080 throw cms::Exception("BadConfig") << "HTrphi: You are not allowed to set EnableMerge2x2 or MiniHTstage = True if "
0081 "you have an odd number of bins "
0082 "in r-phi HT array "
0083 << nBinsQoverPtAxis_ << " " << nBinsPhiTrkAxis_;
0084
0085
0086
0087
0088 killSomeHTCellsRphi_ = settings->killSomeHTCellsRphi();
0089
0090
0091 nReceivedStubs_ = 0;
0092 busyInputSectorKill_ = settings_->busyInputSectorKill();
0093 busySectorKill_ = settings_->busySectorKill();
0094
0095 busyInputSectorNumStubs_ = settings_->busyInputSectorNumStubs();
0096
0097 busySectorNumStubs_ = settings_->busySectorNumStubs();
0098
0099 busySectorMbinRanges_ = settings_->busySectorMbinRanges();
0100
0101 busySectorMbinOrder_ = settings_->busySectorMbinOrder();
0102
0103 busySectorUseMbinRanges_ = (not busySectorMbinRanges_.empty());
0104 busySectorUseMbinOrder_ = (not busySectorMbinOrder_.empty());
0105
0106 bool rescaleMbins = false;
0107 if (busySectorUseMbinRanges_) {
0108
0109
0110
0111 unsigned int nTotalBins = 0;
0112 for (unsigned int j = 0; j < busySectorMbinRanges_.size(); j++) {
0113 nTotalBins += busySectorMbinRanges_[j];
0114 }
0115 rescaleMbins = (nTotalBins != nBinsQoverPtAxis_);
0116
0117 if (rescaleMbins && busySectorUseMbinOrder_)
0118 throw cms::Exception("BadConfig") << "HTrphi: BusySectorUserMbin error";
0119 float rescaleFactor = rescaleMbins ? float(nBinsQoverPtAxis_) / float(nTotalBins) : 1.;
0120
0121 busySectorMbinLow_.resize(busySectorMbinRanges_.size());
0122 busySectorMbinHigh_.resize(busySectorMbinRanges_.size());
0123 float mBinSum = 0.;
0124 for (unsigned int i = 0; i < busySectorMbinRanges_.size(); i++) {
0125 busySectorMbinLow_[i] = std::round(mBinSum);
0126 busySectorMbinHigh_[i] = std::round(mBinSum + rescaleFactor * busySectorMbinRanges_[i]) - 1;
0127 mBinSum += rescaleFactor * busySectorMbinRanges_[i];
0128 }
0129 }
0130
0131 for (unsigned int i = 0; i < nBinsQoverPtAxis_; i++) {
0132 for (unsigned int j = 0; j < nBinsPhiTrkAxis_; j++) {
0133 pair<float, float> helix = this->helix2Dconventional(i, j);
0134 float qOverPt = helix.first;
0135
0136 bool mergedCell = false;
0137 if (enableMerge2x2_ && this->mergedCell(i, j))
0138 mergedCell = true;
0139
0140 HTbase::htArray_(i, j) =
0141 std::make_unique<HTcell>(settings, iPhiSec, iEtaReg, etaMinSector, etaMaxSector, qOverPt, i, mergedCell);
0142 }
0143 }
0144
0145 std::stringstream text;
0146 text << "\n";
0147 text << "=== R-PHI HOUGH TRANSFORM AXES RANGES: abs(q/Pt) < " << maxAbsQoverPtAxis_ << " & abs(track-phi) < "
0148 << maxAbsPhiTrkAxis_ << " ===\n";
0149 text << "=== R-PHI HOUGH TRANSFORM ARRAY SIZE: q/Pt bins = " << nBinsQoverPtAxis_
0150 << " & track-phi bins = " << nBinsPhiTrkAxis_ << " ===\n";
0151 text << "=== R-PHI HOUGH TRANSFORM BIN SIZE: BIN(q/Pt) = " << binSizeQoverPtAxis_
0152 << " & BIN(track-phi) = " << binSizePhiTrkAxis_ << " ===\n\n";
0153 if (busySectorKill_ && busySectorUseMbinRanges_ && rescaleMbins) {
0154 text << "=== R-PHI HOUGH TRANSFORM WARNING: Rescaled m bin ranges specified by cfg parameter "
0155 "BusySectorMbinRanges, as they were inconsistent with total number of m bins in HT.\n";
0156 text << "=== Rescaled values for BusySectorMbinRanges =";
0157 for (unsigned int i = 0; i < busySectorMbinRanges_.size(); i++) {
0158 text << " " << (busySectorMbinHigh_[i] - busySectorMbinLow_[i] + 1);
0159 }
0160 }
0161 text << "\n";
0162 static std::once_flag printOnce;
0163 std::call_once(printOnce, [](string t) { PrintL1trk() << t; }, text.str());
0164
0165
0166 cellCenters_.clear();
0167 for (unsigned int m = 0; m < nBinsQoverPtAxis_; m++) {
0168 std::vector<std::pair<float, float> > binCenters;
0169 for (unsigned int c = 0; c < nBinsPhiTrkAxis_; c++)
0170 binCenters.push_back(this->helix2Dhough(m, c));
0171 cellCenters_.push_back(binCenters);
0172 }
0173 }
0174
0175
0176
0177
0178 void HTrphi::store(Stub* stub, const vector<bool>& inEtaSubSecs) {
0179
0180 if ((!busyInputSectorKill_) || (nReceivedStubs_ < busyInputSectorNumStubs_)) {
0181 nReceivedStubs_++;
0182
0183 unsigned int jPhiTrkBinMinLast = 0;
0184 unsigned int jPhiTrkBinMaxLast = 99999;
0185
0186
0187 for (unsigned int i = 0; i < nBinsQoverPtAxis_; i++) {
0188 if (shape_ == HTshape::square) {
0189
0190
0191
0192 pair<unsigned int, unsigned int> jRange = this->iPhiRange(stub, i);
0193 unsigned int jPhiTrkBinMin = jRange.first;
0194 unsigned int jPhiTrkBinMax = jRange.second;
0195
0196
0197 for (unsigned int j = jPhiTrkBinMin; j <= jPhiTrkBinMax; j++) {
0198 bool canStoreStub = true;
0199 unsigned int iStore = i;
0200 unsigned int jStore = j;
0201
0202
0203
0204 if (enableMerge2x2_) {
0205
0206 if (this->mergedCell(i, j)) {
0207
0208
0209 if (i % 2 == 1)
0210 iStore = i - 1;
0211 if (j % 2 == 1)
0212 jStore = j - 1;
0213
0214 if (HTbase::htArray_(iStore, jStore)->stubStoredInCell(stub))
0215 canStoreStub = false;
0216 }
0217 }
0218
0219 if (canStoreStub)
0220 HTbase::htArray_(iStore, jStore)->store(stub, inEtaSubSecs);
0221 }
0222
0223
0224 if (errMon_ != nullptr) {
0225 this->countFirmwareErrors(i, jPhiTrkBinMin, jPhiTrkBinMax, jPhiTrkBinMinLast, jPhiTrkBinMaxLast);
0226 jPhiTrkBinMinLast = jPhiTrkBinMin;
0227 jPhiTrkBinMaxLast = jPhiTrkBinMax;
0228 }
0229
0230 } else {
0231
0232
0233 if (shape_ == HTshape::diamond) {
0234
0235
0236 float qOverPtBin = -maxAbsQoverPtAxis_ + i * binSizeQoverPtAxis_;
0237 float phiTrk = reco::deltaPhi(stub->phi(), phiCentreSector_) +
0238 invPtToDphi_ * qOverPtBin * (stub->r() - chosenRofPhi_) + maxAbsPhiTrkAxis_;
0239 if (i % 2 == 0)
0240 phiTrk += binSizePhiTrkAxis_ / 2.;
0241 unsigned int binCenter = std::floor(phiTrk / binSizePhiTrkAxis_);
0242 if (binCenter < nBinsPhiTrkAxis_)
0243 HTbase::htArray_(i, binCenter)->store(stub, inEtaSubSecs);
0244
0245 } else if (shape_ == HTshape::hexagon) {
0246
0247
0248 float qOverPtBin = -maxAbsQoverPtAxis_ + i * binSizeQoverPtAxis_;
0249 float qOverPtBinVar = binSizeQoverPtAxis_;
0250 float phiTrk = reco::deltaPhi(stub->phi(), phiCentreSector_) +
0251 invPtToDphi_ * qOverPtBin * (stub->r() - chosenRofPhi_) + maxAbsPhiTrkAxis_;
0252 float phiTrkVar = invPtToDphi_ * qOverPtBinVar * std::abs(stub->r() - chosenRofPhi_);
0253 float phiTrkMin = phiTrk - phiTrkVar;
0254 float phiTrkMax = phiTrk + phiTrkVar;
0255 if (i % 2 == 0)
0256 phiTrk += binSizePhiTrkAxis_ / 6.;
0257 else {
0258 phiTrk -= binSizePhiTrkAxis_ / 3.;
0259 phiTrkMin -= binSizePhiTrkAxis_ / 2.;
0260 phiTrkMax -= binSizePhiTrkAxis_ / 2.;
0261 }
0262 unsigned int iCenter = std::floor(phiTrk / binSizePhiTrkAxis_ * 3.);
0263 unsigned int iMin = std::floor(phiTrkMin / binSizePhiTrkAxis_ * 3.);
0264 unsigned int iMax = std::floor(phiTrkMax / binSizePhiTrkAxis_ * 3.);
0265 std::pair<bool, unsigned int> binCenter;
0266 std::pair<bool, unsigned int> binMin;
0267 std::pair<bool, unsigned int> binMax;
0268 binCenter.second = iCenter / 3;
0269 binMin.second = iMin / 3;
0270 binMax.second = iMax / 3;
0271 binCenter.first = !(iCenter % 3 == 2);
0272 binMin.first = (iMin % 3 == 0);
0273 binMax.first = (iMax % 3 == 0);
0274 if (binCenter.first && binCenter.second < nBinsPhiTrkAxis_)
0275 HTbase::htArray_(i, binCenter.second)->store(stub, inEtaSubSecs);
0276 else if (binMin.first && binMin.second < nBinsPhiTrkAxis_)
0277 HTbase::htArray_(i, binMin.second)->store(stub, inEtaSubSecs);
0278 else if (binMax.first && binMax.second < nBinsPhiTrkAxis_)
0279 HTbase::htArray_(i, binMax.second)->store(stub, inEtaSubSecs);
0280
0281 } else if (shape_ == HTshape::brick) {
0282
0283
0284 float qOverPtBin = -maxAbsQoverPtAxis_ + i * binSizeQoverPtAxis_;
0285 float qOverPtBinVar = binSizeQoverPtAxis_;
0286 float phiTrk = reco::deltaPhi(stub->phi(), phiCentreSector_) +
0287 invPtToDphi_ * qOverPtBin * (stub->r() - chosenRofPhi_) + maxAbsPhiTrkAxis_;
0288 float phiTrkVar = invPtToDphi_ * qOverPtBinVar * std::abs(stub->r() - chosenRofPhi_);
0289 float phiTrkMin = phiTrk - phiTrkVar;
0290 float phiTrkMax = phiTrk + phiTrkVar;
0291 unsigned int iMin = std::floor(phiTrkMin / binSizePhiTrkAxis_ * 2.);
0292 unsigned int iMax = std::floor(phiTrkMax / binSizePhiTrkAxis_ * 2.);
0293 std::pair<bool, unsigned int> binMin;
0294 std::pair<bool, unsigned int> binMax;
0295 binMin.second = iMin / 2;
0296 binMax.second = iMax / 2;
0297 binMin.first = (iMin % 2 == i % 2);
0298 binMax.first = (iMax % 2 == i % 2);
0299 if (binMin.first && binMin.second < nBinsPhiTrkAxis_)
0300 HTbase::htArray_(i, binMin.second)->store(stub, inEtaSubSecs);
0301 else if (binMax.first && binMax.second < nBinsPhiTrkAxis_)
0302 HTbase::htArray_(i, binMax.second)->store(stub, inEtaSubSecs);
0303 }
0304 }
0305 }
0306
0307
0308 if (errMon_ != nullptr) {
0309 errMon_->maxLineGradient = max(errMon_->maxLineGradient.load(), this->calcLineGradArray(stub->r()));
0310 }
0311 }
0312 }
0313
0314
0315
0316 unsigned int HTrphi::getMbinRange(const L1track2D& trk) const {
0317 if (busySectorUseMbinRanges_) {
0318 unsigned int mBin = trk.cellLocationHT().first;
0319 unsigned int mBinOrder;
0320 if (busySectorUseMbinOrder_) {
0321
0322 mBinOrder = 99999;
0323 for (unsigned int k = 0; k < busySectorMbinOrder_.size(); k++) {
0324 if (mBin == busySectorMbinOrder_[k])
0325 mBinOrder = k;
0326 }
0327 if (mBinOrder == 99999)
0328 throw cms::Exception("LogicError") << "HTrphi::getMbinRange() mBinOrder calculation wrong.";
0329 } else {
0330
0331 mBinOrder = mBin;
0332 }
0333 for (unsigned int i = 0; i < busySectorMbinRanges_.size(); i++) {
0334 if (mBinOrder >= busySectorMbinLow_[i] && mBinOrder <= busySectorMbinHigh_[i])
0335 return i;
0336 }
0337 throw cms::Exception("LogicError") << "HTrphi::getMbinRange() messed up";
0338 } else {
0339 return 0;
0340 }
0341 }
0342
0343
0344
0345
0346
0347 pair<unsigned int, unsigned int> HTrphi::iPhiRange(const Stub* stub, unsigned int iQoverPtBin, bool debug) const {
0348
0349 float qOverPtBin = -maxAbsQoverPtAxis_ + (iQoverPtBin + 0.5) * binSizeQoverPtAxis_;
0350
0351 float qOverPtBinVar = 0.5 * binSizeQoverPtAxis_;
0352
0353
0354
0355
0356
0357 float phiTrk = stub->phi() + invPtToDphi_ * qOverPtBin * (stub->r() - chosenRofPhi_);
0358
0359
0360
0361 float phiTrkVar = invPtToDphi_ * qOverPtBinVar * std::abs(stub->r() - chosenRofPhi_);
0362 float phiTrkMin = phiTrk - phiTrkVar;
0363 float phiTrkMax = phiTrk + phiTrkVar;
0364
0365 float deltaPhiMin = reco::deltaPhi(phiTrkMin, phiCentreSector_);
0366 float deltaPhiMax = reco::deltaPhi(phiTrkMax, phiCentreSector_);
0367 pair<float, float> phiTrkRange(deltaPhiMin, deltaPhiMax);
0368
0369
0370 pair<unsigned int, unsigned int> iPhiTrkBinRange = this->HTbase::convertCoordRangeToBinRange(
0371 phiTrkRange, nBinsPhiTrkAxis_, (-maxAbsPhiTrkAxis_), binSizePhiTrkAxis_, killSomeHTCellsRphi_);
0372
0373 return iPhiTrkBinRange;
0374 }
0375
0376
0377
0378 void HTrphi::countFirmwareErrors(unsigned int iQoverPtBin,
0379 unsigned int jPhiTrkBinMin,
0380 unsigned int jPhiTrkBinMax,
0381 unsigned int jPhiTrkBinMinLast,
0382 unsigned int jPhiTrkBinMaxLast) {
0383
0384 if (jPhiTrkBinMax >= jPhiTrkBinMin) {
0385
0386
0387 bool OK_a = (jPhiTrkBinMin + 1 >= jPhiTrkBinMinLast) && (jPhiTrkBinMax <= jPhiTrkBinMaxLast + 1);
0388
0389 bool OK_b = (jPhiTrkBinMax - jPhiTrkBinMin + 1 <= 2);
0390
0391 if (!OK_a)
0392 errMon_->numErrorsTypeA++;
0393 if (!OK_b)
0394 errMon_->numErrorsTypeB++;
0395 errMon_->numErrorsNorm++;
0396 }
0397 }
0398
0399
0400
0401
0402
0403 pair<float, float> HTrphi::helix2Dhough(unsigned int i, unsigned int j) const {
0404 unsigned int qOverPtBin = i;
0405 unsigned int phiTrkBin = j;
0406
0407
0408 bool merged = false;
0409 if (enableMerge2x2_) {
0410
0411 if (this->mergedCell(i, j)) {
0412 merged = true;
0413
0414
0415 if (i % 2 == 1)
0416 qOverPtBin = i - 1;
0417 if (j % 2 == 1)
0418 phiTrkBin = j - 1;
0419 }
0420 }
0421
0422 float qOverPtBinCenter = .5;
0423 float phiTrkBinCenter = .5;
0424
0425 if (shape_ != HTshape::square) {
0426 qOverPtBinCenter = 0.;
0427
0428 float evenPhiPos = 0., oddPhiPos = 0.;
0429 if (shape_ == HTshape::hexagon) {
0430 evenPhiPos = 1. / 6.;
0431 oddPhiPos = 2. / 3.;
0432 } else if (shape_ == HTshape::diamond) {
0433 evenPhiPos = 0.;
0434 oddPhiPos = 0.5;
0435 } else if (shape_ == HTshape::brick) {
0436 evenPhiPos = 0.25;
0437 oddPhiPos = 0.75;
0438 }
0439 phiTrkBinCenter = (qOverPtBin % 2 == 0) ? evenPhiPos : oddPhiPos;
0440 }
0441
0442 float qOverPt = -maxAbsQoverPtAxis_ + (qOverPtBin + qOverPtBinCenter) * binSizeQoverPtAxis_;
0443 float phiTrk = -maxAbsPhiTrkAxis_ + (phiTrkBin + phiTrkBinCenter) * binSizePhiTrkAxis_;
0444
0445 if (merged) {
0446 qOverPt += 0.5 * binSizeQoverPtAxis_;
0447 phiTrk += 0.5 * binSizePhiTrkAxis_;
0448 }
0449
0450
0451 phiTrk = reco::deltaPhi(phiTrk + phiCentreSector_, 0.);
0452 return pair<float, float>(qOverPt, phiTrk);
0453 }
0454
0455
0456
0457
0458
0459 pair<float, float> HTrphi::helix2Dconventional(unsigned int i, unsigned int j) const {
0460
0461 pair<float, float> helix2Dht = this->helix2Dhough(i, j);
0462
0463 float qOverPt = helix2Dht.first;
0464
0465 float phi0 = reco::deltaPhi(helix2Dht.second + invPtToDphi_ * chosenRofPhi_ * qOverPt, 0.);
0466 return pair<float, float>(qOverPt, phi0);
0467 }
0468
0469
0470
0471
0472 pair<unsigned int, unsigned int> HTrphi::trueCell(const TP* tp) const {
0473
0474 float qOverPt = tp->qOverPt();
0475 float phiTrk = tp->trkPhiAtR(chosenRofPhi_);
0476
0477 float deltaPhi = reco::deltaPhi(phiTrk, phiCentreSector_);
0478
0479 int iQoverPt = floor((qOverPt - (-maxAbsQoverPtAxis_)) / binSizeQoverPtAxis_);
0480 int iPhiTrk = floor((deltaPhi - (-maxAbsPhiTrkAxis_)) / binSizePhiTrkAxis_);
0481
0482 if (iQoverPt >= 0 && iQoverPt < int(nBinsQoverPtAxis_) && iPhiTrk >= 0 && iPhiTrk < int(nBinsPhiTrkAxis_)) {
0483
0484
0485
0486
0487 ;
0488 } else {
0489
0490 if (iQoverPt < 0)
0491 iQoverPt = 0;
0492 if (iQoverPt >= int(nBinsQoverPtAxis_))
0493 iQoverPt = nBinsQoverPtAxis_ - 1;
0494 if (iPhiTrk < 0)
0495 iPhiTrk = 0;
0496 if (iPhiTrk >= int(nBinsPhiTrkAxis_))
0497 iPhiTrk = nBinsPhiTrkAxis_ - 1;
0498 }
0499 return pair<unsigned int, unsigned int>(iQoverPt, iPhiTrk);
0500 }
0501
0502
0503
0504
0505
0506 pair<unsigned int, unsigned int> HTrphi::cell(const L1fittedTrack* fitTrk) const {
0507 bool beamConstraint = fitTrk->done_bcon();
0508
0509 float qOverPt = beamConstraint ? fitTrk->qOverPt_bcon() : fitTrk->qOverPt();
0510
0511 float phiTrk = fitTrk->phiAtChosenR(beamConstraint);
0512
0513 float deltaPhi = reco::deltaPhi(phiTrk, phiCentreSector_);
0514
0515 int iQoverPt = 999999;
0516 int iPhiTrk = 999999;
0517
0518 if (shape_ == HTshape::square) {
0519
0520
0521 iQoverPt = floor((qOverPt - (-maxAbsQoverPtAxis_)) / binSizeQoverPtAxis_);
0522 iPhiTrk = floor((deltaPhi - (-maxAbsPhiTrkAxis_)) / binSizePhiTrkAxis_);
0523
0524
0525 if (iQoverPt >= 0 && iQoverPt < int(nBinsQoverPtAxis_) && iPhiTrk >= 0 && iPhiTrk < int(nBinsPhiTrkAxis_)) {
0526
0527
0528
0529
0530 ;
0531 } else {
0532
0533 if (iQoverPt < 0)
0534 iQoverPt = 0;
0535 if (iQoverPt >= int(nBinsQoverPtAxis_))
0536 iQoverPt = nBinsQoverPtAxis_ - 1;
0537 if (iPhiTrk < 0)
0538 iPhiTrk = 0;
0539 if (iPhiTrk >= int(nBinsPhiTrkAxis_))
0540 iPhiTrk = nBinsPhiTrkAxis_ - 1;
0541 }
0542
0543 } else {
0544
0545
0546 float minD = std::numeric_limits<float>::infinity();
0547 float d(0);
0548 unsigned int m(0);
0549 for (const auto& binCenters : cellCenters_) {
0550 unsigned int c(0);
0551 for (auto cellCenter : binCenters) {
0552 d = std::pow((cellCenter.first - qOverPt) / (float)binSizeQoverPtAxis_, 2) +
0553 std::pow((cellCenter.second - phiTrk) / (float)binSizePhiTrkAxis_, 2);
0554 if (d < minD) {
0555 minD = d;
0556 iQoverPt = m;
0557 iPhiTrk = c;
0558 }
0559 c++;
0560 }
0561 m++;
0562 }
0563
0564 if (iQoverPt < 0)
0565 iQoverPt = 0;
0566 if (iQoverPt >= int(nBinsQoverPtAxis_))
0567 iQoverPt = nBinsQoverPtAxis_ - 1;
0568 if (iPhiTrk < 0)
0569 iPhiTrk = 0;
0570 if (iPhiTrk >= int(nBinsPhiTrkAxis_))
0571 iPhiTrk = nBinsPhiTrkAxis_ - 1;
0572 }
0573
0574 return pair<unsigned int, unsigned int>(iQoverPt, iPhiTrk);
0575 }
0576
0577
0578
0579
0580 bool HTrphi::mergedCell(unsigned int iQoverPtBin, unsigned int jPhiTrkBin) const {
0581 bool merge = false;
0582
0583 if (enableMerge2x2_) {
0584 unsigned int i = iQoverPtBin;
0585
0586
0587
0588 float fMergeBins = (maxAbsQoverPtAxis_ - minInvPtToMerge2x2_) / (2. * binSizeQoverPtAxis_);
0589
0590 unsigned int numQoverPtBinsToMerge = 2 * min((unsigned int)(std::round(fMergeBins)), (nBinsQoverPtAxis_ / 4));
0591 const float small = 0.001;
0592 if (minInvPtToMerge2x2_ < small && (unsigned int)(std::round(2. * fMergeBins)) % 2 == 1)
0593 numQoverPtBinsToMerge++;
0594 unsigned int iB = (nBinsQoverPtAxis_ - 1) - i;
0595 if (min(i, iB) < numQoverPtBinsToMerge)
0596 merge = true;
0597 }
0598
0599 return merge;
0600 }
0601
0602
0603
0604 float HTrphi::calcLineGradArray(float r) const {
0605 float grad = std::abs(invPtToDphi_ * (r - chosenRofPhi_));
0606
0607 grad *= binSizeQoverPtAxis_ / binSizePhiTrkAxis_;
0608 if (shape_ == HTshape::hexagon)
0609 grad *= 3.;
0610 else if (shape_ == HTshape::diamond)
0611 grad *= 2.;
0612 else if (shape_ == HTshape::brick)
0613 grad *= 4.;
0614 return grad;
0615 }
0616
0617
0618
0619
0620 list<L1track2D> HTrphi::killTracksBusySec(const list<L1track2D>& tracks) const {
0621 list<L1track2D> outTracks;
0622
0623 if (busySectorKill_) {
0624 unsigned int nStubsOut = 0;
0625
0626 vector<unsigned int> nStubsOutInRange(busySectorMbinRanges_.size(), 0);
0627
0628 for (const L1track2D& trk : tracks) {
0629 bool keep = true;
0630 unsigned int nStubs = trk.numStubs();
0631 if (busySectorUseMbinRanges_) {
0632 unsigned int mBinRange = this->getMbinRange(trk);
0633 nStubsOutInRange[mBinRange] += nStubs;
0634 if (nStubsOutInRange[mBinRange] > busySectorNumStubs_)
0635 keep = false;
0636 } else {
0637 nStubsOut += nStubs;
0638 if (nStubsOut > busySectorNumStubs_)
0639 keep = false;
0640 }
0641
0642 if (keep)
0643 outTracks.push_back(trk);
0644 }
0645
0646 } else {
0647 outTracks = tracks;
0648 }
0649
0650 return outTracks;
0651 }
0652
0653
0654
0655
0656
0657 vector<unsigned int> HTrphi::rowOrder(unsigned int numRows) const {
0658 vector<unsigned int> iOrder;
0659
0660
0661 const bool oddNumRows = (numRows % 2 == 1);
0662
0663
0664 if (oddNumRows) {
0665 unsigned int middleRow = (numRows - 1) / 2;
0666 iOrder.push_back(middleRow);
0667 for (unsigned int i = 1; i <= (numRows - 1) / 2; i++) {
0668 iOrder.push_back(middleRow - i);
0669 iOrder.push_back(middleRow + i);
0670 }
0671 } else {
0672 unsigned int startRowPos = numRows / 2;
0673 unsigned int startRowNeg = startRowPos - 1;
0674 for (unsigned int i = 0; i < numRows / 2; i++) {
0675 iOrder.push_back(startRowNeg - i);
0676 iOrder.push_back(startRowPos + i);
0677 }
0678 }
0679
0680 return iOrder;
0681 }
0682
0683 }