Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSD Detector Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CSD-team
CSD Detector Project
Commits
9570134d
Commit
9570134d
authored
6 years ago
by
lorenzennio
Browse files
Options
Downloads
Patches
Plain Diff
Merged and started testing with new fitting
parent
e2630b16
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Detector.py
+5
-5
5 additions, 5 deletions
Detector.py
analysis.py
+54
-12
54 additions, 12 deletions
analysis.py
test.py
+17
-0
17 additions, 0 deletions
test.py
testAnalysis.py
+27
-5
27 additions, 5 deletions
testAnalysis.py
with
103 additions
and
22 deletions
Detector.py
+
5
−
5
View file @
9570134d
...
...
@@ -9,11 +9,11 @@ class Layer:
#Newton-method to calculate the hit time
def
f
(
self
,
x
,
vector
):
Omega
=
vector
.
q
*
self
.
BField
/
vector
.
m
return
-
vector
.
vz
/
Omega
*
np
.
sin
(
Omega
*
x
)
+
vector
.
vy
/
Omega
*
(
np
.
cos
(
Omega
*
x
)
-
1
)
-
self
.
Position
return
vector
.
vz
/
Omega
*
np
.
sin
(
Omega
*
x
)
+
vector
.
vy
/
Omega
*
(
np
.
cos
(
Omega
*
x
)
-
1
)
-
self
.
Position
def
df
(
self
,
x
,
vector
):
Omega
=
vector
.
q
*
self
.
BField
/
vector
.
m
return
-
vector
.
vz
*
np
.
cos
(
Omega
*
x
)
+
vector
.
vy
*
np
.
sin
(
Omega
*
x
)
return
vector
.
vz
*
np
.
cos
(
Omega
*
x
)
+
vector
.
vy
*
np
.
sin
(
Omega
*
x
)
def
dx
(
self
,
x
,
vector
):
return
abs
(
0
-
self
.
f
(
x
,
vector
))
...
...
@@ -66,7 +66,7 @@ class Layer:
else
:
return
((
None
,
None
),
(
None
,
None
),
(
self
.
Position
,
self
.
Position
))
return
((
xHigh
,
xLow
),
(
yHigh
,
yLow
),
(
self
.
Position
,
self
.
Position
))
return
((
xHigh
,
xLow
),
(
yHigh
,
yLow
),
(
self
.
Position
+
0.005
,
self
.
Position
-
0.005
))
...
...
@@ -85,7 +85,7 @@ class Detector:
"""
Calculate for a given particle class the hit grid. The class needs the membervalues: vx, vy, vz, q, m - Velocity in 3 dimensions, charge, mass.
Returns the known passed volumes or
"
None
"
if one Layer is not hitted
"""
result
=
np
.
array
([[(
0
,
0
),(
0
,
0
),(
0
,
0
)]])
result
=
np
.
array
([[(
0
+
0.0001
,
0
-
0.0001
),(
0
+
0.0001
,
0
-
0.0001
),(
0
+
0.0001
,
0
-
0.0001
)]])
for
Layer
in
[
self
.
Layer1
,
self
.
Layer2
,
self
.
Layer3
,
self
.
Layer4
,
self
.
Layer5
]:
result
=
np
.
append
(
result
,
[
Layer
.
detect
(
particle
)],
axis
=
0
)
...
...
@@ -93,4 +93,4 @@ class Detector:
return
None
return
result
\ No newline at end of file
return
result
This diff is collapsed.
Click to expand it.
analysis.py
+
54
−
12
View file @
9570134d
import
numpy
as
np
import
pandas
as
pd
import
matplotlib
as
plt
import
matplotlib
.pyplot
as
plt
from
scipy.optimize
import
curve_fit
from
scipy
import
odr
class
Analysis
:
...
...
@@ -11,12 +12,15 @@ class Analysis:
The results can then be visualized with two plots.
"""
def
__init__
(
self
,
bounds
):
def
__init__
(
self
):
"""
The class is initialized with the angles from the detector results
and then automatically deletes
'
None
'
entries and computes the minimum
range of angles and the error.
"""
...
def
fill
(
self
,
bounds
):
self
.
xBounds
=
pd
.
Series
({
'
High
'
:
bounds
[:,
0
,
0
],
'
Low
'
:
bounds
[:,
0
,
1
]})
self
.
yBounds
=
pd
.
Series
({
'
High
'
:
bounds
[:,
1
,
0
],
...
...
@@ -41,8 +45,16 @@ class Analysis:
'
Error
'
:
(
bounds
[:,
1
,
0
]
-
bounds
[:,
1
,
1
])
/
2.
})
self
.
zPoints
=
pd
.
DataFrame
({
'
Mean
'
:
(
bounds
[:,
2
,
0
]
+
bounds
[:,
2
,
1
])
/
2.
,
'
Error
'
:
(
bounds
[:,
2
,
0
]
-
bounds
[:,
2
,
1
])
/
2.
})
self
.
fit
()
print
(
self
.
results
)
print
(
self
.
xPoints
)
print
(
self
.
yPoints
)
print
(
self
.
zPoints
)
#plt.plot(self.zPoints['Mean'], self.xPoints['Mean'])
#plt.show()
#self.xFit()
#self.yFit()
#print(self.results)
#TODO: Plot
def
rmNone
(
self
):
...
...
@@ -55,15 +67,30 @@ class Analysis:
self
.
yBounds
[
'
High
'
]
=
np
.
array
([
x
for
x
in
self
.
yBounds
[
'
High
'
]
if
x
is
not
None
])
self
.
yBounds
[
'
Low
'
]
=
np
.
array
([
x
for
x
in
self
.
yBounds
[
'
Low
'
]
if
x
is
not
None
])
def
xEOM
(
self
,
x
,
w
,
Vx
,
Vy
,
Vz
):
z
=
(
1
/
w
)
*
(
-
Vy
*
(
1
-
np
.
cos
(
x
*
w
/
Vx
))
+
Vz
*
np
.
sin
(
x
*
w
/
Vx
))
def
xEOM
(
self
,
B
,
x
):
"""
B= [w, Vx, Vy, Vz]
"""
z
=
(
1
/
B
[
0
])
*
(
-
B
[
2
]
*
(
1
-
np
.
cos
(
x
*
B
[
0
]
/
B
[
1
]))
+
B
[
3
]
*
np
.
sin
(
x
*
B
[
0
]
/
B
[
1
]))
return
z
def
yEOM
(
self
,
z
,
R
,
y0
,
z0
):
y
=
y0
+
np
.
sqrt
(
R
**
2
-
(
z
-
z0
)
**
2
)
def
yEOM
(
self
,
B
,
z
):
"""
B = [R, y0, z0]
"""
y
=
B
[
1
]
+
np
.
sqrt
(
B
[
0
]
**
2
-
(
z
-
B
[
2
])
**
2
)
return
y
def
fit
(
self
):
def
xFit
(
self
):
xModel
=
odr
.
Model
(
self
.
xEOM
)
xData
=
odr
.
RealData
(
self
.
xPoints
[
'
Mean
'
],
self
.
zPoints
[
'
Mean
'
],
sx
=
self
.
xPoints
[
'
Error
'
],
sy
=
self
.
zPoints
[
'
Error
'
])
xODR
=
odr
.
ODR
(
xData
,
xModel
,
beta0
=
[
1
,
1
,
1
,
1
])
xOUT
=
xODR
.
run
()
xOUT
.
pprint
()
"""
xPopt, xPcov = curve_fit(self.xEOM,
self.xPoints[
'
Mean
'
],
self.zPoints[
'
Mean
'
]
...
...
@@ -79,20 +106,35 @@ class Analysis:
self.results[
'
Vy
'
][1] = xPerr[2]
self.results[
'
Vz
'
][0] = xPopt[3]
self.results[
'
Vz
'
][1] = xPerr[3]
"""
def
yFit
(
self
):
"""
yPopt, yPcov = curve_fit(self.yEOM,
self.zPoints[
'
Mean
'
],
self.yPoints[
'
Mean
'
],
sigma
=
self
.
yPoints
[
'
Error
'
],
#sigma=self.yPoints[
'
Error
'
],
p0=[10^3, 1, 1],
absolute_sigma=True)
yPerr = np.sqrt(np.diag(xPcov))
"""
#ODR
yModel
=
odr
.
Model
(
self
.
yEOM
)
yData
=
odr
.
RealData
(
self
.
zPoints
[
'
Mean
'
],
self
.
yPoints
[
'
Mean
'
],
sx
=
self
.
zPoints
[
'
Error
'
],
sy
=
self
.
yPoints
[
'
Error
'
])
yODR
=
odr
.
ODR
(
yData
,
yModel
,
beta0
=
[
1e3
,
1
,
1
])
yOUT
=
yODR
.
run
()
yOUT
.
pprint
()
"""
self.results[
'
R
'
][0] = yPopt[0]
self.results[
'
R
'
][1] = yPerr[0]
self.results[
'
y0
'
][0] = yPopt[1]
self.results[
'
y0
'
][1] = yPerr[1]
self.results[
'
z0
'
][0] = yPopt[2]
self.results[
'
z0
'
][1] = yPerr[2]
"""
"""
def yEOM(self, t, w, yVel, zVel):
y = zVel + (1./w)*(-zVel*np.cos(w*t) + yVel*np.sin(w*t))
...
...
This diff is collapsed.
Click to expand it.
test.py
0 → 100644
+
17
−
0
View file @
9570134d
from
analysis
import
Analysis
from
Detector
import
Detector
class
Particle
:
def
__init__
(
self
):
self
.
vx
=
1
self
.
vy
=
1
self
.
vz
=
300
self
.
m
=
0.522
self
.
q
=
1
DET
=
Detector
()
DETRes
=
DET
.
detect
(
Particle
())
ANA
=
Analysis
(
DETRes
)
This diff is collapsed.
Click to expand it.
testAnalysis.py
+
27
−
5
View file @
9570134d
import
unittest
import
numpy
as
np
from
analysis
import
Analysis
import
matplotlib.pyplot
as
plt
class
testAnalysis
(
unittest
.
TestCase
):
"""
A simple test to check the angle means ans error computation.
"""
def
test
(
self
):
ang
=
np
.
array
([
6
,
5
,
6
,
5
,
8
,
4
,
8
,
4
,
7
,
1
,
7
,
1
,
10
,
3
,
10
,
3
,
None
,
None
,
None
,
None
])
ang
=
np
.
reshape
(
ang
,
(
5
,
2
,
2
))
A
=
Analysis
(
ang
)
self
.
assertEqual
(
A
.
results
[
'
Mean
'
][
0
],
5.5
)
self
.
assertEqual
(
A
.
results
[
'
Error
'
][
0
],
0.5
)
#ang = np.array([6,5,6,5,8,4,8,4,7,1,7,1,10,3,10,3,None,None,None,None])
#ang = np.reshape(ang, (5,2,2))
A
=
Analysis
()
#self.assertEqual(A.results['Mean'][0], 5.5)
#self.assertEqual(A.results['Error'][0], 0.5)
z
=
np
.
arange
(
30
)
y
=
A
.
yEOM
([
100
,
1
,
1
],
z
)
#plt.plot(z,y)
#plt.show()
Data
=
[]
for
i
in
range
(
0
,
len
(
z
)):
err
=
np
.
random
.
random
(
size
=
(
4
))
print
(
err
)
Data
.
append
([[
0
,
0
],
[
y
[
i
]
+
err
[
0
],
y
[
i
]
-
err
[
1
]],
[
z
[
i
]
+
err
[
2
],
z
[
i
]
-
err
[
3
]]])
#np.concatenate((Data,
# [[0,0], [y[i]+0.1,y[i]-0.1], [z[i]+0.1, z[i]-0.1]]), axis=0)
Data
=
np
.
array
(
Data
)
A
.
fill
(
Data
)
A
.
yFit
()
#print(y)
#print(z)
#print(Data)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment