From 4a79ede00367e593f4d1e67383ac13c40a7a64a1 Mon Sep 17 00:00:00 2001
From: Markus Frank <markus.frank@cern.ch>
Date: Thu, 3 Dec 2015 14:46:10 +0000
Subject: [PATCH] Fix to nightly build examples

---
 DDG4/plugins/Geant4SDActions.cpp              |  7 ++--
 DDG4/python/DDG4.py                           | 32 +++++++++++++++---
 examples/CLICSiD/CMakeLists.txt               | 19 ++++++-----
 examples/CLICSiD/scripts/CLICSid.py           | 17 +---------
 examples/ClientTests/CMakeLists.txt           | 21 ++++++++----
 .../{Geant4Assemblies.py => Assemblies.py}    | 23 +++++++------
 examples/ClientTests/scripts/FCC_Hcal.py      | 19 ++++++-----
 examples/ClientTests/scripts/LheD_tracker.py  | 33 +++----------------
 examples/ClientTests/scripts/MiniTel.py       | 12 ++-----
 .../ClientTests/scripts/NestedDetectors.py    | 22 ++++++-------
 examples/ClientTests/scripts/SiliconBlock.py  | 25 +++++++-------
 11 files changed, 112 insertions(+), 118 deletions(-)
 rename examples/ClientTests/scripts/{Geant4Assemblies.py => Assemblies.py} (59%)

diff --git a/DDG4/plugins/Geant4SDActions.cpp b/DDG4/plugins/Geant4SDActions.cpp
index 5b86e3ea1..c8ef7ef9a 100644
--- a/DDG4/plugins/Geant4SDActions.cpp
+++ b/DDG4/plugins/Geant4SDActions.cpp
@@ -318,9 +318,10 @@ namespace DD4hep {
         if ( current == -1 ) {
           return;
         }
-        double deposit = pre.truth.deposit, time = mean_time / deposit;
-        Position pos = mean_pos / deposit;
-        Momentum mom = 0.5 * (pre.momentum + post.momentum);
+        double deposit = pre.truth.deposit;
+        double   time  = deposit != 0 ? mean_time / deposit : mean_time;
+        Position pos   = deposit != 0 ? mean_pos  / deposit : mean_pos;
+        Momentum mom   = 0.5 * (pre.momentum + post.momentum);
         double path_len = (post.position - pre.position).R();
         Geant4Tracker::Hit* hit = new Geant4Tracker::Hit(pre.truth.trackID,
                                                          pre.truth.pdgID,
diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py
index 6593146f3..94076704a 100644
--- a/DDG4/python/DDG4.py
+++ b/DDG4/python/DDG4.py
@@ -497,6 +497,28 @@ class Geant4:
     if type is None: type = self.sensitive_types['tracker']
     return self.setupDetector(name,type)
 
+  def setupTrackingField(self, name='MagFieldTrackingSetup', stepper='HelixSimpleRunge', equation='Mag_UsualEqRhs',prt=False):
+    import SystemOfUnits
+    field = self.addConfig('Geant4FieldTrackingSetupAction/'+name)
+    field.stepper            = stepper
+    field.equation           = equation
+    field.eps_min            = 5e-05*SystemOfUnits.mm
+    field.eps_max            = 0.001*SystemOfUnits.mm
+    field.min_chord_step     = 0.01*SystemOfUnits.mm
+    field.delta_chord        = 0.25*SystemOfUnits.mm
+    field.delta_intersection = 1e-05*SystemOfUnits.mm
+    field.delta_one_step     = 0.001*SystemOfUnits.mm
+    if prt:
+      print '+++++> ',field.name,'-> stepper  = ',field.stepper
+      print '+++++> ',field.name,'-> equation = ',field.equation
+      print '+++++> ',field.name,'-> eps_min  = ',field.eps_min,'[mm]'
+      print '+++++> ',field.name,'-> eps_max  = ',field.eps_max,'[mm]'
+      print '+++++> ',field.name,'-> delta_chord        = ',field.delta_chord,'[mm]'
+      print '+++++> ',field.name,'-> min_chord_step     = ',field.min_chord_step,'[mm]'
+      print '+++++> ',field.name,'-> delta_one_step     = ',field.delta_one_step,'[mm]'
+      print '+++++> ',field.name,'-> delta_intersection = ',field.delta_intersection,'[mm]'
+    return field
+  
   def setupPhysics(self,name):
     phys = self.master().physicsList()
     phys.extends = name
@@ -509,11 +531,11 @@ class Geant4:
     gun = GeneratorAction(self.kernel(),"Geant4ParticleGun/"+name,True)
     for i in args.items():
       setattr(gun,i[0],i[1])
-    gun.energy   = energy
-    gun.particle = particle
+    gun.energy       = energy
+    gun.particle     = particle
     gun.multiplicity = multiplicity
-    gun.position = position
-    gun.isotrop = isotrop
+    gun.position     = position
+    gun.isotrop      = isotrop
     gun.enableUI()
     self.kernel().generatorAction().add(gun)
     return gun
@@ -542,7 +564,7 @@ class Geant4:
   def setupLCIOOutput(self,name,output):
     evt_lcio = EventAction(self.kernel(),'Geant4Output2LCIO/'+name,True)
     evt_lcio.Control = True
-    evt_lcio.Output = output
+    evt_lcio.Output  = output
     evt_lcio.enableUI()
     self.kernel().eventAction().add(evt_lcio)
     return evt_lcio
diff --git a/examples/CLICSiD/CMakeLists.txt b/examples/CLICSiD/CMakeLists.txt
index ad71fa533..d46482574 100644
--- a/examples/CLICSiD/CMakeLists.txt
+++ b/examples/CLICSiD/CMakeLists.txt
@@ -20,11 +20,14 @@ dd4hep_package ( CLICSiD MAJOR 0 MINOR 0 PATCH 1
 )
 dd4hep_install_dir( compact scripts sim DESTINATION ${DD4hep_DIR}/examples/CLICSiD )
 #--------------------------------------------------------------------------
-dd4hep_add_executable(CLICSiDXML SOURCES scripts/CLICSiDXML.C
-  USES  [DD4hep REQUIRED COMPONENTS DDG4] GEANT4 )
-#--------------------------------------------------------------------------
-dd4hep_add_executable(CLICSiDAClick SOURCES scripts/CLICSiDAClick.C
-  USES  [DD4hep REQUIRED COMPONENTS DDG4] GEANT4 )
+if (DD4HEP_USE_GEANT4)
+  dd4hep_add_executable(CLICSiDXML SOURCES scripts/CLICSiDXML.C
+    USES  [DD4hep REQUIRED COMPONENTS DDG4] GEANT4 )
+  #--------------------------------------------------------------------------
+  dd4hep_add_executable(CLICSiDAClick SOURCES scripts/CLICSiDAClick.C
+    USES  [DD4hep REQUIRED COMPONENTS DDG4] GEANT4 )
+endif()
+
 #---Testing-------------------------------------------------------------------------
 dd4hep_configure_scripts ( CLICSiD DEFAULT_SETUP WITH_TESTS )
 
@@ -41,7 +44,7 @@ endforeach()
 # ROOT Geometry overlap checks
 dd4hep_add_test_reg( test_CLICSiD_check_geometry
   COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_CLICSiD.sh"
-  EXEC_ARGS  python ${CMAKE_INSTALL_PREFIX}/python/checkGeometry.py
+  EXEC_ARGS  python ${DD4hep_DIR}/python/checkGeometry.py
                     --compact=file:${CMAKE_CURRENT_SOURCE_DIR}/compact/compact.xml
   # This takes too long                  --full=true --ntracks=10 --option=o --vx=0 --vy=0 --vz=0
   REGEX_PASS " Execution finished..." )
@@ -49,7 +52,7 @@ dd4hep_add_test_reg( test_CLICSiD_check_geometry
 # ROOT Geometry overlap checks
 dd4hep_add_test_reg( test_CLICSiD_check_overlaps
   COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_CLICSiD.sh"
-  EXEC_ARGS  python ${CMAKE_INSTALL_PREFIX}/python/checkOverlaps.py 
+  EXEC_ARGS  python ${DD4hep_DIR}/python/checkOverlaps.py 
                     --compact=file:${CMAKE_CURRENT_SOURCE_DIR}/compact/compact.xml
                     --tolerance=0.1
   REGEX_PASS " Execution finished..." )
@@ -69,7 +72,7 @@ if (DD4HEP_USE_GEANT4)
   # Material scan
   dd4hep_add_test_reg( test_CLICSiD_DDG4_g4material_scan
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_CLICSiD.sh"
-    EXEC_ARGS  python ${CMAKE_INSTALL_PREFIX}/python/g4MaterialScan.py
+    EXEC_ARGS  python ${DD4hep_DIR}/python/g4MaterialScan.py
                       --compact=file:${CMAKE_CURRENT_SOURCE_DIR}/compact/compact.xml 
                       "--position=0,0,0" "--direction=0,1,0"
     REGEX_PASS " Terminate Geant4 and delete associated actions." )
diff --git a/examples/CLICSiD/scripts/CLICSid.py b/examples/CLICSiD/scripts/CLICSid.py
index 4d949735d..32b05f3dd 100644
--- a/examples/CLICSiD/scripts/CLICSid.py
+++ b/examples/CLICSiD/scripts/CLICSid.py
@@ -17,22 +17,7 @@ class CLICSid:
 
   # Example to show how to configure G4 magnetic field tracking
   def setupField(self, quiet=True):
-    field = self.geant4.addConfig('Geant4FieldTrackingSetupAction/MagFieldTrackingSetup')
-    field.stepper            = "HelixGeant4Runge"
-    field.equation           = "Mag_UsualEqRhs"
-    field.eps_min            = 5e-05 * mm
-    field.eps_max            = 0.001 * mm
-    field.min_chord_step     = 0.01 * mm
-    field.delta_chord        = 0.25 * mm
-    field.delta_intersection = 1e-05 * mm
-    field.delta_one_step     = 0.001 * mm
-    if not quiet:
-      print '+++++> ',field.name,'-> stepper  = ',field.stepper
-      print '+++++> ',field.name,'-> equation = ',field.equation
-      print '+++++> ',field.name,'-> eps_min  = ',field.eps_min
-      print '+++++> ',field.name,'-> eps_max  = ',field.eps_max
-      print '+++++> ',field.name,'-> delta_one_step = ',field.delta_one_step
-    return field
+    return self.geant4.setupTrackingField(prt=True)
 
   # Example to show how to setup random generator
   def setupRandom(self, name, type=None, seed=None, quiet=True):
diff --git a/examples/ClientTests/CMakeLists.txt b/examples/ClientTests/CMakeLists.txt
index ae9d9bed1..3527c2263 100644
--- a/examples/ClientTests/CMakeLists.txt
+++ b/examples/ClientTests/CMakeLists.txt
@@ -30,12 +30,15 @@ dd4hep_configure_scripts( ClientTests DEFAULT_SETUP WITH_TESTS)
 #
 #
 #
-foreach (test Assemblies BoxTrafos IronCylinder LheD_tracker MagnetFields MaterialTester MiniTel SectorBarrelCalorimeter SiliconBlock NestedSimple NestedDetectors )
+foreach (test Assemblies BoxTrafos IronCylinder LheD_tracker MagnetFields MaterialTester 
+              MiniTel SectorBarrelCalorimeter SiliconBlock NestedSimple NestedDetectors )
   # Test format conversions
   foreach( type lcdd gdml vis )
     dd4hep_add_test_reg( ClientTests_${test}_converter_${type}
       COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
-      EXEC_ARGS  geoConverter -compact2${type} -input file:${CMAKE_CURRENT_SOURCE_DIR}/compact/${test}.xml -output file:${test}.${type}
+      EXEC_ARGS  geoConverter -compact2${type}
+                              -input file:${CMAKE_CURRENT_SOURCE_DIR}/compact/${test}.xml
+                              -output file:${test}.${type}
       REGEX_PASS " Handled [1-9][0-9]* volumes" )
   endforeach(type)
 endforeach()
@@ -57,7 +60,9 @@ foreach (test Assemblies BoxTrafos LheD_tracker MagnetFields MiniTel SiliconBloc
   if (DD4HEP_USE_GEANT4)
     dd4hep_add_test_reg( ClientTests_${test}_g4material_scan
       COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
-      EXEC_ARGS  python ${CMAKE_INSTALL_PREFIX}/python/g4MaterialScan.py --compact=file:${CMAKE_CURRENT_SOURCE_DIR}/compact/${test}.xml "--position=0,0,0" "--direction=0,1,0"
+      EXEC_ARGS  python ${DD4hep_DIR}/python/g4MaterialScan.py
+                        --compact=file:${CMAKE_CURRENT_SOURCE_DIR}/compact/${test}.xml
+                        "--position=0,0,0" "--direction=0,1,0"
       REGEX_PASS " Terminate Geant4 and delete associated actions." )
   endif(DD4HEP_USE_GEANT4)
 endforeach()
@@ -69,13 +74,17 @@ foreach (test BoxTrafos IronCylinder MiniTel SiliconBlock NestedSimple )
   # ROOT Geometry checks
   dd4hep_add_test_reg( ClientTests_${test}_check_geometry
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
-    EXEC_ARGS  python ${CMAKE_INSTALL_PREFIX}/python/checkGeometry.py --compact=file:${CMAKE_CURRENT_SOURCE_DIR}/compact/${test}.xml --full=true --ntracks=10
+    EXEC_ARGS  python ${DD4hep_DIR}/python/checkGeometry.py
+                      --compact=file:${CMAKE_CURRENT_SOURCE_DIR}/compact/${test}.xml
+                      --full=true --ntracks=10
     REGEX_PASS " Execution finished..." )
   #
   # ROOT Geometry overlap checks
   dd4hep_add_test_reg( ClientTests_${test}_check_overlaps
     COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
-    EXEC_ARGS  python ${CMAKE_INSTALL_PREFIX}/python/checkOverlaps.py --compact=file:${CMAKE_CURRENT_SOURCE_DIR}/compact/${test}.xml --tolerance=0.1
+    EXEC_ARGS  python ${DD4hep_DIR}/python/checkOverlaps.py 
+                      --compact=file:${CMAKE_CURRENT_SOURCE_DIR}/compact/${test}.xml
+                      --tolerance=0.1
     REGEX_PASS " Execution finished..." )
 endforeach()
 #
@@ -84,7 +93,7 @@ endforeach()
 if (DD4HEP_USE_GEANT4)
   #
   # Geant4 full simulation checks of simple detectors
-  foreach(script MiniTel LheD_tracker)
+  foreach(script Assemblies LheD_tracker MiniTel NestedDetectors )
     dd4hep_add_test_reg( ClientTests_sim_${script}
       COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_ClientTests.sh"
       EXEC_ARGS  python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/${script}.py batch
diff --git a/examples/ClientTests/scripts/Geant4Assemblies.py b/examples/ClientTests/scripts/Assemblies.py
similarity index 59%
rename from examples/ClientTests/scripts/Geant4Assemblies.py
rename to examples/ClientTests/scripts/Assemblies.py
index 9da68f795..4dc7b7a2d 100644
--- a/examples/ClientTests/scripts/Geant4Assemblies.py
+++ b/examples/ClientTests/scripts/Assemblies.py
@@ -1,4 +1,4 @@
-import os, time, DDG4
+import os, sys, time, DDG4
 from SystemOfUnits import *
 #
 """
@@ -11,20 +11,23 @@ from SystemOfUnits import *
 def run():
   kernel = DDG4.Kernel()
   install_dir = os.environ['DD4hepINSTALL']
-  example_dir = install_dir+'/examples/DDG4/examples';
   kernel.loadGeometry("file:"+install_dir+"/examples/ClientTests/compact/Assemblies.xml")
-  kernel.loadXML("file:"+example_dir+"/DDG4_field.xml")
   #
-  simple = DDG4.Simple(kernel,tracker='Geant4TrackerCombineAction')
-  simple.printDetectors()
+  geant4 = DDG4.Geant4(kernel,tracker='Geant4TrackerCombineAction')
+  geant4.printDetectors()
   # Configure UI
-  simple.setupCshUI()
+  geant4.setupCshUI()
+  if len(sys.argv) >= 2 and sys.argv[1] =="batch":
+    kernel.UI = ''
+
+  # Configure field
+  field = geant4.setupTrackingField(prt=True)
   # Configure I/O
-  simple.setupROOTOutput('RootOutput','Assemblies_'+time.strftime('%Y-%m-%d_%H-%M'),mc_truth=False)
+  geant4.setupROOTOutput('RootOutput','Assemblies_'+time.strftime('%Y-%m-%d_%H-%M'),mc_truth=False)
   # Setup particle gun
-  simple.setupGun("Gun",particle='e-',energy=2*GeV,position=(0.15*mm,0.12*mm,0.1*cm),multiplicity=1)
+  geant4.setupGun("Gun",particle='e-',energy=2*GeV,position=(0.15*mm,0.12*mm,0.1*cm),multiplicity=1)
   # First the tracking detectors
-  seq,act = simple.setupTracker('VXD')
+  seq,act = geant4.setupTracker('VXD')
   # Now build the physics list:
   phys = kernel.physicsList()
   phys.extends = 'QGSP_BERT'
@@ -32,7 +35,7 @@ def run():
   phys.dump()
 
   DDG4.setPrintLevel(DDG4.OutputLevel.DEBUG)
-  simple.execute()
+  geant4.execute()
 
 if __name__ == "__main__":
   run()
diff --git a/examples/ClientTests/scripts/FCC_Hcal.py b/examples/ClientTests/scripts/FCC_Hcal.py
index 6e1541488..288370d56 100644
--- a/examples/ClientTests/scripts/FCC_Hcal.py
+++ b/examples/ClientTests/scripts/FCC_Hcal.py
@@ -20,26 +20,27 @@ def run():
   kernel.setOutputLevel('ShellHandler',Output.DEBUG)
   kernel.setOutputLevel('Gun',Output.INFO)
   kernel.loadGeometry("file:"+install_dir+"/examples/ClientTests/compact/FCC_HcalBarrel.xml")
-  kernel.loadXML("file:"+example_dir+"/DDG4_field.xml")
 
-  simple = DDG4.Simple(kernel)
-  simple.printDetectors()
-  simple.setupCshUI()
+  geant4 = DDG4.Geant4(kernel)
+  geant4.printDetectors()
+  geant4.setupCshUI()
 
+  # Configure field
+  field = geant4.setupfield(prt=True)
   # Configure I/O
-  evt_root = simple.setupROOTOutput('RootOutput','FCC_'+time.strftime('%Y-%m-%d_%H-%M'),mc_truth=False)
+  evt_root = geant4.setupROOTOutput('RootOutput','FCC_'+time.strftime('%Y-%m-%d_%H-%M'),mc_truth=False)
   # Setup particle gun
-  simple.setupGun("Gun",particle='pi-',energy=100*GeV,multiplicity=1)
+  geant4.setupGun("Gun",particle='pi-',energy=100*GeV,multiplicity=1)
   # Now the calorimeters
-  seq,act = simple.setupTracker('HcalBarrel')
-  seq,act = simple.setupDetector('ContainmentShell','Geant4EscapeCounter')
+  seq,act = geant4.setupTracker('HcalBarrel')
+  seq,act = geant4.setupDetector('ContainmentShell','Geant4EscapeCounter')
   # Now build the physics list:
   phys = kernel.physicsList()
   phys.extends = 'QGSP_BERT'
   phys.enableUI()
   phys.dump()
   # and run
-  simple.execute()
+  geant4.execute()
 
 if __name__ == "__main__":
   run()
diff --git a/examples/ClientTests/scripts/LheD_tracker.py b/examples/ClientTests/scripts/LheD_tracker.py
index 9dbb9cc4d..2d14dcd37 100644
--- a/examples/ClientTests/scripts/LheD_tracker.py
+++ b/examples/ClientTests/scripts/LheD_tracker.py
@@ -1,6 +1,6 @@
 #
 #
-import os, time, DDG4, sys
+import os, sys, time, DDG4
 from DDG4 import OutputLevel as Output
 from SystemOfUnits import *
 #
@@ -30,44 +30,21 @@ def run():
   ##geant4.setupCshUI('csh',True,True,'vis.mac')
   if len(sys.argv) >= 2 and sys.argv[1] =="batch":
     kernel.UI = ''
-  field = geant4.addConfig('Geant4FieldTrackingSetupAction/MagFieldTrackingSetup')
-  field.stepper            = "HelixSimpleRunge"
-  field.equation           = "Mag_UsualEqRhs"
-  field.eps_min            = 5e-05*mm
-  field.eps_max            = 0.001*mm
-  field.min_chord_step     = 0.01*mm
-  field.delta_chord        = 0.25*mm
-  field.delta_intersection = 1e-05*mm
-  field.delta_one_step     = 0.001*mm
-  print '+++++> ',field.name,'-> stepper  = ',field.stepper
-  print '+++++> ',field.name,'-> equation = ',field.equation
-  print '+++++> ',field.name,'-> eps_min  = ',field.eps_min
-  print '+++++> ',field.name,'-> eps_max  = ',field.eps_max
-  print '+++++> ',field.name,'-> delta_one_step = ',field.delta_one_step
-
-  # Configure Run actions
-  run1 = DDG4.RunAction(kernel,'Geant4TestRunAction/RunInit')
-  run1.enableUI()
-  kernel.registerGlobalAction(run1)
-  kernel.runAction().adopt(run1)
-
+    
+  # Configure field
+  field = geant4.setupTrackingField(prt=True)
   # Configure Event actions
   prt = DDG4.EventAction(kernel,'Geant4ParticlePrint/ParticlePrint')
   prt.OutputLevel = Output.WARNING # Output.WARNING
   prt.OutputType  = 3 # Print both: table and tree
   kernel.eventAction().adopt(prt)
 
-  generator_output_level = Output.WARNING
-
   # Configure I/O
-  ##evt_lcio = geant4.setupLCIOOutput('LcioOutput','LHeD_tracker_'+time.strftime('%Y-%m-%d_%H-%M'))
-  ##evt_lcio.OutputLevel = generator_output_level
   evt_root = geant4.setupROOTOutput('RootOutput','LHeD_tracker_'+time.strftime('%Y-%m-%d_%H-%M'))
-
   gen = geant4.setupGun("Gun",particle='geantino',energy=20*GeV,position=(0*mm,0*mm,0*cm),multiplicity=3)
   gen.isotrop = False
   gen.direction = (1,0,0)
-  gen.OutputLevel = generator_output_level
+  gen.OutputLevel = Output.WARNING
 
   #seq,act = geant4.setupTracker('SiVertexBarrel')
 
diff --git a/examples/ClientTests/scripts/MiniTel.py b/examples/ClientTests/scripts/MiniTel.py
index c4d393e65..d5ce52fd5 100644
--- a/examples/ClientTests/scripts/MiniTel.py
+++ b/examples/ClientTests/scripts/MiniTel.py
@@ -1,4 +1,4 @@
-import os, time, DDG4, sys
+import os, sys, time, DDG4
 from DDG4 import OutputLevel as Output
 from SystemOfUnits import *
 #
@@ -25,15 +25,7 @@ def run():
     kernel.UI = ''
 
   # Configure field
-  field = geant4.addConfig('Geant4FieldTrackingSetupAction/MagFieldTrackingSetup')
-  field.stepper            = "HelixSimpleRunge"
-  field.equation           = "Mag_UsualEqRhs"
-  field.eps_min            = 5e-05*mm
-  field.eps_max            = 0.001*mm
-  field.min_chord_step     = 0.01*mm
-  field.delta_chord        = 0.25*mm
-  field.delta_intersection = 1e-05*mm
-  field.delta_one_step     = 0.001*mm
+  field = geant4.setupTrackingField(prt=True)
   # Configure I/O
   evt_root = geant4.setupROOTOutput('RootOutput','MiniTel_'+time.strftime('%Y-%m-%d_%H-%M'),mc_truth=True)
   # Setup particle gun
diff --git a/examples/ClientTests/scripts/NestedDetectors.py b/examples/ClientTests/scripts/NestedDetectors.py
index bd1768375..0bf0e972a 100644
--- a/examples/ClientTests/scripts/NestedDetectors.py
+++ b/examples/ClientTests/scripts/NestedDetectors.py
@@ -1,4 +1,4 @@
-import os, time, DDG4, sys
+import os, sys, time, DDG4
 from DDG4 import OutputLevel as Output
 from SystemOfUnits import *
 #
@@ -14,25 +14,25 @@ from SystemOfUnits import *
 def run():
   kernel = DDG4.Kernel()
   install_dir = os.environ['DD4hepINSTALL']
-  example_dir = install_dir+'/examples/DDG4/examples';
   kernel.setOutputLevel('Geant4Converter',Output.DEBUG)
   kernel.setOutputLevel('Gun',Output.INFO)
   kernel.loadGeometry("file:"+install_dir+"/examples/ClientTests/compact/NestedDetectors.xml")
-  kernel.loadXML("file:"+example_dir+"/DDG4_field.xml")
 
-  simple = DDG4.Simple(kernel)
-  simple.printDetectors()
-  simple.setupCshUI()
+  geant4 = DDG4.Geant4(kernel)
+  geant4.printDetectors()
+  geant4.setupCshUI()
   if len(sys.argv) >= 2 and sys.argv[1] =="batch":
     kernel.UI = ''
 
+  # Configure field
+  field = geant4.setupTrackingField(prt=True)
   # Configure I/O
-  evt_root = simple.setupROOTOutput('RootOutput','Nested_'+time.strftime('%Y-%m-%d_%H-%M'),mc_truth=True)
+  evt_root = geant4.setupROOTOutput('RootOutput','Nested_'+time.strftime('%Y-%m-%d_%H-%M'),mc_truth=True)
   # Setup particle gun
-  simple.setupGun("Gun",particle='pi-',energy=100*GeV,multiplicity=1)
+  geant4.setupGun("Gun",particle='pi-',energy=100*GeV,multiplicity=1)
   # Now the calorimeters
-  seq,act = simple.setupTracker('SiTrackerBarrel')
-  seq,act = simple.setupTracker('SiVertexBarrel')
+  seq,act = geant4.setupTracker('SiTrackerBarrel')
+  seq,act = geant4.setupTracker('SiVertexBarrel')
   # And handle the simulation particles.
   part = DDG4.GeneratorAction(kernel,"Geant4ParticleHandler/ParticleHandler")
   kernel.generatorAction().adopt(part)
@@ -46,7 +46,7 @@ def run():
   phys.enableUI()
   phys.dump()
   # and run
-  simple.execute()
+  geant4.execute()
 
 if __name__ == "__main__":
   run()
diff --git a/examples/ClientTests/scripts/SiliconBlock.py b/examples/ClientTests/scripts/SiliconBlock.py
index 1e6ae4d1b..fedfd1cf4 100644
--- a/examples/ClientTests/scripts/SiliconBlock.py
+++ b/examples/ClientTests/scripts/SiliconBlock.py
@@ -16,18 +16,19 @@ from SystemOfUnits import *
 def run():
   kernel = DDG4.Kernel()
   install_dir = os.environ['DD4hepINSTALL']
-  example_dir = install_dir+'/examples/DDG4/examples';
   kernel.loadGeometry("file:"+install_dir+"/examples/ClientTests/compact/SiliconBlock.xml")
-  kernel.loadXML("file:"+example_dir+"/DDG4_field.xml")
+
   DDG4.importConstants(kernel.lcdd(),debug=False)
-  simple = DDG4.Simple(kernel,tracker='Geant4TrackerCombineAction')
-  simple.printDetectors()
+  geant4 = DDG4.Geant4(kernel,tracker='Geant4TrackerCombineAction')
+  geant4.printDetectors()
   # Configure UI
   if len(sys.argv)>1:
-    simple.setupCshUI(macro=sys.argv[1])
+    geant4.setupCshUI(macro=sys.argv[1])
   else:
-    simple.setupCshUI()
+    geant4.setupCshUI()
 
+  # Configure field
+  field = geant4.setupTrackingField(prt=True)
   # Configure Event actions
   prt = DDG4.EventAction(kernel,'Geant4ParticlePrint/ParticlePrint')
   prt.OutputLevel = Output.DEBUG
@@ -37,10 +38,10 @@ def run():
   generator_output_level = Output.INFO
 
   # Configure I/O
-  evt_root = simple.setupROOTOutput('RootOutput','SiliconBlock_'+time.strftime('%Y-%m-%d_%H-%M'))
+  evt_root = geant4.setupROOTOutput('RootOutput','SiliconBlock_'+time.strftime('%Y-%m-%d_%H-%M'))
 
   # Setup particle gun
-  gun = simple.setupGun("Gun",particle='mu-',energy=20*GeV,multiplicity=1)
+  gun = geant4.setupGun("Gun",particle='mu-',energy=20*GeV,multiplicity=1)
   gun.output_level = generator_output_level
 
   # And handle the simulation particles.
@@ -56,11 +57,11 @@ def run():
   user.enableUI()
   part.adopt(user)
 
-  simple.setupTracker('SiliconBlockUpper')
-  simple.setupTracker('SiliconBlockDown')
+  geant4.setupTracker('SiliconBlockUpper')
+  geant4.setupTracker('SiliconBlockDown')
 
   # Now build the physics list:
-  phys = simple.setupPhysics('QGSP_BERT')
+  phys = geant4.setupPhysics('QGSP_BERT')
   ph = DDG4.PhysicsList(kernel,'Geant4PhysicsList/Myphysics')
   ph.addParticleConstructor('G4Geantino')
   ph.addParticleConstructor('G4BosonConstructor')
@@ -68,7 +69,7 @@ def run():
   phys.adopt(ph)
   phys.dump()
 
-  simple.execute()
+  geant4.execute()
 
 if __name__ == "__main__":
   run()
-- 
GitLab