Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //-------------------------------------------------
0002 //
0003 //   Class: DTSC.cpp
0004 //
0005 //   Description: Implementation of DTSectColl trigger algorithm
0006 //
0007 //
0008 //   Author List:
0009 //   S. Marcellini
0010 //   Modifications:
0011 //   11/11/06 C. Battilana : theta cand added
0012 //   12/12/06 C. Battilana : _stat added
0013 //   09/01/07 C. Battilana : updated to local conf
0014 //
0015 //
0016 //--------------------------------------------------
0017 
0018 //-----------------------
0019 // This Class's Header --
0020 //-----------------------
0021 #include "L1Trigger/DTSectorCollector/interface/DTSC.h"
0022 
0023 //-------------------------------
0024 // Collaborating Class Headers --
0025 //-------------------------------
0026 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigSectColl.h"
0027 #include "L1Trigger/DTSectorCollector/interface/DTSectColl.h"
0028 #include "L1Trigger/DTSectorCollector/interface/DTSectCollPhCand.h"
0029 #include "L1Trigger/DTSectorCollector/interface/DTSectCollThCand.h"
0030 
0031 //---------------
0032 // C++ Headers --
0033 //---------------
0034 #include <iostream>
0035 #include <algorithm>
0036 
0037 //----------------
0038 // Constructors --
0039 //----------------
0040 
0041 DTSC::DTSC(int istat) : _ignoreSecondTrack(0), _stat(istat) {
0042   // reserve the appropriate amount of space for vectors
0043   // test _incand[0].reserve(DTConfigSectColl::NTSMSC);
0044   // test_incand[1].reserve(DTConfigSectColl::NTSMSC);
0045   // test _outcand.reserve(2);
0046 }
0047 
0048 //--------------
0049 // Destructor --
0050 //--------------
0051 DTSC::~DTSC() { clear(); }
0052 
0053 //--------------
0054 // Operations --
0055 //--------------
0056 
0057 void DTSC::clear() {
0058   _ignoreSecondTrack = 0;
0059 
0060   for (int itk = 0; itk <= 1; itk++) {
0061     _incand_ph[itk].clear();
0062   }
0063 
0064   _outcand_ph.clear();
0065   _cand_th.clear();
0066 }
0067 
0068 //
0069 void DTSC::run() {
0070   if (config()->debug()) {
0071     std::cout << "DTSC::run: Processing DTSectColl: ";
0072     std::cout << nFirstTPh() << " first & " << nSecondTPh() << " second Phi tracks ";
0073     std::cout << " - " << nCandTh() << " Theta tracks" << std::endl;
0074   }
0075 
0076   if (nFirstTPh() < 1)
0077     return;  // skip if no first tracks
0078              //
0079              // SORT 1
0080              //
0081 
0082   // debugging
0083   if (config()->debug()) {
0084     std::cout << "Vector of first Phi tracks in DTSectColl: " << std::endl;
0085     std::vector<DTSectCollPhCand*>::const_iterator p;
0086     for (p = _incand_ph[0].begin(); p != _incand_ph[0].end(); p++) {
0087       (*p)->print();
0088     }
0089   }
0090   // end debugging
0091 
0092   DTSectCollPhCand* first = DTSectCollsort1();
0093   if (config()->debug()) {
0094     std::cout << "SC: DTSC::run: first Phi track is = " << first << std::endl;
0095   }
0096   if (first != nullptr) {
0097     _outcand_ph.push_back(first);
0098   }
0099   if (nSecondTPh() < 1)
0100     return;  // skip if no second tracks
0101 
0102   //
0103   // SORT 2
0104   //
0105 
0106   // debugging
0107   if (config()->debug()) {
0108     std::vector<DTSectCollPhCand*>::const_iterator p;
0109     std::cout << "Vector of second Phi tracks in DTSectColl: " << std::endl;
0110     for (p = _incand_ph[1].begin(); p != _incand_ph[1].end(); p++) {
0111       (*p)->print();
0112     }
0113   }
0114   // end debugging
0115 
0116   DTSectCollPhCand* second = DTSectCollsort2();
0117   if (second != nullptr) {
0118     _outcand_ph.push_back(second);
0119   }
0120 }
0121 
0122 DTSectCollPhCand* DTSC::DTSectCollsort1() {
0123   // Do a sort 1
0124   DTSectCollPhCand* best = nullptr;
0125   DTSectCollPhCand* carry = nullptr;
0126   std::vector<DTSectCollPhCand*>::iterator p;
0127   for (p = _incand_ph[0].begin(); p != _incand_ph[0].end(); p++) {
0128     DTSectCollPhCand* curr = (*p);
0129 
0130     curr->setBitsSectColl();  // SM sector collector set bits in dataword to make SC sorting
0131 
0132     // NO Carry in Sector Collector sorting in default
0133     if (config()->SCGetCarryFlag(_stat)) {  // get carry
0134 
0135       if (best == nullptr) {
0136         best = curr;
0137       } else if ((*curr) < (*best)) {
0138         carry = best;
0139         best = curr;
0140       } else if (carry == nullptr) {
0141         carry = curr;
0142       } else if ((*curr) < (*carry)) {
0143         carry = curr;
0144       }
0145 
0146     } else if (config()->SCGetCarryFlag(_stat) == 0) {  // no carry (default)
0147       if (best == nullptr) {
0148         best = curr;
0149       } else if ((*curr) < (*best)) {
0150         best = curr;
0151       }
0152     }
0153 
0154     if (carry != nullptr && config()->SCGetCarryFlag(_stat)) {  // reassign carry to sort 2 candidates
0155       carry->setSecondTrack();                                  // change value of 1st/2nd track bit
0156       _incand_ph[1].push_back(carry);                           // add to list of 2nd track
0157     }
0158   }
0159 
0160   return best;
0161 }
0162 
0163 DTSectCollPhCand* DTSC::DTSectCollsort2() {
0164   // Check if there are second tracks
0165 
0166   if (nTracksPh() < 1) {
0167     std::cout << "DTSC::DTSectCollsort2: called with no first Phi track.";
0168     std::cout << " empty pointer returned!" << std::endl;
0169     return nullptr;
0170   }
0171   // If a first track at the following BX is present, ignore second tracks of any kind
0172   if (_ignoreSecondTrack) {
0173     for (std::vector<DTSectCollPhCand*>::iterator p = _incand_ph[1].begin(); p != _incand_ph[1].end(); p++) {
0174     }
0175     return nullptr;
0176   }
0177 
0178   // If no first tracks at the following BX, do a sort 2
0179   //  DTSectCollCand* best=getTrack(1);  ! not needed as lons as there is no comparison with best in sort 2
0180   DTSectCollPhCand* second = nullptr;
0181   std::vector<DTSectCollPhCand*>::iterator p;
0182   for (p = _incand_ph[1].begin(); p != _incand_ph[1].end(); p++) {
0183     DTSectCollPhCand* curr = (*p);
0184     curr->setBitsSectColl();  // SM sector collector set bits in dataword to make SC sorting
0185 
0186     if (second == nullptr) {
0187       second = curr;
0188     } else if ((*curr) < (*second)) {
0189       second = curr;
0190     }
0191   }
0192 
0193   return second;
0194 }
0195 
0196 void DTSC::addPhCand(DTSectCollPhCand* cand) { _incand_ph[(1 - cand->isFirst())].push_back(cand); }
0197 
0198 void DTSC::addThCand(DTSectCollThCand* cand) { _cand_th.push_back(cand); }
0199 
0200 unsigned DTSC::nCandPh(int ifs) const {
0201   if (ifs < 1 || ifs > 2) {
0202     std::cout << "DTSC::nCandPh: wrong track number: " << ifs;
0203     std::cout << " 0 returned!" << std::endl;
0204     return 0;
0205   }
0206   return _incand_ph[ifs - 1].size();
0207 }
0208 
0209 unsigned DTSC::nCandTh() const { return _cand_th.size(); }
0210 
0211 DTSectCollPhCand* DTSC::getDTSectCollPhCand(int ifs, unsigned n) const {
0212   if (ifs < 1 || ifs > 2) {
0213     std::cout << "DTSC::getDTSectCollPhCand: wrong track number: " << ifs;
0214     std::cout << " empty pointer returned!" << std::endl;
0215     return nullptr;
0216   }
0217   if (n < 1 || n > nCandPh(ifs)) {
0218     std::cout << "DTSC::getDTSectCollPhCand: requested trigger not present: " << n;
0219     std::cout << " empty pointer returned!" << std::endl;
0220     return nullptr;
0221   }
0222 
0223   std::vector<DTSectCollPhCand*>::const_iterator p = _incand_ph[ifs - 1].begin() + n - 1;
0224   return (*p);
0225 }
0226 
0227 DTSectCollThCand* DTSC::getDTSectCollThCand(unsigned n) const {
0228   if (n < 1 || n > nCandTh()) {
0229     std::cout << "DTSC::getDTSectCollThCand: requested trigger not present: " << n;
0230     std::cout << " empty pointer returned!" << std::endl;
0231     return nullptr;
0232   }
0233 
0234   std::vector<DTSectCollThCand*>::const_iterator p = _cand_th.begin() + n - 1;
0235   return (*p);
0236 }
0237 
0238 void DTSC::addDTSectCollPhCand(DTSectCollPhCand* cand) {
0239   int ifs = (cand->isFirst()) ? 0 : 1;
0240 
0241   _incand_ph[ifs].push_back(cand);
0242 }
0243 
0244 DTSectCollPhCand* DTSC::getTrackPh(int n) const {
0245   if (n < 1 || n > nTracksPh()) {
0246     std::cout << "DTSC::getTrackPh: requested track not present: " << n;
0247     std::cout << " empty pointer returned!" << std::endl;
0248     return nullptr;
0249   }
0250 
0251   std::vector<DTSectCollPhCand*>::const_iterator p = _outcand_ph.begin() + n - 1;
0252 
0253   return (*p);
0254 }
0255 
0256 DTSectCollThCand* DTSC::getTrackTh(int n) const {
0257   if (n < 1 || n > nTracksTh()) {
0258     std::cout << "DTSC::getTrackTh: requested track not present: " << n;
0259     std::cout << " empty pointer returned!" << std::endl;
0260     return nullptr;
0261   }
0262 
0263   std::vector<DTSectCollThCand*>::const_iterator p = _cand_th.begin() + n - 1;
0264 
0265   return (*p);
0266 }