source: fact/tools/pyscripts/examples/CalFactFitsPerformance.py@ 17695

Last change on this file since 17695 was 13515, checked in by kraehenb, 13 years ago
Renamed test scripts and Class calls within to new naming standard.
File size: 3.1 KB
Line 
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
10datafilename = '/fact/raw/2012/04/17/20120417_004.fits.gz'
11calibfilename = '/fact/raw/2012/04/17/20120417_003.drs.fits.gz'
12
13import numpy as np
14import itertools
15
16from ROOT import gSystem
17gSystem.Load("calfactfits_h.so")
18from ROOT import *
19print "Testing object creation: "
20caltest = CalFactFits(datafilename,calibfilename)
21npcalevent = np.empty( caltest.npix * caltest.nroi, np.float64) #.reshape(caltest.npix ,caltest.nroi)
22caltest.SetNpcaldataPtr(npcalevent)
23
24print "Common variables:"
25print "ROI: ", caltest.nroi
26print "#Pix: ", caltest.npix
27print "Number of events: ", caltest.nevents
28print
29
30print "Information per Event:"
31caltest.GetCalEvent()
32print "Event ID: ", caltest.event_id
33print "Trigger type: ", caltest.event_triggertype
34print "Uncalibrated data: ", caltest.event_data
35print "Calibrated data: ", caltest.npcaldata
36print "Board times: ", caltest.event_boardtimes
37print "Trigger offsets: ", caltest.event_offset
38print
39
40print "Examples of other information"
41print "Calibfile ROI: ", caltest.calib_nroi
42print "Column size BaselineMean: ", caltest.calibfile.GetN("BaselineMean")
43print "Datafile ROI: ", caltest.data_nroi
44print "Data: ", caltest.datafile.GetN("Data")
45print "StartCellData: ", caltest.datafile.GetN("StartCellData")
46print "Direct datafile access: ", caltest.datafile.GetN("StartCellData")
47print
48print "Columns of the datafile: "
49caltest.datafile.PrintColumns()
50
51def offsum(x,y):
52 return np.sum(npcalevent[x,y+5:y+15])
53vecoffsum = np.vectorize(offsum) #specifying otypes=[np.float/double] does not improve speed
54
55while 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
78del caltest
Note: See TracBrowser for help on using the repository browser.