Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:50:28

0001 #!/usr/bin/env python
0002 """
0003 U4SimulateTest_cf.py
0004 ========================
0005 
0006 """
0007 
0008 import os, numpy as np
0009 from opticks.ana.fold import Fold
0010 from opticks.ana.p import * 
0011 from opticks.ana.nbase import chi2  
0012 from opticks.ana.qcf import QU,QCF,QCFZero
0013 
0014 from opticks.u4.tests.ModelTrigger_Debug import ModelTrigger_Debug       
0015 from opticks.sysrap.sevt import SEvt
0016 
0017 hist_ = lambda _:_.strip().decode("utf-8")   
0018 
0019 
0020 NOGUI = "NOGUI" in os.environ
0021 MODE = int(os.environ.get("MODE", 0))
0022 if not NOGUI:
0023     from opticks.ana.pvplt import * 
0024 pass
0025 
0026 APID = int(os.environ.get("APID", -1))
0027 BPID = int(os.environ.get("BPID", -1))
0028 
0029 GEOM = os.environ.get("GEOM", "DummyGEOM")
0030 GEOMList = os.environ.get("%s_GEOMList" % GEOM, "DummyGEOMList") 
0031 
0032 
0033 if __name__ == '__main__':
0034 
0035     print("APID:%d" % (APID))
0036     print("BPID:%d" % (BPID))
0037 
0038     a = SEvt.Load("$AFOLD", symbol="a")
0039     b = SEvt.Load("$BFOLD", symbol="b")
0040 
0041     #print(repr(a))
0042     #print(repr(b))
0043 
0044     amt = ModelTrigger_Debug.Create(a.f, symbol="amt", publish=False)  # publish:True crashing 
0045     bmt = ModelTrigger_Debug.Create(b.f, symbol="bmt", publish=False)  # publish:True crashing 
0046     if (amt is None) or (bmt is None):
0047         print(" missing ModelTrigger_Debug amt:%s bmt:%s " % ( amt, bmt) )
0048         IMPL = "NoMTD"
0049     else:
0050         assert( amt.IMPL == bmt.IMPL )
0051         IMPL = amt.IMPL
0052     pass
0053 
0054 
0055     check_sevt = True
0056     if check_sevt:
0057         aq_ = a.f.seq[:,0]    #  shape eg (1000, 2, 2)
0058         bq_ = b.f.seq[:,0]     
0059         assert np.all( aq_ == a.q_ )
0060         assert np.all( bq_ == b.q_ )
0061 
0062         an = np.sum( seqnib_(aq_), axis=1 )     ## occupied nibbles across both sets of 16 from the two 64 bit ints 
0063         bn = np.sum( seqnib_(bq_), axis=1 )   
0064         assert np.all( an == a.n ) 
0065         assert np.all( bn == b.n ) 
0066 
0067         aq = ht.seqhis(aq_)  # "|S96"  32 point slots * 3 chars for each abbr eg "BT " 
0068         bq = ht.seqhis(bq_) 
0069 
0070         assert np.all( aq == a.q)
0071         assert np.all( bq == b.q)
0072 
0073         if 'SPECS' in os.environ:
0074             a_st_ = a.f.aux[:,:,2,3].view(np.int32)
0075             a_st = a.SPECS[a_st_]
0076 
0077             b_st_ = b.f.aux[:,:,2,3].view(np.int32)
0078             b_st = b.SPECS[b_st_]
0079 
0080             assert np.all( a.spec == a_st )
0081             assert np.all( b.spec == b_st )
0082         pass
0083     pass
0084 
0085 
0086 
0087     PID_DESC = "Dumping PID history and step specs with record position, time"
0088     if APID > -1:
0089         print("APID:%d # %s " % (APID,PID_DESC)  )
0090         exprs = "a.q[APID] np.c_[a.spec[APID,:a.n[APID]]] a.f.record[APID,:a.n[APID],0]"
0091         for expr in exprs.split(): 
0092             print(expr)
0093             print(repr(eval(expr)))
0094             print(".") 
0095         pass
0096     pass 
0097     if BPID > -1:
0098         print("BPID:%d # %s " % (BPID, PID_DESC) )
0099         exprs = "b.q[BPID] np.c_[b.spec[APID,:b.n[BPID]]] b.f.record[BPID,:b.n[BPID],0]"
0100         for expr in exprs.split(): 
0101             print(expr)
0102             print(repr(eval(expr))) 
0103             print(".") 
0104         pass
0105     pass 
0106 
0107 
0108     assert( a.CHECK == b.CHECK )
0109     CHECK = a.CHECK
0110 
0111     assert( a.LAYOUT == b.LAYOUT )
0112     LAYOUT = a.LAYOUT
0113 
0114     HEADLINE = "./U4SimulateTest.sh cf ## PMT Geometry : A(N=0) Unnatural+FastSim, B(N=1) Natural+CustomBoundary  "
0115     print("\n%s" % HEADLINE)
0116     print("GEOM/GEOMList/IMPL/LAYOUT/CHECK : %s/%s/%s/%s/%s " % (GEOM, GEOMList, IMPL, LAYOUT, CHECK) )
0117 
0118     qcf = QCF(a.q, b.q, symbol="qcf")
0119 
0120     print(qcf.aqu)
0121     print(qcf.bqu)
0122     print(qcf)
0123 
0124     #qcf0 = QCFZero(qcf)
0125     #print(qcf0)
0126 
0127