From 82429bb200b15841c4ec4e9da0ed3766edeeed7c Mon Sep 17 00:00:00 2001 From: cortesep <57937610+cortesep@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:02:03 +0100 Subject: [PATCH] ZDC - Update of the intermediate reconstructed format to avoid losing numerical precision (#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 --- .../ZDC/include/DataFormatsZDC/RecEventFlat.h | 2 +- .../ZDC/include/DataFormatsZDC/ZDCTDCData.h | 45 +++++-------------- .../Detectors/ZDC/src/DataFormatsZDCLinkDef.h | 2 + .../Detectors/ZDC/src/RecEventFlat.cxx | 5 +-- DataFormats/Detectors/ZDC/src/ZDCTDCData.cxx | 3 +- .../ZDC/base/include/ZDCBase/Constants.h | 1 - Detectors/ZDC/reconstruction/src/DigiReco.cxx | 9 ++-- 7 files changed, 22 insertions(+), 45 deletions(-) diff --git a/DataFormats/Detectors/ZDC/include/DataFormatsZDC/RecEventFlat.h b/DataFormats/Detectors/ZDC/include/DataFormatsZDC/RecEventFlat.h index c47ac45373e4b..ea5fd10f92dcc 100644 --- a/DataFormats/Detectors/ZDC/include/DataFormatsZDC/RecEventFlat.h +++ b/DataFormats/Detectors/ZDC/include/DataFormatsZDC/RecEventFlat.h @@ -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::infinity(); diff --git a/DataFormats/Detectors/ZDC/include/DataFormatsZDC/ZDCTDCData.h b/DataFormats/Detectors/ZDC/include/DataFormatsZDC/ZDCTDCData.h index 4e3d0bc9f9d4f..d4d6bcdf75be0 100644 --- a/DataFormats/Detectors/ZDC/include/DataFormatsZDC/ZDCTDCData.h +++ b/DataFormats/Detectors/ZDC/include/DataFormatsZDC/ZDCTDCData.h @@ -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() @@ -43,11 +42,6 @@ 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]; - } - } } }; @@ -55,10 +49,11 @@ 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; @@ -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 @@ -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 @@ -96,7 +91,6 @@ struct ZDCTDCData { } auto TDCVal = std::nearbyint(vala); - auto TDCAmp = std::nearbyint(ampa); if (TDCVal < kMinShort) { int itdc = int(id); @@ -116,46 +110,31 @@ 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; @@ -163,7 +142,7 @@ struct ZDCTDCData { void print() const; - ClassDefNV(ZDCTDCData, 1); + ClassDefNV(ZDCTDCData, 2); }; } // namespace zdc } // namespace o2 diff --git a/DataFormats/Detectors/ZDC/src/DataFormatsZDCLinkDef.h b/DataFormats/Detectors/ZDC/src/DataFormatsZDCLinkDef.h index 6e272dbc8a118..0fbc7308f39e3 100644 --- a/DataFormats/Detectors/ZDC/src/DataFormatsZDCLinkDef.h +++ b/DataFormats/Detectors/ZDC/src/DataFormatsZDCLinkDef.h @@ -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 diff --git a/DataFormats/Detectors/ZDC/src/RecEventFlat.cxx b/DataFormats/Detectors/ZDC/src/RecEventFlat.cxx index 2494b31e5d770..cb49905ea57da 100644 --- a/DataFormats/Detectors/ZDC/src/RecEventFlat.cxx +++ b/DataFormats/Detectors/ZDC/src/RecEventFlat.cxx @@ -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 diff --git a/DataFormats/Detectors/ZDC/src/ZDCTDCData.cxx b/DataFormats/Detectors/ZDC/src/ZDCTDCData.cxx index e86ddddbf2ce7..5c55eddee1525 100644 --- a/DataFormats/Detectors/ZDC/src/ZDCTDCData.cxx +++ b/DataFormats/Detectors/ZDC/src/ZDCTDCData.cxx @@ -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 @@ -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" : ""); } diff --git a/Detectors/ZDC/base/include/ZDCBase/Constants.h b/Detectors/ZDC/base/include/ZDCBase/Constants.h index 031d576e15eca..dfeb5be6d7d98 100644 --- a/Detectors/ZDC/base/include/ZDCBase/Constants.h +++ b/Detectors/ZDC/base/include/ZDCBase/Constants.h @@ -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; diff --git a/Detectors/ZDC/reconstruction/src/DigiReco.cxx b/Detectors/ZDC/reconstruction/src/DigiReco.cxx index f3e22c9ece54f..397e2aef63f1c 100644 --- a/Detectors/ZDC/reconstruction/src/DigiReco.cxx +++ b/Detectors/ZDC/reconstruction/src/DigiReco.cxx @@ -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 @@ -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