File indexing completed on 2026-04-09 07:48:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 import os, sys, logging, numpy as np
0023 from opticks.ana.base import opticks_main
0024 from opticks.ana.cfh import CFH
0025 from opticks.ana.nbase import chi2, vnorm
0026 from opticks.ana.decompression import decompression_bins
0027 from opticks.ana.histype import HisType
0028 from opticks.ana.mattype import MatType
0029 from opticks.ana.evt import Evt
0030 log = logging.getLogger(__name__)
0031
0032
0033 class CF(object):
0034 def __init__(self, args, seqs=[], spawn=None, top=True):
0035 """
0036 :param args:
0037 :param seqs: used beneath top level
0038 :param spawn: only used from top level cf
0039 """
0040
0041 log.info("CF.__init__ START")
0042 self.args = args
0043 self.seqs = seqs
0044 self.top = top
0045
0046 self.af = HisType()
0047 self.mt = MatType()
0048
0049 self.loadevt(seqs)
0050 self.compare()
0051
0052 self.ss = []
0053 self.init_spawn(spawn)
0054 log.info("CF.__init__ DONE")
0055
0056
0057 def init_spawn(self, spawn, flv="seqhis"):
0058 """
0059 Spawn CF for each of the selections, according to
0060 slices of the history sequences.
0061 """
0062 if spawn is None:
0063 return
0064
0065 assert self.top == True, "spawn is only allowed at top level "
0066 totrec = 0
0067 labels = self.seqlabels(spawn, flv)
0068 for label in labels:
0069 seqs = [label]
0070 scf = self.spawn(seqs)
0071 totrec += scf.nrec()
0072 self.ss.append(scf)
0073 pass
0074 self.totrec = totrec
0075
0076 def spawn(self, seqs):
0077 scf = CF(self.args, seqs, spawn=None, top=False)
0078 scf.parent = self
0079 scf.his = self.his
0080 scf.mat = self.mat
0081 return scf
0082
0083 def __repr__(self):
0084 return "CF(%s,%s,%s,%s) " % (self.args.tag, self.args.src, self.args.det, repr(self.seqs))
0085
0086 def dump_ranges(self, i):
0087 log.info("%s : dump_ranges %s " % (repr(self), i) )
0088
0089 a = self.a
0090 b = self.b
0091
0092 ap = a.rpost_(i)
0093 ar = vnorm(ap[:,:2])
0094 if len(ar)>0:
0095 print " ".join(map(lambda _:"%6.3f" % _, (ar.min(),ar.max())))
0096
0097 bp = b.rpost_(0)
0098 br = vnorm(bp[:,:2])
0099 if len(br)>0:
0100 print " ".join(map(lambda _:"%6.3f" % _, (br.min(),br.max())))
0101
0102 def dump(self):
0103 self.dump_ranges(0)
0104 self.dump_histories()
0105
0106
0107 if __name__ == '__main__':
0108 np.set_printoptions(precision=4, linewidth=200)
0109
0110 args = opticks_main(tag="1", src="torch", det="default")
0111 log.info(" args %s " % repr(args))
0112
0113 seqhis_select = slice(1,2)
0114
0115 try:
0116 cf = CF(tag=args.tag, src=args.src, det=args.det, select=seqhis_select )
0117 except IOError as err:
0118 log.fatal(err)
0119 sys.exit(args.mrc)
0120
0121 cf.dump()
0122