1 ''' Prepare CDC x-talk simulation DB object '''
3 from root_pandas
import read_root
4 import matplotlib.pyplot
as plt
6 from scipy.interpolate
import UnivariateSpline
10 from ROOT.Belle2
import FileSystem
11 from ROOT.Belle2
import CDCDatabaseImporter
12 from ROOT
import TH1F, TFile
15 def getEff(var, cut, n=40, limits=(0., 2500.)):
16 ''' Simple efficiency estimator
17 var: pandas series/np array of variable to study
18 cut: bool series/np array pass/fail
20 limits : histogram limits
22 a = np.histogram(var, n, limits)
23 b = np.histogram(var[cut], n, limits)
27 effErr = 1/a[0]*np.sqrt(a[0]*eff*(1-eff))
28 x = 0.5*(a[1][1:]+a[1][:-1])
36 InputFile =
"cosmic.0008.03420_03427.root"
39 df = read_root(InputFile, columns=[
"Channel",
"ADC",
"Board",
"Nhit",
"Asic"])
40 df[
'asic'] = df.Channel//8
42 u1 =
getEff(df[(df.asic % 3 == 1)].ADC_ADC_Sig, df.Nhit > 1, 128, (0, 1024.))
44 u2 =
getEff(df[(df.asic % 3 == 1)].ADC_ADC_Sig, df.Nhit > 1, 16, (1024, 7800.))
46 u = np.append(u1, u2, axis=1)
51 x = np.nan_to_num(u[0])
53 e = np.nan_to_num(u[1])
55 ee = np.where(np.nan_to_num(u[2]) == 0, 1000., u[2])
58 f = UnivariateSpline(x, e, 1/ee)
61 xp = np.arange(-0.5, 8197.5, 1)
67 plt.errorbar(x, e, u[2], fmt=
'.')
68 plt.ylabel(
'Fraction of $N_{hit}>1$')
74 plt.errorbar(x, e, u[2], fmt=
'.')
77 plt.savefig(
"xTalkProb.pdf")
82 names = [
"Board",
"Channel"]
84 names += [
'Asic_ADC{:d}'.format(i),
'Asic_TDC{:d}'.format(i),
'Asic_TOT{:d}'.format(i)]
86 df[(df.Nhit > 1) & (df.asic % 3 == 1)][names].to_root(
"t.root", index=
False)
88 fi = TFile(
"t.root",
"update")
90 t = TH1F(
"ProbXTalk",
"Prob xTalk", 8196, 0, 8196)
96 INPUT = FileSystem.findFile(
"t.root")
108 basf2.use_local_database(
"localdb/database.txt",
"localdb")
111 main = basf2.create_path()
114 eventinfosetter = basf2.register_module(
'EventInfoSetter')
115 main.add_module(eventinfosetter)
122 dbImporter.importCDCCrossTalkLibrary(INPUT)
124 dbImporter.printCDCCrossTalkLibrary()
125 dbImporter.testCDCCrossTalkLibrary()