File indexing completed on 2024-04-06 12:19:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSM.h"
0021
0022
0023
0024
0025 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSCand.h"
0026 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigTSPhi.h"
0027
0028
0029
0030
0031 #include <algorithm>
0032 #include <iostream>
0033
0034
0035
0036
0037
0038 DTTSM::DTTSM(int n) : _n(n), _ignoreSecondTrack(0) {
0039
0040 _incand[0].reserve(DTConfigTSPhi::NTSSTSM);
0041 _incand[1].reserve(DTConfigTSPhi::NTSSTSM);
0042 _outcand.reserve(2);
0043 }
0044
0045
0046
0047
0048 DTTSM::~DTTSM() { clear(); }
0049
0050
0051
0052
0053
0054 void DTTSM::clear() {
0055 _ignoreSecondTrack = 0;
0056 for (int itk = 0; itk <= 1; itk++) {
0057
0058 _incand[itk].clear();
0059 }
0060
0061 _outcand.clear();
0062 }
0063
0064 void DTTSM::run(int bkmod) {
0065 if (config()->debug()) {
0066 std::cout << "DTTSM::run: Processing DTTSM: ";
0067 std::cout << nFirstT() << " first & " << nSecondT() << " second tracks" << std::endl;
0068 }
0069
0070 if (nFirstT() < 1)
0071 return;
0072
0073
0074
0075
0076
0077 if (config()->debug()) {
0078 std::cout << "Vector of first tracks in DTTSM: " << std::endl;
0079 std::vector<DTTSCand *>::const_iterator p;
0080 for (p = _incand[0].begin(); p != _incand[0].end(); p++) {
0081 (*p)->print();
0082 }
0083 }
0084
0085
0086 DTTSCand *first = sortTSM1(bkmod);
0087 if (first != nullptr) {
0088 _outcand.push_back(first);
0089 }
0090 if (nSecondT() < 1)
0091 return;
0092
0093
0094
0095
0096
0097
0098 if (config()->debug()) {
0099 std::vector<DTTSCand *>::const_iterator p;
0100 std::cout << "Vector of second tracks (including carry) in DTTSM: " << std::endl;
0101 for (p = _incand[1].begin(); p != _incand[1].end(); p++) {
0102 (*p)->print();
0103 }
0104 }
0105
0106
0107 DTTSCand *second = sortTSM2(bkmod);
0108 if (second != nullptr) {
0109 _outcand.push_back(second);
0110 }
0111 }
0112
0113 DTTSCand *DTTSM::sortTSM1(int bkmod) {
0114
0115 DTTSCand *best = nullptr;
0116 DTTSCand *carry = nullptr;
0117 std::vector<DTTSCand *>::iterator p;
0118 for (p = _incand[0].begin(); p != _incand[0].end(); p++) {
0119 DTTSCand *curr = (*p);
0120
0121 if (bkmod == 1) {
0122 curr->setBitsTss();
0123
0124 } else if (bkmod == 0) {
0125 curr->setBitsBkmod();
0126 } else {
0127 std::cout << "DTTSM::sortTSM1: bkmod not properly assigned!" << std::endl;
0128 }
0129
0130 if (best == nullptr) {
0131 best = curr;
0132 } else if ((*curr) < (*best)) {
0133 carry = best;
0134 best = curr;
0135 } else if (carry == nullptr) {
0136 carry = curr;
0137 } else if ((*curr) < (*carry)) {
0138 carry = curr;
0139 }
0140 }
0141
0142
0143 if (carry != nullptr) {
0144
0145
0146 bool inner_or_corr;
0147 if (config()->TsmGhost1Corr()) {
0148 inner_or_corr = carry->isInner() || carry->isCorr();
0149 } else {
0150 inner_or_corr = carry->isInner();
0151 }
0152
0153 if (config()->TsmGhost1Flag() < 2) {
0154
0155 int adj = (carry->tssNumber() == best->tssNumber() + 1 &&
0156 best->TcPos() == DTConfigTSPhi::NTCTSS && carry->TcPos() == 1) ||
0157 (carry->tssNumber() == best->tssNumber() - 1 &&
0158 best->TcPos() == 1 && carry->TcPos() == DTConfigTSPhi::NTCTSS) ||
0159 (carry->tssNumber() == best->tssNumber() &&
0160 abs(carry->TcPos() - best->TcPos()) == 1);
0161
0162 if (config()->TsmGhost1Flag() == 0 ||
0163
0164
0165 inner_or_corr ||
0166 !adj) {
0167
0168 carry->setSecondTrack();
0169
0170
0171 _incand[1].push_back(carry);
0172 }
0173 }
0174 }
0175
0176 return best;
0177 }
0178
0179 DTTSCand *DTTSM::sortTSM2(int bkmod) {
0180
0181 if (config()->TsmGhost2Flag() == 3)
0182 return nullptr;
0183
0184
0185 if (nTracks() < 1) {
0186 std::cout << "DTTSM::sortTSM2: called with no first track.";
0187 std::cout << " empty pointer returned!" << std::endl;
0188 return nullptr;
0189 }
0190
0191
0192
0193 if (_ignoreSecondTrack) {
0194 std::vector<DTTSCand *>::iterator p;
0195 for (p = _incand[1].begin(); p != _incand[1].end(); p++) {
0196 if ((*p)->isCarry())
0197 return (*p);
0198 }
0199 return nullptr;
0200 }
0201
0202
0203 DTTSCand *best = getTrack(1);
0204 DTTSCand *second = nullptr;
0205 std::vector<DTTSCand *>::iterator p;
0206 for (p = _incand[1].begin(); p != _incand[1].end(); p++) {
0207 DTTSCand *curr = (*p);
0208
0209
0210
0211 bool inner_or_corr;
0212 if (config()->TsmGhost2Corr()) {
0213 inner_or_corr = curr->isInner() || curr->isCorr();
0214 } else {
0215 inner_or_corr = curr->isInner();
0216 }
0217
0218 if (config()->TsmGhost2Flag() != 0) {
0219 if (
0220
0221 !inner_or_corr &&
0222 (curr->tssNumber() == best->tssNumber() && curr->TcPos() == best->TcPos())) {
0223 if (config()->TsmGhost2Flag() == 2 ||
0224 ((!best->isCorr()) && config()->TsmGhost2Flag() != 4) ||
0225 ((!best->isCorr()) && best->isInner() &&
0226 config()->TsmGhost2Flag() == 4))
0227 {
0228 continue;
0229 }
0230 }
0231 }
0232
0233
0234
0235 if (bkmod == 1) {
0236 curr->setBitsTss();
0237
0238 } else if (bkmod == 0) {
0239 curr->setBitsBkmod();
0240 } else {
0241 std::cout << " DTTSM::sortTSM2 bkmod not properly assigned!" << std::endl;
0242 }
0243
0244
0245
0246
0247 if (second == nullptr) {
0248 second = curr;
0249 } else if ((*curr) < (*second)) {
0250 second = curr;
0251 }
0252 }
0253 return second;
0254 }
0255
0256 void DTTSM::addCand(DTTSCand *cand) {
0257
0258
0259
0260 _incand[(1 - cand->isFirst())].push_back(cand);
0261 }
0262
0263 unsigned DTTSM::nCand(int ifs) const {
0264 if (ifs < 1 || ifs > 2) {
0265 std::cout << "DTTSM::nCand: wrong track number: " << ifs;
0266 std::cout << " 0 returned!" << std::endl;
0267 return 0;
0268 }
0269
0270 return _incand[ifs - 1].size();
0271 }
0272
0273 DTTSCand *DTTSM::getDTTSCand(int ifs, unsigned n) const {
0274 if (ifs < 1 || ifs > 2) {
0275 std::cout << "DTTSM::getDTTSCand: wrong track number: " << ifs;
0276 std::cout << " empty pointer returned!" << std::endl;
0277 return nullptr;
0278 }
0279 if (n < 1 || n > nCand(ifs)) {
0280 std::cout << "DTTSM::getDTTSCand: requested trigger not present: " << n;
0281 std::cout << " empty pointer returned!" << std::endl;
0282 return nullptr;
0283 }
0284 std::vector<DTTSCand *>::const_iterator p = _incand[ifs - 1].begin() + n - 1;
0285 return (*p);
0286 }
0287
0288 const DTTracoTrigData *DTTSM::getTracoT(int ifs, unsigned n) const {
0289 if (ifs < 1 || ifs > 2) {
0290 std::cout << "DTTSM::getTracoT: wrong track number: " << ifs;
0291 std::cout << " empty pointer returned!" << std::endl;
0292 return nullptr;
0293 }
0294 if (n < 1 || n > nCand(ifs)) {
0295 std::cout << "DTTSM::getTracoT: requested trigger not present: " << n;
0296 std::cout << " empty pointer returned!" << std::endl;
0297 return nullptr;
0298 }
0299 return getDTTSCand(ifs, n)->tracoTr();
0300 }
0301
0302 DTTSCand *DTTSM::getTrack(int n) const {
0303 if (n < 1 || n > nTracks()) {
0304 std::cout << "DTTSM::getTrack: requested track not present: " << n;
0305 std::cout << " empty pointer returned!" << std::endl;
0306 return nullptr;
0307 }
0308 std::vector<DTTSCand *>::const_iterator p = _outcand.begin() + n - 1;
0309 return (*p);
0310 }