SND@LHC Software
Loading...
Searching...
No Matches
display_overlap Namespace Reference

Functions

 load_scifi (geo_file)
 
 getFiberWeight (FibresMap)
 
 plot_overlap (scifi, plot_outfile)
 
 main ()
 

Function Documentation

◆ getFiberWeight()

display_overlap.getFiberWeight (   FibresMap)

Definition at line 17 of file display_overlap.py.

17def getFiberWeight(FibresMap):
18
19 # create a fiber_weight list with 3 column fID weight pos
20 fiber_weight = {}
21 for fiber in FibresMap:
22 fID = fiber.first
23 for channel in fiber.second:
24 chanID = channel.first
25 weight = channel.second[0]
26 pos = channel.second[1]
27 #print(fID, chanID, weight, pos)
28
29 if fID not in fiber_weight:
30 fiber_weight[fID] = [weight, pos]
31 else:
32 fiber_weight[fID][0] += weight
33 if pos != fiber_weight[fID][1]:
34 #print(f"changing channel {chanID} pos from {fiber_weight[fID][1]} to {pos}")
35 fiber_weight[fID][1] = pos
36
37 return fiber_weight
38

◆ load_scifi()

display_overlap.load_scifi (   geo_file)

Definition at line 10 of file display_overlap.py.

10def load_scifi(geo_file):
11 snd_geo = SndlhcGeo.GeoInterface(geo_file)
12 lsOfGlobals = ROOT.gROOT.GetListOfGlobals()
13 scifi = snd_geo.modules['Scifi']
14
15 return scifi
16

◆ main()

display_overlap.main ( )

Definition at line 151 of file display_overlap.py.

151def main():
152 parser = argparse.ArgumentParser(description="Plot overlap for SciFi SiPM.")
153 parser.add_argument("--geo", type=str, required=True, help="Path to the geometry ROOT file.")
154 parser.add_argument("--output", type=str, required=True, help="Path to save the output plot.")
155 args = parser.parse_args()
156
157 geo = args.geo
158 output_path = args.output
159
160 scifi= load_scifi(geo)
161
162 plot_overlap(scifi, output_path)
163
int main()
Definition main.cc:133

◆ plot_overlap()

display_overlap.plot_overlap (   scifi,
  plot_outfile 
)

Definition at line 39 of file display_overlap.py.

39def plot_overlap(scifi, plot_outfile):
40 sGeo = ROOT.gGeoManager
41 scifi.SiPMOverlap()
42 scifi.SiPMmapping()
43
44 SiPMmap = scifi.GetSiPMmap()
45 FibresMap = scifi.GetFibresMap()
46 print("GetSiPMmap",len(SiPMmap))
47 print("GetFibresMap",len(FibresMap))
48
49 #print("number of fibers in map",len(FibresMap))
50 #print(SiPMmap)
51
52 fiber_weight = getFiberWeight(FibresMap)
53 #print(fiber_weight)
54 print("number of fibers in map", len(fiber_weight))
55
56 # check all volumns
57 # volume_list = sGeo.GetListOfVolumes()
58 # for vol in volume_list:
59 # name = vol.GetName()
60 # #if "SiPM" in name:
61 # print(name)
62
63 y_values = []
64 z_values = []
65
66 fig, ax = plt.subplots(figsize=(10, 10))
67 SiPMmapVol = sGeo.FindVolumeFast("SiPMmapVol")
68 for sipm in SiPMmapVol.GetNodes():
69 t0 = sipm.GetMatrix().GetTranslation()[0]
70 t1 = sipm.GetMatrix().GetTranslation()[1]
71 t2 = sipm.GetMatrix().GetTranslation()[2]
72
73 y0 = t1
74 z0 = t2
75
76 DX = sipm.GetVolume().GetShape().GetDX()
77 DY = sipm.GetVolume().GetShape().GetDY()
78 DZ = sipm.GetVolume().GetShape().GetDZ()
79
80 #print("sipm t0, t1, t2", t0, t1, t2)
81
82 rect = Rectangle((y0 - DY, z0 - DZ), DY*2, DZ*2, edgecolor='blue', facecolor='none')
83 ax.add_patch(rect)
84
85 y_values.extend([y0 - DY, y0 + DY])
86 z_values.extend([z0 - DZ, z0 + DZ])
87
88 #break
89
90 ScifiHorPlaneVol = sGeo.FindVolumeFast("ScifiHorPlaneVol1")
91 imat = 0
92 norm = colors.Normalize(vmin=0, vmax=1.4)
93 cmap = cm.get_cmap('RdYlGn')
94 for mat in ScifiHorPlaneVol.GetNodes(): # 3 mats
95 mat_t0 = mat.GetMatrix().GetTranslation()[0]
96 mat_t1 = mat.GetMatrix().GetTranslation()[1]
97 mat_t2 = mat.GetMatrix().GetTranslation()[2]
98
99 #print(f"mat {imat+1} t0,t1,t2", mat_t0, mat_t1, mat_t2)
100 for fiber in mat.GetVolume().GetNodes():
101 fiber_t0 = fiber.GetMatrix().GetTranslation()[0]
102 fiber_t1 = fiber.GetMatrix().GetTranslation()[1]
103 fiber_t2 = fiber.GetMatrix().GetTranslation()[2]
104 #print("fiber t0,t1,t2", fiber_t0, fiber_t1, fiber_t2)
105
106 y0 = fiber_t1 + mat_t1
107 z0 = fiber_t2
108
109 fiber_radius = fiber.GetVolume().GetShape().GetDX()
110
111 fID = fiber.GetNumber()%100000 + imat*1e4
112 if fID in fiber_weight:
113 f_weight = fiber_weight[fID][0]
114 else:
115 f_weight = 0
116 color = cmap(norm(f_weight))
117 circ = Circle((y0, z0), radius=fiber_radius, edgecolor='red', facecolor=color, alpha=0.8)
118 ax.add_patch(circ)
119
120 imat+=1
121
122
123
124 print("SiPM Y axis position limit:", (min(y_values), max(y_values)))
125 print("SiPM Z axis position limit:", (min(z_values), max(z_values)))
126
127 xlim = (min(y_values)-0.1, max(y_values)+0.1)
128 ylim = (-0.09, 0.09)
129
130 fig_width = (xlim[1] - xlim[0]) * 10
131 fig_height = (ylim[1] - ylim[0]) * 10
132 fig.set_size_inches(fig_width, fig_height)
133
134 ax.set_xlim(*xlim)
135 ax.set_ylim(*ylim)
136 ax.set_aspect('equal')
137 ax.set_xlabel("Y axis (cm)")
138 ax.set_ylabel("Z axis (cm)")
139
140 # add 0.081 to y axis ticker
141 yticks = list(ax.get_yticks())
142 yticks.append(0.081)
143 yticks = sorted(set(yticks))
144 ax.set_yticks(yticks)
145
146 plt.grid(True)
147 plt.savefig(plot_outfile, dpi=300)
148 print(f"plot saved to {plot_outfile}")
149
150
set(INCLUDE_DIRECTORIES ${SYSTEM_INCLUDE_DIRECTORIES} ${VMC_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/shipdata ${CMAKE_SOURCE_DIR}/shipLHC ${CMAKE_SOURCE_DIR}/analysis/cuts ${CMAKE_SOURCE_DIR}/analysis/tools ${FMT_INCLUDE_DIR}) include_directories($
Definition CMakeLists.txt:1