Newer
Older
import numpy as np
import pandas as pd
import matplotlib as plt
"""
Analysis class:
This class computes mean and error on the detector output angles.
The results can then be visualized with two plots.
"""
"""
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],
'Low' : angles[:,1,1]})
self.results = pd.DataFrame({'Mean' : np.zeros(2),
'Error': np.zeros(2)})
self.Angles(self.xAngles['High'], self.xAngles['Low'], call=0)
self.Angles(self.yAngles['High'], self.yAngles['Low'], call=1)
"""
Fill the angle data into the class vaiebles.
"""
lorenzennio
committed
#print(self.xAngles['High'])
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]
lowBound = lowRev[0]
for a,b in zip(highRev[1:], lowRev[1:]):
if a < highBound and a > lowBound:
highBound = a
if b < highBound and b > lowBound:
lowBound = b
error = (highBound - lowBound)/2
mean = highBound - error
self.results['Mean'][call] = mean
self.results['Error'][call] = error