File indexing completed on 2026-04-10 07:50:27
0001
0002
0003 import os, logging, numpy as np
0004 log = logging.getLogger(__name__)
0005
0006 MODE = int(os.environ.get("MODE","2"))
0007 PIDX = int(os.environ.get("PIDX","-1"))
0008 N = int(os.environ.get("VERSION","-1"))
0009
0010 from opticks.ana.fold import Fold, AttrBase
0011
0012
0013 class ModelTrigger_Debug(AttrBase):
0014 @classmethod
0015 def Create(cls, t, symbol="mtd", prefix="", publish=False):
0016 meta = t.ModelTrigger_Debug_meta if hasattr(t, 'ModelTrigger_Debug_meta') else None
0017 mtd = t.ModelTrigger_Debug if hasattr(t, 'ModelTrigger_Debug' ) else None
0018 incomplete = (meta is None) or (mtd is None)
0019 return None if incomplete else cls(t, symbol=symbol, prefix=prefix, publish=publish)
0020
0021 def __init__(self, t, symbol="mtd", prefix="", publish=False ):
0022 """
0023 :param t: Fold instance
0024 :param prefix: prefix for symbols planted into global scope
0025 :param publish: symbols into global scope
0026 """
0027 AttrBase.__init__(self, symbol=symbol, prefix=prefix, publish=publish)
0028
0029 meta = t.ModelTrigger_Debug_meta
0030 mtd = t.ModelTrigger_Debug
0031
0032 if mtd is None or mtd.shape[0] == 0:
0033 log.fatal("loaded SEvt has missing or empty ModelTrigger_Debug mtd.shape:%s" % (str(mtd.shape)))
0034 log.fatal("Ensure are using SEvt created whilst running with the old FastSim POM active, eg with N=0 ")
0035 pass
0036
0037
0038 PV = np.array(meta.PV)
0039 MLV = np.array(meta.MLV)
0040 WAI = np.array( ["OutOfRegion", "kInGlass ", "kInVacuum ", "kUnset "] )
0041
0042 IMPL = meta.IMPL[0]
0043
0044 pos = mtd[:,0,:3]
0045 time = mtd[:,0,3]
0046
0047 dir = mtd[:,1,:3]
0048 energy = mtd[:,1,3]
0049
0050
0051 dist1 = mtd[:,2,0]
0052 dist2 = mtd[:,2,1]
0053 mlv_ = mtd[:,2,2].view(np.uint64)
0054 etrig = mtd[:,2,3].view("|S8")
0055
0056
0057 index = mtd[:,3,0].view(np.uint64)
0058 pv_ = mtd[:,3,1].view(np.uint64)
0059 whereAmI_ = mtd[:,3,2].view(np.uint64)
0060 trig = mtd[:,3,3].view(np.uint64)
0061
0062 next_pos = mtd[:,4,:3]
0063 next_mct = mtd[:,4,3]
0064
0065 next_norm = mtd[:,5,:3]
0066 impl = mtd[:,5,3].view(np.uint64)
0067
0068 EInside1 = mtd[:,6,0].view(np.uint64)
0069 s61 = mtd[:,6,1].view(np.uint64)
0070 s62 = mtd[:,6,2].view(np.uint64)
0071 s63 = mtd[:,6,3].view(np.uint64)
0072
0073 mlv = MLV[mlv_]
0074 pv = PV[pv_]
0075 whereAmI = WAI[whereAmI_]
0076
0077 dist2[dist2 == 9e99] = np.inf
0078 dist1[dist1 == 9e99] = np.inf
0079
0080
0081 tr = np.eye(4)
0082
0083 lpos = np.ones( (len(pos),4) )
0084 lpos[:,:3] = pos
0085
0086 ldir = np.zeros( (len(dir),4) )
0087 ldir[:,:3] = dir
0088
0089 gpos = np.dot( lpos, tr )
0090 gdir = np.dot( ldir, tr )
0091
0092 lnext_pos = np.ones( (len(next_pos),4) )
0093 lnext_pos[:,:3] = next_pos
0094
0095 lnext_norm = np.zeros( (len(next_norm),4) )
0096 lnext_norm[:,:3] = next_norm
0097
0098 gnext_pos = np.dot( lnext_pos , tr )
0099 gnext_norm = np.dot( lnext_norm, tr )
0100
0101
0102
0103
0104
0105
0106
0107
0108 self.PV = PV
0109 self.MLV = MLV
0110 self.WAI = WAI
0111 self.mtd = mtd
0112 self.meta = meta
0113 self.IMPL = IMPL
0114 self.pos = pos
0115 self.time = time
0116 self.dir = dir
0117 self.energy = energy
0118 self.dist1 = dist1
0119 self.dist2 = dist2
0120 self.mlv_ = mlv_
0121 self.etrig = etrig
0122 self.index = index
0123 self.pv_ = pv_
0124 self.whereAmI_ = whereAmI_
0125 self.trig = trig
0126 self.next_pos = next_pos
0127 self.next_mct = next_mct
0128 self.next_norm = next_norm
0129 self.impl = impl
0130 self.mlv = mlv
0131 self.pv = pv
0132 self.whereAmI = whereAmI
0133 self.tr = tr
0134 self.lpos = lpos
0135 self.ldir = ldir
0136 self.gpos = gpos
0137 self.gdir = gdir
0138 self.lnext_pos = lnext_pos
0139 self.lnext_norm = lnext_norm
0140 self.gnext_pos = gnext_pos
0141 self.gnext_norm = gnext_norm
0142 self.EInside1 = EInside1
0143 self.s61 = s61
0144 self.s62 = s62
0145 self.s63 = s63
0146
0147
0148 def __str__(self):
0149 mtd = self
0150 lines = []
0151
0152 expr = "np.c_[mtd.index, mtd.whereAmI, mtd.trig, mtd.etrig, mtd.pv, mtd.mlv][mtd.index == PIDX]"
0153 lines.append("\n%s ## ModelTrigger_Debug mlv and pv for PIDX " % expr)
0154 lines.append(repr(eval(expr)))
0155
0156 expr = " np.c_[mtd.index, mtd.pos[:,2],mtd.time, mtd.gpos[:,:3], mtd.gdir[:,:3], mtd.dist1, mtd.dist2][mtd.index == PIDX] "
0157 lines.append("\n%s ## ModelTrigger_Debug for PIDX " % expr)
0158 lines.append(repr(eval(expr)))
0159
0160 return "\n".join(lines)
0161
0162
0163
0164 if __name__ == '__main__':
0165 t = Fold.Load(symbol="t")
0166 print(repr(t))
0167
0168 print("MODE:%d" % (MODE) )
0169 print("PIDX:%d" % (PIDX) )
0170 print("N:%d" % (N) )
0171
0172 mtd = ModelTrigger_Debug(t, symbol="mtd", publish=False)
0173 print(mtd)