Back to home page

EIC code displayed by LXR

 
 

    


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

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 scan.py
0023 ============
0024 
0025 scan.py is sibling to bench.py : aiming for a cleaner 
0026 and more general approach to metadata presentation 
0027 based on meta.py (rather than the old metadata.py)
0028 
0029 1. finds dated folders beneath the input base directory
0030 2. reads metadata dicts from .json and .ini files in the dated folders
0031 3. dumps some metadata values in date stamp order 
0032 
0033 """
0034 import os, re, logging, sys, argparse
0035 from collections import OrderedDict as odict
0036 import numpy as np
0037 log = logging.getLogger(__name__)
0038 
0039 from opticks.ana.datedfolder import DatedFolder
0040 from opticks.ana.meta import Meta
0041 
0042 
0043 if __name__ == '__main__':
0044     base = sys.argv[1] if len(sys.argv) > 1 else "." 
0045     cmdline = " ".join([os.path.basename(sys.argv[0])]+sys.argv[1:])
0046     print(cmdline)
0047 
0048     dirs, dfolds, dtimes = DatedFolder.find(base)
0049     assert len(dfolds) == len(dtimes) == len(dirs)
0050     print( "dirs : %d  dtimes : %d " % (len(dirs), len(dtimes) ))
0051 
0052 
0053     ## arrange into groups of runs with the same runstamp/datedfolder
0054     assert len(dfolds) == len(dtimes) 
0055     order = sorted(range(len(dfolds)), key=lambda i:dtimes[i])   ## sorted by run datetimes
0056 
0057     dump_ = lambda m,top:"\n".join(map(lambda kv:"  %30s : %s " % (kv[0],kv[1]),m.d[top].items() )) 
0058 
0059     photons_ = lambda m:m["parameters.NumPhotons"]
0060 
0061     q=odict()
0062     q["ok1"] = "OpticksEvent_launch.launch001"
0063     q["ok2"] = "DeltaTime.OPropagator::launch_0"
0064     q["ok3"] = "OpticksEvent_prelaunch.prelaunch000"
0065     q["ok4"] = "DeltaTime.OpSeeder::seedPhotonsFromGenstepsViaOptiX_0"
0066     q["g4"]  = "DeltaTime.CG4::propagate_0"
0067 
0068     for k,v in q.items():
0069         print(" %4s : %s " % (k,v)) 
0070     pass
0071 
0072         
0073     for i in order:
0074         df = dfolds[i] 
0075         dt = dtimes[i] 
0076 
0077         udirs = filter(lambda _:_.endswith(df),dirs)  ## finding all run folders with this datestamp
0078         #print("\n".join(udirs))
0079         if len(udirs) == 0: continue
0080 
0081         mm = [Meta(p, base) for p in udirs]
0082         assert len(mm) == 2, "expecting only two matches datestamp folders containing metadata from geant4 and opticks measurements"
0083 
0084         tag0 = int(mm[0].parentfold)  
0085         tag1 = int(mm[1].parentfold)  
0086 
0087         ok = 0 if tag0 > 0 else 1    # tag sign convention, > 0 for opticks < 0 for geant4 
0088         g4 = 1 if tag1 < 0 else 0
0089         assert ok ^ g4, ( ok, g4, tag0, tag1 )
0090 
0091         #print(mm[ok])
0092         #print(mm[g4])
0093 
0094         nn = list(set(map(photons_, mm)))
0095         assert len(nn) == 1, "expecting all measurements are for the same photon count"
0096         n = nn[0]
0097 
0098         vq = odict()
0099         for k,v in q.items():
0100             vq[k] = float(mm[ok if k.startswith("ok") else g4][v])
0101         pass
0102 
0103         divi_ = lambda num,den:num/den if den != 0 else 0
0104 
0105         vq["g4/ok1"] = divi_(vq["g4"],vq["ok1"])
0106         vq["g4/ok2"] = divi_(vq["g4"],vq["ok2"])
0107 
0108         svq = " ok1:%(ok1)10.4f  ok2:%(ok2)10.4f  g4:%(g4)10.4f   g4/ok1:%(g4/ok1)10.1f  g4/ok2:%(g4/ok2)10.1f   ok3:%(ok3)10.4f ok4:%(ok4)10.4f  " % vq  
0109 
0110         print(" %s   tag0:%-3d tag1:%-3d  n:%-7d     %s     " % (df, tag0, tag1, n, svq  )  )
0111 
0112         #print(dump_(mm[0],"parameters"))
0113         #print(dump_(mm[1],"OpticksEvent_launch"))
0114 
0115         
0116 
0117 
0118 
0119 
0120