30import modularAnalysis
as ma
31from stdV0s
import stdKshorts
32from stdPi0s
import stdPi0s
33from vertex
import TagV
38basf2.set_log_level(basf2.LogLevel.ERROR)
44 if sys.argv[1]
not in [
'train',
'test',
'apply_signal',
'apply_qqbar']:
45 sys.exit(
"usage:\n\tbasf2 B2A711-DeepContinuumSuppression_Input.py <train,test,apply_signal,apply_qqbar>")
47 step = str(sys.argv[1])
50 input_file_list = [basf2.find_file(
'ccbar_sample_to_train.root',
'examples',
False),
51 basf2.find_file(
'Bd2K0spi0_to_train.root',
'examples',
False)]
53 input_file_list = [basf2.find_file(
'ccbar_sample_to_test.root',
'examples',
False),
54 basf2.find_file(
'Bd2K0spi0_to_test.root',
'examples',
False)]
55elif step ==
'apply_signal':
56 input_file_list = [basf2.find_file(
'Bd2K0spi0_to_test.root',
'examples',
False)]
57elif step ==
'apply_qqbar':
58 input_file_list = [basf2.find_file(
'ccbar_sample_to_test.root',
'examples',
False)]
60 sys.exit(
'Step does not match any of the available samples: `train`, `test`, `apply_signal`or `apply_qqbar`')
62outfile =
'DNN_' + step +
'.root'
66firstpath = basf2.Path()
68ma.inputMdstList(input_file_list, path=firstpath)
70firstpath.add_module(
'ProgressBar')
73stdKshorts(path=firstpath)
74stdPi0s(
'eff40_May2020', path=firstpath)
75ma.reconstructDecay(
'B0 -> K_S0:merged pi0:eff40_May2020',
'5.2 < Mbc < 5.3 and -0.3 < deltaE < 0.2', path=firstpath)
77ma.matchMCTruth(
'B0', path=firstpath)
78ma.buildRestOfEvent(
'B0', path=firstpath)
80cleanMask = (
'cleanMask',
'nCDCHits > 0 and useCMSFrame(p)<=3.2',
'p >= 0.05 and useCMSFrame(p)<=3.2')
81ma.appendROEMasks(
'B0', [cleanMask], path=firstpath)
83ma.buildContinuumSuppression(
'B0',
'cleanMask', path=firstpath)
86ma.applyCuts(
'B0',
'isSignal or isContinuumEvent', path=firstpath)
89TagV(
'B0', path=firstpath)
92roe_path = basf2.create_path()
94deadEndPath = basf2.create_path()
96ma.signalSideParticleFilter(
'B0',
'', roe_path, deadEndPath)
99ma.fillParticleList(
'gamma:roe',
'isInRestOfEvent == 1 and goodBelleGamma == 1', path=roe_path)
100ma.fillParticleList(
'gamma:signal',
'isInRestOfEvent == 0 and goodBelleGamma == 1', path=roe_path)
101ma.fillParticleList(
'pi+:chargedProe',
'isInRestOfEvent == 1', path=roe_path)
102ma.fillParticleList(
'pi+:chargedPsignal',
'isInRestOfEvent == 0', path=roe_path)
103ma.fillParticleList(
'pi-:chargedMroe',
'isInRestOfEvent == 1', path=roe_path)
104ma.fillParticleList(
'pi-:chargedMsignal',
'isInRestOfEvent == 0', path=roe_path)
106v.variables.addAlias(
'cmsp',
'useCMSFrame(p)')
108ma.rankByHighest(
'gamma:roe',
'cmsp', path=roe_path)
109ma.rankByHighest(
'gamma:signal',
'cmsp', path=roe_path)
110ma.rankByHighest(
'pi+:chargedProe',
'cmsp', path=roe_path)
111ma.rankByHighest(
'pi+:chargedPsignal',
'cmsp', path=roe_path)
112ma.rankByHighest(
'pi-:chargedMroe',
'cmsp', path=roe_path)
113ma.rankByHighest(
'pi-:chargedMsignal',
'cmsp', path=roe_path)
123 'KSFWVariables(mm2)',
124 'KSFWVariables(hso00)',
125 'KSFWVariables(hso02)',
126 'KSFWVariables(hso04)',
127 'KSFWVariables(hso10)',
128 'KSFWVariables(hso12)',
129 'KSFWVariables(hso14)',
130 'KSFWVariables(hso20)',
131 'KSFWVariables(hso22)',
132 'KSFWVariables(hso24)',
133 'KSFWVariables(hoo0)',
134 'KSFWVariables(hoo1)',
135 'KSFWVariables(hoo2)',
136 'KSFWVariables(hoo3)',
137 'KSFWVariables(hoo4)',
150basic_variables = [
'p',
'phi',
'cosTheta',
'pErr',
'phiErr',
'cosThetaErr']
151vertex_variables = [
'distance',
'dphi',
'dcosTheta']
152cluster_specific_variables = [
'clusterNHits',
'clusterTiming',
'clusterE9E25',
'clusterReg',
'isInRestOfEvent']
153track_specific_variables = [
'kaonID',
'electronID',
'muonID',
'protonID',
'pValue',
'nCDCHits',
'isInRestOfEvent',
'charge']
156for variablename
in basic_variables + vertex_variables:
157 v.variables.addAlias(
'thrustsig' + variablename,
'useBThrustFrame(' + variablename +
',Signal)')
159cluster_variables = cluster_specific_variables[:]
160for variablename
in basic_variables:
161 cluster_variables.append(
'thrustsig' + variablename)
163track_variables = track_specific_variables
164for variablename
in basic_variables + vertex_variables:
165 track_variables.append(
'thrustsig' + variablename)
168variables = [
'isContinuumEvent',
'isNotContinuumEvent',
'isSignal',
'M',
'p',
'Mbc',
'DeltaZ',
169 'deltaE',
'daughter(0, M)',
'daughter(0, p)',
'daughter(1, M)',
'daughter(1, p)']
172for rank
in range(10):
173 for shortcut, particlelist
in [(
'Croe',
'gamma:roe'), (
'Csig',
'gamma:signal')]:
174 for variable
in cluster_variables:
175 v.variables.addAlias(
176 f
'{variable}_{shortcut}{rank}', f
'getVariableByRank({particlelist}, cmsp, {variable}, {rank + 1})')
177 variables.append(f
'{variable}_{shortcut}{rank}')
180 for shortcut, particlelist
in [(
'TProe',
'pi+:chargedProe'), (
'TPsig',
'pi+:chargedPsignal'),
181 (
'TMroe',
'pi+:chargedMroe'), (
'TMsig',
'pi+:chargedMsignal')]:
182 for variable
in track_variables:
183 v.variables.addAlias(
184 f
'{variable}_{shortcut}{rank}', f
'getVariableByRank({particlelist}, cmsp, {variable}, {rank + 1})')
185 variables.append(f
'{variable}_{shortcut}{rank}')
188ma.variablesToNtuple(
'B0', variables + contVars, treename=
'tree', filename=outfile, path=roe_path)
191firstpath.for_each(
'RestOfEvent',
'RestOfEvents', roe_path)
193basf2.process(firstpath)
194print(basf2.statistics)
198 with uproot.open(outfile)
as outf:
199 df = outf[
'tree'].arrays(library=
'pd')
200 df = df.sample(frac=1)
201 df.to_csv(outfile+
'.shuffled.csv')