Example #1
0
    def load_one(self, itag):

        ok = self.ok
        aname = "a%d" % itag
        bname = "b%d" % itag

        atag = "%s" % itag
        btag = "-%s" % itag

        a = Evt(tag=atag, src=ok.src, det=ok.det, pfx=ok.pfx, args=ok)
        b = Evt(tag=btag, src=ok.src, det=ok.det, pfx=ok.pfx, args=ok)

        ap = A.path_("ox", ok.src, atag, ok.det, ok.pfx)
        bp = A.path_("ox", ok.src, btag, ok.det, ok.pfx)

        print(ap)
        print(a.ox.path)

        print(bp)
        print(b.ox.path)

        globals()[aname] = a
        globals()[bname] = b

        if itag == 1:
            # TODO: should really assert-compare and add
            self.aj["parameters.json"] = a.metadata.parameters
            self.bj["parameters.json"] = b.metadata.parameters
        pass

        ## necessary metadata arrays : fdom, idom
        for mtem in self.mtems:
            a_ = getattr(a, mtem)
            b_ = getattr(b, mtem)

            if not mtem in self.am:
                self.am[mtem] = a_
            else:
                assert np.all(self.am[mtem] == a_)
            pass
            if not mtem in self.bm:
                self.bm[mtem] = b_
            else:
                assert np.all(self.bm[mtem] == b_)
            pass
        pass

        ## content arrays : ox, rx, ph, ...
        for stem in self.stems:

            a_ = getattr(a, stem)
            b_ = getattr(b, stem)

            if not a_.missing and len(a_) > 0:
                self.aa[stem].append(a_)
            pass
            if not b_.missing and len(b_) > 0:
                self.bb[stem].append(b_)
            pass
        pass
Example #2
0
    def load(self):
        """
        It takes aound 4s on Precision Workstation to load 1M full AB evt pair. 
        So avoid needing to duplicate that.
        """
        pyver = "{major}.{minor}.{micro}".format(major=sys.version_info.major,minor=sys.version_info.minor,micro=sys.version_info.micro)  
        log.info("[ smry:%s np.__version__ %s py%s" % (self.ok.smry, np.__version__, pyver) )
        args = self.ok
 
        if args.utag is None:
            assert len(args.utags) == 2, ( "expecting 2 utags ", args.utags )
            atag = "%s" % args.utags[0]
            btag = "%s" % args.utags[1]
        else:
            atag = "%s" % args.utag
            btag = "-%s" % args.utag
        pass

        a = Evt(tag=atag, src=args.src, det=args.det, pfx=args.pfx, args=args, nom="A", smry=args.smry)
        b = Evt(tag=btag, src=args.src, det=args.det, pfx=args.pfx, args=args, nom="B", smry=args.smry)

        pass
        self.a = a
        self.b = b 

        valid = a.valid and b.valid 
        if not valid:
            log.fatal("invalid loads : a.valid:%s b.valid:%s " % (a.valid, b.valid))
        pass
        self.valid = valid 

        self.align = None
        self._dirty = False

        ## property setters
        if valid:
            self.sel = None
            self.irec = 0
            self.qwn = "X"
        pass
        log.info("] ")
Example #3
0
 def _make_cf(self, ana, shortname):
     """
     all_ tables have no selection applied so they are not dirtied by changing selection
     """
     ordering = self.ok.cfordering 
     assert ordering in ["max","self","other"] 
     c_tab = Evt.compare_ana( self.a, self.b, ana, lmx=self.ok.lmx, cmx=self.ok.cmx, c2max=None, cf=True, ordering=ordering, shortname=shortname )
     if not ana[0:3] == "all":
         self.tabs.append(c_tab)
     pass 
     tabname = self.tabname(ana)
     setattr(self, tabname, c_tab)
     return c_tab 
from opticks.ana.nbase import count_unique
from opticks.ana.evt import Evt
from opticks.ana.proplib import PropLib

X,Y,Z,W = 0,1,2,3


if __name__ == '__main__':
    from opticks.ana.main import opticks_main
    #args = opticks_main(tag="1", det="boolean", src="torch")
    ok = opticks_main()


    blib = PropLib("GBndLib")

    evt = Evt(tag=ok.tag, det=ok.det, src=ok.src, pfx=ok.pfx, args=ok)

    if not evt.valid:
       log.fatal("failed to load evt %s " % repr(args))
       sys.exit(1) 

    ox = evt.ox

    ## assume layout written by oxrap/cu/generate.cu:tracetest ##

    p0 = ox[:,0,:W]
    d0 = ox[:,1,:W]
    t0 = ox[:,1,W]
    flg = ox[:,3].view(np.uint32)  # u-flags 

    p1 = p0 + np.repeat(t0,3).reshape(-1,3)*d0   # intersect position
Example #5
0
    ax.set_yscale('log')

    ax = fig.add_subplot(222)
    ax.hist(y[s], bins=100)
    ax.set_yscale('log')

    ax = fig.add_subplot(223)
    ax.hist(z[s], bins=100)
    ax.set_yscale('log')

    ax = fig.add_subplot(224)
    ax.hist(t[s], bins=100)
    ax.set_yscale('log')
    fig.show()


if __name__ == '__main__':

    ok = opticks_main(src="G4Gun", det="G4Gun", tag="-1")

    try:
        evt = Evt(tag=ok.tag, src=ok.src, det=ok.det, args=ok)
    except IOError as err:
        log.fatal(err)
        sys.exit(ok.mrc)
    pass

    print evt

    red_gensteps_everywhere_issue(evt.gs)
Example #6
0
            ax.hist(pos[:, ic], bins=nb)
            ax.set_xlabel(lab)


def angle_plot(fig, evts, irec=0, axis=[0, 0, 1], origin=[0, 0, -200], nb=100):

    origin = np.asarray(origin)
    nc = len(evts)
    nr = 1

    for ic, evt in enumerate(evts):
        pos = evt.rpost_(irec)[:, :3] - origin

        axis_ = np.tile(axis, len(pos)).reshape(-1, len(axis))

        ct = costheta_(pos, axis_)
        th = np.arccos(ct) / deg

        ax = fig.add_subplot(nr, nc, 1 + ic)
        ax.hist(th, bins=nb)
        ax.set_xlabel("angle to axis %s " % str(axis))


if __name__ == '__main__':
    args = opticks_main(tag="5", det="rainbow", src="torch")
    try:
        evt = Evt(tag=args.tag, det=args.det, src=args.src, args=args)
    except IOError as err:
        log.fatal(err)
        sys.exit(args.mrc)
Example #7
0
TODO: for G4 only (-ve itag) could use the deluxe buffer dx.npy for double precision step points 


"""
import numpy as np
from opticks.ana.evt import Evt
import pyvista as pv

if __name__ == '__main__':
    from opticks.ana.main import opticks_main
    ok = opticks_main(pfx="tds3ip", src="natural")

    itag = int(ok.utag)

    a = Evt(tag="%d"%itag, src=ok.src, det=ok.det, pfx=ok.pfx, args=ok)
    if hasattr(a, 'seqhis_ana'):
        expr="a.seqhis_ana.table[0:20]"
        print(expr)
        print(eval(expr))
    pass 

    if itag < 0:
        a.sel = "TO BT BT BT BT SD"  # 0x7ccccd 
        #        -6 -5 -4 -3 -2 -1
        #         Y  M  C  B  G  R
    elif itag > 0:
        a.sel = "TO BT BT BT SD"    #  0x7cccd 
        #        -5 -4 -3 -2 -1
        #         M  C  B  G  R
    else:
Example #8
0
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

from opticks.ana.base import opticks_main
from opticks.ana.evt import Evt
from opticks.ana.planck import planck

if __name__ == '__main__':
    plt.ion()
    args = opticks_main(tag="1", det="white", src="torch")

    ## tag = "1"   ## dont have any tag 1 anymore
    ## tag = "15"     ## so added tag 15,16 to ggv-rainbow with wavelength=0 which is default black body

    try:
        evt = Evt(tag=args.tag, det=args.det, src=args.src, args=args)
    except IOError as err:
        log.fatal(err)
        sys.exit(args.mrc)

    if not evt.valid:
        log.fatal("failed to load evt %s " % repr(args))
        sys.exit(1)

    wl = evt.wl
    w0 = evt.recwavelength(0)

    w = wl
    #w = w0

    wd = np.linspace(60, 820, 256) - 1.
Example #9
0
from opticks.ana.nbase import vnorm
from opticks.ana.evt import Evt

X, Y, Z, W = 0, 1, 2, 3

if __name__ == '__main__':
    args = opticks_main(tag="1", src="torch", det="BoxInBox")

    np.set_printoptions(precision=4, linewidth=200)
    np.set_printoptions(formatter={'int': hex})

    plt.ion()
    plt.close()

    try:
        a = Evt(tag="%s" % args.tag, src=args.src, det=args.det, args=args)
        b = Evt(tag="-%s" % args.tag, src=args.src, det=args.det, args=args)
    except IOError as err:
        log.fatal(err)
        sys.exit(args.mrc)

    log.info(" A : %s " % a.brief)
    log.info(" B : %s " % b.brief)

if 1:
    c2max = args.c2max
    c2max = None

    log.info("\n\nEvt.compare_table.0\n")
    Evt.compare_table(a,
                      b,
Example #10
0
    def __init__(self, evt, focus, normal):
        """
        :param evt:
        :param focus: coordinates of reflection point

        
        p0a initial position with no selection applied

        """

        al = evt
        p0a = al.rpost_(0)[:, :W] - focus
        tha = self.theta(p0a, normal)

        br = Evt.selection(evt,
                           seqs=["TO BR SA", "TO BR AB"],
                           label="TO BR ..")

        p0 = br.rpost_(0)[:, :W] - focus  # start
        p1 = br.rpost_(1)[:, :W] - focus  # refl point
        p2 = br.rpost_(2)[:, :W] - focus  # end

        #miss = p1[:,2] != p1[0,2]   # this assumes a particular geometry
        # missers confirmed to be a triangulation crack effect
        # avoid by not targetting cracks with millions of photons whilst doing reflection tests
        # ...get **ZERO** missers when avoid cracks ...

        if 0:
            miss = np.tile(False, len(p1))
            self.miss = miss
            msk = ~miss
            p0u = p0[msk]
            p2u = p2[msk]
        else:
            p0u = p0
            p2u = p2

        th0 = self.theta(p0u, normal)
        th2 = self.theta(p2u, normal)
        th = th0

        missrat = Rat(th0, p0, "th0/p0")

        rats = []
        rats.append(Rat(p0, tha, "p0/tha"))
        rats.append(Rat(th0, tha, "th0/tha"))
        rats.append(missrat)

        msg = " ".join(map(repr, rats))
        log.info("%s : %s " % (repr(evt), msg))

        # th0 and th2 are incident and reflected angles
        # matching very well after exclude miss-ers

        self.evt = evt
        self.focus = focus
        self.normal = normal
        self.al = al
        self.br = br
        self.p0a = p0a
        self.tha = tha
        self.p0 = p0
        self.p1 = p1
        self.p2 = p2
        self.th0 = th0
        self.th2 = th2
        self.th = th
        self.missfrac = 1. - missrat.r
        self.rats = rats
Example #11
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
"""
import os, logging, numpy as np

log = logging.getLogger(__name__)

from opticks.ana.base import opticks_environment
from opticks.ana.evt import Evt

deg = np.pi / 180.

if __name__ == '__main__':
    pass
    logging.basicConfig(level=logging.INFO)
    opticks_environment()

    spol, ppol = "5", "6"
    g = Evt(tag="-" + spol, det="rainbow", label="S G4")
    o = Evt(tag=spol, det="rainbow", label="S Op")

    # check magnitude of polarization
    for e in [g, o]:
        mag = np.linalg.norm(e.rpol_(0), 2, 1)
        assert mag.max() < 1.01 and mag.min() > 0.99
Example #12
0
                        tag="1",
                        src="torch",
                        det="boxlaser",
                        c2max=2.0,
                        tagoffset=0)

    log.info("tag %s src %s det %s c2max %s  " %
             (args.utag, args.src, args.det, args.c2max))

    a_seqs = []
    b_seqs = []

    try:
        a = Evt(tag="%s" % args.utag,
                src=args.src,
                det=args.det,
                seqs=a_seqs,
                args=args)
        b = Evt(tag="-%s" % args.utag,
                src=args.src,
                det=args.det,
                seqs=b_seqs,
                args=args)
    except IOError as err:
        log.fatal(err)
        sys.exit(args.mrc)

    print "A", a
    print "B", b

    log.info(" a : %s " % a.brief)
Example #13
0
    fig.show()


def attic():
    transform = "0.500,0.866,0.000,0.000,-0.866,0.500,0.000,0.000,0.000,0.000,1.000,0.000,-86.603,0.000,0.000,1.000"
    tx = np.fromstring(transform, sep=",").reshape(4, 4)
    focus = np.dot([0, 0, 0, 1], tx)[:3]
    normal = np.dot([0, 1, 0, 0], tx)[:3]


if __name__ == '__main__':

    args = opticks_main(det="reflect", stag="1", ptag="2")

    try:
        es = Evt(tag=args.stag, label="S", det=args.det, args=args)
        ep = Evt(tag=args.ptag, label="P", det=args.det, args=args)
    except IOError as err:
        log.fatal(err)
        sys.exit(args.mrc)

    log.info(" es : %s " % es.brief)
    log.info(" ep : %s " % ep.brief)

    if not (es.valid and ep.valid):
        log.fatal("both es and ep must be valid")
        sys.exit(1)
    pass

    normal = [0, 0, -1]
    source = [0, 0, -200]
Example #14
0
            pass
        pass

    if ox:
        xs = evt.ox[:, 0, 0]
        ys = evt.ox[:, 0, 1]
        zs = evt.ox[:, 0, 2]
        ax.scatter(xs, ys, zs)
    pass


if __name__ == '__main__':
    args = opticks_main(tag="1", src="natural", det="g4live", doc=__doc__)
    np.set_printoptions(suppress=True, precision=3)

    evt = Evt(tag=args.tag, src=args.src, det=args.det, seqs=[], args=args)

    log.debug("evt")
    print(evt)

    log.debug("evt.history_table")
    evt.history_table(slice(0, 20))
    log.debug("evt.history_table DONE")

    plt.ion()
    fig = plt.figure()

    plot(evt, fig)

    plt.show()
Example #15
0
                        src="torch",
                        det="PmtInBox",
                        c2max=2.0,
                        tagoffset=0)

    log.info("tag %s src %s det %s c2max %s  " %
             (args.utag, args.src, args.det, args.c2max))

    #seqs = ["TO BT BR BT BT BT BT SA"]
    #seqs = ["TO BT BR BR BT SA"]
    seqs = []

    try:
        a = Evt(tag="%s" % args.utag,
                src=args.src,
                det=args.det,
                seqs=seqs,
                args=args)
        b = Evt(tag="-%s" % args.utag,
                src=args.src,
                det=args.det,
                seqs=seqs,
                args=args)
    except IOError as err:
        log.fatal(err)
        #sys.exit(args.mrc)  this causes a sysrap-t test fail from lack of a tmp file
        sys.exit(0)

    log.info(" a : %s " % a.brief)
    log.info(" b : %s " % b.brief)
Example #16
0
"""
import os, sys, logging, numpy as np
log = logging.getLogger(__name__)

from opticks.ana.base import opticks_main
from opticks.ana.evt import Evt
from opticks.ana.hismask import HisMask
from opticks.ana.nbase import count_unique_sorted

if __name__ == '__main__':
    ok = opticks_main(det="concentric", src="torch", tag="1")
    hm = HisMask()

    e = Evt(tag="-%s" % ok.utag,
            src=ok.src,
            det=ok.det,
            args=ok,
            seqs=["PFLAGS_DEBUG"])
    e.history_table(slice(0, 20))

    cu_pflags = count_unique_sorted(e.pflags[e.psel])
    cu_pflags2 = count_unique_sorted(e.pflags2[e.psel])

    print "\n".join(["", "cu_pflags (masks from CRecorder)"] +
                    map(lambda _: hm.label(_), cu_pflags[:, 0]))
    print cu_pflags

    print "\n".join(["", "cu_pflags2 (masks derived from seqhis)"] +
                    map(lambda _: hm.label(_), cu_pflags2[:, 0]))
    print cu_pflags2
Example #17
0
    tag = args.tag
    if tag == "-6":
        label = "P G4"
    elif tag == "-5":
        label = "S G4"
    elif tag == "5":
        label = "S Op"
    elif tag == "6":
        label = "P Op"
    else:
        label = "label?"

    try:
        evt = Evt(tag=tag,
                  det=args.det,
                  src=args.src,
                  seqs=seqs,
                  label=label,
                  args=args)
    except IOError as err:
        log.fatal(err)
        sys.exit(args.mrc)

    log.info("loaded %s " % repr(evt))

    sr = SphereReflect(evt)

    p1 = sr.p1

    sr.spatial()

    #sr.check_intersection()
Example #18
0
     129     3332332332332231            56            4            45.07       14.000 +- 1.871        0.071 +- 0.036  [16] Gd Ac LS LS Ac Ac LS Ac Ac LS Ac Ac LS Ac Ac Ac
     135     2231111323443231            51            6            35.53        8.500 +- 1.190        0.118 +- 0.048  [16] Gd Ac LS Ac MO MO Ac LS Ac Gd Gd Gd Gd Ac LS LS
    .                               1000000      1000000      2325.00/233 =  9.98 


"""
import os, sys, logging, numpy as np
log = logging.getLogger(__name__)

from opticks.ana.base import opticks_main
from opticks.ana.evt import Evt
from opticks.ana.nbase import count_unique_sorted

if __name__ == '__main__':
    ok = opticks_main(det="concentric", src="torch", tag="1")

    #seq = "Gd Ac LS Ac MO MO MO"
    #seq = "TO BT BT BT BT DR AB"
    #seq = "TO BT BT BT BT SC AB"
    #seq = "Gd Ac LS Ac MO MO Ac LS Ac Gd Ac LS Ac MO MO MO"
    seq = "Gd Gd Gd Ac LS Ac MO MO Ac LS Ac Gd Ac LS Ac Ac"

    a = Evt(tag="%s" % ok.utag, src=ok.src, det=ok.det, args=ok, seqs=[seq])
    b = Evt(tag="-%s" % ok.utag, src=ok.src, det=ok.det, args=ok, seqs=[seq])

    a.history_table(slice(0, 20))
    b.history_table(slice(0, 20))

    acu = count_unique_sorted(a.seqhis[a.psel])
    bcu = count_unique_sorted(b.seqhis[b.psel])
Example #19
0
        Out[58]: 1.6846611499786377

    """
    plt.hist(d, bins=100)




if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    args = opticks_main(det="newton", tag="1", src="torch")

    plt.ion()

    try:
        sel = Evt(tag=args.tag, det=args.det, src=args.src, seqs=["TO BT BT SA"], args=args)  # newton, uses single incident angle
    except IOError as err:
        log.fatal(err)
        sys.exit(args.mrc)

    log.info("loaded %s " % repr(sel))

    boundary = Boundary("Vacuum///GlassSchottF2")

    prism = Prism("60.,300,300,0", boundary)

    n = boundary.imat.refractive_index(sel.wl)  

    xprism = PrismExpected(prism.a, n)

    pc = PrismCheck(prism, xprism, sel )
Example #20
0
    sc = gdml2gltf_main(args)
    tx = sc.get_transform(3159)
    print tx

    itx = la.inv(tx)
    print itx

    log.info("tag %s src %s det %s  " % (args.utag, args.src, args.det))

    seqs = []

    try:
        a = Evt(tag="%s" % args.utag,
                src=args.src,
                det=args.det,
                seqs=seqs,
                args=args)
    except IOError as err:
        log.fatal(err)
        #sys.exit(args.mrc)  this causes a sysrap-t test fail from lack of a tmp file
        sys.exit(0)

    log.info(" a : %s " % a.brief)

    print a.seqhis_ana.table

    a.sel = "TO SA"
    ox = a.ox

    print ox.shape  # masked array with those photons
Example #21
0
    ax.hist2d(w, y, bins=100, norm=LogNorm())


if __name__ == '__main__':

    args = opticks_main(tag="1", det="prism")

    plt.ion()

    #wl = np.arange(10, dtype=np.float32)*70. + 100.
    # low range is off edge of the refractive index values

    seqs = ["TO BT BT SA"]

    try:
        sel = Evt(tag=args.tag, det=args.det, seqs=seqs, args=args)
    except IOError as err:
        log.fatal(err)
        sys.exit(args.mrc)

    log.info("sel %s " % sel.brief)

    if not sel.valid:
        log.fatal("failed to load tag %s det %s " % (args.tag, args.det))
        sys.exit(1)

    boundary = Boundary("Vacuum///GlassSchottF2")

    prism = Prism("60.,300,300,0", boundary)

    log.info("prism %s " % repr(prism))
Example #22
0
    if det == "rainbow":
        if tag == "5":
            label = "S-Pol"
        elif tag == "6":
            label = "P-Pol"
        else:
            label = "no label"

    seqs = []

    try:
        a = Evt(tag=tag,
                src=src,
                det=det,
                label="%s Op" % label,
                seqs=seqs,
                not_=not_,
                rec=rec,
                args=args)
        b = Evt(tag="-%s" % tag,
                src=src,
                det=det,
                label="%s G4" % label,
                seqs=seqs,
                not_=not_,
                rec=rec,
                args=args)
    except IOError as err:
        log.fatal(err)
        sys.exit(args.mrc)
Example #23
0
from opticks.ana.evt import Evt

if __name__ == '__main__':

    args = opticks_main(tag="1",
                        src="natural",
                        det="g4live",
                        pfx="OKG4Test",
                        doc=__doc__)
    np.set_printoptions(suppress=True, precision=3)

    print("pfx:%s" % args.pfx)

    a = Evt(tag=args.tag,
            src=args.src,
            det=args.det,
            pfx=args.pfx,
            seqs=[],
            args=args)
    print("a")
    print(a)

    #a2 = Evt(tag=args.tag, src=args.src, det=args.det, pfx="source", seqs=[], args=args)
    #print("a2")
    #print(a2)

    b = Evt(tag="-%s" % args.tag,
            src=args.src,
            det=args.det,
            pfx=args.pfx,
            seqs=[],
            args=args)
Example #24
0
    ALL, PYREX, VACUUM, CATHODE, BOTTOM, DYNODE = None, 0, 1, 2, 3, 4
    pts = pmt.parts(ALL)
    one_plot(fig, pmt, pts, axes=ZX, clip=True)

    pol = False

    # aseqs=["TO BT BR BT BT BT BT BT BT SA"]   before fixing the TIR bug this was what was happening
    aseqs = ["TO BT BR BR BT SA"]
    bseqs = ["TO BT BR BR BT SA"]
    na = len(aseqs[0].split())
    nb = len(bseqs[0].split())

    try:
        a = Evt(tag="%s" % args.tag,
                src=args.src,
                det=args.det,
                seqs=aseqs,
                args=args)
        b = Evt(tag="-%s" % args.tag,
                src=args.src,
                det=args.det,
                seqs=bseqs,
                args=args)
    except IOError as err:
        log.fatal(err)
        sys.exit(args.mrc)

    if a.valid:
        log.info("A : plot zrt_profile %s " % a.label)
        print "A(Op) %s " % a.label
        a_zrt = a.zrt_profile(na, pol=pol)