Skip to content
Snippets Groups Projects
Commit 58448269 authored by lorenzennio's avatar lorenzennio
Browse files

Added documentation.

parent 89198072
No related branches found
No related tags found
No related merge requests found
"""
Analysis class
"""
import numpy as np
import pandas as pd
import matplotlib as plt
class Analysis:
"""
Analysis class:
This class computes mean and error on the detector output angles.
The results can then be visualized with two plots.
"""
def __init__(self, angles):
# Better to put in Pandas dataframe
"""
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.
"""
self.xAngles = pd.Series({'High' : angles[0][0],
'Low' : angles[0][1],})
self.yAngles = pd.Series({'High' : angles[1][0],
......@@ -19,20 +25,35 @@ class Analysis:
self.results = pd.DataFrame({'Mean' : np.zeros(2),
'Error': np.zeros(2)})
#TODO: Determine mean and std
self.rmNone()
#Determine mean and std
self.FillAngles()
self.Angles(self.xAngles['High'], self.xAngles['Low'], call=0)
self.Angles(self.yAngles['High'], self.yAngles['Low'], call=1)
#TODO: Plot
def rmNone(self):
self.xAngles['High'] = np.array([x for x in self.xAngles['High'] if x is not None])
self.xAngles['Low'] = np.array([x for x in self.xAngles['Low'] if x is not None])
self.yAngles['High'] = np.array([x for x in self.yAngles['High'] if x is not None])
self.yAngles['Low'] = np.array([x for x in self.yAngles['Low'] if x is not None])
def FillAngles(self):
"""
Fill the angle data into the class vaiebles.
"""
self.xAngles['High'] = np.array([x for x in self.xAngles['High'] if x is not None])
self.xAngles['Low'] = np.array([x for x in self.xAngles['Low'] if x is not None])
self.yAngles['High'] = np.array([x for x in self.yAngles['High'] if x is not None])
self.yAngles['Low'] = np.array([x for x in self.yAngles['Low'] if x is not None])
def Angles(self, high, low, call=0):
"""
Algorithm to compute the minimum possible range of angles.
The upper and lower angles must be given as a argument and also
the 'call' variable secifies the plane you are working in
(x-z or y-z plane).
The algorithim loops over the angles from the last detector layer
to the first, and replaces the upper and lower angle bounds, if
a certain layer restricts the range further.
The mean is calculated as the arithmetic mean of the resulting
angles and the error is the difference from the mean to the angle
bounds.
"""
highRev = high[::-1]
lowRev = low[::-1]
highBound = highRev[0]
......@@ -43,6 +64,7 @@ class Analysis:
highBound = a
if b < highBound and b > lowBound:
lowBound = b
print(highBound,lowBound)
error = (highBound - lowBound)/2
mean = highBound - error
self.results['Mean'][call] = mean
......
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