1 | #!/usr/bin/python -tt
|
---|
2 | # ********************************
|
---|
3 | # Test script for the CalFactFits class
|
---|
4 | #
|
---|
5 | # written by Thomas Kraehenbuehl, ETH Zurich
|
---|
6 | # tpk@phys.ethz.ch, +41 44 633 3973
|
---|
7 | # April 2012
|
---|
8 | # ********************************
|
---|
9 |
|
---|
10 | datafilename = '/fact/raw/2012/04/17/20120417_004.fits.gz'
|
---|
11 | calibfilename = '/fact/raw/2012/04/17/20120417_003.drs.fits.gz'
|
---|
12 |
|
---|
13 | import numpy as np
|
---|
14 | import itertools
|
---|
15 |
|
---|
16 | from ROOT import gSystem
|
---|
17 | gSystem.Load("calfactfits_h.so")
|
---|
18 | from ROOT import *
|
---|
19 | print "Testing object creation: "
|
---|
20 | caltest = CalFactFits(datafilename,calibfilename)
|
---|
21 | npcalevent = np.empty( caltest.npix * caltest.nroi, np.float64) #.reshape(caltest.npix ,caltest.nroi)
|
---|
22 | caltest.SetNpcaldataPtr(npcalevent)
|
---|
23 |
|
---|
24 | print "Common variables:"
|
---|
25 | print "ROI: ", caltest.nroi
|
---|
26 | print "#Pix: ", caltest.npix
|
---|
27 | print "Number of events: ", caltest.nevents
|
---|
28 | print
|
---|
29 |
|
---|
30 | print "Information per Event:"
|
---|
31 | caltest.GetCalEvent()
|
---|
32 | print "Event ID: ", caltest.event_id
|
---|
33 | print "Trigger type: ", caltest.event_triggertype
|
---|
34 | print "Uncalibrated data: ", caltest.event_data
|
---|
35 | print "Calibrated data: ", caltest.npcaldata
|
---|
36 | print "Board times: ", caltest.event_boardtimes
|
---|
37 | print "Trigger offsets: ", caltest.event_offset
|
---|
38 | print
|
---|
39 |
|
---|
40 | print "Examples of other information"
|
---|
41 | print "Calibfile ROI: ", caltest.calib_nroi
|
---|
42 | print "Column size BaselineMean: ", caltest.calibfile.GetN("BaselineMean")
|
---|
43 | print "Datafile ROI: ", caltest.data_nroi
|
---|
44 | print "Data: ", caltest.datafile.GetN("Data")
|
---|
45 | print "StartCellData: ", caltest.datafile.GetN("StartCellData")
|
---|
46 | print "Direct datafile access: ", caltest.datafile.GetN("StartCellData")
|
---|
47 | print
|
---|
48 | print "Columns of the datafile: "
|
---|
49 | caltest.datafile.PrintColumns()
|
---|
50 |
|
---|
51 | def offsum(x,y):
|
---|
52 | return np.sum(npcalevent[x,y+5:y+15])
|
---|
53 | vecoffsum = np.vectorize(offsum) #specifying otypes=[np.float/double] does not improve speed
|
---|
54 |
|
---|
55 | while caltest.GetCalEvent():
|
---|
56 | if caltest.event_id>30:
|
---|
57 | break
|
---|
58 | npcalevent = npcalevent.reshape((caltest.npix, caltest.nroi))
|
---|
59 | npthr = npcalevent>2.5 #true if above threshold
|
---|
60 | npthr = npthr[:,1:-14] * np.logical_not(npthr[:,:-15]) #only true for the zero crossings, shape (1400,285) [smaller due to necessary integration range]
|
---|
61 | # print [(x,y) for x,y in zip(npthr.nonzero()[0],npthr.nonzero()[1])] #print the coordinates, range 0-1399,0-284
|
---|
62 |
|
---|
63 | integrals = []
|
---|
64 | #Various versions to get the integral, all with approximately the same miserable speed (3 Hz), except for the last one (vectorized function) with ~4.3 Hz
|
---|
65 | #Missing: add deadtime after an integration, remove start & end of the array
|
---|
66 | # integrals = [np.sum(npcalevent[x,y+5:y+15]) for x,y in np.transpose(npthr.nonzero())]
|
---|
67 | # integrals = [np.sum(npcalevent[x,y+5:y+15]) for x,y in zip(npthr.nonzero()[0],npthr.nonzero()[1])]
|
---|
68 | # integrals = [np.sum(npcalevent[x,y+5:y+15]) for x,y in itertools.izip(npthr.nonzero()[0],npthr.nonzero()[1])]
|
---|
69 | # integrals = map((lambda index_a,index_b: np.sum(npcalevent[index_a,index_b+5:index_b+15])),npthr.nonzero()[0],npthr.nonzero()[1])
|
---|
70 | integrals = vecoffsum(npthr.nonzero()[0],npthr.nonzero()[1])
|
---|
71 |
|
---|
72 | # print len(integrals)
|
---|
73 | # for i in range(10):
|
---|
74 | # print i, npcalevent[0,i], integrals[i]
|
---|
75 | # print caltest.event_id, caltest.event_triggertype, caltest.event_caldata[10]
|
---|
76 | # pass
|
---|
77 |
|
---|
78 | del caltest
|
---|