Skip to content

Commit 5c6d39b

Browse files
atrioloalibuild
andauthored
[ALICE3] TRK/FT3 digitizer: introduced discretization of the timestamp into digits with the ALMIRA ToA timestamp format (#16137)
Co-authored-by: ALICE Action Bot <alibuild@cern.ch>
1 parent 7bb4590 commit 5c6d39b

7 files changed

Lines changed: 111 additions & 20 deletions

File tree

‎DataFormats/Detectors/Upgrades/ALICE3/TRKFT3/common/include/DataFormatsTRKFT3/Digit.h‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "Rtypes.h"
1616
#include <climits>
17+
#include <cstdint>
1718
#include <iosfwd>
1819

1920
namespace o2::trkft3
@@ -22,14 +23,14 @@ namespace o2::trkft3
2223
class Digit
2324
{
2425
public:
25-
Digit(UShort_t chipindex = 0, UShort_t row = 0, UShort_t col = 0, Int_t charge = 0, float toa = 0);
26+
Digit(UShort_t chipindex = 0, UShort_t row = 0, UShort_t col = 0, Int_t charge = 0, uint16_t timestampToA = 0);
2627
~Digit() = default;
2728

2829
UShort_t getChipIndex() const { return mChipIndex; }
2930
UShort_t getColumn() const { return mCol; }
3031
UShort_t getRow() const { return mRow; }
3132
Int_t getCharge() const { return mCharge; }
32-
float getTimeOfArrival() const { return mToA; }
33+
uint16_t getTimestampToA() const { return mTimestampToA; }
3334

3435
void setChipIndex(UShort_t index) { mChipIndex = index; }
3536
void setPixelIndex(UShort_t row, UShort_t col)
@@ -39,7 +40,7 @@ class Digit
3940
}
4041
void setCharge(Int_t charge) { mCharge = charge < USHRT_MAX ? charge : USHRT_MAX; }
4142
void addCharge(int charge) { setCharge(charge + int(mCharge)); }
42-
void setToA(float toa) { mToA = toa; }
43+
void setTimestampToA(uint16_t ts) { mTimestampToA = ts; }
4344

4445
std::ostream& print(std::ostream& output) const;
4546
friend std::ostream& operator<<(std::ostream& output, const Digit& digi)
@@ -53,9 +54,9 @@ class Digit
5354
UShort_t mRow = 0;
5455
UShort_t mCol = 0;
5556
UShort_t mCharge = 0;
56-
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
57+
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
5758

58-
ClassDefNV(Digit, 2);
59+
ClassDefNV(Digit, 3);
5960
};
6061

6162
} // namespace o2::trkft3

‎DataFormats/Detectors/Upgrades/ALICE3/TRKFT3/common/src/Digit.cxx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ ClassImp(o2::trkft3::Digit);
1616

1717
using namespace o2::trkft3;
1818

19-
Digit::Digit(UShort_t chipindex, UShort_t row, UShort_t col, Int_t charge, float toa)
19+
Digit::Digit(UShort_t chipindex, UShort_t row, UShort_t col, Int_t charge, uint16_t timestampToA)
2020
: mChipIndex(chipindex), mRow(row), mCol(col)
2121
{
2222
setCharge(charge);
23-
setToA(toa);
23+
setTimestampToA(timestampToA);
2424
}
2525

2626
std::ostream& Digit::print(std::ostream& output) const
2727
{
28-
output << "TRKFT3Digit chip [" << mChipIndex << "] R:" << mRow << " C:" << mCol << " Q: " << mCharge << " ToA: " << mToA;
28+
output << "TRKFT3Digit chip [" << mChipIndex << "] R:" << mRow << " C:" << mCol << " Q: " << mCharge << " TS: " << mTimestampToA;
2929
return output;
3030
}

‎Detectors/Upgrades/ALICE3/TRKFT3/TRK/base/include/TRKBase/AlmiraParam.h‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#define O2_TRK_ALMIRAPARAM_H
1414

1515
#include <algorithm>
16+
#include <cmath>
17+
#include <cstdint>
1618

1719
#include "CommonConstants/LHCConstants.h"
1820
#include "CommonUtils/ConfigurableParam.h"
@@ -29,18 +31,57 @@ struct AlmiraParam : public o2::conf::ConfigurableParamHelper<AlmiraParam> {
2931
static constexpr size_t kNLayers = constants::VD::petal::nLayers + constants::ML::nLayers + constants::OT::nLayers + constants::MLOTDisks::nLayers;
3032
static constexpr size_t getNLayers() { return kNLayers; }
3133

34+
static constexpr int kDefROFLengthInBC = 16; ///< default ROF length in BC (16 clock cycles of 1 BC for VD)
35+
3236
int roFrameLengthInBCPerLayer[kNLayers] = {0}; ///< ROF length in BC per layer
3337
float strobeDelayPerLayer[kNLayers] = {0}; ///< strobe delay in ns per layer
3438
float strobeLengthContPerLayer[kNLayers] = {0}; ///< strobe length in ns per layer
3539
int roFrameBiasInBCPerLayer[kNLayers] = {0}; ///< ROF start bias in BC per layer
3640
int roFrameDelayInBCPerLayer[kNLayers] = {0}; ///< extra ROF delay in BC per layer
41+
float clockPeriodPerLayer[kNLayers] = {0}; ///< ALMIRA clock period in ns per layer (timestamp fine granularity), 0 = default (1 BC VD, 4 BC ML/OT/disks)
42+
int nTimestampBits = 12; ///< bits of the digit timestamp: [frame (coarse) | clock cycle in ROF (fine)]
43+
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
44+
45+
float getClockPeriod(int layer) const
46+
{
47+
if (clockPeriodPerLayer[layer] > 0) {
48+
return clockPeriodPerLayer[layer];
49+
}
50+
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)
51+
}
52+
53+
/// number of clock cycles in a ROF (the ROF length is a multiple of the clock period, as required by the ALMIRA design)
54+
static int computeNClockCycles(int rofLengthInBC, float clockPeriod)
55+
{
56+
return std::round(rofLengthInBC * o2::constants::lhc::LHCBunchSpacingNS / clockPeriod);
57+
}
58+
59+
int getNClockCyclesPerROF(int layer) const { return computeNClockCycles(getROFLengthInBC(layer), getClockPeriod(layer)); }
60+
61+
/// 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
62+
/// (ROFs counted continuously by the digitizer from the first sampled IR). The frame is a free-running ROF counter which
63+
/// rolls over at 2^(nTimestampBits - nFineBits). toa < 0 means that the signal started in the previous ROF and is still
64+
/// above threshold in this one: the timestamp refers to the ROF where the signal started.
65+
/// TODO: once the edge detection is implemented, check this
66+
uint16_t encodeTimestamp(float toa, long rofIndex, int rofLengthInBC, float clockPeriod, int nClockCycles) const
67+
{
68+
const float rofNS = rofLengthInBC * o2::constants::lhc::LHCBunchSpacingNS;
69+
const int shift = std::floor(toa / rofNS); // 0, or -1 if the signal started in the previous ROF
70+
const float tInROF = toa - shift * rofNS; // in [0, rofNS)
71+
const int clockCycle = std::min<int>(tInROF / clockPeriod, nClockCycles - 1);
72+
const long frame = (rofIndex + shift) & ((1L << (nTimestampBits - nFineBits)) - 1); // rollover (ROF -1 gets the last frame)
73+
return uint16_t(frame << nFineBits | clockCycle);
74+
}
75+
76+
int getFrame(uint16_t ts) const { return ts >> nFineBits; }
77+
int getClockCycle(uint16_t ts) const { return ts & ((1 << nFineBits) - 1); }
3778

3879
int getROFLengthInBC(int layer) const
3980
{
4081
if (roFrameLengthInBCPerLayer[layer] > 0) {
4182
return roFrameLengthInBCPerLayer[layer];
4283
} else {
43-
return o2::constants::lhc::LHCMaxBunches / 198;
84+
return kDefROFLengthInBC;
4485
}
4586
}
4687
float getStrobeDelay(int layer) const { return strobeDelayPerLayer[layer]; }

‎Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/include/TRKFT3Simulation/DigiParams.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,19 @@ class DigiParams
122122

123123
virtual void print() const;
124124

125+
void setClockPeriod(float ns, int layer) // also sets the clock cycles per ROF: call after setROFrameLengthInBC
126+
{
127+
mClockPeriod[layer] = ns;
128+
mNClockCyclesPerROF[layer] = o2::trk::AlmiraParam::computeNClockCycles(mROFrameLayerLengthInBC[layer], ns);
129+
}
130+
float getClockPeriod(int layer) const { return mClockPeriod[layer]; }
131+
int getNClockCyclesPerROF(int layer) const { return mNClockCyclesPerROF[layer]; }
132+
133+
uint16_t encodeTimestamp(float toa, long rofIndex, int layer) const
134+
{
135+
return o2::trk::AlmiraParam::Instance().encodeTimestamp(toa, rofIndex, mROFrameLayerLengthInBC[layer], mClockPeriod[layer], mNClockCyclesPerROF[layer]);
136+
}
137+
125138
private:
126139
static constexpr double infTime = 1e99;
127140
float mNoisePerPixel = 0.2; ///< noise rate per pixel, in hits/s
@@ -150,6 +163,9 @@ class DigiParams
150163
// auxiliary precalculated parameters
151164
std::array<float, MaxLayers> mROFrameLayerLengthInv; ///< inverse length of RO frame in ns per layer
152165

166+
std::array<float, MaxLayers> mClockPeriod{}; ///< ALMIRA clock period in ns per layer
167+
std::array<int, MaxLayers> mNClockCyclesPerROF{}; ///< clock cycles in a ROF per layer (if the ROF is not a multiple of the clock period, the last cycle is shorter)
168+
153169
// ClassDef(DigiParams, 2);
154170
};
155171

‎Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/src/DigiParams.cxx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ void DigiParams<DetIDV>::print() const
6969
printf("Number of charge sharing steps : %d\n", mNSimSteps);
7070
printf("ELoss to N electrons factor : %e\n", mEnergyToNElectrons);
7171
printf("Noise rate per pixel : %e/s\n", mNoisePerPixel);
72+
printf("Timestamp [frame (ROF counter) | clock cycle in ROF] per layer:\n");
73+
for (size_t i = 0; i < MaxLayers; ++i) {
74+
if (mClockPeriod[i] > 0) { // layers in use
75+
printf(" layer %2zu: ROF %d BC, clock period %.2f ns, %d clock cycles per ROF\n",
76+
i, mROFrameLayerLengthInBC[i], mClockPeriod[i], mNClockCyclesPerROF[i]);
77+
}
78+
}
79+
7280
printf("Charge time-response:\n");
7381
mSignalShape.print();
7482
}

‎Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/src/Digitizer.cxx‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ void Digitizer<DetID>::process(const std::vector<Hit>* hits, int evID, int srcID
117117
{
118118
// digitize single event, the time must have been set beforehand
119119

120-
LOG(info) << " Digitizing " << mGeometry->getName() << " (ID: " << mGeometry->getDetID()
121-
<< ") hits of event " << evID << " from source " << srcID
122-
<< " at time " << mEventTime.getTimeNS() << " ROFrame = " << mNewROFrame
123-
<< " Min/Max ROFrames " << mROFrameMin << "/" << mROFrameMax << " layer " << layer;
120+
LOG(debug) << " Digitizing " << mGeometry->getName() << " (ID: " << mGeometry->getDetID()
121+
<< ") hits of event " << evID << " from source " << srcID
122+
<< " at time " << mEventTime.getTimeNS() << " ROFrame = " << mNewROFrame
123+
<< " Min/Max ROFrames " << mROFrameMin << "/" << mROFrameMax << " layer " << layer;
124124

125125
// std::cout << "Printing segmentation info: " << std::endl;
126126
// SegmentationChip::Print();
@@ -138,7 +138,7 @@ void Digitizer<DetID>::process(const std::vector<Hit>* hits, int evID, int srcID
138138
[hits](auto lhs, auto rhs) {
139139
return (*hits)[lhs].GetDetectorID() < (*hits)[rhs].GetDetectorID();
140140
});
141-
LOG(info) << "Processing " << nHits << " hits";
141+
LOG(debug) << "Processing " << nHits << " hits";
142142
std::vector<float> respMatrix; // the hits' charge response, reused from hit to hit within the event
143143
for (int i : hitIdx | std::views::filter([&](int idx) {
144144
if (layer < 0) {
@@ -199,8 +199,8 @@ void Digitizer<DetID>::fillOutputContainer(uint32_t frameLast, int layer)
199199
}
200200
// // make sure all buffers for extra digits are created up to the maxFrame
201201
getExtraDigBuffer(mROFrameMax);
202-
LOG(info) << "Filling " << mGeometry->getName() << " digits output for RO frames " << mROFrameMin << ":"
203-
<< frameLast;
202+
LOG(debug) << "Filling " << mGeometry->getName() << " digits output for RO frames " << mROFrameMin << ":"
203+
<< frameLast;
204204

205205
o2::trkft3::ROFRecord rcROF; /// using temporarly trkft3::ROFRecord
206206

@@ -229,7 +229,7 @@ void Digitizer<DetID>::fillOutputContainer(uint32_t frameLast, int layer)
229229
auto& preDig = iter->second; // preDigit
230230
if (preDig.charge >= mParams.getChargeThreshold()) {
231231
int digID = mDigits->size();
232-
mDigits->emplace_back(chip.getChipIndex(), preDig.row, preDig.col, preDig.charge, preDig.toa);
232+
mDigits->emplace_back(chip.getChipIndex(), preDig.row, preDig.col, preDig.charge, mParams.encodeTimestamp(preDig.toa, mROFrameMin, layer));
233233
LOG(debug) << "Adding digit ID: " << digID << " with chipID: " << chip.getChipIndex() << ", row: " << preDig.row << ", col: " << preDig.col << ", charge: " << preDig.charge << ", ToA: " << preDig.toa;
234234
mMCLabels->addElement(digID, preDig.labelRef.label);
235235
auto& nextRef = preDig.labelRef; // extra contributors are in extra array

‎Steer/DigitizerWorkflow/src/TRKDigitizerSpec.cxx‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ class TRKFT3DPLDigitizerTask : BaseDPLDigitizer
138138
auto& digitsAccum = pc.outputs().make<std::vector<trkft3::Digit>>(Output{Origin, "DIGITS", iLayer});
139139

140140
const int roFrameLengthInBC = mDigitizer.getParams().getROFrameLengthInBC(iLayer);
141-
const int nROFsPerOrbit = o2::constants::lhc::LHCMaxBunches / roFrameLengthInBC;
142-
const int nROFsTF = nROFsPerOrbit * raw::HBFUtils::Instance().getNOrbitsPerTF();
141+
const long tfLengthInBC = long(o2::constants::lhc::LHCMaxBunches) * raw::HBFUtils::Instance().getNOrbitsPerTF();
142+
const int nROFsTF = (tfLengthInBC + roFrameLengthInBC - 1) / roFrameLengthInBC; // rounded up: if the TF length is not a multiple of the ROF length, the last ROF is truncated by the end of the TF
143+
// (simulation artifact: the handling of ROFs across the TF boundary is still to be defined with DAQ)
144+
143145
mROFRecordsAccum[iLayer].reserve(nROFsTF);
144146

145147
auto accumulate = [this, &digitsAccum, &iLayer]() {
@@ -159,7 +161,7 @@ class TRKFT3DPLDigitizerTask : BaseDPLDigitizer
159161
if (mWithMCTruth) {
160162
mLabelsAccum[iLayer].mergeAtBack(mLabels[iLayer]);
161163
}
162-
LOG(info) << "Added " << mDigits[iLayer].size() << " digits on layer " << iLayer;
164+
LOG(debug) << "Added " << mDigits[iLayer].size() << " digits on layer " << iLayer;
163165
mLabels[iLayer].clear();
164166
mDigits[iLayer].clear();
165167
mROFRecords[iLayer].clear();
@@ -288,6 +290,10 @@ class TRKFT3DPLDigitizerTask : BaseDPLDigitizer
288290

289291
// FT3's discs take the AlmiraParam entries after TRK's barrel layers, which it reserves for them.
290292
constexpr int firstParLayer = N == o2::detectors::DetID::TRK ? 0 : o2::trk::AlmiraParam::getNLayers() - o2::trk::constants::MLOTDisks::nLayers;
293+
if (aopt.nTimestampBits > 16 || aopt.nFineBits < 0 || aopt.nFineBits > aopt.nTimestampBits) { // TODO: check once the bits division has been definitively chosen
294+
LOGP(fatal, "Invalid timestamp format: {} bits with {} fine bits (the digit timestamp is a uint16_t)", aopt.nTimestampBits, aopt.nFineBits);
295+
}
296+
291297
for (int iLayer = 0; iLayer < mLayers; ++iLayer) {
292298
const int parLayer = std::min<int>(firstParLayer + iLayer, o2::trk::AlmiraParam::getNLayers() - 1);
293299
const auto roFrameLengthInBC = aopt.getROFLengthInBC(parLayer);
@@ -299,6 +305,25 @@ class TRKFT3DPLDigitizerTask : BaseDPLDigitizer
299305
const auto strobeLengthCont = aopt.getStrobeLengthCont(parLayer);
300306
digipar.setStrobeLength(strobeLengthCont > 0 ? strobeLengthCont : frameNS - aopt.getStrobeDelay(parLayer), iLayer);
301307
digipar.setROFrameLength(frameNS, iLayer);
308+
digipar.setClockPeriod(aopt.getClockPeriod(parLayer), iLayer); // after setROFrameLengthInBC: computes and sets the clock cycles per ROF
309+
310+
const int nCycles = digipar.getNClockCyclesPerROF(iLayer);
311+
const float clockPeriod = digipar.getClockPeriod(iLayer);
312+
if (std::abs(nCycles * clockPeriod - frameNS) > 1e-3f * clockPeriod) { // tolerance for the float comparison only
313+
LOGP(fatal, "{} layer {}: ROF length {} BC ({:.2f} ns) is not a multiple of the clock period ({:.2f} ns), as required by the ALMIRA design",
314+
ID.getName(), iLayer, roFrameLengthInBC, frameNS, clockPeriod);
315+
}
316+
317+
const long tfLengthInBC = long(o2::constants::lhc::LHCMaxBunches) * o2::raw::HBFUtils::Instance().getNOrbitsPerTF();
318+
if (tfLengthInBC % roFrameLengthInBC != 0) {
319+
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);
320+
}
321+
if ((1L << (aopt.nTimestampBits - aopt.nFineBits)) * roFrameLengthInBC <= o2::constants::lhc::LHCMaxBunches) {
322+
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);
323+
}
324+
if (nCycles > (1 << aopt.nFineBits)) {
325+
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);
326+
}
302327
}
303328
// parameters of signal time response: flat-top duration, max rise time and q @ which rise time is 0
304329
digipar.getSignalShape().setParameters(dopt.strobeFlatTop, dopt.strobeMaxRiseTime, dopt.strobeQRiseTime0);

0 commit comments

Comments
 (0)