source: fact/tools/pyscripts/sandbox/kraehenb/calfits.h@ 13397

Last change on this file since 13397 was 13396, checked in by kraehenb, 12 years ago
[In development] Wrapper class for fits.h or pyfits.h Provides fast access to calibrated events of FACT raw data.
File size: 3.5 KB
Line 
1//********************************
2//
3// Class Calfits
4// Wrapper class for fits.h or pyfits.h
5// Provides fast access to calibrated events of FACT raw files
6//
7// written by Thomas Kraehenbuehl, ETH Zurich
8// tpk@phys.ethz.ch, +41 44 633 3973
9// April 2012
10//
11//********************************
12//
13// Compilation:
14// ...
15//
16// Usage in Python:
17// ...handles etc...
18//
19//********************************
20
21//ToDo: Code aufräumen, ToDo's abarbeiten, alle Event-Parameter zugänglich, shared library creation debuggen
22
23#include <cstdio>
24#include <vector>
25#include <string>
26#include "pyfits.h"
27
28class CalFits
29{
30public:
31 //No standard constructor CalFits()!
32
33 //Direct handlers of the files
34 fits datafile, calibfile; //Class name should be PyFits or better FactPyFits...
35
36 //Calibration variables
37 UInt_t calib_nroi, calib_npix;
38 vector<float> calib_basemean;
39 vector<float> calib_gainmean;
40 vector<float> calib_triggeroffsetmean;
41 //ToDo: use arrays of size 1440x1024 (x2 for wrap-arounds) and read all variables into those
42
43 //Data variables
44 UInt_t data_nroi, data_npix, data_ndata;
45
46 //Common variables
47 UInt_t nroi, npix, nevents;
48
49 //Event variables
50 UInt_t data_eventid;
51 vector<int16_t> data_data;
52 vector<int16_t> data_offset;
53
54 //Vector for calibrated event
55 vector<float> calevent;
56
57 CalFits(const string &datafilename, const string &calibfilename) //Construct with two filenames
58 : datafile(datafilename),
59 calibfile(calibfilename)
60 {
61 //Read basic parameters of the two files
62 std::cout << "...Reading basic file parameters..." << std::endl;
63 calib_nroi = calibfile.GetUInt("NROI");
64 calib_npix = calibfile.GetUInt("NPIX");
65 data_nroi = datafile.GetUInt("NROI");
66 data_npix = datafile.GetUInt("NPIX");
67 nevents = datafile.GetNumRows();
68 data_ndata = datafile.GetN("Data");
69
70 //ToDo: check nroi*npix = ndata, calib_nroi=data_nroi, calib_npix=data_npix
71
72 //Read the calibration data
73 std::cout << "...Reading calibration data..." << std::endl;
74 calib_basemean.resize(calibfile.GetN("BaselineMean"),0);
75 calibfile.SetVecAddress("BaselineMean", calib_basemean);
76 calib_gainmean.resize(calibfile.GetN("GainMean"),0);
77 calibfile.SetVecAddress("GainMean", calib_gainmean);
78 calib_triggeroffsetmean.resize(calibfile.GetN("TriggerOffsetMean"),0);
79 calibfile.SetVecAddress("TriggerOffsetMean", calib_triggeroffsetmean);
80 calibfile.GetRow(0);
81
82 //Set the data vectors
83 std::cout << "...Setting datafile pointers..." << std::endl;
84 datafile.SetRefAddress("EventNum", data_eventid);
85 data_data.resize(data_ndata,0);
86 datafile.SetVecAddress("Data", data_data);
87 calevent.resize(data_ndata,0);
88 data_offset.resize(datafile.GetN("StartCellData"),0);
89 datafile.SetVecAddress("StartCellData", data_offset);
90 }
91
92 //double* GetCalEvent() { }
93 int GetCalEvent()
94 {
95 if(datafile.GetNextRow() == false) {
96 std::cout << "Last event reached..." << std::endl;
97 //ToDo: raise exception or stop or whatever GetNextRow does
98 }
99 else {
100 UInt_t drs_calib_offset;
101 for(UInt_t pixel=0;pixel<data_npix;pixel++) {
102 for(UInt_t slice=0;slice<data_nroi;slice++) {
103 //ToDo: replace 1024 by column size/npix
104 drs_calib_offset = (slice+data_offset[pixel])%1024;
105 calevent[pixel*data_nroi+slice] = float((data_data[pixel*data_nroi+slice]*2000./4096.-calib_basemean[pixel*1024+drs_calib_offset]-calib_triggeroffsetmean[pixel*calib_nroi+slice])/calib_gainmean[pixel*1024+drs_calib_offset]*1907.35);
106 //Note: data_nroi=calib_nroi
107 }
108 }
109 }
110 return 0;
111 }
112};
Note: See TracBrowser for help on using the repository browser.