8 ''' Prepare CDC x-talk simulation DB object '''
11 import matplotlib.pyplot
as plt
13 from scipy.interpolate
import UnivariateSpline
16 from ROOT.Belle2
import FileSystem
17 from ROOT.Belle2
import CDCDatabaseImporter
18 from ROOT
import TH1F, TFile
21 def getEff(var, cut, n=40, limits=(0., 2500.)):
22 ''' Simple efficiency estimator
23 var: pandas series/np array of variable to study
24 cut: bool series/np array pass/fail
26 limits : histogram limits
28 a = np.histogram(var, n, limits)
29 b = np.histogram(var[cut], n, limits)
33 effErr = 1/a[0]*np.sqrt(a[0]*eff*(1-eff))
34 x = 0.5*(a[1][1:]+a[1][:-1])
42 InputFile =
"cosmic.0008.03420_03427.root"
45 df = uproot.open(InputFile)[
"tree"].arrays([
"Channel",
"ADC",
"Board",
"Nhit",
"Asic"], library=
"pd")
46 df[
'asic'] = df.Channel//8
48 u1 = getEff(df[(df.asic % 3 == 1)].ADC_ADC_Sig, df.Nhit > 1, 128, (0, 1024.))
50 u2 = getEff(df[(df.asic % 3 == 1)].ADC_ADC_Sig, df.Nhit > 1, 16, (1024, 7800.))
52 u = np.append(u1, u2, axis=1)
57 x = np.nan_to_num(u[0])
59 e = np.nan_to_num(u[1])
61 ee = np.where(np.nan_to_num(u[2]) == 0, 1000., u[2])
64 f = UnivariateSpline(x, e, 1/ee)
67 xp = np.arange(-0.5, 8197.5, 1)
73 plt.errorbar(x, e, u[2], fmt=
'.')
74 plt.ylabel(
'Fraction of $N_{hit}>1$')
80 plt.errorbar(x, e, u[2], fmt=
'.')
83 plt.savefig(
"xTalkProb.pdf")
88 names = [
"Board",
"Channel"]
90 names += [
'Asic_ADC{:d}'.format(i),
'Asic_TDC{:d}'.format(i),
'Asic_TOT{:d}'.format(i)]
92 df[(df.Nhit > 1) & (df.asic % 3 == 1)][names].to_root(
"t.root", index=
False)
94 fi = TFile(
"t.root",
"update")
96 t = TH1F(
"ProbXTalk",
"Prob xTalk", 8196, 0, 8196)
102 INPUT = FileSystem.findFile(
"t.root")
114 basf2.use_local_database(
"localdb/database.txt",
"localdb")
117 main = basf2.create_path()
120 eventinfosetter = basf2.register_module(
'EventInfoSetter')
121 main.add_module(eventinfosetter)
128 dbImporter.importCDCCrossTalkLibrary(INPUT)
130 dbImporter.printCDCCrossTalkLibrary()
131 dbImporter.testCDCCrossTalkLibrary()