Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:49:16

0001 #!/usr/bin/env python
0002 #
0003 # Copyright (c) 2019 Opticks Team. All Rights Reserved.
0004 #
0005 # This file is part of Opticks
0006 # (see https://bitbucket.org/simoncblyth/opticks).
0007 #
0008 # Licensed under the Apache License, Version 2.0 (the "License"); 
0009 # you may not use this file except in compliance with the License.  
0010 # You may obtain a copy of the License at
0011 #
0012 #   http://www.apache.org/licenses/LICENSE-2.0
0013 #
0014 # Unless required by applicable law or agreed to in writing, software 
0015 # distributed under the License is distributed on an "AS IS" BASIS, 
0016 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0017 # See the License for the specific language governing permissions and 
0018 # limitations under the License.
0019 #
0020 
0021 """
0022 nopstep_viz_debug.py: Creates fake nopstep (non-photon step) for visualization debugging
0023 ============================================================================================
0024 
0025 See okc/OpticksEvent::setFakeNopstepPath
0026 
0027 
0028 """
0029 import os, logging
0030 import numpy as np
0031 
0032 import matplotlib.pyplot as plt
0033 
0034 from opticks.ana.base import opticks_environment
0035 from opticks.ana.nload import A
0036 from opticks.ana.debug.CGDMLDetector import CGDMLDetector
0037 
0038 def make_fake_nopstep(tk):
0039     """
0040     :param tk: dict of dict containing track parameters
0041     :return nop:  numpy array of shape (tot n, 4, 4)
0042                   containing time and global positions in [:,0] 
0043 
0044     For each track
0045 
0046     *n* 
0047           number of time steps 
0048     *tmin*
0049           ns
0050     *tmax*
0051           ns
0052     *fn*
0053           parametric equation returning local coordinate [0,1,2] from time input           
0054     *frame*
0055           4x4 homogenous matrix applied to the local trajectory coordinates
0056           to get global coordinates
0057 
0058     """
0059     traj = {}
0060     ftraj = {}
0061 
0062     for k in tk.keys():
0063 
0064         tkd = tk[k]
0065         n = tkd["n"]
0066         fn = tkd["fn"]
0067         mat = tkd["frame"]
0068 
0069         traj[k] = np.ones([n, 4], dtype=np.float32)
0070         t = np.linspace(tkd["tmin"],tkd["tmax"], n)
0071 
0072         for p in range(n):
0073             traj[k][p,:3] = fn(t[p])    
0074         pass
0075 
0076         ftraj[k] = np.dot(traj[k], mat)   
0077         ftraj[k][:,3] = t 
0078     pass 
0079 
0080     combi = np.vstack(ftraj.values())
0081     nop = np.zeros([combi.shape[0], 4, 4], dtype=np.float32)
0082     nop[:,0] = combi 
0083 
0084     return nop
0085 
0086 
0087 
0088 if __name__ == '__main__':
0089     logging.basicConfig(level=logging.INFO)
0090     opticks_environment()
0091 
0092     frame = 3153
0093 
0094     det = CGDMLDetector()
0095     mat = det.getGlobalTransform(frame)
0096     print "mat %s " % repr(mat)
0097 
0098     tk = {} 
0099     tk["+x"] = dict(n=10,frame=mat,tmin=0,tmax=10,fn=lambda t:np.array([0,0,0]) + t*np.array([100,0,0]))
0100     tk["-x"] = dict(n=20,frame=mat,tmin=1,tmax=20,fn=lambda t:np.array([0,0,0]) + t*np.array([-100,0,0]))
0101     tk["+y"] = dict(n=10,frame=mat,tmin=0,tmax=10,fn=lambda t:np.array([0,0,0]) + t*np.array([0,100,0]))
0102     tk["-y"] = dict(n=20,frame=mat,tmin=1,tmax=20,fn=lambda t:np.array([0,0,0]) + t*np.array([0,-100,0]))
0103     tk["+z"] = dict(n=10,frame=mat,tmin=0,tmax=10,fn=lambda t:np.array([0,0,0]) + t*np.array([0,0,100]))
0104     tk["-z"] = dict(n=20,frame=mat,tmin=1,tmax=20,fn=lambda t:np.array([0,0,0]) + t*np.array([0,0,-100]))
0105 
0106 
0107     nop = make_fake_nopstep(tk)
0108 
0109     path = "$TMP/fake_nopstep.npy"
0110     np.save(os.path.expandvars(path), nop)
0111  
0112     a = np.load(os.path.expandvars(path))
0113 
0114