From 5bf3cadadd41acb526e15c3a98873d93b51ec437 Mon Sep 17 00:00:00 2001
From: Andre Sailer <andre.philippe.sailer@cern.ch>
Date: Mon, 14 Sep 2020 17:17:40 +0200
Subject: [PATCH] DDSim: Sensitive Detectors: add possibility to tweak which
 sensitive detector types can be used

---
 DDG4/python/DDSim/DD4hepSimulation.py | 13 ++++++-------
 DDG4/python/DDSim/Helper/Action.py    | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/DDG4/python/DDSim/DD4hepSimulation.py b/DDG4/python/DDSim/DD4hepSimulation.py
index 5f3d72368..46fd5e0c5 100644
--- a/DDG4/python/DDSim/DD4hepSimulation.py
+++ b/DDG4/python/DDSim/DD4hepSimulation.py
@@ -263,8 +263,7 @@ class DD4hepSimulation(object):
       self.__printSteeringFile(parser)
       exit(1)
 
-  @staticmethod
-  def getDetectorLists(detectorDescription):
+  def getDetectorLists(self, detectorDescription):
     ''' get lists of trackers and calorimeters that are defined in detectorDescription (the compact xml file)'''
     import DDG4
     trackers, calos = [], []
@@ -274,13 +273,13 @@ class DD4hepSimulation(object):
       sd = detectorDescription.sensitiveDetector(name)
       if sd.isValid():
         detType = sd.type()
-  #      if len(detectorList) and not(name in detectorList):
-  #        continue
-        logger.info('getDetectorLists - found active detctor %s type: %s', name, detType)
-        if detType == "tracker":
+        logger.info('getDetectorLists - found active detector %s type: %s', name, detType)
+        if any(pat in detType.lower() for pat in self.action.trackerSDTypes):
           trackers.append(det.name())
-        if detType == "calorimeter":
+        elif any(pat in detType.lower() for pat in self.action.calorimeterSDTypes):
           calos.append(det.name())
+        else:
+          logger.warn('Unknown sensitive detector type: %s', detType)
 
     return trackers, calos
 
diff --git a/DDG4/python/DDSim/Helper/Action.py b/DDG4/python/DDSim/Helper/Action.py
index a9def6156..21488c8d2 100644
--- a/DDG4/python/DDSim/Helper/Action.py
+++ b/DDG4/python/DDSim/Helper/Action.py
@@ -32,6 +32,8 @@ class Action(ConfigHelper):
     self._tracker = ('Geant4TrackerWeightedAction', {'HitPositionCombination': 2, 'CollectSingleDeposits': False})
     self._calo = 'Geant4ScintillatorCalorimeterAction'
     self._mapActions = dict()
+    self._trackerSDTypes = ['tracker']
+    self._calorimeterSDTypes = ['calorimeter']
 
   @property
   def tracker(self):
@@ -78,3 +80,21 @@ class Action(ConfigHelper):
   def clearMapActions(self):
     """empty the mapActions dictionary"""
     self._mapActions = dict()
+
+  @property
+  def trackerSDTypes(self):
+    """List of patterns matching sensitive detectors of type Tracker."""
+    return self._trackerSDTypes
+
+  @trackerSDTypes.setter
+  def trackerSDTypes(self, val):
+    self._trackerSDTypes = ConfigHelper.makeList(val)
+
+  @property
+  def calorimeterSDTypes(self):
+    """List of patterns matching sensitive detectors of type Calorimeter."""
+    return self._calorimeterSDTypes
+
+  @calorimeterSDTypes.setter
+  def calorimeterSDTypes(self, val):
+    self._calorimeterSDTypes = ConfigHelper.makeList(val)
-- 
GitLab