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< 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_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:71

Member Function Documentation

◆ add_cand()

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

Definition at line 34 of file CandCloner.h.

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

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

34  {
35  m_hits_to_add[idx].push_back(cand_info);
36 
38  }
std::vector< std::vector< IdxChi2List > > m_hits_to_add
Definition: CandCloner.h:55

◆ begin_eta_bin()

void mkfit::CandCloner::begin_eta_bin ( EventOfCombCandidates e_o_ccs,
std::vector< UpdateIndices > *  update_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, and mp_kalman_update_list.

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

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

◆ begin_iteration()

void mkfit::CandCloner::begin_iteration ( )

Definition at line 59 of file CandCloner.cc.

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

59  {
60  // Do nothing, "secondary" state vars updated when work completed/assigned.
61  }

◆ begin_layer()

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

Definition at line 46 of file CandCloner.cc.

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

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

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

◆ combCandWithOriginalIndex()

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

◆ doWork()

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

Definition at line 101 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().

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

◆ end_eta_bin()

void mkfit::CandCloner::end_eta_bin ( )

Definition at line 93 of file CandCloner.cc.

References mkfit::dtime().

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

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

◆ end_iteration()

void mkfit::CandCloner::end_iteration ( )

Definition at line 63 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().

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

◆ end_layer()

void mkfit::CandCloner::end_layer ( )

Definition at line 74 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().

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

◆ num_cands()

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

Definition at line 40 of file CandCloner.h.

References heavyIonCSV_trainingSettings::idx, and m_hits_to_add.

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

◆ processSeedRange()

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

Definition at line 124 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_update_list, pv::pT, mkfit::TrackBase::pT(), mkfit::IterationParams::pTCutOverlap, 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().

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

◆ 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:71
const IterationParams * mp_iteration_params
Definition: CandCloner.h:57
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 55 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 54 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 54 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 67 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 66 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 66 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 58 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 60 of file CandCloner.h.

Referenced by begin_eta_bin().

◆ mp_iteration_params

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

Definition at line 57 of file CandCloner.h.

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

◆ mp_kalman_update_list

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

Definition at line 59 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 71 of file CandCloner.h.

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