Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //-------------------------------------------------
0002 //
0003 //   Class: DTSectColl.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 : CoarseSync and Theta included
0012 //   11/12/06 C. Battilana : New Sector Collector Definition
0013 //   09/01/07 C. Battilana : moved to local conf
0014 //   mar07 - S. Vanini : parameters from DTConfigManager
0015 //
0016 //
0017 //--------------------------------------------------
0018 
0019 //-----------------------
0020 // This Class's Header --
0021 //-----------------------
0022 #include "L1Trigger/DTSectorCollector/interface/DTSectColl.h"
0023 
0024 //-------------------------------
0025 // Collaborating Class Headers --
0026 //-------------------------------
0027 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigSectColl.h"
0028 #include "L1Trigger/DTSectorCollector/interface/DTSC.h"
0029 #include "L1Trigger/DTSectorCollector/interface/DTSectCollThCand.h"
0030 #include "L1Trigger/DTSectorCollector/interface/DTSectCollPhCand.h"
0031 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSPhi.h"
0032 #include "L1Trigger/DTTriggerServerTheta/interface/DTTSTheta.h"
0033 #include "L1Trigger/DTTriggerServerPhi/interface/DTChambPhSegm.h"
0034 #include "L1Trigger/DTTriggerServerTheta/interface/DTChambThSegm.h"
0035 #include "L1Trigger/DTSectorCollector/interface/DTSCTrigUnit.h"
0036 
0037 //---------------
0038 // C++ Headers --
0039 //---------------
0040 #include <iostream>
0041 #include <algorithm>
0042 
0043 //----------------
0044 // Constructors --
0045 //----------------
0046 
0047 DTSectColl::DTSectColl(DTSectCollId id) : _sectcollid(id) {
0048   //_config = _conf_manager->getDTConfigSectColl(_sectcollid);
0049 
0050   // create SC Chips
0051   for (int istat = 0; istat < 4; istat++) {
0052     for (int istep = 0; istep < DTConfigSectColl::NSTEPL - DTConfigSectColl::NSTEPF + 1; istep++) {
0053       _tsc[istep][istat] = new DTSC(istat + 1);
0054     }
0055   }
0056   for (int istat = 0; istat < 5; istat++)
0057     _tsphi[istat] = nullptr;
0058   for (int istat = 0; istat < 3; istat++)
0059     _tstheta[istat] = nullptr;
0060 }
0061 
0062 //--------------
0063 // Destructor --
0064 //--------------
0065 DTSectColl::~DTSectColl() {
0066   localClear();
0067 
0068   for (int istat = 0; istat < 4; istat++) {
0069     for (int istep = 0; istep < DTConfigSectColl::NSTEPL - DTConfigSectColl::NSTEPF + 1; istep++) {
0070       delete _tsc[istep][istat];
0071     }
0072   }
0073 }
0074 
0075 //--------------
0076 // Operations --
0077 //--------------
0078 
0079 void DTSectColl::localClear() {
0080   // clear all sector collectors
0081   for (int istat = 0; istat < 4; istat++) {
0082     for (int istep = 0; istep < DTConfigSectColl::NSTEPL - DTConfigSectColl::NSTEPF + 1; istep++) {
0083       _tsc[istep][istat]->clear();
0084     }
0085   }
0086 
0087   for (int iph = 0; iph < 2; ++iph) {
0088     std::vector<DTSectCollPhCand*>::const_iterator phbi = _incand_ph[iph].begin();
0089     std::vector<DTSectCollPhCand*>::const_iterator phei = _incand_ph[iph].end();
0090     for (std::vector<DTSectCollPhCand*>::const_iterator iphit = phbi; iphit != phei; ++iphit)
0091       delete (*iphit);
0092     _incand_ph[iph].clear();
0093   }
0094 
0095   _outcand_ph.clear();
0096 
0097   std::vector<DTSectCollThCand*>::const_iterator thb = _incand_th.begin();
0098   std::vector<DTSectCollThCand*>::const_iterator the = _incand_th.end();
0099   for (std::vector<DTSectCollThCand*>::const_iterator ithit = thb; ithit != the; ++ithit)
0100     delete (*ithit);
0101   _incand_th.clear();
0102 
0103   _outcand_th.clear();
0104 }
0105 
0106 void DTSectColl::setConfig(const DTConfigManager* conf) {
0107   _config = conf->getDTConfigSectColl(_sectcollid);
0108 
0109   for (int istat = 0; istat < 4; istat++) {
0110     for (int istep = 0; istep < DTConfigSectColl::NSTEPL - DTConfigSectColl::NSTEPF + 1; istep++) {
0111       _tsc[istep][istat]->setConfig(config());
0112     }
0113   }
0114 }
0115 
0116 void DTSectColl::addTU(DTSCTrigUnit* tru /*, int flag*/) {
0117   int stat = tru->station();
0118   int sect = tru->sector();
0119   switch (sect) {
0120     case 13:
0121       stat = 5;
0122       sect = 4;
0123       break;
0124     case 14:
0125       stat = 5;
0126       sect = 10;
0127       break;
0128   }
0129 
0130   if (_sectcollid != DTSectCollId() && _sectcollid != DTSectCollId(tru->wheel(), sect)) {
0131     std::cout << "DTSectColl::addTU: Trying to add tru " << tru << " into SectColl " << _sectcollid
0132               << " Skipping insertion" << std::endl;
0133     return;
0134   }
0135 
0136   if (stat < 1 || stat > 5) {
0137     std::cout << "DTSectColl::addTU: Wrong station number Skipping insertion" << std::endl;
0138     return;
0139   }
0140 
0141   _tsphi[stat - 1] = tru->TSPhTrigs();
0142   if (stat < 4)
0143     _tstheta[stat - 1] = tru->TSThTrigs();
0144 
0145   if (_sectcollid == DTSectCollId())
0146     _sectcollid = DTSectCollId(tru->wheel(), sect);
0147 
0148   // add a Trigger Unit to the Sector Collector
0149   //   if(flag==2) {
0150   //        _tsphi1 = tru->TSPhTrigs();    // these are the "normal" stations
0151   //        _tsphi2 = 0;
0152   //        _tstheta = tru->TSThTrigs();
0153   //   }
0154   //   else if (flag==0){
0155   //     _tsphi1 = tru->TSPhTrigs();
0156   //     _tstheta = 0;
0157   //   }
0158   //   else if(flag==1) {
0159   //     _tsphi2 = tru->TSPhTrigs();        // these are the "double" stations
0160   //     _tstheta = 0;
0161   //   }
0162   //   // generates SectColl Id from tsphi Id
0163   //   if (flag==2 || flag==0){
0164   //     int sect  = tru->sector();
0165   //     if (sect == 13) sect=4;
0166   //     if (sect == 14) sect=10;
0167   //     _sectcollid=DTSectCollId(tru->wheel(),tru->station(),sect);
0168   //   }
0169 }
0170 
0171 void DTSectColl::loadSectColl() {
0172   localClear();
0173 
0174   std::vector<DTChambPhSegm>::const_iterator p;
0175   std::vector<DTChambPhSegm>::const_iterator pend;
0176 
0177   for (int istat = 1; istat < 5; istat++) {
0178     pend = _tsphi[istat - 1]->end();
0179     for (p = _tsphi[istat - 1]->begin(); p != pend; p++) {
0180       int step = p->step();
0181       int fs = (p->isFirst()) ? 1 : 2;
0182       // load trigger
0183       addTSPhi(step, &(*p), fs, istat);
0184     }
0185   }
0186 
0187   if (!(_tsphi[4] == nullptr)) {  // only for double stations
0188     pend = _tsphi[4]->end();
0189     for (p = _tsphi[4]->begin(); p != pend; p++) {
0190       int step = p->step();
0191       int fs = (p->isFirst()) ? 1 : 2;
0192       // load trigger
0193       addTSPhi(step, &(*p), fs, 4);
0194     }
0195   }
0196   std::vector<DTChambThSegm>::const_iterator pth;
0197   std::vector<DTChambThSegm>::const_iterator pthend;
0198 
0199   for (int istat = 1; istat < 4; istat++) {
0200     pthend = _tstheta[istat - 1]->end();
0201     for (pth = _tstheta[istat - 1]->begin(); pth != pthend; pth++) {
0202       int step = pth->step();
0203       // load trigger
0204       addTSTheta(step, &(*pth), istat);
0205     }
0206   }
0207 }
0208 
0209 void DTSectColl::addTSPhi(int step, const DTChambPhSegm* tsmsegm, int ifs, int istat) {
0210   if (step < DTConfigSectColl::NSTEPF || step > DTConfigSectColl::NSTEPL) {
0211     std::cout << "DTSectColl::addTSPhi: step out of range: " << step;
0212     std::cout << " trigger not added!" << std::endl;
0213     return;
0214   }
0215 
0216   if (istat < 1 || istat > 4) {
0217     std::cout << "DTSectColl::addTSPhi: station out of SC range: " << istat;
0218     std::cout << " trigger not added!" << std::endl;
0219     return;
0220   }
0221 
0222   // Check that a trigger is present, by its code
0223   if (tsmsegm->oldCode() == 0) {
0224     std::cout << "DTSectColl::addTSPhi -->  code = 0 ! ";
0225     std::cout << " trigger not added!" << std::endl;
0226     return;
0227   }
0228 
0229   DTSC* tsc = getDTSC(step, istat);
0230 
0231   DTSectCollPhCand* cand = new DTSectCollPhCand(tsc, tsmsegm, ifs);
0232 
0233   bool fs = (ifs == 1);
0234   _incand_ph[fs].push_back(cand);
0235 
0236   tsc->addDTSectCollPhCand(cand);
0237 
0238   // Debugging...
0239   if (config()->debug()) {
0240     std::cout << "DTSectColl::addTSPhi at step " << step;
0241     std::cout << " in SC station " << istat;
0242     if (ifs == 1) {
0243       std::cout << " (first track)" << std::endl;
0244     } else {
0245       std::cout << " (second track)" << std::endl;
0246     }
0247   }
0248 }
0249 
0250 void DTSectColl::addTSTheta(int step, const DTChambThSegm* tstsegm, int istat) {
0251   if (step < DTConfigSectColl::NSTEPF || step > DTConfigSectColl::NSTEPL) {
0252     std::cout << "DTSectColl::addTSTheta: step out of range: " << step;
0253     std::cout << " trigger not added!" << std::endl;
0254     return;
0255   }
0256 
0257   if (istat < 1 || istat > 5) {
0258     std::cout << "DTSectColl::addTSTheta: station out of SC range: " << istat;
0259     std::cout << " trigger not added!" << std::endl;
0260     return;
0261   }
0262 
0263   // Check if a trigger is present in theta
0264   bool is_empty = false;
0265   for (int i = 0; i < 7; i++)
0266     if (tstsegm->position(i) == 1) {
0267       is_empty = false;
0268       break;
0269     }
0270   if (is_empty == true) {
0271     std::cout << "DTSectColl::addTSTheta --> no position bit equal to 1 ! ";
0272     std::cout << " trigger not added!" << std::endl;
0273     return;
0274   }
0275 
0276   DTSC* tsc = getDTSC(step, istat);
0277 
0278   DTSectCollThCand* cand = new DTSectCollThCand(tsc, tstsegm);
0279 
0280   _incand_th.push_back(cand);
0281 
0282   tsc->addThCand(cand);
0283 
0284   // Debugging...
0285   if (config()->debug()) {
0286     std::cout << "DTSectColl::addTSTheta at step " << step << std::endl;
0287   }
0288 }
0289 
0290 DTSC* DTSectColl::getDTSC(int step, int istat) const {
0291   if (step < DTConfigSectColl::NSTEPF || step > DTConfigSectColl::NSTEPL) {
0292     std::cout << "DTSectColl::getDTSC: step out of range: " << step;
0293     std::cout << " empty pointer returned!" << std::endl;
0294     return nullptr;
0295   }
0296 
0297   if (istat < 1 || istat > 4) {
0298     std::cout << "DTSectColl::getDTSC: station out of SC range: " << istat;
0299     std::cout << " emty pointer returned!" << std::endl;
0300     return nullptr;
0301   }
0302 
0303   return _tsc[step - DTConfigSectColl::NSTEPF][istat - 1];
0304 }
0305 
0306 void DTSectColl::runSectColl() {
0307   for (int istat = 0; istat < 4; istat++) {
0308     for (int istep = DTConfigSectColl::NSTEPF; istep < DTConfigSectColl::NSTEPL + 1; istep++) {
0309       if (_tsc[istep - DTConfigSectColl::NSTEPF][istat]->nFirstTPh() > 0 ||
0310           _tsc[istep - DTConfigSectColl::NSTEPF][istat]->nCandTh() > 0) {
0311         _tsc[istep - DTConfigSectColl::NSTEPF][istat]->run();
0312 
0313         if (_tsc[istep - DTConfigSectColl::NSTEPF][istat]->nTracksPh() > 0) {
0314           DTSectCollPhCand* cand = _tsc[istep - DTConfigSectColl::NSTEPF][istat]->getTrackPh(1);
0315           DTSCPhCache::_cache.push_back(DTSectCollPhSegm(SectCollId(), istep + cand->CoarseSync(), cand->tsTr(), 1));
0316           _outcand_ph.push_back(cand);
0317 
0318           if (_tsc[istep - DTConfigSectColl::NSTEPF][istat]->nTracksPh() > 1) {
0319             DTSectCollPhCand* cand = _tsc[istep - DTConfigSectColl::NSTEPF][istat]->getTrackPh(2);
0320             DTSCPhCache::_cache.push_back(DTSectCollPhSegm(SectCollId(), istep + cand->CoarseSync(), cand->tsTr(), 2));
0321             _outcand_ph.push_back(cand);
0322           }
0323         }
0324         if (_tsc[istep - DTConfigSectColl::NSTEPF][istat]->nTracksTh() > 0) {
0325           DTSectCollThCand* cand = _tsc[istep - DTConfigSectColl::NSTEPF][istat]->getTrackTh(1);
0326           DTSCThCache::_cache.push_back(DTSectCollThSegm(SectCollId(), istep + cand->CoarseSync(), cand->tsTr()));
0327           _outcand_th.push_back(cand);  // CB getTrackTh non dovrebbe prendere argomenti modificala!
0328         }
0329       }
0330     }
0331   }
0332 
0333   // debugging...
0334   if (config()->debug()) {
0335     if (!DTSCPhCache::_cache.empty() || !DTSCThCache::_cache.empty()) {
0336       std::cout << "====================================================" << std::endl;
0337       std::cout << "                  Sect Coll segments                      " << std::endl;
0338       if (!DTSCPhCache::_cache.empty()) {
0339         std::cout << "                  ***Phi Segments***                      " << std::endl;
0340         std::vector<DTSectCollPhSegm>::const_iterator pph;
0341         for (pph = DTSCPhCache::_cache.begin(); pph < DTSCPhCache::_cache.end(); pph++) {
0342           pph->print();
0343         }
0344       }
0345       if (!DTSCThCache::_cache.empty()) {
0346         std::cout << "                  **Theta Segments**                      " << std::endl;
0347         std::vector<DTSectCollThSegm>::const_iterator pth;
0348         for (pth = DTSCThCache::_cache.begin(); pth < DTSCThCache::_cache.end(); pth++) {
0349           pth->print();
0350         }
0351       }
0352       std::cout << "====================================================" << std::endl;
0353     }
0354   }
0355   //  end debugging
0356 }
0357 
0358 DTSectCollPhCand* DTSectColl::getDTSectCollPhCand(int ifs, unsigned n) const {
0359   if (ifs < 1 || ifs > 2) {
0360     std::cout << "DTSectColl::getDTSectCollPhCand: wrong track number: " << ifs;
0361     std::cout << " empty pointer returned!" << std::endl;
0362     return nullptr;
0363   }
0364   if (n < 1 || n > nCandPh(ifs)) {
0365     std::cout << "DTSectColl::getDTSectCollPhCand: requested trigger not present: " << n;
0366     std::cout << " empty pointer returned!" << std::endl;
0367     return nullptr;
0368   }
0369 
0370   std::vector<DTSectCollPhCand*>::const_iterator p = _incand_ph[ifs - 1].begin() + n - 1;
0371   return (*p);
0372 }
0373 
0374 DTSectCollThCand* DTSectColl::getDTSectCollThCand(unsigned n) const {
0375   if (n < 1 || n > nCandTh()) {
0376     std::cout << "DTSectColl::getDTSectCollThCand: requested trigger not present: " << n;
0377     std::cout << " empty pointer returned!" << std::endl;
0378     return nullptr;
0379   }
0380 
0381   std::vector<DTSectCollThCand*>::const_iterator p = _incand_th.begin() + n - 1;
0382   return (*p);
0383 }
0384 
0385 DTSectCollPhCand* DTSectColl::getTrackPh(int n) const {
0386   if (n < 1 || n > nTracksPh()) {
0387     std::cout << "DTSectColl::getTrackPh: requested track not present: " << n;
0388     std::cout << " empty pointer returned!" << std::endl;
0389     return nullptr;
0390   }
0391 
0392   std::vector<DTSectCollPhCand*>::const_iterator p = _outcand_ph.begin() + n - 1;
0393   return (*p);
0394 }
0395 
0396 DTSectCollThCand* DTSectColl::getTrackTh(int n) const {
0397   if (n < 1 || n > nTracksTh()) {
0398     std::cout << "DTSectColl::getTrackTh: requested track not present: " << n;
0399     std::cout << " empty pointer returned!" << std::endl;
0400     return nullptr;
0401   }
0402 
0403   std::vector<DTSectCollThCand*>::const_iterator p = _outcand_th.begin() + n - 1;
0404   return (*p);
0405 }
0406 
0407 unsigned DTSectColl::nCandPh(int ifs) const {
0408   if (ifs < 1 || ifs > 2) {
0409     std::cout << "DTSectColl::nCandPh: wrong track number: " << ifs;
0410     std::cout << " 0 returned!" << std::endl;
0411     return 0;
0412   }
0413 
0414   return _incand_ph[ifs - 1].size();
0415 }
0416 
0417 unsigned DTSectColl::nCandTh() const { return _incand_th.size(); }
0418 
0419 int DTSectColl::nSegmPh(int step) {
0420   int n = 0;
0421   std::vector<DTSectCollPhSegm>::const_iterator p;
0422   std::vector<DTSectCollPhSegm>::const_iterator endp = DTSCPhCache::end();
0423   for (p = DTSCPhCache::begin(); p < endp; p++) {
0424     if (p->step() == step)
0425       n++;
0426   }
0427 
0428   return n;
0429 }
0430 
0431 int DTSectColl::nSegmTh(int step) {
0432   int n = 0;
0433   std::vector<DTSectCollThSegm>::const_iterator p;
0434   std::vector<DTSectCollThSegm>::const_iterator endp = DTSCThCache::end();
0435   for (p = DTSCThCache::begin(); p > endp; p++) {
0436     if (p->step() == step)
0437       n++;
0438   }
0439 
0440   return n;
0441 }
0442 
0443 const DTSectCollPhSegm* DTSectColl::SectCollPhSegment(int step, unsigned n) {
0444   std::vector<DTSectCollPhSegm>::const_iterator p;
0445   std::vector<DTSectCollPhSegm>::const_iterator endp = DTSCPhCache::end();
0446   for (p = DTSCPhCache::begin(); p < endp; p++) {
0447     if (p->step() == step && ((n == 1 && p->isFirst()) || (n == 2 && !p->isFirst())))
0448       return &(*p);
0449   }
0450 
0451   return nullptr;
0452 }
0453 
0454 const DTSectCollThSegm* DTSectColl::SectCollThSegment(int step) {
0455   std::vector<DTSectCollThSegm>::const_iterator p;
0456   std::vector<DTSectCollThSegm>::const_iterator endp = DTSCThCache::end();
0457   for (p = DTSCThCache::begin(); p < endp; p++) {
0458     if (p->step() == step)
0459       return &(*p);
0460   }
0461 
0462   return nullptr;
0463 }