27#include <fairlogger/Logger.h>
37 const int numberOfChips = mGeometry->
getSize();
38 mChips.resize(numberOfChips);
39 for (
int i = numberOfChips;
i--;) {
40 mChips[
i].setChipIndex(
i);
53 LOG(info) <<
"Initializing IOTOF digitizer";
54 LOG(info) <<
" Time resolution: " << mTimeResolution * 1e3 <<
" ps";
55 LOG(info) <<
" Charge threshold: " << mChargeThreshold <<
" electrons";
56 LOG(info) <<
" Detection efficiency: " << mEfficiency * 100 <<
" %";
57 LOG(info) <<
" Continuous mode: " << (mContinuous ?
"ON" :
"OFF");
58 sSegmentation = o2::iotof::Segmentation::Instance();
65 LOG(
debug) <<
"Digitizing IOTOF hits: " << hits->size() <<
" hits from event " << evID <<
" source " << srcID;
67 if (!hits || hits->empty()) {
72 std::vector<int> hitIdx(hits->size());
73 std::iota(hitIdx.begin(), hitIdx.end(), 0);
74 std::sort(hitIdx.begin(), hitIdx.end(),
75 [hits](
int lhs,
int rhs) {
76 return (*hits)[lhs].GetDetectorID() < (*hits)[rhs].GetDetectorID();
80 for (
int i : hitIdx) {
81 processHit((*hits)[
i], evID, srcID);
86 LOG(
debug) <<
"Inner flushing for non-continuous mode";
92void Digitizer::processHit(
const o2::itsmft::Hit& hit,
int evID,
int srcID)
98 LOG(
debug) <<
"Hit rejected by efficiency cut";
104 auto& chip = mChips[chipID];
105 if (chip.isDisabled()) {
106 LOG(
debug) <<
"Hit rejected because chip " << chipID <<
" is disabled";
112 int charge = energyToCharge(energyLoss);
115 if (
charge < mChargeThreshold) {
116 LOG(
debug) <<
"Hit rejected by charge threshold: " <<
charge <<
" < " << mChargeThreshold;
122 double hitTime = hit.
GetTime() * sec2ns;
123 double eventTimeNS = mEventTime.
getTimeNS();
124 double absoluteTime = hitTime + eventTimeNS;
125 double smearedTime = smearTime(absoluteTime);
127 if (chipID < 0 || chipID >= mGeometry->
getSize() || mGeometry->
getSize() < 1) {
128 LOG(
debug) <<
"Invalid detector ID: " << chipID <<
", geometry size: " << mGeometry->
getSize();
133 math_utils::Vector3D<float> xyzPositionStart(matrix ^ (hit.
GetPosStart()));
140 LOG(
debug) <<
"Hit position out of bounds for detector ID " << chipID;
146 const int roFrameAbs = 0;
149 registerDigits(chip, roFrameAbs, smearedTime, nROF,
static_cast<uint16_t
>(
row),
static_cast<uint16_t
>(
col),
charge,
label);
153double Digitizer::smearTime(
double time)
const
156 if (mTimeResolution > 0) {
157 return time + gRandom->Gaus(0, mTimeResolution);
163int Digitizer::energyToCharge(
float energyLoss)
const
168 return static_cast<int>(energyLoss / mEnergyToCharge);
172bool Digitizer::isEfficient()
const
175 return gRandom->Uniform() < mEfficiency;
181 LOG(info) <<
"Filling output container with digits from chips";
182 LOG(
debug) <<
"Number of chips: " << mChips.size();
187 const auto* extraLabelBuffer = mExtraLabelBuffer.empty() ? nullptr : mExtraLabelBuffer.front().get();
188 for (
auto& chip : mChips) {
190 if (chip.isDisabled()) {
196 if (chip.isEmpty()) {
200 auto& chipDigits = chip.getDigits();
201 for (
const auto& [
key, digit] : chipDigits) {
208 int digitID = mDigits->size();
209 mDigits->emplace_back(digit.getChipIndex(), digit.getRow(), digit.getColumn(), digit.getCharge(), digit.getTime());
211 mMCLabels->
addElement(digitID, digit.getLabel().mLabel);
213 auto labelRef = digit.getLabel();
215 while (mMCLabels && extraLabelBuffer !=
nullptr && labelRef.mNext >= 0) {
216 labelRef = (*extraLabelBuffer)[labelRef.mNext];
217 mMCLabels->
addElement(digitID, labelRef.mLabel);
224 rof.
setBCData(mContinuous ? mROFRecordIR : mEventTime);
225 mROFRecords->push_back(rof);
226 LOG(
debug) <<
"Created ROF record with " << mDigits->size() <<
" digits";
233void Digitizer::registerDigits(
Chip& chip, uint32_t roFrame,
double time,
int nROF,
240 if (!existingDigit) {
245 const int storedCharge = existingDigit->
getCharge();
246 existingDigit->
setCharge(storedCharge + nElectrons);
251 std::vector<o2::iotof::McLabelRef>* extra = getExtraLabelBuffer(roFrame);
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;
Definition of the ALICE3 TOF digitizer.
unsigned short GetDetectorID() const
const Mat3D & getMatrixL2G(int sensID) const
Container for similated points connected to a given TOF Chip This will be used in order to allow a mo...
o2::iotof::LabeledDigit * findDigit(ULong64_t key)
reset points container
void addDigit(UShort_t row, UShort_t col, Int_t charge, double time, o2::MCCompLabel label)
Int_t getChipIndex() const
void setTime(double time)
static UInt_t getOrderingKey(UShort_t chipindex, UShort_t row, UShort_t col)
void init()
Initialize the digitizer.
void fillOutputContainer()
Flush the output container.
void process(const std::vector< o2::itsmft::Hit > *hits, int evID, int srcID)
Steer conversion of hits to digits.
int getIOTOFLayer(int index) const
McLabelRef getLabel() const
void setLabel(McLabelRef label)
bool localToDetector(float x, float z, int &iRow, int &iCol, const int subDetectorID)
void setCharge(Int_t charge)
Set the charge of the digit.
Int_t getCharge() const
Get the accumulated charged of the digit.
math_utils::Point3D< Float_t > GetPosStart() const
void setBCData(const BCData &bc)
void setFirstEntry(int idx)
int getFirstEntry() const
GLuint GLsizei const GLchar * label
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
double getTimeNS() const
get time in ns from orbit=0/bc=0
int mNext
eventual next contribution to the same pixel
o2::MCCompLabel mLabel
hit label
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"