Skip to content

Commit 1a29416

Browse files
committed
TF3: fix digit time
1 parent 644949a commit 1a29416

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

Detectors/Upgrades/ALICE3/IOTOF/simulation/include/IOTOFSimulation/Digitizer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Digitizer : public TObject
8989
void processHit(const o2::itsmft::Hit& hit, int evID, int srcID);
9090

9191
/// Register digits in a given chip
92-
void registerDigits(Chip& chip, uint32_t roFrame, float timeInitROF, int nROF,
92+
void registerDigits(Chip& chip, uint32_t roFrame, double time, int nROF,
9393
uint16_t row, uint16_t col, int nElectrons, o2::MCCompLabel& label);
9494

9595
/// Apply time smearing to simulate detector resolution
@@ -141,4 +141,4 @@ class Digitizer : public TObject
141141
};
142142
} // namespace o2::iotof
143143

144-
#endif
144+
#endif

Detectors/Upgrades/ALICE3/IOTOF/simulation/src/Digitizer.cxx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,7 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, int evID, int srcID)
124124
double absoluteTime = hitTime + eventTimeNS; // absolute time
125125
double smearedTime = smearTime(absoluteTime); // apply detector resolution
126126

127-
// For now, use simple row/col mapping from detector ID
128-
// TODO: Implement proper segmentation when geometry is finalized
129-
uint16_t chipIndex = static_cast<uint16_t>(chipID);
130-
131-
if (chipID > mGeometry->getSize() || mGeometry->getSize() < 1) {
127+
if (chipID < 0 || chipID >= mGeometry->getSize() || mGeometry->getSize() < 1) {
132128
LOG(debug) << "Invalid detector ID: " << chipID << ", geometry size: " << mGeometry->getSize();
133129
return; // invalid detector ID
134130
}
@@ -146,13 +142,11 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, int evID, int srcID)
146142
}
147143

148144
// Create the digit with time information
149-
int digID = mDigits->size();
150145
o2::MCCompLabel label(hit.GetTrackID(), evID, srcID, false);
151146
const int roFrameAbs = 0; // For now, we can set this to 0 or calculate based on time if needed
152-
const int timeInitROF = 0; // For now, we can set this to 0 or calculate based on time if needed
153147
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
154148

155-
registerDigits(chip, roFrameAbs, timeInitROF, nROF, static_cast<uint16_t>(row), static_cast<uint16_t>(col), charge, label);
149+
registerDigits(chip, roFrameAbs, smearedTime, nROF, static_cast<uint16_t>(row), static_cast<uint16_t>(col), charge, label);
156150
}
157151

158152
//_______________________________________________________________________
@@ -190,7 +184,7 @@ void Digitizer::fillOutputContainer()
190184
o2::itsmft::ROFRecord rof;
191185
rof.setFirstEntry(mDigits->size()); // index of the first digit
192186

193-
auto& extraLabelBuffer = *(mExtraLabelBuffer.front().get()); // buffer for extra labels
187+
const auto* extraLabelBuffer = mExtraLabelBuffer.empty() ? nullptr : mExtraLabelBuffer.front().get();
194188
for (auto& chip : mChips) {
195189

196190
if (chip.isDisabled()) {
@@ -213,11 +207,13 @@ void Digitizer::fillOutputContainer()
213207

214208
int digitID = mDigits->size();
215209
mDigits->emplace_back(digit.getChipIndex(), digit.getRow(), digit.getColumn(), digit.getCharge(), digit.getTime());
216-
mMCLabels->addElement(digitID, digit.getLabel().mLabel);
210+
if (mMCLabels) {
211+
mMCLabels->addElement(digitID, digit.getLabel().mLabel);
212+
}
217213
auto labelRef = digit.getLabel();
218214

219-
while (labelRef.mNext >= 0) {
220-
labelRef = extraLabelBuffer[labelRef.mNext];
215+
while (mMCLabels && extraLabelBuffer != nullptr && labelRef.mNext >= 0) {
216+
labelRef = (*extraLabelBuffer)[labelRef.mNext];
221217
mMCLabels->addElement(digitID, labelRef.mLabel);
222218
}
223219
}
@@ -234,24 +230,30 @@ void Digitizer::fillOutputContainer()
234230
// mExtraLabelBuffer.pop_front();
235231
}
236232

237-
void Digitizer::registerDigits(Chip& chip, uint32_t roFrame, float timeInitROF, int nROF,
233+
void Digitizer::registerDigits(Chip& chip, uint32_t roFrame, double time, int nROF,
238234
uint16_t row, uint16_t col, int nElectrons, o2::MCCompLabel& label)
239235
{
236+
(void)nROF;
240237

241-
auto key = o2::iotof::Digit::getOrderingKey(roFrame, row, col);
238+
auto key = o2::iotof::Digit::getOrderingKey(chip.getChipIndex(), row, col);
242239
o2::iotof::LabeledDigit* existingDigit = chip.findDigit(key);
243240
if (!existingDigit) {
244241
// No existing digit, create a new one
245-
chip.addDigit(row, col, nElectrons, timeInitROF, label); // Last one should really just be time
242+
chip.addDigit(row, col, nElectrons, time, label);
246243
} else {
247244
// Digit already exists, update charge and labels
248245
const int storedCharge = existingDigit->getCharge();
249246
existingDigit->setCharge(storedCharge + nElectrons);
247+
existingDigit->setTime(std::min(existingDigit->getTime(), time));
250248
if (existingDigit->getLabel().mLabel == label) {
251249
return; // don't store the same label twice
252250
}
253251
std::vector<o2::iotof::McLabelRef>* extra = getExtraLabelBuffer(roFrame);
254-
extra->emplace_back(label);
252+
auto labelRef = existingDigit->getLabel();
253+
const auto next = static_cast<int>(extra->size());
254+
extra->emplace_back(label, labelRef.mNext);
255+
labelRef.mNext = next;
256+
existingDigit->setLabel(labelRef);
255257
}
256258
}
257259

0 commit comments

Comments
 (0)