File indexing completed on 2024-04-06 12:05:22
0001 #include <cmath>
0002 #include <limits>
0003 #include "DataFormats/TrackReco/interface/TrackResiduals.h"
0004
0005 namespace reco {
0006
0007 namespace {
0008
0009 inline TrackResiduals::StorageType pack(float x, float min, float fact) {
0010 constexpr float amax = std::numeric_limits<TrackResiduals::StorageType>::max();
0011 return std::min(std::round(fact * (x - min)), amax);
0012 }
0013
0014 inline float unpack(TrackResiduals::StorageType x, float min, float fact) { return fact * x + min; }
0015
0016 constexpr float pmin = -32;
0017 constexpr float pmult = 1000;
0018 constexpr float pdiv = 1. / pmult;
0019 constexpr float rmin = -3.2;
0020 constexpr float rmult = 10000;
0021 constexpr float rdiv = 1. / rmult;
0022
0023 }
0024
0025 float TrackResiduals::unpack_pull(StorageType x) { return unpack(x, pmin, pdiv); }
0026 TrackResiduals::StorageType TrackResiduals::pack_pull(float x) { return pack(x, pmin, pmult); }
0027 float TrackResiduals::unpack_residual(StorageType x) { return unpack(x, rmin, rdiv); }
0028 TrackResiduals::StorageType TrackResiduals::pack_residual(float x) { return pack(x, rmin, rmult); }
0029
0030 void TrackResiduals::setResidualXY(int idx, float residualX, float residualY) {
0031 m_storage[4 * idx] = pack_residual(residualX);
0032 m_storage[4 * idx + 1] = pack_residual(residualY);
0033 }
0034 void TrackResiduals::setPullXY(int idx, float pullX, float pullY) {
0035 m_storage[4 * idx + 2] = pack_pull(pullX);
0036 m_storage[4 * idx + 3] = pack_pull(pullY);
0037 }
0038
0039 }