Belle II Software  release-08-01-10
polar_plot_stacked.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """
13 Alternative version with stacked bars
14 """
15 
16 import numpy as np
17 from ROOT import TFile
18 from pylab import plt, savefig, show, subplot
19 
20 components = {'Touschek_LER', 'Touschek_HER'}
21 layers = {3, 4, 5, 6}
22 
23 dose_data = {'Touschek_HER': {
24  3: np.zeros((7, 2)),
25  4: np.zeros((10, 3)),
26  5: np.zeros((12, 4)),
27  6: np.zeros((16, 5)),
28 }, 'Touschek_LER': {
29  3: np.zeros((7, 2)),
30  4: np.zeros((10, 3)),
31  5: np.zeros((12, 4)),
32  6: np.zeros((16, 5)),
33 }}
34 
35 layer_phi0 = {
36  3: 33.624 * np.pi / 180,
37  4: 8 * np.pi / 180,
38  5: -8 * np.pi / 180,
39  6: -4 * np.pi / 180,
40 }
41 layer_nladders = {
42  3: 7,
43  4: 10,
44  5: 12,
45  6: 16,
46 }
47 layer_nsensors = {
48  3: 2,
49  4: 3,
50  5: 4,
51  6: 5,
52 }
53 
54 fileName = '/data/belle2/BG/Feb2015/output/base_kekcc/base_touschek_histo.root'
55 print('reading from file ', fileName)
56 
57 rootfile = TFile(fileName)
58 tree = rootfile.Get('bSummary')
59 
60 nev = tree.GetEntries()
61 for iev in range(0, nev):
62  tree.GetEntry(iev)
63 
64  dose_data[str(tree.component)][tree.layer][tree.ladder - 1, tree.sensor - 1] = 100 * tree.dose
65 
66 overlap_factor = 0.0 # Overlap of neighbour bars relative to bar width
67 
68 component = 'Touschek_LER'
69 
70 for layer in layers:
71  ladder_width = 2 * np.pi / layer_nladders[layer]
72  ladder_angles = np.linspace(layer_phi0[layer], layer_phi0[layer] + 2 * np.pi,
73  layer_nladders[layer], endpoint=False)
74  bottoms = np.zeros(layer_nladders[layer])
75  ax = subplot(2, 2, layer - 2, polar=True)
76  for sensor in range(layer_nsensors[layer]):
77  bars = ax.bar(
78  ladder_angles,
79  dose_data[component][layer][:, sensor],
80  width=ladder_width,
81  bottom=bottoms,
82  label=str(sensor + 1),
83  align='center',
84  )
85  bottoms += dose_data[component][layer][:, sensor]
86  for bar in bars:
87  bar.set_facecolor(plt.cm.Paired(0.1 + 0.15 * sensor))
88  bar.set_alpha(0.5)
89 
90  r_shift = 0.1 * max(bottoms)
91  for (i, r) in zip(range(layer_nladders[layer]), bottoms):
92  ax.text(
93  ladder_angles[i],
94  r + r_shift,
95  str(i + 1),
96  ha='center',
97  va='center',
98  fontsize=7,
99  color='b',
100  )
101 
102  for tick in ax.yaxis.get_major_ticks():
103  tick.label.set_fontsize(7)
104 
105  for tick in ax.xaxis.get_major_ticks():
106  tick.label.set_fontsize(9)
107 
108  fullscale = np.max(bottoms)
109  ax.set_ylim(-0.25 * fullscale, 1.2 * fullscale)
110  ax.text(
111  1.1 * np.pi / 8,
112  1.35 * np.max(bottoms),
113  'Dose [Gy/smy]',
114  ha='left',
115  va='center',
116  fontsize=7,
117  )
118 
119  ax.legend(title='Sensor', fontsize=9, bbox_to_anchor=(1.4, 0.5))
120  ax.set_title('Layer ' + str(layer), x=0.0, y=0.97)
121  show()
122 savefig('layers.png')