Beispiel #1
0
    def getDetectorLists(self, detectorDescription):
        ''' get lists of trackers and calorimeters that are defined in detectorDescription (the compact xml file)'''
        import DDG4
        trackers, calos, unknown = [], [], []
        for i in detectorDescription.detectors():
            det = DDG4.DetElement(i.second.ptr())
            name = det.name()
            sd = detectorDescription.sensitiveDetector(name)
            if sd.isValid():
                detType = sd.type()
                logger.info(
                    'getDetectorLists - found active detector %s type: %s',
                    name, detType)
                if any(pat.lower() in detType.lower()
                       for pat in self.action.trackerSDTypes):
                    trackers.append(det.name())
                elif any(pat.lower() in detType.lower()
                         for pat in self.action.calorimeterSDTypes):
                    calos.append(det.name())
                else:
                    logger.warning('Unknown sensitive detector type: %s',
                                   detType)
                    unknown.append(det.name())

        return trackers, calos, unknown
Beispiel #2
0
def run():
  kernel = DDG4.Kernel()
  install_dir = os.environ['DD4hepINSTALL']
  kernel.setOutputLevel('Geant4Converter',Output.DEBUG)
  kernel.setOutputLevel('Gun',Output.INFO)
  kernel.detectorDescription().fromXML("file:"+install_dir+"/examples/DDCMS/data/dd4hep-config.xml");
  kernel.NumEvents = 5
  geant4 = DDG4.Geant4(kernel,tracker='Geant4TrackerCombineAction')
  geant4.printDetectors()
  geant4.setupCshUI()
  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
  field = geant4.setupTrackingField(prt=True)
  # Configure I/O
  evt_root = geant4.setupROOTOutput('RootOutput','CMSTracker_'+time.strftime('%Y-%m-%d_%H-%M'),mc_truth=True)
  # Setup particle gun
  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())
    sd = geant4.description.sensitiveDetector(o.name())
    if sd.isValid():
      type = geant4.sensitive_types[sd.type()]
      print 'CMSTracker: Configure subdetector %-24s of type %s'%(o.name(),type,)
      geant4.setupDetector(o.name(),type)

  # And handle the simulation particles.
  part = DDG4.GeneratorAction(kernel,"Geant4ParticleHandler/ParticleHandler")
  kernel.generatorAction().adopt(part)
  part.SaveProcesses = ['conv','Decay']
  part.MinimalKineticEnergy = 1*MeV
  part.OutputLevel = 5 # generator_output_level
  part.enableUI()

  # Now build the physics list:
  phys = kernel.physicsList()
  phys.extends = 'QGSP_BERT'
  phys.enableUI()
  # and run
  geant4.execute()
Beispiel #3
0
def getDetectorLists( lcdd ):
  ''' get lists of trackers and calorimeters that are defined in lcdd (the compact xml file)'''
#  if len(detectorList):
#    print " subset list of detectors given - will only instantiate these: " , detectorList
  t,c = [],[]
  for i in lcdd.detectors():
    det = DDG4.DetElement(i.second)
    name = det.name()
    sd =  lcdd.sensitiveDetector( name )
    if sd.isValid():
      type = sd.type()
#      if len(detectorList) and not(name in detectorList):
#        continue
      print 'getDetectorLists - found active detctor ' ,  name , ' type: ' , type
      if type == "tracker":
        t.append( det.name() )
      if type == "calorimeter":
        c.append( det.name() )

  return t,c
Beispiel #4
0
    def getDetectorLists(detectorDescription):
        ''' get lists of trackers and calorimeters that are defined in detectorDescription (the compact xml file)'''
        import DDG4
        #  if len(detectorList):
        #    print " subset list of detectors given - will only instantiate these: " , detectorList
        trackers, calos = [], []
        for i in detectorDescription.detectors():
            det = DDG4.DetElement(i.second.ptr())
            name = det.name()
            sd = detectorDescription.sensitiveDetector(name)
            if sd.isValid():
                detType = sd.type()
                #      if len(detectorList) and not(name in detectorList):
                #        continue
                print 'getDetectorLists - found active detctor ', name, ' type: ', detType
                if detType == "tracker":
                    trackers.append(det.name())
                if detType == "calorimeter":
                    calos.append(det.name())

        return trackers, calos
Beispiel #5
0
    def getDetectorLists(detectorDescription):
        ''' get lists of trackers and calorimeters that are defined in detectorDescription (the compact xml file)'''
        import DDG4
        trackers, calos = [], []
        for i in detectorDescription.detectors():
            det = DDG4.DetElement(i.second.ptr())
            name = det.name()
            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":
                    trackers.append(det.name())
                if detType == "calorimeter":
                    calos.append(det.name())

        return trackers, calos
Beispiel #6
0
def run():
    kernel = DDG4.Kernel()
    install_dir = os.environ['DD4hepExamplesINSTALL']
    kernel.setOutputLevel(str('Geant4Converter'), Output.DEBUG)
    kernel.setOutputLevel(str('Gun'), Output.INFO)
    kernel.detectorDescription().fromXML(
        str("file:" + install_dir + "/examples/DDCMS/data/dd4hep-ecal.xml"))
    kernel.NumEvents = 5
    geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
    geant4.printDetectors()

    batch = False
    test = False
    vis = False
    ui = None
    for i in range(len(sys.argv)):
        arg = sys.argv[i].lower()
        if arg == 'batch':
            batch = True
        elif arg[:4] == '-vis':
            vis = True
        elif arg == 'test':
            test = True
        elif arg == 'numevents':
            kernel.NumEvents = int(sys.argv[i + 1])
    if batch or test:
        geant4.setupCshUI(ui=None, vis=None)
        kernel.UI = 'UI'
    else:
        ui = geant4.setupCshUI(vis=vis)

    # Configure field
    geant4.setupTrackingField(prt=True)
    # Configure I/O
    geant4.setupROOTOutput('RootOutput',
                           'CMSEcal_' + time.strftime('%Y-%m-%d_%H-%M'),
                           mc_truth=True)
    # Setup particle gun
    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("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())
        sd = geant4.description.sensitiveDetector(o.name())
        if sd.isValid():
            type = geant4.sensitive_types[sd.type()]
            logger.info('CMSTracker: Configure subdetector %-24s of type %s' %
                        (
                            o.name(),
                            type,
                        ))
            geant4.setupDetector(o.name(), type)

    # And handle the simulation particles.
    part = DDG4.GeneratorAction(kernel,
                                "Geant4ParticleHandler/ParticleHandler")
    kernel.generatorAction().adopt(part)
    part.SaveProcesses = ['conv', 'Decay']
    part.MinimalKineticEnergy = 1 * MeV
    part.OutputLevel = 5  # generator_output_level
    part.enableUI()

    # Now build the physics list:
    phys = kernel.physicsList()
    phys.extends = 'QGSP_BERT'
    phys.enableUI()
    #
    #
    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
    #
    # and run
    geant4.execute()