42 mChips.resize(mNumberOfChips);
43 for (
int i = mNumberOfChips;
i--;) {
44 mChips[
i].setChipIndex(
i);
46 mChips[
i].setNoiseMap(mNoiseMap);
50 mChips[
i].setDeadChanMap(mDeadChanMap);
59 if (doptMFT.Vbb == 0.0) {
60 mAlpSimRespMFT = mAlpSimResp[0];
61 LOG(info) <<
"Choosing Vbb=0V for MFT";
62 }
else if (doptMFT.Vbb == 3.0) {
63 mAlpSimRespMFT = mAlpSimResp[1];
64 LOG(info) <<
"Choosing Vbb=-3V for MFT";
66 LOG(fatal) <<
"Invalid MFT back-bias value";
69 if (doptITS.IBVbb == 0.0) {
70 mAlpSimRespIB = mAlpSimResp[0];
71 LOG(info) <<
"Choosing Vbb=0V for ITS IB";
72 }
else if (doptITS.IBVbb == 3.0) {
73 mAlpSimRespIB = mAlpSimResp[1];
74 LOG(info) <<
"Choosing Vbb=-3V for ITS IB";
76 LOG(fatal) <<
"Invalid ITS Inner Barrel back-bias value";
78 if (doptITS.OBVbb == 0.0) {
79 mAlpSimRespOB = mAlpSimResp[0];
80 LOG(info) <<
"Choosing Vbb=0V for ITS OB";
81 }
else if (doptITS.OBVbb == 3.0) {
82 mAlpSimRespOB = mAlpSimResp[1];
83 LOG(info) <<
"Choosing Vbb=-3V for ITS OB";
85 LOG(fatal) <<
"Invalid ITS Outer Barrel back-bias value";
91 LOG(info) <<
"First IR sampled in digitization is: " << mIRFirstSampledTF;
92 LOG(info) <<
"First IR ns " << mIRFirstSampledTF.
bc2ns();
97 if (mNumberOfChips < 10000) {
98 return mAlpSimRespMFT;
102 return mAlpSimRespIB;
104 return mAlpSimRespOB;
114 LOG(
debug) <<
"Digitizing " << mGeometry->
getName() <<
":" <<
layer <<
" hits of entry " << evID <<
" from source "
115 << srcID <<
" at time " << mEventTime <<
" ROFrame= " << mNewROFrame <<
")"
117 <<
" Min/Max ROFrames " << mROFrameMin <<
"/" << mROFrameMax;
120 if (mNewROFrame > mROFrameMin) {
124 int nHits = hits->size();
125 std::vector<int> hitIdx(nHits);
126 std::iota(std::begin(hitIdx), std::end(hitIdx), 0);
128 std::sort(hitIdx.begin(), hitIdx.end(), [hits](
auto lhs,
auto rhs) {
129 return (*hits)[lhs].GetDetectorID() < (*hits)[rhs].GetDetectorID();
131 for (
int i : hitIdx | std::views::filter([&](
int idx) {
135 return mGeometry->
getLayer((*hits)[idx].GetDetectorID()) ==
layer;
137 processHit((*hits)[
i], mROFrameMax, evID, srcID,
layer);
161 if (mCollisionTimeWrtROF < 0 && nbc > 0) {
170 mIsBeforeFirstRO =
true;
173 mIsBeforeFirstRO =
false;
175 LOG(
debug) <<
" NewROFrame " << mNewROFrame <<
" nbc " << nbc;
183 if (mNewROFrame < mROFrameMin) {
184 LOG(error) <<
"New ROFrame " << mNewROFrame <<
" (" << irt <<
") precedes currently cashed " << mROFrameMin;
185 throw std::runtime_error(
"deduced ROFrame precedes already processed one");
188 if (mParams.
isContinuous() && mROFrameMax < mNewROFrame) {
189 mROFrameMax = mNewROFrame - 1;
197 frameLast = std::min(frameLast, mROFrameMax);
199 getExtraDigBuffer(mROFrameMax);
201 LOG(info) <<
"Filling " << mGeometry->
getName() <<
" digits:" <<
layer <<
" output for RO frames " << mROFrameMin <<
":"
207 for (; mROFrameMin <= frameLast; mROFrameMin++) {
211 auto& extra = *(mExtraBuff.front().get());
212 for (
auto& chip : mChips) {
213 if (chip.isDisabled() || (
layer >= 0 && mGeometry->
getLayer(chip.getChipIndex()) !=
layer)) {
216 chip.addNoise(mROFrameMin, mROFrameMin, &mParams);
217 auto&
buffer = chip.getPreDigits();
221 auto itBeg =
buffer.begin();
223 ULong64_t maxKey = chip.getOrderingKey(mROFrameMin + 1, 0, 0) - 1;
224 for (; iter !=
buffer.end(); ++iter) {
225 if (iter->first > maxKey) {
228 auto& preDig = iter->second;
230 int digID = mDigits->size();
231 mDigits->emplace_back(chip.getChipIndex(), preDig.row, preDig.col, preDig.charge);
232 mMCLabels->
addElement(digID, preDig.labelRef.label);
233 auto& nextRef = preDig.labelRef;
234 while (nextRef.next >= 0) {
235 nextRef = extra[nextRef.next];
240 buffer.erase(itBeg, iter);
250 mROFRecords->push_back(rcROF);
254 mExtraBuff.emplace_back(mExtraBuff.front().release());
255 mExtraBuff.pop_front();
260void Digitizer::processHit(
const o2::itsmft::Hit& hit, uint32_t& maxFr,
int evID,
int srcID,
int lay)
264 auto& chip = mChips[chipID];
265 if (chip.isDisabled()) {
266 LOG(
debug) <<
"skip disabled chip " << chipID;
269 float timeInROF = hit.
GetTime() * sec2ns;
270 if (timeInROF > 20e3) {
271 const int maxWarn = 10;
272 static int warnNo = 0;
273 if (warnNo < maxWarn) {
274 LOG(warning) <<
"Ignoring hit with time_in_event = " << timeInROF <<
" ns"
275 << ((++warnNo < maxWarn) ?
"" :
" (suppressing further warnings)");
280 timeInROF += mCollisionTimeWrtROF;
282 if (mIsBeforeFirstRO && timeInROF < 0) {
296 int nFrames = roFrameRelMax + 1 - roFrameRel;
297 uint32_t roFrameMax = mNewROFrame + roFrameRelMax;
298 maxFr = std::max(roFrameMax, maxFr);
315 int rowS = -1, colS = -1, rowE = -1, colE = -1, nSkip = 0;
318 if (++nSkip >= nSteps) {
325 if (++nSkip >= nSteps) {
332 std::swap(rowS, rowE);
335 std::swap(colS, colE);
339 rowS = std::max(rowS, 0);
345 colS = std::max(colS, 0);
349 int rowSpan = rowE - rowS + 1, colSpan = colE - colS + 1;
351 float respMatrix[rowSpan][colSpan];
352 std::fill(&respMatrix[0][0], &respMatrix[0][0] + rowSpan * colSpan, 0.f);
355 nElectrons *= nStepsInv;
360 int rowPrev = -1, colPrev = -1,
row,
col;
361 float cRowPix = 0.f, cColPix = 0.f;
372 for (
int iStep = nSteps; iStep--;) {
375 if (
row != rowPrev ||
col != colPrev) {
382 bool flipCol =
false, flipRow =
false;
384 auto rspmat = resp->
getResponse(xyzLocS.X() - cRowPix, xyzLocS.Z() - cColPix, xyzLocS.Y(), flipRow, flipCol);
393 if (rowDest < 0 || rowDest >= rowSpan) {
398 if (colDest < 0 || colDest >= colSpan) {
401 respMatrix[rowDest][colDest] += rspmat->getValue(irow, icol, flipRow, flipCol);
408 auto roFrameAbs = mNewROFrame + roFrameRel;
409 for (
int irow = rowSpan; irow--;) {
410 uint16_t rowIS = irow + rowS;
411 for (
int icol = colSpan; icol--;) {
412 float nEleResp = respMatrix[irow][icol];
416 int nEle = gRandom->Poisson(nElectrons * nEleResp);
421 uint16_t colIS = icol + colS;
422 if (mNoiseMap && mNoiseMap->
isNoisy(chipID, rowIS, colIS)) {
425 if (mDeadChanMap && mDeadChanMap->
isNoisy(chipID, rowIS, colIS)) {
429 registerDigits(chip, roFrameAbs, timeInROF, nFrames, rowIS, colIS, nEle, lbl, lay);
435void Digitizer::registerDigits(
ChipDigitsContainer& chip, uint32_t roFrame,
float tInROF,
int nROF,
443 for (
int i = 0;
i < nROF;
i++) {
444 uint32_t roFr = roFrame +
i;
452 mEventROFrameMax = std::max(roFr, mEventROFrameMax);
453 mEventROFrameMin = std::min(roFr, mEventROFrameMin);
463 ExtraDig* extra = getExtraDigBuffer(roFr);
467 if ((*extra)[nxt].
label == lbl) {
471 nxt = (*extra)[nxt].next;
478 extra->emplace_back(lbl);
Definition of the ITS digitizer.
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the SegmentationAlpide class.
math_utils::Point3D< T > GetPos() const
unsigned short GetDetectorID() const
static const DPLDigitizerParam< N > & Instance()
const char * getName() const
const Mat3D & getMatrixL2G(int sensID) const
static int constexpr NPix
float getMaxDuration() const
float getCollectedCharge(float totalNEle, float tMin, float tMax) const
float getDepthMax() const
bool getResponse(float vRow, float vCol, float cDepth, AlpideRespSimMat &dest) const
Container for similated points connected to a given chip.
void addDigit(ULong64_t key, UInt_t roframe, UShort_t row, UShort_t col, int charge, o2::MCCompLabel lbl)
o2::itsmft::PreDigit * findDigit(ULong64_t key)
static ULong64_t getOrderingKey(UInt_t roframe, UShort_t row, UShort_t col)
Get global ordering key made of readout frame, column and row.
int getMinChargeToAccount() const
float getStrobeDelay(int layer=-1) const
virtual void print() const
float getROFrameLengthInv(int layer=-1) const
const SignalShape & getSignalShape() const
float getStrobeLength(int layer=-1) const
float getEnergyToNElectrons() const
int getROFrameLengthInBC(int layer=-1) const
bool isContinuous() const
int getChargeThreshold() const
float getNSimStepsInv() const
float getROFrameLength(int layer=-1) const
void fillOutputContainer(uint32_t maxFrame=0xffffffff, int layer=-1)
auto getChipResponse(int chipID)
bool isContinuous() const
void setEventTime(const o2::InteractionTimeRecord &irt, int layer=-1)
void process(const std::vector< Hit > *hits, int evID, int srcID, int layer=-1)
Steer conversion of hits to digits.
virtual Int_t getLayer(Int_t index) const
Int_t getNumberOfChips() const
math_utils::Point3D< Float_t > GetPosStart() const
bool isFullChipMasked(int chip) const
bool isNoisy(int chip, int row, int col) const
const BCData & getBCData() const
void setFirstEntry(int idx)
int getFirstEntry() const
void setROFrame(ROFtype rof)
static constexpr float SensorLayerThickness
static bool localToDetector(float x, float z, int &iRow, int &iCol)
static constexpr int NRows
static constexpr int NCols
static bool detectorToLocal(L row, L col, T &xRow, T &zCol)
GLuint GLsizei const GLchar * label
GLenum GLuint GLint GLint layer
constexpr double LHCBunchSpacingNS
static double bc2ns(int bc, unsigned int orbit)
int64_t differenceInBC(const InteractionRecord &other) const
void setFromLong(int64_t l)
double timeInBCNS
time in NANOSECONDS relative to orbit/bc
int next
eventual next contribution to the same pixel
o2::MCCompLabel label
hit label
PreDigitLabelRef labelRef
label and reference to the next one
IR getFirstSampledTFIR() const
get TF and HB (abs) for this IR
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"