source: fact/tools/pyscripts/sandbox/dneise/fact_compress/find_groups.py@ 14962

Last change on this file since 14962 was 14216, checked in by neise, 12 years ago
added find groups
  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/python -tti
2#
3#
4
5from pyfact import RawData
6import sys
7from ROOT import TFile, TCanvas, TH2F, TTree, TStyle, TObject
8import numpy as np
9
10data_filename = '/fact/raw/2012/06/06/20120606_116.fits.gz'
11calib_filename = '/fact/raw/2012/06/06/20120606_112.drs.fits.gz'
12
13
14
15run = RawData(data_filename, calib_filename, use_CalFactFits = False, do_calibration = False)
16offset = run.blm / (2000./4096.)
17offset = offset.astype(int)
18roi = run.nroi
19npix = run.npix
20
21rootfile = TFile('test.root', "RECREATE")
22h = TH2F('h', 'diffs', npix, -0.5, npix-0.5, 2401, -1200.5, 1200.5)
23
24bits = np.zeros( roi-1 )
25
26for 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
71h.Write()
72rootfile.Close()
Note: See TracBrowser for help on using the repository browser.