Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MkFit] Per iteration / eta region track candidate scoring function #40490

Merged
merged 3 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions RecoTracker/MkFitCMS/src/MkStdSeqs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -733,5 +733,39 @@ namespace mkfit {
} rqf_instance;
} // namespace

//=========================================================================
// Track scoring
//=========================================================================

float trackScoreDefault(const int nfoundhits,
const int ntailholes,
const int noverlaphits,
const int nmisshits,
const float chi2,
const float pt,
const bool inFindCandidates) {
float maxBonus = 8.0;
float bonus = Config::validHitSlope_ * nfoundhits + Config::validHitBonus_;
float penalty = Config::missingHitPenalty_;
float tailPenalty = Config::tailMissingHitPenalty_;
float overlapBonus = Config::overlapHitBonus_;
if (pt < 0.9) {
penalty *= inFindCandidates ? 1.7f : 1.5f;
bonus = std::min(bonus * (inFindCandidates ? 0.9f : 1.0f), maxBonus);
}
float score =
bonus * nfoundhits + overlapBonus * noverlaphits - penalty * nmisshits - tailPenalty * ntailholes - chi2;
return score;
}

namespace {
CMS_SA_ALLOW struct register_track_scorers {
register_track_scorers() {
IterationConfig::register_track_scorer("default", trackScoreDefault);
IterationConfig::register_track_scorer("phase1:default", trackScoreDefault);
}
} rts_instance;
} // namespace

} // namespace StdSeq
} // namespace mkfit
4 changes: 3 additions & 1 deletion RecoTracker/MkFitCMS/standalone/MkStandaloneSeqs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "RecoTracker/MkFitCore/interface/HitStructures.h"
#include "RecoTracker/MkFitCore/standalone/Event.h"
#include "RecoTracker/MkFitCore/interface/IterationConfig.h"

#include "RecoTracker/MkFitCore/src/Debug.h"

Expand Down Expand Up @@ -396,8 +397,9 @@ namespace mkfit {
}

void score_tracks(TrackVec &tracks) {
auto score_func = IterationConfig::get_track_scorer("default");
for (auto &track : tracks) {
track.setScore(getScoreCand(track));
track.setScore(getScoreCand(score_func, track));
}
}

Expand Down
44 changes: 44 additions & 0 deletions RecoTracker/MkFitCore/interface/FunctionTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef RecoTracker_MkFitCore_interface_FunctionTypes_h
#define RecoTracker_MkFitCore_interface_FunctionTypes_h

#include <functional>

namespace mkfit {

struct BeamSpot;
class EventOfHits;
class TrackerInfo;
class Track;
class TrackCand;
class MkJob;
class IterationConfig;
class IterationSeedPartition;

typedef std::vector<Track> TrackVec;

// ----------------------------------------------------------

using clean_seeds_cf = int(TrackVec &, const IterationConfig &, const BeamSpot &);
using clean_seeds_func = std::function<clean_seeds_cf>;

using partition_seeds_cf = void(const TrackerInfo &, const TrackVec &, const EventOfHits &, IterationSeedPartition &);
using partition_seeds_func = std::function<partition_seeds_cf>;

using filter_candidates_cf = bool(const TrackCand &, const MkJob &);
using filter_candidates_func = std::function<filter_candidates_cf>;

using clean_duplicates_cf = void(TrackVec &, const IterationConfig &);
using clean_duplicates_func = std::function<clean_duplicates_cf>;

using track_score_cf = float(const int nfoundhits,
const int ntailholes,
const int noverlaphits,
const int nmisshits,
const float chi2,
const float pt,
const bool inFindCandidates);
using track_score_func = std::function<track_score_cf>;

} // end namespace mkfit

#endif
38 changes: 12 additions & 26 deletions RecoTracker/MkFitCore/interface/IterationConfig.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef RecoTracker_MkFitCore_interface_IterationConfig_h
#define RecoTracker_MkFitCore_interface_IterationConfig_h

#include "RecoTracker/MkFitCore/interface/FunctionTypes.h"
#include "RecoTracker/MkFitCore/interface/SteeringParams.h"

#include "nlohmann/json_fwd.hpp"
Expand All @@ -9,15 +10,6 @@

namespace mkfit {

struct BeamSpot;
class EventOfHits;
class TrackerInfo;
class Track;
class TrackCand;
class MkJob;

typedef std::vector<Track> TrackVec;

//==============================================================================
// Hit masks / IterationMaskIfc
//==============================================================================
Expand Down Expand Up @@ -129,22 +121,6 @@ namespace mkfit {

class IterationConfig {
public:
// Called directly.
using clean_seeds_cf = int(TrackVec &, const IterationConfig &, const BeamSpot &);
using clean_seeds_func = std::function<clean_seeds_cf>;
// Called from MkBuilder::find_tracks_load_seeds().
using partition_seeds_cf = void(const TrackerInfo &,
const TrackVec &,
const EventOfHits &,
IterationSeedPartition &);
using partition_seeds_func = std::function<partition_seeds_cf>;
// Passed to MkBuilder::filter_comb_cands().
using filter_candidates_cf = bool(const TrackCand &, const MkJob &);
using filter_candidates_func = std::function<filter_candidates_cf>;
// Called directly.
using clean_duplicates_cf = void(TrackVec &, const IterationConfig &);
using clean_duplicates_func = std::function<clean_duplicates_cf>;

int m_iteration_index = -1;
int m_track_algorithm = -1;

Expand Down Expand Up @@ -181,17 +157,24 @@ namespace mkfit {
std::vector<SteeringParams> m_steering_params;
std::vector<IterationLayerConfig> m_layer_configs;

// Standard functions
// *** Standard functions
// - seed cleaning: called directly from top-level per-iteration steering code.
clean_seeds_func m_seed_cleaner;
// - seed partitioning into eta regions: called from MkBuilder::find_tracks_load_seeds().
partition_seeds_func m_seed_partitioner;
// - candidate filtering: passed to MkBuilder::filter_comb_cands().
filter_candidates_func m_pre_bkfit_filter, m_post_bkfit_filter;
// - duplicate cleaning: called directly from top-level per-iteration steering code.
clean_duplicates_func m_duplicate_cleaner;
// - default track scoring function, can be overriden in SteeringParams for each eta region.
track_score_func m_default_track_scorer;

// Names for Standard functions that get saved to / loaded from JSON.
std::string m_seed_cleaner_name;
std::string m_seed_partitioner_name;
std::string m_pre_bkfit_filter_name, m_post_bkfit_filter_name;
std::string m_duplicate_cleaner_name;
std::string m_default_track_scorer_name = "default";

//----------------------------------------------------------------------------

Expand Down Expand Up @@ -225,6 +208,7 @@ namespace mkfit {
m_pre_bkfit_filter_name = o.m_pre_bkfit_filter_name;
m_post_bkfit_filter_name = o.m_post_bkfit_filter_name;
m_duplicate_cleaner_name = o.m_duplicate_cleaner_name;
m_default_track_scorer_name = o.m_default_track_scorer_name;
}

void set_iteration_index_and_track_algorithm(int idx, int trk_alg) {
Expand Down Expand Up @@ -275,11 +259,13 @@ namespace mkfit {
static void register_seed_partitioner(const std::string &name, partition_seeds_func func);
static void register_candidate_filter(const std::string &name, filter_candidates_func func);
static void register_duplicate_cleaner(const std::string &name, clean_duplicates_func func);
static void register_track_scorer(const std::string &name, track_score_func func);

static clean_seeds_func get_seed_cleaner(const std::string &name);
static partition_seeds_func get_seed_partitioner(const std::string &name);
static filter_candidates_func get_candidate_filter(const std::string &name);
static clean_duplicates_func get_duplicate_cleaner(const std::string &name);
static track_score_func get_track_scorer(const std::string &name);
};

//==============================================================================
Expand Down
6 changes: 1 addition & 5 deletions RecoTracker/MkFitCore/interface/MkBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ namespace mkfit {

class Event;

//==============================================================================
// MkJob
//==============================================================================

//==============================================================================
// MkBuilder
//==============================================================================
Expand Down Expand Up @@ -55,7 +51,7 @@ namespace mkfit {
void import_seeds(const TrackVec &in_seeds, const bool seeds_sorted, std::function<insert_seed_foo> insert_seed);

// filter for rearranging cands that will / will not do backward search.
int filter_comb_cands(IterationConfig::filter_candidates_func filter);
int filter_comb_cands(filter_candidates_func filter);

void find_min_max_hots_size();

Expand Down
6 changes: 5 additions & 1 deletion RecoTracker/MkFitCore/interface/SteeringParams.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef RecoTracker_MkFitCore_interface_SteeringParams_h
#define RecoTracker_MkFitCore_interface_SteeringParams_h

#include "RecoTracker/MkFitCore/interface/FunctionTypes.h"

#include <vector>
#include <stdexcept>

Expand Down Expand Up @@ -91,9 +93,11 @@ namespace mkfit {
else
return m_steering_params.m_layer_plan[m_end_index + 1].m_layer;
}
};
}; // class iterator

std::vector<LayerControl> m_layer_plan;
track_score_func m_track_scorer;
std::string m_track_scorer_name;

int m_region;

Expand Down
36 changes: 8 additions & 28 deletions RecoTracker/MkFitCore/interface/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "RecoTracker/MkFitCore/interface/Config.h"
#include "RecoTracker/MkFitCore/interface/MatrixSTypes.h"
#include "RecoTracker/MkFitCore/interface/FunctionTypes.h"
#include "RecoTracker/MkFitCore/interface/Hit.h"
#include "RecoTracker/MkFitCore/interface/TrackerInfo.h"

Expand Down Expand Up @@ -603,31 +604,10 @@ namespace mkfit {
return -1e16; // somewhat arbitrary value, used for handling of best short track during finding (will try to take it out)
}

inline float getScoreCalc(const int nfoundhits,
const int ntailholes,
const int noverlaphits,
const int nmisshits,
const float chi2,
const float pt,
const bool inFindCandidates = false) {
//// Do not allow for chi2<0 in score calculation
// if(chi2<0) chi2=0.f;

float maxBonus = 8.0;
float bonus = Config::validHitSlope_ * nfoundhits + Config::validHitBonus_;
float penalty = Config::missingHitPenalty_;
float tailPenalty = Config::tailMissingHitPenalty_;
float overlapBonus = Config::overlapHitBonus_;
if (pt < 0.9) {
penalty *= inFindCandidates ? 1.7f : 1.5f;
bonus = std::min(bonus * (inFindCandidates ? 0.9f : 1.0f), maxBonus);
}
float score_ =
bonus * nfoundhits + overlapBonus * noverlaphits - penalty * nmisshits - tailPenalty * ntailholes - chi2;
return score_;
}

inline float getScoreCand(const Track& cand1, bool penalizeTailMissHits = false, bool inFindCandidates = false) {
inline float getScoreCand(const track_score_func& score_func,
const Track& cand1,
bool penalizeTailMissHits = false,
bool inFindCandidates = false) {
int nfoundhits = cand1.nFoundHits();
int noverlaphits = cand1.nOverlapHits();
int nmisshits = cand1.nInsideMinusOneHits();
Expand All @@ -637,10 +617,10 @@ namespace mkfit {
// Do not allow for chi2<0 in score calculation
if (chi2 < 0)
chi2 = 0.f;
return getScoreCalc(nfoundhits, ntailmisshits, noverlaphits, nmisshits, chi2, pt, inFindCandidates);
return score_func(nfoundhits, ntailmisshits, noverlaphits, nmisshits, chi2, pt, inFindCandidates);
}

inline float getScoreStruct(const IdxChi2List& cand1) {
inline float getScoreStruct(const track_score_func& score_func, const IdxChi2List& cand1) {
int nfoundhits = cand1.nhits;
int ntailholes = cand1.ntailholes;
int noverlaphits = cand1.noverlaps;
Expand All @@ -650,7 +630,7 @@ namespace mkfit {
// Do not allow for chi2<0 in score calculation
if (chi2 < 0)
chi2 = 0.f;
return getScoreCalc(nfoundhits, ntailholes, noverlaphits, nmisshits, chi2, pt, true /*inFindCandidates*/);
return score_func(nfoundhits, ntailholes, noverlaphits, nmisshits, chi2, pt, true /*inFindCandidates*/);
}

template <typename Vector>
Expand Down
18 changes: 12 additions & 6 deletions RecoTracker/MkFitCore/interface/TrackStructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ namespace mkfit {
return cand1.score() > cand2.score();
}

inline float getScoreCand(const TrackCand& cand1, bool penalizeTailMissHits = false, bool inFindCandidates = false) {
inline float getScoreCand(const track_score_func& score_func,
const TrackCand& cand1,
bool penalizeTailMissHits = false,
bool inFindCandidates = false) {
int nfoundhits = cand1.nFoundHits();
int noverlaphits = cand1.nOverlapHits();
int nmisshits = cand1.nInsideMinusOneHits();
Expand All @@ -265,7 +268,7 @@ namespace mkfit {
// Do not allow for chi2<0 in score calculation
if (chi2 < 0)
chi2 = 0.f;
return getScoreCalc(nfoundhits, ntailmisshits, noverlaphits, nmisshits, chi2, pt, inFindCandidates);
return score_func(nfoundhits, ntailmisshits, noverlaphits, nmisshits, chi2, pt, inFindCandidates);
}

// CombCandidate -- a set of candidates from a given seed.
Expand Down Expand Up @@ -371,14 +374,17 @@ namespace mkfit {
m_hots.clear();
}

void importSeed(const Track& seed, int region);
void importSeed(const Track& seed, const track_score_func& score_func, int region);

int addHit(const HitOnTrack& hot, float chi2, int prev_idx) {
m_hots.push_back({hot, chi2, prev_idx});
return m_hots_size++;
}

void mergeCandsAndBestShortOne(const IterationParams& params, bool update_score, bool sort_cands);
void mergeCandsAndBestShortOne(const IterationParams& params,
const track_score_func& score_func,
bool update_score,
bool sort_cands);

void compactifyHitStorageForBestCand(bool remove_seed_hits, int backward_fit_min_hits);
void beginBkwSearch();
Expand Down Expand Up @@ -612,10 +618,10 @@ namespace mkfit {
m_n_seeds_inserted -= n_removed;
}

void insertSeed(const Track& seed, int region, int pos) {
void insertSeed(const Track& seed, const track_score_func& score_func, int region, int pos) {
assert(pos < m_size);

m_candidates[pos].importSeed(seed, region);
m_candidates[pos].importSeed(seed, score_func, region);

++m_n_seeds_inserted;
}
Expand Down
Loading