diff --git a/scripts/optics_lgc.py b/scripts/optics_lgc.py new file mode 100644 index 0000000000000000000000000000000000000000..727ef0644c41800f81c0fd68dadd73c30c6e736d --- /dev/null +++ b/scripts/optics_lgc.py @@ -0,0 +1,90 @@ +""" +DD4hep simulation with some argument parsing +Based on M. Frank and F. Gaede runSim.py + @author A.Sailer + @version 0.1 + +Modified with settings for RICH simulation +""" +from __future__ import absolute_import, unicode_literals +import logging +import sys +import os + +from DDSim.DD4hepSimulation import DD4hepSimulation + + +if __name__ == "__main__": + logging.basicConfig( + format="%(name)-16s %(levelname)s %(message)s", + level=logging.INFO, + stream=sys.stdout, + ) + logger = logging.getLogger("DDSim") + + SIM = DD4hepSimulation() + + # Ensure that Cerenkov and optical physics are always loaded + def setupCerenkov(kernel): + from DDG4 import PhysicsList + + seq = kernel.physicsList() + cerenkov = PhysicsList(kernel, "Geant4CerenkovPhysics/CerenkovPhys") + cerenkov.MaxNumPhotonsPerStep = 10 + cerenkov.MaxBetaChangePerStep = 10.0 + cerenkov.TrackSecondariesFirst = False + cerenkov.VerboseLevel = 0 + cerenkov.enableUI() + seq.adopt(cerenkov) + ph = PhysicsList(kernel, "Geant4OpticalPhotonPhysics/OpticalGammaPhys") + ph.addParticleConstructor("G4OpticalPhoton") + ph.VerboseLevel = 0 + ph.enableUI() + seq.adopt(ph) + return None + + SIM.physics.setupUserPhysics(setupCerenkov) + + # Allow energy depositions to 0 energy in trackers (which include optical detectors) + SIM.filter.tracker = "edep0" + + # Some detectors are only sensitive to optical photons + SIM.filter.filters["opticalphotons"] = dict( + name="ParticleSelectFilter/OpticalPhotonSelector", + parameter={"particle": "opticalphoton"}, + ) + SIM.filter.mapDetFilter["LightGasCherenkov"] = "opticalphotons" + + # Use the optical tracker + SIM.action.mapActions["LightGasCherenkov"] = "Geant4OpticalTrackerAction" + + # Disable user tracker particle handler, so hits can be associated to photons + SIM.part.userParticleHandler = "" + + # Particle gun settings: pions with fixed energy and theta, varying phi + SIM.numberOfEvents = 100 + SIM.enableGun = True + SIM.gun.energy = "3*GeV" + SIM.gun.particle = "e-" + SIM.gun.thetaMin = "16.0*deg" + SIM.gun.thetaMax = "16.1*deg" + SIM.gun.distribution = "cos(theta)" + SIM.gun.position = (0., 0., "-300.*cm") + + # Output file (assuming CWD) + SIM.outputFile = "optics_lgc.root" + SIM.outputConfig.forceDD4HEP = True + + # Override with user options + SIM.parseOptions() + + # Run the simulation + try: + SIM.run() + logger.info("TEST: passed") + except NameError as e: + logger.fatal("TEST: failed") + if "global name" in str(e): + globalToSet = str(e).split("'")[1] + logger.fatal("Unknown global variable, please add\nglobal %s\nto your steeringFile" % globalToSet) + diff --git a/scripts/run_solid_lgc.py b/scripts/run_solid_lgc.py new file mode 100644 index 0000000000000000000000000000000000000000..ecb863afe240dbc4785699fbcecd0cd2ea34c059 --- /dev/null +++ b/scripts/run_solid_lgc.py @@ -0,0 +1,133 @@ +# ========================================================================== +# AIDA Detector description implementation +# -------------------------------------------------------------------------- +# Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +# All rights reserved. +# +# For the licensing terms see $DD4hepINSTALL/LICENSE. +# For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +# +# ========================================================================== +# +from __future__ import absolute_import, unicode_literals +import os +import sys +import DDG4 +from DDG4 import OutputLevel as Output +from g4units import GeV, cm +""" + + dd4hep simulation example setup using the python configuration + + @author M.Frank + @version 1.0 + +""" + + +def run(): + kernel = DDG4.Kernel() + kernel.loadGeometry("solid.xml") + + DDG4.importConstants(kernel.detectorDescription(), debug=False) + geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction') + geant4.printDetectors() + geant4.setupUI(typ='qt', vis=True, ui=True, macro='macro/vis.mac') + ''' + # Configure UI + if len(sys.argv) > 1: + geant4.setupCshUI(macro=sys.argv[1]) + else: + geant4.setupCshUI() + ''' + # Configure field + geant4.setupTrackingField(prt=True) + # Configure Event actions + prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint') + prt.OutputLevel = Output.DEBUG + prt.OutputType = 3 # Print both: table and tree + kernel.eventAction().adopt(prt) + + generator_output_level = Output.INFO + + # Configure G4 geometry setup + seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo") + act.DebugMaterials = True + act.DebugElements = False + act.DebugVolumes = True + act.DebugShapes = True + act.DebugSurfaces = True + + # Configure I/O + # evt_root = geant4.setupROOTOutput('RootOutput','OpNovice_'+time.strftime('%Y-%m-%d_%H-%M')) + + # Setup particle gun + gun = geant4.setupGun("Gun", particle='e-', energy=4*GeV, multiplicity=1, position=(0., 0., -300*cm)) + gun.OutputLevel = generator_output_level + gun.direction = (0., 0., 1.) + + # And handle the simulation particles. + """ + part = DDG4.GeneratorAction(kernel,"Geant4ParticleHandler/ParticleHandler") + kernel.generatorAction().adopt(part) + part.SaveProcesses = ['Decay'] + part.MinimalKineticEnergy = 100*MeV + part.OutputLevel = Output.INFO #generator_output_level + part.enableUI() + user = DDG4.Action(kernel,"Geant4TCUserParticleHandler/UserParticleHandler") + user.TrackingVolume_Zmax = 3.0*m + user.TrackingVolume_Rmax = 3.0*m + user.enableUI() + part.adopt(user) + """ + geant4.setupTracker('LightGasCherenkov') + + # Now build the physics list: + phys = geant4.setupPhysics('') + ph = DDG4.PhysicsList(kernel, 'Geant4OpticalPhotonPhysics/OpticalGammaPhys') + ph.VerboseLevel = 2 + ph.addParticleGroup('G4BosonConstructor') + ph.addParticleGroup('G4LeptonConstructor') + ph.addParticleGroup('G4MesonConstructor') + ph.addParticleGroup('G4BaryonConstructor') + ph.addParticleGroup('G4IonConstructor') + ph.addParticleConstructor('G4OpticalPhoton') + + ph.addDiscreteParticleProcess('gamma', 'G4GammaConversion') + ph.addDiscreteParticleProcess('gamma', 'G4ComptonScattering') + ph.addDiscreteParticleProcess('gamma', 'G4PhotoElectricEffect') + ph.addParticleProcess(str('e[+-]'), str('G4eMultipleScattering'), -1, 1, 1) + ph.addParticleProcess(str('e[+-]'), str('G4eIonisation'), -1, 2, 2) + ph.addParticleProcess(str('e[+-]'), str('G4eBremsstrahlung'), -1, 3, 3) + ph.addParticleProcess(str('e+'), str('G4eplusAnnihilation'), 0, -1, 4) + ph.addParticleProcess(str('mu[+-]'), str('G4MuMultipleScattering'), -1, 1, 1) + ph.addParticleProcess(str('mu[+-]'), str('G4MuIonisation'), -1, 2, 2) + ph.addParticleProcess(str('mu[+-]'), str('G4MuBremsstrahlung'), -1, 3, 3) + ph.addParticleProcess(str('mu[+-]'), str('G4MuPairProduction'), -1, 4, 4) + ph.enableUI() + phys.adopt(ph) + + ph = DDG4.PhysicsList(kernel, 'Geant4ScintillationPhysics/ScintillatorPhys') + ph.ScintillationYieldFactor = 1.0 + ph.ScintillationExcitationRatio = 1.0 + ph.TrackSecondariesFirst = False + ph.VerboseLevel = 2 + ph.enableUI() + phys.adopt(ph) + + ph = DDG4.PhysicsList(kernel, 'Geant4CerenkovPhysics/CerenkovPhys') + ph.MaxNumPhotonsPerStep = 10 + ph.MaxBetaChangePerStep = 10.0 + ph.TrackSecondariesFirst = True + ph.VerboseLevel = 2 + ph.enableUI() + phys.adopt(ph) + + phys.dump() + + geant4.execute() + + +if __name__ == "__main__": + run() +