Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.