@@ -104,32 +104,18 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, int evID, int srcID)
104104
105105 // Get detector element ID
106106 const int chipID = hit.GetDetectorID ();
107+ if (chipID < 0 || chipID >= mGeometry ->getSize () || mGeometry ->getSize () < 1 ) {
108+ LOG (debug) << " Invalid detector ID: " << chipID << " , geometry size: " << mGeometry ->getSize ();
109+ return ; // invalid detector ID
110+ }
111+ const int subdetectorID = mGeometry ->getIOTOFLayer (chipID);
112+
107113 auto & chip = mChips [chipID];
108114 if (chip.isDisabled ()) {
109115 LOG (debug) << " Hit rejected because chip " << chipID << " is disabled" ;
110116 return ;
111117 }
112118
113- // middle position of the hit in the sensor frame
114- const auto & matrix = mGeometry ->getMatrixL2G (chipID);
115- auto xyzPositionStart = matrix ^ hit.GetPosStart ();
116- auto xyzPositionEnd = matrix ^ hit.GetPos ();
117- const auto xMid = 0 .5f * (xyzPositionStart.X () + xyzPositionEnd.X ());
118- const auto zMid = 0 .5f * (xyzPositionStart.Z () + xyzPositionEnd.Z ());
119- // move this to the local pixel coordinates for the efficiency map
120- int row, col;
121- float xPixelCenter, zPixelCenter;
122- if (!sSegmentation ->localToDetector (xMid, zMid, row, col, mGeometry ->getIOTOFLayer (chipID))) {
123- LOG (debug) << " Hit rejected because position (" << xMid << " , " << zMid << " ) is outside the active area of chip " << chipID;
124- return ; // hit is outside the active area
125- }
126- sSegmentation ->detectorToLocalUnchecked (row, col, xPixelCenter, zPixelCenter, mGeometry ->getIOTOFLayer (chipID));
127-
128- if (!isEfficient (xMid - xPixelCenter, zMid - zPixelCenter)) {
129- LOG (debug) << " Hit rejected by efficiency cut" ;
130- return ;
131- }
132-
133119 // Convert energy loss to charge (number of electrons)
134120 float energyLoss = hit.GetEnergyLoss (); // in GeV
135121 int charge = energyToCharge (energyLoss);
@@ -149,20 +135,18 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, int evID, int srcID)
149135 double hitTimeWrtBC = hitTime + eventTimeInBC; // hit time wrt bc
150136 double smearedTime = smearTime (hitTimeWrtBC);
151137
152- if (chipID < 0 || chipID >= mGeometry ->getSize () || mGeometry ->getSize () < 1 ) {
153- LOG (debug) << " Invalid detector ID: " << chipID << " , geometry size: " << mGeometry ->getSize ();
154- return ; // invalid detector ID
155- }
156-
157138 // Create the digit with time information
158139 o2::MCCompLabel label (hit.GetTrackID (), evID, srcID, false );
159140 const int roFrameAbs = 0 ; // For now, we can set this to 0 or calculate based on time if needed
160141 const int nROF = 1 ; // For now, we can assume the signal is contained in one ROF, this can be extended to multiple ROFs based on the time
161142
162143 float ** respMatrix = nullptr ;
144+ float ** avgHitLocalX = nullptr ;
145+ float ** avgHitLocalZ = nullptr ;
163146 int rowStart = 0 , colStart = 0 , rowSpan = 0 , colSpan = 0 ;
164- stepping (hit, respMatrix, rowStart, colStart, rowSpan, colSpan);
147+ stepping (hit, respMatrix, avgHitLocalX, avgHitLocalZ, rowStart, colStart, rowSpan, colSpan);
165148
149+ float xPixelCenter = 0 .0f , zPixelCenter = 0 .0f ;
166150 for (int irow = rowSpan; irow--;) {
167151 uint16_t rowIS = irow + rowStart;
168152 for (int icol = colSpan; icol--;) {
@@ -171,6 +155,14 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, int evID, int srcID)
171155 if (!nEleResp) {
172156 continue ;
173157 }
158+
159+ // Apply efficiency cut based on the hit segment mean position relative to the pixel center
160+ sSegmentation ->detectorToLocal (rowIS, colIS, xPixelCenter, zPixelCenter, subdetectorID);
161+ if (!isEfficient (avgHitLocalX[irow][icol] - xPixelCenter, avgHitLocalZ[irow][icol] - zPixelCenter)) {
162+ LOG (debug) << " Hit rejected by efficiency cut at pixel (" << rowIS << " , " << colIS << " ) in chip " << chipID;
163+ continue ;
164+ }
165+
174166 const int nElectronsSampled = gRandom ->Poisson (electronsPerStep * nEleResp);
175167 // Noise can be added here if needed
176168
@@ -181,12 +173,17 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, int evID, int srcID)
181173
182174 for (int irow = 0 ; irow < rowSpan; ++irow) {
183175 delete[] respMatrix[irow];
176+ delete[] avgHitLocalX[irow];
177+ delete[] avgHitLocalZ[irow];
184178 }
185179 delete[] respMatrix;
180+ delete[] avgHitLocalX;
181+ delete[] avgHitLocalZ;
186182}
187183
188- void Digitizer::stepping (const o2::itsmft::Hit& hit, float **& respMatrix, int & rowStart, int & colStart, int & rowSpan, int & colSpan)
184+ void Digitizer::stepping (const o2::itsmft::Hit& hit, float **& respMatrix, float **& avgHitLocalX, float **& avgHitLocalZ, int & rowStart, int & colStart, int & rowSpan, int & colSpan)
189185{
186+ LOG (debug) << " \n\n Performing stepping" ;
190187 const int chipID = hit.GetDetectorID ();
191188 const auto & matrix = mGeometry ->getMatrixL2G (chipID);
192189 const int subdetectorID = mGeometry ->getIOTOFLayer (chipID);
@@ -238,27 +235,52 @@ void Digitizer::stepping(const o2::itsmft::Hit& hit, float**& respMatrix, int& r
238235 colSpan = colEnd - colStart + 1 ;
239236
240237 respMatrix = new float *[rowSpan];
238+ avgHitLocalX = new float *[rowSpan];
239+ avgHitLocalZ = new float *[rowSpan];
241240 for (int i = 0 ; i < rowSpan; ++i) {
242241 respMatrix[i] = new float [colSpan]();
242+ avgHitLocalX[i] = new float [colSpan]();
243+ avgHitLocalZ[i] = new float [colSpan]();
243244 }
244245
245- int rowPrev = -1 , colPrev = -1 , row = 0 , col = 0 ;
246- if (!respMatrix || rowSpan <= 0 || colSpan <= 0 ) {
246+ if (!respMatrix || !avgHitLocalX || !avgHitLocalZ || rowSpan <= 0 || colSpan <= 0 ) {
247247 return ;
248248 }
249249 if (nSkip) {
250250 nSteps -= nSkip;
251251 }
252252
253- auto & currentPosLocal = xyzPositionStart;
253+ int rowPrev = -1 , colPrev = -1 , row = 0 , col = 0 ;
254+ auto pixelCurrentPosLocal = xyzPositionStart;
255+ auto pixelStartPosLocal = xyzPositionStart;
254256 for (int iStep = nSteps; iStep--;) {
255- sSegmentation ->localToDetector (currentPosLocal.X (), currentPosLocal.Z (), row, col, subdetectorID);
257+
258+ // Step does not contribute if it is in the passive area
259+ if (!sSegmentation ->localToDetector (pixelCurrentPosLocal.X (), pixelCurrentPosLocal.Z (), row, col, subdetectorID)) {
260+ LOG (debug) << " Step is in passive area: (" << pixelCurrentPosLocal.X () << " , " << pixelCurrentPosLocal.Z () << " ) is outside the active area of chip " << subdetectorID;
261+ pixelCurrentPosLocal += stepVector;
262+ continue ;
263+ }
264+
265+ // The step has reached another pixel, compute mean hit segment positions
266+ // for pixel efficiency evaluation and reset the start position for the next pixel
256267 if (row != rowPrev || col != colPrev) {
268+
269+ // Finalize the previous pixel
270+ if (rowPrev != -1 && colPrev != -1 ) {
271+ const int irow = rowPrev - rowStart;
272+ const int icol = colPrev - colStart;
273+ avgHitLocalX[irow][icol] = 0 .5f * (pixelStartPosLocal.X () + pixelCurrentPosLocal.X () - stepVector.X ());
274+ avgHitLocalZ[irow][icol] = 0 .5f * (pixelStartPosLocal.Z () + pixelCurrentPosLocal.Z () - stepVector.Z ());
275+ }
276+
277+ // Start the new pixel
257278 rowPrev = row;
258279 colPrev = col;
280+ pixelStartPosLocal = pixelCurrentPosLocal;
259281 }
260282
261- currentPosLocal += stepVector; // Move to the next step position
283+ pixelCurrentPosLocal += stepVector; // Move to the next step position
262284
263285 for (int irow = digitizerParams.responseMatrixSize ; irow--;) {
264286 int rowDest = row + irow - (digitizerParams.responseMatrixSize / 2 ) - rowStart; // destination row in the respMatrix
@@ -274,6 +296,14 @@ void Digitizer::stepping(const o2::itsmft::Hit& hit, float**& respMatrix, int& r
274296 }
275297 }
276298 }
299+
300+ // Finalize the last pixel
301+ if (rowPrev != -1 && colPrev != -1 ) {
302+ const int irow = rowPrev - rowStart;
303+ const int icol = colPrev - colStart;
304+ avgHitLocalX[irow][icol] = 0 .5f * (pixelStartPosLocal.X () + pixelCurrentPosLocal.X () - stepVector.X ());
305+ avgHitLocalZ[irow][icol] = 0 .5f * (pixelStartPosLocal.Z () + pixelCurrentPosLocal.Z () - stepVector.Z ());
306+ }
277307}
278308
279309// _______________________________________________________________________
@@ -407,7 +437,7 @@ void Digitizer::registerDigits(Chip& chip, uint32_t roFrame, double time, int nR
407437 int tdc = int ((time - nbc * o2::constants::lhc::LHCBunchSpacingNS) / digitizerParams.tdcBin );
408438 nbc += mEventTime .toLong ();
409439
410- LOG (debug) << nbc << " \t " << tdc;
440+ LOG (debug) << " nbc: " << nbc << " \t tdc: " << tdc;
411441 double absoluteTime = tdc * digitizerParams.tdcBin * 1 .e -9 + nbc * o2::constants::lhc::LHCBunchSpacingNS;
412442
413443 auto key = o2::iotof::Digit::getOrderingKey (nbc, row, col);
0 commit comments