Skip to content

Commit

Permalink
ZDC - Update of the intermediate reconstructed format to avoid losing…
Browse files Browse the repository at this point in the history
… numerical precision (AliceO2Group#12712)

* Removing factor to convert float TDC amplitude into int16_t

* Removing accounting of amplitude encoding errors

* Fixes

* Please consider the following formatting changes (#88)

---------

Co-authored-by: ALICE Builder <[email protected]>
  • Loading branch information
cortesep and alibuild authored Mar 12, 2024
1 parent fcd565d commit 82429bb
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ struct RecEventFlat { // NOLINT: false positive in clang-tidy !!
{
if (ich < NTDCChannels) {
if (ipos < TDCAmp[ich].size()) {
return FTDCAmp * TDCAmp[ich][ipos];
return TDCAmp[ich][ipos];
}
}
return -std::numeric_limits<float>::infinity();
Expand Down
45 changes: 12 additions & 33 deletions DataFormats/Detectors/ZDC/include/DataFormatsZDC/ZDCTDCData.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace zdc
struct ZDCTDCDataErr {

static uint32_t mErrVal[NTDCChannels]; // Errors in encoding TDC values
static uint32_t mErrAmp[NTDCChannels]; // Errors in encoding TDC amplitudes
static uint32_t mErrId; // Errors with TDC Id

static void print()
Expand All @@ -43,22 +42,18 @@ struct ZDCTDCDataErr {
LOG(error) << "TDCVal itdc=" << itdc << " " << ChannelNames[TDCSignal[itdc]] << " was out of range #times = " << mErrVal[itdc];
}
}
for (int itdc = 0; itdc < NTDCChannels; itdc++) {
if (mErrAmp[itdc] > 0) {
LOG(warning) << "TDCAmp itdc=" << itdc << " " << ChannelNames[TDCSignal[itdc]] << " was out of range #times = " << mErrAmp[itdc];
}
}
}
};

struct ZDCTDCData {

uint8_t id = 0xff; // channel ID
int16_t val = 0; // tdc value
int16_t amp = 0; // tdc amplitude
float amp = 0; // tdc amplitude

ZDCTDCData() = default;
ZDCTDCData(uint8_t ida, int16_t vala, int16_t ampa, bool isbeg = false, bool isend = false)

ZDCTDCData(uint8_t ida, int16_t vala, float ampa, bool isbeg = false, bool isend = false)
{
// TDC value and amplitude are encoded externally
id = ida < NTDCChannels ? ida : 0xf;
Expand All @@ -70,7 +65,7 @@ struct ZDCTDCData {
amp = ampa;
} else {
val = kMaxShort;
amp = kMaxShort;
amp = FInfty;
#ifdef O2_ZDC_DEBUG
LOG(error) << __func__ << "TDC Id = " << int(ida) << " is out of range";
#endif
Expand All @@ -87,7 +82,7 @@ struct ZDCTDCData {

if (ida >= NTDCChannels) {
val = kMaxShort;
amp = kMaxShort;
amp = FInfty;
#ifdef O2_ZDC_DEBUG
LOG(error) << __func__ << "TDC Id = " << int(ida) << " is out of range";
#endif
Expand All @@ -96,7 +91,6 @@ struct ZDCTDCData {
}

auto TDCVal = std::nearbyint(vala);
auto TDCAmp = std::nearbyint(ampa);

if (TDCVal < kMinShort) {
int itdc = int(id);
Expand All @@ -116,54 +110,39 @@ struct ZDCTDCData {
TDCVal = kMaxShort;
}

if (TDCAmp < kMinShort) {
int itdc = int(ida);
#ifdef O2_ZDC_DEBUG
LOG(warning) << __func__ << "TDCAmp itdc=" << itdc << " " << ChannelNames[TDCSignal[itdc]] << " = " << TDCAmp << " is out of range";
#endif
ZDCTDCDataErr::mErrAmp[itdc]++;
TDCAmp = kMinShort;
}

if (TDCAmp > kMaxShort) {
int itdc = int(ida);
#ifdef O2_ZDC_DEBUG
LOG(warning) << __func__ << "TDCAmp itdc=" << itdc << " " << ChannelNames[TDCSignal[itdc]] << " = " << TDCAmp << " is out of range";
#endif
ZDCTDCDataErr::mErrAmp[itdc]++;
TDCAmp = kMaxShort;
}

val = TDCVal;
amp = TDCAmp;
amp = ampa;
}

inline float amplitude() const
{
// Return decoded value
return FTDCAmp * amp;
return amp;
}

inline float value() const
{
// Return decoded value (ns)
return FTDCVal * val;
}

inline int ch() const
{
return (id & 0x0f);
}

inline bool isBeg() const
{
return id & 0x80 ? true : false;
}

inline bool isEnd() const
{
return id & 0x40 ? true : false;
}

void print() const;

ClassDefNV(ZDCTDCData, 1);
ClassDefNV(ZDCTDCData, 2);
};
} // namespace zdc
} // namespace o2
Expand Down
2 changes: 2 additions & 0 deletions DataFormats/Detectors/ZDC/src/DataFormatsZDCLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@
#pragma link C++ struct o2::zdc::CTF + ;
#pragma link C++ class o2::ctf::EncodedBlocks < o2::zdc::CTFHeader, 12, uint32_t> + ;

#pragma read sourceClass = "ZDCTDCData" targetClass = "ZDCTDCData" source = "int16_t amp" version = "[-1]" target = "amp" targetType = "float" code = "{ amp=onfile.amp / 8.; }"

#endif
5 changes: 2 additions & 3 deletions DataFormats/Detectors/ZDC/src/RecEventFlat.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -765,12 +765,11 @@ void RecEventFlat::printEvent() const
int ich = o2::zdc::TDCSignal[itdc];
int nhit = NtdcV(itdc);
if (NtdcA(itdc) != nhit) {
fprintf(stderr, "Mismatch in TDC %d data Val=%d Amp=%d\n", itdc, NtdcV(itdc), NtdcA(ich));
fprintf(stderr, "Mismatch in TDC %d data length Val=%d Amp=%d values\n", itdc, NtdcV(itdc), NtdcA(ich));
continue;
}
for (int32_t ipos = 0; ipos < nhit; ipos++) {
printf("%9u.%04u T %2d %s = %g @ %g \n", mCurB.ir.orbit, mCurB.ir.bc, ich, ChannelNames[ich].data(),
FTDCAmp * TDCAmp[itdc][ipos], FTDCVal * TDCVal[itdc][ipos]);
printf("%9u.%04u T %2d %s = %g @ %g \n", mCurB.ir.orbit, mCurB.ir.bc, ich, ChannelNames[ich].data(), TDCAmp[itdc][ipos], FTDCVal * TDCVal[itdc][ipos]);
}
}
// Energy
Expand Down
3 changes: 1 addition & 2 deletions DataFormats/Detectors/ZDC/src/ZDCTDCData.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using namespace o2::zdc;

uint32_t ZDCTDCDataErr::mErrVal[NTDCChannels] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint32_t ZDCTDCDataErr::mErrAmp[NTDCChannels] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint32_t ZDCTDCDataErr::mErrId = 0;

void o2::zdc::ZDCTDCData::print() const
Expand All @@ -24,5 +23,5 @@ void o2::zdc::ZDCTDCData::print() const
if (id != 0xff && itdc >= 0 && itdc < NTDCChannels) {
isig = TDCSignal[itdc];
}
printf("%2d (%s) %d = %8.3f @ %d = %6.3f%s%s\n", isig, channelName(isig), amp, amplitude(), val, value(), isBeg() ? " B" : "", isEnd() ? " E" : "");
printf("%2d (%s) %8.3f @ %d = %6.3f%s%s\n", isig, channelName(isig), amp, val, value(), isBeg() ? " B" : "", isEnd() ? " E" : "");
}
1 change: 0 additions & 1 deletion Detectors/ZDC/base/include/ZDCBase/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ constexpr int TSL = 6; // number of zeros on the right (and o
constexpr int TSN = 200; // Number of interpolated points between each pair = TSN-1
constexpr int TSNH = TSN / 2; // Half of TSN
constexpr int NTS = 2 * TSL * TSN + 1; // Tapered sinc function array size
constexpr float FTDCAmp = 1. / 8.; // Multiplication factor in conversion from integer - TODO increase precision assuming Amplitude>0
constexpr int NIS = NTimeBinsPerBC * TSN; // Number of interpolated samples
// With a reference clock of 40 MHz exact this FTDCVal would have been
// constexpr float FTDCVal = 1. / TSNS;
Expand Down
9 changes: 4 additions & 5 deletions Detectors/ZDC/reconstruction/src/DigiReco.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1836,16 +1836,15 @@ void DigiReco::assignTDC(int ibun, int ibeg, int iend, int itdc, int tdc, float
}

// Encode amplitude and assign
auto myamp = TDCAmp / o2::zdc::FTDCAmp;
rec.TDCVal[itdc].push_back(TDCVal);
rec.TDCAmp[itdc].push_back(myamp);
rec.TDCAmp[itdc].push_back(TDCAmp);
int& ihit = mReco[ibun].ntdc[itdc];
#ifdef O2_ZDC_TDC_C_ARRAY
if (ihit < MaxTDCValues) {
rec.tdcVal[itdc][ihit] = TDCVal;
rec.tdcAmp[itdc][ihit] = myamp;
rec.tdcAmp[itdc][ihit] = TDCAmp;
} else {
LOG(error) << rec.ir.orbit << "." << rec.ir.bc << " ibun=" << ibun << " itdc=" << itdc << " tdc=" << tdc << " TDCVal=" << TDCVal * o2::zdc::FTDCVal << " TDCAmp=" << TDCAmp * o2::zdc::FTDCAmp << " OVERFLOW";
LOG(error) << rec.ir.orbit << "." << rec.ir.bc << " ibun=" << ibun << " itdc=" << itdc << " tdc=" << tdc << " TDCVal=" << TDCVal * o2::zdc::FTDCVal << " TDCAmp=" << TDCAmp << " OVERFLOW";
}
#endif
// Assign info about pedestal subtration
Expand All @@ -1863,7 +1862,7 @@ void DigiReco::assignTDC(int ibun, int ibeg, int iend, int itdc, int tdc, float
LOG(info) << __func__ << " itdc=" << itdc << " " << ChannelNames[isig] << " @ ibun=" << ibun << " " << mReco[ibun].ir.orbit << "." << mReco[ibun].ir.bc << " "
<< " tdc=" << tdc << " -> " << TDCValCorr << " shift=" << tdc_shift[itdc] << " -> TDCVal=" << TDCVal << "=" << TDCVal * o2::zdc::FTDCVal
<< " mSource[" << isig << "] = " << unsigned(mSource[isig]) << " = " << mOffset[isig]
<< " amp=" << amp << " -> " << TDCAmpCorr << " calib=" << tdc_calib[itdc] << " offset=" << tdc_offset[itdc] << " -> TDCAmp=" << TDCAmp << "=" << myamp
<< " amp=" << amp << " -> " << TDCAmpCorr << " calib=" << tdc_calib[itdc] << " offset=" << tdc_offset[itdc] << " -> TDCAmp=" << TDCAmp
<< (ibun == ibeg ? " B" : "") << (ibun == iend ? " E" : "");
mAssignedTDC[itdc]++;
#endif
Expand Down

0 comments on commit 82429bb

Please sign in to comment.