Commit in lcdd on MAIN | |||
include/lcdd/detectors/CellReadout.hh | +1 | -16 | 1.8 -> 1.9 |
/CellReadout2D.hh | +17 | -1 | 1.7 -> 1.8 |
src/lcdd/detectors/CellReadout2D.cc | +51 | -76 | 1.3 -> 1.4 |
/CellReadout2DSegmentation.cc | +9 | -1 | 1.5 -> 1.6 |
+78 | -94 |
implement neighboring for CellReadout2D
diff -u -r1.8 -r1.9 --- CellReadout.hh 6 Sep 2013 02:17:48 -0000 1.8 +++ CellReadout.hh 6 Sep 2013 03:29:23 -0000 1.9 @@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/include/lcdd/detectors/CellReadout.hh,v 1.8 2013/09/06 02:17:48 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/include/lcdd/detectors/CellReadout.hh,v 1.9 2013/09/06 03:29:23 jeremy Exp $
#ifndef LCDD_DETECTORS_CELLREADOUT_HH #define LCDD_DETECTORS_CELLREADOUT_HH 1
@@ -18,7 +18,6 @@
public: /** A 2D position, which will usually be XY in the local coordinate system. */
- //typedef std::pair<double, double> Position2D;
struct Position2D { double x;
@@ -31,9 +30,6 @@
/** A list of a cell's neighbor IDs. */ typedef std::vector<CellId> Neighbors;
- /** A list of the field names for this readout. */ - //typedef std::vector<std::string> FieldNames; -
public: /**
@@ -66,17 +62,6 @@
* @return The list of Neighbors for the given CellId. */ virtual Neighbors neighbors(CellId id) = 0;
- - /** - * Get the list of field names. - * @return The list of field names defined by the readout. - */ - //const FieldNames& fieldNames(); - -//protected: - - /** The list of field names. */ - //FieldNames _fieldNames;
}; #endif
diff -u -r1.7 -r1.8 --- CellReadout2D.hh 6 Sep 2013 02:17:48 -0000 1.7 +++ CellReadout2D.hh 6 Sep 2013 03:29:23 -0000 1.8 @@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/include/lcdd/detectors/CellReadout2D.hh,v 1.7 2013/09/06 02:17:48 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/include/lcdd/detectors/CellReadout2D.hh,v 1.8 2013/09/06 03:29:23 jeremy Exp $
#ifndef LCDD_DETECTORS_CELLREADOUT2D_HH #define LCDD_DETECTORS_CELLREADOUT2D_HH 1
@@ -54,6 +54,8 @@
/** * ----------------------------------------------------------
+ * Functionality specific to this implementation. + * ----------------------------------------------------------
*/ /**
@@ -142,6 +144,20 @@
*/ double getDimensionY();
+ /** + * Check if a CellId is valid. + * @param[in] The CellId to check. + * @return True if valid; false if not. + */ + bool isValidCell(CellId cell); + + /** + * Check if a Position2D is valid. + * @param[in] The position to check. + * @return True if valid; false if not. + */ + bool isValidPosition(Position2D position); +
private: double _cellSizeX;
diff -u -r1.3 -r1.4 --- CellReadout2D.cc 6 Sep 2013 02:17:48 -0000 1.3 +++ CellReadout2D.cc 6 Sep 2013 03:29:23 -0000 1.4 @@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/lcdd/detectors/CellReadout2D.cc,v 1.3 2013/09/06 02:17:48 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/lcdd/detectors/CellReadout2D.cc,v 1.4 2013/09/06 03:29:23 jeremy Exp $
// LCDD #include "lcdd/detectors/CellReadout2D.hh"
@@ -9,12 +9,8 @@
#include <stdexcept> CellReadout2D::CellReadout2D(double cellSizeX, double cellSizeY)
+ : _cellSizeX(cellSizeX), _cellSizeY(cellSizeY), _dimensionX(0.), _dimensionY(0.)
{
- _cellSizeX = cellSizeX; - _cellSizeY = cellSizeY; - - //_fieldNames.push_back("ix"); - //_fieldNames.push_back("iy");
} CellReadout2D::~CellReadout2D()
@@ -34,80 +30,28 @@
return createCell(getXIndex(position.x), getYIndex(position.y)); }
-/** - * Create a list of neighbor cells from a cell ID. - */
CellReadout::Neighbors CellReadout2D::neighbors(CellId cellId) { Neighbors neighbors;
+ CellId cell;
- /* - int ix, iy; - - // top left - ix = cellId[0] - 1; - if (ix == 0) - ix = -1; - iy = cellId[1] + 1; - if (iy == 0) - iy = 1; - neighbors.push_back(createCell(ix, iy)); - - // top middle - ix = cellId[0]; - iy = cellId[1] + 1; - if (iy == 0) - iy = 1; - neighbors.push_back(createCell(ix, iy)); - - // top right - ix = cellId[0]; - if (ix == 0) - ix = 1; - iy = cellId[1] + 1; - if (iy == 0) - iy = 1; - neighbors.push_back(createCell(ix, iy)); - - // middle left - ix = cellId[0] - 1; - if (ix == 0) - ix = -1; - iy = cellId[1]; - neighbors.push_back(createCell(ix, iy)); - - // middle right - ix = cellId[0] + 1; - if (ix == 0) - ix = 1; - iy = cellId[1]; - neighbors.push_back(createCell(ix, iy)); - - // bottom left - ix = cellId[0] - 1; - if (ix == 0) - ix = -1; - iy = cellId[1] - 1; - if (iy == 0) - iy = -1; - neighbors.push_back(createCell(ix - 1, iy - 1)); - - // bottom middle - ix = cellId[0]; - iy = cellId[1] - 1; - if (iy == 0) - iy = -1; - neighbors.push_back(createCell(ix, iy - 1)); - - // bottom right - ix = cellId[0] + 1; - if (ix == 0) - ix = 1; - iy = cellId[1] - 1; - if (iy == 0) - iy = -1; - neighbors.push_back(createCell(ix, iy - 1)); - */
+ // Loop over delta Y. + for (int i = -1; i <= 1; i++) { + // Loop over delta X. + for (int j = -1; j <= 1; j++) { + // Ignore this cell. + if (i != 0 || j != 0) { + // Create CellId for this neighbor. + std::cout << "creating neighbor i, j: " << i << ", " << j << std::endl; + cell = createCell(cellId[0] + j, cellId[1] + i); + // Check if valid. + if (isValidCell(cell)) { + // Add if cell is valid. + neighbors.push_back(cell); + } + } + } + }
return neighbors;
@@ -184,3 +128,34 @@
return _dimensionY; }
+bool CellReadout2D::isValidCell(CellId cell) +{ + // DEBUG + std::cout << "isValidCell: " << cell[0] << ", " << cell[1] << std::endl; + + if (cell[0] <= 0 || cell[1] <= 0) { + std::cout << "field value < 0" << std::endl; + return false; + } + int xmax = std::floor(getDimensionX() / getCellSizeX()); + std::cout << "xmax: " << xmax << std::endl; + if (cell[0] > xmax) { + std::cout << cell[0] << " exceeds max allowed X index" << std::endl; + return false; + } + int ymax = std::floor(getDimensionY() / getCellSizeY()); + std::cout << "ymax: " << ymax << std::endl; + if (cell[1] > ymax) { + std::cout << cell[1] << " exceeds max allowed Y index" << std::endl; + return false; + } + return true; +} + +bool CellReadout2D::isValidPosition(Position2D position) +{ + if (position.x > getDimensionX() || position.x < 0) return false; + if (position.y > getDimensionY() || position.y < 0) return false; + return true; +} +
diff -u -r1.5 -r1.6 --- CellReadout2DSegmentation.cc 6 Sep 2013 02:17:48 -0000 1.5 +++ CellReadout2DSegmentation.cc 6 Sep 2013 03:29:23 -0000 1.6 @@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/lcdd/detectors/CellReadout2DSegmentation.cc,v 1.5 2013/09/06 02:17:48 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/lcdd/detectors/CellReadout2DSegmentation.cc,v 1.6 2013/09/06 03:29:23 jeremy Exp $
// LCDD #include "lcdd/detectors/CellReadout2DSegmentation.hh"
@@ -124,6 +124,14 @@
this->setBin(0, cellPosition.x); this->setBin(1, cellPosition.y);
+ // DEBUG + // print the neighbor CellIds + CellReadout::Neighbors neighbors = _readout->neighbors(cell); + std::cout << "neighbors: " << std::endl; + for (CellReadout::Neighbors::const_iterator it = neighbors.begin(); it != neighbors.end(); it++) { + std::cout << " " << (*it)[0] << ", " << (*it)[1] << std::endl; + } +
std::cout << std::endl; }
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1