Skip to content

Commit

Permalink
Merge pull request #345 from trackreco/backward_search_allow_holes
Browse files Browse the repository at this point in the history
Backward search implementation
mmasciov authored Aug 24, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 2cb5720 + f015c76 commit 53b4d5f
Showing 13 changed files with 393 additions and 97 deletions.
1 change: 1 addition & 0 deletions Config.cc
Original file line number Diff line number Diff line change
@@ -105,6 +105,7 @@ namespace Config

bool kludgeCmsHitErrors = false;
bool backwardFit = false;
bool backwardSearch = true;
bool includePCA = false;

bool json_dump_before = false;
1 change: 1 addition & 0 deletions Config.h
Original file line number Diff line number Diff line change
@@ -389,6 +389,7 @@ namespace Config

extern bool kludgeCmsHitErrors;
extern bool backwardFit;
extern bool backwardSearch;
extern bool includePCA;

// NAN and silly track parameter tracking options
58 changes: 45 additions & 13 deletions Geoms/CMS-2017.cc
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ namespace
sp.append_plan(47, false);
sp.fill_plan(48, 53); // TID, 6 layers
sp.fill_plan(54, 71); // TEC, 18 layers
sp.finalize_plan();
sp.set_iterator_limits(2, 0);
}
{
SteeringParams &sp = ic.m_steering_params[TrackerInfo::Reg_Transition_Neg];
@@ -51,17 +51,17 @@ namespace
sp.fill_plan(48, 53); // TID, 6 layers
sp.fill_plan(10, 17); // TOB, 8 layers
sp.fill_plan(54, 71); // TEC, 18 layers
sp.finalize_plan();
sp.set_iterator_limits(2, 0);
}
{
SteeringParams &sp = ic.m_steering_params[TrackerInfo::Reg_Barrel];
sp.reserve_plan(3 + 1 + 6 + 8);
sp.fill_plan(0, 1, false, true); // bk-fit only
sp.append_plan(2, true); // pickup-only
sp.append_plan(3, false);
sp.fill_plan(4, 9); // TIB, 6 layers
sp.fill_plan(10, 17); // TOB, 8 layers
sp.finalize_plan();
sp.fill_plan(4, 9); // TIB, 6 layers [ 4, 9]
sp.fill_plan(10, 17); // TOB, 8 layers [10, 17]
sp.set_iterator_limits(2, 0);
}
{
SteeringParams &sp = ic.m_steering_params[TrackerInfo::Reg_Transition_Pos];
@@ -72,11 +72,11 @@ namespace
sp.append_plan(18, false);
sp.append_plan(19, false);
sp.append_plan(20, false);
sp.fill_plan(4, 9); // TIB, 6 layers
sp.fill_plan(21, 26); // TID, 6 layers
sp.fill_plan(10, 17); // TOB, 8 layers
sp.fill_plan(27, 44); // TEC, 18 layers
sp.finalize_plan();
sp.fill_plan(4, 9); // TIB, 6 layers [ 7, 12]
sp.fill_plan(21, 26); // TID, 6 layers [13, 18]
sp.fill_plan(10, 17); // TOB, 8 layers [19, 26]
sp.fill_plan(27, 44); // TEC, 18 layers [27, 44]
sp.set_iterator_limits(2, 0);
}
{
SteeringParams &sp = ic.m_steering_params[TrackerInfo::Reg_Endcap_Pos];
@@ -86,12 +86,42 @@ namespace
sp.append_plan(18, false);
sp.append_plan(19, false);
sp.append_plan(20, false);
sp.fill_plan(21, 26); // TID, 6 layers
sp.fill_plan(27, 44); // TEC, 18 layers
sp.finalize_plan();
sp.fill_plan(21, 26); // TID, 6 layers [ 6, 11]
sp.fill_plan(27, 44); // TEC, 18 layers [12, 29]
sp.set_iterator_limits(2, 0);
}
}

void OverrideSteeringParams_Iter7(IterationConfig& ic)
{
ic.m_backward_search = true;
ic.m_backward_params = ic.m_params;
ic.m_backward_params.maxHolesPerCand = 2;
ic.m_backward_params.maxConsecHoles = 2;
// Remove pixel layers from FwdSearch, add them to BkwSearch
auto &spv = ic.m_steering_params;
spv[TrackerInfo::Reg_Endcap_Neg] .set_iterator_limits(8, 6, 19);
spv[TrackerInfo::Reg_Transition_Neg].set_iterator_limits(9, 7, 34);
spv[TrackerInfo::Reg_Barrel] .set_iterator_limits(6, 4, 8);
spv[TrackerInfo::Reg_Transition_Pos].set_iterator_limits(9, 7, 34);
spv[TrackerInfo::Reg_Endcap_Pos] .set_iterator_limits(8, 6, 19);
}

void OverrideSteeringParams_Iter8(IterationConfig& ic)
{
ic.m_backward_search = true;
ic.m_backward_params = ic.m_params;
ic.m_backward_params.maxHolesPerCand = 2;
ic.m_backward_params.maxConsecHoles = 2;
// Remove pixel/tib/tid layers from FwdSearch, add them to BkwSearch/
auto &spv = ic.m_steering_params;
spv[TrackerInfo::Reg_Endcap_Neg] .set_iterator_limits(12, 12, 24);
spv[TrackerInfo::Reg_Transition_Neg].set_iterator_limits(27, 19, 39);
spv[TrackerInfo::Reg_Barrel] .set_iterator_limits(12, 10, 14);
spv[TrackerInfo::Reg_Transition_Pos].set_iterator_limits(27, 19, 39);
spv[TrackerInfo::Reg_Endcap_Pos] .set_iterator_limits(12, 12, 24);
}

void SetupIterationParams(IterationParams& ip, unsigned int it=0)
{
if (it == 0)
@@ -391,6 +421,7 @@ namespace
fill_hit_selection_windows_params(ii[6]);

ii[7].Clone(ii[0]);
OverrideSteeringParams_Iter7(ii[7]);
SetupIterationParams(ii[7].m_params, 7);
ii[7].set_iteration_index_and_track_algorithm(7, (int) TrackBase::TrackAlgorithm::pixelLessStep);
ii[7].set_seed_cleaning_params(2.0, 0.135, 0.135, 0.135, 0.135, 0.135, 0.135, 0.135, 0.135);
@@ -399,6 +430,7 @@ namespace
fill_hit_selection_windows_params(ii[7]);

ii[8].Clone(ii[0]);
OverrideSteeringParams_Iter8(ii[8]);
SetupIterationParams(ii[8].m_params, 8);
ii[8].set_iteration_index_and_track_algorithm(8, (int) TrackBase::TrackAlgorithm::tobTecStep);
ii[8].set_seed_cleaning_params(2.0, 0.135, 0.135, 0.135, 0.135, 0.135, 0.135, 0.135, 0.135);
68 changes: 64 additions & 4 deletions mkFit/HitStructures.cc
Original file line number Diff line number Diff line change
@@ -480,11 +480,11 @@ void CombCandidate::ImportSeed(const Track& seed, int region)
{
emplace_back(TrackCand(seed, this));

m_state = CombCandidate::Dormant;
m_last_seed_layer = seed.getLastHitLyr();
m_state = CombCandidate::Dormant;
m_pickup_layer = seed.getLastHitLyr();
#ifdef DUMPHITWINDOW
m_seed_algo = seed.algoint();
m_seed_label = seed.label();
m_seed_algo = seed.algoint();
m_seed_label = seed.label();
#endif

TrackCand &cand = back();
@@ -545,4 +545,64 @@ void CombCandidate::MergeCandsAndBestShortOne(const IterationParams& params, boo
// assert(capacity() == (size_t)Config::maxCandsPerSeed);
}

void CombCandidate::BeginBkwSearch()
{
// The best candidate is assumed to be in position 0, after
// MergeCandsAndBestShortOne has been called.
// Other cands are dropped, their hits are not but they could be.
// This is to be called before backward-search to start with a single
// input candidate for backward cominatorial search.
//
// m_state and m_pickup_layer are also set.

assert( ! empty() );

resize(1);

TrackCand &tc = (*this)[0];

// Could compatify m_hots, removing all not used by element 0.
// Not trivial, as I have to start from back to get to the front
// and then reorder. Or have some semi-complicated scheme to
// put them at the back and then grow new hits in the front.

m_state = Dormant;
m_pickup_layer = m_hots[0].m_hot.layer;
m_lastHitIdx_before_bkwsearch = tc.lastCcIndex();
m_nInsideMinusOneHits_before_bkwsearch = tc.nInsideMinusOneHits();
m_nTailMinusOneHits_before_bkwsearch = tc.nTailMinusOneHits();
tc.setLastCcIndex(0);
tc.setNInsideMinusOneHits(0);
tc.setNTailMinusOneHits(0);
}

void CombCandidate::EndBkwSearch()
{
// MergeCandsAndBestShortOne() has already been called (from MkBuilder::FindXxx()).
// We have to fixup the best candidate.

TrackCand &tc = (*this)[0];

int curr_idx = tc.lastCcIndex();
if (curr_idx != 0)
{
int last_idx = -1, prev_idx;
do {
prev_idx = m_hots[curr_idx].m_prev_idx;

m_hots[curr_idx].m_prev_idx = last_idx;

last_idx = curr_idx;
curr_idx = prev_idx;
} while (prev_idx != -1);
}

tc.setLastCcIndex(m_lastHitIdx_before_bkwsearch);
tc.setNInsideMinusOneHits(m_nInsideMinusOneHits_before_bkwsearch + tc.nInsideMinusOneHits());
tc.setNTailMinusOneHits(m_nTailMinusOneHits_before_bkwsearch + tc.nTailMinusOneHits());
m_lastHitIdx_before_bkwsearch = -1;
m_nInsideMinusOneHits_before_bkwsearch = -1;
m_nTailMinusOneHits_before_bkwsearch = -1;
}

} // end namespace mkfit
34 changes: 26 additions & 8 deletions mkFit/HitStructures.h
Original file line number Diff line number Diff line change
@@ -477,7 +477,7 @@ inline float getScoreCand(const TrackCand& cand1, bool penalizeTailMissHits=fals
int nfoundhits = cand1.nFoundHits();
int noverlaphits = cand1.nOverlapHits();
int nmisshits = cand1.nInsideMinusOneHits();
float ntailmisshits = penalizeTailMissHits ? cand1.nTailMinusOneHits() : 0;
int ntailmisshits = penalizeTailMissHits ? cand1.nTailMinusOneHits() : 0;
float pt = cand1.pT();
float chi2 = cand1.chi2();
// Do not allow for chi2<0 in score calculation
@@ -494,8 +494,12 @@ class CombCandidate : public std::vector<TrackCand>
enum SeedState_e { Dormant = 0, Finding, Finished };

TrackCand m_best_short_cand;
SeedState_e m_state = Dormant;
int m_last_seed_layer = -1;
SeedState_e m_state : 8;
int m_pickup_layer : 16;
short int m_lastHitIdx_before_bkwsearch = -1;
short int m_nInsideMinusOneHits_before_bkwsearch = -1;
short int m_nTailMinusOneHits_before_bkwsearch = -1;

#ifdef DUMPHITWINDOW
int m_seed_algo = 0;
int m_seed_label = 0;
@@ -506,16 +510,19 @@ class CombCandidate : public std::vector<TrackCand>
std::vector<HitMatchPair> m_overlap_hits; // XXXX HitMatchPair could be a member in TrackCand


CombCandidate()
{
}
CombCandidate() :
m_state(Dormant), m_pickup_layer(-1)
{}

// Need this so resize of EventOfCombinedCandidates::m_candidates can reuse vectors used here.
CombCandidate(CombCandidate&& o) :
std::vector<TrackCand>(std::move(o)),
m_best_short_cand(std::move(o.m_best_short_cand)),
m_state(o.m_state),
m_last_seed_layer(o.m_last_seed_layer),
m_pickup_layer(o.m_pickup_layer),
m_lastHitIdx_before_bkwsearch(o.m_lastHitIdx_before_bkwsearch),
m_nInsideMinusOneHits_before_bkwsearch(o.m_nInsideMinusOneHits_before_bkwsearch),
m_nTailMinusOneHits_before_bkwsearch(o.m_nTailMinusOneHits_before_bkwsearch),
#ifdef DUMPHITWINDOW
m_seed_algo(o.m_seed_algo),
m_seed_label(o.m_seed_label),
@@ -540,7 +547,10 @@ class CombCandidate : public std::vector<TrackCand>
std::vector<TrackCand>::operator=( std::move(o) );
m_best_short_cand = std::move(o.m_best_short_cand);
m_state = o.m_state;
m_last_seed_layer = o.m_last_seed_layer;
m_pickup_layer = o.m_pickup_layer;
m_lastHitIdx_before_bkwsearch = o.m_lastHitIdx_before_bkwsearch;
m_nInsideMinusOneHits_before_bkwsearch = o.m_nInsideMinusOneHits_before_bkwsearch;
m_nTailMinusOneHits_before_bkwsearch = o.m_nTailMinusOneHits_before_bkwsearch;
#ifdef DUMPHITWINDOW
m_seed_algo = o.m_seed_algo;
m_seed_label = o.m_seed_label;
@@ -561,6 +571,8 @@ class CombCandidate : public std::vector<TrackCand>

m_best_short_cand.setScore( getScoreWorstPossible() );

// state and pickup_layer set in ImportSeed.

// expected_num_hots is different for CloneEngine and Std, especially as long as we
// instantiate all candidates before purging them.
// ce: N_layer * N_cands ~~ 20 * 6 = 120
@@ -591,6 +603,9 @@ class CombCandidate : public std::vector<TrackCand>
}

void MergeCandsAndBestShortOne(const IterationParams&params, bool update_score, bool sort_cands);

void BeginBkwSearch();
void EndBkwSearch();
};

//==============================================================================
@@ -689,6 +704,9 @@ class EventOfCombCandidates

++m_size;
}

void BeginBkwSearch() { for (int i=0; i<m_size; ++i) m_candidates[i].BeginBkwSearch(); }
void EndBkwSearch() { for (int i=0; i<m_size; ++i) m_candidates[i].EndBkwSearch(); }
};

} // end namespace mkfit
2 changes: 2 additions & 0 deletions mkFit/IterationConfig.cc
Original file line number Diff line number Diff line change
@@ -67,9 +67,11 @@ ITCONF_DEFINE_TYPE_NON_INTRUSIVE(mkfit::IterationConfig,
// /* int */ m_iteration_index,
/* int */ m_track_algorithm,
/* mkfit::IterationParams */ m_params,
/* mkfit::IterationParams */ m_backward_params,
/* bool */ m_requires_seed_hit_sorting,
/* bool */ m_require_quality_filter,
/* bool */ m_require_dupclean_tight,
/* bool */ m_backward_search,
// /* int */ m_n_regions,
// /* vector<int> */ m_region_order,
// /* vector<mkfit::SteeringParams> */ m_steering_params,
4 changes: 4 additions & 0 deletions mkFit/IterationConfig.h
Original file line number Diff line number Diff line change
@@ -155,8 +155,11 @@ class IterationConfig
bool m_require_quality_filter = false;
bool m_require_dupclean_tight = false;

bool m_backward_search = false;

// Iteration parameters (could be a ptr)
IterationParams m_params;
IterationParams m_backward_params;

int m_n_regions;
std::vector<int> m_region_order;
@@ -239,6 +242,7 @@ class IterationConfig
m_n_regions = nreg;
m_region_order.resize(nreg);
m_steering_params.resize(nreg);
for (int i = 0; i < nreg; ++i) m_steering_params[i].m_region = i;
m_layer_configs.resize(nlay);
}

Loading

0 comments on commit 53b4d5f

Please sign in to comment.