CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/L1Trigger/DTSectorCollector/src/DTSC.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: DTSC.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 : theta cand added
00012 //   12/12/06 C. Battilana : _stat added
00013 //   09/01/07 C. Battilana : updated to local conf
00014 //
00015 //
00016 //--------------------------------------------------
00017 
00018 
00019 //-----------------------
00020 // This Class's Header --
00021 //-----------------------
00022 #include "L1Trigger/DTSectorCollector/interface/DTSC.h"
00023 
00024 //-------------------------------
00025 // Collaborating Class Headers --
00026 //-------------------------------
00027 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigSectColl.h"
00028 #include "L1Trigger/DTSectorCollector/interface/DTSectColl.h"
00029 #include "L1Trigger/DTSectorCollector/interface/DTSectCollPhCand.h"
00030 #include "L1Trigger/DTSectorCollector/interface/DTSectCollThCand.h"
00031 
00032 //---------------
00033 // C++ Headers --
00034 //---------------
00035 #include <iostream>
00036 #include <algorithm>
00037 
00038 //----------------
00039 // Constructors --
00040 //----------------
00041 
00042 DTSC::DTSC(int istat) : _ignoreSecondTrack(0) ,_stat(istat){
00043 
00044   // reserve the appropriate amount of space for vectors
00045   // test _incand[0].reserve(DTConfigSectColl::NTSMSC);
00046   // test_incand[1].reserve(DTConfigSectColl::NTSMSC);
00047   // test _outcand.reserve(2);
00048  
00049 }
00050 
00051 
00052 //--------------
00053 // Destructor --
00054 //--------------
00055 DTSC::~DTSC() {
00056 
00057   clear();
00058 
00059 }
00060 
00061 
00062 //--------------
00063 // Operations --
00064 //--------------
00065 
00066 void
00067 DTSC::clear() {
00068 
00069   _ignoreSecondTrack=0;
00070 
00071   for(int itk=0;itk<=1;itk++){
00072  
00073     _incand_ph[itk].clear();
00074   }
00075 
00076   _outcand_ph.clear();
00077   _cand_th.clear();
00078 
00079 }
00080 
00081 
00082 // 
00083 void
00084 DTSC::run() {
00085 
00086   if(config()->debug()){
00087     std::cout << "DTSC::run: Processing DTSectColl: ";
00088     std::cout << nFirstTPh() << " first & " << nSecondTPh() << " second Phi tracks ";
00089     std::cout << " - "<< nCandTh() << " Theta tracks" << std::endl;
00090   
00091   }
00092 
00093   if(nFirstTPh()<1)return; // skip if no first tracks
00094   //
00095   // SORT 1
00096   //
00097 
00098   // debugging
00099     if(config()->debug()){
00100      std::cout << "Vector of first Phi tracks in DTSectColl: " << std::endl;
00101     std::vector<DTSectCollPhCand*>::const_iterator p;
00102     for(p=_incand_ph[0].begin(); p!=_incand_ph[0].end(); p++) {
00103            (*p)->print();
00104     }
00105    }
00106   // end debugging
00107  
00108   DTSectCollPhCand* first=DTSectCollsort1();
00109   if(config()->debug()){
00110     std::cout << "SC: DTSC::run: first Phi track is = " << first << std::endl;
00111   }
00112   if(first!=0) {
00113     _outcand_ph.push_back(first); 
00114 
00115   }
00116   if(nSecondTPh()<1)return; // skip if no second tracks
00117 
00118   //
00119   // SORT 2
00120   //
00121 
00122   // debugging
00123   if(config()->debug()){
00124     std::vector<DTSectCollPhCand*>::const_iterator p;
00125     std::cout << "Vector of second Phi tracks in DTSectColl: " << std::endl;
00126     for(p=_incand_ph[1].begin(); p!=_incand_ph[1].end(); p++) {
00127        (*p)->print();
00128     }
00129   }
00130   // end debugging
00131 
00132   DTSectCollPhCand* second=DTSectCollsort2();
00133   if(second!=0) {
00134     _outcand_ph.push_back(second); 
00135   }
00136   
00137 }
00138 
00139 
00140 DTSectCollPhCand*
00141 DTSC::DTSectCollsort1() {
00142 
00143   // Do a sort 1
00144   DTSectCollPhCand* best=0;
00145   DTSectCollPhCand* carry=0;
00146   std::vector<DTSectCollPhCand*>::iterator p;
00147   for(p=_incand_ph[0].begin(); p!=_incand_ph[0].end(); p++) {
00148     DTSectCollPhCand* curr=(*p);
00149 
00150     curr->setBitsSectColl();    // SM sector collector set bits in dataword to make SC sorting
00151     
00152     // NO Carry in Sector Collector sorting in default 
00153     if(config()->SCGetCarryFlag(_stat)) {  // get carry
00154 
00155       if(best==0){
00156         best=curr;
00157       } 
00158       else if((*curr)<(*best)){
00159         carry=best;
00160         best=curr;
00161       } 
00162       else if(carry==0){
00163         carry=curr;
00164       } 
00165       else if((*curr)<(*carry)){
00166         carry=curr;
00167       } 
00168 
00169     }
00170     else if(config()->SCGetCarryFlag(_stat)==0){ // no carry (default)
00171       if(best==0){
00172         best=curr;
00173       } 
00174       else if((*curr)<(*best)){
00175         
00176         best=curr;
00177       } 
00178       
00179     }
00180     
00181     if(carry!=0 && config()->SCGetCarryFlag(_stat)) { // reassign carry to sort 2 candidates
00182       carry->setSecondTrack(); // change value of 1st/2nd track bit
00183       _incand_ph[1].push_back(carry); // add to list of 2nd track
00184  
00185     }
00186   } 
00187   
00188   return best;
00189 
00190 }
00191 
00192 
00193 DTSectCollPhCand*
00194 DTSC::DTSectCollsort2() {
00195 
00196   // Check if there are second tracks
00197 
00198   if(nTracksPh()<1){
00199     std::cout << "DTSC::DTSectCollsort2: called with no first Phi track.";
00200     std::cout << " empty pointer returned!" << std::endl;
00201     return 0;
00202   }
00203   // If a first track at the following BX is present, ignore second tracks of any kind
00204   if(_ignoreSecondTrack){
00205 
00206     for(std::vector<DTSectCollPhCand*>::iterator p=_incand_ph[1].begin(); p!=_incand_ph[1].end(); p++) {
00207 
00208     }
00209     return 0;
00210   }
00211 
00212   // If no first tracks at the following BX, do a sort 2
00213   //  DTSectCollCand* best=getTrack(1);  ! not needed as lons as there is no comparison with best in sort 2
00214   DTSectCollPhCand* second=0;
00215   std::vector<DTSectCollPhCand*>::iterator p;
00216   for(p=_incand_ph[1].begin(); p!=_incand_ph[1].end(); p++) {
00217     DTSectCollPhCand* curr=(*p);
00218     curr->setBitsSectColl();    // SM sector collector set bits in dataword to make SC sorting
00219     
00220     if(second==0){
00221       second=curr;
00222     } 
00223     else if((*curr)<(*second)){
00224       second=curr;
00225     } 
00226     
00227   }
00228 
00229   return second;
00230 
00231 }
00232 
00233 
00234 void
00235 DTSC::addPhCand(DTSectCollPhCand* cand) {
00236 
00237   _incand_ph[(1-cand->isFirst())].push_back(cand); 
00238 
00239 }
00240 
00241 void
00242 DTSC::addThCand(DTSectCollThCand* cand) {
00243 
00244   _cand_th.push_back(cand); 
00245 
00246 }
00247 
00248 
00249 unsigned
00250 DTSC::nCandPh(int ifs) const {
00251 
00252   if(ifs<1||ifs>2){
00253     std::cout << "DTSC::nCandPh: wrong track number: " << ifs;
00254     std::cout << " 0 returned!" << std::endl;
00255     return 0;
00256   }
00257   return _incand_ph[ifs-1].size();
00258 
00259 }
00260 
00261 unsigned
00262 DTSC::nCandTh() const {
00263 
00264   return _cand_th.size();
00265 
00266 }
00267 
00268 
00269 DTSectCollPhCand*
00270 DTSC::getDTSectCollPhCand(int ifs, unsigned n) const {
00271 
00272   if(ifs<1||ifs>2){
00273     std::cout << "DTSC::getDTSectCollPhCand: wrong track number: " << ifs;
00274     std::cout << " empty pointer returned!" << std::endl;
00275     return 0;
00276   }
00277   if(n<1 || n>nCandPh(ifs)) {
00278     std::cout << "DTSC::getDTSectCollPhCand: requested trigger not present: " << n;
00279     std::cout << " empty pointer returned!" << std::endl;
00280     return 0;
00281   }
00282 
00283   std::vector<DTSectCollPhCand*>::const_iterator p = _incand_ph[ifs-1].begin()+n-1;
00284   return (*p);
00285 
00286 }
00287 
00288 DTSectCollThCand*
00289 DTSC::getDTSectCollThCand(unsigned n) const {
00290 
00291   if(n<1 || n>nCandTh()) {
00292     std::cout << "DTSC::getDTSectCollThCand: requested trigger not present: " << n;
00293     std::cout << " empty pointer returned!" << std::endl;
00294     return 0;
00295   }
00296 
00297   std::vector<DTSectCollThCand*>::const_iterator p = _cand_th.begin()+n-1;
00298   return (*p);
00299 
00300 }
00301 
00302 void
00303 DTSC::addDTSectCollPhCand(DTSectCollPhCand* cand) {
00304 
00305   int ifs = (cand->isFirst()) ? 0 : 1;
00306  
00307   _incand_ph[ifs].push_back(cand); 
00308 
00309 }
00310 
00311 DTSectCollPhCand*
00312 DTSC::getTrackPh(int n) const {
00313 
00314   if(n<1 || n>nTracksPh()) {
00315     std::cout << "DTSC::getTrackPh: requested track not present: " << n;
00316     std::cout << " empty pointer returned!" << std::endl;
00317     return 0;
00318   }
00319 
00320   std::vector<DTSectCollPhCand*>::const_iterator p = _outcand_ph.begin()+n-1;
00321 
00322   return (*p);
00323 
00324 }
00325 
00326 
00327 DTSectCollThCand*
00328 DTSC::getTrackTh(int n) const {
00329 
00330   if(n<1 || n>nTracksTh()) {
00331     std::cout << "DTSC::getTrackTh: requested track not present: " << n;
00332     std::cout << " empty pointer returned!" << std::endl;
00333     return 0;
00334   }
00335 
00336   std::vector<DTSectCollThCand*>::const_iterator p = _cand_th.begin()+n-1;
00337 
00338   return (*p);
00339 
00340 }