Beispiel #1
0
def run():
  kernel = DDG4.Kernel()
  install_dir = os.environ['DD4hepINSTALL']
  kernel.loadGeometry("file:"+install_dir+"/examples/ClientTests/compact/Assemblies.xml")
  #
  geant4 = DDG4.Geant4(kernel,tracker='Geant4TrackerCombineAction')
  geant4.printDetectors()
  # Configure UI
  geant4.setupCshUI()
  if len(sys.argv) >= 2 and sys.argv[1] =="batch":
    kernel.UI = ''

  # Configure field
  field = geant4.setupTrackingField(prt=True)
  # Configure I/O
  geant4.setupROOTOutput('RootOutput','Assemblies_'+time.strftime('%Y-%m-%d_%H-%M'),mc_truth=False)
  # Setup particle gun
  geant4.setupGun("Gun",particle='e-',energy=2*GeV,position=(0.15*mm,0.12*mm,0.1*cm),multiplicity=1)
  # First the tracking detectors
  seq,act = geant4.setupTracker('VXD')
  # Now build the physics list:
  phys = kernel.physicsList()
  phys.extends = 'QGSP_BERT'
  phys.enableUI()
  phys.dump()

  DDG4.setPrintLevel(DDG4.OutputLevel.DEBUG)
  geant4.execute()
Beispiel #2
0
def run():
    kernel = DDG4.Kernel()
    install_dir = os.environ['DD4hepINSTALL']
    kernel.loadGeometry("file:" + install_dir +
                        "/examples/ClientTests/compact/Assemblies.xml")
    #
    geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
    geant4.printDetectors()
    # Configure UI
    geant4.setupCshUI()
    if len(sys.argv) >= 2 and sys.argv[1] == "batch":
        kernel.UI = ''

    # Configure field
    field = geant4.setupTrackingField(prt=True)
    # Configure I/O
    geant4.setupROOTOutput('RootOutput',
                           'Assemblies_' + time.strftime('%Y-%m-%d_%H-%M'),
                           mc_truth=False)
    # Setup particle gun
    geant4.setupGun("Gun",
                    particle='e-',
                    energy=2 * GeV,
                    position=(0.15 * mm, 0.12 * mm, 0.1 * cm),
                    multiplicity=1)
    # First the tracking detectors
    seq, act = geant4.setupTracker('VXD')
    # Now build the physics list:
    phys = kernel.physicsList()
    phys.extends = 'QGSP_BERT'
    phys.enableUI()
    phys.dump()

    DDG4.setPrintLevel(DDG4.OutputLevel.DEBUG)
    geant4.execute()
Beispiel #3
0
def run():
  from MiniTelSetup import Setup
  m = Setup()
  if len(sys.argv) >= 2 and sys.argv[1] == "batch":
    DDG4.setPrintLevel(DDG4.OutputLevel.WARNING)
    m.kernel.UI = ''
  m.configure()
  m.defineOutput()
  m.setupGun()
  m.setupGenerator()
  m.setupPhysics()
  m.run()
Beispiel #4
0
 def loadGeometry(self, file=None):
   import os
   if file is None:
     install_dir = os.environ['DD4hepINSTALL']
     level = DDG4.printLevel()
     DDG4.setPrintLevel(DDG4.OutputLevel.WARNING)
     self.kernel.loadGeometry(str("file:" + install_dir + "/DDDetectors/compact/SiD.xml"))
     DDG4.setPrintLevel(level)
   else:
     ui = DDG4.DD4hepUI(self.description)
     ui.importROOT(file)
   return self
Beispiel #5
0
def run():
    from MiniTelSetup import Setup
    m = Setup()
    if len(sys.argv) >= 2 and sys.argv[1] == "batch":
        DDG4.setPrintLevel(DDG4.OutputLevel.WARNING)
        m.kernel.UI = ''
    m.configure()
    m.defineOutput()
    fname = os.environ[
        'DD4hepExamplesINSTALL'] + '/examples/DDG4/data/Muons10GeV.HEPEvt'
    m.setupInput("Geant4EventReaderHepEvtShort|" + fname)
    m.setupGenerator()
    m.setupPhysics(model='FTFP_BERT')
    m.phys.decays = True
    m.run(num_events=1)
Beispiel #6
0
def run():
    cnt = 0
    geo = None
    vis = False
    batch = False
    for i in sys.argv:
        cnt = cnt + 1
        c = i.upper()
        if c.find('BATCH') < 2 and c.find('BATCH') >= 0:
            batch = True
        elif c[:4] == '-GEO':
            geo = sys.argv[cnt]
        elif c[:4] == '-VIS':
            vis = True

    if not geo:
        help()
        sys.exit(1)

    import DDG4
    kernel = DDG4.Kernel()
    # Configure UI
    geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
    if batch:
        ui = geant4.setupCshUI(typ=None, ui=None, vis=None)
        kernel.UI = 'UI'
    else:
        ui = geant4.setupCshUI(vis=vis)
    kernel.loadGeometry(geo)
    # Configure field
    geant4.setupTrackingField(prt=True)
    # Now build the physics list:
    geant4.setupPhysics('')
    kernel.physicsList().enableUI()
    DDG4.setPrintLevel(DDG4.OutputLevel.DEBUG)
    #
    ui.Commands = [
        '/ddg4/ConstructGeometry/printVolume /world_volume_1',
        '/ddg4/ConstructGeometry/printMaterial Air',
        '/ddg4/ConstructGeometry/printMaterial Vacuum', '/ddg4/UI/exit'
    ]
    kernel.NumEvents = 0
    kernel.configure()
    kernel.initialize()
    kernel.run()
    kernel.terminate()
Beispiel #7
0
def run():
    geo = None
    vis = False
    batch = False
    for i in list(range(len(sys.argv))):
        c = sys.argv[i].upper()
        if c.find('BATCH') < 2 and c.find('BATCH') >= 0:
            batch = True
        elif c[:4] == '-GEO':
            geo = sys.argv[i + 1]
        elif c[:4] == '-VIS':
            vis = True

    if not geo:
        help()
        sys.exit(1)

    import DDG4
    kernel = DDG4.Kernel()
    # Configure UI
    geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
    if batch:
        ui = geant4.setupCshUI(ui=None, vis=None)
        kernel.UI = 'UI'
    else:
        ui = geant4.setupCshUI(vis=vis)
    kernel.loadGeometry(geo)
    # Configure field
    geant4.setupTrackingField(prt=True)
    # Now build the physics list:
    geant4.setupPhysics('')
    kernel.physicsList().enableUI()
    DDG4.setPrintLevel(DDG4.OutputLevel.DEBUG)
    #
    cmds = []
    cmds.append(
        '/ddg4/ConstructGeometry/printVolume /world_volume_1/Shape_Test_0/Shape_Test_vol_0_0'
    )
    cmds.append('/ddg4/UI/exit')
    ui.Commands = cmds
    kernel.NumEvents = 0
    kernel.configure()
    kernel.initialize()
    kernel.run()
    kernel.terminate()
Beispiel #8
0
def run():
    m = MiniTelSetup.Setup()
    if len(sys.argv) >= 2 and sys.argv[1] == "batch":
        m.kernel.NumEvents = 200
        m.kernel.UI = ''
        DDG4.setPrintLevel(Output.WARNING)

    m.configure()
    m.setupGun()
    part = m.setupGenerator()
    part.OutputLevel = Output.DEBUG
    # This is the actual test:
    hit_tuple = DDG4.EventAction(m.kernel, 'HitTupleAction/MiniTelTuple', True)
    hit_tuple.OutputFile = 'MiniTel_EnergyDeposits_' + time.strftime(
        '%Y-%m-%d_%H-%M') + '.root'
    hit_tuple.Collections = ['*']
    m.kernel.eventAction().add(hit_tuple)
    # Setup physics
    m.setupPhysics()
    # ... and run
    m.geant4.execute()
Beispiel #9
0
def run():
    geo = None
    vis = False
    dump = False
    batch = False
    install_dir = os.environ['DD4hepINSTALL']
    #
    for i in list(range(len(sys.argv))):
        c = sys.argv[i].upper()
        if c.find('BATCH') < 2 and c.find('BATCH') >= 0:
            batch = True
        elif c[:4] == '-GEO':
            geo = sys.argv[i + 1]
        elif c[:4] == '-VIS':
            vis = True
        elif c[:4] == '-DUM':
            dump = True

    if not geo:
        help()
        sys.exit(1)

    import DDG4
    kernel = DDG4.Kernel()
    description = kernel.detectorDescription()
    DDG4.setPrintLevel(DDG4.OutputLevel.INFO)
    DDG4.importConstants(description)
    #
    # Configure UI
    geant4 = DDG4.Geant4(kernel)
    ui = None
    if batch:
        geant4.setupCshUI(ui=None, vis=None)
        kernel.UI = 'UI'
    else:
        ui = geant4.setupCshUI(vis=vis)
    Output = DDG4.OutputLevel

    seq, act = geant4.addDetectorConstruction(
        "Geant4DetectorGeometryConstruction/ConstructGeo")
    act.DebugReflections = True
    act.DebugMaterials = False
    act.DebugElements = False
    act.DebugVolumes = False
    act.DebugShapes = False
    if dump:
        act.DumpHierarchy = ~0x0
    #
    kernel.setOutputLevel(str('Geant4Converter'), Output.WARNING)
    kernel.loadGeometry(geo)
    #
    geant4.printDetectors()
    # Configure field
    geant4.setupTrackingField(prt=True)
    logger.info("#  Setup random generator")
    rndm = DDG4.Action(kernel, 'Geant4Random/Random')
    rndm.Seed = 987654321
    rndm.initialize()
    #
    # Setup detector
    seq, act = geant4.setupCalorimeter('NestedBox')
    #
    # Configure I/O
    geant4.setupROOTOutput('RootOutput',
                           'Reflections_' + time.strftime('%Y-%m-%d_%H-%M'),
                           mc_truth=True)
    #
    # Setup particle gun
    geant4.setupGun(name="Gun",
                    particle='e-',
                    energy=1000 * GeV,
                    isotrop=True,
                    multiplicity=1,
                    position=(0 * m, 0 * m, 0 * m),
                    PhiMin=0.0 * rad,
                    PhiMax=math.pi * 2.0 * rad,
                    ThetaMin=0.0 * rad,
                    ThetaMax=math.pi * rad)

    logger.info("#  ....and handle the simulation particles.")
    part = DDG4.GeneratorAction(kernel,
                                str('Geant4ParticleHandler/ParticleHandler'))
    kernel.generatorAction().adopt(part)
    part.MinimalKineticEnergy = 100 * MeV
    part.SaveProcesses = ['Decay']
    part.OutputLevel = 5  # generator_output_level
    part.enableUI()
    user = DDG4.Action(kernel,
                       str('Geant4TCUserParticleHandler/UserParticleHandler'))
    user.TrackingVolume_Rmax = 3.0 * m
    user.TrackingVolume_Zmax = 2.0 * m
    user.enableUI()
    part.adopt(user)
    #
    #
    prt = DDG4.EventAction(kernel, str('Geant4ParticlePrint/ParticlePrint'))
    prt.OutputLevel = Output.INFO
    prt.OutputType = 3  # Print both: table and tree
    kernel.eventAction().adopt(prt)
    #
    # Now build the physics list:
    phys = geant4.setupPhysics(str('QGSP_BERT'))
    ph = geant4.addPhysics(str('Geant4PhysicsList/Myphysics'))
    ph.addPhysicsConstructor(str('G4StepLimiterPhysics'))
    ph.addParticleConstructor(str('G4Geantino'))
    ph.addParticleConstructor(str('G4BosonConstructor'))
    #
    # Add special particle types from specialized physics constructor
    part = geant4.addPhysics('Geant4ExtraParticles/ExtraParticles')
    part.pdgfile = os.path.join(install_dir,
                                'examples/DDG4/examples/particle.tbl')
    #
    # Add global range cut
    rg = geant4.addPhysics('Geant4DefaultRangeCut/GlobalRangeCut')
    rg.RangeCut = 0.7 * mm
    #
    phys.dump()
    #
    #
    if ui and vis:
        cmds = []
        cmds.append('/control/verbose 2')
        cmds.append('/run/initialize')
        cmds.append('/vis/open OGL')
        cmds.append('/vis/verbose errors')
        cmds.append('/vis/drawVolume')
        cmds.append('/vis/viewer/set/viewpointThetaPhi 55. 45.')
        cmds.append('/vis/scene/add/axes 0 0 0 3 m')
        ui.Commands = cmds
    kernel.NumEvents = 0
    kernel.configure()
    kernel.initialize()
    kernel.run()
    kernel.terminate()
Beispiel #10
0
def run():
  import CLICSid
  import DDG4
  import os
  import sys
  from DDG4 import OutputLevel as Output

  sid = CLICSid.CLICSid(no_physics=False)
  geant4 = sid.geant4
  kernel = sid.kernel
  sid.loadGeometry()
  geant4.printDetectors()
  kernel.UI = 'UI'
  if len(sys.argv) >= 2 and sys.argv[1] == "batch":
    DDG4.setPrintLevel(DDG4.OutputLevel.WARNING)
    kernel.UI = ''
  geant4.setupCshUI()
  sid.setupField(quiet=False)
  DDG4.importConstants(kernel.detectorDescription(), debug=False)

  prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
  prt.OutputLevel = Output.INFO
  prt.OutputType = 3  # Print both: table and tree
  kernel.eventAction().adopt(prt)

  # First particle file reader
  gen = DDG4.GeneratorAction(kernel, "Geant4GeneratorActionInit/GenerationInit")
  kernel.generatorAction().adopt(gen)
  input = DDG4.GeneratorAction(kernel, "Geant4InputAction/Input")
  fname = os.environ['DD4hepExamplesINSTALL'] + '/examples/DDG4/data/hepmc_geant4.dat'
  input.Input = "Geant4EventReaderHepMC|" + fname
  input.MomentumScale = 1.0
  input.Mask = 1
  kernel.generatorAction().adopt(input)

  # Merge all existing interaction records
  merger = DDG4.GeneratorAction(kernel, "Geant4InteractionMerger/InteractionMerger")
  merger.enableUI()
  kernel.generatorAction().adopt(merger)

  logger.info("#  Finally generate Geant4 primaries")
  gen = DDG4.GeneratorAction(kernel, "Geant4PrimaryHandler/PrimaryHandler")
  gen.OutputLevel = 4  # generator_output_level
  gen.enableUI()
  kernel.generatorAction().adopt(gen)

  # And handle the simulation particles.
  part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
  kernel.generatorAction().adopt(part)
  part.OutputLevel = Output.INFO
  part.enableUI()

  logger.info("#  Configure Event actions")
  prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
  prt.OutputLevel = Output.INFO
  prt.OutputType = 3  # Print both: table and tree
  kernel.eventAction().adopt(prt)

  user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
  user.TrackingVolume_Zmax = DDG4.EcalEndcap_zmin
  user.TrackingVolume_Rmax = DDG4.EcalBarrel_rmin
  user.enableUI()
  part.adopt(user)
  #
  sid.setupDetectors()
  sid.setupPhysics('QGSP_BERT')
  sid.test_run(have_geo=True, num_events=1)