Changeset 13517
- Timestamp:
- 05/02/12 15:12:17 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/pyfact/pyfact.py
r13516 r13517 85 85 baseline_file_name='', 86 86 return_dict = None, 87 do_calibration = True, 88 use_CalFactFits = True): 87 do_calibration = True): 89 88 """ initialize object 90 89 … … 111 110 return_dict = False 112 111 self.return_dict = return_dict 113 self.use_CalFactFits = use_CalFactFits114 112 115 113 self.do_calibration = do_calibration … … 128 126 129 127 # access data file 130 if use_CalFactFits: 131 try: 132 data_file = CalFactFits(data_file_name, calib_file_name) 133 except IOError: 134 print 'problem accessing data file: ', data_file_name 135 raise # stop ! no data 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) 136 160 137 self.data_file = data_file 138 self.data = np.empty( data_file.npix * data_file.nroi, np.float64) 139 data_file.SetNpcaldataPtr(self.data) 140 141 142 self.nroi = data_file.nroi 143 self.npix = data_file.npix 144 self.nevents = data_file.nevents 145 146 # Data per event 147 self.event_id = None 148 self.trigger_type = None 149 self.data = None 150 self.start_cells = None 151 self.board_times = None 152 153 else: 154 try: 155 data_file = FactFits(self.data_file_name) 156 except IOError: 157 print 'problem accessing data file: ', data_file_name 158 raise # stop ! no data 159 160 self.data_file = data_file 161 162 # get basic information about the data file 163 #: region of interest (number of DRS slices read) 164 self.nroi = data_file.GetUInt('NROI') 165 #: number of pixels (should be 1440) 166 self.npix = data_file.GetUInt('NPIX') 167 #: number of events in the data run 168 self.nevents = data_file.GetNumRows() 169 170 # allocate the data memories 171 self.event_id = c_ulong() 172 self.trigger_type = c_ushort() 173 #: 1D array with raw data 174 self.data = np.zeros( self.npix * self.nroi, np.int16 ).reshape(self.npix ,self.nroi) 175 #: slice where drs readout started 176 self.start_cells = np.zeros( self.npix, np.int16 ) 177 #: time when the FAD was triggered, in some strange units... 178 self.board_times = np.zeros( 40, np.int32 ) 179 180 # set the pointers to the data++ 181 data_file.SetPtrAddress('EventNum', self.event_id) 182 data_file.SetPtrAddress('TriggerType', self.trigger_type) 183 data_file.SetPtrAddress('StartCellData', self.start_cells) 184 data_file.SetPtrAddress('Data', self.data) 185 data_file.SetPtrAddress('BoardTime', self.board_times) 186 187 # open the calibration file 188 try: 189 calib_file = FactFits(self.calib_file_name) 190 except IOError: 191 print 'problem accessing calibration file: ', calib_file_name 192 raise 193 #: drs calibration file 194 self.calib_file = calib_file 195 196 baseline_mean = calib_file.GetN('BaselineMean') 197 gain_mean = calib_file.GetN('GainMean') 198 trigger_offset_mean = calib_file.GetN('TriggerOffsetMean') 199 200 self.Nblm = baseline_mean / self.npix 201 self.Ngm = gain_mean / self.npix 202 self.Ntom = trigger_offset_mean / self.npix 203 204 self.blm = np.zeros(baseline_mean, np.float32).reshape(self.npix , self.Nblm) 205 self.gm = np.zeros(gain_mean, np.float32).reshape(self.npix , self.Ngm) 206 self.tom = np.zeros(trigger_offset_mean, np.float32).reshape(self.npix , self.Ntom) 207 208 calib_file.SetPtrAddress('BaselineMean', self.blm) 209 calib_file.SetPtrAddress('GainMean', self.gm) 210 calib_file.SetPtrAddress('TriggerOffsetMean', self.tom) 211 calib_file.GetRow(0) 212 213 # make calibration constants double, so we never need to roll 214 self.blm = np.hstack((self.blm, self.blm)) 215 self.gm = np.hstack((self.gm, self.gm)) 216 self.tom = np.hstack((self.tom, self.tom)) 217 218 self.v_bsl = np.zeros(self.npix) # array of baseline values (all ZERO) 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) 219 193 220 194 def __iter__(self): 221 195 """ iterator """ 222 196 return self 223 197 198 def __add__(self, jump_over): 199 self.data_file.GetRow(jump_over) 200 return self 201 224 202 def next(self): 225 203 """ used by __iter__ """ 226 if self.use_CalFactFits: 227 if self.data_file.GetCalEvent() == False: 228 raise StopIteration 229 else: 230 self.event_id = self.data_file.event_id 231 self.trigger_type = self.data_file.event_triggertype 232 self.start_cells = self.data_file.event_offset 233 self.board_times = self.data_file.event_boardtimes 204 if self.data_file.GetNextRow() == False: 205 raise StopIteration 234 206 else: 235 if self.data_file.GetNextRow() == False: 236 raise StopIteration 237 else: 238 if self.do_calibration == True: 239 self.calibrate_drs_amplitude() 207 if self.do_calibration == True: 208 self.calibrate_drs_amplitude() 240 209 241 210 #print 'nevents = ', self.nevents, 'event_id = ', self.event_id.value … … 248 217 """ load the next event from disk and calibrate it 249 218 """ 250 if self.use_CalFactFits: 251 self.data_file.GetCalEvent() 252 else: 253 self.data_file.GetNextRow() 254 self.calibrate_drs_amplitude() 219 self.data_file.GetNextRow() 220 self.calibrate_drs_amplitude() 255 221 256 222 def calibrate_drs_amplitude(self):
Note:
See TracChangeset
for help on using the changeset viewer.