Project
Loading...
Searching...
No Matches
Digitizer.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
16#include "TRKBase/Specs.h"
19
20#include <TRandom.h>
21// #include <climits>
22#include <vector>
23#include <iostream>
24#include <numeric>
25#include <ranges>
26#include <fairlogger/Logger.h> // for LOG
27
29using o2::trkft3::Hit;
31
32using namespace o2::trkft3;
33using namespace o2::itsmft;
34// using namespace o2::base;
35//_______________________________________________________________________
36template <int DetID>
38{
39 LOG(info) << "Initializing digitizer";
40 mNumberOfChips = mGeometry->getNumberOfChips();
41 mChips.resize(mNumberOfChips);
42 for (int i = mNumberOfChips; i--;) {
43 mChips[i].setChipIndex(i);
44 if (mNoiseMap) {
45 mChips[i].setNoiseMap(mNoiseMap);
46 }
47 if (mDeadChanMap) {
48 mChips[i].disable(mDeadChanMap->isFullChipMasked(i));
49 mChips[i].setDeadChanMap(mDeadChanMap);
50 }
51 }
52
53 // setting the correct response function (for the moment, for both VD and MLOT the same response function is used)
54 mChipSimResp = mParams.getResponse();
55 mChipSimRespVD = mChipSimResp;
56 mChipSimRespMLOT = mChipSimResp;
57
59 // TODO: adjust Y shift when the geometry is improved
60 LOG(info) << " Depth max VD: " << mChipSimRespVD->getDepthMax();
61 LOG(info) << " Depth min VD: " << mChipSimRespVD->getDepthMin();
62
63 LOG(info) << " Depth max MLOT: " << mChipSimRespMLOT->getDepthMax();
64 LOG(info) << " Depth min MLOT: " << mChipSimRespMLOT->getDepthMin();
65
66 float thicknessVD = 0.0095; // cm --- hardcoded based on geometry currently present
67 float thicknessMLOT = o2::trk::SegmentationChip::SiliconThicknessMLOT; // 0.01 cm = 100 um --- based on geometry currently present
68
69 LOG(info) << "Using response name: " << mRespName;
70 mSimRespOrientation = false;
71
72 if (mRespName == "APTS") { // default
75 mSimRespVDShift = mChipSimRespVD->getDepthMax(); // the curved, rescaled, sensors have a width from 0 to -45. Must add ~10 um (= max depth) to match the APTS response.
78 mSimRespOrientation = true;
79 } else if (mRespName == "ALICE3") {
82 mSimRespVDShift = mChipSimRespVD->getDepthMax(); // the curved, rescaled, sensors have a width from 0 to -95 um. Must align the start of epi layer with the response function.
85 } else {
86 LOG(fatal) << "Unknown response name: " << mRespName;
87 }
88
89 mSimRespMLOTShift = mChipSimRespMLOT->getDepthMax() - thicknessMLOT / 2.f; // the shift should be done considering the rescaling done to adapt to the wrong silicon thickness. TODO: remove the scaling factor for the depth when the silicon thickness match the simulated response
90
91 LOGP(info, "{} Digitizer is initialised.", o2::detectors::DetID::getName(DetID));
92 mParams.print();
93 LOGP(info, "VD shift = {} ; ML/OT shift = {} = {} - {}", mSimRespVDShift, mSimRespMLOTShift, mChipSimRespMLOT->getDepthMax(), thicknessMLOT / 2.f);
94 LOGP(info, "VD pixel scale on x = {} ; z = {}", mSimRespVDScaleX, mSimRespVDScaleZ);
95 LOGP(info, "ML/OT pixel scale on x = {} ; z = {}", mSimRespMLOTScaleX, mSimRespMLOTScaleZ);
96 LOGP(info, "Response orientation: {}", mSimRespOrientation ? "flipped" : "normal");
97
99}
100
101template <int DetID>
103{
104 if (mGeometry->getSubDetID(chipID) == 0) {
105 return mChipSimRespVD;
106 }
107
108 else if (mGeometry->getSubDetID(chipID) == 1 || mGeometry->getSubDetID(chipID) == 2) {
109 return mChipSimRespMLOT;
110 }
111 return nullptr;
112};
113
114//_______________________________________________________________________
115template <int DetID>
116void Digitizer<DetID>::process(const std::vector<Hit>* hits, int evID, int srcID, int layer)
117{
118 // digitize single event, the time must have been set beforehand
119
120 LOG(info) << " Digitizing " << mGeometry->getName() << " (ID: " << mGeometry->getDetID()
121 << ") hits of event " << evID << " from source " << srcID
122 << " at time " << mEventTime.getTimeNS() << " ROFrame = " << mNewROFrame
123 << " Min/Max ROFrames " << mROFrameMin << "/" << mROFrameMax << " layer " << layer;
124
125 // std::cout << "Printing segmentation info: " << std::endl;
126 // SegmentationChip::Print();
127
128 // is there something to flush ?
129 if (mNewROFrame > mROFrameMin) {
130 fillOutputContainer(mNewROFrame - 1, layer); // flush out all frames preceding the new one
131 }
132
133 int nHits = hits->size();
134 std::vector<int> hitIdx(nHits);
135 std::iota(std::begin(hitIdx), std::end(hitIdx), 0);
136 // sort hits to improve memory access
137 std::sort(hitIdx.begin(), hitIdx.end(),
138 [hits](auto lhs, auto rhs) {
139 return (*hits)[lhs].GetDetectorID() < (*hits)[rhs].GetDetectorID();
140 });
141 LOG(info) << "Processing " << nHits << " hits";
142 std::vector<float> respMatrix; // the hits' charge response, reused from hit to hit within the event
143 for (int i : hitIdx | std::views::filter([&](int idx) {
144 if (layer < 0) {
145 return true;
146 }
147 return getROFLayer((*hits)[idx].GetDetectorID()) == layer;
148 })) {
149 processHit((*hits)[i], mROFrameMax, evID, srcID, layer, respMatrix);
150 }
151}
152
153//_______________________________________________________________________
154template <int DetID>
156{
157 LOG(debug) << "Setting event time to " << irt.getTimeNS() << " ns after orbit 0 bc 0";
158 // assign event time in ns
159 mEventTime = irt;
160 // RO frame corresponding to provided time
161 mCollisionTimeWrtROF = mEventTime.timeInBCNS; // in triggered mode the ROF starts at BC (is there a delay?)
162 auto nbc = mEventTime.differenceInBC(mIRFirstSampledTF);
163
164 if (mCollisionTimeWrtROF < 0 && nbc > 0) {
165 // move to the ROF it actually belongs to and account this in the time offset wrt updated reference BC
166 nbc--;
167 mCollisionTimeWrtROF += o2::constants::lhc::LHCBunchSpacingNS;
168 }
169
170 mROFsWrtFirstRO = std::floor(float(nbc) / mParams.getROFrameLengthInBC(layer));
171 if (nbc < 0) {
172 mNewROFrame = 0;
173 } else {
174 mNewROFrame = nbc / mParams.getROFrameLengthInBC(layer);
175 }
176
177 LOG(debug) << " NewROFrame " << mNewROFrame << " nbc " << nbc << " ROFsWrtFirstRO " << mROFsWrtFirstRO;
178
179 // in continuous mode depends on starts of periodic readout frame
180 mCollisionTimeWrtROF += (nbc % mParams.getROFrameLengthInBC(layer)) * o2::constants::lhc::LHCBunchSpacingNS;
181
182 if (mNewROFrame < mROFrameMin) {
183 LOG(error) << "New ROFrame " << mNewROFrame << " (" << irt << ") precedes currently cashed " << mROFrameMin;
184 throw std::runtime_error("deduced ROFrame precedes already processed one");
185 }
186
187 if (mROFrameMax < mNewROFrame) {
188 mROFrameMax = mNewROFrame - 1; // all frames up to this are finished
189 }
190}
191
192//_______________________________________________________________________
193template <int DetID>
194void Digitizer<DetID>::fillOutputContainer(uint32_t frameLast, int layer)
195{
196 // // fill output with digits from min.cached up to requested frame, generating the noise beforehand
197 if (frameLast > mROFrameMax) {
198 frameLast = mROFrameMax;
199 }
200 // // make sure all buffers for extra digits are created up to the maxFrame
201 getExtraDigBuffer(mROFrameMax);
202 LOG(info) << "Filling " << mGeometry->getName() << " digits output for RO frames " << mROFrameMin << ":"
203 << frameLast;
204
206
207 // we have to write chips in RO increasing order, therefore have to loop over the frames here
208 for (; mROFrameMin <= frameLast; mROFrameMin++) {
209 rcROF.setROFrame(mROFrameMin);
210 rcROF.setFirstEntry(mDigits->size()); // start of current ROF in digits
211
212 auto& extra = *(mExtraBuff.front().get());
213 for (auto& chip : mChips) {
214 if (chip.isDisabled() || (layer >= 0 && getROFLayer(chip.getChipIndex()) != layer)) {
215 continue;
216 }
217 chip.addNoise(mROFrameMin, mROFrameMin, &mParams, mGeometry->getSubDetID(chip.getChipIndex()), mGeometry->getLayer(chip.getChipIndex()), mParams.getROFrameLength(getROFLayer(chip.getChipIndex())));
218 auto& buffer = chip.getPreDigits();
219 if (buffer.empty()) {
220 continue;
221 }
222 auto itBeg = buffer.begin();
223 auto iter = itBeg;
224 ULong64_t maxKey = chip.getOrderingKey(mROFrameMin + 1, 0, 0) - 1; // fetch digits with key below that
225 for (; iter != buffer.end(); ++iter) {
226 if (iter->first > maxKey) {
227 break; // is the digit ROFrame from the key > the max requested frame
228 }
229 auto& preDig = iter->second; // preDigit
230 if (preDig.charge >= mParams.getChargeThreshold()) {
231 int digID = mDigits->size();
232 mDigits->emplace_back(chip.getChipIndex(), preDig.row, preDig.col, preDig.charge, preDig.toa);
233 LOG(debug) << "Adding digit ID: " << digID << " with chipID: " << chip.getChipIndex() << ", row: " << preDig.row << ", col: " << preDig.col << ", charge: " << preDig.charge << ", ToA: " << preDig.toa;
234 mMCLabels->addElement(digID, preDig.labelRef.label);
235 auto& nextRef = preDig.labelRef; // extra contributors are in extra array
236 while (nextRef.next >= 0) {
237 nextRef = extra[nextRef.next];
238 mMCLabels->addElement(digID, nextRef.label);
239 }
240 }
241 }
242 buffer.erase(itBeg, iter);
243 }
244 // finalize ROF record
245 rcROF.setNEntries(mDigits->size() - rcROF.getFirstEntry()); // number of digits
246 rcROF.getBCData().setFromLong(mIRFirstSampledTF.toLong() + mROFrameMin * mParams.getROFrameLengthInBC(layer));
247 if (mROFRecords) {
248 mROFRecords->push_back(rcROF);
249 }
250 extra.clear(); // clear container for extra digits of the mROFrameMin ROFrame
251 // and move it as a new slot in the end
252 mExtraBuff.emplace_back(mExtraBuff.front().release());
253 mExtraBuff.pop_front();
254 }
255}
256
257//_______________________________________________________________________
258template <int DetID>
259void Digitizer<DetID>::processHit(const o2::trkft3::Hit& hit, uint32_t& maxFr, int evID, int srcID, int rofLayer, std::vector<float>& respMatrix)
260{
261 int chipID = hit.GetDetectorID();
262 int subDetID = mGeometry->getSubDetID(chipID);
263
264 int layer = mGeometry->getLayer(chipID); // local layer nr for response
265 int disk = getDisk(chipID);
266
267 if (disk != -1) {
268 LOG(debug) << "Skipping VD disk " << disk;
269 return; // skipping hits on disks for the moment
270 }
271
272 LOG(debug) << "Processing hit for chip " << chipID;
273 auto& chip = mChips[chipID];
274 if (chip.isDisabled()) {
275 LOG(debug) << "Skipping disabled chip " << chipID;
276 return;
277 }
278 float timeInROF = hit.GetTime() * sec2ns;
279 LOG(debug) << "Hit time: " << timeInROF << " ns";
280 if (timeInROF > 20e3) {
281 const int maxWarn = 10;
282 static int warnNo = 0;
283 if (warnNo < maxWarn) {
284 LOG(warning) << "Ignoring hit with time_in_event = " << timeInROF << " ns"
285 << ((++warnNo < maxWarn) ? "" : " (suppressing further warnings)");
286 }
287 return;
288 }
289 timeInROF += mCollisionTimeWrtROF;
290 if (mROFsWrtFirstRO < -1 || (mROFsWrtFirstRO == -1 && timeInROF < 0)) {
291 // disregard this hit because it comes from an event byefore readout starts and it does not effect this RO
292 LOG(debug) << "Ignoring hit with timeInROF = " << timeInROF;
293 return;
294 }
295
296 // calculate RO Frame for this hit
297 if (timeInROF < 0) {
298 timeInROF = 0.;
299 }
300 float tTot = mParams.getSignalShape().getMaxDuration();
301 // frame of the hit signal start wrt event ROFrame
302 int roFrameRel = int(timeInROF * mParams.getROFrameLengthInv(rofLayer));
303 // Time of Arrival w.r.t. the start of the ROF where the signal starts (= w.r.t. roFrameAbs)
304 float toaInROF = timeInROF - roFrameRel * mParams.getROFrameLength(rofLayer);
305
306 // frame of the hit signal end wrt event ROFrame: in the triggered mode we read just 1 frame
307 uint32_t roFrameRelMax = (timeInROF + tTot) * mParams.getROFrameLengthInv(rofLayer);
308 int nFrames = roFrameRelMax + 1 - roFrameRel;
309 uint32_t roFrameMax = mNewROFrame + roFrameRelMax;
310 if (roFrameMax > maxFr) {
311 maxFr = roFrameMax; // if signal extends beyond current maxFrame, increase the latter
312 }
313
314 // here we start stepping in the depth of the sensor to generate charge diffusion
315 float nStepsInv = mParams.getNSimStepsInv();
316 int nSteps = mParams.getNSimSteps();
317
318 const auto& matrix = mGeometry->getMatrixL2G(hit.GetDetectorID());
319 // matrix.print();
320
322 math_utils::Vector3D<float> xyzLocS(matrix ^ (hit.GetPosStart())); // start position in sensor frame
323 math_utils::Vector3D<float> xyzLocE(matrix ^ (hit.GetPos())); // end position in sensor frame
324
325 if (subDetID == 0) { // VD - need to take into account for the curved layers. TODO: consider the disks
326 // transform the point on the curved surface to a flat one
327 math_utils::Vector2D<float> xyFlatS = Segmentation::curvedToFlat(layer, xyzLocS.x(), xyzLocS.y());
328 math_utils::Vector2D<float> xyFlatE = Segmentation::curvedToFlat(layer, xyzLocE.x(), xyzLocE.y());
329 LOG(debug) << "Called curved to flat: " << xyzLocS.x() << " -> " << xyFlatS.x() << ", " << xyzLocS.y() << " -> " << xyFlatS.y();
330 // update the local coordinates with the flattened ones
331 xyzLocS.SetXYZ(xyFlatS.x(), xyFlatS.y(), xyzLocS.Z());
332 xyzLocE.SetXYZ(xyFlatE.x(), xyFlatE.y(), xyzLocE.Z());
333 }
334
335 // std::cout<<"Printing example of point in 0.35 0.35 0 in global frame: "<<std::endl;
336 // math_utils::Point3D<float> examplehitGlob(0.35, 0.35, 0);
337 // math_utils::Vector3D<float> exampleLoc(matrix ^ (examplehitGlob)); // start position in sensor frame
338 // std::cout<< "Example hit in local frame: " << exampleLoc << std::endl;
339 // std::cout<<"Going back to glob coordinates: " << (matrix * exampleLoc) << std::endl;
340
341 math_utils::Vector3D<float> step(xyzLocE);
342 step -= xyzLocS;
343 step *= nStepsInv; // position increment at each step
344 // the electrons will injected in the middle of each step
345 // starting from the middle of the first step
346 math_utils::Vector3D<float> stepH(step * 0.5);
347 xyzLocS += stepH;
348 xyzLocE -= stepH;
349
350 LOG(debug) << "Step into the sensitive volume: " << step << ". Number of steps: " << nSteps;
351 int rowS = -1, colS = -1, rowE = -1, colE = -1, nSkip = 0;
352
354 // get entrance pixel row and col
355 while (!Segmentation::localToDetector(xyzLocS.X(), xyzLocS.Z(), rowS, colS, subDetID, layer, disk)) { // guard-ring ?
356 if (++nSkip >= nSteps) {
357 LOG(debug) << "Did not enter to sensitive matrix, " << nSkip << " >= " << nSteps;
358 return; // did not enter to sensitive matrix
359 }
360 xyzLocS += step;
361 }
362
363 // get exit pixel row and col
364 while (!Segmentation::localToDetector(xyzLocE.X(), xyzLocE.Z(), rowE, colE, subDetID, layer, disk)) {
365 if (++nSkip >= nSteps) {
366 LOG(debug) << "Did not enter to sensitive matrix, " << nSkip << " >= " << nSteps;
367 return; // did not enter to sensitive matrix
368 }
369 xyzLocE -= step;
370 }
371
372 int nCols = getNCols(subDetID, layer);
373 int nRows = getNRows(subDetID, layer);
374
375 // estimate the limiting min/max row and col where the non-0 response is possible
376 if (rowS > rowE) {
377 std::swap(rowS, rowE);
378 }
379 if (colS > colE) {
380 std::swap(colS, colE);
381 }
382 rowS -= AlpideRespSimMat::NPix / 2;
383 rowE += AlpideRespSimMat::NPix / 2;
384 if (rowS < 0) {
385 rowS = 0;
386 }
387 if (rowE >= nRows) {
388 rowE = nRows - 1;
389 }
390 colS -= AlpideRespSimMat::NPix / 2;
391 colE += AlpideRespSimMat::NPix / 2;
392 if (colS < 0) {
393 colS = 0;
394 }
395 if (colE >= nCols) {
396 colE = nCols - 1;
397 }
398 int rowSpan = rowE - rowS + 1, colSpan = colE - colS + 1; // size of plaquet where some response is expected
399
400 respMatrix.assign(static_cast<size_t>(rowSpan) * colSpan, 0.f); // response accumulated here, row by row
401
402 float nElectrons = hit.GetEnergyLoss() * mParams.getEnergyToNElectrons(); // total number of deposited electrons
403 nElectrons *= nStepsInv; // N electrons injected per step
404 if (nSkip) {
405 nSteps -= nSkip;
406 }
407
408 int rowPrev = -1, colPrev = -1, row, col;
409 float cRowPix = 0.f, cColPix = 0.f; // local coordinate of the current pixel center
410
411 const o2::trkft3::ChipSimResponse* resp = getChipResponse(chipID);
412 // std::cout << "Printing chip response:" << std::endl;
413 // resp->print();
414
415 // take into account that the ChipSimResponse depth defintion has different min/max boundaries
416 // although the max should coincide with the surface of the epitaxial layer, which in the chip
417 // local coordinates has Y = +SensorLayerThickness/2
418 // LOG(info)<<"SubdetID = " << subDetID<< " shift: "<<mSimRespVDShift<<" or "<<mSimRespMLOTShift;
419 // LOG(info)<< " Before shift: S = " << xyzLocS.Y()*1e4 << " E = " << xyzLocE.Y()*1e4;
420 xyzLocS.SetY(xyzLocS.Y() + ((subDetID == 0) ? mSimRespVDShift : mSimRespMLOTShift));
421 // LOG(info)<< " After shift: S = " << xyzLocS.Y()*1e4 << " E = " << xyzLocE.Y()*1e4;
422
423 // collect charge in every pixel which might be affected by the hit
424 for (int iStep = nSteps; iStep--;) {
425 // Get the pixel ID
426 Segmentation::localToDetector(xyzLocS.X(), xyzLocS.Z(), row, col, subDetID, layer, disk);
427 if (row != rowPrev || col != colPrev) { // update pixel and coordinates of its center
428 if (!Segmentation::detectorToLocal(row, col, cRowPix, cColPix, subDetID, layer, disk)) {
429 continue; // should not happen
430 }
431 rowPrev = row;
432 colPrev = col;
433 }
434 bool flipCol = false, flipRow = false;
435 // note that response needs coordinates along column row (locX) (locZ) then depth (locY)
436 float rowMax{}, colMax{};
437 const AlpideRespSimMat* rspmat{nullptr};
438 if (subDetID == 0) { // VD
439 rowMax = 0.5f * Segmentation::PitchRowVD * mSimRespVDScaleX;
440 colMax = 0.5f * Segmentation::PitchColVD * mSimRespVDScaleZ;
441 rspmat = resp->getResponse(mSimRespVDScaleX * (xyzLocS.X() - cRowPix), mSimRespVDScaleZ * (xyzLocS.Z() - cColPix), xyzLocS.Y(), flipRow, flipCol, rowMax, colMax);
442 } else { // ML/OT
443 rowMax = 0.5f * Segmentation::PitchRowMLOT * mSimRespMLOTScaleX;
444 colMax = 0.5f * Segmentation::PitchColMLOT * mSimRespMLOTScaleZ;
445 rspmat = resp->getResponse(mSimRespMLOTScaleX * (xyzLocS.X() - cRowPix), mSimRespMLOTScaleZ * (xyzLocS.Z() - cColPix), xyzLocS.Y(), flipRow, flipCol, rowMax, colMax);
446 }
447
448 xyzLocS += step;
449
450 if (rspmat == nullptr) {
451 LOG(debug) << "Error in rspmat for step " << iStep << " / " << nSteps;
452 continue;
453 }
454 // LOG(info) << "rspmat valid! for step " << iStep << " / " << nSteps << ", (row,col) = (" << row << "," << col << ")";
455 // LOG(info) << "rspmat valid! for step " << iStep << " / " << nSteps << " Y= " << xyzLocS.Y()*1e4 << " , (row,col) = (" << row << "," << col << ")";
456 // rspmat->print(); // print the response matrix for debugging
457
458 for (int irow = AlpideRespSimMat::NPix; irow--;) {
459 int rowDest = row + irow - AlpideRespSimMat::NPix / 2 - rowS; // destination row in the respMatrix
460 if (rowDest < 0 || rowDest >= rowSpan) {
461 continue;
462 }
463 for (int icol = AlpideRespSimMat::NPix; icol--;) {
464 int colDest = col + icol - AlpideRespSimMat::NPix / 2 - colS; // destination column in the respMatrix
465 if (colDest < 0 || colDest >= colSpan) {
466 continue;
467 }
468 respMatrix[rowDest * colSpan + colDest] += rspmat->getValue(irow, icol, mSimRespOrientation ? !flipRow : flipRow, flipCol);
469 }
470 }
471 }
472 LOG(debug) << "Response done; adding labels; making digits";
473 // fire the pixels assuming Poisson(n_response_electrons)
474 o2::MCCompLabel lbl(hit.GetTrackID(), evID, srcID, false);
475 auto roFrameAbs = mNewROFrame + roFrameRel;
476 LOG(debug) << "\nSpanning through rows and columns; rowspan = " << rowSpan << " colspan = " << colSpan << " = " << colE << " - " << colS << " +1 ";
477 for (int irow = rowSpan; irow--;) { // irow ranging from 4 to 0
478 uint16_t rowIS = irow + rowS; // row distant irow from the row of the hit start
479 for (int icol = colSpan; icol--;) { // icol ranging from 4 to 0
480 float nEleResp = respMatrix[irow * colSpan + icol]; // value of the probability of the response in this pixel
481 if (nEleResp <= 1.e-36) {
482 continue;
483 }
484 LOG(debug) << "nEleResp: value " << nEleResp << " for pixel " << irow << " " << icol;
485 int nEle = gRandom->Poisson(nElectrons * nEleResp); // total charge in given pixel = number of electrons generated in the hit multiplied by the probability of being detected in their position
486 LOG(debug) << "Charge detected in the pixel: " << nEle << " for pixel " << irow << " " << icol;
487 // ignore charge which have no chance to fire the pixel
488 if (nEle < mParams.getMinChargeToAccount()) {
489 LOG(debug) << "Ignoring pixel with nEle = " << nEle << " < min charge to account "
490 << mParams.getMinChargeToAccount() << " for pixel " << irow << " " << icol;
491 continue;
492 }
493
494 uint16_t colIS = icol + colS; // col distant icol from the col of the hit start
495 if (mNoiseMap && mNoiseMap->isNoisy(chipID, rowIS, colIS)) {
496 continue;
497 }
498 if (mDeadChanMap && mDeadChanMap->isNoisy(chipID, rowIS, colIS)) {
499 continue;
500 }
501 registerDigits(chip, roFrameAbs, toaInROF, nFrames, rowIS, colIS, nEle, lbl, rofLayer);
502 }
503 }
504}
505
506//________________________________________________________________________________
507template <int DetID>
508void Digitizer<DetID>::registerDigits(o2::trkft3::ChipDigitsContainer& chip, uint32_t roFrame, float toaInROF, int nROF,
509 uint16_t row, uint16_t col, int nEle, o2::MCCompLabel& lbl, int layer)
510{
511 // Register digits for given pixel, accounting for the possible signal contribution to
512 // multiple ROFrame. The signal starts at time toaInROF wrt the start of provided roFrame
513 // In every ROFrame we check the collected signal during strobe
514 LOG(debug) << "Registering digits for chip " << chip.getChipIndex() << " at ROFrame " << roFrame
515 << " row " << row << " col " << col << " nEle " << nEle << " label " << lbl << " layer " << layer << " toa " << toaInROF;
516 float tStrobe = mParams.getStrobeDelay(layer) - toaInROF; // strobe start wrt signal start
517 for (int i = 0; i < nROF; i++) { // loop on all the ROFs occupied by the same signal to calculate the charge accumulated in that ROF
518 uint32_t roFr = roFrame + i;
519 float toaROF = toaInROF - i * mParams.getROFrameLength(layer); // ToA w.r.t. start of ROF
520 int nEleROF = mParams.getSignalShape().getCollectedCharge(nEle, tStrobe, tStrobe + mParams.getStrobeLength(layer));
521 tStrobe += mParams.getROFrameLength(layer); // for the next ROF
522
523 // discard too small contributions, they have no chance to produce a digit
524 if (nEleROF < mParams.getMinChargeToAccount()) {
525 continue;
526 }
527 if (roFr > mEventROFrameMax) {
528 mEventROFrameMax = roFr;
529 }
530 if (roFr < mEventROFrameMin) {
531 mEventROFrameMin = roFr;
532 }
533 auto key = chip.getOrderingKey(roFr, row, col);
535 if (!pd) {
536 chip.addDigit(key, roFr, row, col, nEleROF, lbl, toaROF);
537 LOG(debug) << "Added digit with key: " << key << " ROF: " << roFr << " row: " << row << " col: " << col << " charge: " << nEleROF;
538 } else { // there is already a digit at this slot, account as PreDigitExtra contribution
539 LOG(debug) << "Added to pre-digit with key: " << key << " ROF: " << roFr << " row: " << row << " col: " << col << " charge: " << nEleROF;
540 pd->charge += nEleROF;
541 pd->toa = std::min(pd->toa, toaROF);
542 if (pd->labelRef.label == lbl) { // don't store the same label twice
543 continue;
544 }
545 ExtraDig* extra = getExtraDigBuffer(roFr);
546 int& nxt = pd->labelRef.next;
547 bool skip = false;
548 while (nxt >= 0) {
549 if ((*extra)[nxt].label == lbl) { // don't store the same label twice
550 skip = true;
551 break;
552 }
553 nxt = (*extra)[nxt].next;
554 }
555 if (skip) {
556 continue;
557 }
558 // new predigit will be added in the end of the chain
559 nxt = extra->size();
560 extra->emplace_back(lbl);
561 }
562 }
563}
564
std::ostringstream debug
unsigned short int uint16_t
int32_t i
char error[CURL_ERROR_SIZE]
Definition of the SegmentationChipclass.
specs of the ALICE3 TRK
Definition of the TRK/FT3 digitizer.
StringRef key
int GetTrackID() const
Definition BaseHits.h:30
V GetEnergyLoss() const
Definition BaseHits.h:103
math_utils::Point3D< T > GetPos() const
Definition BaseHits.h:67
E GetTime() const
Definition BaseHits.h:71
unsigned short GetDetectorID() const
Definition BaseHits.h:73
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:60
static constexpr const char * getName(ID id)
names of defined detectors
Definition DetID.h:148
bool getResponse(float vRow, float vCol, float cDepth, AlpideRespSimMat &dest) const
auto getChipResponse(int chipID)
Definition Digitizer.cxx:95
void fillOutputContainer(uint32_t maxFrame=0xffffffff, int layer=-1)
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.
static constexpr float PitchColVD
static bool localToDetector(float xRow, float zCol, int &iRow, int &iCol, int subDetID, int layer, int disk) noexcept
static constexpr float PitchColMLOT
static constexpr float PitchRowMLOT
static constexpr float PitchRowVD
static bool detectorToLocal(int iRow, int iCol, float &xRow, float &zCol, int subDetID, int layer, int disk) noexcept
static constexpr float SiliconThicknessMLOT
static math_utils::Vector2D< float > curvedToFlat(const int layer, const float xCurved, const float yCurved) noexcept
Container for simulated 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, float toa=0.f)
static ULong64_t getOrderingKey(UInt_t roframe, UShort_t row, UShort_t col)
Get global ordering key made of readout frame, column and row.
o2::trkft3::PreDigit * findDigit(ULong64_t key)
math_utils::Point3D< Float_t > GetPosStart() const
Definition Hit.h:43
void setNEntries(int n)
Definition ROFRecord.h:39
const BCData & getBCData() const
Definition ROFRecord.h:41
int getFirstEntry() const
Definition ROFRecord.h:46
void setFirstEntry(int idx)
Definition ROFRecord.h:38
void setROFrame(ROFtype rof)
Definition ROFRecord.h:36
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
uint8_t int statusCode int
const int float col
value_T step
Definition TrackUtils.h:42
constexpr double pitchZ
Definition Specs.h:219
constexpr double pitchX
Definition Specs.h:218
constexpr double pitchZ
Definition Specs.h:211
constexpr double pitchX
Definition Specs.h:210
void setFromLong(int64_t l)
double timeInBCNS
time in NANOSECONDS relative to orbit/bc
double getTimeNS() const
get time in ns from orbit=0/bc=0
IR getFirstSampledTFIR() const
get TF and HB (abs) for this IR
Definition HBFUtils.h:74
int next
eventual next contribution to the same pixel
Definition PreDigit.h:30
o2::MCCompLabel label
hit label
Definition PreDigit.h:29
float toa
Time of arrival in ns (earliest contribution)
Definition PreDigit.h:41
PreDigitLabelRef labelRef
label and reference to the next one
Definition PreDigit.h:42
int charge
N electrons.
Definition PreDigit.h:40
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< int > row