Skip to content

Commit 3e6db16

Browse files
committed
TRK/FT3 digitizer: changed digit ToA format from float to the format of the ALMIRA timestamp: 12 bits filled as following [frame (8 bits) | clock cycle in the ROF (4 bits)]
1 parent dac10c0 commit 3e6db16

6 files changed

Lines changed: 76 additions & 10 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 | 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; if the ROF is not a multiple of the clock period, the last cycle is shorter
54+
/// (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
55+
static int computeNClockCycles(int rofLengthInBC, float clockPeriod)
56+
{
57+
return std::ceil(rofLengthInBC * o2::constants::lhc::LHCBunchSpacingNS / clockPeriod - 1e-3); // - 1e-3: tolerance for float rounding
58+
}
59+
int getNClockCyclesPerROF(int layer) const { return computeNClockCycles(getROFLengthInBC(layer), getClockPeriod(layer)); }
60+
61+
/// timestamp [frame | 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 | 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)