From 08ba3d3677d116bfe378c7a33447653ae8dc435c Mon Sep 17 00:00:00 2001
From: Nicholas Styles <nicholas.styles@desy.de>
Date: Tue, 19 Jan 2021 15:16:26 +0100
Subject: [PATCH] add z-shift of centre for StripBoxDesign and specific design
 per side

---
 .../ReadoutGeometryBase/DetectorDesign.h      |  3 +++
 .../src/DetectorDesign.cxx                    |  4 +++
 .../src/SolidStateDetectorElementBase.cxx     |  4 +--
 .../SCT_ReadoutGeometry/StripBoxDesign.h      |  7 +++--
 .../src/StripBoxDesign.cxx                    | 11 ++++++--
 .../src/StripGmxInterface.cxx                 | 26 ++++++++++++++-----
 6 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/DetectorDescription/ReadoutGeometryBase/ReadoutGeometryBase/DetectorDesign.h b/DetectorDescription/ReadoutGeometryBase/ReadoutGeometryBase/DetectorDesign.h
index 1f2d5bea7fba..7a97ff6d3a32 100644
--- a/DetectorDescription/ReadoutGeometryBase/ReadoutGeometryBase/DetectorDesign.h
+++ b/DetectorDescription/ReadoutGeometryBase/ReadoutGeometryBase/DetectorDesign.h
@@ -171,6 +171,9 @@ public:
     //virtual const HepGeom::Transform3D SiHitToGeoModel() const;
     virtual const Amg::Transform3D SiHitToGeoModel() const;
 
+    //Transform for "split" modules
+    virtual const Amg::Transform3D moduleShift() const;
+
     ///////////////////////////////////////////////////////////
     //
     // The following will replace existing methods but are not all implemented yet
diff --git a/DetectorDescription/ReadoutGeometryBase/src/DetectorDesign.cxx b/DetectorDescription/ReadoutGeometryBase/src/DetectorDesign.cxx
index 790a62824371..4f1e044f80db 100644
--- a/DetectorDescription/ReadoutGeometryBase/src/DetectorDesign.cxx
+++ b/DetectorDescription/ReadoutGeometryBase/src/DetectorDesign.cxx
@@ -126,4 +126,8 @@ SiIntersect DetectorDesign::inDetector(const SiLocalPosition &localPosition,
     return Amg::Transform3D::Identity();
 }
 
+  const Amg::Transform3D DetectorDesign::moduleShift() const {
+    return Amg::Transform3D::Identity();
+  }
+
 } // namespace InDetDD
diff --git a/DetectorDescription/ReadoutGeometryBase/src/SolidStateDetectorElementBase.cxx b/DetectorDescription/ReadoutGeometryBase/src/SolidStateDetectorElementBase.cxx
index 7437aed2f749..7de503992308 100644
--- a/DetectorDescription/ReadoutGeometryBase/src/SolidStateDetectorElementBase.cxx
+++ b/DetectorDescription/ReadoutGeometryBase/src/SolidStateDetectorElementBase.cxx
@@ -374,12 +374,12 @@ using Trk::distDepth;
       ptrXf = m_geoAlignStore->getAbsPosition(getMaterialGeom());
       if (ptrXf) {
 	m_transformHit = (*ptrXf) * m_design->SiHitToGeoModel(); //need .linear()?
-	geotrf = (*ptrXf);
+	geotrf = (*ptrXf) * m_design->moduleShift();
       }
     }
     else{
       m_transformHit  = (getMaterialGeom()->getAbsoluteTransform() * m_design->SiHitToGeoModel()); //need .linear()?
-      geotrf = getMaterialGeom()->getAbsoluteTransform();
+      geotrf = getMaterialGeom()->getAbsoluteTransform() * m_design->moduleShift();
     }
     
     const GeoTrf::Transform3D& geoTransform = geotrf;
diff --git a/InnerDetector/InDetDetDescr/SCT_ReadoutGeometry/SCT_ReadoutGeometry/StripBoxDesign.h b/InnerDetector/InDetDetDescr/SCT_ReadoutGeometry/SCT_ReadoutGeometry/StripBoxDesign.h
index 7b1c6070f9fb..3c7fe6c91529 100644
--- a/InnerDetector/InDetDetDescr/SCT_ReadoutGeometry/SCT_ReadoutGeometry/StripBoxDesign.h
+++ b/InnerDetector/InDetDetDescr/SCT_ReadoutGeometry/SCT_ReadoutGeometry/StripBoxDesign.h
@@ -40,7 +40,8 @@ public:
                    const int nRows,
                    const int nStrips,
                    const double pitch,
-                   const double length);
+                   const double length,
+		   const double zShift=0.0);
 
     ~StripBoxDesign() = default;
 
@@ -110,6 +111,8 @@ public:
     // For Strip sensors, readout cell == diode cell. Overload the SCT_ModuleSideDesign
     // member
     SiReadoutCellId readoutIdOfCell(const SiCellId &cellId) const;
+    
+    const Amg::Transform3D moduleShift() const final;
 
     // ---------------------------------------------------------------------------------------
     // DEPRECATED at least for Strips
@@ -156,6 +159,7 @@ private:
     int m_nStrips;
     double m_pitch;
     double m_length;
+    double m_zShift;
     Trk::RectangleBounds m_bounds;
 };
 
@@ -217,7 +221,6 @@ inline int StripBoxDesign::strip(int stripId1Dim) const {
     return stripId1Dim % m_nStrips; 
 }
 
-
 /// DEPRECATED for StripBoxDesign; no dead area
 double StripBoxDesign::deadAreaUpperBoundary() const {
     return 0.;
diff --git a/InnerDetector/InDetDetDescr/SCT_ReadoutGeometry/src/StripBoxDesign.cxx b/InnerDetector/InDetDetDescr/SCT_ReadoutGeometry/src/StripBoxDesign.cxx
index d15c9d71dfff..e7043070fdf8 100644
--- a/InnerDetector/InDetDetDescr/SCT_ReadoutGeometry/src/StripBoxDesign.cxx
+++ b/InnerDetector/InDetDetDescr/SCT_ReadoutGeometry/src/StripBoxDesign.cxx
@@ -19,7 +19,8 @@ StripBoxDesign::StripBoxDesign(const SiDetectorDesign::Axis stripDirection,
                                const int nRows,
                                const int nStrips,
                                const double pitch,
-                               const double length) : 
+                               const double length,
+			       const double zShift) : 
     SCT_ModuleSideDesign(thickness, true, true, true, 1, nRows * nStrips, nRows * nStrips, 0, false, carrier,
                          readoutSide, stripDirection, thicknessDirection) {
     if (nRows <= 0) {
@@ -31,6 +32,7 @@ StripBoxDesign::StripBoxDesign(const SiDetectorDesign::Axis stripDirection,
     m_nStrips = nStrips;
     m_pitch = pitch;
     m_length = length;
+    m_zShift = zShift;
 
     double width = m_nStrips * m_pitch;
     double fullLength = m_nRows * m_length;
@@ -246,6 +248,11 @@ void StripBoxDesign::distanceToDetectorEdge(SiLocalPosition const & pos,
 
   const GeoTrf::Transform3D StripBoxDesign::SiHitToGeoModel() const {
     return GeoTrf::RotateY3D(90.*GeoModelKernelUnits::deg);
-}
+  }
 
+  const  Amg::Transform3D StripBoxDesign::moduleShift() const{
+    //local x is global Z (along strip)  
+    return Amg::Translation3D(m_zShift,0.0, 0.0) * Amg::RotationMatrix3D::Identity();
+  }
+  
 } // namespace InDetDD
diff --git a/InnerDetector/InDetDetDescr/StripGeoModelXml/src/StripGmxInterface.cxx b/InnerDetector/InDetDetDescr/StripGeoModelXml/src/StripGmxInterface.cxx
index 97fabbd73e20..6e9b90e61448 100644
--- a/InnerDetector/InDetDetDescr/StripGeoModelXml/src/StripGmxInterface.cxx
+++ b/InnerDetector/InDetDetDescr/StripGeoModelXml/src/StripGmxInterface.cxx
@@ -190,13 +190,22 @@ double length(25.0);
 
     int split = 0;
     if(checkparm(typeName, "splitLevel", par, split)){
+      
+      //start from middle of first strip row
+      double initZShift = length * ( -(double)split*0.5 + 0.5 ) ; 
+
       for(int i = 0;i<split;i++){
-	//do we need some kind of shift for e.g. the corners and centre?	
-	 std::unique_ptr<InDetDD::StripBoxDesign> design=std::make_unique<InDetDD::StripBoxDesign>(stripDirection, fieldDirection,
-												   thickness, readoutSide,carrier, 1, nStrips, pitch,length);//single row
-	 m_detectorManager->addDesign(std::move(design));
-	 std::string splitName = typeName+"_"+std::to_string(i);
+	for(int side:{0,1}){//need different additional shift transform per side...
+	  int sign = (side==0) ? 1:-1;//...because shift in different direction per side
+	  double zShift = sign*(initZShift + (i*length));
+	  
+	  std::unique_ptr<InDetDD::StripBoxDesign> design=std::make_unique<InDetDD::StripBoxDesign>(stripDirection, fieldDirection,
+												    thickness, readoutSide,carrier, 1, nStrips, pitch,length,zShift);//single row
+	  
+	  m_detectorManager->addDesign(std::move(design));
+	  std::string splitName = typeName+"_"+std::to_string(i)+"_"+std::to_string(side);
 	 m_geometryMap[splitName] = m_detectorManager->numDesigns() -1;
+	}
       }
     }
                                                                       
@@ -383,7 +392,6 @@ void StripGmxInterface::addSplitSensor(string typeName, map<string, int> &index,
   map<string, int> updatedIndex;
   splitSensorId(index,extraIndex,updatedIndex);
   int splitIndex = extraIndex.second;
-  //TODO - implement!!
   //
 //    Get the ATLAS "Offline" wafer identifier 
 //
@@ -410,7 +418,13 @@ void StripGmxInterface::addSplitSensor(string typeName, map<string, int> &index,
     //    Create the detector element and add to the DetectorManager
     //
     
+
+    
     string splitTypeName = typeName + "_" + std::to_string(splitIndex);
+    if(updatedIndex["barrel_endcap"]==0){//only barrel-type have side dependence
+      splitTypeName += "_" + std::to_string(updatedIndex["side"]);
+    }
+
     const InDetDD::SiDetectorDesign *design = m_detectorManager->getDesign(m_geometryMap[splitTypeName]);
     
     if (!design) {
-- 
GitLab