CMS 3D CMS Logo

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