From 8cdfc0368150df28f44938fcde4c71990a804c0d Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Thu, 4 Jul 2019 19:33:14 +0200
Subject: [PATCH] Prepare DD4hep for Geant4 units in TGeo; Start digitization
 package

---
 DDDigi/examples/TestFramework.py     | 62 ++++++++++++++++++++++++++++
 DDDigi/src/DigiKernel.cpp            | 10 ++---
 DDG4/src/Geant4SensitiveDetector.cpp |  2 +-
 DDG4/src/Geant4StepHandler.cpp       |  2 -
 4 files changed, 68 insertions(+), 8 deletions(-)
 create mode 100644 DDDigi/examples/TestFramework.py

diff --git a/DDDigi/examples/TestFramework.py b/DDDigi/examples/TestFramework.py
new file mode 100644
index 000000000..8eda36d57
--- /dev/null
+++ b/DDDigi/examples/TestFramework.py
@@ -0,0 +1,62 @@
+
+
+import os, sys, logging, DDDigi
+
+DDDigi.setPrintFormat('%-32s %5s %s')
+kernel = DDDigi.Kernel()
+install_dir = os.environ['DD4hepINSTALL']
+fname = "file:"+install_dir+"/examples/ClientTests/compact/MiniTel.xml"
+kernel.loadGeometry(fname)
+kernel.printProperties()
+digi = DDDigi.Digitize(kernel)
+digi.printDetectors()
+
+
+def make_input():
+  input_1 = DDDigi.TestAction(kernel,'input_01', 100)
+  input_2 = DDDigi.TestAction(kernel,'input_02', 200)
+  input_3 = DDDigi.TestAction(kernel,'input_03', 150)
+  input_4 = DDDigi.TestAction(kernel,'input_04', 60)
+  seq  = kernel.inputAction()
+  seq.adopt(input_1)
+  seq.adopt(input_2)
+  seq.adopt(input_3)
+  seq.adopt(input_4)
+  return seq
+
+def make_subdetector(name):
+  action_1 = DDDigi.TestAction(kernel,name+'_deposits',  150)
+  action_2 = DDDigi.TestAction(kernel,name+'_rndmNoise', 100)
+  action_3 = DDDigi.TestAction(kernel,name+'_deadChan',  100)
+  action_4 = DDDigi.TestAction(kernel,name+'_noiseChan',  50)
+  action_5 = DDDigi.TestAction(kernel,name+'_merge',     200)
+  seq = DDDigi.ActionSequence(kernel,'DigiActionSequence/'+name+'_sequence',True)
+  seq.adopt(action_1)
+  seq.adopt(action_2)
+  seq.adopt(action_3)
+  seq.adopt(action_4)
+  seq.adopt(action_5)
+  return seq
+
+event_processor = DDDigi.Synchronize(kernel,'DigiSynchronize/MainDigitizer',True)
+event_processor.parallel = True
+detectors = DDDigi
+# input
+make_input()
+# Subdetector digitization
+dets = digi.activeDetectors()
+for d in dets:
+  seq = make_subdetector(d['name'])
+  event_processor.adopt(seq)
+kernel.eventAction().adopt(event_processor)
+# Output
+output = DDDigi.TestAction(kernel,'output_01', 200)
+kernel.outputAction().adopt(output)
+
+
+DDDigi.setPrintLevel(DDDigi.OutputLevel.DEBUG)
+kernel.numThreads =  0   # = number of concurrent threads
+kernel.numEvents  = 10
+kernel.maxEventsParallel = 3
+kernel.run()
+DDDigi.setPrintLevel(DDDigi.OutputLevel.INFO)
diff --git a/DDDigi/src/DigiKernel.cpp b/DDDigi/src/DigiKernel.cpp
index ed186124a..b132a7265 100644
--- a/DDDigi/src/DigiKernel.cpp
+++ b/DDDigi/src/DigiKernel.cpp
@@ -270,6 +270,7 @@ void DigiKernel::submit(const DigiAction::Actors<DigiAction>& actions, DigiConte
   }
 #endif
   actions(&DigiAction::execute,context);
+  goto print_stamp;
 
  print_stamp:
   chrono::duration<double> secs = chrono::system_clock::now() - start;
@@ -345,15 +346,14 @@ int DigiKernel::run()   {
   }
 #endif
   if ( internals->eventsToDo > 0 )   {
-    for(int i=0; i<internals->numEvents; ++i)   {
-      unique_ptr<DigiContext> context(new DigiContext(this));
-      ++internals->eventsToDo;
-      executeEvent(context.release());
+    for(int i=0; i<internals->numEvents && !internals->stop; ++i)   {
+      Processor proc(*this);
+      proc();
     }
   }
   chrono::duration<double> duration = chrono::system_clock::now() - start;
   double sec = chrono::duration_cast<chrono::seconds>(duration).count();
-  printout(DEBUG,"DigiKernel","+++ Event processing finished. Total: %7.3f seconds %7.3f seconds/event",
+  printout(DEBUG,"DigiKernel","+++ Event processing finished. Total: %7.1f seconds %7.3f seconds/event",
            sec, sec/double(std::max(1,internals->numEvents)));
   return 1;
 }
diff --git a/DDG4/src/Geant4SensitiveDetector.cpp b/DDG4/src/Geant4SensitiveDetector.cpp
index f717d7ccf..669a06a06 100644
--- a/DDG4/src/Geant4SensitiveDetector.cpp
+++ b/DDG4/src/Geant4SensitiveDetector.cpp
@@ -30,7 +30,7 @@
 #include "DD4hep/DD4hepUnits.h"
 #include "CLHEP/Units/SystemOfUnits.h"
 
-static constexpr double MM_2_CM = (CLHEP::millimeter/dd4hep::millimeter);
+static const double MM_2_CM = (CLHEP::millimeter/dd4hep::millimeter);
 
 #define DEBUG 0
 
diff --git a/DDG4/src/Geant4StepHandler.cpp b/DDG4/src/Geant4StepHandler.cpp
index 79cff318c..58aaad378 100644
--- a/DDG4/src/Geant4StepHandler.cpp
+++ b/DDG4/src/Geant4StepHandler.cpp
@@ -17,8 +17,6 @@
 #include "DD4hep/DD4hepUnits.h"
 #include "CLHEP/Units/SystemOfUnits.h"
 
-static constexpr double MM_2_CM = (CLHEP::millimeter/dd4hep::millimeter);
-
 namespace units = dd4hep;
 using namespace dd4hep;
 using namespace dd4hep::sim;
-- 
GitLab