9 Prepare CDC x-talk simulation DB object, usage:
11 python3 prepareAsicCrosstalkSimDB.py <input_asic_root> <output_path> <exp_num> <data_type>
13 input_asic_root: input path and files containing asic information,
14 produced by AsicBackgroundLibraryCreator.py
15 output_path: output path
16 exp_num: experiment number of raw data
or mc samples
22import matplotlib.pyplot as plt
24from scipy.interpolate import UnivariateSpline
27from ROOT.Belle2 import FileSystem
28from ROOT.Belle2 import CDCDatabaseImporter
29from ROOT import TH1F, TFile
33def getEff(var, cut, n=40, limits=(0., 2500.)):
34 ''' Simple efficiency estimator
35 var: pandas series/np array of variable to study
36 cut: bool series/np array pass/fail
38 limits : histogram limits
40 a = np.histogram(var, n, limits)
41 b = np.histogram(var[cut], n, limits)
44 effErr = 1/a[0]*np.sqrt(a[0]*eff*(1-eff))
45 x = 0.5*(a[1][1:]+a[1][:-1])
50bad_boards = {
'22': [24, 196],
51 '24': [0, 15, 24, 40, 117, 175, 196, 202, 86, 89],
54 '27': [92, 24, 51, 106, 53],
58 sys.exit(
"Four arguments are required: input_root, output_path, experiemnt numebr and data_type")
59InputFile = sys.argv[1]
60OutputPath = sys.argv[2]
62data_type = sys.argv[4]
65df = uproot.open(InputFile, flatten=
True)[
"ASIC"].arrays([
"Channel",
"ADC",
"Board",
"Nhit",
"Asic"], library=
"pd")
66df.columns = [
'_'.join(col)
if col[1] !=
'' else col[0]
for col
in df.columns.values]
68df[
'asic'] = df.Channel//8
70mask = df[
'Board'].isin([m
for m
in bad_boards[f
'{exp}']])
75u1 = getEff(df[(df.asic % 3 == 1)].ADC_ADC_Sig, df.Nhit > f
'{nhits}', 128, (0, 1024.))
77u2 = getEff(df[(df.asic % 3 == 1)].ADC_ADC_Sig, df.Nhit > f
'{nhits}', 8, (1024, 4096.))
79u = np.append(u1, u2, axis=1)
81plt.figure(figsize=(10, 4))
83x = np.nan_to_num(u[0])
85e = np.nan_to_num(u[1])
87ee = np.where(np.nan_to_num(u[2]) == 0, 1000., u[2])
90f = UnivariateSpline(x, e, 1/ee)
92xp = np.arange(-0.5, 4096.5, 1)
97plt.errorbar(x, e, u[2], fmt=
'.')
98plt.ylabel(f
'Fraction of Nhit>{nhits}')
99plt.title(f
'exp{exp} {data_type}')
105plt.errorbar(x, e, u[2], fmt=
'.', label=
'eff: asic=1,4; Nhit>3')
106plt.plot(xp, f(xp), label=
'spline fit')
109plt.savefig(f
'{OutputPath}/xTalkProb_{exp}_{data_type}.pdf')
113names = [
"Board",
"Channel",
'Nhit',
'asic']
115 names += [f
'Asic_ADC{i:d}', f
'Asic_TDC{i:d}', f
'Asic_TOT{i:d}']
117with uproot.recreate(f
'{OutputPath}/xTalkProb_{exp}_{data_type}.root')
as output:
118 df_tmp = df.query(
'nhit>3 & asic==1')
119 output[
'ASIC'] = uproot.newtree({name: df_tmp[name].dtype
for name
in names})
120 output[
'ASIC'].extend({name: df_tmp[name].values
for name
in names})
123fi = TFile(f
'{OutputPath}/xTalkProb_{exp}_{data_type}.root',
"update")
125t = TH1F(
"ProbXTalk",
"Prob xTalk", 4096, 0, 4096)
131INPUT = FileSystem.findFile(f
'{OutputPath}/xTalkProb_{exp}_{data_type}.root')
144basf2.conditions.testing_payloads = [f
'localdb/exp{exp}/database_{exp}.txt']
147main = basf2.create_path()
150eventinfosetter = basf2.register_module(
'EventInfoSetter')
151main.add_module(eventinfosetter)
158dbImporter.importCDCCrossTalkLibrary(INPUT)
160dbImporter.printCDCCrossTalkLibrary()
161dbImporter.testCDCCrossTalkLibrary()