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);
58 auto file = TFile::Open(mResponseFile.data());
60 LOG(fatal) <<
"Cannot open response file " << mResponseFile;
75 if (doptMFT.Vbb == 0.0) {
76 mAlpSimRespMFT = mAlpSimResp;
77 LOG(info) <<
"Choosing Vbb=0V for MFT";
78 }
else if (doptMFT.Vbb == 3.0) {
79 mAlpSimRespMFT = mAlpSimResp + 1;
80 LOG(info) <<
"Choosing Vbb=-3V for MFT";
82 LOG(fatal) <<
"Invalid MFT back-bias value";
85 if (doptITS.IBVbb == 0.0) {
86 mAlpSimRespIB = mAlpSimResp;
87 LOG(info) <<
"Choosing Vbb=0V for ITS IB";
88 }
else if (doptITS.IBVbb == 3.0) {
89 mAlpSimRespIB = mAlpSimResp + 1;
90 LOG(info) <<
"Choosing Vbb=-3V for ITS IB";
92 LOG(fatal) <<
"Invalid ITS Inner Barrel back-bias value";
94 if (doptITS.OBVbb == 0.0) {
95 mAlpSimRespOB = mAlpSimResp;
96 LOG(info) <<
"Choosing Vbb=0V for ITS OB";
97 }
else if (doptITS.OBVbb == 3.0) {
98 mAlpSimRespOB = mAlpSimResp + 1;
99 LOG(info) <<
"Choosing Vbb=-3V for ITS OB";
101 LOG(fatal) <<
"Invalid ITS Outter Barrel back-bias value";
107 LOG(info) <<
"First IR sampled in digitization is: " << mIRFirstSampledTF;
108 LOG(info) <<
"First IR ns " << mIRFirstSampledTF.
bc2ns();
113 if (mNumberOfChips < 10000) {
114 return mAlpSimRespMFT;
118 return mAlpSimRespIB;
120 return mAlpSimRespOB;
129 LOG(info) <<
"Digitizing " << mGeometry->
getName() <<
" hits of entry " << evID <<
" from source "
130 << srcID <<
" at time " << mEventTime <<
" ROFrame= " << mNewROFrame <<
")"
132 <<
" Min/Max ROFrames " << mROFrameMin <<
"/" << mROFrameMax;
135 if (mNewROFrame > mROFrameMin) {
139 int nHits = hits->size();
140 std::vector<int> hitIdx(nHits);
141 std::iota(std::begin(hitIdx), std::end(hitIdx), 0);
143 std::sort(hitIdx.begin(), hitIdx.end(),
144 [hits](
auto lhs,
auto rhs) {
145 return (*hits)[lhs].GetDetectorID() < (*hits)[rhs].GetDetectorID();
147 for (
int i : hitIdx) {
148 processHit((*hits)[
i], mROFrameMax, evID, srcID);
171 if (mCollisionTimeWrtROF < 0 && nbc > 0) {
180 mIsBeforeFirstRO =
true;
183 mIsBeforeFirstRO =
false;
185 LOG(info) <<
" NewROFrame " << mNewROFrame <<
" nbc " << nbc;
193 if (mNewROFrame < mROFrameMin) {
194 LOG(error) <<
"New ROFrame " << mNewROFrame <<
" (" << irt <<
") precedes currently cashed " << mROFrameMin;
195 throw std::runtime_error(
"deduced ROFrame precedes already processed one");
198 if (mParams.
isContinuous() && mROFrameMax < mNewROFrame) {
199 mROFrameMax = mNewROFrame - 1;
207 if (frameLast > mROFrameMax) {
208 frameLast = mROFrameMax;
211 getExtraDigBuffer(mROFrameMax);
213 LOG(info) <<
"Filling " << mGeometry->
getName() <<
" digits output for RO frames " << mROFrameMin <<
":"
219 for (; mROFrameMin <= frameLast; mROFrameMin++) {
223 auto& extra = *(mExtraBuff.front().get());
224 for (
auto& chip : mChips) {
225 if (chip.isDisabled()) {
228 chip.addNoise(mROFrameMin, mROFrameMin, &mParams);
229 auto&
buffer = chip.getPreDigits();
233 auto itBeg =
buffer.begin();
235 ULong64_t maxKey = chip.getOrderingKey(mROFrameMin + 1, 0, 0) - 1;
236 for (; iter !=
buffer.end(); ++iter) {
237 if (iter->first > maxKey) {
240 auto& preDig = iter->second;
242 int digID = mDigits->size();
243 mDigits->emplace_back(chip.getChipIndex(), preDig.row, preDig.col, preDig.charge);
244 mMCLabels->
addElement(digID, preDig.labelRef.label);
245 auto& nextRef = preDig.labelRef;
246 while (nextRef.next >= 0) {
247 nextRef = extra[nextRef.next];
252 buffer.erase(itBeg, iter);
262 mROFRecords->push_back(rcROF);
266 mExtraBuff.emplace_back(mExtraBuff.front().release());
267 mExtraBuff.pop_front();
272void Digitizer::processHit(
const o2::itsmft::Hit& hit, uint32_t& maxFr,
int evID,
int srcID)
276 auto& chip = mChips[chipID];
277 if (chip.isDisabled()) {
278 LOG(
debug) <<
"skip disabled chip " << chipID;
281 float timeInROF = hit.
GetTime() * sec2ns;
282 if (timeInROF > 20e3) {
283 const int maxWarn = 10;
284 static int warnNo = 0;
285 if (warnNo < maxWarn) {
286 LOG(warning) <<
"Ignoring hit with time_in_event = " << timeInROF <<
" ns"
287 << ((++warnNo < maxWarn) ?
"" :
" (suppressing further warnings)");
292 timeInROF += mCollisionTimeWrtROF;
294 if (mIsBeforeFirstRO && timeInROF < 0) {
308 int nFrames = roFrameRelMax + 1 - roFrameRel;
309 uint32_t roFrameMax = mNewROFrame + roFrameRelMax;
310 if (roFrameMax > maxFr) {
329 int rowS = -1, colS = -1, rowE = -1, colE = -1, nSkip = 0;
332 if (++nSkip >= nSteps) {
339 if (++nSkip >= nSteps) {
346 std::swap(rowS, rowE);
349 std::swap(colS, colE);
367 int rowSpan = rowE - rowS + 1, colSpan = colE - colS + 1;
369 float respMatrix[rowSpan][colSpan];
370 std::fill(&respMatrix[0][0], &respMatrix[0][0] + rowSpan * colSpan, 0.f);
373 nElectrons *= nStepsInv;
378 int rowPrev = -1, colPrev = -1,
row,
col;
379 float cRowPix = 0.f, cColPix = 0.f;
390 for (
int iStep = nSteps; iStep--;) {
393 if (
row != rowPrev ||
col != colPrev) {
400 bool flipCol, flipRow;
402 auto rspmat = resp->
getResponse(xyzLocS.X() - cRowPix, xyzLocS.Z() - cColPix, xyzLocS.Y(), flipRow, flipCol);
411 if (rowDest < 0 || rowDest >= rowSpan) {
416 if (colDest < 0 || colDest >= colSpan) {
419 respMatrix[rowDest][colDest] += rspmat->getValue(irow, icol, flipRow, flipCol);
426 auto roFrameAbs = mNewROFrame + roFrameRel;
427 for (
int irow = rowSpan; irow--;) {
428 uint16_t rowIS = irow + rowS;
429 for (
int icol = colSpan; icol--;) {
430 float nEleResp = respMatrix[irow][icol];
434 int nEle = gRandom->Poisson(nElectrons * nEleResp);
439 uint16_t colIS = icol + colS;
440 if (mNoiseMap && mNoiseMap->
isNoisy(chipID, rowIS, colIS)) {
443 if (mDeadChanMap && mDeadChanMap->
isNoisy(chipID, rowIS, colIS)) {
447 registerDigits(chip, roFrameAbs, timeInROF, nFrames, rowIS, colIS, nEle, lbl);
453void Digitizer::registerDigits(
ChipDigitsContainer& chip, uint32_t roFrame,
float tInROF,
int nROF,
461 for (
int i = 0;
i < nROF;
i++) {
462 uint32_t roFr = roFrame +
i;
470 if (roFr > mEventROFrameMax) {
471 mEventROFrameMax = roFr;
473 if (roFr < mEventROFrameMin) {
474 mEventROFrameMin = roFr;
485 ExtraDig* extra = getExtraDigBuffer(roFr);
489 if ((*extra)[nxt].
label == lbl) {
493 nxt = (*extra)[nxt].next;
500 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
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
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
auto getChipResponse(int chipID)
void setEventTime(const o2::InteractionTimeRecord &irt)
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"