Back to home page

EIC code displayed by LXR

 
 

    


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

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 g4gun.py: loads G4Gun event
0023 ===============================
0024 
0025 To create the event use::
0026 
0027    ggv-
0028    ggv-g4gun
0029 
0030 
0031 """
0032 import os, sys, logging, numpy as np
0033 log = logging.getLogger(__name__)
0034 
0035 
0036 from opticks.ana.base import opticks_main
0037 from opticks.ana.evt import Evt
0038 
0039 import matplotlib.pyplot as plt
0040 
0041 
0042 mnavmx_ = lambda _:(np.min(_),np.average(_),np.max(_))
0043 
0044 
0045 def red_gensteps_everywhere_issue(gs):
0046     """
0047     """
0048     post = gs[:,1] 
0049     print post.shape
0050     print post
0051 
0052     npho = gs[:,0,3].view(np.int32)  ## approx half the gs have zero photons ??
0053 
0054     npho_0 = np.count_nonzero(npho == 0)
0055     npho_1 = np.count_nonzero(npho == 1)
0056     npho_2 = np.count_nonzero(npho > 1)
0057 
0058 
0059     cx = np.array(map(mnavmx_, map(np.array, post.T )))
0060     ce = cx[:3,1]
0061     print cx 
0062 
0063     x = post[:,0] - ce[0]
0064     y = post[:,1] - ce[1]
0065     z = post[:,2] - ce[2]
0066     t = post[:,3]
0067 
0068     #s = t < 5
0069     s = npho > 0
0070 
0071     fig = plt.figure()
0072 
0073     ax = fig.add_subplot(221)
0074     ax.hist(x[s], bins=100)
0075     ax.set_yscale('log')
0076 
0077     ax = fig.add_subplot(222)
0078     ax.hist(y[s], bins=100)
0079     ax.set_yscale('log')
0080 
0081     ax = fig.add_subplot(223)
0082     ax.hist(z[s], bins=100)
0083     ax.set_yscale('log')
0084 
0085     ax = fig.add_subplot(224)
0086     ax.hist(t[s], bins=100)
0087     ax.set_yscale('log')
0088     fig.show()
0089 
0090 
0091 
0092 if __name__ == '__main__':
0093 
0094     ok = opticks_main(src="G4Gun", det="G4Gun", tag="-1")
0095 
0096     try:
0097         evt = Evt(tag=ok.tag, src=ok.src, det=ok.det, args=ok)
0098     except IOError as err:
0099         log.fatal(err)
0100         sys.exit(ok.mrc) 
0101     pass
0102 
0103     print evt
0104 
0105     red_gensteps_everywhere_issue(evt.gs)
0106 
0107 
0108 
0109 
0110    
0111