CMS 3D CMS Logo

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(), SortBySector());
228  std::sort(currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), SortByLayer());
229 
230  seedItr = std::unique(currentTrk->m_seeds.begin(), currentTrk->m_seeds.end(), CompareSeeds());
231 
232  currentTrk->m_seeds.resize(seedItr - currentTrk->m_seeds.begin());
233 
234  currentTrk->updateTrkLength();
235 }
236 
239 
240  std::sort(m_tracks.begin(), m_tracks.end(), compare);
241  std::reverse(m_tracks.begin(), m_tracks.end());
242 
243  if (m_debug) {
244  for (auto& tr : m_tracks)
245  std::cout << "Align tracks> trk len: " << tr->length() << " ";
246  std::cout << std::endl;
247  }
248 }
249 
251  m_tracks.clear();
252  m_initialseeds.clear();
253 }
TTUTrackingAlg::SortByLayer
Definition: TTUTrackingAlg.h:140
TTUTrackingAlg.h
mps_fire.i
i
Definition: mps_fire.py:355
TTUTrackingAlg::Seed::m_stationId
int m_stationId
Definition: TTUTrackingAlg.h:56
relativeConstraints.station
station
Definition: relativeConstraints.py:67
gather_cfg.cout
cout
Definition: gather_cfg.py:144
TTUTrackingAlg::Track::add
void add(Seed *sd)
Definition: TTUTrackingAlg.h:69
TTUTrackingAlg::cleanUp
void cleanUp()
Definition: TTUTrackingAlg.cc:250
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
training_settings.idx
idx
Definition: training_settings.py:16
TTUTrackingAlg::CompareSeeds
Definition: TTUTrackingAlg.h:128
groupFilesInBlocks.reverse
reverse
Definition: groupFilesInBlocks.py:131
TTUTrackingAlg::m_mintrklength
int m_mintrklength
Definition: TTUTrackingAlg.h:122
TTUTrackingAlg::filter
void filter(Track *, std::vector< Seed * > &)
Definition: TTUTrackingAlg.cc:207
TTUTrackingAlg::Seed
Definition: TTUTrackingAlg.h:40
TTUTrackingAlg::setBoardSpecs
void setBoardSpecs(const TTUBoardSpecs::TTUBoardConfig &) override
Definition: TTUTrackingAlg.cc:38
TTUInput
Definition: TTUInput.h:18
TTUTrackingAlg::CompareMechanism
Definition: TTUTrackingAlg.h:98
TTUTrackingAlg::runSeedBuster
void runSeedBuster(const TTUInput &)
Definition: TTUTrackingAlg.cc:119
TTUTrackingAlg::executeTracker
int executeTracker(Track *, std::vector< Seed * > &)
Definition: TTUTrackingAlg.cc:145
dqmdumpme.k
k
Definition: dqmdumpme.py:60
TTUTrackingAlg::SortBySector
Definition: TTUTrackingAlg.h:136
TTUTrackingAlg::m_SEscanorder
int m_SEscanorder[12]
Definition: TTUTrackingAlg.h:120
TTUBoardSpecs::TTUBoardConfig
Definition: TTUBoardSpecs.h:25
TTUTrackingAlg::Track::m_seeds
std::vector< Seed * > m_seeds
Definition: TTUTrackingAlg.h:86
TTUTrackingAlg::ghostBuster
void ghostBuster(Track *)
Definition: TTUTrackingAlg.cc:222
TTUTrackingAlg::Track::updateTrkLength
void updateTrkLength()
Definition: TTUTrackingAlg.h:82
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:28
TTUTrackingAlg::Track
Definition: TTUTrackingAlg.h:60
TTUTrackingAlg::m_STscanorder
int m_STscanorder[6]
Definition: TTUTrackingAlg.h:118
TTULogic::m_triggersignal
bool m_triggersignal
Definition: TTULogic.h:30
eostools.move
def move(src, dest)
Definition: eostools.py:511
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
TTUTrackingAlg::findNeighbors
void findNeighbors(Seed *, std::vector< Seed * > &)
Definition: TTUTrackingAlg.cc:175
TTUInput::m_bx
int m_bx
Definition: TTUInput.h:30
TTUInput::input_sec
std::array< std::bitset< 6 >, 12 > input_sec
Definition: TTUInput.h:36
TTUTrackingAlg::~TTUTrackingAlg
~TTUTrackingAlg() override
Destructor.
Definition: TTUTrackingAlg.cc:35
TTUTrackingAlg::m_tracks
std::vector< std::unique_ptr< Track > > m_tracks
Definition: TTUTrackingAlg.h:124
TTUTrackingAlg::m_initialseeds
std::vector< std::unique_ptr< Seed > > m_initialseeds
Definition: TTUTrackingAlg.h:126
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TTUTrackingAlg::alignTracks
void alignTracks()
Definition: TTUTrackingAlg.cc:237
TTUTrackingAlg::process
bool process(const TTUInput &) override
Definition: TTUTrackingAlg.cc:42
TTUTrackingAlg::m_debug
bool m_debug
Definition: TTUTrackingAlg.h:149
compare
bool compare(const P &i, const P &j)
Definition: BDHadronTrackMonitoringAnalyzer.cc:203
TTUTrackingAlg::TTUTrackingAlg
TTUTrackingAlg()
Standard constructor.
Definition: TTUTrackingAlg.cc:16
TTUBoardSpecs::TTUBoardConfig::m_TrackLength
int m_TrackLength
Definition: TTUBoardSpecs.h:36
TTUTrackingAlg::Seed::m_sectorId
int m_sectorId
Definition: TTUTrackingAlg.h:53