27#include <fairlogger/Logger.h>
40 mChips.resize(mNumberOfChips);
41 for (
int i = mNumberOfChips;
i--;) {
42 mChips[
i].setChipIndex(
i);
44 mChips[
i].setNoiseMap(mNoiseMap);
48 mChips[
i].setDeadChanMap(mDeadChanMap);
57 if (doptMFT.Vbb == 0.0) {
58 mAlpSimRespMFT = mAlpSimResp[0];
59 LOG(info) <<
"Choosing Vbb=0V for MFT";
60 }
else if (doptMFT.Vbb == 3.0) {
61 mAlpSimRespMFT = mAlpSimResp[1];
62 LOG(info) <<
"Choosing Vbb=-3V for MFT";
64 LOG(fatal) <<
"Invalid MFT back-bias value";
67 if (doptITS.IBVbb == 0.0) {
68 mAlpSimRespIB = mAlpSimResp[0];
69 LOG(info) <<
"Choosing Vbb=0V for ITS IB";
70 }
else if (doptITS.IBVbb == 3.0) {
71 mAlpSimRespIB = mAlpSimResp[1];
72 LOG(info) <<
"Choosing Vbb=-3V for ITS IB";
74 LOG(fatal) <<
"Invalid ITS Inner Barrel back-bias value";
76 if (doptITS.OBVbb == 0.0) {
77 mAlpSimRespOB = mAlpSimResp[0];
78 LOG(info) <<
"Choosing Vbb=0V for ITS OB";
79 }
else if (doptITS.OBVbb == 3.0) {
80 mAlpSimRespOB = mAlpSimResp[1];
81 LOG(info) <<
"Choosing Vbb=-3V for ITS OB";
83 LOG(fatal) <<
"Invalid ITS Outter Barrel back-bias value";
89 LOG(info) <<
"First IR sampled in digitization is: " << mIRFirstSampledTF;
90 LOG(info) <<
"First IR ns " << mIRFirstSampledTF.
bc2ns();
95 if (mNumberOfChips < 10000) {
96 return mAlpSimRespMFT;
100 return mAlpSimRespIB;
102 return mAlpSimRespOB;
111 LOG(info) <<
"Digitizing " << mGeometry->
getName() <<
" hits of entry " << evID <<
" from source "
112 << srcID <<
" at time " << mEventTime <<
" ROFrame= " << mNewROFrame <<
")"
114 <<
" Min/Max ROFrames " << mROFrameMin <<
"/" << mROFrameMax;
117 if (mNewROFrame > mROFrameMin) {
121 int nHits = hits->size();
122 std::vector<int> hitIdx(nHits);
123 std::iota(std::begin(hitIdx), std::end(hitIdx), 0);
125 std::sort(hitIdx.begin(), hitIdx.end(),
126 [hits](
auto lhs,
auto rhs) {
127 return (*hits)[lhs].GetDetectorID() < (*hits)[rhs].GetDetectorID();
129 for (
int i : hitIdx) {
130 processHit((*hits)[
i], mROFrameMax, evID, srcID);
153 if (mCollisionTimeWrtROF < 0 && nbc > 0) {
162 mIsBeforeFirstRO =
true;
165 mIsBeforeFirstRO =
false;
167 LOG(info) <<
" NewROFrame " << mNewROFrame <<
" nbc " << nbc;
175 if (mNewROFrame < mROFrameMin) {
176 LOG(error) <<
"New ROFrame " << mNewROFrame <<
" (" << irt <<
") precedes currently cashed " << mROFrameMin;
177 throw std::runtime_error(
"deduced ROFrame precedes already processed one");
180 if (mParams.
isContinuous() && mROFrameMax < mNewROFrame) {
181 mROFrameMax = mNewROFrame - 1;
189 if (frameLast > mROFrameMax) {
190 frameLast = mROFrameMax;
193 getExtraDigBuffer(mROFrameMax);
195 LOG(info) <<
"Filling " << mGeometry->
getName() <<
" digits output for RO frames " << mROFrameMin <<
":"
201 for (; mROFrameMin <= frameLast; mROFrameMin++) {
205 auto& extra = *(mExtraBuff.front().get());
206 for (
auto& chip : mChips) {
207 if (chip.isDisabled()) {
210 chip.addNoise(mROFrameMin, mROFrameMin, &mParams);
211 auto&
buffer = chip.getPreDigits();
215 auto itBeg =
buffer.begin();
217 ULong64_t maxKey = chip.getOrderingKey(mROFrameMin + 1, 0, 0) - 1;
218 for (; iter !=
buffer.end(); ++iter) {
219 if (iter->first > maxKey) {
222 auto& preDig = iter->second;
224 int digID = mDigits->size();
225 mDigits->emplace_back(chip.getChipIndex(), preDig.row, preDig.col, preDig.charge);
226 mMCLabels->
addElement(digID, preDig.labelRef.label);
227 auto& nextRef = preDig.labelRef;
228 while (nextRef.next >= 0) {
229 nextRef = extra[nextRef.next];
234 buffer.erase(itBeg, iter);
244 mROFRecords->push_back(rcROF);
248 mExtraBuff.emplace_back(mExtraBuff.front().release());
249 mExtraBuff.pop_front();
254void Digitizer::processHit(
const o2::itsmft::Hit& hit, uint32_t& maxFr,
int evID,
int srcID)
258 auto& chip = mChips[chipID];
259 if (chip.isDisabled()) {
260 LOG(
debug) <<
"skip disabled chip " << chipID;
263 float timeInROF = hit.
GetTime() * sec2ns;
264 if (timeInROF > 20e3) {
265 const int maxWarn = 10;
266 static int warnNo = 0;
267 if (warnNo < maxWarn) {
268 LOG(warning) <<
"Ignoring hit with time_in_event = " << timeInROF <<
" ns"
269 << ((++warnNo < maxWarn) ?
"" :
" (suppressing further warnings)");
274 timeInROF += mCollisionTimeWrtROF;
276 if (mIsBeforeFirstRO && timeInROF < 0) {
290 int nFrames = roFrameRelMax + 1 - roFrameRel;
291 uint32_t roFrameMax = mNewROFrame + roFrameRelMax;
292 if (roFrameMax > maxFr) {
311 int rowS = -1, colS = -1, rowE = -1, colE = -1, nSkip = 0;
314 if (++nSkip >= nSteps) {
321 if (++nSkip >= nSteps) {
328 std::swap(rowS, rowE);
331 std::swap(colS, colE);
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, flipRow;
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);
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 if (roFr > mEventROFrameMax) {
453 mEventROFrameMax = roFr;
455 if (roFr < mEventROFrameMin) {
456 mEventROFrameMin = roFr;
467 ExtraDig* extra = getExtraDigBuffer(roFr);
471 if ((*extra)[nxt].
label == lbl) {
475 nxt = (*extra)[nxt].next;
482 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 getROFrameLengthInv() const
virtual void print() const
const SignalShape & getSignalShape() const
float getEnergyToNElectrons() const
int getROFrameLengthInBC() const
float getStrobeDelay() const
bool isContinuous() const
int getChargeThreshold() const
float getNSimStepsInv() const
float getROFrameLength() const
float getStrobeLength() const
void setEventTime(const o2::InteractionTimeRecord &irt)
auto getChipResponse(int chipID)
bool isContinuous() const
void process(const std::vector< Hit > *hits, int evID, int srcID)
Steer conversion of hits to digits.
void fillOutputContainer(uint32_t maxFrame=0xffffffff)
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
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"