def make_shape(bucket, shape): ''' Make a TGeo shape out of the object ''' typename = type(shape).__name__ shape, _ = wash_units(shape) obj = None if typename == 'Box': obj = bucket.make(ROOT.TGeoBBox, shape.name, shape.dx, shape.dy, shape.dz) if typename == 'Tubs': obj = bucket.make(ROOT.TGeoTubeSeg, shape.name, shape.rmin, shape.rmax, shape.dz, shape.sphi, shape.sphi+shape.dphi) if typename == 'Sphere': obj = bucket.make(ROOT.TGeoSphere, shape.name, shape.rmin, shape.rmax, shape.stheta, shape.stheta+shape.dtheta, shape.sphi, shape.sphi+shape.dphi) # etc.... Grow this as gegede.schema.Schema.shapes grows.... if obj: # for generic look up later bucket.add(obj, 'SHAPE') return obj
def test_wash_units(): Thing = namedtuple("Thing", "name l a") t1 = Thing('t1', Q("1mm"), Q("1degree")) n1, u1 = wash_units(t1, lunit='meter', aunit='radian') assert n1.l == 0.001, n1 assert abs(n1.a - 3.14159 / 180) < 0.01, n1 assert 'meter' == u1['lunit'], u1 assert 'radian' == u1['aunit'], u1 OtherThing = namedtuple("OtherThing", "name l1 l2") ot2 = OtherThing('ot2', Q("1mm"), Q("2meter")) n2, u2 = wash_units(ot2, lunit='meter', aunit='radian') assert n2.l1 == 0.001, n2 assert n2.l2 == 2.0, n2 assert 'meter' == u2['lunit'], u2 assert 'aunit' not in u2, u2
def test_wash_units(): Thing = namedtuple("Thing", "name l a") t1 = Thing('t1', Q("1mm"), Q("1degree")) n1,u1 = wash_units(t1, lunit='meter', aunit='radian') assert n1.l == 0.001, n1 assert abs(n1.a - 3.14159/180) < 0.01, n1 assert 'meter' == u1['lunit'], u1 assert 'radian' == u1['aunit'], u1 OtherThing = namedtuple("OtherThing", "name l1 l2") ot2 = OtherThing('ot2', Q("1mm"), Q("2meter")) n2,u2 = wash_units(ot2, lunit='meter', aunit='radian') assert n2.l1 == 0.001, n2 assert n2.l2 == 2.0, n2 assert 'meter' == u2['lunit'], u2 assert 'aunit' not in u2, u2