From 187b7e45f935044362eedaa401f57ce2cf646a45 Mon Sep 17 00:00:00 2001
From: Shaojun Lu <shaojun.lu@desy.de>
Date: Wed, 27 Apr 2016 09:44:59 +0000
Subject: [PATCH]  Updated WaferGridXY, allow to set and access different Magic
 wafer group. SiWEcal Barrel has different Magic Wafer size in each layer
 group, and SiWEcal Endcaps has different Magic Wafer size in each tower
 group.

---
 .../include/DDSegmentation/WaferGridXY.h      | 36 +++++++++----------
 DDSegmentation/src/WaferGridXY.cpp            | 26 +++++++-------
 2 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/DDSegmentation/include/DDSegmentation/WaferGridXY.h b/DDSegmentation/include/DDSegmentation/WaferGridXY.h
index 0bbd1dd8f..8dd758b4e 100644
--- a/DDSegmentation/include/DDSegmentation/WaferGridXY.h
+++ b/DDSegmentation/include/DDSegmentation/WaferGridXY.h
@@ -10,7 +10,7 @@
 
 #include "DDSegmentation/CartesianGrid.h"
 
-#define MAX_LAYERS 100
+#define MAX_GROUPS 100
 #define MAX_WAFERS 100
 
 namespace DD4hep {
@@ -43,13 +43,13 @@ public:
 	double offsetY() const {
 		return _offsetY;
 	}
-        /// access the coordinate waferOffset for inLayer in X
-	double waferOffsetX(int inLayer, int inWafer) const {
-	  return  _waferOffsetX[inLayer][inWafer];
+        /// access the coordinate waferOffset for inGroup in X
+	double waferOffsetX(int inGroup, int inWafer) const {
+	  return  _waferOffsetX[inGroup][inWafer];
 	}
-        /// access the coordinate waferOffset for inLayer in Y
-	double waferOffsetY(int inLayer, int inWafer) const {
-	  return  _waferOffsetY[inLayer][inWafer];
+        /// access the coordinate waferOffset for inGroup in Y
+	double waferOffsetY(int inGroup, int inWafer) const {
+	  return  _waferOffsetY[inGroup][inWafer];
 	}
 
 	/// access the field name used for X
@@ -77,12 +77,12 @@ public:
 		_offsetY = offset;
 	}
         /// set the coordinate waferOffset for inlayer in X
-        void setWaferOffsetX(int inLayer,int inWafer, double offset) {
-          _waferOffsetX[inLayer][inWafer] = offset;
+        void setWaferOffsetX(int inGroup,int inWafer, double offset) {
+          _waferOffsetX[inGroup][inWafer] = offset;
         }
-        /// set the coordinate waferOffset for inLayer in Y
-        void setWaferOffsetY(int inLayer,int inWafer, double offset) {
-          _waferOffsetY[inLayer][inWafer] = offset;
+        /// set the coordinate waferOffset for inGroup in Y
+        void setWaferOffsetY(int inGroup,int inWafer, double offset) {
+          _waferOffsetY[inGroup][inWafer] = offset;
         }
 
 	/// set the field name used for X
@@ -113,16 +113,16 @@ protected:
 	double _gridSizeY;
 	/// the coordinate offset in Y
 	double _offsetY;
-        /// list of wafer x offset for each layer
-	double _waferOffsetX[MAX_LAYERS][MAX_WAFERS];
-        /// list of wafer y offset for each layer
-	double _waferOffsetY[MAX_LAYERS][MAX_WAFERS];
+        /// list of wafer x offset for each group
+	double _waferOffsetX[MAX_GROUPS][MAX_WAFERS];
+        /// list of wafer y offset for each group
+	double _waferOffsetY[MAX_GROUPS][MAX_WAFERS];
 	/// the field name used for X
 	std::string _xId;
 	/// the field name used for Y
 	std::string _yId;
-        /// encoding field used for the layer
-        std::string _identifierLayer; 
+        /// encoding field used for the Magic Wafer group
+        std::string _identifierMGWaferGroup; 
         /// encoding field used for the wafer
         std::string _identifierWafer; 
 };
diff --git a/DDSegmentation/src/WaferGridXY.cpp b/DDSegmentation/src/WaferGridXY.cpp
index 46e592490..d11adf21f 100644
--- a/DDSegmentation/src/WaferGridXY.cpp
+++ b/DDSegmentation/src/WaferGridXY.cpp
@@ -24,7 +24,7 @@ WaferGridXY::WaferGridXY(const std::string& cellEncoding) :
 	registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
 	registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
 	registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
-        registerParameter("identifier_layer", "Cell encoding identifier for layer", _identifierLayer, std::string("layer"),
+        registerParameter("identifier_groupMGWafer", "Cell encoding identifier for Magic Wafer group", _identifierMGWaferGroup, std::string("layer"),
                         SegmentationParameter::NoUnit, true);
         registerParameter("identifier_wafer", "Cell encoding identifier for wafer", _identifierWafer, std::string("wafer"),
                         SegmentationParameter::NoUnit, true);
@@ -38,25 +38,25 @@ WaferGridXY::~WaferGridXY() {
 /// determine the position based on the cell ID
 Vector3D WaferGridXY::position(const CellID& cID) const {
 	_decoder->setValue(cID);
-        unsigned int _layerIndex;
+        unsigned int _groupMGWaferIndex;
         unsigned int _waferIndex;
 	Vector3D cellPosition;
 
-        _layerIndex = (*_decoder)[_identifierLayer];
+        _groupMGWaferIndex = (*_decoder)[_identifierMGWaferGroup];
         _waferIndex = (*_decoder)[_identifierWafer];
 
-	if ( _waferOffsetX[_layerIndex][_waferIndex] > 0 || _waferOffsetX[_layerIndex][_waferIndex] < 0 )
+	if ( _waferOffsetX[_groupMGWaferIndex][_waferIndex] > 0 || _waferOffsetX[_groupMGWaferIndex][_waferIndex] < 0 )
 	  {
-	    cellPosition.X = binToPosition((*_decoder)[_xId].value(), _gridSizeX, _offsetX+_waferOffsetX[_layerIndex][_waferIndex]);
+	    cellPosition.X = binToPosition((*_decoder)[_xId].value(), _gridSizeX, _offsetX+_waferOffsetX[_groupMGWaferIndex][_waferIndex]);
 	  }
 	else
 	  {
 	    cellPosition.X = binToPosition((*_decoder)[_xId].value(), _gridSizeX, _offsetX);
 	  }
 
-	if ( _waferOffsetY[_layerIndex][_waferIndex] > 0 || _waferOffsetY[_layerIndex][_waferIndex] < 0 )
+	if ( _waferOffsetY[_groupMGWaferIndex][_waferIndex] > 0 || _waferOffsetY[_groupMGWaferIndex][_waferIndex] < 0 )
 	  {
-	    cellPosition.Y = binToPosition((*_decoder)[_yId].value(), _gridSizeY, _offsetY+_waferOffsetY[_layerIndex][_waferIndex]);
+	    cellPosition.Y = binToPosition((*_decoder)[_yId].value(), _gridSizeY, _offsetY+_waferOffsetY[_groupMGWaferIndex][_waferIndex]);
 	  }
 	else
 	  {
@@ -69,24 +69,24 @@ Vector3D WaferGridXY::position(const CellID& cID) const {
 /// determine the cell ID based on the position
   CellID WaferGridXY::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const {
 	_decoder->setValue(vID);
-        unsigned int _layerIndex;
+        unsigned int _groupMGWaferIndex;
         unsigned int _waferIndex;
 
-        _layerIndex = (*_decoder)[_identifierLayer];
+        _groupMGWaferIndex = (*_decoder)[_identifierMGWaferGroup];
         _waferIndex = (*_decoder)[_identifierWafer];
 
-	if ( _waferOffsetX[_layerIndex][_waferIndex] > 0 || _waferOffsetX[_layerIndex][_waferIndex] < 0 )
+	if ( _waferOffsetX[_groupMGWaferIndex][_waferIndex] > 0 || _waferOffsetX[_groupMGWaferIndex][_waferIndex] < 0 )
 	  {
-	    (*_decoder)[_xId] = positionToBin(localPosition.X, _gridSizeX, _offsetX+_waferOffsetX[_layerIndex][_waferIndex]);
+	    (*_decoder)[_xId] = positionToBin(localPosition.X, _gridSizeX, _offsetX+_waferOffsetX[_groupMGWaferIndex][_waferIndex]);
 	  }
 	else
 	  {
 	    (*_decoder)[_xId] = positionToBin(localPosition.X, _gridSizeX, _offsetX);
 	  }
 
-	if ( _waferOffsetY[_layerIndex][_waferIndex] > 0 ||  _waferOffsetY[_layerIndex][_waferIndex] < 0)
+	if ( _waferOffsetY[_groupMGWaferIndex][_waferIndex] > 0 ||  _waferOffsetY[_groupMGWaferIndex][_waferIndex] < 0)
 	  {
-	    (*_decoder)[_yId] = positionToBin(localPosition.Y, _gridSizeY, _offsetY+_waferOffsetY[_layerIndex][_waferIndex]);
+	    (*_decoder)[_yId] = positionToBin(localPosition.Y, _gridSizeY, _offsetY+_waferOffsetY[_groupMGWaferIndex][_waferIndex]);
 	  }
 	else
 	  {
-- 
GitLab