CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Attributes | Private Attributes
mkfit::CandCloner Class Reference

#include <CandCloner.h>

Public Member Functions

void add_cand (int idx, const IdxChi2List &cand_info)
 
void begin_eta_bin (EventOfCombCandidates *e_o_ccs, std::vector< UpdateIndices > *update_list, std::vector< UpdateIndices > *overlap_list, std::vector< std::vector< TrackCand >> *extra_cands, int start_seed, int n_seeds)
 
void begin_iteration ()
 
void begin_layer (int lay)
 
 CandCloner ()
 
CombCandidatecombCandWithOriginalIndex (int idx)
 
void doWork (int idx)
 
void end_eta_bin ()
 
void end_iteration ()
 
void end_layer ()
 
int num_cands (int idx)
 
void processSeedRange (int is_beg, int is_end)
 
void release ()
 
void setup (const IterationParams &ip)
 

Static Public Attributes

static const int s_max_seed_range = 8
 

Private Attributes

std::vector< std::vector< IdxChi2List > > m_hits_to_add
 
int m_idx_max
 
int m_idx_max_prev
 
int m_layer
 
int m_n_seeds
 
int m_start_seed
 
EventOfCombCandidatesmp_event_of_comb_candidates
 
std::vector< std::vector< TrackCand > > * mp_extra_cands
 
const IterationParamsmp_iteration_params = nullptr
 
std::vector< UpdateIndices > * mp_kalman_overlap_list
 
std::vector< UpdateIndices > * mp_kalman_update_list
 
std::vector< std::vector< TrackCand > > t_cands_for_next_lay
 

Detailed Description

Definition at line 16 of file CandCloner.h.

Constructor & Destructor Documentation

◆ CandCloner()

mkfit::CandCloner::CandCloner ( )
inline

Definition at line 21 of file CandCloner.h.

References s_max_seed_range, and t_cands_for_next_lay.

static const int s_max_seed_range
Definition: CandCloner.h:19
std::vector< std::vector< TrackCand > > t_cands_for_next_lay
Definition: CandCloner.h:72

Member Function Documentation

◆ add_cand()

void mkfit::CandCloner::add_cand ( int  idx,
const IdxChi2List cand_info 
)
inline

Definition at line 35 of file CandCloner.h.

References heavyIonCSV_trainingSettings::idx, m_hits_to_add, m_idx_max, and SiStripPI::max.

Referenced by mkfit::MkFinder::findCandidatesCloneEngine().

35  {
36  m_hits_to_add[idx].push_back(cand_info);
37 
39  }
std::vector< std::vector< IdxChi2List > > m_hits_to_add
Definition: CandCloner.h:56

◆ begin_eta_bin()

void mkfit::CandCloner::begin_eta_bin ( EventOfCombCandidates e_o_ccs,
std::vector< UpdateIndices > *  update_list,
std::vector< UpdateIndices > *  overlap_list,
std::vector< std::vector< TrackCand >> *  extra_cands,
int  start_seed,
int  n_seeds 
)

Definition at line 25 of file CandCloner.cc.

References mkfit::dtime(), mps_fire::i, m_hits_to_add, m_n_seeds, m_start_seed, mp_event_of_comb_candidates, mp_extra_cands, mp_kalman_overlap_list, and mp_kalman_update_list.

Referenced by mkfit::MkBuilder::find_tracks_in_layers().

30  {
32  mp_kalman_update_list = update_list;
33  mp_kalman_overlap_list = overlap_list;
34  mp_extra_cands = extra_cands;
35  m_start_seed = start_seed;
36  m_n_seeds = n_seeds;
37  m_hits_to_add.resize(n_seeds);
38 
39  for (int i = 0; i < n_seeds; ++i)
40  m_hits_to_add[i].reserve(4);
41 
42 #ifdef CC_TIME_ETA
43  printf("CandCloner::begin_eta_bin\n");
44  t_eta = dtime();
45 #endif
46  }
EventOfCombCandidates * mp_event_of_comb_candidates
Definition: CandCloner.h:59
std::vector< std::vector< IdxChi2List > > m_hits_to_add
Definition: CandCloner.h:56
std::vector< std::vector< TrackCand > > * mp_extra_cands
Definition: CandCloner.h:61
double dtime()
std::vector< UpdateIndices > * mp_kalman_overlap_list
Definition: CandCloner.h:60
std::vector< UpdateIndices > * mp_kalman_update_list
Definition: CandCloner.h:60

◆ begin_iteration()

void mkfit::CandCloner::begin_iteration ( )

Definition at line 62 of file CandCloner.cc.

Referenced by mkfit::MkBuilder::find_tracks_in_layers().

62  {
63  // Do nothing, "secondary" state vars updated when work completed/assigned.
64  }

◆ begin_layer()

void mkfit::CandCloner::begin_layer ( int  lay)

Definition at line 48 of file CandCloner.cc.

References mkfit::dtime(), m_idx_max, m_idx_max_prev, m_layer, mp_kalman_overlap_list, and mp_kalman_update_list.

Referenced by mkfit::MkBuilder::find_tracks_in_layers().

48  {
49  m_layer = lay;
50 
51  m_idx_max = 0;
52  m_idx_max_prev = 0;
53 
54  mp_kalman_update_list->clear();
55  mp_kalman_overlap_list->clear();
56 
57 #ifdef CC_TIME_LAYER
58  t_lay = dtime();
59 #endif
60  }
double dtime()
std::vector< UpdateIndices > * mp_kalman_overlap_list
Definition: CandCloner.h:60
std::vector< UpdateIndices > * mp_kalman_update_list
Definition: CandCloner.h:60

◆ combCandWithOriginalIndex()

CombCandidate& mkfit::CandCloner::combCandWithOriginalIndex ( int  idx)
inline

◆ doWork()

void mkfit::CandCloner::doWork ( int  idx)

Definition at line 104 of file CandCloner.cc.

References dprintf, heavyIonCSV_trainingSettings::idx, m_idx_max_prev, SiStripPI::min, processSeedRange(), and s_max_seed_range.

Referenced by end_iteration(), and end_layer().

104  {
105  dprintf("CandCloner::DoWork assigning work from seed %d to %d\n", m_idx_max_prev, idx);
106 
107  int beg = m_idx_max_prev;
108  int the_end = idx;
109 
110  dprintf("CandCloner::DoWork working on beg=%d to the_end=%d\n", beg, the_end);
111 
112  while (beg != the_end) {
113  int end = std::min(beg + s_max_seed_range, the_end);
114 
115  dprintf("CandCloner::DoWork processing %4d -> %4d\n", beg, end);
116 
117  processSeedRange(beg, end);
118 
119  beg = end;
120  }
121 
123  }
static const int s_max_seed_range
Definition: CandCloner.h:19
void processSeedRange(int is_beg, int is_end)
Definition: CandCloner.cc:127
#define dprintf(...)
Definition: Debug.h:98

◆ end_eta_bin()

void mkfit::CandCloner::end_eta_bin ( )

Definition at line 96 of file CandCloner.cc.

References mkfit::dtime().

Referenced by mkfit::MkBuilder::find_tracks_in_layers().

96  {
97 #ifdef CC_TIME_ETA
98  t_eta = dtime() - t_eta;
99  printf("CandCloner::end_eta_bin t_eta=%8.6f\n", t_eta);
100 #endif
101  }
double dtime()

◆ end_iteration()

void mkfit::CandCloner::end_iteration ( )

Definition at line 66 of file CandCloner.cc.

References doWork(), dprintf, m_idx_max, m_idx_max_prev, and s_max_seed_range.

Referenced by mkfit::MkBuilder::find_tracks_in_layers().

66  {
67  int proc_n = m_idx_max - m_idx_max_prev;
68 
69  dprintf("CandCloner::end_iteration process %d, max_prev=%d, max=%d\n", proc_n, m_idx_max_prev, m_idx_max);
70 
71  if (proc_n >= s_max_seed_range) {
72  // Round to multiple of s_max_seed_range.
74  }
75  }
static const int s_max_seed_range
Definition: CandCloner.h:19
void doWork(int idx)
Definition: CandCloner.cc:104
#define dprintf(...)
Definition: Debug.h:98

◆ end_layer()

void mkfit::CandCloner::end_layer ( )

Definition at line 77 of file CandCloner.cc.

References doWork(), mkfit::dtime(), mps_fire::i, m_hits_to_add, m_idx_max, m_idx_max_prev, m_layer, and m_n_seeds.

Referenced by mkfit::MkBuilder::find_tracks_in_layers().

77  {
78  if (m_n_seeds > m_idx_max_prev) {
80  }
81 
82  for (int i = 0; i < m_n_seeds; ++i) {
83  m_hits_to_add[i].clear();
84  }
85 
86 #ifdef CC_TIME_LAYER
87  t_lay = dtime() - t_lay;
88  printf("CandCloner::end_layer %d -- t_lay=%8.6f\n", m_layer, t_lay);
89  printf(" m_idx_max=%d, m_idx_max_prev=%d, issued work=%d\n",
90  m_idx_max,
93 #endif
94  }
std::vector< std::vector< IdxChi2List > > m_hits_to_add
Definition: CandCloner.h:56
void doWork(int idx)
Definition: CandCloner.cc:104
double dtime()

◆ num_cands()

int mkfit::CandCloner::num_cands ( int  idx)
inline

Definition at line 41 of file CandCloner.h.

References heavyIonCSV_trainingSettings::idx, and m_hits_to_add.

41 { return m_hits_to_add[idx].size(); }
std::vector< std::vector< IdxChi2List > > m_hits_to_add
Definition: CandCloner.h:56

◆ processSeedRange()

void mkfit::CandCloner::processSeedRange ( int  is_beg,
int  is_end 
)

Definition at line 127 of file CandCloner.cc.

References mkfit::TrackCand::addHitIdx(), mkfit::EventOfCombCandidates::cand(), nano_mu_local_reco_cff::chi2, mkfit::IdxChi2List::chi2_hit, mkfit::CombCandidate::clear(), cuy::cv, dprint, dprintf, mkfit::CombCandidate::emplace_back(), mkfit::CombCandidate::Finding, mkfit::IdxChi2List::hitIdx, cuy::ii, mkfit::TrackCand::incOverlapCount(), createfilelist::int, mkfit::HitMatch::m_hit_idx, m_hits_to_add, m_layer, m_start_seed, mkfit::IterationParams::maxCandsPerSeed, mkfit::IdxChi2List::module, mp_event_of_comb_candidates, mp_iteration_params, mp_kalman_overlap_list, mp_kalman_update_list, pv::pT, mkfit::TrackBase::pT(), mkfit::IterationParams::pTCutOverlap, mkfit::IterationParams::recheckOverlap, mkfit::CombCandidate::refBestShortCand(), mkfit::CombCandidate::resize(), mkfit::IdxChi2List::score, mkfit::TrackBase::score(), mkfit::CombCandidate::setBestShortCand(), mkfit::TrackBase::setScore(), jetUpdater_cfi::sort, mkfit::sortByScoreTrackCand(), mkfit::CombCandidate::state(), t_cands_for_next_lay, and mkfit::IdxChi2List::trkIdx.

Referenced by doWork().

127  {
128  // Process new hits for a range of seeds.
129 
130  // bool debug = true;
131 
132  dprintf("\nCandCloner::ProcessSeedRange is_beg=%d, is_end=%d\n", is_beg, is_end);
133 
134  //1) sort the candidates
135  for (int is = is_beg; is < is_end; ++is) {
136  std::vector<IdxChi2List> &hitsForSeed = m_hits_to_add[is];
137 
138  CombCandidate &ccand = mp_event_of_comb_candidates->cand(m_start_seed + is);
139  std::vector<TrackCand> &extras = (*mp_extra_cands)[is];
140  auto extra_i = extras.begin();
141  auto extra_e = extras.end();
142 
143  // Extras are sorted by candScore.
144 
145 #ifdef DEBUG
146  dprint(" seed n " << is << " with input candidates=" << hitsForSeed.size());
147  for (int ih = 0; ih < (int)hitsForSeed.size(); ih++) {
148  dprint("trkIdx=" << hitsForSeed[ih].trkIdx << " hitIdx=" << hitsForSeed[ih].hitIdx
149  << " chi2=" << hitsForSeed[ih].chi2 << std::endl
150  << " "
151  << "original pt=" << ccand[hitsForSeed[ih].trkIdx].pT() << " "
152  << "nTotalHits=" << ccand[hitsForSeed[ih].trkIdx].nTotalHits() << " "
153  << "nFoundHits=" << ccand[hitsForSeed[ih].trkIdx].nFoundHits() << " "
154  << "chi2=" << ccand[hitsForSeed[ih].trkIdx].chi2());
155  }
156 #endif
157 
158  if (!hitsForSeed.empty()) {
159  //sort the new hits
160  std::sort(hitsForSeed.begin(), hitsForSeed.end(), sortCandListByScore);
161 
162  int num_hits = (int)hitsForSeed.size();
163 
164  // This is from buffer, we know it was cleared after last usage.
165  std::vector<TrackCand> &cv = t_cands_for_next_lay[is - is_beg];
166 
167  int n_pushed = 0;
168 
169  // Loop over available hits. There are extra loop exit checks every time
170  // a new candidate is inserted into the new candidate_vector.
171  for (int ih = 0; ih < num_hits; ih++) {
172  const IdxChi2List &h2a = hitsForSeed[ih];
173 
174  TrackCand tc(ccand[h2a.trkIdx]);
175  tc.addHitIdx(h2a.hitIdx, m_layer, h2a.chi2_hit);
176  tc.setScore(h2a.score);
177 
178  if (h2a.hitIdx == -2) {
179  if (h2a.score > ccand.refBestShortCand().score()) {
180  ccand.setBestShortCand(tc);
181  }
182  continue;
183  }
184 
185  // Could also skip storing of cands with last -3 hit.
186 
187  // Squeeze in extra tracks that are better than current one.
188  while (extra_i != extra_e && sortByScoreTrackCand(*extra_i, tc) &&
189  n_pushed < mp_iteration_params->maxCandsPerSeed) {
190  cv.emplace_back(*extra_i);
191  ++n_pushed;
192  ++extra_i;
193  }
194 
195  if (n_pushed >= mp_iteration_params->maxCandsPerSeed)
196  break;
197 
198  if (h2a.hitIdx >= 0) {
199  // set the overlap if we have it and pT > pTCutOverlap
200  HitMatch *hm;
201  if (tc.pT() > mp_iteration_params->pTCutOverlap &&
202  (hm = ccand[h2a.trkIdx].findOverlap(h2a.hitIdx, h2a.module))) {
204  // Special overlap_list if the overlap hit needs to be re-checked after primary update.
205  mp_kalman_overlap_list->emplace_back(
206  UpdateIndices(m_start_seed + is, n_pushed, h2a.hitIdx, hm->m_hit_idx));
207  } else {
208  tc.addHitIdx(hm->m_hit_idx, m_layer, 0);
209  tc.incOverlapCount();
210  mp_kalman_update_list->emplace_back(UpdateIndices(m_start_seed + is, n_pushed, h2a.hitIdx, -1));
211  }
212  } else {
213  mp_kalman_update_list->emplace_back(UpdateIndices(m_start_seed + is, n_pushed, h2a.hitIdx, -1));
214  }
215  }
216 
217  cv.emplace_back(tc);
218  ++n_pushed;
219 
220  if (n_pushed >= mp_iteration_params->maxCandsPerSeed)
221  break;
222  }
223 
224  // Add remaining extras as long as there is still room for them.
225  while (extra_i != extra_e && n_pushed < mp_iteration_params->maxCandsPerSeed) {
226  cv.emplace_back(*extra_i);
227  ++n_pushed;
228  ++extra_i;
229  }
230 
231  // Can not use ccand.swap(cv) -- allocations for TrackCand vectors need to be
232  // in the same memory segment for gather operation to work in backward-fit.
233  ccand.resize(cv.size());
234  for (size_t ii = 0; ii < cv.size(); ++ii) {
235  ccand[ii] = cv[ii];
236  }
237  cv.clear();
238  } else // hitsForSeed.empty()
239  {
240  if (ccand.state() == CombCandidate::Finding) {
241  ccand.clear();
242 
243  while (extra_i != extra_e) {
244  ccand.emplace_back(*extra_i);
245  ++extra_i;
246  }
247  }
248  }
249 
250  extras.clear();
251  }
252  }
EventOfCombCandidates * mp_event_of_comb_candidates
Definition: CandCloner.h:59
std::vector< std::vector< IdxChi2List > > m_hits_to_add
Definition: CandCloner.h:56
cv
Definition: cuy.py:363
std::vector< std::vector< TrackCand > > t_cands_for_next_lay
Definition: CandCloner.h:72
const IterationParams * mp_iteration_params
Definition: CandCloner.h:58
CombCandidate & cand(int i)
ii
Definition: cuy.py:589
bool sortByScoreTrackCand(const TrackCand &cand1, const TrackCand &cand2)
#define dprint(x)
Definition: Debug.h:95
std::vector< UpdateIndices > * mp_kalman_overlap_list
Definition: CandCloner.h:60
std::vector< UpdateIndices > * mp_kalman_update_list
Definition: CandCloner.h:60
#define dprintf(...)
Definition: Debug.h:98

◆ release()

void mkfit::CandCloner::release ( )

Definition at line 23 of file CandCloner.cc.

References mp_iteration_params.

23 { mp_iteration_params = nullptr; }
const IterationParams * mp_iteration_params
Definition: CandCloner.h:58

◆ setup()

void mkfit::CandCloner::setup ( const IterationParams ip)

Definition at line 16 of file CandCloner.cc.

References iseed, mkfit::IterationParams::maxCandsPerSeed, mp_iteration_params, s_max_seed_range, and t_cands_for_next_lay.

16  {
17  mp_iteration_params = &ip;
18  for (int iseed = 0; iseed < s_max_seed_range; ++iseed) {
20  }
21  }
static const int s_max_seed_range
Definition: CandCloner.h:19
std::vector< std::vector< TrackCand > > t_cands_for_next_lay
Definition: CandCloner.h:72
const IterationParams * mp_iteration_params
Definition: CandCloner.h:58
int iseed
Definition: AMPTWrapper.h:134

Member Data Documentation

◆ m_hits_to_add

std::vector<std::vector<IdxChi2List> > mkfit::CandCloner::m_hits_to_add
private

Definition at line 56 of file CandCloner.h.

Referenced by add_cand(), begin_eta_bin(), end_layer(), num_cands(), and processSeedRange().

◆ m_idx_max

int mkfit::CandCloner::m_idx_max
private

Definition at line 55 of file CandCloner.h.

Referenced by add_cand(), begin_layer(), end_iteration(), and end_layer().

◆ m_idx_max_prev

int mkfit::CandCloner::m_idx_max_prev
private

Definition at line 55 of file CandCloner.h.

Referenced by begin_layer(), doWork(), end_iteration(), and end_layer().

◆ m_layer

int mkfit::CandCloner::m_layer
private

Definition at line 68 of file CandCloner.h.

Referenced by begin_layer(), end_layer(), and processSeedRange().

◆ m_n_seeds

int mkfit::CandCloner::m_n_seeds
private

Definition at line 67 of file CandCloner.h.

Referenced by begin_eta_bin(), and end_layer().

◆ m_start_seed

int mkfit::CandCloner::m_start_seed
private

Definition at line 67 of file CandCloner.h.

Referenced by begin_eta_bin(), and processSeedRange().

◆ mp_event_of_comb_candidates

EventOfCombCandidates* mkfit::CandCloner::mp_event_of_comb_candidates
private

Definition at line 59 of file CandCloner.h.

Referenced by begin_eta_bin(), combCandWithOriginalIndex(), and processSeedRange().

◆ mp_extra_cands

std::vector<std::vector<TrackCand> >* mkfit::CandCloner::mp_extra_cands
private

Definition at line 61 of file CandCloner.h.

Referenced by begin_eta_bin().

◆ mp_iteration_params

const IterationParams* mkfit::CandCloner::mp_iteration_params = nullptr
private

Definition at line 58 of file CandCloner.h.

Referenced by processSeedRange(), release(), and setup().

◆ mp_kalman_overlap_list

std::vector<UpdateIndices> * mkfit::CandCloner::mp_kalman_overlap_list
private

Definition at line 60 of file CandCloner.h.

Referenced by begin_eta_bin(), begin_layer(), and processSeedRange().

◆ mp_kalman_update_list

std::vector<UpdateIndices>* mkfit::CandCloner::mp_kalman_update_list
private

Definition at line 60 of file CandCloner.h.

Referenced by begin_eta_bin(), begin_layer(), and processSeedRange().

◆ s_max_seed_range

const int mkfit::CandCloner::s_max_seed_range = 8
static

Definition at line 19 of file CandCloner.h.

Referenced by CandCloner(), doWork(), end_iteration(), and setup().

◆ t_cands_for_next_lay

std::vector<std::vector<TrackCand> > mkfit::CandCloner::t_cands_for_next_lay
private

Definition at line 72 of file CandCloner.h.

Referenced by CandCloner(), processSeedRange(), and setup().