Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:07

0001 //-------------------------------------------------
0002 //
0003 //   Class: DTTSS.cpp
0004 //
0005 //   Description: Implementation of DTTSS trigger algorithm
0006 //
0007 //
0008 //   Author List:
0009 //   C. Grandi
0010 //   Modifications:
0011 //   04/01/2007 : C. Battilana local config update
0012 //
0013 //
0014 //--------------------------------------------------
0015 
0016 //-----------------------
0017 // This Class's Header --
0018 //-----------------------
0019 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSS.h"
0020 
0021 //-------------------------------
0022 // Collaborating Class Headers --
0023 //-------------------------------
0024 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSCand.h"
0025 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigTSPhi.h"
0026 
0027 //---------------
0028 // C++ Headers --
0029 //---------------
0030 #include <algorithm>
0031 #include <iostream>
0032 
0033 //----------------
0034 // Constructors --
0035 //----------------
0036 DTTSS::DTTSS(int n) : _n(n), _ignoreSecondTrack(0) {
0037   // reserve the appropriate amount of space for vectors
0038   //_tctrig[0].reserve(DTConfigTSPhi::NTCTSS);
0039   //_tctrig[1].reserve(DTConfigTSPhi::NTCTSS);
0040   //_outcand.reserve(2);
0041   _logWord1 = "1/----";
0042   _logWord2 = "2/----";
0043 }
0044 
0045 //--------------
0046 // Destructor --
0047 //--------------
0048 DTTSS::~DTTSS() { clear(); }
0049 
0050 //--------------
0051 // Operations --
0052 //--------------
0053 
0054 void DTTSS::clear() {
0055   _ignoreSecondTrack = 0;
0056   for (int itk = 0; itk <= 1; itk++) {
0057     // content of _tctrig is deleted in the DTTSPhi
0058     _tctrig[itk].clear();
0059   }
0060   // content of _outcand is deleted in the DTTSPhi
0061   _outcand.clear();
0062 
0063   // log words
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;  // skip if no first tracks
0076   //
0077   // SORT 1
0078   //
0079   // debugging
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   // end debugging
0088 
0089   DTTSCand *first = sortTSS1();
0090   if (first != nullptr) {
0091     _outcand.push_back(first);
0092   }
0093 
0094   if (nSecondT() < 1)
0095     return;  // skip if no second tracks
0096   //
0097   // SORT 2
0098   //
0099   // debugging
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   // end debugging
0108 
0109   DTTSCand *second = sortTSS2();
0110   if (second != nullptr) {
0111     _outcand.push_back(second);
0112   }
0113 }
0114 
0115 DTTSCand *DTTSS::sortTSS1() {
0116   // Do a sort 1
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     // SM sector collector Set bits for tss
0123     curr->setBitsTss();
0124     if (curr->dataword() == 0x1ff)
0125       continue;
0126     _logWord1[1 + curr->TcPos()] = (curr->isFirst()) ? '1' : '2';
0127     //     std::cout << "Running TSS: --->curr->dataword() sort 1 " <<
0128     //     curr->dataword()  << std::endl;
0129     if (best == nullptr) {
0130       best = curr;
0131     } else if ((*curr) <= (*best)) {
0132       carry = best;
0133       best = curr;
0134     } else if (carry == nullptr) {
0135       carry = curr;
0136     } else if ((*curr) <= (*carry)) {
0137       carry = curr;
0138     }
0139   }
0140 
0141   // Ghost 1 suppression: use carry only if not suppressed
0142 
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()->TssGhost1Corr()) {
0148       inner_or_corr = carry->isInner() || carry->isCorr();
0149 
0150     } else {
0151       inner_or_corr = carry->isInner();
0152     }
0153     if (config()->TssGhost1Flag() < 2 && (                                      // Carry isn't always suppressed
0154                                              config()->TssGhost1Flag() == 0 ||  // Carry always enabled
0155                                              //       carry->isInner() ||                    // Carry is inner
0156                                              inner_or_corr ||                           // carry is inner or corr
0157                                              abs(carry->TcPos() - best->TcPos()) != 1)  // Carry not adj. to best
0158     ) {
0159       // add carry to second tracks for sort 2
0160       carry->setSecondTrack();      // change value of first/second track bit
0161       carry->setBitsTss();          // set quality bits as for second tracks
0162       _tctrig[1].push_back(carry);  // add to list of second tracks
0163     } else {
0164       _logWord1[1 + carry->TcPos()] = 'g';
0165     }
0166   }
0167 
0168   /*
0169   if(carry!=0 && config()->TssGhost1Flag()<2){ // Carry isn't always suppressed
0170     if(config()->TssGhost1Flag()==0 ||           // Carry always enabled
0171        carry->isInner() ||                       // Carry is inner
0172        abs(carry->TcPos()-best->TcPos())!=1) {   // Carry not adj. to best
0173        // add carry to second tracks to for sort 2
0174       carry->setSecondTrack(); // change value of first/second track bit
0175       carry->setBitsTss();     // set quality bits as for second tracks
0176       _tctrig[1].push_back(carry); // add to list of second tracks
0177     }
0178   }
0179   */
0180   // std::cout << " best TSS sort 1 = " << best->dataword() << std::endl;
0181   // std::cout << " SM end of TSS sort 1: best = " <<  std::endl;
0182   // best->print();
0183 
0184   return best;
0185 }
0186 
0187 DTTSCand *DTTSS::sortTSS2() {
0188   // Check if there are second tracks
0189   if (nTracks() < 1) {
0190     std::cout << "DTTSS::DTTSSsort2: called with no first track.";
0191     std::cout << " empty pointer returned!" << std::endl;
0192     return nullptr;
0193   }
0194 
0195   if (_ignoreSecondTrack) {
0196     // At the time being if a a first track at the following BX is present,
0197     // the carry is thrown
0198     //    std::vector<DTTSCand*>::iterator p;
0199     //    for(p=_tctrig[1].begin(); p!=_tctrig[1].end(); p++) {
0200     //      if((*p)->isCarry()) return (*p);
0201     //    }
0202     // Fill log word
0203     std::vector<DTTSCand *>::iterator p;
0204     for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++)
0205       if (!(*p)->isCarry())
0206         _logWord2[1 + (*p)->TcPos()] = 'o';  // out of time
0207     return nullptr;
0208   }
0209 
0210   // If second tracks are always suppressed skip processing
0211   if (config()->TssGhost2Flag() == 3) {
0212     // Fill log word
0213     std::vector<DTTSCand *>::iterator p;
0214     for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++)
0215       _logWord2[1 + (*p)->TcPos()] = 'G';
0216     return nullptr;
0217   }
0218 
0219   // If no first tracks at the following BX, do a sort 2
0220   DTTSCand *best = getTrack(1);
0221   DTTSCand *second = nullptr;
0222   std::vector<DTTSCand *>::iterator p;
0223   for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++) {
0224     DTTSCand *curr = (*p);
0225     // SM sector collector set bits for tss
0226     curr->setBitsTss();
0227     //     std::cout << "Running TSS sort 2: --- curr->dataword() "  <<
0228     //     curr->dataword()  << std::endl;
0229     if (!curr->isCarry()) {
0230       _logWord2[1 + curr->TcPos()] = (curr->isFirst()) ? '1' : '2';
0231       if (curr->dataword() == 0x1ff)
0232         continue;
0233     }
0234     // ghost 2 suppression: skip track if suppressed
0235     if (config()->TssGhost2Flag() != 0) {  // 2nd tracks not always enabled
0236 
0237       bool inner_or_corr;
0238       if (config()->TssGhost2Corr()) {
0239         inner_or_corr = curr->isInner() || curr->isCorr();
0240 
0241       } else {
0242         inner_or_corr = curr->isInner();
0243       }
0244 
0245       if (
0246           //! curr->isInner() &&               // outer track
0247           !inner_or_corr &&                                           // outer and not corr
0248           curr->TcPos() == best->TcPos()) {                           // same correlator of 1st track
0249         if (config()->TssGhost2Flag() == 2 ||                         // do not look to corr bit of 1st
0250             ((!best->isCorr()) && config()->TssGhost2Flag() != 4) ||  // skip if best is not corr
0251             ((!best->isCorr()) && best->isInner() &&
0252              config()->TssGhost2Flag() == 4))  // skip only if best is inner and not corr
0253         {
0254           _logWord2[1 + curr->TcPos()] = 'G';
0255           //      std::cout << " skip sort 2 in TSS" << std::endl;
0256           continue;  // skip track
0257         }
0258       }
0259     }
0260     if (second == nullptr) {
0261       second = curr;
0262     } else if ((*curr) <= (*second)) {
0263       second = curr;
0264     }
0265   }
0266   //  if(!second==0) {std::cout << " best sort 2 = " << second->dataword() <<
0267   //  std::endl;
0268   //   std::cout << " SM end of TSS sort 2: second = " <<  std::endl;
0269   //   second->print(); }
0270 
0271   return second;
0272 }
0273 
0274 void DTTSS::addDTTSCand(DTTSCand *cand) {
0275   int ifs = (cand->isFirst()) ? 0 : 1;
0276   //  std::cout << "SM DTTSS::addDTTSCand ifs = " << ifs << std::endl;
0277   _tctrig[ifs].push_back(cand);
0278 }
0279 
0280 unsigned DTTSS::nTracoT(int ifs) const {
0281   if (ifs < 1 || ifs > 2) {
0282     std::cout << "DTTSS::nTracoT: wrong track number: " << ifs;
0283     std::cout << " 0 returned!" << std::endl;
0284     return 0;
0285   }
0286   return _tctrig[ifs - 1].size();
0287 }
0288 
0289 DTTSCand *DTTSS::getDTTSCand(int ifs, unsigned n) const {
0290   if (ifs < 1 || ifs > 2) {
0291     std::cout << "DTTSS::getDTTSCand: wrong track number: " << ifs;
0292     std::cout << " empty pointer returned!" << std::endl;
0293     return nullptr;
0294   }
0295   if (n < 1 || n > nTracoT(ifs)) {
0296     std::cout << "DTTSS::getDTTSCand: requested trigger not present: " << n;
0297     std::cout << " empty pointer returned!" << std::endl;
0298     return nullptr;
0299   }
0300   std::vector<DTTSCand *>::const_iterator p = _tctrig[ifs - 1].begin() + n - 1;
0301   return (*p);
0302 }
0303 
0304 const DTTracoTrigData *DTTSS::getTracoT(int ifs, unsigned n) const {
0305   if (ifs < 1 || ifs > 2) {
0306     std::cout << "DTTSS::getTracoT: wrong track number: " << ifs;
0307     std::cout << " empty pointer returned!" << std::endl;
0308     return nullptr;
0309   }
0310   if (n < 1 || n > nTracoT(ifs)) {
0311     std::cout << "DTTSS::getTracoT: requested trigger not present: " << n;
0312     std::cout << " empty pointer returned!" << std::endl;
0313     return nullptr;
0314   }
0315   return getDTTSCand(ifs, n)->tracoTr();
0316 }
0317 
0318 DTTSCand *DTTSS::getTrack(int n) const {
0319   if (n < 1 || n > nTracks()) {
0320     std::cout << "DTTSS::getTrack: requested track not present: " << n;
0321     std::cout << " empty pointer returned!" << std::endl;
0322     return nullptr;
0323   }
0324   std::vector<DTTSCand *>::const_iterator p = _outcand.begin() + n - 1;
0325   return (*p);
0326 }
0327 
0328 DTTSCand *DTTSS::getCarry() const {
0329   std::vector<DTTSCand *>::const_iterator p;
0330   for (p = _tctrig[1].begin(); p != _tctrig[1].end(); p++)
0331     if ((*p)->isCarry())
0332       return (*p);
0333   return nullptr;
0334 }
0335 
0336 std::string DTTSS::logWord(int n) const {
0337   std::string lw = "";
0338   switch (n) {
0339     case 1:
0340       lw = _logWord1;
0341       break;
0342     case 2:
0343       lw = _logWord2;
0344       break;
0345     default:
0346       std::cout << "DTTSS::logWord: requested track not present: " << n;
0347       std::cout << " empty string returned!" << std::endl;
0348   }
0349   return lw;
0350 }