38 mChips.resize(numOfChips);
39 for (
int i = numOfChips;
i--;) {
40 mChips[
i].setChipIndex(
i);
41 if (mDeadChanMap !=
nullptr) {
43 mChips[
i].setDeadChanMap(mDeadChanMap);
48 std::string responseFile =
"$(O2_ROOT)/share/Detectors/ITSMFT/data/AlpideResponseData/AlpideResponseData.root";
49 LOGP(info,
"Loading AlpideSimRespnse from file: {}", responseFile);
50 auto file = TFile::Open(responseFile.data());
62 LOG(info) <<
"Digitizing " << mGeometry->
getName() <<
" hits of entry " << evID <<
" from source "
63 << srcID <<
" at time " << mEventTime <<
" ROFrame = " << mNewROFrame <<
")"
65 <<
" Min/Max ROFrames " << mROFrameMin <<
"/" << mROFrameMax;
68 if (mNewROFrame > mROFrameMin) {
72 int nHits = hits->size();
73 std::vector<int> hitIdx(nHits);
74 std::iota(std::begin(hitIdx), std::end(hitIdx), 0);
76 std::sort(hitIdx.begin(), hitIdx.end(),
77 [hits](
auto lhs,
auto rhs) {
78 return (*hits)[lhs].GetDetectorID() < (*hits)[rhs].GetDetectorID();
80 for (
int i : hitIdx) {
81 processHit((*hits)[
i], mROFrameMax, evID, srcID);
103 if (mCollisionTimeWrtROF < 0 && nbc > 0) {
113 if (mNewROFrame < mROFrameMin) {
114 LOG(error) <<
"New ROFrame " << mNewROFrame <<
" (" << irt <<
") precedes currently cashed " << mROFrameMin;
115 throw std::runtime_error(
"deduced ROFrame precedes already processed one");
118 if (mParams.
isContinuous() && mROFrameMax < mNewROFrame) {
119 mROFrameMax = mNewROFrame - 1;
126 if (frameLast > mROFrameMax) {
127 frameLast = mROFrameMax;
130 getExtraDigBuffer(mROFrameMax);
132 LOG(info) <<
"Filling " << mGeometry->
getName() <<
" digits output for RO frames " << mROFrameMin <<
":"
138 for (; mROFrameMin <= frameLast; mROFrameMin++) {
142 auto& extra = *(mExtraBuff.front().get());
143 for (
size_t iChip{0}; iChip < mChips.size(); ++iChip) {
144 auto& chip = mChips[iChip];
148 chip.addNoise(mROFrameMin, mROFrameMin, &mParams);
150 auto&
buffer = chip.getPreDigits();
154 auto itBeg =
buffer.begin();
156 ULong64_t maxKey = chip.getOrderingKey(mROFrameMin + 1, 0, 0) - 1;
157 for (; iter !=
buffer.end(); ++iter) {
158 if (iter->first > maxKey) {
161 auto& preDig = iter->second;
163 int digID = mDigits->size();
164 mDigits->emplace_back(chip.getChipIndex(), preDig.row, preDig.col, preDig.charge);
165 mMCLabels->
addElement(digID, preDig.labelRef.label);
166 auto& nextRef = preDig.labelRef;
167 while (nextRef.next >= 0) {
168 nextRef = extra[nextRef.next];
173 buffer.erase(itBeg, iter);
182 if (mROFRecords !=
nullptr) {
183 mROFRecords->push_back(rcROF);
187 mExtraBuff.emplace_back(mExtraBuff.front().release());
188 mExtraBuff.pop_front();
192void Digitizer::processHit(
const o2::itsmft::Hit& hit, uint32_t& maxFr,
int evID,
int srcID)
196 auto& chip = mChips[chipID];
197 if (chip.isDisabled()) {
200 float timeInROF = hit.
GetTime() * sec2ns;
201 if (timeInROF > 20e3) {
202 const int maxWarn = 10;
203 static int warnNo = 0;
204 if (warnNo < maxWarn) {
205 LOG(warning) <<
"Ignoring hit with time_in_event = " << timeInROF <<
" ns"
206 << ((++warnNo < maxWarn) ?
"" :
" (suppressing further warnings)");
211 timeInROF += mCollisionTimeWrtROF;
222 int nFrames = roFrameRelMax + 1 - roFrameRel;
223 uint32_t roFrameMax = mNewROFrame + roFrameRelMax;
224 if (roFrameMax > maxFr) {
234 bool innerBarrel{
layer < 3};
237 xyzLocE = matrix ^ (hit.
GetPos());
240 float xFlatE{0.f}, yFlatE{0.f}, xFlatS{0.f}, yFlatS{0.f};
244 xyzLocS.SetXYZ(xFlatS, yFlatS, xyzLocS.Z());
245 xyzLocE.SetXYZ(xFlatE, yFlatE, xyzLocE.Z());
255 int rowS = -1, colS = -1, rowE = -1, colE = -1, nSkip = 0;
259 if (++nSkip >= nSteps) {
266 if (++nSkip >= nSteps) {
274 if (++nSkip >= nSteps) {
281 if (++nSkip >= nSteps) {
290 std::swap(rowS, rowE);
293 std::swap(colS, colE);
295 rowS -= AlpideRespSimMat::NPix / 2;
296 rowE += AlpideRespSimMat::NPix / 2;
303 if (rowE >= maxNrows) {
306 colS -= AlpideRespSimMat::NPix / 2;
307 colE += AlpideRespSimMat::NPix / 2;
311 if (colE >= maxNcols) {
314 int rowSpan = rowE - rowS + 1, colSpan = colE - colS + 1;
315 float respMatrix[rowSpan][colSpan];
316 std::fill(&respMatrix[0][0], &respMatrix[0][0] + rowSpan * colSpan, 0.f);
319 nElectrons *= nStepsInv;
324 int rowPrev = -1, colPrev = -1,
row,
col;
325 float cRowPix = 0.f, cColPix = 0.f;
331 xyzLocS.SetY(xyzLocS.Y() + mAlpSimResp->
getDepthMax() - thickness / 2.);
333 for (
int iStep = nSteps; iStep--;) {
340 if (
row != rowPrev ||
col != colPrev) {
351 bool flipCol =
false, flipRow =
false;
355 auto rspmat = mAlpSimResp->
getResponse(xyzLocS.X() - cRowPix, xyzLocS.Z() - cColPix, xyzLocS.Y(), flipRow, flipCol, rowMax, colMax);
358 if (rspmat ==
nullptr) {
362 for (
int irow = AlpideRespSimMat::NPix; irow--;) {
363 int rowDest =
row + irow - AlpideRespSimMat::NPix / 2 - rowS;
364 if (rowDest < 0 || rowDest >= rowSpan) {
367 for (
int icol = AlpideRespSimMat::NPix; icol--;) {
368 int colDest =
col + icol - AlpideRespSimMat::NPix / 2 - colS;
369 if (colDest < 0 || colDest >= colSpan) {
372 respMatrix[rowDest][colDest] += rspmat->getValue(irow, icol, flipRow, flipCol);
379 auto roFrameAbs = mNewROFrame + roFrameRel;
380 for (
int irow = rowSpan; irow--;) {
381 uint16_t rowIS = irow + rowS;
382 for (
int icol = colSpan; icol--;) {
383 float nEleResp = respMatrix[irow][icol];
384 if (nEleResp <= 1.e-36) {
387 int nEle = gRandom->Poisson(nElectrons * nEleResp);
392 uint16_t colIS = icol + colS;
393 registerDigits(chip, roFrameAbs, timeInROF, nFrames, rowIS, colIS, nEle, lbl);
406 for (
int i = 0;
i < nROF;
i++) {
407 uint32_t roFr = roFrame +
i;
415 if (roFr > mEventROFrameMax) {
416 mEventROFrameMax = roFr;
418 if (roFr < mEventROFrameMin) {
419 mEventROFrameMin = roFr;
430 ExtraDig* extra = getExtraDigBuffer(roFr);
434 if ((*extra)[nxt].
label == lbl) {
438 nxt = (*extra)[nxt].next;
445 extra->emplace_back(lbl);
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the SegmentationAlpide class.
Definition of the ITS digitizer.
math_utils::Point3D< T > GetPos() const
short GetDetectorID() const
static const HBFUtils & Instance()
const char * getName() const
const Mat3D & getMatrixL2G(int sensID) const
bool isContinuous() const
void setEventTime(const o2::InteractionTimeRecord &irt)
void process(const std::vector< itsmft::Hit > *hits, int evID, int srcID)
Steer conversion of hits to digits.
void fillOutputContainer(uint32_t maxFrame=0xffffffff)
Segmentation and response for pixels in ITS3 upgrade.
static constexpr int mNRows
static constexpr float mPitchRow
static constexpr int mNCols
static constexpr float mSensorLayerThickness
static constexpr float mPitchCol
int getLayer(int index) const
Get chip layer, from 0.
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
void setAlpSimResponse(const o2::itsmft::AlpideSimResponse *par)
const o2::itsmft::AlpideSimResponse * getAlpSimResponse() 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
Int_t getNumberOfChips() const
math_utils::Point3D< Float_t > GetPosStart() const
bool isFullChipMasked(int chip) 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 float PitchCol
static constexpr int NRows
static constexpr int NCols
static constexpr float PitchRow
static bool detectorToLocal(L row, L col, T &xRow, T &zCol)
GLuint GLsizei const GLchar * label
GLenum GLuint GLint GLint layer
constexpr double LHCBunchSpacingNS
constexpr float thickness
const std::array< SegmentationSuperAlpide, constants::nLayers > SuperSegmentations
Segmentation array.
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"