Commit in lcdd on MAIN
include/lcdd/detectors/CellReadout.hh+12-71.7 -> 1.8
                      /CellReadout2D.hh+29-21.6 -> 1.7
                      /CellReadout2DSegmentation.hh+9-31.7 -> 1.8
src/lcdd/detectors/CellReadout.cc+5-51.2 -> 1.3
                  /CellReadout2D.cc+35-161.2 -> 1.3
                  /CellReadout2DSegmentation.cc+103-201.4 -> 1.5
+193-53
6 modified files
work in progress on new cell segmentation interface; change from signed to unsigned coordinate system in CellReadout2D; implement CelReadout2DSegmentation::getGlobalHitPosition; other minor changes and refactorings

lcdd/include/lcdd/detectors
CellReadout.hh 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- CellReadout.hh	10 Jul 2013 18:06:17 -0000	1.7
+++ CellReadout.hh	6 Sep 2013 02:17:48 -0000	1.8
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/include/lcdd/detectors/CellReadout.hh,v 1.7 2013/07/10 18:06:17 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/include/lcdd/detectors/CellReadout.hh,v 1.8 2013/09/06 02:17:48 jeremy Exp $
 
 #ifndef LCDD_DETECTORS_CELLREADOUT_HH
 #define LCDD_DETECTORS_CELLREADOUT_HH 1
@@ -18,16 +18,21 @@
 public:
 
     /** A 2D position, which will usually be XY in the local coordinate system. */
-    typedef std::pair<double, double> Position2D;
+    //typedef std::pair<double, double> Position2D;
+    struct Position2D
+    {
+        double x;
+        double y;
+    };
 
-    /** A cell ID as a list of int values. */
+    /** A cell ID represented as a list of int values. */
     typedef std::vector<int> CellId;
 
     /** 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;
+    //typedef std::vector<std::string> FieldNames;
 
 public:
 
@@ -66,12 +71,12 @@
      * Get the list of field names.
      * @return The list of field names defined by the readout.
      */
-    const FieldNames& fieldNames();
+    //const FieldNames& fieldNames();
 
-protected:
+//protected:
 
     /** The list of field names. */
-    FieldNames _fieldNames;
+    //FieldNames _fieldNames;
 };
 
 #endif

lcdd/include/lcdd/detectors
CellReadout2D.hh 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- CellReadout2D.hh	10 Jul 2013 16:49:45 -0000	1.6
+++ CellReadout2D.hh	6 Sep 2013 02:17:48 -0000	1.7
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/include/lcdd/detectors/CellReadout2D.hh,v 1.6 2013/07/10 16:49:45 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/include/lcdd/detectors/CellReadout2D.hh,v 1.7 2013/09/06 02:17:48 jeremy Exp $
 
 #ifndef LCDD_DETECTORS_CELLREADOUT2D_HH
 #define LCDD_DETECTORS_CELLREADOUT2D_HH 1
@@ -12,7 +12,6 @@
 
 /**
  * @brief A concrete implementation of CellReadout using a 2D grid.
- * @todo Move to DDSegmentation package.
  */
 class CellReadout2D: public CellReadout
 {
@@ -118,10 +117,38 @@
      */
     int getCellIndex(double x, double cellSize);
 
+    /**
+     * Set the current X dimension.
+     * @param[in] dimensionX The dimension in X.
+     */
+    void setDimensionX(double dimensionX);
+
+    /**
+     * Set the current Y dimension.
+     * @param[in] dimensionY The dimension in Y.
+     */
+
+    void setDimensionY(double dimensionY);
+
+    /**
+     * Get the current dimension in X.
+     * @return The dimension in X.
+     */
+    double getDimensionX();
+
+    /**
+     * Get the current dimension in Y.
+     * @return The dimension in Y.
+     */
+    double getDimensionY();
+
 private:
 
     double _cellSizeX;
     double _cellSizeY;
+
+    double _dimensionX;
+    double _dimensionY;
 };
 
 #endif

lcdd/include/lcdd/detectors
CellReadout2DSegmentation.hh 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- CellReadout2DSegmentation.hh	11 Jul 2013 20:41:53 -0000	1.7
+++ CellReadout2DSegmentation.hh	6 Sep 2013 02:17:48 -0000	1.8
@@ -11,7 +11,7 @@
 class G4Step;
 
 /**
- * @brief Adapt a CellReadout2D to the LCDD Segmentation interface.
+ * @brief Adapt a CellReadout2D object to the LCDD Segmentation interface.
  */
 class CellReadout2DSegmentation: public Segmentation
 {
@@ -49,7 +49,7 @@
     void setBinNames();
 
     /**
-     * Setup the Segmentation from the G4Step.
+     * Setup derived state of the Segmentation from a G4Step.
      * @param[in] The G4Step object.
      */
     void setup(const G4Step* step);
@@ -59,7 +59,13 @@
      * @param[in] pos The local position.
      * @return The readout coordinates.
      */
-    CellReadout2D::Position2D localToReadoutCoordinates(G4ThreeVector& pos);
+    CellReadout::Position2D localToReadoutCoordinates(G4ThreeVector& pos);
+
+    /**
+     * Convert unsigned readout coordinates back to local.
+     * @return The local coordinates converted from readout XY position.
+     */
+    G4ThreeVector readoutToLocalCoordinates(CellReadout::Position2D position);
 
 private:
 

lcdd/src/lcdd/detectors
CellReadout.cc 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- CellReadout.cc	10 Jul 2013 16:49:47 -0000	1.2
+++ CellReadout.cc	6 Sep 2013 02:17:48 -0000	1.3
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/lcdd/detectors/CellReadout.cc,v 1.2 2013/07/10 16:49:47 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/lcdd/detectors/CellReadout.cc,v 1.3 2013/09/06 02:17:48 jeremy Exp $
 
 #include "lcdd/detectors/CellReadout.hh"
 
@@ -13,7 +13,7 @@
 /**
  * Get the list of field names.
  */
-const CellReadout::FieldNames& CellReadout::fieldNames()
-{
-    return _fieldNames;
-}
+//const CellReadout::FieldNames& CellReadout::fieldNames()
+//{
+//    return _fieldNames;
+//}

lcdd/src/lcdd/detectors
CellReadout2D.cc 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- CellReadout2D.cc	10 Jul 2013 16:49:47 -0000	1.2
+++ CellReadout2D.cc	6 Sep 2013 02:17:48 -0000	1.3
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/lcdd/detectors/CellReadout2D.cc,v 1.2 2013/07/10 16:49:47 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/lcdd/detectors/CellReadout2D.cc,v 1.3 2013/09/06 02:17:48 jeremy Exp $
 
 // LCDD
 #include "lcdd/detectors/CellReadout2D.hh"
@@ -13,8 +13,8 @@
     _cellSizeX = cellSizeX;
     _cellSizeY = cellSizeY;
 
-    _fieldNames.push_back("ix");
-    _fieldNames.push_back("iy");
+    //_fieldNames.push_back("ix");
+    //_fieldNames.push_back("iy");
 }
 
 CellReadout2D::~CellReadout2D()
@@ -23,15 +23,15 @@
 
 CellReadout2D::Position2D CellReadout2D::position(CellReadout2D::CellId cellId)
 {
-    Position2D pos;
-    pos.first = getCellPositionX(cellId[0]);
-    pos.second = getCellPositionY(cellId[1]);
-    return pos;
+    Position2D position;
+    position.x = getCellPositionX(cellId[0]);
+    position.y = getCellPositionY(cellId[1]);
+    return position;
 }
 
-CellReadout::CellId CellReadout2D::cellId(Position2D pos)
+CellReadout::CellId CellReadout2D::cellId(Position2D position)
 {
-    return createCell(getXIndex(pos.first), getYIndex(pos.second));
+    return createCell(getXIndex(position.x), getYIndex(position.y));
 }
 
 /**
@@ -40,6 +40,8 @@
 CellReadout::Neighbors CellReadout2D::neighbors(CellId cellId)
 {
     Neighbors neighbors;
+
+    /*
     int ix, iy;
 
     // top left
@@ -105,6 +107,7 @@
     if (iy == 0)
         iy = -1;
     neighbors.push_back(createCell(ix, iy - 1));
+    */
 
     return neighbors;
 
@@ -132,19 +135,14 @@
 
 double CellReadout2D::getCellCoordinate(int i, double cellSize)
 {
-    double v = i * cellSize;
-    if (v > 0)
-        v -= cellSize / 2;
-    else
-        v += cellSize / 2;
-    return v;
+    return (i * cellSize) - cellSize / 2;
 }
 
 int CellReadout2D::getCellIndex(double c, double cellSize)
 {
     int v = std::ceil(c / cellSize);
     if (v == 0)
-        v -= 1;
+        v = 1;
     return v;
 }
 
@@ -165,3 +163,24 @@
     cell.push_back(y);
     return cell;
 }
+
+void CellReadout2D::setDimensionX(double dimensionX)
+{
+    _dimensionX = dimensionX;
+}
+
+void CellReadout2D::setDimensionY(double dimensionY)
+{
+    _dimensionY = dimensionY;
+}
+
+double CellReadout2D::getDimensionX()
+{
+    return _dimensionX;
+}
+
+double CellReadout2D::getDimensionY()
+{
+    return _dimensionY;
+}
+

lcdd/src/lcdd/detectors
CellReadout2DSegmentation.cc 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- CellReadout2DSegmentation.cc	11 Jul 2013 20:41:54 -0000	1.4
+++ CellReadout2DSegmentation.cc	6 Sep 2013 02:17:48 -0000	1.5
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/lcdd/detectors/CellReadout2DSegmentation.cc,v 1.4 2013/07/11 20:41:54 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/lcdd/detectors/CellReadout2DSegmentation.cc,v 1.5 2013/09/06 02:17:48 jeremy Exp $
 
 // LCDD
 #include "lcdd/detectors/CellReadout2DSegmentation.hh"
@@ -25,33 +25,106 @@
 
 G4ThreeVector CellReadout2DSegmentation::getGlobalHitPosition(const G4Step* aStep)
 {
-    // TODO: implement me
+    std::cout << "CellReadout2DSegmentation::getGlobalHitPosition" << std::endl;
+
+    // Setup the readout with step dependent information.
+    setup(aStep);
+
+    // Compute the mid-point of the global step.
+    G4ThreeVector globalStepPosition = ReadoutUtil::computeMidPos(aStep);
+
+    // DEBUG
+    std::cout << "globalStepPosition: " << globalStepPosition.x() << " " << globalStepPosition.y() << " " << globalStepPosition.z() << std::endl;
+
+    // Compute the local step position.
+    G4ThreeVector localStepPosition = ReadoutUtil::transformGlobalToLocal(aStep, globalStepPosition);
+
+    // DEBUG
+    std::cout << "localStepPosition: " << localStepPosition.x() << " " << localStepPosition.y() << " " << localStepPosition.z() << std::endl;
+
+    // Convert into readout coordinates.
+    CellReadout::Position2D readoutStepPosition = localToReadoutCoordinates(localStepPosition);
+
+    // DEBUG
+    std::cout << "readoutStepPosition: " << readoutStepPosition.x << " " << readoutStepPosition.y << std::endl;
+
+    // Compute the cell indices from the position.
+    CellReadout::CellId cell = _readout->cellId(readoutStepPosition);
+
+    // DEBUG
+    std::cout << "cell: " << cell[0] << " " << cell[1] << std::endl;
+
+    // Get the cell's readout position from the cell ID.
+    CellReadout::Position2D cellPosition = _readout->position(cell);
+
+    // DEBUG
+    std::cout << "cellPosition: " << cellPosition.x << " " << cellPosition.y << std::endl;
+
+    // Convert from readout back to localcoordinates.
+    G4ThreeVector localCellPosition = readoutToLocalCoordinates(cellPosition);
+
+    // DEBUG
+    std::cout << "localCellPosition: "<< localCellPosition.x() << " " << localCellPosition.y() << " " << localCellPosition.z() << std::endl;
+
+    // Finally convert from the local coordinates into global.
+    G4ThreeVector globalCellPosition = ReadoutUtil::transformLocalToGlobal(aStep, localCellPosition);
+
+    // DEBUG
+    std::cout << "globalCellPosition: "
+            << globalCellPosition.x() << " "
+            << globalCellPosition.y() << " "
+            << globalCellPosition.z() << std::endl;
+
+    std::cout << std::endl;
+
+    return globalCellPosition;
 }
 
 void CellReadout2DSegmentation::setBins(const G4Step* aStep)
 {
+    // DEBUG
+    std::cout << "CellReadout2DSegmentation::setBins" << std::endl;
+
+    // Setup the readout with step dependent information.
+    setup(aStep);
+
+    // DEBUG
+    G4ThreeVector prePosition = aStep->GetPreStepPoint()->GetPosition();
+    std::setprecision(10);
+    std::cout << "pre-step pos: " << prePosition.x() << " " << prePosition.y() << " " << prePosition.z() << std::endl;
+
     // Set state from current step.
     setup(aStep);
 
     // Compute the global mid-point of the step.
     G4ThreeVector globalStepPos = ReadoutUtil::computeMidPos(aStep);
 
+    // DEBUG
+    std::cout << "globalStepPos: " << globalStepPos.x() << " " << globalStepPos.y() << " " << globalStepPos.z() << std::endl;
+
     // Compute the local step position from the global mid-point.
     G4ThreeVector localStepPos = ReadoutUtil::transformGlobalToLocal(aStep, globalStepPos);
 
+    // DEBUG
+    std::cout << "localStepPos: " << localStepPos.x() << " " << localStepPos.y() << " " << localStepPos.z() << std::endl;
+
     // Compute the X and Y readout coordinates from the local position.
-    CellReadout2D::Position2D localXY;
-    localXY.first = localStepPos.x();
-    localXY.second = localStepPos.y();
-    CellReadout2D::Position2D xy;
-    //= m_readout->localToReadoutCoordinates(localXY);
+    CellReadout::Position2D cellPosition = localToReadoutCoordinates(localStepPos);
+
+    // DEBUG
+    std::cout << "cell pos XY: " << cellPosition.x << " " << cellPosition.y << std::endl;
 
     // Get the cell for the position.
-    CellReadout2D::CellId cell = _readout->cellId(xy);
+    CellReadout::CellId cell = _readout->cellId(cellPosition);
+
+    // DEBUG
+    std::cout << "cell ID: " << cell[0] << " " << cell[1] << std::endl;
 
-    // Set bin values.
-    this->setBin(0, xy.first);
-    this->setBin(1, xy.second);
+    // Set the segmentation's bin values.
+    this->setBin(0, cellPosition.x);
+    this->setBin(1, cellPosition.y);
+
+    std::cout << std::endl;
 }
 
 void CellReadout2DSegmentation::setBinNames()
@@ -65,18 +138,28 @@
     // Set dimensions from box volume.
     G4VSolid* solid = ReadoutUtil::getSolidFromStepPoint(aStep->GetPreStepPoint());
     G4Box* box = dynamic_cast<G4Box*>(solid);
-    if (0 == box) {
+    if (box == 0) {
         std::cerr << "Volume is not a box" << std::endl;
-        G4Exception("", "", FatalException, "CellReadout2D points to shape that is not a box.");
+        G4Exception("", "", FatalException, "CellReadout2D points to a shape that is not a G4Box.");
     }
-    //m_readout->setReadoutDimensionX(box->GetXHalfLength() * 2);
-    //m_readout->setReadoutDimensionY(box->GetYHalfLength() * 2);
+    _readout->setDimensionX(box->GetXHalfLength() * 2);
+    _readout->setDimensionY(box->GetYHalfLength() * 2);
+
+    // DEBUG
+    std::cout << "set readout dimensions XY: " << _readout->getDimensionX() << " " << _readout->getDimensionY() << std::endl;
+}
+
+CellReadout::Position2D CellReadout2DSegmentation::localToReadoutCoordinates(G4ThreeVector& vec)
+{
+    CellReadout::Position2D position;
+    position.x = vec.x() + _readout->getDimensionX() / 2.;
+    position.y = vec.y() + _readout->getDimensionY() / 2.;
+    return position;
 }
 
-CellReadout2D::Position2D CellReadout2DSegmentation::localToReadoutCoordinates(G4ThreeVector& vec)
+G4ThreeVector CellReadout2DSegmentation::readoutToLocalCoordinates(CellReadout::Position2D position)
 {
-    CellReadout2D::Position2D xy;
-    //xy.first = vec.x() + m_readout->getReadoutDimensionX() / 2.0;
-    //xy.second = vec.y() + m_readout->getReadoutDimensionY() / 2.0;
-    return xy;
+    double x = position.x - _readout->getDimensionX() / 2.;
+    double y = position.y - _readout->getDimensionY() / 2.;
+    return G4ThreeVector(x, y, 0);
 }
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