Skip to content

Commit

Permalink
Merge pull request cms-sw#172 from cerati/phifix
Browse files Browse the repository at this point in the history
Handle input hit phi outside of (-pi,pi) during hit binning
  • Loading branch information
kmcdermo authored Oct 12, 2018
2 parents 825e264 + ff4b294 commit 2542985
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Hit.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ inline float squashPhiGeneral(float phi)
return phi - floor(0.5*Config::InvPI*(phi+Config::PI)) * Config::TwoPI;
}

inline float squashPhiMinimal(float phi)
{
return phi >= Config::PI ? phi - Config::TwoPI : (phi < -Config::PI ? phi + Config::TwoPI : phi);
}

// moved from config to here
inline int getEtaBin(float eta)
{
Expand Down
4 changes: 3 additions & 1 deletion mkFit/HitStructures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void LayerOfHits::SuckInHits(const HitVec &hitv)
for (auto const &h : hitv)
{
HitInfo &hi = ha[i];
// N.1.a For phi in [-pi, pi): squashPhiMinimal(h.phi()); Apparently atan2 can round the wrong way.
hi.phi = h.phi();
hi.q = is_brl ? h.z() : h.r();
hi.qbin = std::max(std::min(static_cast<int>((hi.q - m_qmin) * m_fq), m_nq - 1), 0);
Expand Down Expand Up @@ -157,7 +158,8 @@ void LayerOfHits::SuckInHits(const HitVec &hitv)
curr_phi_bin = 0;
}

int phi_bin = GetPhiBin(ha[j].phi);
// N.1.b ha[j].phi is returned by atan2 and can be rounded the wrong way, resulting in bin -1 or Config::m_nphi
int phi_bin = clamp(GetPhiBin(ha[j].phi), 0, Config::m_nphi - 1);

if (phi_bin > curr_phi_bin)
{
Expand Down
4 changes: 3 additions & 1 deletion mkFit/HitStructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@ class LayerOfHits

int GetQBinChecked(float q) const { int qb = GetQBin(q); if (qb < 0) qb = 0; else if (qb >= m_nq) qb = m_nq - 1; return qb; }

// if you don't pass phi in (-pi, +pi), mask away the upper bits using m_phi_mask
// If you don't pass phi in (-pi, +pi), mask away the upper bits using m_phi_mask or use the Checked version.
int GetPhiBin(float phi) const { return std::floor(m_fphi * (phi + Config::PI)); }

int GetPhiBinChecked(float phi) const { return GetPhiBin(phi) & m_phi_mask; }

const vecPhiBinInfo_t& GetVecPhiBinInfo(float q) const { return m_phi_bin_infos[GetQBin(q)]; }

void SuckInHits(const HitVec &hitv);
Expand Down

0 comments on commit 2542985

Please sign in to comment.