Skip to content
Snippets Groups Projects
Commit aeb6d6da authored by unknown's avatar unknown
Browse files

Change from vector to angles

parent 9b1d66f9
No related branches found
No related tags found
No related merge requests found
class CLayer: import numpy as np
class Layer:
def __init__(self, Position): def __init__(self, Position):
self.Position = Position self.Position = Position
def detect (self, (x,y,z)): def detect (self, (phi, theta)):
"""Calculate for a given vector (x, y, z) the hit grid. """Calculate for a given angles (phi, theta) the hit grid.
Numbered like a matrix with index i,j, starting with 1,1 in the left upper corner with view from the source""" Returns the angles from source to grid edge"""
x = x*(self.Position/z) # calculate the realitiv position of the vector in the z-Plane
y = y*(self.Position/z) #define Dummyvalue - necessary for run
if -50 < x < 50 and -50 < y < 50: phiHigh = 99
j = int((-x+50)/0.0025+1) # (-x+50) /0.0025 +1 phiLow = 99
i = int((-y+50)/0.0025+1) # ^math correction of coordinate system ^each grid has 25 micrometer ^to i,j element [1,40.000] 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
return (i,j,self.Position) else:
return 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
return ((phiHigh, phiLow), (thetaHigh, thetaLow))
class CDetector: class Detector:
def __init__ (self): def __init__ (self):
"""5 Layer of Tracker""" """5 Layer of Tracker"""
self.Layer1 = CLayer (100) self.Layer1 = Layer (100)
self.Layer2 = CLayer (110) self.Layer2 = Layer (110)
self.Layer3 = CLayer (120) self.Layer3 = Layer (120)
self.Layer4 = CLayer (130) self.Layer4 = Layer (130)
self.Layer5 = CLayer (140) self.Layer5 = Layer (140)
def detect (self, vector): def detect (self, (phi, theta)):
"""Calculate for a given vector (x, y, z) the hitted grid. """Calculate for a given angles (phi, theta) the hitted grid.
Numbered like a matrix with index i,j, starting with 1,1 in the left upper corner with view from the source Returns the angles from source to grid edge or "None" if the Layer is not hitted"""
returns "None" if the Layer is not hitted"""
result = [] result = []
for Layer in [self.Layer1, self.Layer2, self.Layer3, self.Layer4, self.Layer5]: for Layer in [self.Layer1, self.Layer2, self.Layer3, self.Layer4, self.Layer5]:
result.append(Layer.detect(vector)) result.append(Layer.detect((phi, theta)))
return result return result
\ No newline at end of file
Module: Detector
============================
This module calculates the possible angles for a particle flying throw a 5 layer detector.<br>
To use this module, it’s enough to create one instance of CDetector and use the function CDetector.detect (vector). To use this module, it’s enough to create one instance of CDetector and use the function CDetector.detect (vector).
#Classes: Classes:
CDetector ============================
CDetector<br>
CLayer CLayer
#CDetector:
**Functions:** CDetector:
__init__() ============================
Functions:
----------------------------
\_\_init\_\_()<br>
detect (vector) detect (vector)
**__init__():** **\_\_init\_\_():**<br>
Creates 5 instances of CLayer with initvalues {100, 110, 120, 130, 140} which represents the (z-)position of the Layers. Creates 5 instances of CLayer with initvalues {100, 110, 120, 130, 140} which represents the (z-)position of the Layers.
**detect (vector):** **detect (vector):**<br>
Loop over all Layers the function CLayer.detect (vector). Loop over all Layers the function CLayer.detect (vector).<br><br>
*Arguments:* *Arguments:*<br>
vector: Tuple of 3 Numbers describing a vector phi, theta: represents the angles of the particle starting from the source<br>
*Return:* phi is for the x-axis [-pi,pi]<br>
Returns a List of 5 Tuples, each Tuple has 3 Numbers: (i, j, Position) theta is for the y-axis [-pi,pi]<br><br>
(i,j) are the Number of the hit grid. It is numbered like a matrix – (1,1) in the upper left to (40.000,40.000) in the lower right corner *Return:*<br>
Position returns the Position of the Layer (z-coordinate) Returns a List of 5 Tuples, each Tuple has 2 Tuples with a higher and a lower angle bound.<br>
If a Layer is not hit, the Tuple is “None” This means:<br>
e.g. returnvalue [a][b][c]<br>
a – [0,4] select Layer<br>
b – 0 is phi, 1 is theta<br>
c – 0 is the upper bound, 1 the lower bound<br><br>
If a Layer is not hit, the Tuple is “None”<br>
e.g. returnvalue [a] is “None”<br>
CLayer:
============================
Functions:
----------------------------
\_\_init\_\_(Position)<br>
#CLayer:
**Functions:**
__init__(Position)
detect (vector) detect (vector)
**__init__(Position):**
Just copy the argument.
*Arguments:* **\_\_init\_\_(Position):**<br>
Position: Location of the Layer at the z-axis
Just copy the argument.<br><br>
**detect (vector):** *Arguments:*<br>
Calculate which grid of this Layer is hit. Position: Location of the Layer at the z-axis<br>
*Arguments:*
vector: Tuple of 3 Numbers describing a vector **detect (vector):**<br>
*Return:* Calculate the bounds of hit grid.<br><br>
Returns a Tuple with 3 Numbers: (i, j, Position) *Arguments:*<br>
(i,j) are the Number of the hit grid. It is numbered like a matrix – (1,1) in the upper left to (40.000,40.000) in the lower right corner phi, theta: represents the angles of the particle starting from the source<br>
Position returns the Position of the Layer (z-coordinate) phi is for the x-axis [-pi,pi]<br>
If this Layer is not hit, the Tuple is “None” theta is for the y-axis [-pi,pi]<br><br>
*Return:*<br>
Returns 2 Tuples with a higher and a lower angle bound.<br>
This means:<br>
e.g. returnvalue [a][b]<br>
a – 0 is phi, 1 is theta<br>
b – 0 is the upper bound, 1 the lower bound<br><br>
If this Layer is not hit, the Tuple is “None”<br>
This diff is collapsed.
# CSD Detector Project # CSD Detector Project
New
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment