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