Skip to content

Commit

Permalink
Change bin index precision, more flexile custom binning
Browse files Browse the repository at this point in the history
* Bin index was unsingend short limiting number of bins
* Binning vector can now be
  - empty: use default uniform binning
  - single number: use number as number of bins for uniform binning
  - exact bin limits
  • Loading branch information
wiechula committed Feb 5, 2024
1 parent 37710db commit 3640c95
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ class TrackResiduals
/// \param ip Bin index in Y/X
/// \param iz Bin index in Z/X
/// \return global bin number
unsigned short getGlbVoxBin(int ix, int ip, int iz) const;
size_t getGlbVoxBin(int ix, int ip, int iz) const;

/// Calculates the global bin number
/// \param bvox Array with the voxels bin indices in X, Y/X and Z/X
/// \return global bin number
unsigned short getGlbVoxBin(const std::array<unsigned char, VoxDim>& bvox) const;
size_t getGlbVoxBin(const std::array<unsigned char, VoxDim>& bvox) const;

/// Calculates the coordinates of the center for a given voxel.
/// These are not global TPC coordinates, but the coordinates for the given global binning system.
Expand Down Expand Up @@ -498,7 +498,7 @@ class TrackResiduals
float mEffVdriftCorr{0.f}; ///< global correction factor for vDrift based on d(delta(z))/dz fit
float mEffT0Corr{0.f}; ///< global correction for T0 shift from offset of d(delta(z))/dz fit
// (intermediate) results
std::array<std::bitset<param::NPadRows>, SECTORSPERSIDE * SIDES> mXBinsIgnore{}; ///< flags which X bins to ignore
std::array<std::bitset<param::NPadRows>, SECTORSPERSIDE * SIDES> mXBinsIgnore{}; ///<! flags which X bins to ignore
std::array<std::array<float, param::NPadRows>, SECTORSPERSIDE * SIDES> mValidFracXBins{}; ///< for each sector for each X-bin the fraction of validated voxels
std::array<std::vector<VoxRes>, SECTORSPERSIDE * SIDES> mVoxelResults{}; ///< results per sector and per voxel for 3-D distortions
VoxRes mVoxelResultsOut{}; ///< the results from mVoxelResults are copied in here to be able to stream them
Expand All @@ -508,13 +508,13 @@ class TrackResiduals
};

//_____________________________________________________
inline unsigned short TrackResiduals::getGlbVoxBin(const std::array<unsigned char, VoxDim>& bvox) const
inline size_t TrackResiduals::getGlbVoxBin(const std::array<unsigned char, VoxDim>& bvox) const
{
return bvox[VoxX] + (bvox[VoxF] + bvox[VoxZ] * mNY2XBins) * mNXBins;
}

//_____________________________________________________
inline unsigned short TrackResiduals::getGlbVoxBin(int ix, int ip, int iz) const
inline size_t TrackResiduals::getGlbVoxBin(int ix, int ip, int iz) const
{
return ix + (ip + iz * mNY2XBins) * mNXBins;
}
Expand Down
36 changes: 32 additions & 4 deletions Detectors/TPC/calibration/SpacePoints/src/TrackResiduals.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,24 @@ void TrackResiduals::setY2XBinning(const std::vector<float>& binning)
LOG(error) << "Binning already initialized, not changing y/x binning";
return;
}
int nBins = binning.size() - 1;

if (binning.size() == 0) {
LOGP(info, "Empty binning provided, will use default uniform y/x binning with {} bins", mNY2XBins);
return;
} else if (binning.size() == 1) {
const int bins = static_cast<int>(binning.at(0));
setNY2XBins(bins);
LOGP(info, "Setting uniform binning for y/x with {} bins", bins - 1);
return;
}

const int nBins = binning.size() - 1;
if (fabsf(binning[0] + 1.f) > param::sEps || fabsf(binning[nBins] - 1.f) > param::sEps) {
LOG(error) << "Provided binning for y/x not in range -1 to 1: " << binning[0] << " - " << binning[nBins] << ". Not changing y/x binning";
return;
}

LOGP(info, "Setting custom binning for y/x with {} bins", nBins);
setNY2XBins(nBins);
mUniformBins[VoxF] = false;
mY2XBinsDH.clear();
Expand All @@ -84,6 +97,7 @@ void TrackResiduals::setY2XBinning(const std::vector<float>& binning)
mY2XBinsDH.push_back(.5f * (binning[iBin + 1] - binning[iBin]));
mY2XBinsDI.push_back(.5f / mY2XBinsDH[iBin]);
mY2XBinsCenter.push_back(binning[iBin] + mY2XBinsDH[iBin]);
LOGF(info, "Bin %i: center (%.3f), half bin width (%.3f)", iBin, mY2XBinsCenter.back(), mY2XBinsDH.back());
}
}

Expand All @@ -94,11 +108,24 @@ void TrackResiduals::setZ2XBinning(const std::vector<float>& binning)
LOG(error) << "Binning already initialized, not changing z/x binning";
return;
}

if (binning.size() == 0) {
LOGP(info, "Empty binning provided, will use default uniform z/x binning with {} bins", mNZ2XBins);
return;
} else if (binning.size() == 1) {
const int bins = static_cast<int>(binning.at(0));
setNZ2XBins(bins);
LOGP(info, "Setting uniform binning for z/x with {} bins", bins);
return;
}

int nBins = binning.size() - 1;
if (fabsf(binning[0]) > param::sEps || fabsf(binning[nBins] - 1.f) > param::sEps) {
LOG(error) << "Provided binning for z/x not in range 0 to 1: " << binning[0] << " - " << binning[nBins] << ". Not changing z/x binning";
return;
}

LOGP(info, "Setting custom binning for z/x with {} bins", nBins);
setNZ2XBins(nBins);
mUniformBins[VoxZ] = false;
mZ2XBinsDH.clear();
Expand All @@ -108,6 +135,7 @@ void TrackResiduals::setZ2XBinning(const std::vector<float>& binning)
mZ2XBinsDH.push_back(.5f * (binning[iBin + 1] - binning[iBin]) * mMaxZ2X);
mZ2XBinsDI.push_back(.5f / mZ2XBinsDH[iBin]);
mZ2XBinsCenter.push_back(binning[iBin] * mMaxZ2X + mZ2XBinsDH[iBin]);
LOGF(info, "Bin %i: center (%.3f), half bin width (%.3f)", iBin, mZ2XBinsCenter.back(), mZ2XBinsDH.back());
}
}

Expand Down Expand Up @@ -181,7 +209,7 @@ void TrackResiduals::initResultsContainer(int iSec)
for (int ix = 0; ix < mNXBins; ++ix) {
for (int ip = 0; ip < mNY2XBins; ++ip) {
for (int iz = 0; iz < mNZ2XBins; ++iz) {
int binGlb = getGlbVoxBin(ix, ip, iz);
const size_t binGlb = getGlbVoxBin(ix, ip, iz);
VoxRes& resVox = mVoxelResults[iSec][binGlb];
resVox.bvox[VoxX] = ix;
resVox.bvox[VoxF] = ip;
Expand Down Expand Up @@ -338,7 +366,7 @@ void TrackResiduals::processSectorResiduals(int iSec)
initResultsContainer(iSec);
// effective t0 correction changes sign between A-/C-side
float effT0corr = (iSec < SECTORSPERSIDE) ? mEffT0Corr : -1. * mEffT0Corr;
std::vector<unsigned short> binData;
std::vector<size_t> binData;
for (const auto& res : mLocalResidualsIn) {
binData.push_back(getGlbVoxBin(res.bvox));
}
Expand All @@ -356,7 +384,7 @@ void TrackResiduals::processSectorResiduals(int iSec)
dyVec.reserve(1e3);
dzVec.reserve(1e3);
tgVec.reserve(1e3);
int currVoxBin = -1;
size_t currVoxBin = -1;
unsigned int nPointsInVox = 0;
unsigned int nProcessed = 0;
while (nProcessed < binData.size()) {
Expand Down

0 comments on commit 3640c95

Please sign in to comment.