Skip to content

Commit ec14c9e

Browse files
committed
Feat: add lite tables for all particles
1 parent f6b93e9 commit ec14c9e

2 files changed

Lines changed: 281 additions & 24 deletions

File tree

PWGCF/Femto/Core/femtoUtils.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include <TPDGCode.h>
2626

27+
#include <sys/types.h>
28+
2729
#include <algorithm>
2830
#include <cmath>
2931
#include <concepts>
@@ -279,6 +281,43 @@ inline float unBinLogSigned(T binned, float magMin, float magMax)
279281
return sign * mag;
280282
}
281283

284+
template <typename T>
285+
inline int unBinSign(T binned)
286+
{
287+
static_assert(std::is_unsigned_v<T>, "unBinSign requires an unsigned storage type");
288+
constexpr uint64_t TotalBits = sizeof(T) * 8;
289+
constexpr T SignMask = static_cast<T>(uint64_t{1} << (TotalBits - 1));
290+
return (binned & SignMask) ? -1 : 1;
291+
}
292+
293+
template <typename T>
294+
inline T binLogUnsigned(float value, float magMin, float magMax)
295+
{
296+
static_assert(std::is_unsigned_v<T>, "binLogUnsigned requires an unsigned storage type");
297+
constexpr uint64_t TotalBits = sizeof(T) * 8;
298+
constexpr uint64_t Levels = uint64_t{1} << TotalBits; // number of representable values, e.g. 65536 for uint16_t
299+
float mag = std::clamp(value, magMin, magMax);
300+
float logLo = std::log(magMin);
301+
float logHi = std::log(magMax);
302+
float step = (logHi - logLo) / static_cast<float>(Levels - 1);
303+
auto idx = static_cast<uint64_t>(std::round((std::log(mag) - logLo) / step));
304+
idx = std::clamp(idx, uint64_t{0}, Levels - 1);
305+
return static_cast<T>(idx);
306+
}
307+
308+
template <typename T>
309+
inline float unBinLogUnsigned(T binned, float magMin, float magMax)
310+
{
311+
constexpr uint64_t TotalBits = sizeof(T) * 8;
312+
constexpr uint64_t Levels = uint64_t{1} << TotalBits;
313+
uint64_t idx = binned;
314+
float logLo = std::log(magMin);
315+
float logHi = std::log(magMax);
316+
float step = (logHi - logLo) / static_cast<float>(Levels - 1);
317+
float mag = std::exp(logLo + static_cast<float>(idx) * step);
318+
return mag;
319+
}
320+
282321
}; // namespace utils
283322
}; // namespace o2::analysis::femto
284323
//

0 commit comments

Comments
 (0)