From 90d0f1a1201db7c9083d53f7ee7ec9106ba74afc Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Thu, 20 Oct 2016 21:16:41 +0200
Subject: [PATCH] Fix handle issues for segmentations

---
 DDCore/include/DD4hep/CartesianGridXY.h       |   8 ++
 DDCore/include/DD4hep/CartesianGridXYZ.h      |  12 ++
 DDCore/include/DD4hep/CartesianGridXZ.h       |   8 ++
 DDCore/include/DD4hep/CartesianGridYZ.h       |  12 +-
 DDCore/include/DD4hep/Handle.inl              |  15 ++-
 DDCore/include/DD4hep/PolarGridRPhi.h         |   8 ++
 DDCore/include/DD4hep/PolarGridRPhi2.h        |  23 +++-
 .../DD4hep/objects/SegmentationsInterna.h     |   2 +
 DDCore/src/CartesianGridXY.cpp                |  20 +++
 DDCore/src/CartesianGridXYZ.cpp               |  30 +++++
 DDCore/src/CartesianGridXZ.cpp                |  20 +++
 DDCore/src/CartesianGridYZ.cpp                |  20 +++
 DDCore/src/PolarGridRPhi.cpp                  |  20 +++
 DDCore/src/PolarGridRPhi2.cpp                 |  29 +++++
 DDCore/src/World.cpp                          |   1 -
 DDTest/CMakeLists.txt                         |   5 +-
 DDTest/src/test_segmentationHandles.cc        | 115 ++++++++++++++++++
 17 files changed, 339 insertions(+), 9 deletions(-)
 create mode 100644 DDTest/src/test_segmentationHandles.cc

diff --git a/DDCore/include/DD4hep/CartesianGridXY.h b/DDCore/include/DD4hep/CartesianGridXY.h
index 1efcffea4..9f31f7887 100644
--- a/DDCore/include/DD4hep/CartesianGridXY.h
+++ b/DDCore/include/DD4hep/CartesianGridXY.h
@@ -87,10 +87,18 @@ namespace DD4hep {
       double gridSizeX() const;
       /// access the grid size in Y
       double gridSizeY() const;
+      /// set the grid size in X
+      void setGridSizeX(double cellSize) const;
+      /// set the grid size in Y
+      void setGridSizeY(double cellSize) const;
       /// access the coordinate offset in X
       double offsetX() const;
       /// access the coordinate offset in Y
       double offsetY() const;
+      /// set the coordinate offset in X
+      void setOffsetX(double offset) const;
+      /// set the coordinate offset in Y
+      void setOffsetY(double offset) const;
       /// access the field name used for X
       const std::string& fieldNameX() const;
       /// access the field name used for Y
diff --git a/DDCore/include/DD4hep/CartesianGridXYZ.h b/DDCore/include/DD4hep/CartesianGridXYZ.h
index 695318416..4e5dce48f 100644
--- a/DDCore/include/DD4hep/CartesianGridXYZ.h
+++ b/DDCore/include/DD4hep/CartesianGridXYZ.h
@@ -87,12 +87,24 @@ namespace DD4hep {
       double gridSizeY() const;
        /// access the grid size in Z
       double gridSizeZ() const;
+      /// set the grid size in X
+      void setGridSizeX(double cellSize) const;
+      /// set the grid size in Y
+      void setGridSizeY(double cellSize) const;
+      /// set the grid size in Z
+      void setGridSizeZ(double cellSize) const;
      /// access the coordinate offset in X
       double offsetX() const;
       /// access the coordinate offset in Y
       double offsetY() const;
       /// access the coordinate offset in Z
       double offsetZ() const;
+      /// set the coordinate offset in X
+      void setOffsetX(double offset) const;
+      /// set the coordinate offset in Y
+      void setOffsetY(double offset) const;
+      /// set the coordinate offset in Z
+      void setOffsetZ(double offset) const;
       /// access the field name used for X
       const std::string& fieldNameX() const;
       /// access the field name used for Y
diff --git a/DDCore/include/DD4hep/CartesianGridXZ.h b/DDCore/include/DD4hep/CartesianGridXZ.h
index df9de6813..6da8b60c0 100644
--- a/DDCore/include/DD4hep/CartesianGridXZ.h
+++ b/DDCore/include/DD4hep/CartesianGridXZ.h
@@ -86,10 +86,18 @@ namespace DD4hep {
       double gridSizeX() const;
       /// access the grid size in Z
       double gridSizeZ() const;
+      /// set the grid size in X
+      void setGridSizeX(double cellSize) const;
+      /// set the grid size in Z
+      void setGridSizeZ(double cellSize) const;
       /// access the coordinate offset in X
       double offsetX() const;
       /// access the coordinate offset in Z
       double offsetZ() const;
+      /// set the coordinate offset in X
+      void setOffsetX(double offset) const;
+      /// set the coordinate offset in Z
+      void setOffsetZ(double offset) const;
       /// access the field name used for X
       const std::string& fieldNameX() const;
       /// access the field name used for Z
diff --git a/DDCore/include/DD4hep/CartesianGridYZ.h b/DDCore/include/DD4hep/CartesianGridYZ.h
index 61c4727fd..13d4a3e83 100644
--- a/DDCore/include/DD4hep/CartesianGridYZ.h
+++ b/DDCore/include/DD4hep/CartesianGridYZ.h
@@ -81,18 +81,22 @@ namespace DD4hep {
       Position position(const CellID& cellID) const;
       /// determine the cell ID based on the position
       CellID cellID(const Position& local, const Position& global, const VolumeID& volID) const;
-      /// access the grid size in X
-      double gridSizeX() const;
       /// access the grid size in Y
       double gridSizeY() const;
       /// access the grid size in Z
       double gridSizeZ() const;
-      /// access the coordinate offset in X
-      double offsetX() const;
+      /// set the grid size in Y
+      void setGridSizeY(double cellSize) const;
+      /// set the grid size in Z
+      void setGridSizeZ(double cellSize) const;
       /// access the coordinate offset in Y
       double offsetY() const;
       /// access the coordinate offset in Z
       double offsetZ() const;
+      /// set the coordinate offset in Y
+      void setOffsetY(double offset) const;
+      /// set the coordinate offset in Z
+      void setOffsetZ(double offset) const;
       /// access the field name used for X
       const std::string& fieldNameX() const;
       /// access the field name used for Y
diff --git a/DDCore/include/DD4hep/Handle.inl b/DDCore/include/DD4hep/Handle.inl
index 1e2cdf238..deb942d5d 100644
--- a/DDCore/include/DD4hep/Handle.inl
+++ b/DDCore/include/DD4hep/Handle.inl
@@ -46,11 +46,24 @@ namespace DD4hep {
 
 }   /* End namespace DD4hep      */
 
+#if 0
+#include <iostream>
+
+      std::cout << "element:" << (void*)m_element << std::endl;\
+      std::cout << "type:   "  << (char*)(m_element ? typeName(typeid(*m_element)).c_str() : "---") << std::endl;\
+      std::cout << "type:   "  << (void*)(m_element ? &typeid(*m_element) : 0) << std::endl;\
+      std::cout << "target: "  << typeName(typeid(X)) << std::endl;\
+      std::cout << "target: "  << (void*)&typeid(X) << std::endl;\
+      std::cout << "cast:   "  << dynamic_cast<X*>((TObject*)m_element) << std::endl;\
+      std::cout << "cast:   "  << dynamic_cast<X*>(m_element) << std::endl;\
+
+#endif
+
 #define DD4HEP_INSTANTIATE_HANDLE(X)                                    \
   namespace DD4hep {                                                    \
     template <> void Handle<X>::verifyObject() const  {                 \
       increment_object_validations();					\
-      if (m_element && dynamic_cast<X*>((TObject*)m_element) == 0) {	\
+      if (m_element && dynamic_cast<X*>(m_element) == 0) {	        \
         bad_assignment(typeid(*m_element), typeid(X));		        \
       }                                                                 \
   }}                                                                    \
diff --git a/DDCore/include/DD4hep/PolarGridRPhi.h b/DDCore/include/DD4hep/PolarGridRPhi.h
index caf9a0f7e..d8cf860db 100644
--- a/DDCore/include/DD4hep/PolarGridRPhi.h
+++ b/DDCore/include/DD4hep/PolarGridRPhi.h
@@ -83,10 +83,18 @@ namespace DD4hep {
       double gridSizeR() const;
       /// access the grid size in Phi
       double gridSizePhi() const;
+      /// set the grid size in R
+      void setGridSizeR(double cellSize) const;
+      /// set the grid size in Phi
+      void setGridSizePhi(double cellSize) const;
       /// access the coordinate offset in R
       double offsetR() const;
       /// access the coordinate offset in Phi
       double offsetPhi() const;
+      /// set the coordinate offset in R
+      void setOffsetR(double offset) const;
+      /// set the coordinate offset in Phi
+      void setOffsetPhi(double offset) const;
       /// access the field name used for R
       const std::string& fieldNameR() const;
       /// access the field name used for Phi
diff --git a/DDCore/include/DD4hep/PolarGridRPhi2.h b/DDCore/include/DD4hep/PolarGridRPhi2.h
index 5eaa808f0..7fbb67fd3 100644
--- a/DDCore/include/DD4hep/PolarGridRPhi2.h
+++ b/DDCore/include/DD4hep/PolarGridRPhi2.h
@@ -87,11 +87,32 @@ namespace DD4hep {
       double offsetR() const;
       /// access the coordinate offset in Phi
       double offsetPhi() const;
+      /// set the coordinate offset in R
+      void setOffsetR(double offset) const;
+      /// set the coordinate offset in Phi
+      void setOffsetPhi(double offset) const;
       /// access the grid size in R
       std::vector<double> gridRValues() const;
       /// access the grid size in Phi
       std::vector<double>  gridPhiValues() const;
-      /// access the field name used for R
+      /// set the grid Boundaries in R
+      void setGridSizeR(double cellSize, int rID) const;
+      /// set the grid size in Phi
+      void setGridSizePhi(double cellSize, int phiID) const;
+      /// set the grid boundaries for R
+      /** @param rValues The boundaries of the segments in radius,
+       *                 the first value is the lower boundary of the first bin, 
+       *                 the highest value is the upper boundary of the last bin
+       */
+      void setGridRValues(std::vector<double> const& rValues) const;
+      /// set the grid size in Phi for each bin in R
+      /** @param phiValues The size in phi for each bin in R, 
+       *                   this vector is one smaller than the vector 
+       *                   for PolarGridRPhi2::setGridRValues
+       */
+      void setGridPhiValues(std::vector<double> const& phiValues) const;
+
+     /// access the field name used for R
       const std::string& fieldNameR() const;
       /// access the field name used for Phi
       const std::string& fieldNamePhi() const;
diff --git a/DDCore/include/DD4hep/objects/SegmentationsInterna.h b/DDCore/include/DD4hep/objects/SegmentationsInterna.h
index db063b514..4f78a962f 100644
--- a/DDCore/include/DD4hep/objects/SegmentationsInterna.h
+++ b/DDCore/include/DD4hep/objects/SegmentationsInterna.h
@@ -56,6 +56,7 @@ namespace DD4hep {
       const std::string& name() const;
       /// Set the segmentation name
       void setName(const std::string& value);
+
       /// Access the segmentation type
       const std::string& type() const;
       /// Access the description of the segmentation
@@ -83,6 +84,7 @@ namespace DD4hep {
       /// Calculates the neighbours of the given cell ID and adds them to the list of neighbours
       void neighbours(const CellID& cellID, std::set<CellID>& neighbours) const;
 
+      /** Data members.                                          */
       /// Magic word to check object integrity
       unsigned long magic;
       /// Flag to use segmentation for hit positioning
diff --git a/DDCore/src/CartesianGridXY.cpp b/DDCore/src/CartesianGridXY.cpp
index 7f75342d2..51aa81712 100644
--- a/DDCore/src/CartesianGridXY.cpp
+++ b/DDCore/src/CartesianGridXY.cpp
@@ -44,6 +44,16 @@ double CartesianGridXY::gridSizeY() const {
   return access()->implementation->gridSizeY();
 }
 
+/// set the grid size in X
+void CartesianGridXY::setGridSizeX(double cellSize) const   {
+  access()->implementation->setGridSizeX(cellSize);
+}
+
+/// set the grid size in Y
+void CartesianGridXY::setGridSizeY(double cellSize) const   {
+  access()->implementation->setGridSizeY(cellSize);
+}
+
 /// access the coordinate offset in X
 double CartesianGridXY::offsetX() const {
   return access()->implementation->offsetX();
@@ -54,6 +64,16 @@ double CartesianGridXY::offsetY() const {
   return access()->implementation->offsetY();
 }
 
+/// set the coordinate offset in X
+void CartesianGridXY::setOffsetX(double offset) const   {
+  access()->implementation->setOffsetX(offset);
+}
+
+/// set the coordinate offset in Y
+void CartesianGridXY::setOffsetY(double offset) const   {
+  access()->implementation->setOffsetY(offset);
+}
+
 /// access the field name used for X
 const string& CartesianGridXY::fieldNameX() const {
   return access()->implementation->fieldNameX();
diff --git a/DDCore/src/CartesianGridXYZ.cpp b/DDCore/src/CartesianGridXYZ.cpp
index 50b9ccb19..de16d3be9 100644
--- a/DDCore/src/CartesianGridXYZ.cpp
+++ b/DDCore/src/CartesianGridXYZ.cpp
@@ -49,6 +49,21 @@ double CartesianGridXYZ::gridSizeZ() const {
   return access()->implementation->gridSizeZ();
 }
 
+/// set the grid size in X
+void CartesianGridXYZ::setGridSizeX(double cellSize) const   {
+  access()->implementation->setGridSizeX(cellSize);
+}
+
+/// set the grid size in Y
+void CartesianGridXYZ::setGridSizeY(double cellSize) const   {
+  access()->implementation->setGridSizeY(cellSize);
+}
+
+/// set the grid size in Z
+void CartesianGridXYZ::setGridSizeZ(double cellSize) const   {
+  access()->implementation->setGridSizeZ(cellSize);
+}
+
 /// access the coordinate offset in X
 double CartesianGridXYZ::offsetX() const {
   return access()->implementation->offsetX();
@@ -64,6 +79,21 @@ double CartesianGridXYZ::offsetZ() const {
   return access()->implementation->offsetZ();
 }
 
+/// set the coordinate offset in X
+void CartesianGridXYZ::setOffsetX(double offset) const   {
+  access()->implementation->setOffsetX(offset);
+}
+
+/// set the coordinate offset in Y
+void CartesianGridXYZ::setOffsetY(double offset) const   {
+  access()->implementation->setOffsetY(offset);
+}
+
+/// set the coordinate offset in Z
+void CartesianGridXYZ::setOffsetZ(double offset) const   {
+  access()->implementation->setOffsetZ(offset);
+}
+
 /// access the field name used for X
 const string& CartesianGridXYZ::fieldNameX() const {
   return access()->implementation->fieldNameX();
diff --git a/DDCore/src/CartesianGridXZ.cpp b/DDCore/src/CartesianGridXZ.cpp
index f28a75c0a..765c156e6 100644
--- a/DDCore/src/CartesianGridXZ.cpp
+++ b/DDCore/src/CartesianGridXZ.cpp
@@ -44,6 +44,16 @@ double CartesianGridXZ::gridSizeZ() const {
   return access()->implementation->gridSizeZ();
 }
 
+/// set the grid size in X
+void CartesianGridXZ::setGridSizeX(double cellSize) const   {
+  access()->implementation->setGridSizeX(cellSize);
+}
+
+/// set the grid size in Z
+void CartesianGridXZ::setGridSizeZ(double cellSize) const   {
+  access()->implementation->setGridSizeZ(cellSize);
+}
+
 /// access the coordinate offset in X
 double CartesianGridXZ::offsetX() const {
   return access()->implementation->offsetX();
@@ -54,6 +64,16 @@ double CartesianGridXZ::offsetZ() const {
   return access()->implementation->offsetZ();
 }
 
+/// set the coordinate offset in X
+void CartesianGridXZ::setOffsetX(double offset) const   {
+  access()->implementation->setOffsetX(offset);
+}
+
+/// set the coordinate offset in Z
+void CartesianGridXZ::setOffsetZ(double offset) const   {
+  access()->implementation->setOffsetZ(offset);
+}
+
 /// access the field name used for X
 const string& CartesianGridXZ::fieldNameX() const {
   return access()->implementation->fieldNameX();
diff --git a/DDCore/src/CartesianGridYZ.cpp b/DDCore/src/CartesianGridYZ.cpp
index 7e9a59058..9e3cb22ec 100644
--- a/DDCore/src/CartesianGridYZ.cpp
+++ b/DDCore/src/CartesianGridYZ.cpp
@@ -44,6 +44,16 @@ double CartesianGridYZ::gridSizeZ() const {
   return access()->implementation->gridSizeZ();
 }
 
+/// set the grid size in Y
+void CartesianGridYZ::setGridSizeY(double cellSize) const   {
+  access()->implementation->setGridSizeY(cellSize);
+}
+
+/// set the grid size in Z
+void CartesianGridYZ::setGridSizeZ(double cellSize) const   {
+  access()->implementation->setGridSizeZ(cellSize);
+}
+
 /// access the coordinate offset in Y
 double CartesianGridYZ::offsetY() const {
   return access()->implementation->offsetY();
@@ -54,6 +64,16 @@ double CartesianGridYZ::offsetZ() const {
   return access()->implementation->offsetZ();
 }
 
+/// set the coordinate offset in Y
+void CartesianGridYZ::setOffsetY(double offset) const   {
+  access()->implementation->setOffsetY(offset);
+}
+
+/// set the coordinate offset in Z
+void CartesianGridYZ::setOffsetZ(double offset) const   {
+  access()->implementation->setOffsetZ(offset);
+}
+
 /// access the field name used for Y
 const string& CartesianGridYZ::fieldNameY() const {
   return access()->implementation->fieldNameY();
diff --git a/DDCore/src/PolarGridRPhi.cpp b/DDCore/src/PolarGridRPhi.cpp
index 416e372b4..e7bfe7b5e 100644
--- a/DDCore/src/PolarGridRPhi.cpp
+++ b/DDCore/src/PolarGridRPhi.cpp
@@ -54,6 +54,26 @@ double PolarGridRPhi::offsetPhi() const  {
   return access()->implementation->offsetPhi();
 }
 
+/// set the coordinate offset in R
+void PolarGridRPhi::setOffsetR(double offset) const  {
+  access()->implementation->setOffsetR(offset);
+}
+
+/// set the coordinate offset in Phi
+void PolarGridRPhi::setOffsetPhi(double offset) const  {
+  access()->implementation->setOffsetPhi(offset);
+}
+
+/// set the grid size in R
+void PolarGridRPhi::setGridSizeR(double cellSize) const  {
+  access()->implementation->setGridSizeR(cellSize);
+}
+
+/// set the grid size in Phi
+void PolarGridRPhi::setGridSizePhi(double cellSize) const  {
+  access()->implementation->setGridSizePhi(cellSize);
+}
+
 /// access the field name used for R
 const string& PolarGridRPhi::fieldNameR() const  {
   return access()->implementation->fieldNameR();
diff --git a/DDCore/src/PolarGridRPhi2.cpp b/DDCore/src/PolarGridRPhi2.cpp
index 47e18d1de..3717e530d 100644
--- a/DDCore/src/PolarGridRPhi2.cpp
+++ b/DDCore/src/PolarGridRPhi2.cpp
@@ -43,6 +43,25 @@ vector<double> PolarGridRPhi2::gridRValues() const  {
 vector<double> PolarGridRPhi2::gridPhiValues() const  {
   return access()->implementation->gridPhiValues();
 }
+/// set the grid Boundaries in R
+void PolarGridRPhi2::setGridSizeR(double cellSize, int rID) const  {
+  access()->implementation->setGridRValues(cellSize,rID);
+}
+
+/// set the grid size in Phi
+void PolarGridRPhi2::setGridSizePhi(double cellSize, int phiID) const  {
+  access()->implementation->setGridSizePhi(cellSize,phiID);
+}
+
+/// set the grid boundaries for R
+void PolarGridRPhi2::setGridRValues(std::vector<double> const& rValues) const  {
+  access()->implementation->setGridRValues(rValues);
+}
+
+/// set the grid size in Phi for each bin in R
+void PolarGridRPhi2::setGridPhiValues(std::vector<double> const& phiValues) const  {
+  access()->implementation->setGridPhiValues(phiValues);
+}
 
 /// access the coordinate offset in R
 double PolarGridRPhi2::offsetR() const  {
@@ -54,6 +73,16 @@ double PolarGridRPhi2::offsetPhi() const  {
   return access()->implementation->offsetPhi();
 }
 
+/// set the coordinate offset in R
+void PolarGridRPhi2::setOffsetR(double offset) const  {
+  access()->implementation->setOffsetR(offset);
+}
+
+/// set the coordinate offset in Phi
+void PolarGridRPhi2::setOffsetPhi(double offset) const  {
+  access()->implementation->setOffsetPhi(offset);
+}
+
 /// access the field name used for R
 const string& PolarGridRPhi2::fieldNameR() const  {
   return access()->implementation->fieldNameR();
diff --git a/DDCore/src/World.cpp b/DDCore/src/World.cpp
index 064774816..c3417d150 100644
--- a/DDCore/src/World.cpp
+++ b/DDCore/src/World.cpp
@@ -40,4 +40,3 @@ World::AlignmentsLoader& World::alignmentsLoader() const   {
 LCDD& World::lcdd() const   {
   return *(access()->lcdd);
 }
-
diff --git a/DDTest/CMakeLists.txt b/DDTest/CMakeLists.txt
index ed7e136df..c090767d5 100644
--- a/DDTest/CMakeLists.txt
+++ b/DDTest/CMakeLists.txt
@@ -23,12 +23,13 @@ dd4hep_add_test_reg ( test_surface             BUILD_EXEC REGEX_FAIL "TEST_FAILE
   EXEC_ARGS file:${CMAKE_CURRENT_SOURCE_DIR}/units.xml )
 
 dd4hep_add_test_reg ( test_bitfield64          BUILD_EXEC REGEX_FAIL "TEST_FAILED" )
-dd4hep_add_test_reg ( test_DetType            BUILD_EXEC REGEX_FAIL "TEST_FAILED" )
+dd4hep_add_test_reg ( test_DetType             BUILD_EXEC REGEX_FAIL "TEST_FAILED" )
 dd4hep_add_test_reg ( test_PolarGridRPhi2      BUILD_EXEC REGEX_FAIL "TEST_FAILED" )
 dd4hep_add_test_reg ( test_cellDimensions      BUILD_EXEC REGEX_FAIL "TEST_FAILED" )
 dd4hep_add_test_reg ( test_cellDimensionsRPhi2 BUILD_EXEC REGEX_FAIL "TEST_FAILED" )
+dd4hep_add_test_reg ( test_segmentationHandles BUILD_EXEC REGEX_FAIL "TEST_FAILED" )
 
 if (DD4HEP_USE_GEANT4)
   dd4hep_add_test_reg ( test_EventReaders BUILD_EXEC REGEX_FAIL "TEST_FAILED"
     EXEC_ARGS ${CMAKE_CURRENT_SOURCE_DIR} )
-endif()
\ No newline at end of file
+endif()
diff --git a/DDTest/src/test_segmentationHandles.cc b/DDTest/src/test_segmentationHandles.cc
new file mode 100644
index 000000000..a281589a7
--- /dev/null
+++ b/DDTest/src/test_segmentationHandles.cc
@@ -0,0 +1,115 @@
+#include "DD4hep/Segmentations.h"
+#include "DD4hep/CartesianGridXY.h"
+#include "DD4hep/CartesianGridYZ.h"
+#include "DD4hep/CartesianGridXZ.h"
+#include "DD4hep/CartesianGridXYZ.h"
+#include "DD4hep/DDTest.h"
+
+#include <iostream>
+#include <iomanip>
+#include <vector>
+#include <algorithm>
+#include <exception>
+#include <cmath>
+
+
+DD4hep::DDTest test = DD4hep::DDTest( "CellDimensions" ) ;
+using namespace DD4hep;
+using namespace DD4hep::Geometry;
+
+int main() {
+  try{
+    BitField64 bf("system:8,barrel:3,layer:8,slice:5,x:16,y:16");
+    Segmentation base("CartesianGridXY","Test",&bf);
+    CartesianGridXY seg(base);
+    const double xSize=12343.43243;
+    const double ySize=M_PI;
+
+    test( seg.isValid(), " Assignment from Segmentation -> "+typeName(typeid(seg))+" worked" );
+
+    seg.setGridSizeX(xSize);
+    seg.setGridSizeY(ySize);
+
+    DD4hep::DDSegmentation::VolumeID volID = 0;
+
+    test( fabs(seg.cellDimensions(volID)[0] - xSize )  < 1e-11, " CG_XY: Dimension for X" );
+    test( fabs(seg.cellDimensions(volID)[1] - ySize )  < 1e-11, " CG_XY: Dimension for Y" );
+
+  } catch( std::exception &e ){
+    test.log( e.what() );
+    test.error( "exception occurred" );
+  }
+
+  try{
+    BitField64 bf("system:8,barrel:3,layer:8,slice:5,x:16,z:16");
+    Segmentation base("CartesianGridXZ","Test",&bf);
+    CartesianGridXZ seg(base);
+
+    const double xSize=12343.43243;
+    const double zSize=M_PI;
+
+    test( seg.isValid(), " Assignment from Segmentation -> "+typeName(typeid(seg))+" worked" );
+
+    seg.setGridSizeX(xSize);
+    seg.setGridSizeZ(zSize);
+
+    VolumeID volID = 0;
+
+    test( fabs(seg.cellDimensions(volID)[0] - xSize )  < 1e-11, " CG_XZ: Dimension for X" );
+    test( fabs(seg.cellDimensions(volID)[1] - zSize )  < 1e-11, " CG_XZ: Dimension for Z" );
+
+  } catch( std::exception &e ){
+    test.log( e.what() );
+    test.error( "exception occurred" );
+  }
+
+  try{
+    BitField64 bf("system:8,barrel:3,layer:8,slice:5,y:16,z:16");
+    Segmentation base("CartesianGridYZ","Test",&bf);
+    CartesianGridYZ seg = base;
+
+    test( seg.isValid(), " Assignment from Segmentation -> "+typeName(typeid(seg))+" worked" );
+
+    const double ySize=12343.43243;
+    const double zSize=M_PI;
+
+    seg.setGridSizeY(ySize);
+    seg.setGridSizeZ(zSize);
+
+    DD4hep::DDSegmentation::VolumeID volID = 0;
+
+    test( fabs(seg.cellDimensions(volID)[0] - ySize )  < 1e-11, " CG_YZ: Dimension for Y" );
+    test( fabs(seg.cellDimensions(volID)[1] - zSize )  < 1e-11, " CG_YZ: Dimension for Z" );
+
+  } catch( std::exception &e ){
+    test.log( e.what() );
+    test.error( "exception occurred" );
+  }
+
+  try{
+    BitField64 bf("system:8,barrel:3,layer:8,slice:7,x:10,y:10,z:10");
+    Segmentation base("CartesianGridXYZ","Test",&bf);
+    CartesianGridXYZ seg = base;
+
+    test( seg.isValid(), " Assignment from Segmentation -> "+typeName(typeid(seg))+" worked" );
+
+    const double xSize=42.24;
+    const double ySize=12343.43243;
+    const double zSize=M_PI;
+
+    seg.setGridSizeX(xSize);
+    seg.setGridSizeY(ySize);
+    seg.setGridSizeZ(zSize);
+
+    DD4hep::DDSegmentation::VolumeID volID = 0;
+
+    test( fabs(seg.cellDimensions(volID)[0] - xSize )  < 1e-11, " CG_XYZ: Dimension for X" );
+    test( fabs(seg.cellDimensions(volID)[1] - ySize )  < 1e-11, " CG_XYZ: Dimension for Y" );
+    test( fabs(seg.cellDimensions(volID)[2] - zSize )  < 1e-11, " CG_XYZ: Dimension for Z" );
+
+  } catch( std::exception &e ){
+    test.log( e.what() );
+    test.error( "exception occurred" );
+  }
+  return 0;
+}
-- 
GitLab