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):
self.Position = Position
def detect (self, (x,y,z)):
"""Calculate for a given vector (x, y, z) 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"""
x = x*(self.Position/z) # calculate the realitiv position of the vector in the z-Plane
y = y*(self.Position/z)
if -50 < x < 50 and -50 < y < 50:
j = int((-x+50)/0.0025+1) # (-x+50) /0.0025 +1
i = int((-y+50)/0.0025+1) # ^math correction of coordinate system ^each grid has 25 micrometer ^to i,j element [1,40.000]
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
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):
"""5 Layer of Tracker"""
self.Layer1 = CLayer (100)
self.Layer2 = CLayer (110)
self.Layer3 = CLayer (120)
self.Layer4 = CLayer (130)
self.Layer5 = CLayer (140)
self.Layer1 = Layer (100)
self.Layer2 = Layer (110)
self.Layer3 = Layer (120)
self.Layer4 = Layer (130)
self.Layer5 = Layer (140)
def detect (self, vector):
"""Calculate for a given vector (x, y, z) 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 "None" if the Layer is not hitted"""
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"""
result = []
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
\ 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).
#Classes:
CDetector
Classes:
============================
CDetector<br>
CLayer
#CDetector:
**Functions:**
__init__()
CDetector:
============================
Functions:
----------------------------
\_\_init\_\_()<br>
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.
**detect (vector):**
Loop over all Layers the function CLayer.detect (vector).
*Arguments:*
vector: Tuple of 3 Numbers describing a vector
*Return:*
Returns a List of 5 Tuples, each Tuple has 3 Numbers: (i, j, Position)
(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
Position returns the Position of the Layer (z-coordinate)
If a Layer is not hit, the Tuple is “None”
**detect (vector):**<br>
Loop over all Layers the function CLayer.detect (vector).<br><br>
*Arguments:*<br>
phi, theta: represents the angles of the particle starting from the source<br>
phi is for the x-axis [-pi,pi]<br>
theta is for the y-axis [-pi,pi]<br><br>
*Return:*<br>
Returns a List of 5 Tuples, each Tuple has 2 Tuples with a higher and a lower angle bound.<br>
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)
**__init__(Position):**
Just copy the argument.
*Arguments:*
Position: Location of the Layer at the z-axis
**detect (vector):**
Calculate which grid of this Layer is hit.
*Arguments:*
vector: Tuple of 3 Numbers describing a vector
*Return:*
Returns a Tuple with 3 Numbers: (i, j, Position)
(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
Position returns the Position of the Layer (z-coordinate)
If this Layer is not hit, the Tuple is “None”
**\_\_init\_\_(Position):**<br>
Just copy the argument.<br><br>
*Arguments:*<br>
Position: Location of the Layer at the z-axis<br>
**detect (vector):**<br>
Calculate the bounds of hit grid.<br><br>
*Arguments:*<br>
phi, theta: represents the angles of the particle starting from the source<br>
phi is for the x-axis [-pi,pi]<br>
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
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