GeomConverter/src/org/lcsim/detector/tracker/silicon
diff -u -r1.8 -r1.9
--- SiPixels.java 7 May 2009 22:33:44 -0000 1.8
+++ SiPixels.java 22 Sep 2009 18:26:53 -0000 1.9
@@ -112,12 +112,20 @@
// Neigbor ncells away along each axis
public int getNeighborCell(int cell_id, int ncells_row, int ncells_col) {
- int neighbor = cell_id + ncells_row * _ncols + ncells_col;
- if (isValidCell(neighbor)) {
- return neighbor;
- } else {
- return -1;
- }
+
+ // Get the column and row numbers of the neighbor cell
+ int nbrcol = getColumnNumber(cell_id) + ncells_col;
+ int nbrrow = getRowNumber(cell_id) + ncells_row;
+
+ // Get teh neighbor cell ID and check that it's valid
+ int nbrcell = getCellID(nbrrow, nbrcol);
+ if (nbrcell < 0) return nbrcell;
+
+ // Check that the cell is valid (needed for non-rectangular geometries)
+ if (!isValidCell(cell_id)) return -1;
+
+ // Valid neighbor - return the cell ID
+ return nbrcell;
}
// Get all nearest neighbor cells
@@ -186,6 +194,8 @@
// ID of cell from row and column number
public int getCellID(int row_number, int column_number) {
+ if (row_number < 0 || row_number >=_nrows) return -1;
+ if (column_number < 0 || column_number >= _ncols) return -1;
return row_number * _ncols + column_number;
}
@@ -348,7 +358,7 @@
int ipixel = getCellID(ixmin + ix, iymin + iy);
// Make sure we have a valid pixel
- if (isValidCell(ipixel)) {
+ if (ipixel >= 0) {
// Calculate the charge in this pixel
int pixel_charge = (int) Math.round(normalization * prob[ix][iy]);