Skip to content

Commit

Permalink
[MkFit] Recheck overlap hit chi2 after update with primary hit on a g…
Browse files Browse the repository at this point in the history
…iven layer.
  • Loading branch information
osschar committed Feb 23, 2023
1 parent 209ebcd commit 5cfa541
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 10 deletions.
12 changes: 7 additions & 5 deletions RecoTracker/MkFitCore/src/CandCloner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ namespace mkfit {

void 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) {
mp_event_of_comb_candidates = e_o_ccs;
mp_kalman_update_list = update_list;
mp_kalman_overlap_list = overlap_list;
mp_extra_cands = extra_cands;
m_start_seed = start_seed;
m_n_seeds = n_seeds;
Expand All @@ -50,6 +52,7 @@ namespace mkfit {
m_idx_max_prev = 0;

mp_kalman_update_list->clear();
mp_kalman_overlap_list->clear();

#ifdef CC_TIME_LAYER
t_lay = dtime();
Expand Down Expand Up @@ -193,14 +196,13 @@ namespace mkfit {
break;

if (h2a.hitIdx >= 0) {
mp_kalman_update_list->emplace_back(UpdateIndices(m_start_seed + is, n_pushed, h2a.hitIdx));

// set the overlap if we have it and and pT > pTCutOverlap
// set the overlap if we have it and pT > pTCutOverlap
HitMatch *hm;
if (tc.pT() > mp_iteration_params->pTCutOverlap &&
(hm = ccand[h2a.trkIdx].findOverlap(h2a.hitIdx, h2a.module))) {
tc.addHitIdx(hm->m_hit_idx, m_layer, 0);
tc.incOverlapCount();
mp_kalman_overlap_list->emplace_back(UpdateIndices(m_start_seed + is, n_pushed, h2a.hitIdx, hm->m_hit_idx));
} else {
mp_kalman_update_list->emplace_back(UpdateIndices(m_start_seed + is, n_pushed, h2a.hitIdx, -1));
}
}

Expand Down
3 changes: 2 additions & 1 deletion RecoTracker/MkFitCore/src/CandCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace mkfit {

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);
Expand Down Expand Up @@ -56,7 +57,7 @@ namespace mkfit {

const IterationParams *mp_iteration_params = nullptr;
EventOfCombCandidates *mp_event_of_comb_candidates;
std::vector<UpdateIndices> *mp_kalman_update_list;
std::vector<UpdateIndices> *mp_kalman_update_list, *mp_kalman_overlap_list;
std::vector<std::vector<TrackCand>> *mp_extra_cands;

#if defined(CC_TIME_ETA) or defined(CC_TIME_LAYER)
Expand Down
4 changes: 4 additions & 0 deletions RecoTracker/MkFitCore/src/FindingFoos.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace mkfit {
const MPlexLS &, const MPlexLV &, MPlexQI &, const MPlexHS &, const MPlexHV &, MPlexLS &, MPlexLV &, MPlexQI &, \
const int, const PropagationFlags, const bool

#define COMPUTE_CHI2_AND_UPDATE_ARGS \
const MPlexLS &, const MPlexLV &, MPlexQI &, const MPlexHS &, const MPlexHV &, MPlexQF &, MPlexLS &, MPlexLV &, \
MPlexQI &, const int, const PropagationFlags, const bool

class FindingFoos {
public:
void (*m_compute_chi2_foo)(COMPUTE_CHI2_ARGS);
Expand Down
56 changes: 54 additions & 2 deletions RecoTracker/MkFitCore/src/MkBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -970,15 +970,16 @@ namespace mkfit {
const int n_seeds = end_seed - start_seed;

std::vector<std::pair<int, int>> seed_cand_idx;
std::vector<UpdateIndices> seed_cand_update_idx;
std::vector<UpdateIndices> seed_cand_update_idx, seed_cand_overlap_idx;
seed_cand_idx.reserve(n_seeds * params.maxCandsPerSeed);
seed_cand_update_idx.reserve(n_seeds * params.maxCandsPerSeed);
seed_cand_overlap_idx.reserve(n_seeds * params.maxCandsPerSeed);

std::vector<std::vector<TrackCand>> extra_cands(n_seeds);
for (int ii = 0; ii < n_seeds; ++ii)
extra_cands[ii].reserve(params.maxCandsPerSeed);

cloner.begin_eta_bin(&eoccs, &seed_cand_update_idx, &extra_cands, start_seed, n_seeds);
cloner.begin_eta_bin(&eoccs, &seed_cand_update_idx, &seed_cand_overlap_idx, &extra_cands, start_seed, n_seeds);

// Loop over layers, starting from after the seed.

Expand Down Expand Up @@ -1101,6 +1102,8 @@ namespace mkfit {

// Update loop of best candidates. CandCloner prepares the list of those
// that need update (excluding all those with negative last hit index).
// This is split into two sections - candidates without overlaps and with overlaps.
// On CMS PU-50 the ratio of those is ~ 65 : 35 over all iterations.

const int theEndUpdater = seed_cand_update_idx.size();

Expand All @@ -1115,6 +1118,55 @@ namespace mkfit {
mkfndr->copyOutParErr(eoccs.refCandidates_nc(), end - itrack, false);
}

const int theEndOverlapper = seed_cand_overlap_idx.size();

for (int itrack = 0; itrack < theEndOverlapper; itrack += NN) {
const int end = std::min(itrack + NN, theEndOverlapper);

mkfndr->inputTracksAndHits(eoccs.refCandidates(), layer_of_hits, seed_cand_overlap_idx, itrack, end, true);

mkfndr->updateWithLoadedHit(end - itrack, fnd_foos);

mkfndr->copyOutParErr(eoccs.refCandidates_nc(), end - itrack, false);

mkfndr->inputOverlapHits(layer_of_hits, seed_cand_overlap_idx, itrack, end);

// XXXX Could also be calcChi2AndUpdate(), then copy-out would have to be done
// below, choosing appropriate slot (with or without the overlap hit).
// Probably in a dedicated MkFinder copyOutXyzz function.
mkfndr->chi2OfLoadedHit(end - itrack, fnd_foos);

for (int ii = itrack; ii < end; ++ii) {
const int fi = ii - itrack;
TrackCand &tc = eoccs[seed_cand_overlap_idx[ii].seed_idx][seed_cand_overlap_idx[ii].cand_idx];

// XXXX For now we DO NOT use chi2 as this was how things were done before the post-update
// chi2 check. To use it we should retune scoring function (might be even simpler).
if (mkfndr->m_FailFlag[fi] == 0 && mkfndr->m_Chi2[fi] >= 0.0f && mkfndr->m_Chi2[fi] <= 60.0f) {
tc.addHitIdx(seed_cand_overlap_idx[ii].ovlp_idx, curr_layer, 0.0f);
tc.incOverlapCount();
}
}

/*
perl -ne 'if (/^RT_OVLP/) { s/^RT_OVLP //og; print; }' | grep -v nan > ovlp.rtt
TTree t;
t.ReadFile("ovlp.rtt", "algo/I:region:layer:fail:chi2_est/F:chi2_real:pt:theta:phi:phi_pos");
// momEta() sometimes makes nans ... hmmh.
*/
/*
for (int ii = itrack; ii < end; ++ii) {
const int fi = ii - itrack;
const TrackCand &trk = eoccs[seed_cand_overlap_idx[ii].seed_idx][seed_cand_overlap_idx[ii].cand_idx];
printf("RT_OVLP %d %d %d %d %f %f %f %f %f %f\n",
m_job->m_iter_config.m_track_algorithm, region, curr_layer,
mkfndr->m_FailFlag[fi],
seed_cand_overlap_idx[ii].chi2_overlap, mkfndr->m_Chi2[fi], trk.pT(), trk.theta(), trk.momPhi(),
trk.posPhi());
}
*/
}

// Check if cands are sorted, as expected.
#ifdef DEBUG
for (int iseed = start_seed; iseed < end_seed; ++iseed) {
Expand Down
33 changes: 33 additions & 0 deletions RecoTracker/MkFitCore/src/MkFinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ namespace mkfit {
}
}

void MkFinder::inputOverlapHits(const LayerOfHits &layer_of_hits,
const std::vector<UpdateIndices> &idxs,
int beg,
int end) {
// Copy overlap hit values in.

for (int i = beg, imp = 0; i < end; ++i, ++imp) {
const Hit &hit = layer_of_hits.refHit(idxs[i].ovlp_idx);
m_msErr.copyIn(imp, hit.errArray());
m_msPar.copyIn(imp, hit.posArray());
}
}

void MkFinder::inputTracksAndHitIdx(const std::vector<CombCandidate> &tracks,
const std::vector<std::pair<int, IdxChi2List>> &idxs,
int beg,
Expand Down Expand Up @@ -1375,6 +1388,26 @@ namespace mkfit {
// }
}

void MkFinder::chi2OfLoadedHit(int N_proc, const FindingFoos &fnd_foos) {
// We expect input in iC slots from above function.
// See comment in MkBuilder::find_tracks_in_layer() about intra / inter flags used here
// for propagation to the hit.
clearFailFlag();
(*fnd_foos.m_compute_chi2_foo)(m_Err[iC],
m_Par[iC],
m_Chg,
m_msErr,
m_msPar,
m_Chi2,
m_Par[iP],
m_FailFlag,
N_proc,
m_prop_config->finding_inter_layer_pflags,
m_prop_config->finding_requires_propagation_to_hit_pos);

// PROP-FAIL-ENABLE .... removed here
}

//==============================================================================
// CopyOutParErr
//==============================================================================
Expand Down
9 changes: 8 additions & 1 deletion RecoTracker/MkFitCore/src/MkFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ namespace mkfit {
int seed_idx;
int cand_idx;
int hit_idx;
int ovlp_idx;

UpdateIndices(int si, int ci, int hi) : seed_idx(si), cand_idx(ci), hit_idx(hi) {}
UpdateIndices(int si, int ci, int hi, int oi) : seed_idx(si), cand_idx(ci), hit_idx(hi), ovlp_idx(oi) {}
};

class MkFinder : public MkBase {
Expand Down Expand Up @@ -81,6 +82,10 @@ namespace mkfit {
int beg,
int end,
bool inputProp);
void inputOverlapHits(const LayerOfHits &layer_of_hits,
const std::vector<UpdateIndices> &idxs,
int beg,
int end);

void inputTracksAndHitIdx(const std::vector<CombCandidate> &tracks,
const std::vector<std::pair<int, IdxChi2List>> &idxs,
Expand Down Expand Up @@ -138,6 +143,8 @@ namespace mkfit {

void updateWithLoadedHit(int N_proc, const FindingFoos &fnd_foos);

void chi2OfLoadedHit(int N_proc, const FindingFoos &fnd_foos);

void copyOutParErr(std::vector<CombCandidate> &seed_cand_vec, int N_proc, bool outputProp) const;

//----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion RecoTracker/MkFitCore/src/PropagationMPlex.icc
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static inline void helixAtRFromIterativeCCS_impl(const Tf& __restrict__ inPar,
<< " r=" << std::setprecision(9) << r[n - nmin] << " r0=" << std::setprecision(9) << r0[n - nmin]
<< " id=" << std::setprecision(9) << id[n - nmin] << " dr=" << std::setprecision(9)
<< r[n - nmin] - r0[n - nmin] << " cosa=" << cosa[n - nmin] << " sina=" << sina[n - nmin]
<< " dir_cos(rad,pT)=" << 1.0f / oodotp[n]);
<< " 1/dir_cos(rad,pT)=" << oodotp[n - nmin]);
}

//update derivatives on total distance
Expand Down

0 comments on commit 5cfa541

Please sign in to comment.