diff --git a/DataFormats/Detectors/Upgrades/ALICE3/TRKFT3/common/include/DataFormatsTRKFT3/Digit.h b/DataFormats/Detectors/Upgrades/ALICE3/TRKFT3/common/include/DataFormatsTRKFT3/Digit.h index cefadca6b266f..5e63972cde4a2 100644 --- a/DataFormats/Detectors/Upgrades/ALICE3/TRKFT3/common/include/DataFormatsTRKFT3/Digit.h +++ b/DataFormats/Detectors/Upgrades/ALICE3/TRKFT3/common/include/DataFormatsTRKFT3/Digit.h @@ -14,6 +14,7 @@ #include "Rtypes.h" #include +#include #include namespace o2::trkft3 @@ -22,14 +23,14 @@ namespace o2::trkft3 class Digit { public: - Digit(UShort_t chipindex = 0, UShort_t row = 0, UShort_t col = 0, Int_t charge = 0, float toa = 0); + Digit(UShort_t chipindex = 0, UShort_t row = 0, UShort_t col = 0, Int_t charge = 0, uint16_t timestampToA = 0); ~Digit() = default; UShort_t getChipIndex() const { return mChipIndex; } UShort_t getColumn() const { return mCol; } UShort_t getRow() const { return mRow; } Int_t getCharge() const { return mCharge; } - float getTimeOfArrival() const { return mToA; } + uint16_t getTimestampToA() const { return mTimestampToA; } void setChipIndex(UShort_t index) { mChipIndex = index; } void setPixelIndex(UShort_t row, UShort_t col) @@ -39,7 +40,7 @@ class Digit } void setCharge(Int_t charge) { mCharge = charge < USHRT_MAX ? charge : USHRT_MAX; } void addCharge(int charge) { setCharge(charge + int(mCharge)); } - void setToA(float toa) { mToA = toa; } + void setTimestampToA(uint16_t ts) { mTimestampToA = ts; } std::ostream& print(std::ostream& output) const; friend std::ostream& operator<<(std::ostream& output, const Digit& digi) @@ -53,9 +54,9 @@ class Digit UShort_t mRow = 0; UShort_t mCol = 0; UShort_t mCharge = 0; - float mToA = 0; // TimeOfArrival, set to float at the moment. TODO: implement correctly the size https://indico.cern.ch/event/1724141/contributions/7252329/attachments/3336751/5980668/data_throughput_estimation.pdf + uint16_t mTimestampToA = 0; ///< Time of Arrival timestamp: [frame (ROF counter) | clock cycle in ROF], see AlmiraParam::encodeTimestamp. https://indico.cern.ch/event/1724141/contributions/7252329/attachments/3336751/5980668/data_throughput_estimation.pdf - ClassDefNV(Digit, 2); + ClassDefNV(Digit, 3); }; } // namespace o2::trkft3 diff --git a/DataFormats/Detectors/Upgrades/ALICE3/TRKFT3/common/src/Digit.cxx b/DataFormats/Detectors/Upgrades/ALICE3/TRKFT3/common/src/Digit.cxx index d339aa5df5f8d..e67da8ca1839f 100644 --- a/DataFormats/Detectors/Upgrades/ALICE3/TRKFT3/common/src/Digit.cxx +++ b/DataFormats/Detectors/Upgrades/ALICE3/TRKFT3/common/src/Digit.cxx @@ -16,15 +16,15 @@ ClassImp(o2::trkft3::Digit); using namespace o2::trkft3; -Digit::Digit(UShort_t chipindex, UShort_t row, UShort_t col, Int_t charge, float toa) +Digit::Digit(UShort_t chipindex, UShort_t row, UShort_t col, Int_t charge, uint16_t timestampToA) : mChipIndex(chipindex), mRow(row), mCol(col) { setCharge(charge); - setToA(toa); + setTimestampToA(timestampToA); } std::ostream& Digit::print(std::ostream& output) const { - output << "TRKFT3Digit chip [" << mChipIndex << "] R:" << mRow << " C:" << mCol << " Q: " << mCharge << " ToA: " << mToA; + output << "TRKFT3Digit chip [" << mChipIndex << "] R:" << mRow << " C:" << mCol << " Q: " << mCharge << " TS: " << mTimestampToA; return output; } diff --git a/Detectors/Upgrades/ALICE3/TRKFT3/TRK/base/include/TRKBase/AlmiraParam.h b/Detectors/Upgrades/ALICE3/TRKFT3/TRK/base/include/TRKBase/AlmiraParam.h index 53d4792f7c2a5..492e8349c86fb 100644 --- a/Detectors/Upgrades/ALICE3/TRKFT3/TRK/base/include/TRKBase/AlmiraParam.h +++ b/Detectors/Upgrades/ALICE3/TRKFT3/TRK/base/include/TRKBase/AlmiraParam.h @@ -13,6 +13,8 @@ #define O2_TRK_ALMIRAPARAM_H #include +#include +#include #include "CommonConstants/LHCConstants.h" #include "CommonUtils/ConfigurableParam.h" @@ -29,18 +31,57 @@ struct AlmiraParam : public o2::conf::ConfigurableParamHelper { static constexpr size_t kNLayers = constants::VD::petal::nLayers + constants::ML::nLayers + constants::OT::nLayers + constants::MLOTDisks::nLayers; static constexpr size_t getNLayers() { return kNLayers; } + static constexpr int kDefROFLengthInBC = 16; ///< default ROF length in BC (16 clock cycles of 1 BC for VD) + int roFrameLengthInBCPerLayer[kNLayers] = {0}; ///< ROF length in BC per layer float strobeDelayPerLayer[kNLayers] = {0}; ///< strobe delay in ns per layer float strobeLengthContPerLayer[kNLayers] = {0}; ///< strobe length in ns per layer int roFrameBiasInBCPerLayer[kNLayers] = {0}; ///< ROF start bias in BC per layer int roFrameDelayInBCPerLayer[kNLayers] = {0}; ///< extra ROF delay in BC per layer + float clockPeriodPerLayer[kNLayers] = {0}; ///< ALMIRA clock period in ns per layer (timestamp fine granularity), 0 = default (1 BC VD, 4 BC ML/OT/disks) + int nTimestampBits = 12; ///< bits of the digit timestamp: [frame (coarse) | clock cycle in ROF (fine)] + int nFineBits = 4; ///< bits of the fine part (clock cycle in ROF); the coarse part (frame: free-running ROF counter, rolling over at 2^(nTimestampBits - nFineBits)) has nTimestampBits - nFineBits + + float getClockPeriod(int layer) const + { + if (clockPeriodPerLayer[layer] > 0) { + return clockPeriodPerLayer[layer]; + } + return (layer < constants::VD::petal::nLayers ? 1 : 4) * o2::constants::lhc::LHCBunchSpacingNS; // the clock is synchronous with the LHC: 1 BC (VD), 4 BC (ML/OT/disks) + } + + /// number of clock cycles in a ROF; if the ROF is not a multiple of the clock period, the last cycle is shorter + /// (e.g. ROF 18 BC, clock 4 BC -> 4.5 -> 5 cycles). Tolerance for the float rounding: 18 BC / 24.95 ns must give 18, not 19 + static int computeNClockCycles(int rofLengthInBC, float clockPeriod) + { + return std::ceil(rofLengthInBC * o2::constants::lhc::LHCBunchSpacingNS / clockPeriod - 1e-3); // - 1e-3: tolerance for float rounding + } + int getNClockCyclesPerROF(int layer) const { return computeNClockCycles(getROFLengthInBC(layer), getClockPeriod(layer)); } + + /// timestamp [frame (ROF counter) | clock cycle in ROF] of a signal with time toa (ns) w.r.t. the start of the ROF with index rofIndex + /// (ROFs counted continuously by the digitizer from the first sampled IR). The frame is a free-running ROF counter which + /// rolls over at 2^(nTimestampBits - nFineBits). toa < 0 means that the signal started in the previous ROF and is still + /// above threshold in this one: the timestamp refers to the ROF where the signal started. + /// TODO: once the edge detection is implemented, check this + uint16_t encodeTimestamp(float toa, long rofIndex, int rofLengthInBC, float clockPeriod, int nClockCycles) const + { + const float rofNS = rofLengthInBC * o2::constants::lhc::LHCBunchSpacingNS; + const int shift = std::floor(toa / rofNS); // 0, or -1 if the signal started in the previous ROF + const float tInROF = toa - shift * rofNS; // in [0, rofNS) + const int clockCycle = std::min(tInROF / clockPeriod, nClockCycles - 1); + const long frame = (rofIndex + shift) & ((1L << (nTimestampBits - nFineBits)) - 1); // rollover (ROF -1 gets the last frame) + return uint16_t(frame << nFineBits | clockCycle); + } + + int getFrame(uint16_t ts) const { return ts >> nFineBits; } + int getClockCycle(uint16_t ts) const { return ts & ((1 << nFineBits) - 1); } int getROFLengthInBC(int layer) const { if (roFrameLengthInBCPerLayer[layer] > 0) { return roFrameLengthInBCPerLayer[layer]; } else { - return o2::constants::lhc::LHCMaxBunches / 198; + return kDefROFLengthInBC; } } float getStrobeDelay(int layer) const { return strobeDelayPerLayer[layer]; } diff --git a/Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/include/TRKFT3Simulation/DigiParams.h b/Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/include/TRKFT3Simulation/DigiParams.h index 96e31fe477d6f..ddf131c71e9e7 100644 --- a/Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/include/TRKFT3Simulation/DigiParams.h +++ b/Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/include/TRKFT3Simulation/DigiParams.h @@ -122,6 +122,19 @@ class DigiParams virtual void print() const; + void setClockPeriod(float ns, int layer) // also sets the clock cycles per ROF: call after setROFrameLengthInBC + { + mClockPeriod[layer] = ns; + mNClockCyclesPerROF[layer] = o2::trk::AlmiraParam::computeNClockCycles(mROFrameLayerLengthInBC[layer], ns); + } + float getClockPeriod(int layer) const { return mClockPeriod[layer]; } + int getNClockCyclesPerROF(int layer) const { return mNClockCyclesPerROF[layer]; } + + uint16_t encodeTimestamp(float toa, long rofIndex, int layer) const + { + return o2::trk::AlmiraParam::Instance().encodeTimestamp(toa, rofIndex, mROFrameLayerLengthInBC[layer], mClockPeriod[layer], mNClockCyclesPerROF[layer]); + } + private: static constexpr double infTime = 1e99; float mNoisePerPixel = 0.2; ///< noise rate per pixel, in hits/s @@ -150,6 +163,9 @@ class DigiParams // auxiliary precalculated parameters std::array mROFrameLayerLengthInv; ///< inverse length of RO frame in ns per layer + std::array mClockPeriod{}; ///< ALMIRA clock period in ns per layer + std::array mNClockCyclesPerROF{}; ///< clock cycles in a ROF per layer (if the ROF is not a multiple of the clock period, the last cycle is shorter) + // ClassDef(DigiParams, 2); }; diff --git a/Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/src/DigiParams.cxx b/Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/src/DigiParams.cxx index 0fbe093f67936..82e111b0601f6 100644 --- a/Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/src/DigiParams.cxx +++ b/Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/src/DigiParams.cxx @@ -69,6 +69,14 @@ void DigiParams::print() const printf("Number of charge sharing steps : %d\n", mNSimSteps); printf("ELoss to N electrons factor : %e\n", mEnergyToNElectrons); printf("Noise rate per pixel : %e/s\n", mNoisePerPixel); + printf("Timestamp [frame (ROF counter) | clock cycle in ROF] per layer:\n"); + for (size_t i = 0; i < MaxLayers; ++i) { + if (mClockPeriod[i] > 0) { // layers in use + printf(" layer %2zu: ROF %d BC, clock period %.2f ns, %d clock cycles per ROF\n", + i, mROFrameLayerLengthInBC[i], mClockPeriod[i], mNClockCyclesPerROF[i]); + } + } + printf("Charge time-response:\n"); mSignalShape.print(); } diff --git a/Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/src/Digitizer.cxx b/Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/src/Digitizer.cxx index a20463737f816..59d521cd4f605 100644 --- a/Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/src/Digitizer.cxx +++ b/Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/src/Digitizer.cxx @@ -117,10 +117,10 @@ void Digitizer::process(const std::vector* hits, int evID, int srcID { // digitize single event, the time must have been set beforehand - LOG(info) << " Digitizing " << mGeometry->getName() << " (ID: " << mGeometry->getDetID() - << ") hits of event " << evID << " from source " << srcID - << " at time " << mEventTime.getTimeNS() << " ROFrame = " << mNewROFrame - << " Min/Max ROFrames " << mROFrameMin << "/" << mROFrameMax << " layer " << layer; + LOG(debug) << " Digitizing " << mGeometry->getName() << " (ID: " << mGeometry->getDetID() + << ") hits of event " << evID << " from source " << srcID + << " at time " << mEventTime.getTimeNS() << " ROFrame = " << mNewROFrame + << " Min/Max ROFrames " << mROFrameMin << "/" << mROFrameMax << " layer " << layer; // std::cout << "Printing segmentation info: " << std::endl; // SegmentationChip::Print(); @@ -138,7 +138,7 @@ void Digitizer::process(const std::vector* hits, int evID, int srcID [hits](auto lhs, auto rhs) { return (*hits)[lhs].GetDetectorID() < (*hits)[rhs].GetDetectorID(); }); - LOG(info) << "Processing " << nHits << " hits"; + LOG(debug) << "Processing " << nHits << " hits"; std::vector respMatrix; // the hits' charge response, reused from hit to hit within the event for (int i : hitIdx | std::views::filter([&](int idx) { if (layer < 0) { @@ -199,7 +199,7 @@ void Digitizer::fillOutputContainer(uint32_t frameLast, int layer) } // // make sure all buffers for extra digits are created up to the maxFrame getExtraDigBuffer(mROFrameMax); - LOG(info) << "Filling " << mGeometry->getName() << " digits output for RO frames " << mROFrameMin << ":" + LOG(debug) << "Filling " << mGeometry->getName() << " digits output for RO frames " << mROFrameMin << ":" << frameLast; o2::trkft3::ROFRecord rcROF; /// using temporarly trkft3::ROFRecord @@ -229,7 +229,7 @@ void Digitizer::fillOutputContainer(uint32_t frameLast, int layer) auto& preDig = iter->second; // preDigit if (preDig.charge >= mParams.getChargeThreshold()) { int digID = mDigits->size(); - mDigits->emplace_back(chip.getChipIndex(), preDig.row, preDig.col, preDig.charge, preDig.toa); + mDigits->emplace_back(chip.getChipIndex(), preDig.row, preDig.col, preDig.charge, mParams.encodeTimestamp(preDig.toa, mROFrameMin, layer)); LOG(debug) << "Adding digit ID: " << digID << " with chipID: " << chip.getChipIndex() << ", row: " << preDig.row << ", col: " << preDig.col << ", charge: " << preDig.charge << ", ToA: " << preDig.toa; mMCLabels->addElement(digID, preDig.labelRef.label); auto& nextRef = preDig.labelRef; // extra contributors are in extra array diff --git a/Steer/DigitizerWorkflow/src/TRKDigitizerSpec.cxx b/Steer/DigitizerWorkflow/src/TRKDigitizerSpec.cxx index 291c501323683..f8403a1a0176b 100644 --- a/Steer/DigitizerWorkflow/src/TRKDigitizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TRKDigitizerSpec.cxx @@ -138,8 +138,9 @@ class TRKFT3DPLDigitizerTask : BaseDPLDigitizer auto& digitsAccum = pc.outputs().make>(Output{Origin, "DIGITS", iLayer}); const int roFrameLengthInBC = mDigitizer.getParams().getROFrameLengthInBC(iLayer); - const int nROFsPerOrbit = o2::constants::lhc::LHCMaxBunches / roFrameLengthInBC; - const int nROFsTF = nROFsPerOrbit * raw::HBFUtils::Instance().getNOrbitsPerTF(); + const long tfLengthInBC = long(o2::constants::lhc::LHCMaxBunches) * raw::HBFUtils::Instance().getNOrbitsPerTF(); + const int nROFsTF = (tfLengthInBC + roFrameLengthInBC - 1) / roFrameLengthInBC; // rounded up: the last ROF may be truncated by the end of the TF + mROFRecordsAccum[iLayer].reserve(nROFsTF); auto accumulate = [this, &digitsAccum, &iLayer]() { @@ -159,7 +160,7 @@ class TRKFT3DPLDigitizerTask : BaseDPLDigitizer if (mWithMCTruth) { mLabelsAccum[iLayer].mergeAtBack(mLabels[iLayer]); } - LOG(info) << "Added " << mDigits[iLayer].size() << " digits on layer " << iLayer; + LOG(debug) << "Added " << mDigits[iLayer].size() << " digits on layer " << iLayer; mLabels[iLayer].clear(); mDigits[iLayer].clear(); mROFRecords[iLayer].clear(); @@ -288,6 +289,10 @@ class TRKFT3DPLDigitizerTask : BaseDPLDigitizer // FT3's discs take the AlmiraParam entries after TRK's barrel layers, which it reserves for them. constexpr int firstParLayer = N == o2::detectors::DetID::TRK ? 0 : o2::trk::AlmiraParam::getNLayers() - o2::trk::constants::MLOTDisks::nLayers; + if (aopt.nTimestampBits > 16 || aopt.nFineBits < 0 || aopt.nFineBits > aopt.nTimestampBits) { // TODO: check once the bits division has been definitively chosen + LOGP(fatal, "Invalid timestamp format: {} bits with {} fine bits (the digit timestamp is a uint16_t)", aopt.nTimestampBits, aopt.nFineBits); + } + for (int iLayer = 0; iLayer < mLayers; ++iLayer) { const int parLayer = std::min(firstParLayer + iLayer, o2::trk::AlmiraParam::getNLayers() - 1); const auto roFrameLengthInBC = aopt.getROFLengthInBC(parLayer); @@ -299,6 +304,19 @@ class TRKFT3DPLDigitizerTask : BaseDPLDigitizer const auto strobeLengthCont = aopt.getStrobeLengthCont(parLayer); digipar.setStrobeLength(strobeLengthCont > 0 ? strobeLengthCont : frameNS - aopt.getStrobeDelay(parLayer), iLayer); digipar.setROFrameLength(frameNS, iLayer); + digipar.setClockPeriod(aopt.getClockPeriod(parLayer), iLayer); // after setROFrameLengthInBC: computes and sets the clock cycles per ROF + + const int nCycles = digipar.getNClockCyclesPerROF(iLayer); + const long tfLengthInBC = long(o2::constants::lhc::LHCMaxBunches) * o2::raw::HBFUtils::Instance().getNOrbitsPerTF(); + if (tfLengthInBC % roFrameLengthInBC != 0) { + LOGP(warning, "{} layer {}: ROF length {} BC does not divide the TF length {} BC: the last ROF of the TF is truncated", ID.getName(), iLayer, roFrameLengthInBC, tfLengthInBC); + } + if ((1L << (aopt.nTimestampBits - aopt.nFineBits)) * roFrameLengthInBC <= o2::constants::lhc::LHCMaxBunches) { + LOGP(warning, "{} layer {}: the timestamp frame counter ({} bits) rolls over within an orbit with ROF length {} BC", ID.getName(), iLayer, aopt.nTimestampBits - aopt.nFineBits, roFrameLengthInBC); + } + if (nCycles > (1 << aopt.nFineBits)) { + LOGP(fatal, "{} layer {}: {} clock cycles per ROF do not fit in the {} fine bits of the timestamp. Possible values: 16 BC for VD; 16,32,64 BC for MLOT/FT3.", ID.getName(), iLayer, nCycles, aopt.nFineBits); + } } // parameters of signal time response: flat-top duration, max rise time and q @ which rise time is 0 digipar.getSignalShape().setParameters(dopt.strobeFlatTop, dopt.strobeMaxRiseTime, dopt.strobeQRiseTime0);