         // Save time value in apropiate bin
         for (int xpos = 0; xpos < num_x_tdet; xpos++){
           for (int ypos = 0; ypos < num_y_tdet; ypos++){
-            if ((fabsf(p.x - DeviceMem.tdet_pos_x[xpos]) + fabsf(p.x - DeviceMem.tdet_pos_x[xpos])) < (det_dc[0].temp_det_r) * (det_dc[0].temp_det_r)){
+            if ((fabsf(p.x - DeviceMem.tdet_pos_x[xpos]) + fabsf(p.y - DeviceMem.tdet_pos_y[ypos])) < (det_dc[0].temp_det_r) * (det_dc[0].temp_det_r)){
               // Inside time detector
               index = xpos + num_x_tdet*(ypos + num_y_tdet*__float2uint_rz(__fdividef(p.tof, det_dc[0].max_temp)*num_tbins));
               if (DeviceMem.time_xyt[index] + p.weight < LLONG_MAX) atomicAdd(&DeviceMem.time_xyt[index], p.weight); // Check for overflow and add atomically //TODO why LLONG_MAX?

            // Save time value in apropiate bin
            for (int xpos = 0; xpos < num_x_tdet; xpos++){
              for (int ypos = 0; ypos < num_y_tdet; ypos++){
                if ((fabsf(p.x - DeviceMem.tdet_pos_x[xpos]) + fabsf(p.x - DeviceMem.tdet_pos_x[xpos])) < (det_dc[0].temp_det_r) * (det_dc[0].temp_det_r)){
                  // Inside time detector
                  index = xpos + num_x_tdet*(ypos + num_y_tdet*__float2uint_rz(__fdividef(p.tof, det_dc[0].max_temp)*num_tbins));
                  if (DeviceMem.time_xyt[index] + p.weight < LLONG_MAX) atomicAdd(&DeviceMem.time_xyt[index], p.weight); // Check for overflow and add atomically //TODO why LLONG_MAX?

            // Save time value in apropiate bin
            for (int xpos = 0; xpos < num_x_tdet; xpos++){
              for (int ypos = 0; ypos < num_y_tdet; ypos++){
                if ((fabsf(p.x - DeviceMem.tdet_pos_x[xpos]) + fabsf(p.y - DeviceMem.tdet_pos_y[ypos])) < (det_dc[0].temp_det_r) * (det_dc[0].temp_det_r)){
                  // Inside time detector
                  index = xpos + num_x_tdet*(ypos + num_y_tdet*__float2uint_rz(__fdividef(p.tof, det_dc[0].max_temp)*num_tbins));
                  if (DeviceMem.time_xyt[index] + p.weight < LLONG_MAX) atomicAdd(&DeviceMem.time_xyt[index], p.weight); // Check for overflow and add atomically //TODO why LLONG_MAX?
