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