From 0484d1dcab5c69b80e8b154b258c53c871362a2c Mon Sep 17 00:00:00 2001
From: Markus Frank <markus.frank@cern.ch>
Date: Wed, 25 Mar 2015 14:37:57 +0000
Subject: [PATCH] Add Halfspace shape

---
 DDCore/include/DD4hep/Shapes.h      | 33 +++++++++++++++++++++++++++++
 DDCore/src/Handle.cpp               |  1 +
 DDCore/src/Shapes.cpp               | 12 +++++++++++
 DDCore/src/plugins/ShapePlugins.cpp | 12 +++++++++--
 4 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/DDCore/include/DD4hep/Shapes.h b/DDCore/include/DD4hep/Shapes.h
index 3d3f4a7d2..99b863128 100644
--- a/DDCore/include/DD4hep/Shapes.h
+++ b/DDCore/include/DD4hep/Shapes.h
@@ -29,6 +29,7 @@
 #include "TGeoEltu.h"
 #include "TGeoHype.h"
 #include "TGeoTorus.h"
+#include "TGeoHalfSpace.h"
 #include "TGeoCompositeShape.h"
 
 /// Namespace for the AIDA detector description toolkit
@@ -152,6 +153,38 @@ namespace DD4hep {
       double z() const;
     };
 
+    /// Class describing half-space
+    /**
+     *   For any further documentation please see the following ROOT documentation:
+     *   \see http://root.cern.ch/root/html/TGeoHalfSpace.html
+     *
+     *
+     *   \author  M.Frank
+     *   \version 1.0
+     *   \ingroup DD4HEP_GEOMETRY
+     */
+    class HalfSpace: public Solid_type<TGeoHalfSpace> {
+    protected:
+      /// Internal helper method to support object construction
+      void make(const double* const point, const double* const normal);
+
+    public:
+      /// Constructor to be used with an existing object
+      template <typename Q> HalfSpace(const Q* p)
+        : Solid_type<TGeoHalfSpace>(p) {
+      }
+
+      /// Constructor to be used with an existing object
+      template <typename Q> HalfSpace(const Handle<Q>& e)
+        : Solid_type<TGeoHalfSpace>(e) {
+      }
+
+      /// Constructor to create an new halfspace object from a point on a plane and the plane normal
+      HalfSpace(const double* const point, const double* const normal) {
+        make(point,normal);
+      }
+    };
+
     /// Class describing a Polycone shape
     /**
      *   Polycone. It has at least 9 parameters :
diff --git a/DDCore/src/Handle.cpp b/DDCore/src/Handle.cpp
index 7b3ca2073..150f7ef2b 100644
--- a/DDCore/src/Handle.cpp
+++ b/DDCore/src/Handle.cpp
@@ -258,6 +258,7 @@ DD4HEP_INSTANTIATE_HANDLE(TGeoTrd1);
 DD4HEP_INSTANTIATE_HANDLE(TGeoTrd2);
 DD4HEP_INSTANTIATE_HANDLE(TGeoSphere);
 DD4HEP_INSTANTIATE_HANDLE(TGeoTorus);
+DD4HEP_INSTANTIATE_HANDLE(TGeoHalfSpace);
 DD4HEP_INSTANTIATE_HANDLE(TGeoShape);
 DD4HEP_INSTANTIATE_HANDLE(TGeoShapeAssembly);
 DD4HEP_INSTANTIATE_HANDLE(TGeoCompositeShape);
diff --git a/DDCore/src/Shapes.cpp b/DDCore/src/Shapes.cpp
index 979d78bd4..ba3f2f710 100644
--- a/DDCore/src/Shapes.cpp
+++ b/DDCore/src/Shapes.cpp
@@ -30,6 +30,7 @@
 #include "TGeoSphere.h"
 #include "TGeoTorus.h"
 #include "TGeoMatrix.h"
+#include "TGeoHalfSpace.h"
 #include "TGeoBoolNode.h"
 #include "TGeoCompositeShape.h"
 
@@ -55,6 +56,11 @@ std::string DD4hep::Geometry::toStringSolid(const TGeoShape* shape, int precisio
         << " y:" << s->GetDY()
         << " z:" << s->GetDZ();
   }
+  else if (cl == TGeoHalfSpace::Class()) {
+    TGeoHalfSpace* s = (TGeoHalfSpace*)(const_cast<TGeoShape*>(shape));
+    log << " Point:  (" << s->GetPoint()[0] << ", " << s->GetPoint()[1] << ", " << s->GetPoint()[2] << ") " 
+	<< " Normal: (" << s->GetNorm()[0]  << ", " << s->GetNorm()[1]  << ", " << s->GetNorm()[2]  << ") ";
+  }
   else if (cl == TGeoTube::Class()) {
     const TGeoTube* s = (const TGeoTube*) shape;
     log << " rmin:" << s->GetRmin() << " rmax:" << s->GetRmax() << " dz:" << s->GetDz();
@@ -185,6 +191,11 @@ double Box::z() const {
   return this->ptr()->GetDZ();
 }
 
+/// Internal helper method to support object construction
+void HalfSpace::make(const double* const point, const double* const normal)   {
+  _assign(new TGeoHalfSpace("",(Double_t*)point, (Double_t*)normal), "", "halfspace",true);
+}
+
 /// Constructor to be used when creating a new object
 Polycone::Polycone(double start, double delta) {
   _assign(new TGeoPcon(start/dd4hep::deg, delta/dd4hep::deg, 0), "", "polycone", false);
@@ -501,6 +512,7 @@ IntersectionSolid::IntersectionSolid(const Solid& shape1, const Solid& shape2, c
 
 INSTANTIATE(TGeoShape);
 INSTANTIATE(TGeoBBox);
+INSTANTIATE(TGeoHalfSpace);
 INSTANTIATE(TGeoCone);
 INSTANTIATE(TGeoConeSeg);
 INSTANTIATE(TGeoParaboloid);
diff --git a/DDCore/src/plugins/ShapePlugins.cpp b/DDCore/src/plugins/ShapePlugins.cpp
index 6894a7e01..a17edaf93 100644
--- a/DDCore/src/plugins/ShapePlugins.cpp
+++ b/DDCore/src/plugins/ShapePlugins.cpp
@@ -17,13 +17,11 @@ using namespace std;
 using namespace DD4hep;
 using namespace DD4hep::Geometry;
 
-#if 0
 static Ref_t create_Assembly(lcdd_t&, xml_h e)   {
   xml_dim_t dim(e);
   return Ref_t(new TGeoShapeAssembly());
 }
 DECLARE_XMLELEMENT(Assembly__shape_constructor,create_Assembly)
-#endif
 
 static Ref_t create_Box(lcdd_t&, xml_h e)   {
   xml_dim_t dim(e);
@@ -31,6 +29,16 @@ static Ref_t create_Box(lcdd_t&, xml_h e)   {
 }
 DECLARE_XMLELEMENT(Box__shape_constructor,create_Box)
 
+static Ref_t create_HalfSpace(lcdd_t&, xml_h e)   {
+  xml_dim_t dim(e);
+  xml_dim_t point  = e.child(_U(point));
+  xml_dim_t normal = e.child(_U(normal));
+  double p[3] = { point.x(),  point.y(),  point.z()};
+  double n[3] = { normal.x(), normal.y(), normal.z()};
+  return HalfSpace(p, n);
+}
+DECLARE_XMLELEMENT(HalfSpace__shape_constructor,create_HalfSpace)
+
 static Ref_t create_Polycone(lcdd_t&, xml_h element)   {
   xml_dim_t e(element);
   int num = 0;
-- 
GitLab