From e9f0a3f3c922b320b1f8185ac24ca0c94bdf1d06 Mon Sep 17 00:00:00 2001
From: Wouter Deconinck <wdconinc@gmail.com>
Date: Fri, 27 May 2022 00:27:28 +0000
Subject: [PATCH] Use ActsDD4hep instead of Acts; Acts::UnitConstants::mm == 1

---
 CMakeLists.txt                 | 13 ++++++++++---
 src/B0Preshower_geo.cpp        |  6 +++++-
 src/B0Tracker_geo.cpp          |  7 ++++---
 src/IP6BeamPipe.cpp            | 21 ++++++++++++---------
 src/OffMomentumTracker_geo.cpp |  7 +++++--
 src/Timepix_geo.cpp            |  4 ++++
 6 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 31d0ca3..287eacd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,7 +12,14 @@ SET(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
 
 find_package(DD4hep REQUIRED COMPONENTS DDCore DDG4)
-find_package(Acts REQUIRED COMPONENTS Core PluginTGeo PluginDD4hep )
+find_package(ActsDD4hep)
+if(ActsDD4hep_FOUND)
+  add_compile_definitions(USE_ACTSDD4HEP)
+  set(ActsDD4hep ActsDD4hep::ActsDD4hep)
+else()
+  find_package(Acts REQUIRED COMPONENTS Core PluginIdentification PluginTGeo PluginDD4hep)
+  set(ActsDD4hep ActsCore ActsPluginDD4hep)
+endif()
 
 #-----------------------------------------------------------------------------------
 set(a_lib_name IP6)
@@ -41,10 +48,10 @@ dd4hep_add_plugin(${a_lib_name}
   src/ZeroDegreeCalorimeterEcalWSciFi_geo.cpp
   src/ZeroDegreeCalorimeterEcal_geo.cpp
   src/ZeroDegreeCalorimeterSampling_geo.cpp
-  USES ActsCore ActsPluginDD4hep ROOT::Core ROOT::Gdml
+  USES ${ActsDD4hep} ROOT::Core ROOT::Gdml
   )
 target_link_libraries(${a_lib_name}
-  PUBLIC DD4hep::DDCore  DD4hep::DDRec DD4hep::DDG4
+  PUBLIC DD4hep::DDCore DD4hep::DDRec DD4hep::DDG4
   )
 
 #-----------------------------------------------------------------------------------
diff --git a/src/B0Preshower_geo.cpp b/src/B0Preshower_geo.cpp
index 1cfb91c..d918658 100644
--- a/src/B0Preshower_geo.cpp
+++ b/src/B0Preshower_geo.cpp
@@ -1,7 +1,11 @@
 #include <map>
 #include "DD4hep/DetFactoryHelper.h"
+
+#if defined(USE_ACTSDD4HEP)
+#include "ActsDD4hep/ActsExtension.hpp"
+#else
 #include "Acts/Plugins/DD4hep/ActsExtension.hpp"
-#include "Acts/Definitions/Units.hpp"
+#endif
 
 using namespace std;
 using namespace dd4hep;
diff --git a/src/B0Tracker_geo.cpp b/src/B0Tracker_geo.cpp
index 394408a..e44b417 100644
--- a/src/B0Tracker_geo.cpp
+++ b/src/B0Tracker_geo.cpp
@@ -7,10 +7,11 @@
 #include "XML/Layering.h"
 #include "XML/Utilities.h"
 
-
+#if defined(USE_ACTSDD4HEP)
+#include "ActsDD4hep/ActsExtension.hpp"
+#else
 #include "Acts/Plugins/DD4hep/ActsExtension.hpp"
-#include "Acts/Definitions/Units.hpp"
-
+#endif
 using namespace std;
 using namespace dd4hep;
 using namespace dd4hep::rec;
diff --git a/src/IP6BeamPipe.cpp b/src/IP6BeamPipe.cpp
index b88a884..ebcf481 100644
--- a/src/IP6BeamPipe.cpp
+++ b/src/IP6BeamPipe.cpp
@@ -11,8 +11,11 @@
 #include "TMath.h"
 #include <XML/Helper.h>
 
-#include "Acts/Definitions/Units.hpp"
+#if defined(USE_ACTSDD4HEP)
+#include "ActsDD4hep/ActsExtension.hpp"
+#else
 #include "Acts/Plugins/DD4hep/ActsExtension.hpp"
+#endif
 
 using namespace std;
 using namespace dd4hep;
@@ -61,10 +64,10 @@ static Ref_t create_detector(Detector& det, xml_h e, SensitiveDetector /* sens *
   // Add extension for the beampipe
   //Acts::ActsExtension* sdExtension = new Acts::ActsExtension();
   //sdExtension->addType("beampipe", "layer");
-  //sdExtension->addValue(0.001 * Acts::UnitConstants::mm, "r_min", "envelope");
-  //sdExtension->addValue(0.001 * Acts::UnitConstants::mm, "r_max", "envelope");
-  //sdExtension->addValue(0.001 * Acts::UnitConstants::mm, "z_min", "envelope");
-  //sdExtension->addValue(0.001 * Acts::UnitConstants::mm, "z_max", "envelope");
+  //sdExtension->addValue(0.001, "r_min", "envelope"); // Acts::UnitConstants::mm == 1
+  //sdExtension->addValue(0.001, "r_max", "envelope"); // Acts::UnitConstants::mm == 1
+  //sdExtension->addValue(0.001, "z_min", "envelope"); // Acts::UnitConstants::mm == 1
+  //sdExtension->addValue(0.001, "z_max", "envelope"); // Acts::UnitConstants::mm == 1
   //sdet.addExtension<Acts::ActsExtension>(sdExtension);
 
 
@@ -82,10 +85,10 @@ static Ref_t create_detector(Detector& det, xml_h e, SensitiveDetector /* sens *
     //beamPipeExtension->addType("beampipe", "beampipe");
     //beamPipeExtension->addType("passive cylinder", "layer");
     beamPipeExtension->addType("beampipe", "layer");
-    beamPipeExtension->addValue(0.001 * Acts::UnitConstants::mm, "r_min", "envelope");
-    beamPipeExtension->addValue(0.001 * Acts::UnitConstants::mm, "r_max", "envelope");
-    beamPipeExtension->addValue(0.001 * Acts::UnitConstants::mm, "z_min", "envelope");
-    beamPipeExtension->addValue(0.001 * Acts::UnitConstants::mm, "z_max", "envelope");
+    beamPipeExtension->addValue(0.001, "r_min", "envelope"); // Acts::UnitConstants::mm == 1
+    beamPipeExtension->addValue(0.001, "r_max", "envelope"); // Acts::UnitConstants::mm == 1
+    beamPipeExtension->addValue(0.001, "z_min", "envelope"); // Acts::UnitConstants::mm == 1
+    beamPipeExtension->addValue(0.001, "z_max", "envelope"); // Acts::UnitConstants::mm == 1
 
     central_det.addExtension<Acts::ActsExtension>(beamPipeExtension);
     // TODO add material binning
diff --git a/src/OffMomentumTracker_geo.cpp b/src/OffMomentumTracker_geo.cpp
index 9ff7361..188c7b0 100644
--- a/src/OffMomentumTracker_geo.cpp
+++ b/src/OffMomentumTracker_geo.cpp
@@ -2,9 +2,12 @@
 #include "DD4hep/DetFactoryHelper.h"
 #include "XML/Utilities.h"
 #include "XML/Layering.h"
-#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
-#include "Acts/Definitions/Units.hpp"
 
+#if defined(USE_ACTSDD4HEP)
+#include "ActsDD4hep/ActsExtension.hpp"
+#else
+#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
+#endif
 using namespace std;
 using namespace dd4hep;
 using namespace dd4hep::detail;
diff --git a/src/Timepix_geo.cpp b/src/Timepix_geo.cpp
index a45c1f4..2ccf98d 100644
--- a/src/Timepix_geo.cpp
+++ b/src/Timepix_geo.cpp
@@ -4,7 +4,11 @@
 #include "DDRec/Surface.h"
 #include "DDRec/DetectorData.h"
 
+//#if defined(USE_ACTSDD4HEP)
+//#include "ActsDD4hep/ActsExtension.hpp"
+//#else
 //#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
+//#endif
 
 using namespace std;
 using namespace dd4hep;
-- 
GitLab