CMS 3D CMS Logo

TTUTrackingAlg.cc
Go to the documentation of this file.
1 // Include files
2 
3 
4 
5 // local
7 #include <algorithm>
8 
9 //-----------------------------------------------------------------------------
10 // Implementation file for class : TTUTrackingAlg
11 //
12 // 2008-10-18 : Andres Osorio
13 //-----------------------------------------------------------------------------
14 
15 //=============================================================================
16 // Standard constructor, initializes variables
17 //=============================================================================
19 
20  int StOrder[6]={6,5,4,3,2,1};
21  int SeOrder[12]={4,5,3,6,2,7,1,8,12,9,11,10};
22 
23  for(int i=0; i < 6; ++i)
24  {
25  m_STscanorder[i] = StOrder[i];
26  m_SEscanorder[i*2] = SeOrder[i*2];
27  m_SEscanorder[(i*2)+1] = SeOrder[(i*2)+1];
28  }
29 
30  m_triggersignal = false;
31  m_mintrklength = 4;
32 
33  m_debug = false;
34 
35 }
36 
37 //=============================================================================
38 // Destructor
39 //=============================================================================
41 }
42 
43 //=============================================================================
45 {
46 
47  m_mintrklength = boardspecs.m_TrackLength;
48 
49 }
50 
51 bool TTUTrackingAlg::process( const TTUInput & inmap )
52 {
53 
54  if( m_debug) std::cout << "TTUTrackingAlg>process() starts + bx= " << inmap.m_bx << std::endl;
55 
56  m_triggersignal = false;
57 
58  auto initTrk =std::make_unique<Track>();
59 
60  //.
61  runSeedBuster( inmap );
62 
63  if ( !m_initialseeds.empty() && m_initialseeds.size() < 20 ) // if too much hits, then cannot process
64  initTrk->add( m_initialseeds[0].get() );
65  else {
66  initTrk->addnone();
67  if( m_debug) std::cout << "TTUTrackingAlg>process() ends: no initialseeds" << std::endl;
68  return false;
69  }
70 
71  auto trk = m_tracks.emplace_back( std::move(initTrk) ).get();
72 
73  //..
74  auto _seed = m_initialseeds.begin();
75  std::vector<Seed*> neighbors;
76 
77  while ( _seed != m_initialseeds.end() ) {
78 
79  findNeighbors( (*_seed).get() , neighbors );
80  filter( trk, neighbors );
81  executeTracker( trk, neighbors );
82  ghostBuster( trk );
83 
84  ++_seed;
85 
86  if ( _seed != m_initialseeds.end() ) {
87  auto initTrk = std::make_unique<Track>();
88  initTrk->add((*_seed).get());
89  m_tracks.emplace_back( std::move(initTrk) );
90 
91  }
92 
93  }
94 
95  if( m_debug) {
96  std::cout << "Total tracks: " << m_tracks.size() << std::endl;
97  for( auto& tr : m_tracks)
98  std::cout << "length: " << tr->length() << '\t';
99  std::cout << std::endl;
100  }
101 
102  //...
103  alignTracks();
104 
105  //.... Look at the first track and compare its track length
106 
107  int tracklen(0);
108  auto itr = m_tracks.begin();
109  if ( itr != m_tracks.end() ) tracklen = (*itr)->length();
110 
111  if ( tracklen >= m_mintrklength )
112  m_triggersignal = true;
113 
114  if( m_debug ) {
115  std::cout << "TTUTrackingAlg> trk len= "
116  << tracklen << '\t' << "triggered: "
117  << m_triggersignal << std::endl;
118  }
119 
120  //..... Clean up for next run
121 
122  cleanUp();
123 
124  //.......................................................
125 
126  if( m_debug ) std::cout << "TTUTrackingAlg>process ends" << std::endl;
127 
128  return true;
129 
130 }
131 
133 {
134 
135  int idx(0);
136  int idy(0);
137 
138  for(int i=0; i < 12; ++i)
139  {
140  idx = (m_SEscanorder[i] - 1);
141  std::bitset<6> station = inmap.input_sec[idx];
142 
143  if ( ! station.any() ) continue;
144 
145  for(int k=0; k < 6; ++k ) {
146 
147  idy = (m_STscanorder[k] - 1);
148  bool _hit = station[idy];
149 
150  if ( _hit ) {
151  m_initialseeds.emplace_back(std::make_unique<Seed>(idx, idy, 0) );
152  }
153  }
154  }
155 
156  //...
157  if ( m_debug ) std::cout << "SeedBuster: " << m_initialseeds.size() << std::endl;
158 
159 }
160 
161 int TTUTrackingAlg::executeTracker( Track * _trk, std::vector<Seed*> & neighbors)
162 {
163 
164  if ( m_debug ) std::cout << "executeTracker: " << neighbors.size() << std::endl;
165 
166  //...
167 
168  auto _itr = neighbors.begin();
169 
170  while( _itr != neighbors.end() ) {
171 
172  _trk->add( (*_itr) );
173 
174  std::vector<Seed*> _nextneighbors;
175 
176  findNeighbors( (*_itr) , _nextneighbors );
177 
178  filter( _trk, _nextneighbors );
179 
180  if ( _nextneighbors.size() == 1 )
181  executeTracker( _trk, _nextneighbors );
182 
183  //... bifurcation not considered at the moment
184 
185  ++_itr;
186 
187  }
188 
189  //...
190 
191 
192 
193  return 1;
194 
195 }
196 
197 void TTUTrackingAlg::findNeighbors( Seed * _seed, std::vector<Seed*> & neighbors)
198 {
199 
200  neighbors.clear();
201 
202  int _xo = _seed->m_sectorId;
203  int _yo = _seed->m_stationId;
204 
205  if( m_debug ) std::cout << "X: " << _xo+1 << " Y: " << _yo+1 << std::endl;
206 
207  auto _itr = m_initialseeds.begin();
208 
209  while( _itr != m_initialseeds.end() ) {
210 
211  int _difx = std::abs( _xo - (*_itr)->m_sectorId );
212  int _dify = std::abs( _yo - (*_itr)->m_stationId );
213 
214  if (m_debug) std::cout << "difference (x,y): " << _difx << "," << _dify << "\t";
215 
216  if ( _difx == 11 ) _difx = 1;
217 
218  if ( ((_difx == 1) && (_dify == 1)) ||
219  ((_difx == 1) && (_dify == 0)) ||
220  ((_difx == 0) && (_dify == 1)) )
221 
222  neighbors.push_back( (*_itr).get() );
223 
224  ++_itr;
225  }
226 
227  if (m_debug) std::cout << std::endl;
228 
229 }
230 
232  std::vector<Seed*> & _nbrs )
233 {
234 
235  //... filter: removes from neighbors list, seeds already present
236  //... in tracks
237 
238  for( auto _itr = _trk->m_seeds.begin();_itr != _trk->m_seeds.end(); ++_itr)
239  {
240  auto _isalready = std::find( _nbrs.begin(),_nbrs.end(), (*_itr) );
241 
242  if( _isalready != _nbrs.end() ) {
243  _nbrs.erase( _isalready );
244  if( m_debug ) std::cout << "removing ..." << std::endl;
245  }
246 
247 
248  }
249 
250 }
251 
252 void TTUTrackingAlg::ghostBuster( Track * currentTrk )
253 {
254 
255  //...do a final check to make sure there are no repeated seeds in track
256 
257  std::vector<Seed*>::iterator seedItr;
258 
259  std::sort( currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), SortBySector() );
260  std::sort( currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), SortByLayer() );
261 
262  seedItr = std::unique (currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), CompareSeeds() );
263 
264  currentTrk->m_seeds.resize(seedItr - currentTrk->m_seeds.begin());
265 
266  currentTrk->updateTrkLength();
267 
268 }
269 
271 {
272 
274 
275  std::sort( m_tracks.begin(), m_tracks.end(), compare );
276  std::reverse( m_tracks.begin(), m_tracks.end() );
277 
278  if( m_debug ) {
279  for( auto& tr : m_tracks)
280  std::cout << "Align tracks> trk len: " << tr->length() << " ";
281  std::cout << std::endl;
282  }
283 
284 }
285 
287 {
288 
289  m_tracks.clear();
290  m_initialseeds.clear();
291 
292 }
bool compare(const P &i, const P &j)
int m_bx
Definition: TTUInput.h:31
std::vector< std::unique_ptr< Seed > > m_initialseeds
int m_SEscanorder[12]
void setBoardSpecs(const TTUBoardSpecs::TTUBoardConfig &) override
void findNeighbors(Seed *, std::vector< Seed * > &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void ghostBuster(Track *)
TTUTrackingAlg()
Standard constructor.
std::vector< std::unique_ptr< Track > > m_tracks
void filter(Track *, std::vector< Seed * > &)
def unique(seq, keepstr=True)
Definition: tier0.py:25
std::vector< Seed * > m_seeds
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::array< std::bitset< 6 >, 12 > input_sec
Definition: TTUInput.h:37
int executeTracker(Track *, std::vector< Seed * > &)
~TTUTrackingAlg() override
Destructor.
int k[5][pyjets_maxn]
bool process(const TTUInput &) override
bool m_triggersignal
Definition: TTULogic.h:34
void runSeedBuster(const TTUInput &)
def move(src, dest)
Definition: eostools.py:511
void add(Seed *sd)