ATLAS Offline Software
Loading...
Searching...
No Matches
MMPostProcessing.py
Go to the documentation of this file.
2# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3#
4
5from ROOT import TH2F, TLine
6from .MMMonUtils import getMMLabelX, get_MPV_charge, get_mean_and_sigma, getXYbins, poi, get_time
7
9 inputs = list(inputs)
10 names = []
11 histos_unsorted = []
12 for i in range(len(inputs)):
13 h=inputs[i][1][0].Clone()
14 histos_unsorted.append(h.GetName())
15 names.append(h.GetName())
16 names.sort()
17
18 nPCB = 3 # for SM2 and LM2
19 eta='eta2'
20 bins=24
21 if('eta1' in names[0]):
22 nPCB = 5 # for SM1 and LM1
23 eta='eta1'
24 bins = 40
25 side='ASide'
26 if('CSide' in names[0]):
27 side='CSide'
28 list_of_all_histos=[]
29 for phi in range(16):
30 test_list = []
31 for mult in range(2):
32 for gg in range(4):
33 test_list.append(f'pcb_{eta}_{side}_phi{phi}_multiplet{mult+1}_gas_gap{gg+1}_vs_hitcut')
34 list_of_all_histos.append(test_list)
35 histos_sorted = []
36 for ihisto in range(len(names)):
37 ind = histos_unsorted.index(names[ihisto])
38 histos_sorted.append(inputs[ind][1][0])
39
40 h_eff_per_PCB = TH2F(f'Efficiency_{side}_{eta}_per_PCB', f'Efficiency {side} {eta} per PCB', bins,0,bins, 16, .5,16.5)
41 thisLabelx=getMMLabelX("x_lab_occ_etaminus2")
42 if(nPCB==5):
43 thisLabelx=getMMLabelX("x_lab_occ_etaminus1")
44 for xbin in range(len(thisLabelx)):
45 h_eff_per_PCB.GetXaxis().SetBinLabel(xbin+1, thisLabelx[xbin])
46 h_eff_per_PCB.GetYaxis().SetTitle('Sector')
47
48 for ihisto in range(len(histos_sorted)):
49 iphi = histos_sorted[ihisto].GetName()[18:20]
50 if '_' in iphi:
51 iphi = histos_sorted[ihisto].GetName()[18:19]
52 xbin,ybin = getXYbins(nPCB, int(iphi), True, histos_sorted[ihisto].GetName(), list_of_all_histos)
53 ybin+=1
54 for ipcb in range(nPCB):
55 h_eff_per_PCB.SetBinContent(xbin, ybin, histos_sorted[ihisto].GetEfficiency(ipcb+1))
56 xbin+=1
57 return [h_eff_per_PCB]
58
59def residual_map(inputs):
60 inputs = list(inputs)
61 side = 'A'
62 if('CSide' in inputs[0][1][0].GetName()):
63 side = 'C'
64 eta='eta2'
65 if('stationEta1' in inputs[0][1][0].GetName()):
66 eta='eta1'
67
68 output1 = TH2F(f'h_residual_sigma_{eta}_E{side}',f'EndCap{side}: Sigma of Gaussian Fit {eta} - residuals',8, 0, 8, 16, .5, 16.5)
69 output2 = TH2F(f'h_residual_mean_{eta}_E{side}',f'EndCap{side}: Mean of Gaussian Fit {eta} - residuals',8, 0, 8, 16, .5, 16.5)
70 thisLabelx=getMMLabelX("x_lab_mpv")
71
72 for xbin in range(len(thisLabelx)):
73 output1.GetXaxis().SetBinLabel(xbin+1, thisLabelx[xbin])
74 output2.GetXaxis().SetBinLabel(xbin+1, thisLabelx[xbin])
75 output1.GetYaxis().SetTitle('Sector')
76 output1.GetZaxis().SetTitle('#sigma [mm]')
77 output2.GetYaxis().SetTitle('Sector')
78 output2.GetZaxis().SetTitle('Mean [mm]')
79
80 for ihisto in range(len(inputs)):
81 h = inputs[ihisto][1][0]
82 sector = inputs[ihisto][1][0].GetName()[19:21]
83 ml = inputs[ihisto][1][0].GetName()[43:44]
84 gap = inputs[ihisto][1][0].GetName()[52:53]
85 if '_' in sector:
86 sector = inputs[ihisto][1][0].GetName()[19:20]
87 ml = inputs[ihisto][1][0].GetName()[42:43]
88 gap = inputs[ihisto][1][0].GetName()[51:52]
89 ybin = int(sector)
90 xbin = int(gap) + (int(ml) -1)*4
91
92 mean,sigma = get_mean_and_sigma(h, -10, 10)
93 output1.SetBinContent(xbin,ybin,sigma)
94 output2.SetBinContent(xbin,ybin,mean)
95 output1.GetZaxis().SetRangeUser(0, 10)
96 output2.GetZaxis().SetRangeUser(-5, 5)
97
98 return [output1,output2]
99
101 inputs = list(inputs)
102
103 side = 'A'
104 if('CSide' in inputs[0][1][0].GetName()):
105 side = 'C'
106 eta='eta2'
107 if('stEta1' in inputs[0][1][0].GetName()):
108 eta='eta1'
109
110 output = TH2F(f'h_landau_{eta}_E{side}',f'E{side}: MPV of Landau Fit to Cluster charge {eta}',8, 0, 8, 16, .5, 16.5)
111 thisLabelx=getMMLabelX("x_lab_mpv")
112
113 for xbin in range(len(thisLabelx)):
114 output.GetXaxis().SetBinLabel(xbin+1, thisLabelx[xbin])
115 output.GetYaxis().SetTitle('Sector')
116 output.GetZaxis().SetTitle('MPV')
117
118 for ihisto in range(len(inputs)):
119 h = inputs[ihisto][1][0]
120 sector = inputs[ihisto][1][0].GetName()[18:20]
121 ml = inputs[ihisto][1][0].GetName()[37:38]
122 gap = inputs[ihisto][1][0].GetName()[42:43]
123 if '_' in sector:
124 sector = inputs[ihisto][1][0].GetName()[18:19]
125 ml = inputs[ihisto][1][0].GetName()[36:37]
126 gap = inputs[ihisto][1][0].GetName()[41:42]
127 ybin = int(sector)
128 xbin = int(gap) + (int(ml) -1)*4
129
130 if (h.GetEntries()==0):
131 continue
132 else:
133 mpv = get_MPV_charge(h)
134 output.SetBinContent(xbin,ybin,mpv)
135 return[output]
136
137def map_per_PCB(inputs, histo_name, start_index, proctype):
138 inputs = list(inputs)
139 names = []
140 histos_unsorted = []
141 for i in range(len(inputs)):
142 h=inputs[i][1][0].Clone()
143 histos_unsorted.append(h.GetName())
144 names.append(h.GetName())
145 names.sort()
146
147 nPCB = 3 # for SM2 and LM2
148 eta='eta2'
149 bins=24
150 if('eta1' in names[0]):
151 nPCB = 5 # for SM1 and LM1
152 eta='eta1'
153 bins = 40
154
155 side='ASide'
156 if('CSide' in names[0]):
157 side='CSide'
158 list_of_all_histos=[]
159 for phi in range(16):
160 test_list = []
161 for mult in range(2):
162 for gg in range(4):
163 test_list.append(f'{histo_name}_{side}_{eta}_phi{phi+1}_ml{mult+1}_gap{gg+1}')
164 list_of_all_histos.append(test_list)
165
166 histos_sorted = []
167 for ihisto in range(len(names)):
168 ind = histos_unsorted.index(names[ihisto])
169 histos_sorted.append(inputs[ind][1][0])
170 if proctype=='fermiDirac_tzero':
171 h_poi_per_PCB = TH2F(f'{histo_name}_{side}_{eta}_tzero_per_PCB', poi(histo_name,side,eta)+' tzero' , bins, 0, bins, 16, .5, 16.5)
172 elif proctype=='fermiDirac_deltat':
173 h_poi_per_PCB = TH2F(f'{histo_name}_{side}_{eta}_tzero_per_PCB', poi(histo_name,side,eta)+' deltaT' , bins, 0, bins, 16, .5, 16.5)
174 else:
175 h_poi_per_PCB = TH2F(f'{histo_name}_{side}_{eta}_per_PCB', poi(histo_name,side,eta), bins, 0, bins, 16, .5, 16.5)
176 thisLabelx=getMMLabelX("x_lab_occ_etaminus2")
177 if(nPCB==5):
178 thisLabelx=getMMLabelX("x_lab_occ_etaminus1")
179 for xbin in range(len(thisLabelx)):
180 h_poi_per_PCB.GetXaxis().SetBinLabel(xbin+1, thisLabelx[xbin])
181 h_poi_per_PCB.GetYaxis().SetTitle('Sector')
182
183 for ihisto in range(len(histos_sorted)):
184 histo_name=histos_sorted[ihisto].GetName()
185 iphi = histos_sorted[ihisto].GetName()[start_index:start_index+2]
186 if '_' in iphi:
187 iphi = histos_sorted[ihisto].GetName()[start_index:start_index+1]
188
189 xbin,ybin = getXYbins(nPCB, int(iphi), False, histos_sorted[ihisto].GetName(), list_of_all_histos)
190 for ipcb in range(nPCB):
191 histo_tmp = histos_sorted[ihisto].ProjectionY(histos_sorted[ihisto].GetName()+"_py_"+str(ipcb+1),ipcb+1,ipcb+1)
192 if proctype=='mean':
193 if (histo_tmp.GetEntries()==0):
194 h_poi_per_PCB.SetBinContent(xbin, ybin, -999)
195 else:
196 h_poi_per_PCB.SetBinContent(xbin, ybin, histo_tmp.GetMean())
197 h_poi_per_PCB.GetZaxis().SetRangeUser(0, 20)
198 if proctype=='gaus':
199 if (histo_tmp.GetEntries()<100):
200 h_poi_per_PCB.SetBinContent(xbin, ybin, -999)
201 else:
202 gmean, gsigma = get_mean_and_sigma(histo_tmp, -100, 700)
203 h_poi_per_PCB.SetBinContent(xbin, ybin, gmean)
204 h_poi_per_PCB.GetZaxis().SetRangeUser(-100, 700)
205 if proctype=='landau':
206 if (histo_tmp.GetEntries()<100):
207 h_poi_per_PCB.SetBinContent(xbin, ybin, -999)
208 else:
209 mpv = get_MPV_charge(histo_tmp)
210 h_poi_per_PCB.SetBinContent(xbin, ybin, mpv)
211 h_poi_per_PCB.GetZaxis().SetRangeUser(0, 100)
212 if proctype=='fermiDirac_tzero':
213 if (histo_tmp.GetEntries()<100):
214 h_poi_per_PCB.SetBinContent(xbin, ybin, -999)
215 else:
216 t0, tmax = get_time(histo_tmp)
217 h_poi_per_PCB.SetBinContent(xbin, ybin, t0)
218 h_poi_per_PCB.GetZaxis().SetRangeUser(-100, 700)
219 if proctype=='fermiDirac_deltat':
220 if (histo_tmp.GetEntries()<100):
221 h_poi_per_PCB.SetBinContent(xbin, ybin, -999)
222 else:
223 t0, tmax = get_time(histo_tmp)
224 h_poi_per_PCB.SetBinContent(xbin, ybin, tmax-t0)
225 h_poi_per_PCB.GetZaxis().SetRangeUser(0, 300)
226 xbin+=1
227 return[h_poi_per_PCB]
228
229
230def add_layer_lines(inputs):
231 h1 = inputs[0][1][0].Clone()
232 putLine(h1, 16, 0.5, 16, 16.5, offset=0, c=2)
233 putLine(h1, 32, 0.5, 32, 16.5, offset=0, c=2)
234 putLine(h1, 48, 0.5, 48, 16.5, offset=0, c=2)
235 putLine(h1, 64, 0.5, 64, 16.5, offset=0, c=2)
236 putLine(h1, 80, 0.5, 80, 16.5, offset=0, c=2)
237 putLine(h1, 96, 0.5, 96, 16.5, offset=0, c=2)
238 putLine(h1, 112, 0.5, 112, 16.5, offset=0, c=2)
239
240 h2 = inputs[0][1][1].Clone()
241 putLine(h2, 16, 0.5, 16, 16.5, offset=0, c=2)
242 putLine(h2, 32, 0.5, 32, 16.5, offset=0, c=2)
243 putLine(h2, 48, 0.5, 48, 16.5, offset=0, c=2)
244 putLine(h2, 64, 0.5, 64, 16.5, offset=0, c=2)
245 putLine(h2, 80, 0.5, 80, 16.5, offset=0, c=2)
246 putLine(h2, 96, 0.5, 96, 16.5, offset=0, c=2)
247 putLine(h2, 112, 0.5, 112, 16.5, offset=0, c=2)
248
249
250 return [h1, h2]
251
252def putLine(h, x1, y1, x2, y2, offset=0, c=1):
253 line = TLine(x1-offset, y1, x2-offset, y2)
254 line.SetLineColor(c)
255 line.SetLineStyle(2)
256 line.SetLineWidth(2)
257 h.GetListOfFunctions().Add(line)
258
if(febId1==febId2)
putLine(h, x1, y1, x2, y2, offset=0, c=1)
map_per_PCB(inputs, histo_name, start_index, proctype)
make_eff_histo_per_PCB(inputs)