Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:46

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 cfg4_speedplot.py 
0023 ======================
0024 
0025 
0026 """
0027 import os, logging, numpy as np
0028 log = logging.getLogger(__name__)
0029 
0030 import matplotlib.pyplot as plt
0031 
0032 from opticks.ana.metadata import Metadata
0033 from opticks.ana.catdir import Catdir
0034 
0035 
0036 
0037 def speedplot(cat, tag, a, landscape=False, ylim=None, log_=False):
0038 
0039     if a is None:
0040         log.warning("no metadata skipping")
0041         return   
0042 
0043     nnp = len(np.unique(a.numPhotons))
0044 
0045     if nnp != 1:
0046         log.fatal("numPhotons not unique, cannot compare : nnp %s " % nnp)
0047         log.fatal("Tags and negated counterparts should always have the same photon statistics")
0048         log.fatal(" TO AVOID THIS PROBLEM ADOPT A NEW TAG WHEN CHANGING PHOTON STATS ")
0049 
0050     assert nnp == 1, "Tags and negated counterparts should always have the same photon statistics" 
0051 
0052     mega = float(a.numPhotons[0])/1e6
0053     title = "Propagate times (s) for %3.1fM Photons with %s geometry, tag %s, [max/avg/min]" % (mega, cat, tag)  
0054 
0055     plt.close()
0056     plt.ion()
0057 
0058     fig = plt.figure()
0059     fig.suptitle(title)
0060 
0061     compute = a.flgs & Metadata.COMPUTE != 0 
0062     interop = a.flgs & Metadata.INTEROP != 0 
0063     cfg4    = a.flgs & Metadata.CFG4 != 0 
0064 
0065     msks = [cfg4, interop, compute]
0066     ylims = [[0,60],[0,5],[0,1]]
0067     labels = ["CfGeant4", "Opticks Interop", "Opticks Compute"]
0068 
0069     n = len(msks)
0070     for i, msk in enumerate(msks):
0071 
0072         if landscape: 
0073             ax = fig.add_subplot(1,n,i+1)
0074         else:
0075             ax = fig.add_subplot(n,1,i+1)
0076         pass
0077         d = a[msk]
0078 
0079         t = d.propagate
0080 
0081         mn = t.min()
0082         mx = t.max()
0083         av = np.average(t)        
0084 
0085         label = "%s [%5.2f/%5.2f/%5.2f] " % (labels[i], mx,av,mn)
0086  
0087         loc = "lower right" if i == 0 else "upper right" 
0088 
0089         ax.plot( d.index, d.propagate, "o")
0090         ax.plot( d.index, d.propagate, drawstyle="steps", label=label)
0091 
0092         if log_:
0093             ax.set_yscale("log")
0094 
0095         if ylim is not None:
0096             ax.set_ylim(ylim)
0097         else:
0098             ax.set_ylim(ylims[i])
0099         pass
0100         ax.legend(loc=loc)
0101     pass
0102 
0103 
0104     ax.set_xlabel('All times from: MacBook Pro (2013), NVIDIA GeForce GT 750M 2048 MB (384 cores)')
0105     ax.xaxis.set_label_coords(-0.5, -0.07 )
0106 
0107     plt.show()
0108 
0109 
0110 
0111 
0112 if __name__ == '__main__':
0113     from opticks.ana.main import opticks_main
0114     ok = opticks_main() 
0115 
0116     cat = Catdir(ok.catdir)
0117     a = cat.times(ok.tag)
0118 
0119 
0120 if 1:
0121     speedplot(cat, ok.tag, a, landscape=True, ylim=[0.1, 60], log_=True)
0122     
0123