Skip to content
Snippets Groups Projects
checkGeometry.py 3.28 KiB
Newer Older
#!/bin/python
Marko Petric's avatar
Marko Petric committed
# ==========================================================================
Marko Petric's avatar
Marko Petric committed
#  AIDA Detector description implementation
Marko Petric's avatar
Marko Petric committed
# --------------------------------------------------------------------------
Markus Frank's avatar
Markus Frank committed
# 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.
#
Marko Petric's avatar
Marko Petric committed
# ==========================================================================
from __future__ import absolute_import, unicode_literals
Marko Petric's avatar
Marko Petric committed
import sys
import errno
import optparse
import logging
logging.basicConfig(format='%(levelname)s: %(message)s')
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

parser = optparse.OptionParser()
parser.description = "TGeo Geometry checking."
parser.formatter.width = 132
parser.add_option("-c", "--compact", dest="compact", default=None,
                  help="Define LCCDD style compact xml input",
Marko Petric's avatar
Marko Petric committed
                  metavar="<FILE>")
Marko Petric's avatar
Marko Petric committed
parser.add_option("-f", "--full",
                  dest="full", default=False,
                  help="Full geometry checking",
Marko Petric's avatar
Marko Petric committed
                  metavar="<boolean>")

parser.add_option("-n", "--ntracks",
Marko Petric's avatar
Marko Petric committed
                  dest="num_tracks", default=1000000,
                  help="Number of tracks [requires '--full']",
Marko Petric's avatar
Marko Petric committed
                  metavar="<integer>")

parser.add_option("-x", "--vx",
Marko Petric's avatar
Marko Petric committed
                  dest="vx", default=0.0,
                  help="X-position of track origine vertex [requires '--full']",
Marko Petric's avatar
Marko Petric committed
                  metavar="<double>")

parser.add_option("-y", "--vy",
Marko Petric's avatar
Marko Petric committed
                  dest="vy", default=0.0,
                  help="Y-position of track origine vertex [requires '--full']",
Marko Petric's avatar
Marko Petric committed
                  metavar="<double>")

parser.add_option("-z", "--vz",
Marko Petric's avatar
Marko Petric committed
                  dest="vz", default=0.0,
                  help="Z-position of track origine vertex [requires '--full']",
Marko Petric's avatar
Marko Petric committed
                  metavar="<double>")

parser.add_option("-o", "--option", dest="option", default='ob',
                  help="TGeoManager geometry check option default:ob",
Marko Petric's avatar
Marko Petric committed
                  metavar="<string>")

(opts, args) = parser.parse_args()

if opts.compact is None:
Marko Petric's avatar
Marko Petric committed
  logger.info("   %s", parser.format_help())
  sys.exit(1)

try:
  import ROOT
  from ROOT import gROOT
  gROOT.SetBatch(1)
except ImportError as X:
Marko Petric's avatar
Marko Petric committed
  logger.error('PyROOT interface not accessible: %s', str(X))
  sys.exit(errno.ENOENT)

except ImportError as X:
Marko Petric's avatar
Marko Petric committed
  logger.error('dd4hep python interface not accessible: %s', str(X))
  sys.exit(errno.ENOENT)
dd4hep.setPrintLevel(dd4hep.OutputLevel.ERROR)
Marko Petric's avatar
Marko Petric committed
logger.info('+++%s\n+++ Loading compact geometry:%s\n+++%s', 120 * '=', opts.compact, 120 * '=')
description = dd4hep.Detector.getInstance()
Markus Frank's avatar
Markus Frank committed
description.fromXML(opts.compact)
opts.num_tracks = int(opts.num_tracks)
opts.vx = float(opts.vx)
opts.vy = float(opts.vy)
opts.vz = float(opts.vz)
Marko Petric's avatar
Marko Petric committed
logger.info('+++%s\n+++ Checking geometry:%s full-check:%s\n+++%s', 120 * '=', opts.compact, opts.full, 120 * '=')
if opts.full:
Marko Petric's avatar
Marko Petric committed
  logger.info('+++ # tracks:%d vertex:(%7.3f, %7.3f, %7.3f) [cm]', opts.num_tracks, opts.vx, opts.vy, opts.vz)
  description.manager().CheckGeometryFull(opts.num_tracks, opts.vx, opts.vy, opts.vz, opts.option)
Markus Frank's avatar
Markus Frank committed
  description.manager().CheckGeometry()