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 "L1TriggerConfig/DTTPGConfig/interface/BitArray.h"
0021
0022
0023
0024
0025 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSPhi.h"
0026
0027
0028
0029
0030 #include "L1Trigger/DTTraco/interface/DTTracoCard.h"
0031 #include "L1Trigger/DTTraco/interface/DTTracoTrigData.h"
0032 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSCand.h"
0033 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSM.h"
0034 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSS.h"
0035
0036 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0037
0038
0039
0040
0041 #include <iostream>
0042
0043
0044
0045
0046 DTTSPhi::DTTSPhi(DTTrigGeom *geom, DTTracoCard *tracocard) : DTGeomSupplier(geom), _tracocard(tracocard) {
0047
0048 int i = 0;
0049 for (i = 0; i < DTConfigTSPhi::NSTEPL - DTConfigTSPhi::NSTEPF + 1; i++) {
0050 _tss[i].reserve(DTConfigTSPhi::NTSSTSM);
0051
0052 _tsm[i].reserve(DTConfigTSPhi::NTSMD);
0053 }
0054
0055 for (int is = 0; is < DTConfigTSPhi::NSTEPL - DTConfigTSPhi::NSTEPF + 1; is++) {
0056
0057 for (int itss = 1; itss <= DTConfigTSPhi::NTSSTSM; itss++) {
0058 DTTSS *tss = new DTTSS(itss);
0059 _tss[is].push_back(tss);
0060 }
0061
0062
0063 for (int itsmd = 1; itsmd <= DTConfigTSPhi::NTSMD; itsmd++) {
0064 DTTSM *tsm = new DTTSM(itsmd);
0065 _tsm[is].push_back(tsm);
0066 }
0067 }
0068 }
0069
0070
0071
0072
0073 DTTSPhi::~DTTSPhi() {
0074 std::vector<DTTSS *>::iterator ptss;
0075 std::vector<DTTSM *>::iterator ptsm;
0076 for (int is = 0; is < DTConfigTSPhi::NSTEPL - DTConfigTSPhi::NSTEPF + 1; is++) {
0077
0078 for (ptss = _tss[is].begin(); ptss != _tss[is].end(); ptss++) {
0079 delete (*ptss);
0080 }
0081 _tss[is].clear();
0082
0083 for (ptsm = _tsm[is].begin(); ptsm != _tsm[is].end(); ptsm++) {
0084 delete (*ptsm);
0085 }
0086 _tsm[is].clear();
0087 }
0088
0089 localClear();
0090
0091
0092 }
0093
0094
0095
0096
0097
0098 void DTTSPhi::localClear() {
0099 for (int is = 0; is < DTConfigTSPhi::NSTEPL - DTConfigTSPhi::NSTEPF + 1; is++) {
0100
0101 std::vector<DTTSCand *>::iterator p1;
0102 for (p1 = _tctrig[is].begin(); p1 != _tctrig[is].end(); p1++) {
0103 delete (*p1);
0104 }
0105 _tctrig[is].clear();
0106
0107 std::vector<DTTSS *>::iterator ptss;
0108 for (ptss = _tss[is].begin(); ptss != _tss[is].end(); ptss++) {
0109 (*ptss)->clear();
0110 }
0111
0112 std::vector<DTTSM *>::iterator ptsm;
0113 for (ptsm = _tsm[is].begin(); ptsm != _tsm[is].end(); ptsm++) {
0114 (*ptsm)->clear();
0115 }
0116 }
0117 }
0118
0119 void DTTSPhi::setConfig(const DTConfigManager *conf) {
0120 DTChamberId sid = ChamberId();
0121 _config = conf->getDTConfigTSPhi(sid);
0122
0123 for (int is = 0; is < DTConfigTSPhi::NSTEPL - DTConfigTSPhi::NSTEPF + 1; is++) {
0124
0125 std::vector<DTTSS *>::iterator ptss;
0126 for (ptss = _tss[is].begin(); ptss != _tss[is].end(); ptss++) {
0127 (*ptss)->setConfig(config());
0128 }
0129
0130 std::vector<DTTSM *>::iterator ptsm;
0131 for (ptsm = _tsm[is].begin(); ptsm != _tsm[is].end(); ptsm++) {
0132 (*ptsm)->setConfig(config());
0133 }
0134 }
0135 }
0136
0137 void DTTSPhi::loadTSPhi() {
0138
0139 localClear();
0140
0141 if (config()->debug()) {
0142 edm::LogInfo("DTTSPhi") << "loadDTTSPhi called for wheel=" << wheel() << ", station=" << station()
0143 << ", sector=" << sector();
0144 }
0145
0146
0147 std::vector<DTTracoTrigData>::const_iterator p;
0148 std::vector<DTTracoTrigData>::const_iterator pend = _tracocard->end();
0149 for (p = _tracocard->begin(); p != pend; p++) {
0150 if (config()->usedTraco(p->tracoNumber()) ) {
0151 int step = p->step();
0152 int fs = (p->isFirst()) ? 1 : 2;
0153
0154
0155 if (fs == 1 && step > DTConfigTSPhi::NSTEPF)
0156 ignoreSecondTrack(step - 1, p->tracoNumber());
0157
0158
0159 addTracoT(step, &(*p), fs);
0160 }
0161 }
0162 }
0163
0164 void DTTSPhi::addTracoT(int step, const DTTracoTrigData *tracotrig, int ifs) {
0165 if (step < DTConfigTSPhi::NSTEPF || step > DTConfigTSPhi::NSTEPL) {
0166 edm::LogWarning("DTTSPhi") << "addTracoT: step out of range: " << step << " trigger not added!";
0167 return;
0168 }
0169
0170 if (!tracotrig->pvCode() || !tracotrig->code()) {
0171 edm::LogWarning("DTTSPhi") << "addTracoT: preview not present in TRACO trigger or its code=0 "
0172 << " trigger not added!";
0173 return;
0174 }
0175
0176
0177 int itss = (tracotrig->tracoNumber() - 1) / DTConfigTSPhi::NTCTSS + 1;
0178 if (itss < 1 || itss > DTConfigTSPhi::NTSSTSM) {
0179 edm::LogWarning("DTTSPhi") << "addTracoT: wrong TRACO number: " << tracotrig->tracoNumber()
0180 << " trigger not added!";
0181 return;
0182 }
0183
0184
0185
0186 if (config()->TsmStatus().element(itss) == 0) {
0187 return;
0188 }
0189
0190 int pos = tracotrig->tracoNumber() - (itss - 1) * DTConfigTSPhi::NTCTSS;
0191 DTTSS *tss = getDTTSS(step, itss);
0192
0193
0194 DTTSCand *cand = new DTTSCand(tss, tracotrig, ifs, pos);
0195
0196
0197 _tctrig[step - DTConfigTSPhi::NSTEPF].push_back(cand);
0198 tss->addDTTSCand(cand);
0199
0200
0201 if (config()->debug()) {
0202 edm::LogInfo("DTTSPhi") << "addTracoT at step " << step;
0203 if (ifs == 1) {
0204 edm::LogWarning("DTTSPhi") << " (first track)";
0205 } else {
0206 edm::LogWarning("DTTSPhi") << " (second track)";
0207 }
0208 edm::LogWarning("DTTSPhi") << " from TRACO " << tracotrig->tracoNumber() << " to TSS " << tss->number()
0209 << ", position=" << pos;
0210 tracotrig->print();
0211 }
0212
0213 }
0214
0215 void DTTSPhi::runTSPhi() {
0216 DTTSCand *secondPrevBx = nullptr;
0217
0218 bool existSecondPrevBx = false;
0219 int itsmd = 1;
0220 int ntsm[DTConfigTSPhi::NSTEPL + 1 - DTConfigTSPhi::NSTEPF][DTConfigTSPhi::NTSMD];
0221 int i_tsmd;
0222
0223 for (int is = DTConfigTSPhi::NSTEPF; is < DTConfigTSPhi::NSTEPL + 1; is++) {
0224
0225 i_tsmd = 0;
0226 ntsm[is - DTConfigTSPhi::NSTEPF][0] = 0;
0227 ntsm[is - DTConfigTSPhi::NSTEPF][1] = 0;
0228 std::vector<DTTSS *>::iterator p;
0229 for (p = _tss[is - DTConfigTSPhi::NSTEPF].begin(); p < _tss[is - DTConfigTSPhi::NSTEPF].end(); p++) {
0230 if ((*p)->nTracoT(1) > 0) {
0231
0232 (*p)->run();
0233
0234 if ((*p)->nTracks() > 0) {
0235 for (int it = 1; it <= (*p)->nTracks(); it++) {
0236
0237 int bkmod = config()->TsmStatus().element(0);
0238 if (bkmod == 0) {
0239 int my_itss = (*p)->number();
0240 int ntsstsmd = config()->TSSinTSMD(station(), sector());
0241 if (ntsstsmd < 2 || ntsstsmd > DTConfigTSPhi::NTSSTSMD) {
0242 edm::LogWarning("DTTSPhi") << " addTracoT - wrong TSMD: " << ntsstsmd;
0243 }
0244
0245
0246 itsmd = (my_itss - 1) / ntsstsmd + 1;
0247 if (config()->debug()) {
0248 edm::LogInfo("DTTSPhi") << " addTracoT: itsmd = (my_itss -1 ) / ntsstsmd + 1 ---> my_itss = "
0249 << my_itss << " ntsstsmd = " << ntsstsmd << " itsmd = " << itsmd;
0250 }
0251 } else if (bkmod == 1) {
0252 itsmd = 1;
0253 }
0254 if (itsmd > 2)
0255 edm::LogWarning("DTTSPhi") << "****** RunTSPhi wrong itsmd = " << itsmd;
0256 DTTSM *tsm = getDTTSM(is, itsmd);
0257 tsm->addCand((*p)->getTrack(it));
0258 }
0259 }
0260 }
0261 }
0262
0263
0264
0265 std::vector<DTTSM *>::iterator p_tsm;
0266
0267 for (p_tsm = _tsm[is - DTConfigTSPhi::NSTEPF].begin(); p_tsm < _tsm[is - DTConfigTSPhi::NSTEPF].end(); p_tsm++) {
0268
0269
0270 i_tsmd = (*p_tsm)->number() - 1;
0271
0272 if ((*p_tsm)->nCand(1) > 0) {
0273 int bkmod = config()->TsmStatus().element(0);
0274
0275 (*p_tsm)->run(bkmod);
0276
0277
0278
0279
0280 if ((*p_tsm)->nTracks() > 0) {
0281
0282
0283 if ((*p_tsm)->getTrack(1)->tracoTr()->code() > 0) {
0284 DTTSCand *first = (*p_tsm)->getTrack(1);
0285 if (config()->TsmGetCarryFlag() == 0) {
0286
0287
0288 _cache.push_back(DTChambPhSegm(ChamberId(), is, (*p_tsm)->getTrack(1)->tracoTr(), 1));
0289 ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd]++;
0290 if (config()->debug())
0291 edm::LogInfo("DTTSPhi") << "ntsm = " << ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd] << " is = " << is
0292 << " i_tsmd = " << i_tsmd;
0293 if ((*p_tsm)->nTracks() > 1) {
0294 if ((*p_tsm)->getTrack(2)->tracoTr()->code() > 0) {
0295 ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd]++;
0296 if (config()->debug())
0297 edm::LogInfo("DTTSPhi") << "ntsm = " << ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd] << " is = " << is
0298 << " i_tsmd = " << i_tsmd;
0299
0300 secondPrevBx = (*p_tsm)->getTrack(2);
0301 }
0302 }
0303 } else if (config()->TsmGetCarryFlag() == 1) {
0304
0305 existSecondPrevBx =
0306 ((is - 1 - DTConfigTSPhi::NSTEPF >= 0) && (ntsm[is - 1 - DTConfigTSPhi::NSTEPF][i_tsmd] > 1) &&
0307 (secondPrevBx->tracoTr()->code() > 0));
0308 if ((!existSecondPrevBx) ||
0309 !((secondPrevBx->isCorr() && secondPrevBx->isHtrig() && secondPrevBx->isInner()) ||
0310 (secondPrevBx->isCorr() && secondPrevBx->isHtrig() && !secondPrevBx->isInner()) ||
0311 (!secondPrevBx->isCorr() && secondPrevBx->isHtrig() && secondPrevBx->isInner())) ||
0312
0313 ((secondPrevBx->isCorr() && secondPrevBx->isHtrig() && secondPrevBx->isInner()) &&
0314 (first->isCorr() && first->isHtrig() && first->isInner())) ||
0315
0316 ((secondPrevBx->isCorr() && secondPrevBx->isHtrig() && !secondPrevBx->isInner()) &&
0317 ((first->isCorr() && first->isHtrig() && first->isInner()) ||
0318 (first->isCorr() && first->isHtrig() && !first->isInner()))) ||
0319
0320 ((!secondPrevBx->isCorr() && secondPrevBx->isHtrig() && secondPrevBx->isInner()) &&
0321 !((!first->isCorr() && first->isHtrig() && !first->isInner()) ||
0322 (!first->isCorr() && !first->isHtrig() && first->isInner()) ||
0323 (!first->isCorr() && !first->isHtrig() && !first->isInner()) ||
0324 (first->isCorr() && !first->isHtrig() && !first->isInner()) ||
0325 (first->isCorr() && !first->isHtrig() && first->isInner())))) {
0326
0327 ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd]++;
0328
0329
0330
0331 _cache.push_back(DTChambPhSegm(ChamberId(), is, (*p_tsm)->getTrack(1)->tracoTr(), 1));
0332
0333
0334 if ((*p_tsm)->nTracks() > 1) {
0335 ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd]++;
0336 if ((*p_tsm)->getTrack(2)->tracoTr()->code() > 0) {
0337 secondPrevBx = (*p_tsm)->getTrack(2);
0338 }
0339 }
0340 } else {
0341
0342 ntsm[is - 1 - DTConfigTSPhi::NSTEPF][i_tsmd]++;
0343 _cache.push_back(DTChambPhSegm(ChamberId(), is - 1, secondPrevBx->tracoTr(), 2));
0344
0345 }
0346 }
0347
0348 else if (config()->TsmGetCarryFlag() == 2) {
0349
0350 existSecondPrevBx =
0351 ((is - 1 - DTConfigTSPhi::NSTEPF >= 0) && (ntsm[is - 1 - DTConfigTSPhi::NSTEPF][i_tsmd] > 1) &&
0352 (secondPrevBx->tracoTr()->code() > 0));
0353 if ((!existSecondPrevBx) || first->isHtrig() || first->isCorr()) {
0354 ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd]++;
0355
0356 _cache.push_back(DTChambPhSegm(ChamberId(), is, (*p_tsm)->getTrack(1)->tracoTr(), 1));
0357
0358
0359 if ((*p_tsm)->nTracks() > 1) {
0360 ntsm[is - DTConfigTSPhi::NSTEPF][i_tsmd]++;
0361 if ((*p_tsm)->getTrack(2)->tracoTr()->code() > 0) {
0362 secondPrevBx = (*p_tsm)->getTrack(2);
0363 }
0364 }
0365 } else {
0366 ntsm[is - 1 - DTConfigTSPhi::NSTEPF][i_tsmd]++;
0367 _cache.push_back(DTChambPhSegm(ChamberId(), is - 1, secondPrevBx->tracoTr(), 2));
0368
0369 }
0370 }
0371 }
0372 }
0373
0374 } else if (((*p_tsm)->nCand(1) == 0) && (is - 1 - DTConfigTSPhi::NSTEPF >= 0) &&
0375 ntsm[is - 1 - DTConfigTSPhi::NSTEPF][i_tsmd] >
0376 0) {
0377
0378 existSecondPrevBx =
0379 ((is - 1 - DTConfigTSPhi::NSTEPF >= 0) && (ntsm[is - 1 - DTConfigTSPhi::NSTEPF][i_tsmd] > 1) &&
0380 (secondPrevBx->tracoTr()->code() > 0));
0381 if (existSecondPrevBx) {
0382 _cache.push_back(DTChambPhSegm(ChamberId(), is - 1, secondPrevBx->tracoTr(), 2));
0383
0384
0385 }
0386 }
0387 }
0388
0389
0390 }
0391
0392 if (config()->debug()) {
0393 if (!_cache.empty()) {
0394 edm::LogInfo("DTTSPhi") << " Phi segments ";
0395 std::vector<DTChambPhSegm>::const_iterator p;
0396 for (p = _cache.begin(); p < _cache.end(); p++) {
0397 p->print();
0398 }
0399 }
0400 }
0401
0402 }
0403
0404 void DTTSPhi::ignoreSecondTrack(int step, int tracon) {
0405 int itsmd = 1;
0406
0407 if (step < DTConfigTSPhi::NSTEPF || step > DTConfigTSPhi::NSTEPL) {
0408 edm::LogWarning("DTTSPhi") << "ignoreSecondTrack: step out of range: " << step << " no flag set!";
0409 return;
0410 }
0411 int itss = (tracon - 1) / DTConfigTSPhi::NTCTSS + 1;
0412 if (itss < 1 || itss > DTConfigTSPhi::NTSSTSM) {
0413 edm::LogWarning("DTTSPhi") << "ignoreSecondTrack: wrong TRACO number: " << tracon << " no flag set!";
0414 return;
0415 }
0416 DTTSS *tss = getDTTSS(step, itss);
0417 tss->ignoreSecondTrack();
0418
0419 int bkmod = config()->TsmStatus().element(0);
0420 if (bkmod == 0) {
0421
0422 int ntsstsmd = config()->TSSinTSMD(station(), sector());
0423
0424 itsmd = (itss - 1) / ntsstsmd + 1;
0425 }
0426
0427 DTTSM *tsm = getDTTSM(step, itsmd);
0428 tsm->ignoreSecondTrack();
0429 }
0430
0431 DTTSS *DTTSPhi::getDTTSS(int step, unsigned n) const {
0432 if (step < DTConfigTSPhi::NSTEPF || step > DTConfigTSPhi::NSTEPL) {
0433 edm::LogWarning("DTTSPhi") << "getDTTSS: step out of range: " << step << " empty pointer returned!";
0434 return nullptr;
0435 }
0436 if (n < 1 || n > _tss[step - DTConfigTSPhi::NSTEPF].size()) {
0437 edm::LogWarning("DTTSPhi") << "getDTTSS: requested DTTSS not present: " << n << " (at step " << step << ")"
0438 << " empty pointer returned!";
0439 return nullptr;
0440 }
0441
0442 std::vector<DTTSS *>::const_iterator p = _tss[step - DTConfigTSPhi::NSTEPF].begin() + n - 1;
0443 return *p;
0444 }
0445
0446 DTTSM *DTTSPhi::getDTTSM(int step, unsigned n) const {
0447 if (step < DTConfigTSPhi::NSTEPF || step > DTConfigTSPhi::NSTEPL) {
0448 edm::LogWarning("DTTSPhi") << "getDTTSM: step out of range: " << step << " empty pointer returned!";
0449 return nullptr;
0450 }
0451 if (n < 1 || n > _tsm[step - DTConfigTSPhi::NSTEPF].size()) {
0452 edm::LogWarning("DTTSPhi") << "getDTTSM: requested DTTSM not present: " << n << " (at step " << step << ")"
0453 << " empty pointer returned!";
0454 return nullptr;
0455 }
0456 std::vector<DTTSM *>::const_iterator p_tsm = _tsm[step - DTConfigTSPhi::NSTEPF].begin() + n - 1;
0457 return *p_tsm;
0458 }
0459
0460 int DTTSPhi::nSegm(int step) {
0461 int n = 0;
0462 std::vector<DTChambPhSegm>::const_iterator p;
0463 for (p = begin(); p < end(); p++) {
0464 if (p->step() == step)
0465 n++;
0466 }
0467 return n;
0468 }
0469
0470 const DTChambPhSegm *DTTSPhi::segment(int step, unsigned n) {
0471 std::vector<DTChambPhSegm>::const_iterator p;
0472 for (p = begin(); p < end(); p++) {
0473 if (p->step() == step && ((n == 1 && p->isFirst()) || (n == 2 && !p->isFirst())))
0474 return &(*p);
0475 }
0476 return nullptr;
0477 }
0478
0479 LocalPoint DTTSPhi::localPosition(const DTTrigData *tr) const {
0480
0481
0482
0483 const DTChambPhSegm *trig = dynamic_cast<const DTChambPhSegm *>(tr);
0484 if (!trig) {
0485 edm::LogWarning("DTTSPhi") << "LocalPosition called with wrong argument!";
0486 return LocalPoint(0, 0, 0);
0487 }
0488 return _tracocard->localPosition(trig->tracoTrig());
0489 }
0490
0491 LocalVector DTTSPhi::localDirection(const DTTrigData *tr) const {
0492 DTChambPhSegm *trig = dynamic_cast<DTChambPhSegm *>(const_cast<DTTrigData *>(tr));
0493
0494 if (!trig) {
0495 edm::LogWarning("DTTSPhi") << "LocalDirection called with wrong argument!";
0496 return LocalVector(0, 0, 0);
0497 }
0498 return _tracocard->localDirection(trig->tracoTrig());
0499 }