test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  TracksItr itr1;
43  for (itr1=m_tracks.begin(); itr1!=m_tracks.end(); ++itr1)
44  delete (*itr1);
45 
46  SeedsItr itr2;
47  for (itr2=m_initialseeds.begin(); itr2!=m_initialseeds.end(); ++itr2)
48  delete (*itr2);
49 
50  //m_tracks.clear();
51  //m_initialseeds.clear();
52 
53 }
54 
55 //=============================================================================
57 {
58 
59  m_mintrklength = boardspecs.m_TrackLength;
60 
61 }
62 
63 bool TTUTrackingAlg::process( const TTUInput & inmap )
64 {
65 
66  if( m_debug) std::cout << "TTUTrackingAlg>process() starts + bx= " << inmap.m_bx << std::endl;
67 
68  m_triggersignal = false;
69 
70  Track * initTrk = new Track();
71 
72  //.
73  runSeedBuster( inmap );
74 
75  if ( m_initialseeds.size() > 0 && m_initialseeds.size() < 20 ) // if too much hits, then cannot process
76  initTrk->add( m_initialseeds[0] );
77  else {
78  initTrk->addnone();
79  if( m_debug) std::cout << "TTUTrackingAlg>process() ends: no initialseeds" << std::endl;
80  return false;
81  }
82 
83 
84 
85 
86 
87  m_tracks.push_back( initTrk );
88 
89  //..
90  SeedsItr _seed = m_initialseeds.begin();
91  std::vector<Seed*> neighbors;
92 
93  while ( _seed != m_initialseeds.end() ) {
94 
95  findNeighbors( (*_seed) , neighbors );
96  filter( initTrk, neighbors );
97  executeTracker( initTrk, neighbors );
98  ghostBuster( initTrk );
99 
100  ++_seed;
101 
102  if ( _seed != m_initialseeds.end() ) {
103  initTrk = new Track();
104  initTrk->add((*_seed));
105  m_tracks.push_back( initTrk );
106 
107  }
108 
109  }
110 
111  TracksItr itr;
112 
113  if( m_debug) {
114  std::cout << "Total tracks: " << m_tracks.size() << std::endl;
115  for( itr = m_tracks.begin(); itr != m_tracks.end(); ++itr)
116  std::cout << "length: " << (*itr)->length() << '\t';
117  std::cout << std::endl;
118  }
119 
120  //...
121  alignTracks();
122 
123  //.... Look at the first track and compare its track length
124 
125  int tracklen(0);
126  itr = m_tracks.begin();
127  if ( itr != m_tracks.end() ) tracklen = (*itr)->length();
128 
129  if ( tracklen >= m_mintrklength )
130  m_triggersignal = true;
131 
132  if( m_debug ) {
133  std::cout << "TTUTrackingAlg> trk len= "
134  << tracklen << '\t' << "triggered: "
135  << m_triggersignal << std::endl;
136  }
137 
138  //..... Clean up for next run
139 
140  cleanUp();
141 
142  //.......................................................
143 
144  if( m_debug ) std::cout << "TTUTrackingAlg>process ends" << std::endl;
145 
146  return true;
147 
148 }
149 
151 {
152 
153  int idx(0);
154  int idy(0);
155 
156  for(int i=0; i < 12; ++i)
157  {
158  idx = (m_SEscanorder[i] - 1);
159  std::bitset<6> station = inmap.input_sec[idx];
160 
161  if ( ! station.any() ) continue;
162 
163  for(int k=0; k < 6; ++k ) {
164 
165  idy = (m_STscanorder[k] - 1);
166  bool _hit = station[idy];
167 
168  if ( _hit ) {
169  Seed *_seed = new Seed( idx, idy, 0 );
170  m_initialseeds.push_back(_seed);
171  }
172  }
173  }
174 
175  //...
176  if ( m_debug ) std::cout << "SeedBuster: " << m_initialseeds.size() << std::endl;
177 
178 }
179 
180 int TTUTrackingAlg::executeTracker( Track * _trk, std::vector<Seed*> & neighbors)
181 {
182 
183  if ( m_debug ) std::cout << "executeTracker: " << neighbors.size() << std::endl;
184 
185  //...
186 
187  SeedsItr _itr = neighbors.begin();
188 
189  while( _itr != neighbors.end() ) {
190 
191  _trk->add( (*_itr) );
192 
193  std::vector<Seed*> _nextneighbors;
194 
195  findNeighbors( (*_itr) , _nextneighbors );
196 
197  filter( _trk, _nextneighbors );
198 
199  if ( _nextneighbors.size() == 1 )
200  executeTracker( _trk, _nextneighbors );
201 
202  //... bifurcation not considered at the moment
203 
204  ++_itr;
205 
206  }
207 
208  //...
209 
210 
211 
212  return 1;
213 
214 }
215 
216 void TTUTrackingAlg::findNeighbors( Seed * _seed, std::vector<Seed*> & neighbors)
217 {
218 
219  neighbors.clear();
220 
221  int _xo = _seed->m_sectorId;
222  int _yo = _seed->m_stationId;
223 
224  if( m_debug ) std::cout << "X: " << _xo+1 << " Y: " << _yo+1 << std::endl;
225 
226  SeedsItr _itr = m_initialseeds.begin();
227 
228  while( _itr != m_initialseeds.end() ) {
229 
230  int _difx = std::abs( _xo - (*_itr)->m_sectorId );
231  int _dify = std::abs( _yo - (*_itr)->m_stationId );
232 
233  if (m_debug) std::cout << "difference (x,y): " << _difx << "," << _dify << "\t";
234 
235  if ( _difx == 11 ) _difx = 1;
236 
237  if ( ((_difx == 1) && (_dify == 1)) ||
238  ((_difx == 1) && (_dify == 0)) ||
239  ((_difx == 0) && (_dify == 1)) )
240 
241  neighbors.push_back( (*_itr) );
242 
243  ++_itr;
244  }
245 
246  if (m_debug) std::cout << std::endl;
247 
248 }
249 
251  std::vector<Seed*> & _nbrs )
252 {
253 
254  //... filter: removes from neighbors list, seeds already present
255  //... in tracks
256 
257  SeedsItr _itr;
258 
259  for( _itr = _trk->m_seeds.begin();_itr != _trk->m_seeds.end(); ++_itr)
260  {
261  SeedsItr _isalready = std::find( _nbrs.begin(),_nbrs.end(), (*_itr) );
262 
263  if( _isalready != _nbrs.end() ) {
264  _nbrs.erase( _isalready );
265  if( m_debug ) std::cout << "removing ..." << std::endl;
266  }
267 
268 
269  }
270 
271 }
272 
273 void TTUTrackingAlg::ghostBuster( Track * currentTrk )
274 {
275 
276  //...do a final check to make sure there are no repeated seeds in track
277 
278  std::vector<Seed*>::iterator seedItr;
279 
280  std::sort( currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), SortBySector() );
281  std::sort( currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), SortByLayer() );
282 
283  seedItr = std::unique (currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), CompareSeeds() );
284 
285  currentTrk->m_seeds.resize(seedItr - currentTrk->m_seeds.begin());
286 
287  currentTrk->updateTrkLength();
288 
289 }
290 
292 {
293 
294  TracksItr itr;
296 
297  std::sort( m_tracks.begin(), m_tracks.end(), compare );
298  std::reverse( m_tracks.begin(), m_tracks.end() );
299 
300  if( m_debug ) {
301  for( itr = m_tracks.begin(); itr != m_tracks.end(); ++itr )
302  std::cout << "Align tracks> trk len: " << (*itr)->length() << " ";
303  std::cout << std::endl;
304  }
305 
306 }
307 
309 {
310 
311  TracksItr itr1;
312  for (itr1=m_tracks.begin(); itr1!=m_tracks.end(); ++itr1)
313  delete (*itr1);
314 
315  SeedsItr itr2;
316  for (itr2=m_initialseeds.begin(); itr2!=m_initialseeds.end(); ++itr2)
317  delete (*itr2);
318 
319  m_tracks.clear();
320  m_initialseeds.clear();
321 
322 }
int i
Definition: DBlmapReader.cc:9
int m_bx
Definition: TTUInput.h:52
int m_SEscanorder[12]
virtual ~TTUTrackingAlg()
Destructor.
bool process(const TTUInput &)
void findNeighbors(Seed *, std::vector< Seed * > &)
std::vector< Seed * > m_initialseeds
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
void ghostBuster(Track *)
TTUTrackingAlg()
Standard constructor.
std::vector< Seed * >::iterator SeedsItr
void filter(Track *, std::vector< Seed * > &)
std::vector< Seed * > m_seeds
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int executeTracker(Track *, std::vector< Seed * > &)
bool m_triggersignal
Definition: TTULogic.h:34
void runSeedBuster(const TTUInput &)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void setBoardSpecs(const TTUBoardSpecs::TTUBoardConfig &)
tuple cout
Definition: gather_cfg.py:145
std::vector< Track * >::iterator TracksItr
std::vector< Track * > m_tracks
void add(Seed *sd)
std::bitset< 6 > * input_sec
Definition: TTUInput.h:58