@@ -126,51 +126,55 @@ void Digitizer::processHit(const o2::itsmft::Hit& hit, int evID, int srcID)
126126 double absoluteTime = hitTime + eventTimeNS; // absolute time
127127 double smearedTime = smearTime (absoluteTime); // apply detector resolution
128128
129- // For now, use simple row/col mapping from detector ID
130- // TODO: Implement proper segmentation when geometry is finalized
131- uint16_t chipIndex = static_cast <uint16_t >(chipID);
132-
133129 if (chipID < 0 || chipID >= mGeometry ->getSize () || mGeometry ->getSize () < 1 ) {
134130 LOG (debug) << " Invalid detector ID: " << chipID << " , geometry size: " << mGeometry ->getSize ();
135131 return ; // invalid detector ID
136132 }
137-
138- // stepping is called here
139- float ** respMatrix = nullptr ;
140- int rowStart = 0 , colStart = 0 , rowSpan = 0 , colSpan = 0 ;
141- stepping (hit, respMatrix, rowStart, colStart, rowSpan, colSpan);
142-
133+
143134 // Create the digit with time information
144135 o2::MCCompLabel label (hit.GetTrackID (), evID, srcID, false );
145136 const int roFrameAbs = 0 ; // For now, we can set this to 0 or calculate based on time if needed
146137 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
147- for (int irow = rowSpan; irow--;) {
148- uint16_t rowIS = irow + rowStart;
149- for (int icol = colSpan; icol--;) {
150- uint16_t colIS = icol + colStart;
151- float nEleResp = respMatrix[irow][icol];
152- if (!nEleResp) {
153- continue ;
138+
139+
140+ if (digitizerParams.performStepping ) {
141+ float ** respMatrix = nullptr ;
142+ int rowStart = 0 , colStart = 0 , rowSpan = 0 , colSpan = 0 ;
143+ stepping (hit, respMatrix, rowStart, colStart, rowSpan, colSpan);
144+
145+ for (int irow = rowSpan; irow--;) {
146+ uint16_t rowIS = irow + rowStart;
147+ for (int icol = colSpan; icol--;) {
148+ uint16_t colIS = icol + colStart;
149+ float nEleResp = respMatrix[irow][icol];
150+ if (!nEleResp) {
151+ continue ;
152+ }
153+ const int nElectronsSampled = gRandom ->Poisson (electronsPerStep * nEleResp);
154+ // Noise can be added here if needed
155+
156+ registerDigits (chip, roFrameAbs, smearedTime, nROF,
157+ static_cast <uint16_t >(rowIS), static_cast <uint16_t >(colIS), nElectronsSampled, label);
154158 }
155- int nElectronsSampled = gRandom ->Poisson (electronsPerStep * nEleResp);
156- // Noise can be added here if needed
157-
158- registerDigits (chip, roFrameAbs, smearedTime, nROF,
159- static_cast <uint16_t >(rowIS), static_cast <uint16_t >(colIS), nElectronsSampled, label);
160159 }
161- }
162160
163- for (int irow = 0 ; irow < rowSpan; ++irow) {
164- delete[] respMatrix[irow];
161+ for (int irow = 0 ; irow < rowSpan; ++irow) {
162+ delete[] respMatrix[irow];
163+ }
164+ delete[] respMatrix;
165+ } else {
166+ int row = 0 , col = 0 ;
167+ responseInTheMiddle (hit, row, col);
168+ const int nElectronsSampled = gRandom ->Poisson (charge);
169+ registerDigits (chip, roFrameAbs, smearedTime, nROF, static_cast <uint16_t >(row), static_cast <uint16_t >(col), nElectronsSampled, label);
165170 }
166- delete[] respMatrix;
167171}
168172
169173void Digitizer::stepping (const o2::itsmft::Hit& hit, float **& respMatrix, int & rowStart, int & colStart, int & rowSpan, int & colSpan)
170174{
171175 const auto & matrix = mGeometry ->getMatrixL2G (hit.GetDetectorID ());
172176 const int chipID = hit.GetDetectorID ();
173- const int subdetectorID = mGeometry ->getIOTOFLayer ();
177+ const int subdetectorID = mGeometry ->getIOTOFLayer (chipID );
174178
175179 auto xyzPositionStart (matrix ^ (hit.GetPosStart ())); // start position in sensor frame
176180 auto xyzPositionEnd (matrix ^ (hit.GetPos ())); // end position in sensor frame
@@ -256,6 +260,23 @@ void Digitizer::stepping(const o2::itsmft::Hit& hit, float**& respMatrix, int& r
256260 }
257261}
258262
263+ void Digitizer::responseInTheMiddle (const o2::itsmft::Hit& hit, int & row, int & col)
264+ {
265+ const auto & matrix = mGeometry ->getMatrixL2G (hit.GetDetectorID ());
266+ const int chipID = hit.GetDetectorID ();
267+
268+ math_utils::Vector3D<float > xyzPositionStart (matrix ^ (hit.GetPosStart ())); // start position in sensor frame
269+ math_utils::Vector3D<float > xyzPositionEnd (matrix ^ (hit.GetPos ())); // end position in sensor frame
270+
271+ // Calculate the middle position of the hit
272+ math_utils::Vector3D<float > xyzPositionMiddle = (xyzPositionStart + xyzPositionEnd) * 0 .5f ;
273+
274+ if (!sSegmentation ->localToDetector (xyzPositionMiddle.X (), xyzPositionMiddle.Z (), row, col, mGeometry ->getIOTOFLayer (chipID))) {
275+ LOG (debug) << " Hit position out of bounds for detector ID " << chipID;
276+ return ; // hit is outside the active area
277+ }
278+ }
279+
259280// _______________________________________________________________________
260281double Digitizer::smearTime (double time) const
261282{
0 commit comments