From e1bef9a0f3fc41547240ebd52c34da9340f8d8db Mon Sep 17 00:00:00 2001
From: Whitney Armstrong <warmstrong@anl.gov>
Date: Mon, 15 Mar 2021 11:52:59 -0500
Subject: [PATCH] Updated cmake and added TestDetector

	modified:   CMakeLists.txt

	new file:   src/TestDetector.cpp
---
 CMakeLists.txt       | 26 +++++++++++++++++---------
 src/TestDetector.cpp | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 9 deletions(-)
 create mode 100644 src/TestDetector.cpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 70248b41..36f5f7a4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,18 +1,25 @@
 cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
+PROJECT(detector_template
+  VERSION 0.0.1
+  LANGUAGES CXX
+  DESCRIPTION "A template dd4hep+acts detector"
+  )
+
+find_package( DD4hep REQUIRED COMPONENTS DDCore DDG4 )
 
-#set(CMAKE_PREFIX_PATH $ENV{HOME}/lib CMAKE_PREFIX_PATH)
 #find_package(Acts REQUIRED COMPONENTS Core IdentificationPlugin TGeoPlugin DD4hepPlugin PATHS /home/whit/lib/cmake NO_DEFAULT_PATH)
-find_package(Acts REQUIRED COMPONENTS Core PluginIdentification PluginTGeo PluginDD4hep )
+#find_package(Acts REQUIRED COMPONENTS Core PluginIdentification PluginTGeo PluginDD4hep )
 
 #-----------------------------------------------------------------------------------
-set(a_lib_name topside2)
+set(a_lib_name detector_template)
+
+if("${PROJECT_NAME}" STREQUAL "detector_template")
+  message(WARNING "
+  Current project and library is named detector_template!
+  Please rename library to match corresponding detector implmentation.")
+endif()
+
 dd4hep_configure_output()
-#dd4hep_package (${a_lib_name} MAJOR 0 MINOR 0 PATCH 1
-#    USES         [ROOT   REQUIRED COMPONENTS Geom GenVector] 
-#                 [DD4hep REQUIRED COMPONENTS DDCore DDRec]
-#    OPTIONAL     XERCESC
-#    INCLUDE_DIRS include
-#    )
 
 dd4hep_add_plugin(${a_lib_name} SOURCES src/*.cpp
         USES ActsCore ActsPluginDD4hep
@@ -22,6 +29,7 @@ target_link_libraries(${a_lib_name}
   )
 
 #-----------------------------------------------------------------------------------
+# Install the detector description files.
 install(DIRECTORY compact/
     DESTINATION share/${PROJECT_NAME}/${a_lib_name}
     FILES_MATCHING PATTERN "*.xml"
diff --git a/src/TestDetector.cpp b/src/TestDetector.cpp
new file mode 100644
index 00000000..5669184b
--- /dev/null
+++ b/src/TestDetector.cpp
@@ -0,0 +1,36 @@
+#include <XML/Helper.h>
+
+using namespace dd4hep;
+
+static Ref_t createDetector(Detector& desc, xml_h handle, SensitiveDetector sens) {
+  xml::DetElement detElem = handle;
+  std::string     detName = detElem.nameStr();
+  int             detID   = detElem.id();
+
+  xml::Component dims      = detElem.dimensions();
+  double         rInner    = dims.inner_radius();
+  double         rMin      = dims.rmin();
+  double         thickness = dims.thickness();
+  double         innerZ    = dims.inner_z();
+  double         angle     = dims.angle();
+
+  Material mat = desc.material(detElem.materialStr());
+
+  Tube             outerTubeShape(rMin, rInner + thickness, innerZ + thickness);
+  Tube             innerTubeShape(0, rInner, innerZ);
+  SubtractionSolid unchamferedShape(outerTubeShape, innerTubeShape);
+  Cone             chamferShape(thickness, 0, rMin, 0, rMin + 2 * tan(angle) * thickness);
+  SubtractionSolid detShape(unchamferedShape, chamferShape, Position(0, 0, innerZ + thickness));
+  Volume           detVol(detName, detShape, mat);
+
+  detVol.setVisAttributes(desc.visAttributes(detElem.visStr()));
+
+  DetElement   det(detName, detID);
+  Volume       motherVol = desc.pickMotherVolume(det);
+  PlacedVolume detPV     = motherVol.placeVolume(detVol);
+  det.setPlacement(detPV);
+  return det;
+}
+
+// clang-format off
+DECLARE_DETELEMENT(TestDetector, createDetector)
-- 
GitLab