Skip to content

Commit aeb75a7

Browse files
authored
ALICE3: TRK/FT3 digitizer response matrix on the heap, not the stack (#16033)
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 440b7d2 commit aeb75a7

6 files changed

Lines changed: 21 additions & 21 deletions

File tree

‎Detectors/ITSMFT/common/simulation/include/ITSMFTSimulation/Digitizer.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Digitizer : public TObject
102102
}
103103

104104
private:
105-
void processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID, int srcID, int lay);
105+
void processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID, int srcID, int lay, std::vector<float>& respMatrix);
106106
void registerDigits(ChipDigitsContainer& chip, uint32_t roFrame, float tInROF, int nROF,
107107
uint16_t row, uint16_t col, int nEle, o2::MCCompLabel& lbl, int lay);
108108

‎Detectors/ITSMFT/common/simulation/src/Digitizer.cxx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,14 @@ void Digitizer::process(const std::vector<Hit>* hits, int evID, int srcID, int l
128128
std::sort(hitIdx.begin(), hitIdx.end(), [hits](auto lhs, auto rhs) {
129129
return (*hits)[lhs].GetDetectorID() < (*hits)[rhs].GetDetectorID();
130130
});
131+
std::vector<float> respMatrix; // the hits' charge response, reused from hit to hit within the event
131132
for (int i : hitIdx | std::views::filter([&](int idx) {
132133
if (layer < 0) {
133134
return true;
134135
}
135136
return mGeometry->getLayer((*hits)[idx].GetDetectorID()) == layer;
136137
})) {
137-
processHit((*hits)[i], mROFrameMax, evID, srcID, layer);
138+
processHit((*hits)[i], mROFrameMax, evID, srcID, layer, respMatrix);
138139
}
139140

140141
// in the triggered mode store digits after every MC event
@@ -256,7 +257,7 @@ void Digitizer::fillOutputContainer(uint32_t frameLast, int layer)
256257
}
257258

258259
//_______________________________________________________________________
259-
void Digitizer::processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID, int srcID, int lay)
260+
void Digitizer::processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID, int srcID, int lay, std::vector<float>& respMatrix)
260261
{
261262
// convert single hit to digits
262263
auto chipID = hit.GetDetectorID();
@@ -347,8 +348,7 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID
347348
}
348349
int rowSpan = rowE - rowS + 1, colSpan = colE - colS + 1; // size of plaquet where some response is expected
349350

350-
float respMatrix[rowSpan][colSpan]; // response accumulated here
351-
std::fill(&respMatrix[0][0], &respMatrix[0][0] + rowSpan * colSpan, 0.f);
351+
respMatrix.assign(static_cast<size_t>(rowSpan) * colSpan, 0.f); // response accumulated here, row by row
352352

353353
float nElectrons = hit.GetEnergyLoss() * mParams.getEnergyToNElectrons(); // total number of deposited electrons
354354
nElectrons *= nStepsInv; // N electrons injected per step
@@ -397,7 +397,7 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID
397397
if (colDest < 0 || colDest >= colSpan) {
398398
continue;
399399
}
400-
respMatrix[rowDest][colDest] += rspmat->getValue(irow, icol, flipRow, flipCol);
400+
respMatrix[rowDest * colSpan + colDest] += rspmat->getValue(irow, icol, flipRow, flipCol);
401401
}
402402
}
403403
}
@@ -409,7 +409,7 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID
409409
for (int irow = rowSpan; irow--;) {
410410
uint16_t rowIS = irow + rowS;
411411
for (int icol = colSpan; icol--;) {
412-
float nEleResp = respMatrix[irow][icol];
412+
float nEleResp = respMatrix[irow * colSpan + icol];
413413
if (!nEleResp) {
414414
continue;
415415
}

‎Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/include/TRKFT3Simulation/Digitizer.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Digitizer
9393
void setDeadChannelsMap(const o2::itsmft::NoiseMap* mp) { mDeadChanMap = mp; }
9494

9595
private:
96-
void processHit(const o2::trkft3::Hit& hit, uint32_t& maxFr, int evID, int srcID, int rofLayer);
96+
void processHit(const o2::trkft3::Hit& hit, uint32_t& maxFr, int evID, int srcID, int rofLayer, std::vector<float>& respMatrix);
9797
void registerDigits(o2::trkft3::ChipDigitsContainer& chip, uint32_t roFrame, float toaInROF, int nROF,
9898
uint16_t row, uint16_t col, int nEle, o2::MCCompLabel& lbl, int layer);
9999

‎Detectors/Upgrades/ALICE3/TRKFT3/common/simulation/src/Digitizer.cxx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,14 @@ void Digitizer<DetID>::process(const std::vector<Hit>* hits, int evID, int srcID
139139
return (*hits)[lhs].GetDetectorID() < (*hits)[rhs].GetDetectorID();
140140
});
141141
LOG(info) << "Processing " << nHits << " hits";
142+
std::vector<float> respMatrix; // the hits' charge response, reused from hit to hit within the event
142143
for (int i : hitIdx | std::views::filter([&](int idx) {
143144
if (layer < 0) {
144145
return true;
145146
}
146147
return getROFLayer((*hits)[idx].GetDetectorID()) == layer;
147148
})) {
148-
processHit((*hits)[i], mROFrameMax, evID, srcID, layer);
149+
processHit((*hits)[i], mROFrameMax, evID, srcID, layer, respMatrix);
149150
}
150151
}
151152

@@ -255,7 +256,7 @@ void Digitizer<DetID>::fillOutputContainer(uint32_t frameLast, int layer)
255256

256257
//_______________________________________________________________________
257258
template <int DetID>
258-
void Digitizer<DetID>::processHit(const o2::trkft3::Hit& hit, uint32_t& maxFr, int evID, int srcID, int rofLayer)
259+
void Digitizer<DetID>::processHit(const o2::trkft3::Hit& hit, uint32_t& maxFr, int evID, int srcID, int rofLayer, std::vector<float>& respMatrix)
259260
{
260261
int chipID = hit.GetDetectorID(); //// the chip ID at the moment is not referred to the chip but to a wider detector element (e.g. quarter of layer or disk in VD, stave in ML, half stave in OT)
261262
int subDetID = mGeometry->getSubDetID(chipID);
@@ -396,8 +397,7 @@ void Digitizer<DetID>::processHit(const o2::trkft3::Hit& hit, uint32_t& maxFr, i
396397
}
397398
int rowSpan = rowE - rowS + 1, colSpan = colE - colS + 1; // size of plaquet where some response is expected
398399

399-
float respMatrix[rowSpan][colSpan]; // response accumulated here
400-
std::fill(&respMatrix[0][0], &respMatrix[0][0] + rowSpan * colSpan, 0.f);
400+
respMatrix.assign(static_cast<size_t>(rowSpan) * colSpan, 0.f); // response accumulated here, row by row
401401

402402
float nElectrons = hit.GetEnergyLoss() * mParams.getEnergyToNElectrons(); // total number of deposited electrons
403403
nElectrons *= nStepsInv; // N electrons injected per step
@@ -465,7 +465,7 @@ void Digitizer<DetID>::processHit(const o2::trkft3::Hit& hit, uint32_t& maxFr, i
465465
if (colDest < 0 || colDest >= colSpan) {
466466
continue;
467467
}
468-
respMatrix[rowDest][colDest] += rspmat->getValue(irow, icol, mSimRespOrientation ? !flipRow : flipRow, flipCol);
468+
respMatrix[rowDest * colSpan + colDest] += rspmat->getValue(irow, icol, mSimRespOrientation ? !flipRow : flipRow, flipCol);
469469
}
470470
}
471471
}
@@ -477,7 +477,7 @@ void Digitizer<DetID>::processHit(const o2::trkft3::Hit& hit, uint32_t& maxFr, i
477477
for (int irow = rowSpan; irow--;) { // irow ranging from 4 to 0
478478
uint16_t rowIS = irow + rowS; // row distant irow from the row of the hit start
479479
for (int icol = colSpan; icol--;) { // icol ranging from 4 to 0
480-
float nEleResp = respMatrix[irow][icol]; // value of the probability of the response in this pixel
480+
float nEleResp = respMatrix[irow * colSpan + icol]; // value of the probability of the response in this pixel
481481
if (nEleResp <= 1.e-36) {
482482
continue;
483483
}

‎Detectors/Upgrades/ITS3/simulation/include/ITS3Simulation/Digitizer.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Digitizer : public TObject
8686
void setDeadChannelsMap(const o2::itsmft::NoiseMap* mp) { mDeadChanMap = mp; }
8787

8888
private:
89-
void processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID, int srcID, int layer);
89+
void processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID, int srcID, int layer, std::vector<float>& respMatrix);
9090
void registerDigits(o2::its3::ChipDigitsContainer& chip, uint32_t roFrame, float tInROF, int nROF,
9191
uint16_t row, uint16_t col, int nEle, o2::MCCompLabel& lbl, int layer);
9292

‎Detectors/Upgrades/ITS3/simulation/src/Digitizer.cxx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,14 @@ void Digitizer::process(const std::vector<itsmft::Hit>* hits, int evID, int srcI
9595
[hits](auto lhs, auto rhs) {
9696
return (*hits)[lhs].GetDetectorID() < (*hits)[rhs].GetDetectorID();
9797
});
98+
std::vector<float> respMatrix; // the hits' charge response, reused from hit to hit within the event
9899
for (int i : hitIdx | std::views::filter([&](int idx) {
99100
if (layer < 0) {
100101
return true;
101102
}
102103
return mGeometry->getLayer((*hits)[idx].GetDetectorID()) == layer;
103104
})) {
104-
processHit((*hits)[i], mROFrameMax, evID, srcID, layer);
105+
processHit((*hits)[i], mROFrameMax, evID, srcID, layer, respMatrix);
105106
}
106107
// in the triggered mode store digits after every MC event
107108
// TODO: in the real triggered mode this will not be needed, this is actually for the
@@ -218,7 +219,7 @@ void Digitizer::fillOutputContainer(uint32_t frameLast, int layer)
218219
}
219220
}
220221

221-
void Digitizer::processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID, int srcID, int lay)
222+
void Digitizer::processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID, int srcID, int lay, std::vector<float>& respMatrix)
222223
{
223224
// convert single hit to digits
224225
auto chipID = hit.GetDetectorID();
@@ -336,8 +337,7 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID
336337
colE = std::min(colE, maxNcols - 1);
337338

338339
int rowSpan = rowE - rowS + 1, colSpan = colE - colS + 1; // size of plaquet where some response is expected
339-
float respMatrix[rowSpan][colSpan]; // response accumulated here
340-
std::fill(&respMatrix[0][0], &respMatrix[0][0] + rowSpan * colSpan, 0.f);
340+
respMatrix.assign(static_cast<size_t>(rowSpan) * colSpan, 0.f); // response accumulated here, row by row
341341

342342
float nElectrons = hit.GetEnergyLoss() * mParams.getEnergyToNElectrons(); // total number of deposited electrons
343343
nElectrons *= nStepsInv; // N electrons injected per step
@@ -401,7 +401,7 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID
401401
if (colDest < 0 || colDest >= colSpan) {
402402
continue;
403403
}
404-
respMatrix[rowDest][colDest] += rspmat->getValue(irow, icol, ((chip.isIB() && mSimRespIBOrientation) ? !flipRow : flipRow), flipCol);
404+
respMatrix[rowDest * colSpan + colDest] += rspmat->getValue(irow, icol, ((chip.isIB() && mSimRespIBOrientation) ? !flipRow : flipRow), flipCol);
405405
}
406406
}
407407
}
@@ -413,7 +413,7 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, uint32_t& maxFr, int evID
413413
for (int irow = rowSpan; irow--;) {
414414
uint16_t rowIS = irow + rowS;
415415
for (int icol = colSpan; icol--;) {
416-
float nEleResp = respMatrix[irow][icol];
416+
float nEleResp = respMatrix[irow * colSpan + icol];
417417
if (nEleResp <= 1.e-36) {
418418
continue;
419419
}

0 commit comments

Comments
 (0)