forked from lbariogl/NucleiFlow
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresolution.py
More file actions
410 lines (349 loc) · 12.5 KB
/
resolution.py
File metadata and controls
410 lines (349 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
from itertools import combinations
import yaml
import argparse
import numpy as np
import ROOT
import sys
sys.path.append("utils")
import utils as utils
parser = argparse.ArgumentParser(description="Configure the parameters of the script.")
parser.add_argument(
"--config",
dest="config_file",
help="path to the YAML file with configuration.",
default="",
)
args = parser.parse_args()
if args.config_file == "":
print("** No config file provided. Exiting. **")
exit()
config_file = open(args.config_file, "r")
config = yaml.full_load(config_file)
output_dir = config["output_dir_name"]
input_file_AR_name = config["input_file_AR_name"]
input_file = ROOT.TFile(input_file_AR_name)
ref_names = ["FT0C", "FT0A", "TPCl", "TPCr", "TPC"]
use_EP_tables = True
hSP_dict_EP = {}
hProfile_dict_EP = {}
cSpProfile_dict_EP = {}
hResolution_dict_EP = {}
hSP_dict_SP = {}
hProfile_dict_SP = {}
cSpProfile_dict_SP = {}
hResolution_dict_SP = {}
cent_bins = np.array(
[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0], dtype=np.float64
)
n_cent_bins = len(cent_bins) - 1
def getResolution(
histo_resolution, det1_det2_name, det2_det3_name, det1_det3_name, hProfile_dict
):
histo_resolution.GetYaxis().SetRangeUser(0.0, 1.0)
n_bins = histo_resolution.GetNbinsX()
for ibin in range(1, n_bins + 1):
val1_2 = hProfile_dict[det1_det2_name].GetBinContent(ibin)
val2_3 = hProfile_dict[det2_det3_name].GetBinContent(ibin)
val1_3 = hProfile_dict[det1_det3_name].GetBinContent(ibin)
err1_2 = hProfile_dict[det1_det2_name].GetBinError(ibin)
err2_3 = hProfile_dict[det2_det3_name].GetBinError(ibin)
err1_3 = hProfile_dict[det1_det3_name].GetBinError(ibin)
if val2_3 > 0:
val = val1_2 * val1_3 / val2_3
else:
val = -999
if val2_3 > 0 and val1_2 > 0 and val2_3 > 0:
err = (
np.sqrt(
err1_2 * err1_2 / val1_2 / val1_2
+ err2_3 * err2_3 / val2_3 / val2_3
+ err1_3 * err1_3 / val1_3 / val1_3
)
* val
)
else:
err = 0
if val > 0:
histo_resolution.SetBinContent(ibin, np.sqrt(val))
histo_resolution.SetBinError(ibin, np.sqrt(err))
def doAllPlots(
det_name1,
det_name2,
det_name3,
ep_table=True,
use_SP=False,
hSP_dict=hSP_dict_EP,
hProfile_dict=hProfile_dict_EP,
cSpProfile_dict=cSpProfile_dict_EP,
hResolution_dict=hResolution_dict_EP,
):
if ep_table:
print("** Using EP tables **")
directory = "flow_ep"
input_suffix = "EP"
else:
print("** Using Qvector tables **")
directory = "flow_qvec"
input_suffix = "Qvec"
if use_SP:
print("** Using scalar product **")
histo_name = "hScalarProduct"
output_suffix = "SP"
else:
print("** Using event plane **")
histo_name = "hNormalisedScalarProduct"
output_suffix = "EP"
# first combination
det1_det2_name = f"{det_name1}_{det_name2}"
if det1_det2_name not in hSP_dict.keys():
hSP_dict[det1_det2_name] = input_file.Get(
f"flow-qc/{directory}/{histo_name}_{det1_det2_name}_{input_suffix}"
)
hSP_dict[det1_det2_name].RebinX(10)
hProfile_dict[det1_det2_name] = hSP_dict[det1_det2_name].ProfileX(
f"hProfile_{det1_det2_name}_{output_suffix}"
)
utils.setHistStyle(hProfile_dict[det1_det2_name], ROOT.kRed)
cSpProfile_dict[det1_det2_name] = ROOT.TCanvas(
f"cSpProfile_{det1_det2_name}_{output_suffix}",
f"cSpProfile_{det1_det2_name}_{output_suffix}",
800,
600,
)
hSP_dict[det1_det2_name].Draw("colz")
hProfile_dict[det1_det2_name].Draw("pe same")
# second combination
det2_det3_name = f"{det_name2}_{det_name3}"
if det2_det3_name not in hSP_dict.keys():
hSP_dict[det2_det3_name] = input_file.Get(
f"flow-qc/{directory}/{histo_name}_{det2_det3_name}_{input_suffix}"
)
hSP_dict[det2_det3_name].RebinX(10)
hProfile_dict[det2_det3_name] = hSP_dict[det2_det3_name].ProfileX(
f"hProfile_{det2_det3_name}_{output_suffix}"
)
utils.setHistStyle(hProfile_dict[det2_det3_name], ROOT.kRed)
cSpProfile_dict[det2_det3_name] = ROOT.TCanvas(
f"cSpProfile_{det2_det3_name}_{output_suffix}",
f"cSpProfile_{det2_det3_name}_{output_suffix}",
800,
600,
)
hSP_dict[det2_det3_name].Draw("colz")
hProfile_dict[det2_det3_name].Draw("pe same")
# third combination
det1_det3_name = f"{det_name1}_{det_name3}"
if det1_det3_name not in hSP_dict.keys():
hSP_dict[det1_det3_name] = input_file.Get(
f"flow-qc/{directory}/{histo_name}_{det1_det3_name}_{input_suffix}"
)
hSP_dict[det1_det3_name].RebinX(10)
hProfile_dict[det1_det3_name] = hSP_dict[det1_det3_name].ProfileX(
f"hProfile_{det1_det3_name}_{output_suffix}"
)
utils.setHistStyle(hProfile_dict[det1_det3_name], ROOT.kRed)
cSpProfile_dict[det1_det3_name] = ROOT.TCanvas(
f"cSpProfile_{det1_det3_name}_{output_suffix}",
f"cSpProfile_{det1_det3_name}_{output_suffix}",
800,
600,
)
hSP_dict[det1_det3_name].Draw("colz")
hProfile_dict[det1_det3_name].Draw("pe same")
# evaluate resolutions
n_bins = hSP_dict[det1_det2_name].GetNbinsX()
cent_axis_limits = [
hSP_dict[det1_det2_name].GetXaxis().GetBinLowEdge(1),
hSP_dict[det1_det2_name].GetXaxis().GetBinUpEdge(n_bins),
]
cent_axis_title = hSP_dict[det1_det2_name].GetXaxis().GetTitle()
resolution_name1 = f"{det_name1}_{det_name2}_{det_name3}"
resolution_title1 = r"R_{2} " + f"({det_name1}#; {det_name2}, {det_name3})"
print(f"Creating resolution {resolution_name1}")
hResolution_dict[resolution_name1] = ROOT.TH1F(
f"hResolution_{resolution_name1}_{output_suffix}",
f";{cent_axis_title};{resolution_title1}",
n_bins,
cent_axis_limits[0],
cent_axis_limits[1],
)
getResolution(
hResolution_dict[resolution_name1],
det1_det2_name,
det2_det3_name,
det1_det3_name,
hProfile_dict,
)
utils.setHistStyle(hResolution_dict[resolution_name1], ROOT.kRed)
resolution_name2 = f"{det_name2}_{det_name3}_{det_name1}"
resolution_title2 = r"R_{2} " + f"({det_name2}#; {det_name1}, {det_name3})"
print(f"Creating resolution {resolution_name2}")
hResolution_dict[resolution_name2] = ROOT.TH1F(
f"hResolution_{resolution_name2}_{output_suffix}",
f";{cent_axis_title};{resolution_title2}",
n_bins,
cent_axis_limits[0],
cent_axis_limits[1],
)
getResolution(
hResolution_dict[resolution_name2],
det2_det3_name,
det1_det3_name,
det1_det2_name,
hProfile_dict,
)
utils.setHistStyle(hResolution_dict[resolution_name2], ROOT.kRed)
resolution_name3 = f"{det_name3}_{det_name1}_{det_name2}"
resolution_title3 = r"R_{2} " + f"({det_name3}#; {det_name1}, {det_name2})"
print(f"Creating resolution {resolution_name3}")
hResolution_dict[resolution_name3] = ROOT.TH1F(
f"hResolution_{resolution_name3}_{output_suffix}",
f";{cent_axis_title};{resolution_title3}",
n_bins,
cent_axis_limits[0],
cent_axis_limits[1],
)
getResolution(
hResolution_dict[resolution_name3],
det1_det3_name,
det1_det2_name,
det2_det3_name,
hProfile_dict,
)
utils.setHistStyle(hResolution_dict[resolution_name3], ROOT.kRed)
# rebin histograms
det_combos = list(combinations(ref_names, 3))
for det_combo in det_combos:
doAllPlots(
det_combo[0],
det_combo[1],
det_combo[2],
use_EP_tables,
use_SP=False,
hSP_dict=hSP_dict_EP,
hProfile_dict=hProfile_dict_EP,
cSpProfile_dict=cSpProfile_dict_EP,
hResolution_dict=hResolution_dict_EP,
)
doAllPlots(
det_combo[0],
det_combo[1],
det_combo[2],
use_EP_tables,
use_SP=True,
hSP_dict=hSP_dict_SP,
hProfile_dict=hProfile_dict_SP,
cSpProfile_dict=cSpProfile_dict_SP,
hResolution_dict=hResolution_dict_SP,
)
if use_EP_tables:
output_file_name = output_dir + "resolution_EP.root"
else:
output_file_name = output_dir + "resolution_Qvec.root"
output_file = ROOT.TFile(output_file_name, "recreate")
SP_dir_EP = output_file.mkdir("SP_normalised")
SP_dir_SP = output_file.mkdir("SP")
Resolution_EP_dir = output_file.mkdir("Resolution_EP")
Resolution_SP_dir = output_file.mkdir("Resolution_SP")
SP_dir_EP.cd()
for key in hSP_dict_EP.keys():
hSP_dict_EP[key].Write()
hProfile_dict_EP[key].Write()
cSpProfile_dict_EP[key].Write()
SP_dir_SP.cd()
for key in hSP_dict_SP.keys():
hSP_dict_SP[key].Write()
hProfile_dict_SP[key].Write()
cSpProfile_dict_SP[key].Write()
Resolution_EP_dir.cd()
for res in hResolution_dict_EP.values():
res.Write()
Resolution_SP_dir.cd()
for res in hResolution_dict_SP.values():
res.Write()
# check sourav
input_file_sourav = ROOT.TFile("../sourav_check/AnalysisResults.root")
print("Sourav check")
hSP_dict_Sourav = {}
hProfile_dict_Sourav = {}
cSpProfile_dict_Sourav = {}
hResolution_dict_Sourav = {}
hSP_FT0C_TPC = input_file_sourav.Get("phipbpb/ResSPFT0CTPC").Project3D("zx")
hSP_FT0C_TPC.SetName("hScalarProduct_FT0C_TPC_Sourav")
hSP_FT0C_TPC.SetTitle(r";centrality (%); #vec{Q}_{2}^{FT0C} #upoint #vec{Q}_{2}^{TPC}")
# hSP_FT0C_TPC.GetYaxis().SetRangeUser(-2.0, 2.0)
hSP_dict_Sourav["FT0C_TPC"] = hSP_FT0C_TPC
hProfile_dict_Sourav["FT0C_TPC"] = hSP_FT0C_TPC.ProfileX("hProfile_FT0C_TPC_Sourav")
utils.setHistStyle(hProfile_dict_Sourav["FT0C_TPC"], ROOT.kRed)
cSpProfile_dict_Sourav["FT0C_TPC"] = ROOT.TCanvas(
"cSpProfile_FT0C_TPC_Sourav",
"cSpProfile_FT0C_TPC_Sourav",
800,
600,
)
hSP_FT0C_TPC.Draw("colz")
hProfile_dict_Sourav["FT0C_TPC"].Draw("pe same")
hSP_FT0C_FT0A = input_file_sourav.Get("phipbpb/ResSPFT0CFT0A").Project3D("zx")
hSP_FT0C_FT0A.SetName("hScalarProduct_FT0C_FT0A_Sourav")
hSP_FT0C_FT0A.SetTitle(
r";centrality (%); #vec{Q}_{2}^{FT0C} #upoint #vec{Q}_{2}^{FT0A}"
)
# hSP_FT0C_FT0A.GetYaxis().SetRangeUser(-2.0, 2.0)
hSP_dict_Sourav["FT0C_FT0A"] = hSP_FT0C_FT0A
hProfile_dict_Sourav["FT0C_FT0A"] = hSP_FT0C_FT0A.ProfileX("hProfile_FT0C_FT0A_Sourav")
utils.setHistStyle(hProfile_dict_Sourav["FT0C_FT0A"], ROOT.kRed)
cSpProfile_dict_Sourav["FT0C_FT0A"] = ROOT.TCanvas(
"cSpProfile_FT0C_FT0A_Sourav",
"cSpProfile_FT0C_FT0A_Sourav",
800,
600,
)
hSP_FT0C_FT0A.Draw("colz")
hProfile_dict_Sourav["FT0C_FT0A"].Draw("pe same")
hSP_FT0A_TPC = input_file_sourav.Get("phipbpb/ResSPFT0ATPC").Project3D("zx")
hSP_FT0A_TPC.SetName("hScalarProduct_FT0A_TPC_Sourav")
hSP_FT0A_TPC.SetTitle(r";centrality (%); #vec{Q}_{2}^{FT0A} #upoint #vec{Q}_{2}^{TPC}")
# hSP_FT0A_TPC.GetYaxis().SetRangeUser(-2.0, 2.0)
hSP_dict_Sourav["FT0A_TPC"] = hSP_FT0A_TPC
hProfile_dict_Sourav["FT0A_TPC"] = hSP_FT0A_TPC.ProfileX("hProfile_FT0A_TPC_Sourav")
utils.setHistStyle(hProfile_dict_Sourav["FT0A_TPC"], ROOT.kRed)
cSpProfile_dict_Sourav["FT0A_TPC"] = ROOT.TCanvas(
"cSpProfile_FT0A_TPC_Sourav",
"cSpProfile_FT0A_TPC_Sourav",
800,
600,
)
hSP_FT0A_TPC.Draw("colz")
hProfile_dict_Sourav["FT0A_TPC"].Draw("pe same")
n_bins = hSP_dict_Sourav["FT0C_TPC"].GetNbinsX()
cent_axis_limits = [
hSP_dict_Sourav["FT0C_TPC"].GetXaxis().GetBinLowEdge(1),
hSP_dict_Sourav["FT0C_TPC"].GetXaxis().GetBinUpEdge(n_bins),
]
cent_axis_title = hSP_dict_Sourav["FT0C_TPC"].GetXaxis().GetTitle()
resolution_name1 = "FT0C_FT0A_TPC"
resolution_title1 = r"R_{2} (FT0C#; FT0A, TPC)"
print(f"Creating resolution {resolution_name1}")
hResolution_dict_Sourav[resolution_name1] = ROOT.TH1F(
f"hResolution_{resolution_name1}_Sourav",
f";{cent_axis_title};{resolution_title1}",
n_bins,
cent_axis_limits[0],
cent_axis_limits[1],
)
getResolution(
hResolution_dict_Sourav[resolution_name1],
"FT0C_TPC",
"FT0A_TPC",
"FT0C_FT0A",
hProfile_dict_Sourav,
)
utils.setHistStyle(hResolution_dict_Sourav[resolution_name1], ROOT.kRed)
Sourav_dir = output_file.mkdir("Sourav")
Sourav_dir.cd()
for key in hSP_dict_Sourav.keys():
hSP_dict_Sourav[key].Write()
hProfile_dict_Sourav[key].Write()
cSpProfile_dict_Sourav[key].Write()
for res in hResolution_dict_Sourav.values():
res.Write()