| 1 | #!/usr/bin/python -itt | 
|---|
| 2 | # | 
|---|
| 3 | # Dominik Neise | 
|---|
| 4 | # | 
|---|
| 5 | # cleaning a small step towards the truth | 
|---|
| 6 | from pyfact import RawData | 
|---|
| 7 | import os.path | 
|---|
| 8 | import matplotlib.pyplot as plt | 
|---|
| 9 | import numpy as np | 
|---|
| 10 | from fir_filter import * | 
|---|
| 11 | from extractor import * | 
|---|
| 12 | from drs_spikes import * | 
|---|
| 13 | from plotters import * | 
|---|
| 14 | import time as t | 
|---|
| 15 | from cleaners import AmplitudeCleaner | 
|---|
| 16 | from image_extractors import SimpleArea, SimpleSize | 
|---|
| 17 | confirm_next_step = False# this is for user interaction | 
|---|
| 18 |  | 
|---|
| 19 | data_file_name = 'data/20120223_212.fits.gz' | 
|---|
| 20 | calib_file_name = 'data/20120223_206.drs.fits.gz' | 
|---|
| 21 | if not os.path.isfile(data_file_name): | 
|---|
| 22 | print 'not able to find file:', data_file_name | 
|---|
| 23 | sys.exit(-1) | 
|---|
| 24 | if not os.path.isfile(calib_file_name ): | 
|---|
| 25 | print 'not able to find file:', calib_file_name | 
|---|
| 26 | sys.exit(-1) | 
|---|
| 27 |  | 
|---|
| 28 | run = RawData(data_file_name, calib_file_name) | 
|---|
| 29 | despike = DRSSpikes() | 
|---|
| 30 | smooth = SlidingAverage(8) | 
|---|
| 31 | extract = GlobalMaxFinder(40,200) | 
|---|
| 32 | cleaner = AmplitudeCleaner(45,18) | 
|---|
| 33 | area = SimpleArea() | 
|---|
| 34 | size = SimpleSize() | 
|---|
| 35 |  | 
|---|
| 36 | #plotA = CamPlotter('amplitudes') | 
|---|
| 37 | #plotT = CamPlotter('times') | 
|---|
| 38 | #plotCA = CamPlotter('cleaned amplitudes') | 
|---|
| 39 |  | 
|---|
| 40 | #plotArea = HistPlotter('area', 1440, (0,1440) ) | 
|---|
| 41 | #plotSize = HistPlotter('size', 1000, (0,10000) ) | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 | areas = [] | 
|---|
| 45 | sizes = [] | 
|---|
| 46 | for data,startcell,tt in run: | 
|---|
| 47 | # trigger type 4 means 'physics event' | 
|---|
| 48 | if tt==4: | 
|---|
| 49 | data = despike(data) | 
|---|
| 50 | data = smooth(data) | 
|---|
| 51 | amplitude, time_of_max = extract(data) | 
|---|
| 52 | survivors = cleaner(amplitude, return_bool_mask=False ) | 
|---|
| 53 | areas.append( area(survivors) ) | 
|---|
| 54 | sizes.append( size(survivors, amplitude) ) | 
|---|
| 55 |  | 
|---|
| 56 | if confirm_next_step: | 
|---|
| 57 | user_input = raw_input("'q'-quit, 'r'-run, anything else goes one step") | 
|---|
| 58 | number=None | 
|---|
| 59 | try: | 
|---|
| 60 | number=int(user_input) | 
|---|
| 61 | except: | 
|---|
| 62 | number=None | 
|---|
| 63 | if user_input.find('q') != -1: | 
|---|
| 64 | sys.exit(0) | 
|---|
| 65 | elif user_input.find('r') != -1: | 
|---|
| 66 | confirm_next_step = False | 
|---|
| 67 | elif number!=None: | 
|---|
| 68 | run += number | 
|---|
| 69 |  | 
|---|
| 70 |  | 
|---|
| 71 | plt.ion() | 
|---|
| 72 | myfig = plt.figure() | 
|---|
| 73 | myn = myfig.number | 
|---|
| 74 | logsize = np.log10(np.array(sizes)) | 
|---|
| 75 | areas = np.array(areas) | 
|---|
| 76 |  | 
|---|
| 77 | plt.figure(myn) | 
|---|
| 78 | plt.title('area vs. log10(size) of '+ str(run.event_id.value) + 'events') | 
|---|
| 79 | plt.xlabel('log10(size/1mV)') | 
|---|
| 80 | plt.ylabel('area [#pixel]') | 
|---|
| 81 | plt.plot( logsize,areas, '.') | 
|---|