From b2c2a08b8ded710a426f3c5959d67b68a9c3a435 Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Mon, 25 Jul 2022 21:52:29 +0200
Subject: [PATCH] Fix fast sim example. Improve param.volumes examples

---
 DDCore/src/Grammar.cpp                         | 18 ++++++++++++++++--
 DDG4/src/Geant4Converter.cpp                   |  6 ++++--
 examples/ClientTests/CMakeLists.txt            |  2 +-
 .../ClientTests/compact/ReplicateVolume.xml    |  6 +++---
 examples/ClientTests/src/ParamVolume_geo.cpp   |  3 +++
 5 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/DDCore/src/Grammar.cpp b/DDCore/src/Grammar.cpp
index ad54bfc45..c89593da8 100644
--- a/DDCore/src/Grammar.cpp
+++ b/DDCore/src/Grammar.cpp
@@ -38,10 +38,11 @@
 #endif
 
 namespace dd4hep {
+  const dd4hep::tools::Evaluator& evaluator();
   const dd4hep::tools::Evaluator& g4Evaluator();
 }
 namespace {
-  static const dd4hep::tools::Evaluator& s__eval(dd4hep::g4Evaluator());
+  static const dd4hep::tools::Evaluator* s__eval(&dd4hep::g4Evaluator());
 }
 
 
@@ -76,8 +77,21 @@ namespace dd4hep {
     /// Helper to parse single item
     std::pair<int,double> grammar_evaluate_item(std::string val);
   }
+
+  /// Set grammar evaluator
+  void setGrammarEvaluator(const std::string& type)    {
+    if ( type == "TGeo" )
+      s__eval = &evaluator();
+    else if ( type == "Geant4" || type == "G4" )
+      s__eval = &g4Evaluator();
+    else if ( type == "CGS" )
+      s__eval = &g4Evaluator();
+    else
+      except("Grammar","++ Undefined evaluator type: "+type);
+  }
 }
 
+
 /// Equality operator
 bool dd4hep::BasicGrammar::specialization_t::operator==(const specialization_t& cp)  const  {
   return this->bind  == cp.bind &&
@@ -238,7 +252,7 @@ std::pair<int,double> dd4hep::detail::grammar_evaluate_item(std::string val)   {
     val.erase(idx, 5);
   while (val[0] == ' ')
     val.erase(0, 1);
-  auto result = s__eval.evaluate(val.c_str());
+  auto result = s__eval->evaluate(val.c_str());
   return result;
 }
 
diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp
index c86bd3e7f..1c10dbb27 100644
--- a/DDG4/src/Geant4Converter.cpp
+++ b/DDG4/src/Geant4Converter.cpp
@@ -872,12 +872,14 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node)
 	else
 	  except("Geant4Converter",
 		 "++ Replication around unknown axis is not implemented. flags: %16X", flags);
+	printout(INFO,"Geant4Converter","++ Replicate: Axis: %ld Count: %ld offset: %f width: %f",
+		 axis, count, offset, width);
 	auto* g4pv = new G4PVReplica(name,      // its name
 				     g4vol,     // its logical volume
 				     g4mot,     // its mother (logical) volume
 				     axis,      // its replication axis
 				     count,     // Number of replicas
-				     width,     // Distanve between 2 replicas
+				     width,     // Distance between 2 replicas
 				     offset);   // Placement offset in axis direction
 	pvPlaced = { g4pv, nullptr };
 #if 0
@@ -887,7 +889,7 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node)
 						     g4mot,     // its mother (logical) volume
 						     axis,      // its replication axis
 						     count,     // Number of replicas
-						     width,     // Distanve between 2 replicas
+						     width,     // Distance between 2 replicas
 						     offset);   // Placement offset in axis direction
 	/// Update replica list to avoid additional conversions...
 	auto* g4pv = pvPlaced.second ? pvPlaced.second : pvPlaced.first;
diff --git a/examples/ClientTests/CMakeLists.txt b/examples/ClientTests/CMakeLists.txt
index 584584ceb..7c91305b4 100644
--- a/examples/ClientTests/CMakeLists.txt
+++ b/examples/ClientTests/CMakeLists.txt
@@ -441,7 +441,7 @@ if (DD4HEP_USE_GEANT4)
       dd4hep_add_test_reg( ClientTests_sim_${script}_LONGTEST
         COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
         EXEC_ARGS  ${Python_EXECUTABLE} ${ClientTestsEx_INSTALL}/scripts/${script}.py -batch -events 2
-		   -geometry ${ClientTestsEx_INSTALL}/compact/${script}.xml -batch -events 2
+		   -geometry ${ClientTestsEx_INSTALL}/compact/SiliconBlock.xml -batch -events 2
         REGEX_PASS "Event 1 Begin event action. Access event related information"
         REGEX_FAIL "Exception;EXCEPTION;ERROR;Error" )
     endforeach(script)
diff --git a/examples/ClientTests/compact/ReplicateVolume.xml b/examples/ClientTests/compact/ReplicateVolume.xml
index a42f2cce8..93352521b 100644
--- a/examples/ClientTests/compact/ReplicateVolume.xml
+++ b/examples/ClientTests/compact/ReplicateVolume.xml
@@ -41,11 +41,11 @@
   </limits>
 
   <detectors>
-    <detector id="1" name="Param3D_1" type="DD4hep_ParamVolume" vis="VisibleGreen" readout="Hits3D" limits="param_limits">
+    <detector id="1" name="Replicate_1" type="DD4hep_ParamVolume" vis="VisibleGreen" readout="Hits3D" limits="param_limits">
       <!-- Mother volume dimensions  -->
       <box x="120*cm" y="120*cm" z="120*cm" material="Air"/>
       <!-- Mother volume placement in the world -->
-      <position x="0*cm" y="0*cm" z="-120*cm"/>
+      <position x="0*cm" y="0*cm" z="0*cm"/>
       <rotation x="0" y="0" z="0"/>
 
       <!-- Parameterisation arguments -->
@@ -55,7 +55,7 @@
 	  <position x="0*cm" y="0*cm" z="0*cm"/>
 	  <rotation x="0" y="0" z="0"/>
 	</start>
-	<replicate count="1" distance="10*cm" start="0*cm" axis="z"/>
+	<replicate count="5" distance="10*cm" start="0*cm" axis="z"/>
       </param>
     </detector>
   </detectors>
diff --git a/examples/ClientTests/src/ParamVolume_geo.cpp b/examples/ClientTests/src/ParamVolume_geo.cpp
index 79492220a..dea1e9f8d 100644
--- a/examples/ClientTests/src/ParamVolume_geo.cpp
+++ b/examples/ClientTests/src/ParamVolume_geo.cpp
@@ -12,6 +12,7 @@
 //==========================================================================
 
 // Framework includes
+#include "DD4hep/Printout.h"
 #include "DD4hep/DetFactoryHelper.h"
 
 using namespace dd4hep;
@@ -60,6 +61,8 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
 				x_repl.count(),
 				x_repl.distance(),
 				x_repl.start());
+    printout(INFO,"ReplicateVolume","Axis: %s Count: %d offset:%f  width:%f",
+	     ax.c_str(), x_repl.count(), x_repl.start(), x_repl.distance());
   }
   else if ( x_param.hasChild(_U(transformation)) )   {
     xml_dim_t  x_dim_x, x_dim_y, x_dim_z, x_trafo = x_param.transformation();
-- 
GitLab