Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:50

0001 //-------------------------------------------------
0002 //
0003 //   Class: DTTSM.cpp
0004 //
0005 //   Description: Implementation of DTTSM trigger algorithm
0006 //
0007 //
0008 //   Author List:
0009 //   C. Grandi
0010 //   Modifications:
0011 //   S. Marcellini, D. Bonacorsi
0012 //   04/01/2007 : C.Battilana local config update
0013 //
0014 //
0015 //--------------------------------------------------
0016 
0017 //-----------------------
0018 // This Class's Header --
0019 //-----------------------
0020 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSM.h"
0021 
0022 //-------------------------------
0023 // Collaborating Class Headers --
0024 //-------------------------------
0025 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSCand.h"
0026 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigTSPhi.h"
0027 
0028 //---------------
0029 // C++ Headers --
0030 //---------------
0031 #include <algorithm>
0032 #include <iostream>
0033 
0034 //----------------
0035 // Constructors --
0036 //----------------
0037 // DBSM-doubleTSM
0038 DTTSM::DTTSM(int n) : _n(n), _ignoreSecondTrack(0) {
0039   // reserve the appropriate amount of space for vectors
0040   _incand[0].reserve(DTConfigTSPhi::NTSSTSM);
0041   _incand[1].reserve(DTConfigTSPhi::NTSSTSM);
0042   _outcand.reserve(2);
0043 }
0044 
0045 //--------------
0046 // Destructor --
0047 //--------------
0048 DTTSM::~DTTSM() { clear(); }
0049 
0050 //--------------
0051 // Operations --
0052 //--------------
0053 
0054 void DTTSM::clear() {
0055   _ignoreSecondTrack = 0;
0056   for (int itk = 0; itk <= 1; itk++) {
0057     // content of _incand is deleted by DTTSPhi
0058     _incand[itk].clear();
0059   }
0060   // content of _outcand is deleted by DTTSPhi
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;  // skip if no first tracks
0072   //
0073   // SORT 1
0074   //
0075 
0076   // debugging
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   // end debugging
0085 
0086   DTTSCand *first = sortTSM1(bkmod);
0087   if (first != nullptr) {
0088     _outcand.push_back(first);
0089   }
0090   if (nSecondT() < 1)
0091     return;  // skip if no second tracks
0092 
0093   //
0094   // SORT 2
0095   //
0096 
0097   // debugging
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   // end debugging
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   // Do a sort 1
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) {         // NORMAL mode ---> sorting on dataword
0122       curr->setBitsTss();     // maybe not necessary, as they are the same as for
0123                               // TSS in the default
0124     } else if (bkmod == 0) {  //  { // BACKUP mode ---> sorting on modified dataword
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     }  // else { }
0140   }
0141 
0142   // Ghost 1 suppression: use carry only if not suppressed
0143   if (carry != nullptr) {  // A carry is present
0144 
0145     // Carry enabled if correlated and TRACO is next to best
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) {  // Carry isn't always suppressed
0154       // check if adjacent DTTracoChips
0155       int adj = (carry->tssNumber() == best->tssNumber() + 1 &&  // next DTTracoChip
0156                  best->TcPos() == DTConfigTSPhi::NTCTSS && carry->TcPos() == 1) ||
0157                 (carry->tssNumber() == best->tssNumber() - 1 &&  // prev DTTracoChip
0158                  best->TcPos() == 1 && carry->TcPos() == DTConfigTSPhi::NTCTSS) ||
0159                 (carry->tssNumber() == best->tssNumber() &&  // same DTTracoChip
0160                  abs(carry->TcPos() - best->TcPos()) == 1);
0161 
0162       if (config()->TsmGhost1Flag() == 0 ||  // Carry always enabled
0163                                              //       carry->isInner() || //
0164                                              //       Carry is inner
0165           inner_or_corr ||                   // Carry is inner or corr
0166           !adj) {                            // Carry not adj. to best
0167         // add carry to second tracks to for sort 2
0168         carry->setSecondTrack();  // change value of first/second track bit
0169         // NEW DESIGN: DTTSM is not configurable!
0170         // carry->setBitsTsm();     // set quality bits as for second tracks
0171         _incand[1].push_back(carry);  // add to list of second tracks
0172       }
0173     }
0174   }
0175   // best->print();
0176   return best;
0177 }
0178 
0179 DTTSCand *DTTSM::sortTSM2(int bkmod) {
0180   // If second tracks are always suppressed skip processing
0181   if (config()->TsmGhost2Flag() == 3)
0182     return nullptr;
0183 
0184   // Check if there are second tracks
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   // If a first track at the following BX is present, ignore second tracks of
0192   // any kind
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   // If no first tracks at the following BX, do a sort 2
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     // ghost 2 suppression: skip track if suppressed
0209     // this is not needed if config of DTTSM == config of DTTSS
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) {  // 2nd tracks not always enabled
0219       if (
0220           //! curr->isInner() &&                // outer track
0221           !inner_or_corr &&                                                              // outer and not corr
0222           (curr->tssNumber() == best->tssNumber() && curr->TcPos() == best->TcPos())) {  // same correlator of 1st track
0223         if (config()->TsmGhost2Flag() == 2 ||                         // do not look to corr bit of 1st
0224             ((!best->isCorr()) && config()->TsmGhost2Flag() != 4) ||  // skip if best is not corr
0225             ((!best->isCorr()) && best->isInner() &&
0226              config()->TsmGhost2Flag() == 4))  // skip only if best is inner and not corr
0227         {
0228           continue;  // skip track
0229         }
0230       }
0231     }
0232 
0233     // added DBSM
0234     // SM double TSM    if ( bkmod == 1 ) { // NORMAL mode ---> sorting with <
0235     if (bkmod == 1) {         // NORMAL mode ---> sorting on dataword
0236       curr->setBitsTss();     // maybe not necessary, as they are the same as for
0237                               // TSS in the default
0238     } else if (bkmod == 0) {  //  { // BACKUP mode ---> sorting on modified dataword
0239       curr->setBitsBkmod();
0240     } else {
0241       std::cout << " DTTSM::sortTSM2 bkmod not properly assigned!" << std::endl;
0242     }
0243 
0244     // added DBSM
0245     // SM double TSM    if ( bkmod == 1 ) { // NORMAL mode ---> sorting with <
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   // NEW DESIGN: DTTSM is not configurable!
0258   //  cand->resetCarry(); // reset carry information
0259   //  cand->setBitsTsm(); // set quality bits for DTTSM sorting
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 }