Changeset 13182 for fact/tools/pyscripts/pyfact
- Timestamp:
- 03/22/12 21:19:29 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/pyfact/image_extractors.py
r13143 r13182 5 5 # 6 6 from coor import Coordinator 7 import numpy as np 7 8 from euclid import Vector2 9 import sys 8 10 9 11 class SimpleArea(object): … … 42 44 def __init__(self): 43 45 self.coordinator = Coordinator() 44 self.chid2coor = self.coordinator.chid2 vec46 self.chid2coor = self.coordinator.chid2coor_np 45 47 pass 46 48 … … 51 53 self._CalculateSize() 52 54 self._CalculateCOG() 53 55 self._CaluculateCovarianceMatrix() 54 56 55 57 def _CalculateSize(self): … … 69 71 amplitude = self.amplitude 70 72 chid2coor = self.chid2coor 73 center = self.coordinator.center 74 ex = np.array(self.coordinator.ex) 75 ey = np.array(self.coordinator.ey) 71 76 72 73 cog = Vector2( 0, 0) 77 cog = np.zeros(2) 74 78 for chid in survivors: 75 79 cog += chid2coor[chid] * amplitude[chid] 76 80 cog /= self.size 77 81 self.cog = cog 78 return cog 79 def _CaluculateM(self): 80 """ M is a matrix I didn't understand yet. 81 Maybe some kind of covariance matrix... 82 print 'debug-COG=',cog, 'in hex coordinates' 83 cog_euc = cog[0] * ex + cog[1] * ey + center 84 self.cog_euc = cog_euc 85 print 'debug-COG=', cog_euc, 'in euclidic coordinates' 86 return cog, cog_euc 87 88 89 def _CaluculateCovarianceMatrix(self): 90 """ calculates the covariance matrix 82 91 """ 92 # shortcuts 93 survivors = self.survivors 94 amplitude = self.amplitude 95 chid2coor = self.chid2coor 96 cog_euc = self.cog_euc 97 S = self.size 98 center = self.coordinator.center 99 ex = np.array(self.coordinator.ex) 100 ey = np.array(self.coordinator.ey) 101 102 # make new 2x2 covarianz matrix 103 cov = np.zeros( (2,2) ) 104 for pixel in survivors: 105 # hex coordinates 106 coor = chid2coor[pixel] 107 # make euclidic coordinates 108 coor = coor[0] * ex + coor[1] * ey + center 109 rel_coor = coor - cog_euc 110 111 # make new 2x2 matrix 112 mi = np.ones( (2,2) ) 113 # ugly ! ... 114 mi[0][0] = rel_coor[0] * rel_coor[0] 115 mi[0][1] = rel_coor[0] * rel_coor[1] 116 mi[1][0] = rel_coor[1] * rel_coor[0] 117 mi[1][1] = rel_coor[1] * rel_coor[1] 118 mi *= amplitude[pixel] 119 #print mi , amplitude[pixel] 120 cov += mi 121 self.cov = cov 122 123 #more funny shortcuts 124 Mxx = cov[0][0] 125 Myy = cov[1][1] 126 Mxy = cov[0][1] 127 128 #print 'corariance matrix' 129 #print cov 130 # use the covariance matrix to calulate the number TB also cals in his thesis 131 radicand = (Myy-Mxx)**2 + 4*Mxy**2 132 k = np.sqrt(radicand) + (Myy - Mxx) 133 print 'k:', k 134 tan_delta = k / (2*Mxy ) 135 if tan_delta > 0: 136 delta_in_rad = np.arctan ( tan_delta ) 137 else: 138 delta_in_rad = np.arctan ( tan_delta ) + np.pi 139 delta_in_deg = delta_in_rad / np.pi * 180 140 print 'delta_in_rad' , delta_in_rad 141 print 'delta_in_deg' , delta_in_deg 142 143 # width 144 numerator = Mxx*tan_delta**2 - k + Myy 145 denominiator = (tan_delta**2 + 1) * S 146 width = np.sqrt(numerator / denominiator) 147 148 #length 149 numerator = Myy*tan_delta**2 + k + Mxx 150 denominiator = (tan_delta**2 + 1) * S 151 length = np.sqrt(numerator / denominiator) 152 153 # make strange rotation matrix .. called capital R in TBs diss 154 # shortcut 155 d = delta_in_rad 156 R = np.array( ((np.cos(d), np.sin(d)),(-np.sin(d), np.cos(d))) ) 157 158 # calculate vector v between COG of shower and source position 159 # currently I don't know the cource position, so I use the center of the camera 160 v = cog_euc - np.array( [0,10] ) 161 # and calculate some strange vertor r = R v 162 r = (R*v).sum(axis=1) 163 print 'r',r 164 165 #dist 166 dist = np.sqrt( v[0]**2 + v[1]**2 ) 167 print 'dist', dist 168 169 #alpha 170 alpha = np.arcsin( r[1] / dist) 171 alpha_in_deg = alpha / np.pi * 180 172 print 'alpha', alpha 173 print 'alpha_in_deg ', alpha_in_deg 174 83 175 84 176 if __name__ == '__main__':
Note:
See TracChangeset
for help on using the changeset viewer.