#!/usr/bin/python

import ROOT
import numpy as np

fn = "tree.root"
f = ROOT.TFile(fn, "read")
t = f.Get("tcal")

points_x, points_y, points_z = [],[],[]

for x in xrange(16, 16+16):
	for y in xrange(16, 16+16):
		t.Draw("avg_pc_data[0][0]["+str(x)+"]["+str(y)+"]:pc_threshold[0][0][0][0]", "", "goff")
		points_z.append(np.array(np.frombuffer(t.GetV1(), dtype=np.float64, count=t.GetSelectedRows())))
		points_x.append(np.array(np.frombuffer(t.GetV2(), dtype=np.float64, count=t.GetSelectedRows())))
		points_y.append(np.ones(points_x[-1].size)*(len(points_z)-1))

print "Entries:", len(points_z)

points_x = np.array(points_x, dtype=np.float64)
points_y = np.array(points_y, dtype=np.float64)
points_z = np.array(points_z, dtype=np.float64)

print points_x.size, points_y.size, points_z.size
print points_x, points_y, points_z

g2d = ROOT.TGraph2D(points_x.size, points_x.ravel(), points_y.ravel(), points_z.ravel())
g2d.SetLineWidth(3)
g2d.SetMarkerSize(3)

c1 = ROOT.TCanvas()
g2d.Draw("pcol line")
c1.Modified()
c1.Update()


rep = ''
while not rep in [ 'q', 'Q' ]:
	ROOT.gSystem.ProcessEvents()
	rep = raw_input('enter "q" to quit: ')
	if 1 < len(rep):
		rep = rep[0]
