Coverage for yaptide/converter/converter/fluka/helper_parsers/detector_parser.py: 100%

57 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-07-01 12:55 +0000

1from dataclasses import dataclass 

2 

3 

4@dataclass 

5class MeshDetector: 

6 """Class representing detector with cartesian mesh coordinates""" 

7 

8 name: str 

9 x_min: float 

10 x_max: float 

11 x_bins: int 

12 y_min: float 

13 y_max: float 

14 y_bins: int 

15 z_min: float 

16 z_max: float 

17 z_bins: int 

18 

19 

20@dataclass 

21class CylinderDetector: 

22 """Class representing detector with in shape of cylinder""" 

23 

24 name: str 

25 x: float 

26 y: float 

27 r_min: float 

28 r_max: float 

29 z_min: float 

30 z_max: float 

31 r_bins: int 

32 z_bins: int 

33 phi_bins: int 

34 

35 

36def get_min_coord(center: float, size: float) -> float: 

37 """Returns minimal coordinate basing on center and size""" 

38 return center - size / 2 

39 

40 

41def parse_mesh_detector(detector_dict: dict) -> MeshDetector: 

42 """Creates detector from dictionary""" 

43 geometry_data = detector_dict['geometryData'] 

44 parameters = geometry_data['parameters'] 

45 

46 depth = parameters['depth'] 

47 height = parameters['height'] 

48 width = parameters['width'] 

49 

50 x_min = get_min_coord(geometry_data['position'][0], width) 

51 y_min = get_min_coord(geometry_data['position'][1], height) 

52 z_min = get_min_coord(geometry_data['position'][2], depth) 

53 

54 x_max = x_min + width 

55 y_max = y_min + height 

56 z_max = z_min + depth 

57 

58 x_bins = parameters['xSegments'] 

59 y_bins = parameters['ySegments'] 

60 z_bins = parameters['zSegments'] 

61 

62 return MeshDetector( 

63 name=detector_dict['name'], 

64 x_min=x_min, 

65 y_min=y_min, 

66 z_min=z_min, 

67 x_max=x_max, 

68 y_max=y_max, 

69 z_max=z_max, 

70 x_bins=x_bins, 

71 y_bins=y_bins, 

72 z_bins=z_bins 

73 ) 

74 

75 

76def parse_cylinder_detector(detector_dict: dict) -> 'CylinderDetector': 

77 """Creates detector from dictionary""" 

78 geometry_data = detector_dict['geometryData'] 

79 parameters = geometry_data['parameters'] 

80 

81 x = geometry_data['position'][0] 

82 y = geometry_data['position'][1] 

83 

84 r_min = parameters['innerRadius'] 

85 r_max = parameters['radius'] 

86 

87 depth = parameters['depth'] 

88 z_min = get_min_coord(geometry_data['position'][2], depth) 

89 z_max = z_min + depth 

90 

91 r_bins = parameters['radialSegments'] 

92 z_bins = parameters['zSegments'] 

93 

94 # default from fluka documentation, not provided in json dict 

95 phi_bins = 1 

96 

97 return CylinderDetector( 

98 name=detector_dict['name'], 

99 x=x, 

100 y=y, 

101 r_min=r_min, 

102 r_max=r_max, 

103 z_min=z_min, 

104 z_max=z_max, 

105 r_bins=r_bins, 

106 z_bins=z_bins, 

107 phi_bins=phi_bins 

108 )