Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:50:27

0001 #!/usr/bin/env python
0002 """
0003 U4Debug.py
0004 ============
0005 
0006 Comparing C and S steps between opticksMode
0007 
0008 opticksMode:0
0009     as if there is no Opticks there
0010 
0011 opticksMode:1
0012     only GPU propagation, CPU photon generation is skipped
0013     (NB because this changes the Geant4 random consumption the C+S steps will
0014     not match those obtained wih opticksMode 0)
0015 
0016 opticksMode:3
0017     both CPU and GPU propagations, the CPU ones should be the same as opticksMode:0
0018     (NB because the Geant4 random consumption of the C+S steps is unchanged
0019     there should be an exact match between opticksMode 0 and 3)
0020 
0021 
0022 """
0023 import os, numpy as np
0024 from opticks.ana.fold import Fold
0025 
0026 class U4Debug(object):
0027     @classmethod
0028     def Create(cls, rel, base, symbol):
0029         f = Fold.Load(base, rel, symbol=symbol)
0030         return None if f is None else cls(f, rel=rel)        
0031 
0032     def __init__(self, f, rel):
0033         self.rel = rel
0034         self.f = f 
0035 
0036         c = f.U4Cerenkov_Debug.reshape(-1,8) 
0037         s = f.U4Scintillation_Debug.reshape(-1,8) 
0038         h = f.U4Hit_Debug.reshape(-1,4) 
0039         g = f.gsl.reshape(-1,4) if hasattr(getattr(f,'gsl', None),'shape') else None
0040 
0041         self.c = c 
0042         self.s = s 
0043         self.h = h 
0044         self.g = g
0045 
0046     def __str__(self):
0047         f = self.f
0048         return repr(f)
0049 
0050     def __repr__(self):
0051         rel = self.rel
0052         c = self.c 
0053         s = self.s 
0054         h = self.h 
0055         g = self.g 
0056         gs = str(g.shape) if not g is None else "-"
0057         return "%20s c %10s s %10s h %10s g %10s " % (rel, str(c.shape), str(s.shape), str(h.shape), gs) 
0058  
0059 
0060 if __name__ == '__main__':
0061     base = "/tmp/u4debug"
0062 
0063     x00 = U4Debug.Create("ntds0/000", symbol="x00", base=base)
0064     x01 = U4Debug.Create("ntds0/001", symbol="x01", base=base)
0065 
0066     x10 = U4Debug.Create("ntds1/000", symbol="x10", base=base)
0067     x11 = U4Debug.Create("ntds1/001", symbol="x11", base=base)
0068  
0069     x30 = U4Debug.Create("ntds3/000", symbol="x30", base=base)
0070     x31 = U4Debug.Create("ntds3/001", symbol="x31", base=base)
0071      
0072     if not x00 is None and not x30 is None:
0073         assert np.all( x00.c == x30.c )
0074         assert np.all( x00.s == x30.s )
0075     else:
0076         print("one of x00 or x30 is None")
0077     pass
0078     if not x01 is None and not x31 is None:
0079         assert np.all( x01.c == x31.c )
0080         assert np.all( x01.s == x31.s )
0081     else:
0082         print("one of x01 or x31 is None")
0083     pass
0084     ## hit records dont match as gensteps are not collected for opticksMode 0 changing hit indices
0085     #assert np.all( x00.h == x30.h )  
0086     #assert np.all( x01.h == x31.h )
0087     pass
0088 
0089