CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/L1Trigger/DTSectorCollector/src/DTSectColl.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: DTSectColl.cpp
00004 //
00005 //   Description: Implementation of DTSectColl trigger algorithm
00006 //
00007 //
00008 //   Author List:
00009 //   S. Marcellini
00010 //   Modifications:
00011 //   11/11/06 C. Battilana : CoarseSync and Theta included 
00012 //   11/12/06 C. Battilana : New Sector Collector Definition
00013 //   09/01/07 C. Battilana : moved to local conf
00014 //   mar07 - S. Vanini : parameters from DTConfigManager 
00015 //
00016 //
00017 //--------------------------------------------------
00018 
00019 
00020 //-----------------------
00021 // This Class's Header --
00022 //-----------------------
00023 #include "L1Trigger/DTSectorCollector/interface/DTSectColl.h"
00024 
00025 //-------------------------------
00026 // Collaborating Class Headers --
00027 //-------------------------------
00028 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigSectColl.h"
00029 #include "L1Trigger/DTSectorCollector/interface/DTSC.h"
00030 #include "L1Trigger/DTSectorCollector/interface/DTSectCollThCand.h"
00031 #include "L1Trigger/DTSectorCollector/interface/DTSectCollPhCand.h"
00032 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSPhi.h"
00033 #include "L1Trigger/DTTriggerServerTheta/interface/DTTSTheta.h"
00034 #include "L1Trigger/DTTriggerServerPhi/interface/DTChambPhSegm.h"
00035 #include "L1Trigger/DTTriggerServerTheta/interface/DTChambThSegm.h"
00036 #include "L1Trigger/DTSectorCollector/interface/DTSCTrigUnit.h"
00037 
00038 //---------------
00039 // C++ Headers --
00040 //---------------
00041 #include <iostream>
00042 #include <algorithm>
00043 
00044 //----------------
00045 // Constructors --
00046 //----------------
00047 
00048 DTSectColl::DTSectColl(DTSectCollId id) : _sectcollid(id){
00049 
00050   //_config = _conf_manager->getDTConfigSectColl(_sectcollid);
00051   
00052   // create SC Chips
00053   for(int istat=0;istat<4;istat++){
00054     for(int istep=0;istep<DTConfigSectColl::NSTEPL-DTConfigSectColl::NSTEPF+1;istep++) {
00055       _tsc[istep][istat] = new DTSC(istat+1);
00056     }
00057   }
00058   for (int istat=0;istat<5;istat++) _tsphi[istat]=0;
00059   for (int istat=0;istat<3;istat++) _tstheta[istat]=0;
00060 
00061 }
00062 
00063 //--------------
00064 // Destructor --
00065 //--------------
00066 DTSectColl::~DTSectColl(){
00067 
00068   localClear();
00069 
00070   for(int istat=0;istat<4;istat++){
00071     for(int istep=0;istep<DTConfigSectColl::NSTEPL-DTConfigSectColl::NSTEPF+1;istep++){
00072       delete _tsc[istep][istat];
00073     }
00074   }
00075 
00076 }
00077 
00078 
00079 //--------------
00080 // Operations --
00081 //--------------
00082 
00083 void
00084 DTSectColl::localClear() {
00085 
00086   // clear all sector collectors
00087   for(int istat=0;istat<4;istat++){
00088     for(int istep=0;istep<DTConfigSectColl::NSTEPL-DTConfigSectColl::NSTEPF+1;istep++) {
00089       _tsc[istep][istat]->clear();
00090     }
00091   }
00092   
00093   for(int iph=0;iph<2;++iph){
00094     std::vector<DTSectCollPhCand*>::const_iterator phbi = _incand_ph[iph].begin();
00095     std::vector<DTSectCollPhCand*>::const_iterator phei = _incand_ph[iph].end();
00096     for ( std::vector<DTSectCollPhCand*>::const_iterator iphit = phbi;iphit!= phei;++iphit)
00097       delete (*iphit);
00098     _incand_ph[iph].clear();
00099   }
00100   
00101   _outcand_ph.clear();
00102   
00103   std::vector<DTSectCollThCand*>::const_iterator thb = _incand_th.begin();
00104   std::vector<DTSectCollThCand*>::const_iterator the = _incand_th.end();
00105   for ( std::vector<DTSectCollThCand*>::const_iterator ithit = thb;ithit!= the;++ithit)
00106     delete (*ithit);
00107   _incand_th.clear();
00108   
00109   _outcand_th.clear();
00110   
00111 }
00112 
00113 void
00114 DTSectColl::setConfig (const DTConfigManager *conf){
00115 
00116   _config = conf->getDTConfigSectColl(_sectcollid);
00117 
00118   for(int istat=0;istat<4;istat++){
00119     for(int istep=0;istep<DTConfigSectColl::NSTEPL-DTConfigSectColl::NSTEPF+1;istep++){
00120       _tsc[istep][istat]->setConfig(config());
00121     }
00122   }
00123 
00124 }
00125 
00126 
00127 void
00128 DTSectColl::addTU(DTSCTrigUnit* tru /*, int flag*/) {
00129 
00130   int stat = tru->station();
00131   int sect = tru->sector();
00132   switch (sect){
00133   case 13:
00134     stat = 5;
00135     sect = 4;
00136     break;
00137   case 14:
00138     stat = 5;
00139     sect = 10;
00140     break;
00141   }
00142    
00143   if (_sectcollid!=DTSectCollId() &&
00144       _sectcollid!=DTSectCollId(tru->wheel(),sect)){
00145     std::cout << "DTSectColl::addTU: Trying to add tru " << tru
00146               << " into SectColl " << _sectcollid
00147               << " Skipping insertion" << std::endl;
00148     return;
00149   }
00150   
00151   if (stat<1 || stat >5) {
00152     std::cout << "DTSectColl::addTU: Wrong station number Skipping insertion" << std::endl;
00153     return;
00154   }
00155 
00156   _tsphi[stat-1] = tru->TSPhTrigs();
00157   if (stat<4) _tstheta[stat-1]=tru->TSThTrigs();
00158   
00159   if (_sectcollid==DTSectCollId())
00160     _sectcollid=DTSectCollId(tru->wheel(),sect);
00161 
00162   // add a Trigger Unit to the Sector Collector
00163 //   if(flag==2) { 
00164 //        _tsphi1 = tru->TSPhTrigs();    // these are the "normal" stations
00165 //        _tsphi2 = 0;
00166 //        _tstheta = tru->TSThTrigs();
00167 //   }
00168 //   else if (flag==0){ 
00169 //     _tsphi1 = tru->TSPhTrigs();
00170 //     _tstheta = 0;
00171 //   }
00172 //   else if(flag==1) {    
00173 //     _tsphi2 = tru->TSPhTrigs();        // these are the "double" stations
00174 //     _tstheta = 0;
00175 //   }
00176 //   // generates SectColl Id from tsphi Id
00177 //   if (flag==2 || flag==0){
00178 //     int sect  = tru->sector();
00179 //     if (sect == 13) sect=4;
00180 //     if (sect == 14) sect=10;
00181 //     _sectcollid=DTSectCollId(tru->wheel(),tru->station(),sect);
00182 //   }
00183 
00184 }
00185 
00186 
00187 void
00188 DTSectColl::loadSectColl() {
00189 
00190   localClear();
00191   
00192   std::vector<DTChambPhSegm>::const_iterator p;
00193   std::vector<DTChambPhSegm>::const_iterator pend;
00194 
00195   for(int istat=1;istat<5;istat++){
00196     pend=_tsphi[istat-1]->end();
00197     for(p=_tsphi[istat-1]->begin();p!=pend;p++){
00198       int step = p->step();
00199       int fs = (p->isFirst()) ? 1 : 2 ;
00200       // load trigger
00201       addTSPhi(step, &(*p), fs, istat);
00202     }
00203   }
00204 
00205   if(!(_tsphi[4]==0)){  // only for double stations
00206     pend=_tsphi[4]->end();
00207     for(p=_tsphi[4]->begin();p!=pend;p++){
00208       int step = p->step();
00209       int fs = (p->isFirst()) ? 1 : 2 ;
00210       // load trigger
00211       addTSPhi(step, &(*p), fs ,4);
00212     }
00213   }
00214   std::vector<DTChambThSegm>::const_iterator pth;
00215   std::vector<DTChambThSegm>::const_iterator pthend;
00216   
00217   for(int istat=1;istat<4;istat++){
00218     pthend=_tstheta[istat-1]->end();
00219     for(pth=_tstheta[istat-1]->begin();pth!=pthend;pth++){
00220       int step = pth->step();      
00221       // load trigger
00222       addTSTheta(step,  &(*pth), istat);
00223     }
00224   }
00225 
00226 }
00227 
00228 
00229 void
00230 DTSectColl::addTSPhi(int step, const DTChambPhSegm* tsmsegm, int ifs, int istat) {
00231 
00232   if(step<DTConfigSectColl::NSTEPF||step>DTConfigSectColl::NSTEPL){
00233     std::cout << "DTSectColl::addTSPhi: step out of range: " << step;
00234     std::cout << " trigger not added!" << std::endl;
00235     return;
00236   }
00237 
00238   if(istat<1 || istat>4){
00239     std::cout << "DTSectColl::addTSPhi: station out of SC range: " << istat;
00240     std::cout << " trigger not added!" << std::endl;
00241     return;
00242   }
00243   
00244   // Check that a trigger is present, by its code
00245   if(tsmsegm->oldCode()==0) {
00246     std::cout << "DTSectColl::addTSPhi -->  code = 0 ! ";
00247     std::cout << " trigger not added!" << std::endl;
00248     return;
00249   }
00250    
00251   DTSC* tsc = getDTSC(step,istat);
00252   
00253   DTSectCollPhCand* cand = new DTSectCollPhCand(tsc, tsmsegm, ifs);
00254    
00255   bool fs = (ifs==1);
00256   _incand_ph[fs].push_back(cand);
00257   
00258   tsc->addDTSectCollPhCand(cand);
00259   
00260   // Debugging...
00261   if(config()->debug()){
00262     std::cout << "DTSectColl::addTSPhi at step " << step; 
00263     std::cout << " in SC station " << istat;
00264     if(ifs==1) {
00265       std::cout << " (first track)" << std::endl;
00266     } else {
00267       std::cout << " (second track)" << std::endl;
00268     }
00269   }
00270 
00271 }
00272 
00273 void
00274 DTSectColl::addTSTheta(int step, const DTChambThSegm* tstsegm, int istat) {
00275 
00276   if(step<DTConfigSectColl::NSTEPF||step>DTConfigSectColl::NSTEPL){
00277     std::cout << "DTSectColl::addTSTheta: step out of range: " << step;
00278     std::cout << " trigger not added!" << std::endl;
00279     return;
00280   }
00281 
00282   if(istat<1 || istat>5){
00283     std::cout << "DTSectColl::addTSTheta: station out of SC range: " << istat;
00284     std::cout << " trigger not added!" << std::endl;
00285     return;
00286   }
00287 
00288   // Check if a trigger is present in theta
00289   bool is_empty=0;
00290   for (int i=0;i<7;i++) if (tstsegm->position(i)==1){
00291       is_empty = false;
00292       break;
00293     }
00294   if (is_empty==true) {
00295     std::cout << "DTSectColl::addTSTheta --> no position bit equal to 1 ! ";
00296     std::cout << " trigger not added!" << std::endl;
00297     return;
00298   }
00299   
00300    
00301 
00302   DTSC* tsc = getDTSC(step,istat);
00303   
00304   DTSectCollThCand* cand = new DTSectCollThCand(tsc, tstsegm);
00305    
00306   _incand_th.push_back(cand);
00307 
00308   tsc->addThCand(cand);
00309   
00310   // Debugging...
00311   if(config()->debug()){
00312     std::cout << "DTSectColl::addTSTheta at step " << step << std::endl;
00313   }
00314   
00315 }
00316 
00317 
00318 DTSC*
00319 DTSectColl::getDTSC(int step, int istat) const {
00320 
00321   if(step<DTConfigSectColl::NSTEPF||step>DTConfigSectColl::NSTEPL){
00322     std::cout << "DTSectColl::getDTSC: step out of range: " << step;
00323     std::cout << " empty pointer returned!" << std::endl;
00324     return 0;
00325   }
00326 
00327   if(istat<1 || istat>4){
00328     std::cout << "DTSectColl::getDTSC: station out of SC range: " << istat;
00329     std::cout << " emty pointer returned!" << std::endl;
00330     return 0;
00331   }
00332 
00333   return _tsc[step-DTConfigSectColl::NSTEPF][istat-1];  
00334 
00335 }
00336 
00337 
00338 void
00339 DTSectColl::runSectColl() {
00340 
00341   for(int istat=0;istat<4;istat++){
00342     for(int istep=DTConfigSectColl::NSTEPF;istep<DTConfigSectColl::NSTEPL+1;istep++) {
00343       
00344       if(_tsc[istep-DTConfigSectColl::NSTEPF][istat]->nFirstTPh()>0 || _tsc[istep-DTConfigSectColl::NSTEPF][istat]->nCandTh()>0 ) {
00345            
00346         _tsc[istep-DTConfigSectColl::NSTEPF][istat]->run();
00347         
00348         if(_tsc[istep-DTConfigSectColl::NSTEPF][istat]->nTracksPh()>0) {
00349         
00350           DTSectCollPhCand *cand = _tsc[istep-DTConfigSectColl::NSTEPF][istat]->getTrackPh(1);
00351           DTSCPhCache::_cache.push_back(DTSectCollPhSegm(SectCollId(),istep+cand->CoarseSync(),cand->tsTr(),1));
00352           _outcand_ph.push_back(cand);
00353           
00354           if(_tsc[istep-DTConfigSectColl::NSTEPF][istat]->nTracksPh()>1) {
00355             
00356             DTSectCollPhCand *cand = _tsc[istep-DTConfigSectColl::NSTEPF][istat]->getTrackPh(2);
00357             DTSCPhCache::_cache.push_back(DTSectCollPhSegm(SectCollId(),istep+cand->CoarseSync(),cand->tsTr(),2)); 
00358             _outcand_ph.push_back(cand);
00359           }
00360         }
00361         if(_tsc[istep-DTConfigSectColl::NSTEPF][istat]->nTracksTh()>0) {
00362           
00363           DTSectCollThCand *cand = _tsc[istep-DTConfigSectColl::NSTEPF][istat]->getTrackTh(1);
00364           DTSCThCache::_cache.push_back(DTSectCollThSegm(SectCollId(),istep+cand->CoarseSync(),cand->tsTr()));
00365           _outcand_th.push_back(cand); // CB getTrackTh non dovrebbe prendere argomenti modificala!
00366 
00367         }
00368       }
00369     }
00370   }
00371  
00372   // debugging...
00373   if(config()->debug()){
00374     if( DTSCPhCache::_cache.size()>0 || DTSCThCache::_cache.size()>0){
00375       std::cout << "====================================================" << std::endl;
00376       std::cout << "                  Sect Coll segments                      " << std::endl;
00377         if (DTSCPhCache::_cache.size()>0){
00378         std:: cout << "                  ***Phi Segments***                      " << std:: endl;
00379         std::vector<DTSectCollPhSegm>::const_iterator pph;
00380         for(pph=DTSCPhCache::_cache.begin();pph<DTSCPhCache::_cache.end();pph++) {
00381           pph->print();
00382         }
00383       }
00384       if (DTSCThCache::_cache.size()>0){
00385         std:: cout << "                  **Theta Segments**                      " << std:: endl;
00386         std::vector<DTSectCollThSegm>::const_iterator pth;
00387         for(pth=DTSCThCache::_cache.begin();pth<DTSCThCache::_cache.end();pth++) {
00388           pth->print();
00389         }
00390       }
00391       std::cout << "====================================================" << std::endl;
00392     }
00393   }
00394   //  end debugging
00395   
00396 }
00397 
00398 
00399 DTSectCollPhCand*
00400 DTSectColl::getDTSectCollPhCand(int ifs, unsigned n) const {
00401 
00402   if(ifs<1||ifs>2){
00403     std::cout << "DTSectColl::getDTSectCollPhCand: wrong track number: " << ifs;
00404     std::cout << " empty pointer returned!" << std::endl;
00405     return 0;
00406   }
00407   if(n<1 || n>nCandPh(ifs)) {
00408     std::cout << "DTSectColl::getDTSectCollPhCand: requested trigger not present: " << n;
00409     std::cout << " empty pointer returned!" << std::endl;
00410     return 0;
00411   }
00412 
00413   std::vector<DTSectCollPhCand*>::const_iterator p = _incand_ph[ifs-1].begin()+n-1;
00414   return (*p);
00415 
00416 }
00417 
00418 DTSectCollThCand*
00419 DTSectColl::getDTSectCollThCand(unsigned n) const {
00420 
00421   if(n<1 || n>nCandTh()) {
00422     std::cout << "DTSectColl::getDTSectCollThCand: requested trigger not present: " << n;
00423     std::cout << " empty pointer returned!" << std::endl;
00424     return 0;
00425   }
00426 
00427   std::vector<DTSectCollThCand*>::const_iterator p = _incand_th.begin()+n-1;
00428   return (*p);
00429 
00430 }
00431 
00432 
00433 DTSectCollPhCand*
00434 DTSectColl::getTrackPh(int n) const {
00435 
00436   if(n<1 || n>nTracksPh()) {
00437     std::cout << "DTSectColl::getTrackPh: requested track not present: " << n;
00438     std::cout << " empty pointer returned!" << std::endl;
00439     return 0;
00440   }
00441 
00442   std::vector<DTSectCollPhCand*>::const_iterator p = _outcand_ph.begin()+n-1;
00443   return (*p);
00444 
00445 }
00446 
00447 DTSectCollThCand*
00448 DTSectColl::getTrackTh(int n) const {
00449 
00450   if(n<1 || n>nTracksTh()) {
00451     std::cout << "DTSectColl::getTrackTh: requested track not present: " << n;
00452     std::cout << " empty pointer returned!" << std::endl;
00453     return 0;
00454   }
00455 
00456   std::vector<DTSectCollThCand*>::const_iterator p = _outcand_th.begin()+n-1;
00457   return (*p);
00458 
00459 }
00460 
00461 
00462 unsigned
00463 DTSectColl::nCandPh(int ifs) const {
00464 
00465   if(ifs<1||ifs>2){
00466     std::cout << "DTSectColl::nCandPh: wrong track number: " << ifs;
00467     std::cout << " 0 returned!" << std::endl;
00468     return 0;
00469   }
00470 
00471   return _incand_ph[ifs-1].size();
00472 
00473 }
00474 
00475 unsigned
00476 DTSectColl::nCandTh() const {
00477 
00478   return _incand_th.size();
00479 
00480 }
00481 
00482 int 
00483 DTSectColl::nSegmPh(int step) {
00484 
00485   int n=0;
00486   std::vector<DTSectCollPhSegm>::const_iterator p;
00487    std::vector<DTSectCollPhSegm>::const_iterator endp = DTSCPhCache::end();
00488   for(p=DTSCPhCache::begin(); p<endp; p++) {   
00489     if(p->step()==step)n++;  
00490   } 
00491 
00492   return n;
00493 
00494 }
00495 
00496 int 
00497 DTSectColl::nSegmTh(int step) {
00498 
00499   int n=0;
00500   std::vector<DTSectCollThSegm>::const_iterator p;
00501   std::vector<DTSectCollThSegm>::const_iterator endp = DTSCThCache::end();
00502   for(p=DTSCThCache::begin(); p>endp; p++) {   
00503     if(p->step()==step)n++;  
00504   } 
00505 
00506   return n;
00507 
00508 }
00509 
00510 
00511 const DTSectCollPhSegm*
00512 DTSectColl::SectCollPhSegment(int step, unsigned n) {
00513 
00514   std::vector<DTSectCollPhSegm>::const_iterator p;
00515   std::vector<DTSectCollPhSegm>::const_iterator endp = DTSCPhCache::end(); 
00516   for(p=DTSCPhCache::begin();p<endp;p++){
00517     if(p->step()==step&&((n==1&&p->isFirst())||(n==2&&!p->isFirst())))
00518       return &(*p); 
00519   }
00520 
00521   return 0;
00522 
00523 }
00524 
00525 const DTSectCollThSegm*
00526 DTSectColl::SectCollThSegment(int step) {
00527 
00528   std::vector<DTSectCollThSegm>::const_iterator p;
00529  std::vector<DTSectCollThSegm>::const_iterator endp = DTSCThCache::end();
00530   for(p=DTSCThCache::begin();p<endp;p++){
00531     if(p->step()==step)
00532       return &(*p); 
00533   }
00534 
00535   return 0;
00536 
00537 }