Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-22 22:37:18

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     if (curr == nullptr)
0123       continue;
0124     // SM sector collector Set bits for tss
0125     curr->setBitsTss();
0126     if (curr->dataword() == 0x1ff)
0127       continue;
0128     _logWord1[1 + curr->TcPos()] = (curr->isFirst()) ? '1' : '2';
0129     //     std::cout << "Running TSS: --->curr->dataword() sort 1 " <<
0130     //     curr->dataword()  << std::endl;
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   // Ghost 1 suppression: use carry only if not suppressed
0144 
0145   if (carry != nullptr) {  // A carry is present
0146 
0147     // Carry enabled if correlated and TRACO is next to best
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 && (                                      // Carry isn't always suppressed
0156                                              config()->TssGhost1Flag() == 0 ||  // Carry always enabled
0157                                              //       carry->isInner() ||                    // Carry is inner
0158                                              inner_or_corr ||                           // carry is inner or corr
0159                                              abs(carry->TcPos() - best->TcPos()) != 1)  // Carry not adj. to best
0160     ) {
0161       // add carry to second tracks for sort 2
0162       carry->setSecondTrack();      // change value of first/second track bit
0163       carry->setBitsTss();          // set quality bits as for second tracks
0164       _tctrig[1].push_back(carry);  // add to list of second tracks
0165     } else {
0166       _logWord1[1 + carry->TcPos()] = 'g';
0167     }
0168   }
0169 
0170   /*
0171   if(carry!=0 && config()->TssGhost1Flag()<2){ // Carry isn't always suppressed
0172     if(config()->TssGhost1Flag()==0 ||           // Carry always enabled
0173        carry->isInner() ||                       // Carry is inner
0174        abs(carry->TcPos()-best->TcPos())!=1) {   // Carry not adj. to best
0175        // add carry to second tracks to for sort 2
0176       carry->setSecondTrack(); // change value of first/second track bit
0177       carry->setBitsTss();     // set quality bits as for second tracks
0178       _tctrig[1].push_back(carry); // add to list of second tracks
0179     }
0180   }
0181   */
0182   // std::cout << " best TSS sort 1 = " << best->dataword() << std::endl;
0183   // std::cout << " SM end of TSS sort 1: best = " <<  std::endl;
0184   // best->print();
0185 
0186   return best;
0187 }
0188 
0189 DTTSCand *DTTSS::sortTSS2() {
0190   // Check if there are second tracks
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     // At the time being if a a first track at the following BX is present,
0199     // the carry is thrown
0200     //    std::vector<DTTSCand*>::iterator p;
0201     //    for(p=_tctrig[1].begin(); p!=_tctrig[1].end(); p++) {
0202     //      if((*p)->isCarry()) return (*p);
0203     //    }
0204     // Fill log word
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';  // out of time
0209     return nullptr;
0210   }
0211 
0212   // If second tracks are always suppressed skip processing
0213   if (config()->TssGhost2Flag() == 3) {
0214     // Fill log word
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   // If no first tracks at the following BX, do a sort 2
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     // SM sector collector set bits for tss
0228     curr->setBitsTss();
0229     //     std::cout << "Running TSS sort 2: --- curr->dataword() "  <<
0230     //     curr->dataword()  << std::endl;
0231     if (!curr->isCarry()) {
0232       _logWord2[1 + curr->TcPos()] = (curr->isFirst()) ? '1' : '2';
0233       if (curr->dataword() == 0x1ff)
0234         continue;
0235     }
0236     // ghost 2 suppression: skip track if suppressed
0237     if (config()->TssGhost2Flag() != 0) {  // 2nd tracks not always enabled
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           //! curr->isInner() &&               // outer track
0249           !inner_or_corr &&                                           // outer and not corr
0250           curr->TcPos() == best->TcPos()) {                           // same correlator of 1st track
0251         if (config()->TssGhost2Flag() == 2 ||                         // do not look to corr bit of 1st
0252             ((!best->isCorr()) && config()->TssGhost2Flag() != 4) ||  // skip if best is not corr
0253             ((!best->isCorr()) && best->isInner() &&
0254              config()->TssGhost2Flag() == 4))  // skip only if best is inner and not corr
0255         {
0256           _logWord2[1 + curr->TcPos()] = 'G';
0257           //      std::cout << " skip sort 2 in TSS" << std::endl;
0258           continue;  // skip track
0259         }
0260       }
0261     }
0262     if (second == nullptr) {
0263       second = curr;
0264     } else if ((*curr) <= (*second)) {
0265       second = curr;
0266     }
0267   }
0268   //  if(!second==0) {std::cout << " best sort 2 = " << second->dataword() <<
0269   //  std::endl;
0270   //   std::cout << " SM end of TSS sort 2: second = " <<  std::endl;
0271   //   second->print(); }
0272 
0273   return second;
0274 }
0275 
0276 void DTTSS::addDTTSCand(DTTSCand *cand) {
0277   int ifs = (cand->isFirst()) ? 0 : 1;
0278   //  std::cout << "SM DTTSS::addDTTSCand ifs = " << ifs << std::endl;
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 }