1 '''Defines the SetupComponent class for theia.'''
2
3
4
5
6
7
8
9
10 import numpy as np
11 from abc import ABCMeta, abstractmethod
12 from ..helpers.tools import formatter
15 '''
16
17 SetupComponent class.
18
19 This is an Abstract Base Class for all the components (optical or not) of
20 the setup. Its methods may be implemented in daughter classes.
21
22 *=== Attributes ===*
23 SetupCount: class attribute, counts setup components. [integer]
24 HRCenter: center of the principal face of the component in space.
25 [3D vector]
26 HRnorm: normal unitary vector the this principal face, supposed to point
27 outside the media. [3D vector]
28 Thick: thickness of the component, counted in opposite direction to
29 HRNorm. [float]
30 Dia: diameter of the component. [float]
31 Name: name of the component. [string]
32 Ref: reference string (for keeping track with the lab). [string]
33
34
35 '''
36
37 __metaclass__ = ABCMeta
38 SetupCount = 0
39
40 - def __init__(self, HRCenter, HRNorm,
41 Name, Ref, Thickness, Diameter):
42 '''SetupComponent initializer.
43
44 Parameters are the attributes of the object to construct.
45
46 Returns a setupComponent.
47
48 '''
49
50 if Ref is None:
51 Ref = "Set" + str(SetupComponent.SetupCount)
52
53 self.HRCenter = np.array(HRCenter, dtype = np.float64)
54 self.HRNorm = np.array(HRNorm, dtype = np.float64)
55 self.HRNorm = self.HRNorm/np.linalg.norm(self.HRNorm)
56 self.Thick = Thickness
57 self.Dia = Diameter
58 self.Name = Name
59 self.Ref = Ref
60
61 SetupComponent.SetupCount = SetupComponent.SetupCount + 1
62
64 '''String representation of the component, when calling print(object).
65
66 '''
67 return formatter(self.lines())
68
69 @abstractmethod
71 '''Method to return the list of strings to __str__.
72
73 Abstract (pure virtual) method.
74
75 '''
76 pass
77
78 @abstractmethod
80 '''Method to determine if component is hit by a beam.
81
82 Abstract (pure virtual) method.
83
84 '''
85 pass
86