Commit in lcdd on MAIN
include/CellReadout2D.hh+65-341.1 -> 1.2
src/CellReadout2D.cc+74-551.1 -> 1.2
   /CellReadout2DSegmentation.cc+8-221.1 -> 1.2
+147-111
3 modified files

lcdd/include
CellReadout2D.hh 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- CellReadout2D.hh	30 May 2013 00:04:12 -0000	1.1
+++ CellReadout2D.hh	10 Jun 2013 19:42:47 -0000	1.2
@@ -5,121 +5,152 @@
 #include <map>
 
 /**
- * 2D cell readout with positive coordinate system originating
- * at the upper left of a box volume.  Cells are numbered from x,y = (1,1).
+ * This class defines and implements a 2D cell readout with positive coordinate
+ * system originating at the upper left of a box volume.  Cells are numbered from
+ * x,y = (1,1).  Unless otherwise noted, any reference to a "position" in the comments
+ * refers to coordinates in the readout's system.  Coordinates should be transformed into
+ * the readout's system by the caller such as a segmentation class.
  */
 class CellReadout2D
 {
 
 public:
 
+    /**
+     * A pair of cell indices.
+     */
 	typedef std::pair<int, int> Cell;
-	typedef std::pair<double, double> PositionXY;
 
+	/**
+	 * A 2D position in the readout.
+	 */
+	typedef std::pair<double, double> PositionXY;
 
+	/**
+	 * dtor
+	 */
     virtual ~CellReadout2D();
 
+    /**
+     * ctor
+     */
     CellReadout2D(double cellSizeX, double cellSizeY);
 
 	/**
 	 * Get the X cell size.
 	 */
-	virtual double getCellSizeX();
+	double getCellSizeX();
 
 	/**
 	 * Get the Y cell size.
 	 */
-	virtual double getCellSizeY();
+	double getCellSizeY();
 
 	/**
-	 * Get the full dimension of the readout in X.
+	 * Get the dimension of the readout in X.
 	 */
-	virtual double getDimensionX();
+	double getReadoutDimensionX();
 
 	/**
-	 * Get the full dimension of the readout in Y.
+	 * Get the dimension of the readout in Y.
 	 */
-	virtual double getDimensionY();
+	double getReadoutDimensionY();
 
 	/**
-	 * Get the local position of the cell.
+	 * Get the position of the cell.
 	 */
-	virtual PositionXY getPosition(Cell);
+	PositionXY getCellPosition(Cell);
 
 	/**
 	 * Get the cell from a position.
 	 */
-    virtual Cell getCell(PositionXY);
+    Cell getCell(PositionXY);
 
 	/**
-	 * Get the X bin from a position.
+	 * Get the X index from a position.
 	 */
-	virtual int getCellX(double x);
+	int getXIndex(double x);
 
 	/**
-	 * Get Y bin from a position.
+	 * Get the Y index from a position.
 	 */
-	virtual int getCellY(double y);
+	int getYIndex(double y);
 
 	/*
-	 * Get the X position from an X bin value.
+	 * Get the X position from a cell index.
 	 */
-	virtual double getPositionX(int x);
+	double getCellPositionX(int ix);
 
 	/**
 	 * Get the Y position from a Y bin value.
 	 */
-	virtual double getPositionY(int y);
+	double getCellPositionY(int iy);
 
 	/**
 	 * Get the neighbors of a cell.
 	 */
-	virtual std::vector<Cell> getNeighbors(Cell);
+	//std::vector<Cell> getNeighbors(Cell);
 
 	/**
-	 * Get a pair of indices representing a cell.  This method should check that the indices are valid.
+	 * Get a pair of indices representing a cell.
+	 * This method should check that the indices are valid.
 	 */
-	virtual Cell createCell(int x, int y);
+	Cell createCell(int x, int y);
 
 	/**
 	 * Check if an X index is valid.
 	 */
-	virtual bool isValidX(int x);
+	bool isValidXIndex(int x);
 
 	/**
 	 * Check if a Y index is valid.
 	 */
-	virtual bool isValidY(int y);
+	bool isValidYIndex(int y);
 
 	/**
-	 * Check if a local X position is inside this readout.
+	 * Check if an X position is inside this readout.
 	 */
-	virtual bool isInsideX(double x);
+	bool isCoordinateInsideX(double x);
 
 	/**
-	 * Check if a local Y position is inside this readout.
+	 * Check if a Y position is inside this readout.
 	 */
-	virtual bool isInsideY(double y);
+	bool isCoordinateInsideY(double y);
 
 	/**
-	 * Given a cell index, return the corresponding coordinate.
+	 * Given an index and cell size, compute the corresponding coordinate.
 	 */
-	virtual double getCoordinate(int u, double cellSize);
+	double getCellCoordinate(int u, double cellSize);
 
 	/**
-	 * Given a coordinate in the readout's reference frame, return the corresponding coordinate.
+	 * Given a coordinate and cell size, compute the corresponding cell index.
 	 */
-	virtual int getIndex(double x, double cellSize);
+	int getCellIndex(double x, double cellSize);
 
 	/**
 	 * Set the X dimension of the readout.
 	 */
-	virtual void setDimensionX(double x);
+	void setReadoutDimensionX(double x);
 
 	/**
 	 * Set the Y dimension of the readout.
 	 */
-	virtual void setDimensionY(double y);
+	void setReadoutDimensionY(double y);
+
+	/**
+	 * Get the maximum valid X index.
+	 */
+	int getMaximumXIndex();
+
+	/**
+	 * Get the maximum valid Y index.
+	 */
+	int getMaximumYIndex();
+
+	/**
+	 * Transform local XY coordinates into readout coordinates.
+	 */
+	PositionXY localToReadoutCoordinates(PositionXY xy);
 
 private:
 

lcdd/src
CellReadout2D.cc 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- CellReadout2D.cc	30 May 2013 00:04:12 -0000	1.1
+++ CellReadout2D.cc	10 Jun 2013 19:42:47 -0000	1.2
@@ -2,14 +2,15 @@
 
 #include <cmath>
 #include <iostream>
+#include <stdexcept>
 
 CellReadout2D::CellReadout2D(double cellSizeX, double cellSizeY)
-	//: m_cellSizeX(cellSizeX), m_cellSizeY(m_cellSizeY)
+//: m_cellSizeX(cellSizeX), m_cellSizeY(m_cellSizeY)
 {
     m_cellSizeX = cellSizeX;
     m_cellSizeY = cellSizeY;
     //std::cout << "args x,y: " << cellSizeX << " " << cellSizeY << std::endl;
-    std::cout << "CellReadout2D(x,y): " << m_cellSizeX << " " << m_cellSizeY << std::endl;
+    //std::cout << "CellReadout2D(x,y): " << m_cellSizeX << " " << m_cellSizeY << std::endl;
 }
 
 CellReadout2D::~CellReadout2D()
@@ -18,118 +19,136 @@
 
 double CellReadout2D::getCellSizeX()
 {
-	return m_cellSizeX;
+    return m_cellSizeX;
 }
 
 double CellReadout2D::getCellSizeY()
 {
-	return m_cellSizeY;
+    return m_cellSizeY;
 }
 
-double CellReadout2D::getDimensionX()
+double CellReadout2D::getReadoutDimensionX()
 {
-	return m_dimensionX;
+    return m_dimensionX;
 }
 
-double CellReadout2D::getDimensionY()
+double CellReadout2D::getReadoutDimensionY()
 {
-	return m_dimensionY;
+    return m_dimensionY;
 }
 
-int CellReadout2D::getCellX(double x)
+int CellReadout2D::getXIndex(double x)
 {
-	return getIndex(x, m_cellSizeX);
+    return getCellIndex(x, m_cellSizeX);
 }
 
-
-int CellReadout2D::getCellY(double y)
+int CellReadout2D::getYIndex(double y)
 {
-	return getIndex(y, m_cellSizeY);
+    return getCellIndex(y, m_cellSizeY);
 }
 
-CellReadout2D::PositionXY CellReadout2D::getPosition(CellReadout2D::Cell cell)
+CellReadout2D::PositionXY CellReadout2D::getCellPosition(CellReadout2D::Cell cell)
 {
-	int ix = cell.first;
-	int iy = cell.second;
-	PositionXY pos;
-	pos.first = getPositionX(ix);
-	pos.second = getPositionY(iy);
-	return pos;
+    int ix = cell.first;
+    int iy = cell.second;
+    PositionXY pos;
+    pos.first = getCellPositionX(ix);
+    pos.second = getCellPositionY(iy);
+    return pos;
 }
 
-double CellReadout2D::getCoordinate(int i, double cellSize)
+double CellReadout2D::getCellCoordinate(int i, double cellSize)
 {
-	return (i*cellSize)-cellSize/2;
+    return (i * cellSize) - cellSize / 2;
 }
 
-int CellReadout2D::getIndex(double x, double cellSize)
+int CellReadout2D::getCellIndex(double x, double cellSize)
 {
-    std::cout << "getIndex(x,cellSize): " << x << " " << cellSize << std::endl;
-    std::cout << "floor(x/cellSize): " << std::floor(x/cellSize) << std::endl;
-	return std::floor(x/cellSize)+1;
+    //std::cout << "getIndex(x,cellSize): " << x << " " << cellSize << std::endl;
+    //std::cout << "floor(x/cellSize): " << std::floor(x/cellSize) << std::endl;
+    return std::floor(x / cellSize) + 1;
 }
 
-double CellReadout2D::getPositionX(int ix)
+double CellReadout2D::getCellPositionX(int ix)
 {
-	return getCoordinate(ix, m_cellSizeX);
+    return getCellCoordinate(ix, m_cellSizeX);
 }
 
-double CellReadout2D::getPositionY(int iy)
+double CellReadout2D::getCellPositionY(int iy)
 {
-	return getCoordinate(iy, m_cellSizeY);
+    return getCellCoordinate(iy, m_cellSizeY);
 }
 
 CellReadout2D::Cell CellReadout2D::getCell(PositionXY xy)
 {
+    Cell cell = createCell(getXIndex(xy.first), getYIndex(xy.second));
+    return cell;
+}
+
+//std::vector<CellReadout2D::Cell> CellReadout2D::getNeighbors(CellReadout2D::Cell cell)
+//{
+//}
+
+CellReadout2D::Cell CellReadout2D::createCell(int x, int y)
+{
+    if (!isValidXIndex(x)) {
+        std::cerr << "X coordinate is outside readout: " << x << std::endl;
+        throw std::runtime_error("invalid X index");
+    }
+    if (!isValidYIndex(y)) {
+        std::cerr << "Y coordinate is outside readout: " << y << std::endl;
+        throw std::runtime_error("invalid Y index");
+    }
     Cell cell;
-    cell.first = getCellX(xy.first);
-    cell.second = getCellY(xy.second);
+    cell.first = x;
+    cell.second = y;
     return cell;
 }
 
-std::vector<CellReadout2D::Cell> CellReadout2D::getNeighbors(CellReadout2D::Cell cell)
+bool CellReadout2D::isValidXIndex(int x)
 {
-	// TODO: implement me
+    return x > 0 && x <= getMaximumXIndex();
 }
 
-CellReadout2D::Cell CellReadout2D::createCell(int x, int y)
+bool CellReadout2D::isValidYIndex(int y)
+{
+    return y > 0 && y <= getMaximumYIndex();
+}
+
+bool CellReadout2D::isCoordinateInsideX(double x)
 {
-	Cell cell;
-	cell.first = x;
-	cell.second = y;
-	return cell;
+    return x >= 0 && x <= getReadoutDimensionX();
 }
 
-bool CellReadout2D::isValidX(int x)
+bool CellReadout2D::isCoordinateInsideY(double y)
 {
-	// FIXME: dummy implementation
-	return true;
+    return y >= 1 && y <= getReadoutDimensionY();
 }
 
-bool CellReadout2D::isValidY(int y)
+void CellReadout2D::setReadoutDimensionX(double dimensionX)
 {
-	// FIXME: dummy implementation
-	return true;
+    m_dimensionX = dimensionX;
 }
 
-bool CellReadout2D::isInsideX(double x)
+void CellReadout2D::setReadoutDimensionY(double dimensionY)
 {
-	// FIXME: dummy implementation
-	return true;
+    m_dimensionY = dimensionY;
 }
 
-bool CellReadout2D::isInsideY(double y)
+int CellReadout2D::getMaximumXIndex()
 {
-	// FIXME: dummy implementation
-	return true;
+    return getXIndex(getReadoutDimensionX());
 }
 
-void CellReadout2D::setDimensionX(double dimensionX)
+int CellReadout2D::getMaximumYIndex()
 {
-	m_dimensionX = dimensionX;
+    return getYIndex(getReadoutDimensionY());
 }
 
-void CellReadout2D::setDimensionY(double dimensionY)
+CellReadout2D::PositionXY CellReadout2D::localToReadoutCoordinates(CellReadout2D::PositionXY localPos)
 {
-	m_dimensionY = dimensionY;
+    CellReadout2D::PositionXY readoutPos;
+    readoutPos.first = localPos.first + this->getReadoutDimensionX() / 2.0;
+    readoutPos.second = localPos.second + this->getReadoutDimensionY() / 2.0;
+    return readoutPos;
 }

lcdd/src
CellReadout2DSegmentation.cc 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- CellReadout2DSegmentation.cc	30 May 2013 00:04:12 -0000	1.1
+++ CellReadout2DSegmentation.cc	10 Jun 2013 19:42:47 -0000	1.2
@@ -27,41 +27,27 @@
 
 void CellReadout2DSegmentation::setBins(const G4Step* aStep)
 {
-    std::cout << "setBins" << std::endl;
-
-    std::cout << "cellSize(x,y): " << m_readout->getCellSizeX() << " " << m_readout->getCellSizeY() << std::endl;
-
     // Set state from current step.
     setup(aStep);
 
-    std::cout.precision(15);
-
-    std::cout << "dimension x: " << m_readout->getDimensionX() << std::endl;
-    std::cout << "dimension y: " << m_readout->getDimensionY() << std::endl;
-
     // Compute the global mid-point of the step.
     G4ThreeVector globalStepPos = ReadoutUtil::computeMidPos(aStep);
 
     // Compute the local step position from the global mid-point.
     G4ThreeVector localStepPos = ReadoutUtil::transformGlobalToLocal(aStep, globalStepPos);
 
-    std::cout << "localStepPos: " << localStepPos.x() << ", " << localStepPos.y() << ", " << localStepPos.z() << std::endl;
-
     // Compute the X and Y readout coordinates from the local position.
-    CellReadout2D::PositionXY xy = localToReadoutCoordinates(localStepPos);
-
-    std::cout << "readout coordinates: " << xy.first << " " << xy.second << std::endl;
+    CellReadout2D::PositionXY localXY;
+    localXY.first = localStepPos.x();
+    localXY.second = localStepPos.y();
+    CellReadout2D::PositionXY xy = m_readout->localToReadoutCoordinates(localXY);
 
     // Get the cell for the position.
     CellReadout2D::Cell cell = m_readout->getCell(xy);
 
-    std::cout << "cell(ix,iy): " << cell.first << " " << cell.second << std::endl;
-
     // Set bin values.
     this->setBin(0, xy.first);
     this->setBin(1, xy.second);
-
-    std::cout << std::endl;
 }
 
 void CellReadout2DSegmentation::setBinNames()
@@ -79,14 +65,14 @@
         std::cerr << "Volume is not a box" << std::endl;
         G4Exception("", "", FatalException, "CellReadout2D points to shape that is not a box.");
     }
-    m_readout->setDimensionX(box->GetXHalfLength() * 2);
-    m_readout->setDimensionY(box->GetYHalfLength() * 2);
+    m_readout->setReadoutDimensionX(box->GetXHalfLength() * 2);
+    m_readout->setReadoutDimensionY(box->GetYHalfLength() * 2);
 }
 
 CellReadout2D::PositionXY CellReadout2DSegmentation::localToReadoutCoordinates(G4ThreeVector& vec)
 {
     CellReadout2D::PositionXY xy;
-    xy.first = vec.x() + m_readout->getDimensionX() / 2.0;
-    xy.second = vec.y() + m_readout->getDimensionY() / 2.0;
+    xy.first = vec.x() + m_readout->getReadoutDimensionX() / 2.0;
+    xy.second = vec.y() + m_readout->getReadoutDimensionY() / 2.0;
     return xy;
 }
CVSspam 0.2.12


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