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 import Belle2
28from ROOT.Belle2
import FileSystem
29from ROOT.Belle2
import CDCDatabaseImporter
30from ROOT
import TH1F, TFile
34def getEff(var, cut, n=40, limits=(0., 2500.)):
35 ''' Simple efficiency estimator
36 var: pandas series/np array of variable to study
37 cut: bool series/np array pass/fail
39 limits : histogram limits
41 a = np.histogram(var, n, limits)
42 b = np.histogram(var[cut], n, limits)
45 effErr = 1/a[0]*np.sqrt(a[0]*eff*(1-eff))
46 x = 0.5*(a[1][1:]+a[1][:-1])
51bad_boards = {
'22': [24, 196],
52 '24': [0, 15, 24, 40, 117, 175, 196, 202, 86, 89],
55 '27': [92, 24, 51, 106, 53],
59 sys.exit(
"Four arguments are required: input_root, output_path, experiemnt numebr and data_type")
60InputFile = sys.argv[1]
61OutputPath = sys.argv[2]
63data_type = sys.argv[4]
66df = uproot.open(InputFile, flatten=
True)[
"ASIC"].arrays([
"Channel",
"ADC",
"Board",
"Nhit",
"Asic"], library=
"pd")
67df.columns = [
'_'.join(col)
if col[1] !=
'' else col[0]
for col
in df.columns.values]
69df[
'asic'] = df.Channel//8
71mask = df[
'Board'].isin([m
for m
in bad_boards[f
'{exp}']])
76u1 = getEff(df[(df.asic % 3 == 1)].ADC_ADC_Sig, df.Nhit > f
'{nhits}', 128, (0, 1024.))
78u2 = getEff(df[(df.asic % 3 == 1)].ADC_ADC_Sig, df.Nhit > f
'{nhits}', 8, (1024, 4096.))
80u = np.append(u1, u2, axis=1)
82plt.figure(figsize=(10, 4))
84x = np.nan_to_num(u[0])
86e = np.nan_to_num(u[1])
88ee = np.where(np.nan_to_num(u[2]) == 0, 1000., u[2])
91f = UnivariateSpline(x, e, 1/ee)
93xp = np.arange(-0.5, 4096.5, 1)
98plt.errorbar(x, e, u[2], fmt=
'.')
99plt.ylabel(f
'Fraction of Nhit>{nhits}')
100plt.title(f
'exp{exp} {data_type}')
106plt.errorbar(x, e, u[2], fmt=
'.', label=
'eff: asic=1,4; Nhit>3')
107plt.plot(xp, f(xp), label=
'spline fit')
110plt.savefig(f
'{OutputPath}/xTalkProb_{exp}_{data_type}.pdf')
114names = [
"Board",
"Channel",
'Nhit',
'asic']
116 names += [f
'Asic_ADC{i:d}', f
'Asic_TDC{i:d}', f
'Asic_TOT{i:d}']
118with uproot.recreate(f
'{OutputPath}/xTalkProb_{exp}_{data_type}.root')
as output:
119 df_tmp = df.query(
'nhit>3 & asic==1')
120 output[
'ASIC'] = uproot.newtree({name: df_tmp[name].dtype
for name
in names})
121 output[
'ASIC'].extend({name: df_tmp[name].values
for name
in names})
124fi = TFile(f
'{OutputPath}/xTalkProb_{exp}_{data_type}.root',
"update")
126t = TH1F(
"ProbXTalk",
"Prob xTalk", 4096, 0, 4096)
132INPUT = FileSystem.findFile(f
'{OutputPath}/xTalkProb_{exp}_{data_type}.root')
145basf2.conditions.testing_payloads = [f
'localdb/exp{exp}/database_{exp}.txt']
148main = basf2.create_path()
151eventinfosetter = basf2.register_module(
'EventInfoSetter')
152main.add_module(eventinfosetter)
159dbImporter.importCDCCrossTalkLibrary(INPUT)
161dbImporter.printCDCCrossTalkLibrary()
162dbImporter.testCDCCrossTalkLibrary()