|
16 | 16 | main script for doing data processing, machine learning and analysis |
17 | 17 | """ |
18 | 18 | import math |
19 | | -import array |
| 19 | +from array import array |
20 | 20 | import pickle |
21 | 21 | import pandas as pd |
22 | 22 | import numpy as np |
@@ -54,46 +54,55 @@ def __init__(self, case, datap, run_param, mcordata, p_maxfiles, |
54 | 54 | self.l_selml = ["y_test_prob%s>%s" % (self.p_modelname, self.lpt_probcutfin[ipt]) \ |
55 | 55 | for ipt in range(self.p_nptbins)] |
56 | 56 |
|
| 57 | + # first variable (hadron pt) |
| 58 | + self.v_var_binning = datap["var_binning"] # name |
| 59 | + self.lpt_finbinmin = datap["analysis"][self.typean]["sel_an_binmin"] |
| 60 | + self.lpt_finbinmax = datap["analysis"][self.typean]["sel_an_binmax"] |
| 61 | + self.p_nptfinbins = len(self.lpt_finbinmin) # number of bins |
| 62 | + self.bin_matching = datap["analysis"][self.typean]["binning_matching"] |
| 63 | + self.var1ranges = self.lpt_finbinmin.copy() |
| 64 | + self.var1ranges.append(self.lpt_finbinmax[-1]) |
| 65 | + self.var1binarray = array("d", self.var1ranges) # array of bin edges to use in histogram constructors |
| 66 | + |
57 | 67 | # second variable (jet pt) |
58 | 68 | self.v_var2_binning = datap["analysis"][self.typean]["var_binning2"] # name |
59 | 69 | self.lvar2_binmin_reco = datap["analysis"][self.typean].get("sel_binmin2_reco", None) |
60 | 70 | self.lvar2_binmax_reco = datap["analysis"][self.typean].get("sel_binmax2_reco", None) |
61 | | - self.p_nbin2_reco = len(self.lvar2_binmin_reco) |
| 71 | + self.p_nbin2_reco = len(self.lvar2_binmin_reco) # number of reco bins |
62 | 72 | self.lvar2_binmin_gen = datap["analysis"][self.typean].get("sel_binmin2_gen", None) |
63 | 73 | self.lvar2_binmax_gen = datap["analysis"][self.typean].get("sel_binmax2_gen", None) |
64 | | - self.p_nbin2_gen = len(self.lvar2_binmin_gen) |
| 74 | + self.p_nbin2_gen = len(self.lvar2_binmin_gen) # number of gen bins |
| 75 | + self.var2ranges_reco = self.lvar2_binmin_reco.copy() |
| 76 | + self.var2ranges_reco.append(self.lvar2_binmax_reco[-1]) |
| 77 | + self.var2binarray_reco = array("d", self.var2ranges_reco) # array of bin edges to use in histogram constructors |
| 78 | + self.var2ranges_gen = self.lvar2_binmin_gen.copy() |
| 79 | + self.var2ranges_gen.append(self.lvar2_binmax_gen[-1]) |
| 80 | + self.var2binarray_gen = array("d", self.var2ranges_gen) # array of bin edges to use in histogram constructors |
65 | 81 |
|
66 | 82 | # observable (z, shape,...) |
67 | 83 | self.v_varshape_binning = datap["analysis"][self.typean]["var_binningshape"] # name (reco) |
68 | 84 | self.v_varshape_binning_gen = datap["analysis"][self.typean]["var_binningshape_gen"] # name (gen) |
69 | | - self.v_varshape_latex = datap["analysis"][self.typean]["var_shape_latex"] # LaTeX name |
70 | 85 | self.lvarshape_binmin_reco = \ |
71 | 86 | datap["analysis"][self.typean].get("sel_binminshape_reco", None) |
72 | 87 | self.lvarshape_binmax_reco = \ |
73 | 88 | datap["analysis"][self.typean].get("sel_binmaxshape_reco", None) |
74 | | - self.p_nbinshape_reco = len(self.lvarshape_binmin_reco) |
75 | | - self.lvarshape_binmin_gen = datap["analysis"][self.typean].get("sel_binminshape_gen", None) |
76 | | - self.lvarshape_binmax_gen = datap["analysis"][self.typean].get("sel_binmaxshape_gen", None) |
77 | | - self.p_nbinshape_gen = len(self.lvarshape_binmin_gen) |
78 | | - |
79 | | - self.closure_frac = datap["analysis"][self.typean].get("sel_closure_frac", None) |
80 | | - |
81 | | - self.var2ranges_reco = self.lvar2_binmin_reco.copy() |
82 | | - self.var2ranges_reco.append(self.lvar2_binmax_reco[-1]) |
83 | | - self.var2ranges_gen = self.lvar2_binmin_gen.copy() |
84 | | - self.var2ranges_gen.append(self.lvar2_binmax_gen[-1]) |
| 89 | + self.p_nbinshape_reco = len(self.lvarshape_binmin_reco) # number of reco bins |
| 90 | + self.lvarshape_binmin_gen = \ |
| 91 | + datap["analysis"][self.typean].get("sel_binminshape_gen", None) |
| 92 | + self.lvarshape_binmax_gen = \ |
| 93 | + datap["analysis"][self.typean].get("sel_binmaxshape_gen", None) |
| 94 | + self.p_nbinshape_gen = len(self.lvarshape_binmin_gen) # number of gen bins |
85 | 95 | self.varshaperanges_reco = self.lvarshape_binmin_reco.copy() |
86 | 96 | self.varshaperanges_reco.append(self.lvarshape_binmax_reco[-1]) |
| 97 | + self.varshapebinarray_reco = array("d", self.varshaperanges_reco) # array of bin edges to use in histogram constructors |
87 | 98 | self.varshaperanges_gen = self.lvarshape_binmin_gen.copy() |
88 | 99 | self.varshaperanges_gen.append(self.lvarshape_binmax_gen[-1]) |
| 100 | + self.varshapebinarray_gen = array("d", self.varshaperanges_gen) # array of bin edges to use in histogram constructors |
89 | 101 |
|
| 102 | + self.closure_frac = datap["analysis"][self.typean].get("sel_closure_frac", None) |
90 | 103 | self.doprior = datap["analysis"][self.typean]["doprior"] |
91 | 104 |
|
92 | | - self.lpt_finbinmin = datap["analysis"][self.typean]["sel_an_binmin"] |
93 | | - self.lpt_finbinmax = datap["analysis"][self.typean]["sel_an_binmax"] |
94 | | - self.p_nptfinbins = len(self.lpt_finbinmin) |
95 | | - self.bin_matching = datap["analysis"][self.typean]["binning_matching"] |
96 | | - #self.sel_final_fineptbins = datap["analysis"][self.typean]["sel_final_fineptbins"] |
| 105 | + # selection |
97 | 106 | self.s_evtsel = datap["analysis"][self.typean]["evtsel"] |
98 | 107 | self.s_jetsel_gen = datap["analysis"][self.typean]["jetsel_gen"] |
99 | 108 | self.s_jetsel_reco = datap["analysis"][self.typean]["jetsel_reco"] |
@@ -163,8 +172,8 @@ def process_histomass_single(self, index): |
163 | 172 | h_invmass.Write() |
164 | 173 |
|
165 | 174 | massarray = [1.0 + i * (5.0 / 5000.0) for i in range(5001)] # 5000 bins in range 1.0-6.0 |
166 | | - massarray_reco = array.array('d', massarray) |
167 | | - zarray_reco = array.array('d', self.varshaperanges_reco) |
| 175 | + massarray_reco = array('d', massarray) |
| 176 | + zarray_reco = array('d', self.varshaperanges_reco) |
168 | 177 | h_zvsinvmass = TH2F("hzvsmass" + suffix, "", \ |
169 | 178 | 5000, massarray_reco, self.p_nbinshape_reco, zarray_reco) |
170 | 179 | h_zvsinvmass.Sumw2() |
@@ -197,7 +206,7 @@ def process_efficiency_single(self, index): |
197 | 206 | n_bins = self.p_nptfinbins |
198 | 207 | analysis_bin_lims_temp = self.lpt_finbinmin.copy() |
199 | 208 | analysis_bin_lims_temp.append(self.lpt_finbinmax[n_bins-1]) |
200 | | - analysis_bin_lims = array.array('f', analysis_bin_lims_temp) |
| 209 | + analysis_bin_lims = array('f', analysis_bin_lims_temp) |
201 | 210 | h_gen_pr = TH1F("h_gen_pr" + stringbin2, "Prompt Generated in acceptance |y|<0.5", \ |
202 | 211 | n_bins, analysis_bin_lims) |
203 | 212 | h_presel_pr = TH1F("h_presel_pr" + stringbin2, "Prompt Reco in acc |#eta|<0.8 and sel", \ |
@@ -338,27 +347,27 @@ def process_response_single(self, index): # pylint: disable=too-many-locals |
338 | 347 | zbin_reco = [] |
339 | 348 | nzbin_reco = self.p_nbinshape_reco |
340 | 349 | zbin_reco = self.varshaperanges_reco |
341 | | - zbinarray_reco = array.array('d', zbin_reco) |
| 350 | + zbinarray_reco = array('d', zbin_reco) |
342 | 351 |
|
343 | 352 | zbin_gen = [] |
344 | 353 | nzbin_gen = self.p_nbinshape_gen |
345 | 354 | zbin_gen = self.varshaperanges_gen |
346 | | - zbinarray_gen = array.array('d', zbin_gen) |
| 355 | + zbinarray_gen = array('d', zbin_gen) |
347 | 356 |
|
348 | 357 | jetptbin_reco = [] |
349 | 358 | njetptbin_reco = self.p_nbin2_reco |
350 | 359 | jetptbin_reco = self.var2ranges_reco |
351 | | - jetptbinarray_reco = array.array('d', jetptbin_reco) |
| 360 | + jetptbinarray_reco = array('d', jetptbin_reco) |
352 | 361 |
|
353 | 362 | jetptbin_gen = [] |
354 | 363 | njetptbin_gen = self.p_nbin2_gen |
355 | 364 | jetptbin_gen = self.var2ranges_gen |
356 | | - jetptbinarray_gen = array.array('d', jetptbin_gen) |
| 365 | + jetptbinarray_gen = array('d', jetptbin_gen) |
357 | 366 |
|
358 | 367 | candptbin = [] |
359 | 368 | candptbin = self.lpt_finbinmin.copy() |
360 | 369 | candptbin.append(self.lpt_finbinmax[-1]) |
361 | | - candptbinarray = array.array('d', candptbin) |
| 370 | + candptbinarray = array('d', candptbin) |
362 | 371 |
|
363 | 372 | out_file = TFile.Open(self.l_historesp[index], "recreate") |
364 | 373 | list_df_mc_reco = [] |
|
0 commit comments