CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/L1Trigger/DTTriggerServerPhi/src/DTTSM.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: DTTSM.cpp
00004 //
00005 //   Description: Implementation of DTTSM trigger algorithm
00006 //
00007 //
00008 //   Author List:
00009 //   C. Grandi
00010 //   Modifications: 
00011 //   S. Marcellini, D. Bonacorsi 
00012 //   04/01/2007 : C.Battilana local config update
00013 //
00014 //
00015 //--------------------------------------------------
00016 
00017 //-----------------------
00018 // This Class's Header --
00019 //-----------------------
00020 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSM.h"
00021 
00022 //-------------------------------
00023 // Collaborating Class Headers --
00024 //-------------------------------
00025 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigTSPhi.h"
00026 #include "L1Trigger/DTTriggerServerPhi/interface/DTTSCand.h"
00027 
00028 //---------------
00029 // C++ Headers --
00030 //---------------
00031 #include <iostream>
00032 #include <algorithm>
00033 
00034 //----------------
00035 // Constructors --
00036 //----------------
00037 // DBSM-doubleTSM
00038 DTTSM::DTTSM(int n) : _n(n), _ignoreSecondTrack(0) {
00039   // reserve the appropriate amount of space for vectors
00040   _incand[0].reserve(DTConfigTSPhi::NTSSTSM);
00041   _incand[1].reserve(DTConfigTSPhi::NTSSTSM);
00042   _outcand.reserve(2);
00043 }
00044 
00045 
00046 //--------------
00047 // Destructor --
00048 //--------------
00049 DTTSM::~DTTSM(){
00050   clear();
00051 }
00052 
00053 
00054 //--------------
00055 // Operations --
00056 //--------------
00057 
00058 void
00059 DTTSM::clear() {
00060   _ignoreSecondTrack=0;
00061   for(int itk=0;itk<=1;itk++){
00062     // content of _incand is deleted by DTTSPhi
00063     _incand[itk].clear();
00064   }
00065   // content of _outcand is deleted by DTTSPhi
00066   _outcand.clear(); 
00067 }
00068 
00069 void
00070 DTTSM::run(int bkmod) {
00071   
00072   if(config()->debug()){
00073     std::cout << "DTTSM::run: Processing DTTSM: ";
00074     std::cout << nFirstT() << " first & " << nSecondT() << " second tracks" << std::endl;
00075   }
00076   
00077   if(nFirstT()<1)return; // skip if no first tracks
00078   //
00079   // SORT 1
00080   //
00081   
00082   // debugging
00083   if(config()->debug()){
00084     std::cout << "Vector of first tracks in DTTSM: " << std::endl;
00085     std::vector<DTTSCand*>::const_iterator p;
00086     for(p=_incand[0].begin(); p!=_incand[0].end(); p++) {
00087       (*p)->print();
00088     }
00089   }
00090   // end debugging
00091   
00092   
00093   DTTSCand* first=sortTSM1(bkmod);
00094   if(first!=0) {
00095     _outcand.push_back(first); 
00096   }
00097   if(nSecondT()<1)return; // skip if no second tracks
00098 
00099   //
00100   // SORT 2
00101   //
00102   
00103   // debugging
00104   if(config()->debug()){
00105     std::vector<DTTSCand*>::const_iterator p;
00106     std::cout << "Vector of second tracks (including carry) in DTTSM: " << std::endl;
00107     for(p=_incand[1].begin(); p!=_incand[1].end(); p++) {
00108       (*p)->print();
00109     }
00110   }
00111   // end debugging
00112   
00113   DTTSCand* second=sortTSM2(bkmod);
00114   if(second!=0) {
00115     
00116     _outcand.push_back(second); 
00117   }
00118   
00119 }
00120 
00121 DTTSCand*
00122 DTTSM::sortTSM1(int bkmod) {
00123   // Do a sort 1
00124   DTTSCand* best=0;
00125   DTTSCand* carry=0;
00126   std::vector<DTTSCand*>::iterator p;
00127   for(p=_incand[0].begin(); p!=_incand[0].end(); p++) {
00128     DTTSCand* curr=(*p);
00129     
00130     if ( bkmod == 1 ) { // NORMAL mode ---> sorting on dataword
00131       curr->setBitsTss(); // maybe not necessary, as they are the same as for TSS in the default
00132     } else if( bkmod == 0) { //  { // BACKUP mode ---> sorting on modified dataword
00133       curr->setBitsBkmod();
00134     } else {
00135       std::cout << "DTTSM::sortTSM1:  bkmod not properly assigned!" << std::endl;
00136     }
00137     
00138     
00139     if(best==0){
00140       best=curr;
00141     } 
00142     else if((*curr)<(*best)){
00143       carry=best;
00144       best=curr;
00145     } 
00146     else if(carry==0){
00147       carry=curr;
00148     } 
00149     else if((*curr)<(*carry)){
00150       carry=curr;
00151     } //else { }    
00152   }
00153   
00154   
00155   // Ghost 1 suppression: use carry only if not suppressed
00156   if(carry!=0) {   // A carry is present
00157     
00158     // Carry enabled if correlated and TRACO is next to best
00159     bool inner_or_corr;
00160     if(config()->TsmGhost1Corr()) {
00161       inner_or_corr=carry->isInner() || carry->isCorr();  
00162     } else {
00163       inner_or_corr=carry->isInner();
00164     }
00165     
00166     if(config()->TsmGhost1Flag()<2){ // Carry isn't always suppressed
00167       // check if adjacent DTTracoChips
00168       int adj = (carry->tssNumber()==best->tssNumber()+1 &&          //next DTTracoChip
00169                  best->TcPos()==DTConfigTSPhi::NTCTSS && carry->TcPos()==1 ) ||
00170         (carry->tssNumber()==best->tssNumber()-1 &&         // prev DTTracoChip
00171          best->TcPos()==1 && carry->TcPos()==DTConfigTSPhi::NTCTSS ) ||
00172         (carry->tssNumber()==best->tssNumber() &&           // same DTTracoChip
00173          abs(carry->TcPos()-best->TcPos())==1                     );   
00174       
00175       if(config()->TsmGhost1Flag()==0 ||          // Carry always enabled
00176          //       carry->isInner() ||                      // Carry is inner
00177          inner_or_corr ||                         // Carry is inner or corr
00178          !adj                          ) {        // Carry not adj. to best   
00179         // add carry to second tracks to for sort 2
00180         carry->setSecondTrack(); // change value of first/second track bit
00181         // NEW DESIGN: DTTSM is not configurable!
00182         // carry->setBitsTsm();     // set quality bits as for second tracks
00183         _incand[1].push_back(carry); // add to list of second tracks
00184       }
00185     }
00186   }
00187   // best->print();
00188   return best;
00189 }
00190 
00191 
00192 
00193 
00194 DTTSCand*
00195 DTTSM::sortTSM2(int bkmod) {
00196 
00197   // If second tracks are always suppressed skip processing
00198   if(config()->TsmGhost2Flag()==3)return 0;
00199   
00200   // Check if there are second tracks
00201   if(nTracks()<1){
00202     std::cout << "DTTSM::sortTSM2: called with no first track.";
00203     std::cout << " empty pointer returned!" << std::endl;
00204     return 0;
00205   }
00206   
00207   // If a first track at the following BX is present, ignore second tracks of any kind
00208   if(_ignoreSecondTrack){
00209     std::vector<DTTSCand*>::iterator p;
00210     for(p=_incand[1].begin(); p!=_incand[1].end(); p++) {
00211       if((*p)->isCarry()) return (*p);
00212     }
00213     return 0;
00214   }
00215   
00216   // If no first tracks at the following BX, do a sort 2
00217   DTTSCand* best=getTrack(1);
00218   DTTSCand* second=0;
00219   std::vector<DTTSCand*>::iterator p;
00220   for(p=_incand[1].begin(); p!=_incand[1].end(); p++) {
00221     DTTSCand* curr=(*p);
00222     // ghost 2 suppression: skip track if suppressed
00223     // this is not needed if config of DTTSM == config of DTTSS
00224     
00225     bool inner_or_corr;
00226     if(config()->TsmGhost2Corr())
00227       {inner_or_corr=curr->isInner() || curr->isCorr();
00228       }
00229     else
00230       {inner_or_corr=curr->isInner();
00231       }
00232     
00233     if(config()->TsmGhost2Flag()!=0){     // 2nd tracks not always enabled
00234       if(
00236          !inner_or_corr &&                    // outer and not corr
00237          (curr->tssNumber()==best->tssNumber() &&
00238           curr->TcPos()==best->TcPos()) ) { // same correlator of 1st track
00239         if(config()->TsmGhost2Flag()==2 ||    // do not look to corr bit of 1st
00240            ( (!best->isCorr() ) &&  config()->TsmGhost2Flag()!=4 ) || // skip if best is not corr
00241            ( (!best->isCorr() ) &&  best->isInner() && config()->TsmGhost2Flag()==4) )   // skip only if best is inner and not corr
00242           {                 
00243             continue;                             // skip track
00244           }
00245       }
00246     }
00247     
00248     // added DBSM
00249     // SM double TSM    if ( bkmod == 1 ) { // NORMAL mode ---> sorting with <
00250     if ( bkmod == 1 ) { // NORMAL mode ---> sorting on dataword
00251       curr->setBitsTss(); // maybe not necessary, as they are the same as for TSS in the default
00252     } else if( bkmod == 0) { //  { // BACKUP mode ---> sorting on modified dataword
00253       curr->setBitsBkmod();
00254     } else {
00255       std::cout << " DTTSM::sortTSM2 bkmod not properly assigned!" << std::endl;
00256     }
00257     
00258     
00259     
00260     // added DBSM
00261     // SM double TSM    if ( bkmod == 1 ) { // NORMAL mode ---> sorting with <
00262     
00263     if(second==0){
00264       second=curr;
00265     } 
00266     else if((*curr)<(*second)){
00267       second=curr;
00268     }  
00269   }
00270   return second;
00271 }
00272 
00273 
00274 
00275 void
00276 DTTSM::addCand(DTTSCand* cand) {
00277   // NEW DESIGN: DTTSM is not configurable!
00278   //  cand->resetCarry(); // reset carry information
00279   //  cand->setBitsTsm(); // set quality bits for DTTSM sorting
00280   _incand[(1-cand->isFirst())].push_back(cand); 
00281 }
00282 
00283 unsigned
00284 DTTSM::nCand(int ifs) const {
00285   if(ifs<1||ifs>2){
00286     std::cout << "DTTSM::nCand: wrong track number: " << ifs;
00287     std::cout << " 0 returned!" << std::endl;
00288     return 0;
00289   }
00290 
00291   return _incand[ifs-1].size();
00292 }
00293 
00294 DTTSCand*
00295 DTTSM::getDTTSCand(int ifs, unsigned n) const {
00296   if(ifs<1||ifs>2){
00297     std::cout << "DTTSM::getDTTSCand: wrong track number: " << ifs;
00298     std::cout << " empty pointer returned!" << std::endl;
00299     return 0;
00300   }
00301   if(n<1 || n>nCand(ifs)) {
00302     std::cout << "DTTSM::getDTTSCand: requested trigger not present: " << n;
00303     std::cout << " empty pointer returned!" << std::endl;
00304     return 0;
00305   }
00306   std::vector<DTTSCand*>::const_iterator p = _incand[ifs-1].begin()+n-1;
00307   return (*p);
00308 }
00309 
00310 const DTTracoTrigData*
00311 DTTSM::getTracoT(int ifs, unsigned n) const {
00312   if(ifs<1||ifs>2){
00313     std::cout << "DTTSM::getTracoT: wrong track number: " << ifs;
00314     std::cout << " empty pointer returned!" << std::endl;
00315     return 0;
00316   }
00317   if(n<1 || n>nCand(ifs)) {
00318     std::cout << "DTTSM::getTracoT: requested trigger not present: " << n;
00319     std::cout << " empty pointer returned!" << std::endl;
00320     return 0;
00321   }
00322   return getDTTSCand(ifs, n)->tracoTr();
00323 }
00324 
00325 DTTSCand*
00326 DTTSM::getTrack(int n) const {
00327 
00328   if(n<1 || n>nTracks()) {
00329     std::cout << "DTTSM::getTrack: requested track not present: " << n;
00330     std::cout << " empty pointer returned!" << std::endl;
00331     return 0;
00332   }
00333   std::vector<DTTSCand*>::const_iterator p = _outcand.begin()+n-1;
00334   return (*p);
00335 }
00336 
00337 
00338 
00339 
00340 
00341