From 88a6e2781e0b2855c018a5d594d008f81c8498b5 Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Wed, 18 Oct 2017 19:57:41 +0200 Subject: [PATCH] Add Simulation test to DDCMS example --- DDG4/python/DDG4.py | 5 +++-- examples/DDCMS/CMakeLists.txt | 9 ++++++++- examples/DDCMS/scripts/CMSTrackerSim.py | 22 +++++++++++++++++++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index a5e059b44..34dd78f61 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -614,7 +614,7 @@ class Geant4: phys.adopt(opt) return opt - def setupGun(self, name, particle, energy, isotrop=True, multiplicity=1, position=(0.0,0.0,0.0),**args): + def setupGun(self, name, particle, energy, isotrop=True, multiplicity=1, position=(0.0,0.0,0.0),register=True, **args): gun = GeneratorAction(self.kernel(),"Geant4ParticleGun/"+name,True) for i in args.items(): setattr(gun,i[0],i[1]) @@ -624,7 +624,8 @@ class Geant4: gun.position = position gun.isotrop = isotrop gun.enableUI() - self.kernel().generatorAction().add(gun) + if register: + self.kernel().generatorAction().add(gun) return gun """ diff --git a/examples/DDCMS/CMakeLists.txt b/examples/DDCMS/CMakeLists.txt index b63ef6ead..c2233948f 100644 --- a/examples/DDCMS/CMakeLists.txt +++ b/examples/DDCMS/CMakeLists.txt @@ -112,7 +112,14 @@ dd4hep_add_test_reg( DDCMS_VolumeMgrTest_TOB REGEX_FAIL "Exception" REGEX_FAIL "FAILED" ) - +# +# Dump CMS detector element tree of SD TOB +dd4hep_add_test_reg( DDCMS_Geant4_LONGTEST + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDCMS.sh" + EXEC_ARGS python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/CMSTrackerSim.py batch test numevents 2 + REGEX_PASS "\\+\\+\\+ Finished run 0 after 2 events \\(2 events in total\\)" + REGEX_FAIL "Exception;EXCEPTION;ERROR;FAILED" + ) # # Test saving geometry to ROOT file dd4hep_add_test_reg( DDCMS_Persist_Save_LONGTEST diff --git a/examples/DDCMS/scripts/CMSTrackerSim.py b/examples/DDCMS/scripts/CMSTrackerSim.py index a3165681a..caea821ea 100644 --- a/examples/DDCMS/scripts/CMSTrackerSim.py +++ b/examples/DDCMS/scripts/CMSTrackerSim.py @@ -18,10 +18,20 @@ def run(): kernel.setOutputLevel('Gun',Output.INFO) kernel.detectorDescription().fromXML("file:"+install_dir+"/examples/DDCMS/data/dd4hep-config.xml"); kernel.NumEvents = 5 - geant4 = DDG4.Geant4(kernel) + geant4 = DDG4.Geant4(kernel,tracker='Geant4TrackerCombineAction') geant4.printDetectors() geant4.setupCshUI() - if len(sys.argv) >= 2 and sys.argv[1] =="batch": + batch = False + test = False + for i in xrange(len(sys.argv)): + arg = sys.argv[i].lower() + if arg == 'batch': + batch = True + elif arg == 'test': + test = True + elif arg == 'numevents': + kernel.NumEvents = int(sys.argv[i+1]) + if batch or test: kernel.UI = '' # Configure field @@ -29,7 +39,13 @@ def run(): # Configure I/O evt_root = geant4.setupROOTOutput('RootOutput','CMSTracker_'+time.strftime('%Y-%m-%d_%H-%M'),mc_truth=True) # Setup particle gun - geant4.setupGun("Gun",particle='pi-',energy=100*GeV,multiplicity=1) + generators = [] + generators.append(geant4.setupGun("GunPi-",particle='pi-',energy=300*GeV,multiplicity=1,Standalone=False,register=False, Mask=1)) + if not test: + generators.append(geant4.setupGun("GunPi+",particle='pi+',energy=300*GeV,multiplicity=1,Standalone=False,register=False, Mask=2)) + generators.append(geant4.setupGun("GunE-",particle='e-',energy=100*GeV,multiplicity=1,Standalone=False,register=False, Mask=4)) + generators.append(geant4.setupGun("GunE+",particle='e+',energy=100*GeV,multiplicity=1,Standalone=False,register=False, Mask=8)) + geant4.buildInputStage(generators) # Now setup all tracking detectors for i in geant4.description.detectors(): o = DDG4.DetElement(i.second.ptr()) -- GitLab