CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/L1Trigger/RPCTechnicalTrigger/src/TTUTrackingAlg.cc

Go to the documentation of this file.
00001 // $Id: TTUTrackingAlg.cc,v 1.10 2009/10/27 09:01:48 aosorio Exp $
00002 // Include files 
00003 
00004 
00005 
00006 // local
00007 #include "L1Trigger/RPCTechnicalTrigger/interface/TTUTrackingAlg.h"
00008 #include <algorithm>
00009 
00010 //-----------------------------------------------------------------------------
00011 // Implementation file for class : TTUTrackingAlg
00012 //
00013 // 2008-10-18 : Andres Osorio
00014 //-----------------------------------------------------------------------------
00015 
00016 //=============================================================================
00017 // Standard constructor, initializes variables
00018 //=============================================================================
00019 TTUTrackingAlg::TTUTrackingAlg(  ) {
00020 
00021   int StOrder[6]={6,5,4,3,2,1};
00022   int SeOrder[12]={4,5,3,6,2,7,1,8,12,9,11,10};
00023   
00024   for(int i=0; i < 6; ++i) 
00025   {
00026     m_STscanorder[i]       = StOrder[i];
00027     m_SEscanorder[i*2]     = SeOrder[i*2];
00028     m_SEscanorder[(i*2)+1] = SeOrder[(i*2)+1];
00029   }
00030   
00031   m_triggersignal = false;
00032   m_mintrklength = 4;
00033 
00034   m_debug = false;
00035   
00036 }
00037 
00038 //=============================================================================
00039 // Destructor
00040 //=============================================================================
00041 TTUTrackingAlg::~TTUTrackingAlg() {
00042 
00043   TracksItr itr1;
00044   for (itr1=m_tracks.begin(); itr1!=m_tracks.end(); ++itr1)
00045     delete (*itr1);
00046   
00047   SeedsItr itr2;
00048   for (itr2=m_initialseeds.begin(); itr2!=m_initialseeds.end(); ++itr2)
00049     delete (*itr2);
00050   
00051   //m_tracks.clear();
00052   //m_initialseeds.clear();
00053   
00054 } 
00055 
00056 //=============================================================================
00057 void TTUTrackingAlg::setBoardSpecs( const TTUBoardSpecs::TTUBoardConfig & boardspecs ) 
00058 {
00059   
00060   m_mintrklength = boardspecs.m_TrackLength;
00061   
00062 }
00063 
00064 bool TTUTrackingAlg::process( const TTUInput & inmap )
00065 {
00066   
00067   if( m_debug) std::cout << "TTUTrackingAlg>process() starts + bx= " << inmap.m_bx << std::endl;
00068 
00069   m_triggersignal = false;
00070   
00071   Track * initTrk = new Track();
00072   
00073   //.
00074   runSeedBuster( inmap );
00075   
00076   if ( m_initialseeds.size() > 0 && m_initialseeds.size() < 20 ) // if too much hits, then cannot process
00077     initTrk->add( m_initialseeds[0] );
00078   else {
00079     initTrk->addnone();
00080     if( m_debug) std::cout << "TTUTrackingAlg>process() ends: no initialseeds" << std::endl;
00081     return false;
00082   }
00083   
00084 
00085 
00086 
00087 
00088   m_tracks.push_back( initTrk );
00089   
00090   //..
00091   SeedsItr _seed = m_initialseeds.begin();
00092   std::vector<Seed*> neighbors;
00093   
00094   while ( _seed != m_initialseeds.end() ) {
00095     
00096     findNeighbors( (*_seed) , neighbors );
00097     filter( initTrk, neighbors );
00098     executeTracker( initTrk, neighbors );
00099     ghostBuster( initTrk );
00100     
00101     ++_seed;
00102     
00103     if ( _seed != m_initialseeds.end() ) {
00104       initTrk = new Track();
00105       initTrk->add((*_seed));
00106       m_tracks.push_back( initTrk );
00107       
00108     }
00109 
00110   }
00111 
00112   TracksItr itr;
00113   
00114   if( m_debug) { 
00115     std::cout << "Total tracks: " << m_tracks.size() << std::endl;
00116     for( itr = m_tracks.begin(); itr != m_tracks.end(); ++itr)
00117       std::cout << "length: " << (*itr)->length() << '\t';
00118     std::cout << std::endl;
00119   }
00120   
00121   //...
00122   alignTracks();
00123   
00124   //.... Look at the first track and compare its track length
00125   
00126   int tracklen(0);
00127   itr = m_tracks.begin();
00128   if ( itr != m_tracks.end() ) tracklen = (*itr)->length();
00129   
00130   if ( tracklen >= m_mintrklength )
00131     m_triggersignal = true;
00132   
00133   if( m_debug ) {
00134     std::cout << "TTUTrackingAlg> trk len= " 
00135               << tracklen << '\t' << "triggered: "
00136               << m_triggersignal << std::endl;
00137   }
00138   
00139   //..... Clean up for next run
00140   
00141   cleanUp();
00142     
00143   //.......................................................
00144   
00145   if( m_debug ) std::cout << "TTUTrackingAlg>process ends" << std::endl;
00146   
00147   return true;
00148   
00149 }
00150 
00151 void TTUTrackingAlg::runSeedBuster( const TTUInput & inmap )
00152 {
00153   
00154   int idx(0);
00155   int idy(0);
00156 
00157   for(int i=0; i < 12; ++i) 
00158   {
00159     idx = (m_SEscanorder[i] - 1);
00160     std::bitset<6> station = inmap.input_sec[idx];
00161     
00162     if ( ! station.any() ) continue;
00163     
00164     for(int k=0; k < 6; ++k ) {
00165       
00166       idy = (m_STscanorder[k] - 1);
00167       bool _hit = station[idy];
00168       
00169       if ( _hit ) {
00170         Seed *_seed = new Seed( idx, idy, 0 );
00171         m_initialseeds.push_back(_seed);
00172       }
00173     }
00174   }
00175   
00176   //...
00177   if ( m_debug ) std::cout << "SeedBuster: " << m_initialseeds.size() << std::endl;
00178     
00179 }
00180 
00181 int TTUTrackingAlg::executeTracker( Track * _trk, std::vector<Seed*> & neighbors)
00182 {
00183   
00184   if ( m_debug ) std::cout << "executeTracker: " << neighbors.size() << std::endl;
00185   
00186   //...
00187   
00188   SeedsItr _itr = neighbors.begin();
00189   
00190   while( _itr != neighbors.end() ) {
00191   
00192     _trk->add( (*_itr) );
00193     
00194     std::vector<Seed*> _nextneighbors;
00195     
00196     findNeighbors( (*_itr) , _nextneighbors );
00197     
00198     filter( _trk, _nextneighbors );
00199     
00200     if ( _nextneighbors.size() == 1 ) 
00201       executeTracker( _trk, _nextneighbors );
00202     
00203     //... bifurcation not considered at the moment
00204         
00205     ++_itr;
00206     
00207   }
00208   
00209   //...
00210   
00211 
00212   
00213   return 1;
00214   
00215 }
00216 
00217 void TTUTrackingAlg::findNeighbors( Seed  * _seed, std::vector<Seed*> & neighbors)
00218 {
00219   
00220   neighbors.clear();
00221   
00222   int _xo = _seed->m_sectorId;
00223   int _yo = _seed->m_stationId;
00224 
00225   if( m_debug ) std::cout << "X: " << _xo+1 << " Y: " << _yo+1 << std::endl;
00226   
00227   SeedsItr _itr = m_initialseeds.begin();
00228   
00229   while( _itr != m_initialseeds.end() ) {
00230     
00231     int _difx    = std::abs( _xo - (*_itr)->m_sectorId );
00232     int _dify    = std::abs( _yo - (*_itr)->m_stationId );
00233     
00234     if (m_debug) std::cout << "difference (x,y): " << _difx << "," << _dify << "\t";
00235     
00236     if ( _difx == 11 ) _difx = 1;
00237     
00238     if ( ((_difx == 1) && (_dify == 1)) ||
00239          ((_difx == 1) && (_dify == 0)) ||
00240          ((_difx == 0) && (_dify == 1)) ) 
00241       
00242       neighbors.push_back( (*_itr) );
00243     
00244     ++_itr;
00245   }
00246 
00247   if (m_debug) std::cout << std::endl;
00248   
00249 }
00250 
00251 void TTUTrackingAlg::filter( Track * _trk, 
00252                              std::vector<Seed*> & _nbrs )
00253 {
00254   
00255   //... filter: removes from neighbors list, seeds already present
00256   //...    in tracks
00257 
00258   SeedsItr _itr;
00259   
00260   for( _itr = _trk->m_seeds.begin();_itr != _trk->m_seeds.end(); ++_itr) 
00261   {
00262     SeedsItr _isalready = std::find( _nbrs.begin(),_nbrs.end(), (*_itr) );
00263     
00264     if( _isalready != _nbrs.end() ) { 
00265       _nbrs.erase( _isalready ); 
00266       if( m_debug ) std::cout << "removing ..." << std::endl;
00267     }
00268     
00269     
00270   }
00271   
00272 }
00273 
00274 void TTUTrackingAlg::ghostBuster( Track * currentTrk )
00275 {
00276   
00277   //...do a final check to make sure there are no repeated seeds in track
00278   
00279   std::vector<Seed*>::iterator seedItr;
00280   
00281   std::sort( currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), SortBySector() );
00282   std::sort( currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), SortByLayer() );
00283   
00284   seedItr = std::unique (currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), CompareSeeds() );
00285   
00286   currentTrk->m_seeds.resize(seedItr - currentTrk->m_seeds.begin());
00287 
00288   currentTrk->updateTrkLength();
00289     
00290 }
00291 
00292 void TTUTrackingAlg::alignTracks()
00293 {
00294 
00295   TracksItr itr;
00296   CompareMechanism<Track> compare;
00297   
00298   std::sort( m_tracks.begin(), m_tracks.end(), compare );
00299   std::reverse( m_tracks.begin(), m_tracks.end() );
00300   
00301   if( m_debug ) {
00302     for( itr = m_tracks.begin(); itr != m_tracks.end(); ++itr )
00303       std::cout << "Align tracks> trk len: " << (*itr)->length() << " ";
00304     std::cout << std::endl;
00305   }
00306   
00307 }
00308 
00309 void TTUTrackingAlg::cleanUp()
00310 {
00311   
00312   TracksItr itr1;
00313   for (itr1=m_tracks.begin(); itr1!=m_tracks.end(); ++itr1)
00314     delete (*itr1);
00315   
00316   SeedsItr itr2;
00317   for (itr2=m_initialseeds.begin(); itr2!=m_initialseeds.end(); ++itr2)
00318     delete (*itr2);
00319   
00320   m_tracks.clear();
00321   m_initialseeds.clear();
00322   
00323 }