diff --git a/DDCore/python/dd4hep_base.py b/DDCore/python/dd4hep_base.py index 713f057e36bb71a4cc98d651d8c1dbe8ef292ed8..73fa64fb07e749ff7b9e3a7cc487de075c116cc5 100644 --- a/DDCore/python/dd4hep_base.py +++ b/DDCore/python/dd4hep_base.py @@ -361,6 +361,47 @@ class Logger: dd4hep_logger = Logger + +# --------------------------------------------------------------------------- +# +# Helper: Command line interpreter +# +# --------------------------------------------------------------------------- +class CommandLine: + """ + Helper to ease parsing the command line. + Any argument given in the command line is accessible + from the object. If no value is supplied, the returned + value is True. If the argument is not present None is returned. + + \author M.Frank + \version 1.0 + """ + def __init__(self, help=None): + import sys + self.data = {} + help_call = help + have_help = False + for i in range(len(sys.argv)): + if sys.argv[i][0] == '-': + key = sys.argv[i][1:] + val = True + if i + 1 < len(sys.argv): + v = sys.argv[i + 1] + if v[0] != '-': + val = v + self.data[key] = val + if key.upper() == 'HELP' or key.upper() == '?': + have_help = True + if have_help and help_call: + help_call() + + def __getattr__(self, attr): + if self.data.get(attr): + return self.data.get(attr) + return None + + # --------------------------------------------------------------------------- # # Import units from TGeo. diff --git a/DDDigi/python/digitize.py b/DDDigi/python/digitize.py index 5ba9fa0eec3d988d55d0632ff11872be052ee571..86673200e73ff0a2a99700e15541100204d24f5d 100644 --- a/DDDigi/python/digitize.py +++ b/DDDigi/python/digitize.py @@ -13,7 +13,7 @@ import dd4hep import dddigi -class Digitize(dd4hep.Logger): +class Digitize(dd4hep.Logger, dd4hep.CommandLine): """ Helper object to perform stuff, which occurs very often. I am sick of typing the same over and over again. diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index 84a50de6265ff5cbbe957c8aa05c6628ac76091f..45192b2d092cca137d55bf0dc5fab19a6f8a7c73 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -360,41 +360,11 @@ _props('UserInitializationSequenceHandle') _props('Geant4PhysicsListActionSequence') -class CommandLine: - """ - Helper to ease parsing the command line. - Any argument given in the command line is accessible - from the object. If no value is supplied, the returned - value is True. If the argument is not present None is returned. - - \author M.Frank - \version 1.0 - """ - def __init__(self, help=None): - import sys - self.data = {} - help_call = help - have_help = False - for i in range(len(sys.argv)): - if sys.argv[i][0] == '-': - key = sys.argv[i][1:] - val = True - if i + 1 < len(sys.argv): - v = sys.argv[i + 1] - if v[0] != '-': - val = v - self.data[key] = val - if key.upper() == 'HELP' or key.upper() == '?': - have_help = True - if have_help and help_call: - help_call() - - def __getattr__(self, attr): - if self.data.get(attr): - return self.data.get(attr) - return None - - +# --------------------------------------------------------------------------- +# +# Basic helper to configure the DDG4 instance from python +# +# --------------------------------------------------------------------------- class Geant4: """ Helper object to perform stuff, which occurs very often. diff --git a/examples/ClientTests/scripts/MiniTelGenerate.py b/examples/ClientTests/scripts/MiniTelGenerate.py index 31b3b1d7bf08c1354905a110064aa6a1712c706b..a41142da6fc4df82a12c632a16f39515c1250801 100644 --- a/examples/ClientTests/scripts/MiniTelGenerate.py +++ b/examples/ClientTests/scripts/MiniTelGenerate.py @@ -44,8 +44,24 @@ def run(): gen = DDG4.GeneratorAction(kernel, "Geant4GeneratorActionInit/GenerationInit") kernel.generatorAction().adopt(gen) - gun = DDG4.GeneratorAction(kernel, "Geant4IsotropeGenerator/IsotropPi+") - gun.Mask = 1 + gun = DDG4.GeneratorAction(kernel, "Geant4IsotropeGenerator/IsotropPi+1") + gun.Mask = 1 << 0 + gun.Particle = 'pi+' + gun.Energy = 100 * GeV + gun.Multiplicity = 1 + gun.Distribution = 'cos(theta)' + kernel.generatorAction().adopt(gun) + + gun = DDG4.GeneratorAction(kernel, "Geant4IsotropeGenerator/IsotropPi+2") + gun.Mask = 1 << 1 + gun.Particle = 'pi+' + gun.Energy = 100 * GeV + gun.Multiplicity = 1 + gun.Distribution = 'cos(theta)' + kernel.generatorAction().adopt(gun) + + gun = DDG4.GeneratorAction(kernel, "Geant4IsotropeGenerator/IsotropPi+3") + gun.Mask = 1 << 2 gun.Particle = 'pi+' gun.Energy = 100 * GeV gun.Multiplicity = 1 @@ -53,7 +69,7 @@ def run(): kernel.generatorAction().adopt(gun) gun = DDG4.GeneratorAction(kernel, "Geant4IsotropeGenerator/IsotropPi-") - gun.Mask = 2 + gun.Mask = 1 << 3 gun.Particle = 'pi-' gun.Energy = 100 * GeV gun.Multiplicity = 1 @@ -61,7 +77,7 @@ def run(): kernel.generatorAction().adopt(gun) gun = DDG4.GeneratorAction(kernel, "Geant4IsotropeGenerator/IsotropE+1") - gun.Mask = 4 + gun.Mask = 1 << 4 gun.Particle = 'e+' gun.Energy = 50 * GeV gun.Multiplicity = 1 @@ -69,12 +85,37 @@ def run(): kernel.generatorAction().adopt(gun) gun = DDG4.GeneratorAction(kernel, "Geant4IsotropeGenerator/IsotropE+2") - gun.Mask = 8 + gun.Mask = 1 << 5 gun.Particle = 'e+' gun.Energy = 100 * GeV gun.Multiplicity = 1 gun.Distribution = 'cos(theta)' kernel.generatorAction().adopt(gun) + + gun = DDG4.GeneratorAction(kernel, "Geant4IsotropeGenerator/IsotropE+3") + gun.Mask = 1 << 6 + gun.Particle = 'e+' + gun.Energy = 50 * GeV + gun.Multiplicity = 1 + gun.Distribution = 'cos(theta)' + kernel.generatorAction().adopt(gun) + + gun = DDG4.GeneratorAction(kernel, "Geant4IsotropeGenerator/IsotropE+4") + gun.Mask = 1 << 7 + gun.Particle = 'e+' + gun.Energy = 100 * GeV + gun.Multiplicity = 1 + gun.Distribution = 'cos(theta)' + kernel.generatorAction().adopt(gun) + + gun = DDG4.GeneratorAction(kernel, "Geant4IsotropeGenerator/IsotropE+5") + gun.Mask = 1 << 8 + gun.Particle = 'e+' + gun.Energy = 100 * GeV + gun.Multiplicity = 1 + gun.Distribution = 'cos(theta)' + kernel.generatorAction().adopt(gun) + gun = None gen = DDG4.GeneratorAction(kernel, "Geant4InteractionMerger/InteractionMerger") diff --git a/examples/DDDigi/CMakeLists.txt b/examples/DDDigi/CMakeLists.txt index 0aebc3c3378dc1af4338504e2c74b5785e02f735..0fb7b52cf50c105370a4913a921e0751c9681697 100644 --- a/examples/DDDigi/CMakeLists.txt +++ b/examples/DDDigi/CMakeLists.txt @@ -65,8 +65,8 @@ if (DD4HEP_USE_GEANT4) dd4hep_add_test_reg(DDDigi_generate_data COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDDigi.sh" EXEC_ARGS ${Python_EXECUTABLE} ${CMAKE_INSTALL_PREFIX}/examples/ClientTests/scripts/MiniTelGenerate.py - -batch -events 100 -runs 8 - REGEX_PASS "\\+\\+\\+ Finished run 7 after 100 events \\(800 events in total\\)." + -batch -events 30 -runs 8 + REGEX_PASS "\\+\\+\\+ Finished run 7 after 30 events \\(240 events in total\\)." REGEX_FAIL "Error;ERROR;Exception" ) # Test basic input reading from DDG4 @@ -157,6 +157,38 @@ if (DD4HEP_USE_GEANT4) REGEX_PASS "\\+\\+\\+ 5 Events out of 5 processed" REGEX_FAIL "Error;ERROR;Exception" ) + # Test container parellization + dd4hep_add_test_reg(DDDigi_test_containers_parallel + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDDigi.sh" + EXEC_ARGS ${Python_EXECUTABLE} ${CMAKE_INSTALL_PREFIX}/examples/DDDigi/scripts/TestMultiContainerParallel.py + DEPENDS DDDigi_generate_data + REGEX_PASS "\\+\\+\\+ 5 Events out of 5 processed" + REGEX_FAIL "Error;ERROR;Exception" + ) + # Test hit resegmentation + dd4hep_add_test_reg(DDDigi_test_detector_resegmentation + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDDigi.sh" + EXEC_ARGS ${Python_EXECUTABLE} ${CMAKE_INSTALL_PREFIX}/examples/DDDigi/scripts/TestResegmentation.py + DEPENDS DDDigi_generate_data + REGEX_PASS "\\+\\+\\+ 5 Events out of 5 processed" + REGEX_FAIL "Error;ERROR;Exception" + ) + # Test work splitting by segmentation + dd4hep_add_test_reg(DDDigi_test_segmentation_split_1 + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDDigi.sh" + EXEC_ARGS ${Python_EXECUTABLE} ${CMAKE_INSTALL_PREFIX}/examples/DDDigi/scripts/TestSegmentationSplit.py + DEPENDS DDDigi_generate_data + REGEX_PASS "\\+\\+\\+ 5 Events out of 5 processed" + REGEX_FAIL "Error;ERROR;Exception" + ) + # Test work splitting by segmentation (2) + dd4hep_add_test_reg(DDDigi_test_segmentation_split_2 + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDDigi.sh" + EXEC_ARGS ${Python_EXECUTABLE} ${CMAKE_INSTALL_PREFIX}/examples/DDDigi/scripts/TestSegmentationSplit2.py + DEPENDS DDDigi_generate_data + REGEX_PASS "\\+\\+\\+ 5 Events out of 5 processed" + REGEX_FAIL "Error;ERROR;Exception" + ) # Test simple ADC response dd4hep_add_test_reg(DDDigi_test_simple_adc_response COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDDigi.sh" diff --git a/examples/DDDigi/scripts/TestResegmentation.py b/examples/DDDigi/scripts/TestResegmentation.py index 4bba47447085e959528862d9602fe16c2d262e48..7642d0a5e35182783df0fff4705f804eb7ae91cc 100644 --- a/examples/DDDigi/scripts/TestResegmentation.py +++ b/examples/DDDigi/scripts/TestResegmentation.py @@ -27,21 +27,21 @@ def run(): input_mask=0x0, input_segment='inputs', output_mask=0xFEED, output_segment='outputs') resegment = digi.create_action('DigiResegment/Resegment') - resegment.detector = 'EcalBarrel' - resegment.readout = 'NewEcalBarrelHits' + resegment.detector = 'Minitel1' + resegment.readout = 'NewMinitel1Hits' resegment.descriptor = """ - <readout name="NewEcalBarrelHits"> - <segmentation type="CartesianGridXY" grid_size_x="10" grid_size_y="10"/> - <id>system:8,barrel:3,module:4,layer:6,slice:5,x:32:-16,y:-16</id> + <readout name="NewMinitel1Hits"> + <segmentation type="CartesianGridXY" grid_size_x="20*mm" grid_size_y="20*mm"/> + <id>system:6,side:2,module:8,x:28:-12,y:52:-12</id> </readout> """ resegment.debug = False - seq.adopt_container_processor(resegment, 'EcalBarrelHits') + seq.adopt_container_processor(resegment, 'Minitel1Hits') event.adopt_action('DigiStoreDump/StoreDump') digi.info('Created event.dump') # ======================================================================== - digi.run_checked(num_events=3, num_threads=5, parallel=3) + digi.run_checked(num_events=5, num_threads=15, parallel=3) if __name__ == '__main__': diff --git a/examples/DDDigi/scripts/TestSegmentationSplit.py b/examples/DDDigi/scripts/TestSegmentationSplit.py index e64c83806f7d9fdcb838b76e4330bfb209e072c7..fb2b544d347bf1aa5eb1e127ec782d279c6c5adf 100644 --- a/examples/DDDigi/scripts/TestSegmentationSplit.py +++ b/examples/DDDigi/scripts/TestSegmentationSplit.py @@ -12,6 +12,14 @@ from __future__ import absolute_import def run(): + """ + Small test for process splitting by segmentation. + Assigned parts of the segmentation are processed by a specified + container action (here a DigiSegmentDepositPrint instance) + + \author M.Frank + \version 1.0 + """ import DigiTest digi = DigiTest.Test(geometry=None) digi.load_geo() @@ -30,15 +38,15 @@ def run(): output_mask=0xFEED) splitter = digi.create_action('DigiSegmentSplitter/Splitter', parallel=True, - split_by='layer', - detector='SiTrackerBarrel', + split_by='module', + detector='Minitel1', processor_type='DigiSegmentDepositPrint') split_action.adopt_container_processor(splitter, splitter.collection_names()) event.adopt_action('DigiStoreDump/StoreDump') digi.info('Created event.dump') # ======================================================================== - digi.run_checked(num_events=3, num_threads=10, parallel=3) + digi.run_checked(num_events=5, num_threads=10, parallel=3) if __name__ == '__main__': diff --git a/examples/DDDigi/scripts/TestSegmentationSplit2.py b/examples/DDDigi/scripts/TestSegmentationSplit2.py index 63fba35f90c3f1627e455adeeb8f8f5446ef35c2..1dba594a92348297c15cd7de5e7cb5a36c525860 100644 --- a/examples/DDDigi/scripts/TestSegmentationSplit2.py +++ b/examples/DDDigi/scripts/TestSegmentationSplit2.py @@ -30,14 +30,14 @@ def run(): output_mask=0xFEED) splitter = digi.create_action('DigiSegmentSplitter/Splitter', parallel=True, - split_by='layer', - detector='SiTrackerEndcap') + split_by='module', + detector='Minitel1') printer = digi.create_action('DigiSegmentDepositPrint/P1') splitter.get().adopt_segment_processor(printer, 1) printer = digi.create_action('DigiSegmentDepositPrint/P2') - splitter.adopt_segment_processor(printer, [2, 3]) + splitter.adopt_segment_processor(printer, [2, 3, 4, 5, 6]) printer = digi.create_action('DigiSegmentDepositPrint/P3') - splitter.adopt_segment_processor(printer, [4]) + splitter.adopt_segment_processor(printer, [7, 8, 9]) split_action.adopt_container_processor(splitter, splitter.collection_names()) event.adopt_action('DigiStoreDump/StoreDump')