diff --git a/Detectors/Upgrades/ALICE3/IOTOF/simulation/include/IOTOFSimulation/Digitizer.h b/Detectors/Upgrades/ALICE3/IOTOF/simulation/include/IOTOFSimulation/Digitizer.h index a0c55f62eb3a4..bfb6a121ea46b 100644 --- a/Detectors/Upgrades/ALICE3/IOTOF/simulation/include/IOTOFSimulation/Digitizer.h +++ b/Detectors/Upgrades/ALICE3/IOTOF/simulation/include/IOTOFSimulation/Digitizer.h @@ -62,6 +62,7 @@ class Digitizer : public TObject /// Set the event time void setEventTime(const o2::InteractionTimeRecord& irt) { mEventTime = irt; } + void setROFRecordIR(const o2::InteractionRecord& ir) { mROFRecordIR = ir; } /// Set continuous readout mode void setContinuous(bool v) { mContinuous = v; } @@ -89,7 +90,7 @@ class Digitizer : public TObject void processHit(const o2::itsmft::Hit& hit, int evID, int srcID); /// Register digits in a given chip - void registerDigits(Chip& chip, uint32_t roFrame, float timeInitROF, int nROF, + void registerDigits(Chip& chip, uint32_t roFrame, double time, int nROF, uint16_t row, uint16_t col, int nElectrons, o2::MCCompLabel& label); /// Apply time smearing to simulate detector resolution @@ -127,6 +128,7 @@ class Digitizer : public TObject o2::dataformats::MCTruthContainer* mMCLabels = nullptr; //! output labels o2::InteractionTimeRecord mEventTime; ///< global event time and interaction record + o2::InteractionRecord mROFRecordIR; ///< interaction record assigned to the output ROF bool mContinuous = true; ///< continuous readout mode // Digitization parameters @@ -141,4 +143,4 @@ class Digitizer : public TObject }; } // namespace o2::iotof -#endif \ No newline at end of file +#endif diff --git a/Detectors/Upgrades/ALICE3/IOTOF/simulation/src/Digitizer.cxx b/Detectors/Upgrades/ALICE3/IOTOF/simulation/src/Digitizer.cxx index 754eb2e76f123..f5694412c5f5e 100644 --- a/Detectors/Upgrades/ALICE3/IOTOF/simulation/src/Digitizer.cxx +++ b/Detectors/Upgrades/ALICE3/IOTOF/simulation/src/Digitizer.cxx @@ -124,11 +124,7 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, int evID, int srcID) double absoluteTime = hitTime + eventTimeNS; // absolute time double smearedTime = smearTime(absoluteTime); // apply detector resolution - // For now, use simple row/col mapping from detector ID - // TODO: Implement proper segmentation when geometry is finalized - uint16_t chipIndex = static_cast(chipID); - - if (chipID > mGeometry->getSize() || mGeometry->getSize() < 1) { + if (chipID < 0 || chipID >= mGeometry->getSize() || mGeometry->getSize() < 1) { LOG(debug) << "Invalid detector ID: " << chipID << ", geometry size: " << mGeometry->getSize(); return; // invalid detector ID } @@ -146,13 +142,11 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, int evID, int srcID) } // Create the digit with time information - int digID = mDigits->size(); o2::MCCompLabel label(hit.GetTrackID(), evID, srcID, false); const int roFrameAbs = 0; // For now, we can set this to 0 or calculate based on time if needed - const int timeInitROF = 0; // For now, we can set this to 0 or calculate based on time if needed const int nROF = 1; // For now, we can assume the signal is contained in one ROF, this can be extended to multiple ROFs based on the time - registerDigits(chip, roFrameAbs, timeInitROF, nROF, static_cast(row), static_cast(col), charge, label); + registerDigits(chip, roFrameAbs, smearedTime, nROF, static_cast(row), static_cast(col), charge, label); } //_______________________________________________________________________ @@ -190,7 +184,7 @@ void Digitizer::fillOutputContainer() o2::itsmft::ROFRecord rof; rof.setFirstEntry(mDigits->size()); // index of the first digit - auto& extraLabelBuffer = *(mExtraLabelBuffer.front().get()); // buffer for extra labels + const auto* extraLabelBuffer = mExtraLabelBuffer.empty() ? nullptr : mExtraLabelBuffer.front().get(); for (auto& chip : mChips) { if (chip.isDisabled()) { @@ -213,11 +207,13 @@ void Digitizer::fillOutputContainer() int digitID = mDigits->size(); mDigits->emplace_back(digit.getChipIndex(), digit.getRow(), digit.getColumn(), digit.getCharge(), digit.getTime()); - mMCLabels->addElement(digitID, digit.getLabel().mLabel); + if (mMCLabels) { + mMCLabels->addElement(digitID, digit.getLabel().mLabel); + } auto labelRef = digit.getLabel(); - while (labelRef.mNext >= 0) { - labelRef = extraLabelBuffer[labelRef.mNext]; + while (mMCLabels && extraLabelBuffer != nullptr && labelRef.mNext >= 0) { + labelRef = (*extraLabelBuffer)[labelRef.mNext]; mMCLabels->addElement(digitID, labelRef.mLabel); } } @@ -225,7 +221,7 @@ void Digitizer::fillOutputContainer() } rof.setNEntries(mDigits->size() - rof.getFirstEntry()); // number of digits - rof.setBCData(mEventTime); + rof.setBCData(mContinuous ? mROFRecordIR : mEventTime); mROFRecords->push_back(rof); LOG(debug) << "Created ROF record with " << mDigits->size() << " digits"; @@ -234,24 +230,30 @@ void Digitizer::fillOutputContainer() // mExtraLabelBuffer.pop_front(); } -void Digitizer::registerDigits(Chip& chip, uint32_t roFrame, float timeInitROF, int nROF, +void Digitizer::registerDigits(Chip& chip, uint32_t roFrame, double time, int nROF, uint16_t row, uint16_t col, int nElectrons, o2::MCCompLabel& label) { + (void)nROF; - auto key = o2::iotof::Digit::getOrderingKey(roFrame, row, col); + auto key = o2::iotof::Digit::getOrderingKey(chip.getChipIndex(), row, col); o2::iotof::LabeledDigit* existingDigit = chip.findDigit(key); if (!existingDigit) { // No existing digit, create a new one - chip.addDigit(row, col, nElectrons, timeInitROF, label); // Last one should really just be time + chip.addDigit(row, col, nElectrons, time, label); } else { // Digit already exists, update charge and labels const int storedCharge = existingDigit->getCharge(); existingDigit->setCharge(storedCharge + nElectrons); + existingDigit->setTime(std::min(existingDigit->getTime(), time)); if (existingDigit->getLabel().mLabel == label) { return; // don't store the same label twice } std::vector* extra = getExtraLabelBuffer(roFrame); - extra->emplace_back(label); + auto labelRef = existingDigit->getLabel(); + const auto next = static_cast(extra->size()); + extra->emplace_back(label, labelRef.mNext); + labelRef.mNext = next; + existingDigit->setLabel(labelRef); } } diff --git a/Steer/DigitizerWorkflow/src/IOTOFDigitizerSpec.cxx b/Steer/DigitizerWorkflow/src/IOTOFDigitizerSpec.cxx index 4611ec4e0af11..97f292332ecdb 100644 --- a/Steer/DigitizerWorkflow/src/IOTOFDigitizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/IOTOFDigitizerSpec.cxx @@ -90,6 +90,7 @@ class IOTOFDPLDigitizerTask : o2::base::BaseDPLDigitizer mDigitizer.setDigits(&mDigits); mDigitizer.setROFRecords(&mROFRecords); + mDigitizer.setROFRecordIR(firstIR); if (mWithMCTruth) { mDigitizer.setMCLabels(&mLabels); }