1 | #!/usr/bin/python -tti
|
---|
2 | #
|
---|
3 | #
|
---|
4 |
|
---|
5 | from pyfact import RawData
|
---|
6 | import sys
|
---|
7 | from ROOT import TFile, TCanvas, TH2F, TTree, TStyle, TObject
|
---|
8 | import numpy as np
|
---|
9 |
|
---|
10 | data_filename = '/fact/raw/2012/06/06/20120606_116.fits.gz'
|
---|
11 | calib_filename = '/fact/raw/2012/06/06/20120606_112.drs.fits.gz'
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 | run = RawData(data_filename, calib_filename, use_CalFactFits = False, do_calibration = False)
|
---|
16 | offset = run.blm / (2000./4096.)
|
---|
17 | offset = offset.astype(int)
|
---|
18 | roi = run.nroi
|
---|
19 | npix = run.npix
|
---|
20 |
|
---|
21 | rootfile = TFile('test.root', "RECREATE")
|
---|
22 | h = TH2F('h', 'diffs', npix, -0.5, npix-0.5, 2401, -1200.5, 1200.5)
|
---|
23 |
|
---|
24 | bits = np.zeros( roi-1 )
|
---|
25 |
|
---|
26 | for event in run:
|
---|
27 | index = event['event_id'].value
|
---|
28 | print index, '/', run.nevents
|
---|
29 | data = event['data']
|
---|
30 |
|
---|
31 |
|
---|
32 |
|
---|
33 | for pixel in range(npix):
|
---|
34 | sc = event['start_cells'][pixel]
|
---|
35 | data[pixel,:] -= offset[pixel,sc:sc+roi]
|
---|
36 |
|
---|
37 | diffs = np.diff(data[pixel,:])
|
---|
38 |
|
---|
39 | for i,d in enumerate(diffs):
|
---|
40 | if d >= -8 and d <= 7:
|
---|
41 | bits[i] = 4
|
---|
42 | elif d >= -16 and d <= 15:
|
---|
43 | bits[i] = 5
|
---|
44 | elif d >= -32 and d <= 31:
|
---|
45 | bits[i] = 6
|
---|
46 | elif d >= -64 and d <= 63:
|
---|
47 | bits[i] = 7
|
---|
48 | elif d >= -128 and d <= 127:
|
---|
49 | bits[i] = 8
|
---|
50 | elif d >= -256 and d <= 255:
|
---|
51 | bits[i] = 9
|
---|
52 | elif d >= -512 and d <= 511:
|
---|
53 | bits[i] = 10
|
---|
54 | else:
|
---|
55 | bits[i] = 16
|
---|
56 |
|
---|
57 | groups = np.array_split(bits,np.where( np.diff(a)!=0 )[0]+1)
|
---|
58 |
|
---|
59 | cost = 2
|
---|
60 | for group in groups:
|
---|
61 | cost += 2
|
---|
62 | cost += group.sum() / 8
|
---|
63 | if group.sum() % 8 != 0:
|
---|
64 | cost += 1
|
---|
65 |
|
---|
66 | sys.exit(0)
|
---|
67 |
|
---|
68 | for d in diffs:
|
---|
69 | h.Fill(pixel, d)
|
---|
70 |
|
---|
71 | h.Write()
|
---|
72 | rootfile.Close()
|
---|