Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "Rtypes.h"
#include <climits>
#include <cstdint>
#include <iosfwd>

namespace o2::trkft3
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#define O2_TRK_ALMIRAPARAM_H

#include <algorithm>
#include <cmath>
#include <cstdint>

#include "CommonConstants/LHCConstants.h"
#include "CommonUtils/ConfigurableParam.h"
Expand All @@ -29,18 +31,57 @@ struct AlmiraParam : public o2::conf::ConfigurableParamHelper<AlmiraParam> {
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 (the ROF length is a multiple of the clock period, as required by the ALMIRA design)
static int computeNClockCycles(int rofLengthInBC, float clockPeriod)
{
return std::round(rofLengthInBC * o2::constants::lhc::LHCBunchSpacingNS / clockPeriod);
}

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<int>(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]; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -150,6 +163,9 @@ class DigiParams
// auxiliary precalculated parameters
std::array<float, MaxLayers> mROFrameLayerLengthInv; ///< inverse length of RO frame in ns per layer

std::array<float, MaxLayers> mClockPeriod{}; ///< ALMIRA clock period in ns per layer
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)

// ClassDef(DigiParams, 2);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ void DigiParams<DetIDV>::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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ void Digitizer<DetID>::process(const std::vector<Hit>* 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();
Expand All @@ -138,7 +138,7 @@ void Digitizer<DetID>::process(const std::vector<Hit>* 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<float> 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) {
Expand Down Expand Up @@ -199,8 +199,8 @@ void Digitizer<DetID>::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 << ":"
<< frameLast;
LOG(debug) << "Filling " << mGeometry->getName() << " digits output for RO frames " << mROFrameMin << ":"
<< frameLast;

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

Expand Down Expand Up @@ -229,7 +229,7 @@ void Digitizer<DetID>::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
Expand Down
31 changes: 28 additions & 3 deletions Steer/DigitizerWorkflow/src/TRKDigitizerSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ class TRKFT3DPLDigitizerTask : BaseDPLDigitizer
auto& digitsAccum = pc.outputs().make<std::vector<trkft3::Digit>>(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: if the TF length is not a multiple of the ROF length, the last ROF is truncated by the end of the TF
// (simulation artifact: the handling of ROFs across the TF boundary is still to be defined with DAQ)

mROFRecordsAccum[iLayer].reserve(nROFsTF);

auto accumulate = [this, &digitsAccum, &iLayer]() {
Expand All @@ -159,7 +161,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();
Expand Down Expand Up @@ -288,6 +290,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<int>(firstParLayer + iLayer, o2::trk::AlmiraParam::getNLayers() - 1);
const auto roFrameLengthInBC = aopt.getROFLengthInBC(parLayer);
Expand All @@ -299,6 +305,25 @@ 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 float clockPeriod = digipar.getClockPeriod(iLayer);
if (std::abs(nCycles * clockPeriod - frameNS) > 1e-3f * clockPeriod) { // tolerance for the float comparison only
LOGP(fatal, "{} layer {}: ROF length {} BC ({:.2f} ns) is not a multiple of the clock period ({:.2f} ns), as required by the ALMIRA design",
ID.getName(), iLayer, roFrameLengthInBC, frameNS, clockPeriod);
}

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);
Expand Down
Loading