Changeset 13518
- Timestamp:
- 05/02/12 15:56:50 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/pyfact/pyfact.py
r13517 r13518 1 #!/usr/bin/python -tt i1 #!/usr/bin/python -tt 2 2 # 3 3 # Werner Lustermann, Dominik Neise … … 15 15 # having it in PYTHONPATH is *not* sufficient 16 16 gSystem.Load('factfits_h.so') 17 gSystem.Load('calfactfits_h.so') 17 18 from ROOT import * 18 19 … … 85 86 baseline_file_name='', 86 87 return_dict = None, 87 do_calibration = True): 88 do_calibration = True, 89 use_CalFactFits = True): 88 90 """ initialize object 89 91 … … 110 112 return_dict = False 111 113 self.return_dict = return_dict 114 self.use_CalFactFits = use_CalFactFits 112 115 113 116 self.do_calibration = do_calibration … … 126 129 127 130 # access data file 128 try: 129 data_file = FactFits(self.data_file_name) 130 except IOError: 131 print 'problem accessing data file: ', data_file_name 132 raise # stop ! no data 133 #: data file (fits object) 134 self.data_file = data_file 135 136 # get basic information about the data file 137 #: region of interest (number of DRS slices read) 138 self.nroi = data_file.GetUInt('NROI') 139 #: number of pixels (should be 1440) 140 self.npix = data_file.GetUInt('NPIX') 141 #: number of events in the data run 142 self.nevents = data_file.GetNumRows() 143 144 # allocate the data memories 145 self.event_id = c_ulong() 146 self.trigger_type = c_ushort() 147 #: 1D array with raw data 148 self.data = np.zeros( self.npix * self.nroi, np.int16 ).reshape(self.npix ,self.nroi) 149 #: slice where drs readout started 150 self.start_cells = np.zeros( self.npix, np.int16 ) 151 #: time when the FAD was triggered, in some strange units... 152 self.board_times = np.zeros( 40, np.int32 ) 153 154 # set the pointers to the data++ 155 data_file.SetPtrAddress('EventNum', self.event_id) 156 data_file.SetPtrAddress('TriggerType', self.trigger_type) 157 data_file.SetPtrAddress('StartCellData', self.start_cells) 158 data_file.SetPtrAddress('Data', self.data) 159 data_file.SetPtrAddress('BoardTime', self.board_times) 131 if use_CalFactFits: 132 try: 133 data_file = CalFactFits(data_file_name, calib_file_name) 134 except IOError: 135 print 'problem accessing data file: ', data_file_name 136 raise # stop ! no data 160 137 161 # open the calibration file 162 try: 163 calib_file = FactFits(self.calib_file_name) 164 except IOError: 165 print 'problem accessing calibration file: ', calib_file_name 166 raise 167 #: drs calibration file 168 self.calib_file = calib_file 169 170 baseline_mean = calib_file.GetN('BaselineMean') 171 gain_mean = calib_file.GetN('GainMean') 172 trigger_offset_mean = calib_file.GetN('TriggerOffsetMean') 173 174 self.Nblm = baseline_mean / self.npix 175 self.Ngm = gain_mean / self.npix 176 self.Ntom = trigger_offset_mean / self.npix 177 178 self.blm = np.zeros(baseline_mean, np.float32).reshape(self.npix , self.Nblm) 179 self.gm = np.zeros(gain_mean, np.float32).reshape(self.npix , self.Ngm) 180 self.tom = np.zeros(trigger_offset_mean, np.float32).reshape(self.npix , self.Ntom) 181 182 calib_file.SetPtrAddress('BaselineMean', self.blm) 183 calib_file.SetPtrAddress('GainMean', self.gm) 184 calib_file.SetPtrAddress('TriggerOffsetMean', self.tom) 185 calib_file.GetRow(0) 186 187 # make calibration constants double, so we never need to roll 188 self.blm = np.hstack((self.blm, self.blm)) 189 self.gm = np.hstack((self.gm, self.gm)) 190 self.tom = np.hstack((self.tom, self.tom)) 191 192 self.v_bsl = np.zeros(self.npix) # array of baseline values (all ZERO) 138 self.data_file = data_file 139 self.data = np.empty( data_file.npix * data_file.nroi, np.float64) 140 data_file.SetNpcaldataPtr(self.data) 141 self.data = self.data.reshape( data_file.npix, data_file.nroi ) 142 self.acal_data = self.data 143 144 self.nroi = data_file.nroi 145 self.npix = data_file.npix 146 self.nevents = data_file.nevents 147 148 # Data per event 149 self.event_id = None 150 self.trigger_type = None 151 self.start_cells = None 152 self.board_times = None 153 154 else: 155 try: 156 data_file = FactFits(self.data_file_name) 157 except IOError: 158 print 'problem accessing data file: ', data_file_name 159 raise # stop ! no data 160 161 self.data_file = data_file 162 163 # get basic information about the data file 164 #: region of interest (number of DRS slices read) 165 self.nroi = data_file.GetUInt('NROI') 166 #: number of pixels (should be 1440) 167 self.npix = data_file.GetUInt('NPIX') 168 #: number of events in the data run 169 self.nevents = data_file.GetNumRows() 170 171 # allocate the data memories 172 self.event_id = c_ulong() 173 self.trigger_type = c_ushort() 174 #: 1D array with raw data 175 self.data = np.zeros( self.npix * self.nroi, np.int16 ).reshape(self.npix ,self.nroi) 176 #: slice where drs readout started 177 self.start_cells = np.zeros( self.npix, np.int16 ) 178 #: time when the FAD was triggered, in some strange units... 179 self.board_times = np.zeros( 40, np.int32 ) 180 181 # set the pointers to the data++ 182 data_file.SetPtrAddress('EventNum', self.event_id) 183 data_file.SetPtrAddress('TriggerType', self.trigger_type) 184 data_file.SetPtrAddress('StartCellData', self.start_cells) 185 data_file.SetPtrAddress('Data', self.data) 186 data_file.SetPtrAddress('BoardTime', self.board_times) 187 188 # open the calibration file 189 try: 190 calib_file = FactFits(self.calib_file_name) 191 except IOError: 192 print 'problem accessing calibration file: ', calib_file_name 193 raise 194 #: drs calibration file 195 self.calib_file = calib_file 196 197 baseline_mean = calib_file.GetN('BaselineMean') 198 gain_mean = calib_file.GetN('GainMean') 199 trigger_offset_mean = calib_file.GetN('TriggerOffsetMean') 200 201 self.Nblm = baseline_mean / self.npix 202 self.Ngm = gain_mean / self.npix 203 self.Ntom = trigger_offset_mean / self.npix 204 205 self.blm = np.zeros(baseline_mean, np.float32).reshape(self.npix , self.Nblm) 206 self.gm = np.zeros(gain_mean, np.float32).reshape(self.npix , self.Ngm) 207 self.tom = np.zeros(trigger_offset_mean, np.float32).reshape(self.npix , self.Ntom) 208 209 calib_file.SetPtrAddress('BaselineMean', self.blm) 210 calib_file.SetPtrAddress('GainMean', self.gm) 211 calib_file.SetPtrAddress('TriggerOffsetMean', self.tom) 212 calib_file.GetRow(0) 213 214 # make calibration constants double, so we never need to roll 215 self.blm = np.hstack((self.blm, self.blm)) 216 self.gm = np.hstack((self.gm, self.gm)) 217 self.tom = np.hstack((self.tom, self.tom)) 218 219 self.v_bsl = np.zeros(self.npix) # array of baseline values (all ZERO) 193 220 194 221 def __iter__(self): 195 222 """ iterator """ 196 223 return self 197 198 def __add__(self, jump_over): 199 self.data_file.GetRow(jump_over) 200 return self 201 224 202 225 def next(self): 203 226 """ used by __iter__ """ 204 if self.data_file.GetNextRow() == False: 205 raise StopIteration 206 else: 207 if self.do_calibration == True: 208 self.calibrate_drs_amplitude() 227 if self.use_CalFactFits: 228 if self.data_file.GetCalEvent() == False: 229 raise StopIteration 230 else: 231 self.event_id = self.data_file.event_id 232 self.trigger_type = self.data_file.event_triggertype 233 self.start_cells = self.data_file.event_offset 234 self.board_times = self.data_file.event_boardtimes 235 #self.acal_data = self.data.copy().reshape(self.data_file.npix, self.data_file.nroi) 236 else: 237 if self.data_file.GetNextRow() == False: 238 raise StopIteration 239 else: 240 if self.do_calibration == True: 241 self.calibrate_drs_amplitude() 209 242 210 243 #print 'nevents = ', self.nevents, 'event_id = ', self.event_id.value … … 217 250 """ load the next event from disk and calibrate it 218 251 """ 219 self.data_file.GetNextRow() 220 self.calibrate_drs_amplitude() 252 if self.use_CalFactFits: 253 self.data_file.GetCalEvent() 254 else: 255 self.data_file.GetNextRow() 256 self.calibrate_drs_amplitude() 221 257 222 258 def calibrate_drs_amplitude(self): … … 802 838 803 839 for event in run: 804 print 'ev ', event['event_id'] .value, 'data[0,0] = ', event['acal_data'][0,0], 'start_cell[0] = ', event['start_cells'][0], 'trigger type = ', event['trigger_type']805 if run.event_id .value== nevents:806 840 print 'ev ', event['event_id'], 'data[0,0] = ', event['acal_data'][0,0], 'start_cell[0] = ', event['start_cells'][0], 'trigger type = ', event['trigger_type'] 841 if run.event_id == nevents: 842 break 807 843 808 844 if __name__ == '__main__': … … 813 849 print 'in order to test the SlowData classe please use:', sys.argv[0], 'fits-file-name' 814 850 _test_iter(10) 851 852 815 853 else: 816 854 print 'showing test of SlowData class'
Note:
See TracChangeset
for help on using the changeset viewer.