import numpy as np class Layer: def __init__(self, Position): self.Position = Position def detect (self, (phi, theta)): """Calculate for a given angles (phi, theta) the hit grid. Returns the angles from source to grid edge""" #define Dummyvalue - necessary for run phiHigh = 99 phiLow = 99 thetaHigh = 99 thetaLow = 99 x = np.tan(phi)*self.Position #calculate position of hit with Layer y = np.tan(theta)*self.Position if 0 <= x < 50: phiHigh = np.arctan(int(x/0.0025+1)*0.0025/self.Position) #angel for z-axis to upper edge of hit grid phiLow = np.arctan(int(x/0.0025)*0.0025/self.Position) # phi = arctan(opposite/adjacent) elif -50 < x < 0: phiHigh = np.arctan(int(x/0.0025)*0.0025/self.Position) #np.arctan (int(x/0.0025)*0.0025/ self.Position) phiLow = np.arctan(int(x/0.0025-1)*0.0025/self.Position) #^arctan ^round x to next upper/lower 25 mikrometer ^adjacent else: return ((None, None), (None, None)) # if the Layer is not hit, return "None" if 0 <= y < 50: thetaHigh = np.arctan(int(y/0.0025+1)*0.0025/self.Position) thetaLow = np.arctan(int(y/0.0025)*0.0025/self.Position) elif -50 < y < 0: thetaHigh = np.arctan(int(y/0.0025)*0.0025/self.Position) thetaLow = np.arctan(int(y/0.0025-1)*0.0025/self.Position) else: return ((None, None), (None, None)) return ((phiHigh, phiLow), (thetaHigh, thetaLow)) class Detector: def __init__ (self): """5 Layer of Tracker""" self.Layer1 = Layer (100) self.Layer2 = Layer (110) self.Layer3 = Layer (120) self.Layer4 = Layer (130) self.Layer5 = Layer (140) def detect (self, (phi, theta)): """Calculate for a given angles (phi, theta) the hitted grid. Returns the angles from source to grid edge or "None" if the Layer is not hitted""" for Layer in [self.Layer1, self.Layer2, self.Layer3, self.Layer4, self.Layer5]: if Layer == self.Layer1: #First Time creat numpy array result = np.array([Layer.detect((phi, theta))]) else: #For rest, just add result = np.append(result, [Layer.detect((phi, theta))], axis = 0) return result