CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/L1Trigger/DTTriggerServerPhi/src/DTTSS.cc

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