- Timestamp:
- 06/08/12 15:31:05 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/pyfact/pyfact.py
r13815 r14118 29 29 the second should be an amplitude calibration file(\*.drs.fits.gz) 30 30 """ 31 32 self.__module__ = 'pyfact' 33 31 34 # sanity check for input 32 35 if type(filelist) != type(list()): … … 72 75 """ raw data access and calibration 73 76 77 class is **iterable** 78 74 79 - open raw data file and drs calibration file 75 80 - performs amplitude calibration … … 83 88 84 89 def __init__(self, data_file_name, calib_file_name, 85 user_action_calib=lambda acal_data, data, blm, tom, gm, scells, nroi: None,86 90 baseline_file_name='', 87 91 return_dict = True, 92 use_CalFactFits = True, 88 93 do_calibration = True, 89 use_CalFactFits = True): 90 """ initialize object 91 92 open data file and calibration data file 93 get basic information about the data in data_file_name 94 allocate buffers for data access 95 96 data_file_name : fits or fits.gz file of the data including the path 97 calib_file_name : fits or fits.gz file containing DRS calibration data 98 baseline_file_name : npy file containing the baseline values 94 user_action_calib=lambda acal_data, data, blm, tom, gm, scells, nroi: None): 95 """ -constructor- 96 97 - open data file and calibration data file 98 - get basic information about the data in data_file_name 99 - allocate buffers for data access 100 101 *data_file_name* : fits or fits.gz file of the data including the path 102 103 *calib_file_name* : fits or fits.gz file containing DRS calibration data 104 105 *baseline_file_name* : npy file containing the baseline values 106 107 *return_dict* : this option will be removed in future releases. 108 formerly the next() method returned only a subset of (important) event information, 109 and it was not transparent how to retrieve the other (less important) information. 110 Nowadays next() returns self.__dict__ which contains everything we were able to find in the fits file. 111 112 *use_CalFactFits* : formerly the DRS amplitude calibration was 113 implemented in python. But for performance reasons this was now moved into 114 a C++ class called CalFactFits. For test purposes, this option can be set to 115 False, but this is not really maintained anymore. If DRS the DRS calibration algorithm is 116 beeing updated in C++ it may not be updated in the python implementation. 117 118 *do_calibration* : In case *use_CalFactFits* is False, one may choose 119 not to calibrate the data at all, thus safe quite some time. 120 This is imho only needed in case one is interesting in learning something about the 121 calibration algorithm itself. 122 123 *user_action_calib* : callback function, intended for tests of the DRS calibration algorithm. 124 but since this is not done in the Python regime anymore, this function is never called. 125 (depending on *use_CalFactFits* of course) 99 126 """ 100 127 self.__module__='pyfact' … … 122 149 self.correct_baseline = True 123 150 151 124 152 # access data file 125 153 if use_CalFactFits: … … 129 157 print 'problem accessing data file: ', data_file_name 130 158 raise # stop ! no data 131 159 160 #: either CalFactFits object or FactFits object, depending on *use_CalFactFits* 132 161 self.data_file = data_file 162 #: 1440x300 nparray containing the event data. pixel sorted according to CHID 133 163 self.data = np.empty( data_file.npix * data_file.nroi, np.float64) 134 164 data_file.SetNpcaldataPtr(self.data) 135 self.data = self.data.reshape( data_file.npix, data_file.nroi ) 165 self.data = self.data.reshape( data_file.npix, data_file.nroi ) 166 #: copy of data. here for historical reasons 136 167 self.acal_data = self.data 137 168 #: region of interest. (number of DRS slices read). 169 # for FACT data mostly 300. for special runs sometimes 1024. 138 170 self.nroi = data_file.nroi 171 #: number of Pixel in FACT. should be 1440 139 172 self.npix = data_file.npix 173 #: the total number of events in the data_file 140 174 self.nevents = data_file.nevents 141 175 142 176 # Data per event 177 #: starting at 1 143 178 self.event_id = None 179 #: data=4 ; the rest I don't know by heart .. should be documented here :-) 144 180 self.trigger_type = None 145 181 #self.start_cells = None 146 182 #self.board_times = None 183 #: slice where drs readout started for all DRS chips (160) .. but enlarged to the size of 1440 pixel. thus there are always 9 equal numbers inside. 147 184 self.start_cells = np.zeros( self.npix, np.int16 ) 185 #: each FAD has an onboard clock running from startup time. Currently I don't know the time unit. However this is an array of 40 times, since we have 40 boards. 148 186 self.board_times = np.zeros( 40, np.int32 ) 149 187 … … 164 202 165 203 # get basic information about the data file 166 #: region of interest (number of DRS slices read)167 204 self.nroi = data_file.GetUInt('NROI') 168 #: number of pixels (should be 1440)169 205 self.npix = data_file.GetUInt('NPIX') 170 #: number of events in the data run171 206 self.nevents = data_file.GetNumRows() 172 207 … … 174 209 self.event_id = c_ulong() 175 210 self.trigger_type = c_ushort() 176 #: 1D array with raw data177 211 self.data = np.zeros( self.npix * self.nroi, np.int16 ).reshape(self.npix ,self.nroi) 178 #: slice where drs readout started179 212 self.start_cells = np.zeros( self.npix, np.int16 ) 180 #: time when the FAD was triggered, in some strange units...181 213 self.board_times = np.zeros( 40, np.int32 ) 182 214 … … 226 258 227 259 def next(self): 228 """ used by __iter__ """ 260 """ used by __iter__ 261 262 returns self.__dict__ 263 """ 229 264 if self.use_CalFactFits: 230 265 if self.data_file.GetCalEvent() == False: … … 250 285 251 286 def next_event(self): 252 """ load the next event from disk and calibrate it 287 """ ---- DEPRICATED ---- 288 289 load the next event from disk and calibrate it 253 290 """ 254 291 if self.use_CalFactFits: … … 259 296 260 297 def calibrate_drs_amplitude(self): 261 """ perform the drs amplitude calibration of the event data 262 298 """ --- DEPRICATED --- 299 300 since the DRS calibration is done by the C++ class CalFactFits 301 302 perform the drs amplitude calibration of the event data 263 303 """ 264 304 # shortcuts … … 295 335 def baseline_read_values(self, file, bsl_hist='bsl_sum/hplt_mean'): 296 336 """ 297 298 337 open ROOT file with baseline histogram and read baseline values 299 file name of the root file 300 bsl_hist path to the histogram containing the basline values 301 338 339 *file* : name of the root file 340 341 *bsl_hist* : path to the histogram containing the basline values 302 342 """ 303 343 … … 317 357 def baseline_correct(self): 318 358 """ subtract baseline from the data 319 359 360 DN 08.06.2011: I didn't use this function at all so far... don't know how well it works. 320 361 """ 321 362 … … 325 366 def info(self): 326 367 """ print run information 327 368 369 not very well implemented ... we need more info here. 328 370 """ 329 371 print 'data file: ', self.data_file_name … … 334 376 class RawDataFake( object ): 335 377 """ raw data FAKE access similar to real RawData access 378 379 DO NOT USE ... its not working 336 380 """ 337 381 … … 419 463 class SlowData( FactFits ): 420 464 """ -Fact SlowData File- 421 A Python wrapper for the fits-class implemented in pyfits.h 465 466 A Python wrapper for the fits-class implemented in factfits.h 422 467 provides easy access to the fits file meta data. 468 423 469 * dictionary of file metadata - self.meta 424 470 * dict of table metadata - self.columns … … 429 475 """ 430 476 self.path = path 477 self.__module__ = 'pyfact' 431 478 try: 432 479 FactFits.__init__(self,path) … … 438 485 self.columns = self._make_columns_dict() 439 486 440 self. treat_meta_dict()487 self._treat_meta_dict() 441 488 442 489 … … 533 580 # raise TypeError("I don't know how to stack "+col+". It is of type: "+str(type(self.dict[col]))) 534 581 535 def register(self, input_str): 582 def register(self, col_name): 583 """ register for a column in the fits file 584 585 after the call, this SlowData object will have a new member variable 586 self.col_name, if col_name is a key in self.colums 587 588 the value will be updated after each call of next(), or while iterating over self. 589 NB: the initial value is zero(s) 590 591 *col_name* : name of a key in self.columns, or 'all' to choose all. 592 """ 536 593 columns = self.columns 537 if input_str.lower() == 'all':594 if col_name.lower() == 'all': 538 595 for col in columns: 539 596 self._register(col) 540 597 else: 541 598 #check if colname is in columns: 542 if input_strnot in columns:599 if col_name not in columns: 543 600 error_msg = 'colname:'+ input_str +' is not a column in the binary table.\n' 544 601 error_msg+= 'possible colnames are\n' … … 630 687 631 688 632 def treat_meta_dict(self):689 def _treat_meta_dict(self): 633 690 """make 'interesting' meta information available like normal members. 634 691 non interesting are: … … 699 756 700 757 def next(self): 701 """ used by __iter__ """ 758 """ use to iterate over the file 759 760 do not forget to call register() before iterating over the file 761 call show() in order to find out, what parameters register() accepts. 762 or just call register('all') in case you are unsure. 763 764 returns self 765 """ 702 766 # Here one might check, if looping makes any sense, and if not 703 767 # one could stop looping or so... … … 725 789 726 790 def show(self): 791 """ 792 """ 727 793 pprint.pprint(self.dict) 728 794
Note:
See TracChangeset
for help on using the changeset viewer.