Skip to content

Instantly share code, notes, and snippets.

@akira-okumura
Created May 31, 2020 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akira-okumura/7a65f1516c7ac59c2cd85d6113d456ac to your computer and use it in GitHub Desktop.
Save akira-okumura/7a65f1516c7ac59c2cd85d6113d456ac to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import ROOT
def readSK(fname, batch=False):
global nt
nt = ROOT.TNtuple('nt', 'nt', 'ch:pe:t:x:y:z')
nt.ReadFile(fname)
if not batch:
nt.SetMarkerStyle(20)
nt.SetMarkerSize(0.5)
nt.Draw("z:y:x:pe", "", "col")
return
maxpe = nt.GetMaximum('pe')
for i in range(nt.GetEntries()):
nt.GetEntry(i)
# LDraw axes (+X, +Z, -Y)
pe, x, z, y = nt.pe, nt.x, nt.y, -nt.z
# LDR colors
# https://www.ldraw.org/article/547.html
colors = [33, 44, 36, 38, 54, 46, 47]
ncolors = len(colors)
color = colors[int(pe / (maxpe * 1.001 / ncolors))]
shape = '4073.dat'
rot = ROOT.TRotation()
if y == -1810: # top
rot.RotateZ(ROOT.TMath.Pi())
elif y == 1810: # bottom
pass # keep upward
else: # side
rot.RotateZ(-ROOT.TMath.Pi() / 2)
rot.RotateY(-ROOT.TMath.ATan2(z, x))
Rxx, Rxy, Rxz = rot.XX(), rot.XY(), rot.XZ()
Ryx, Ryy, Ryz = rot.YX(), rot.YY(), rot.YZ()
Rzx, Rzy, Rzz = rot.ZX(), rot.ZY(), rot.ZZ()
print('1 %d %f %f %f %f %f %f %f %f %f %f %f %f %s' % (color, x / 3, y / 3, z / 3, Rxx, Rxy, Rxz, Ryx, Ryy, Ryz, Rzx, Rzy, Rzz, shape))
if __name__ == '__main__':
import sys
readSK(sys.argv[1], True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment