Skip to content

Commit 956e12f

Browse files
SuJeong-Jialibuild
andauthored
[PWGLF] Small changes for microtrack in LFResonanceTable.h (#13178)
Co-authored-by: ALICE Action Bot <alibuild@cern.ch>
1 parent f6acde1 commit 956e12f

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

PWGLF/DataModel/LFResonanceTables.h

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -351,16 +351,26 @@ struct PidNSigma {
351351
/// @brief Encode 0.2 sigma interval to 0~10 range
352352
static uint8_t encodeNSigma(float nSigma)
353353
{
354-
float encoded = std::abs((nSigma - 1.5) / 0.2); // Convert to 0~10 range
355-
encoded = std::min(std::max(encoded, 0.f), 10.f); // Clamp to 0~10 range
356-
return (uint8_t)round(encoded);
354+
const float x = std::abs(nSigma);
355+
if (x <= 1.5)
356+
return 0; // Return 0 when absolute nSigma is smaller than 1.5
357+
float t = (x - 1.5) / 0.2;
358+
int encoded = static_cast<int>(std::ceil(t)); // (1.5,1.7]->1, ..., (3.3,3.5]->10
359+
if (encoded < 1)
360+
encoded = 1;
361+
if (encoded > 10)
362+
encoded = 10;
363+
return static_cast<uint8_t>(encoded);
357364
}
358365

359366
/// @brief Decode 0~10 value to original 1.5~3.5 sigma range
360367
static float decodeNSigma(uint8_t encoded)
361368
{
362-
encoded = std::min(encoded, (uint8_t)10); // Safety check, should not be needed if encode is used properly
363-
return (encoded * 0.2) + 1.5;
369+
if (encoded == 0)
370+
return 1.5;
371+
if (encoded > 10)
372+
encoded = 10;
373+
return 1.5 + static_cast<float>(encoded) * 0.2;
364374
}
365375

366376
/// @brief Check if TOF info is available
@@ -416,14 +426,18 @@ struct ResoMicroTrackSelFlag {
416426
flag = (DCAxyEncoded << 4) | DCAzEncoded; // Upper 4 bits = DCAxy, Lower 4 bits = DCAz
417427
}
418428

419-
/// @brief Convert DCA to 1~15 steps (0 value is not used)
429+
/// @brief Convert DCA to 1~15 steps (|DCA|<0.1 is saved in 0)
420430
static uint8_t encodeDCA(float DCA)
421431
{
422-
for (uint8_t i = 1; i < 15; i++) {
423-
if (DCA < i * 0.1f)
424-
return i;
425-
}
426-
return 15;
432+
float x = std::fabs(DCA);
433+
if (x < 0.1)
434+
return 0;
435+
int encoded = static_cast<int>(std::ceil((x - 0.1) / 0.1)); // (0.1, 0.2] -> 1, ..., (1.4, 1.5] -> 14
436+
if (encoded < 1)
437+
encoded = 1;
438+
if (encoded > 14)
439+
encoded = 15;
440+
return static_cast<uint8_t>(encoded);
427441
}
428442

429443
/// @brief Operator to convert to `uint8_t` (for SOA storage)

0 commit comments

Comments
 (0)