Project

General

Profile

Wiki » plot.py

Adey, David, 12 September 2014 18:38

 
1
import ROOT
2
import sys
3
import binascii
4
import struct
5
import os
6
file = open(sys.argv[1],'rb')
7
size = os.path.getsize(sys.argv[1])
8
print size
9
adcs = ROOT.TH2F("all","all",9000,0,9000,300,-20,280)
10

    
11
wordSize = 4
12
bytes = file.read(wordSize)
13
bin = 0
14
channel = 0
15
flip = 0
16
#for byte in range(0,size,4):
17
"""while bytes != "":
18
	if (bin > 255): # if the last bin has been reached,
19
		bin = 0 # reset and increment channel
20
		channel += 1
21
		#hist = run.getChannelRun(channel).adcHist
22
	word = struct.unpack('i',bytes)[0]
23
	print bytes, word
24
	bytes = file.read(wordSize) # read the next word
25
	if (word): # if the bin value is not zero, add to the histogram
26
		adcs.Fill(channel, bin, word)
27
		
28
		bin += 1
29
		print channel, bin
30

    
31
"""
32

    
33
f =  open(sys.argv[1], "rb")
34
byte = f.read(4)
35
while byte:
36
	#print int(byte)
37
	word = struct.unpack('I',byte)[0]
38
	#print word
39
	adcs.Fill(channel,bin,word)
40
	bin += 1
41
	if (bin == 256):
42
		bin = 0
43
		channel += 1
44
        # Do stuff with byte.
45
	if (channel > 2000 and channel < 3000 and word > 0):
46
		print channel, bin, word
47
	#print channel, bin
48
        byte = f.read(4)
49

    
50
c = ROOT.TCanvas()
51
adcs.Draw()
52
c.SaveAs("adcs.C")
(5-5/15)