22 import modularAnalysis
as ma
23 from vertex
import TagV
29 from root_pandas
import read_root, to_root
32 basf2.set_log_level(basf2.LogLevel.ERROR)
35 if (len(sys.argv) < 2
or sys.argv[1]
not in [
'train',
'test',
'apply_signal',
'apply_qqbar']):
36 sys.exit(
"usage:\n\tbasf2 B2A701-ContinuumSuppression_Input.py <train,test,apply_signal,apply_qqbar>")
38 step = str(sys.argv[1])
40 path =
'/group/belle2/tutorial/release_01-00-00/DCS_Bd_KsPi0'
41 train_inputfiles = glob.glob(path +
'/*/*/*8.root.mdst')
42 val_inputfiles = glob.glob(path +
'/*/*/*2.root.mdst')
43 signal_inputfiles = glob.glob(path +
'/*/*/*1.root.mdst')
44 qqbar_inputfiles = glob.glob(path +
'/*/*/*7.root.mdst')
47 np.random.shuffle(train_inputfiles)
48 np.random.shuffle(val_inputfiles)
49 np.random.shuffle(signal_inputfiles)
50 np.random.shuffle(qqbar_inputfiles)
53 input = train_inputfiles
55 input = val_inputfiles
56 elif step ==
'apply_signal':
57 input = signal_inputfiles
58 elif step ==
'apply_qqbar':
59 input = qqbar_inputfiles
61 sys.exit(
'Step does not match any of the available samples: `train`, `test`, `apply_signal`or `apply_qqbar`')
63 outfile = step +
'.root'
67 firstpath = basf2.Path()
69 ma.inputMdstList(
'default', input, path=firstpath)
71 firstpath.add_module(
'ProgressBar')
74 ma.fillParticleList(
'gamma',
'goodGamma == 1', path=firstpath)
76 ma.fillParticleList(
'pi+:good',
'chiProb > 0.001 and pionID > 0.5', path=firstpath)
78 ma.reconstructDecay(
'K_S0 -> pi+:good pi-:good',
'0.480<=M<=0.516', path=firstpath)
79 ma.reconstructDecay(
'pi0 -> gamma gamma',
'0.115<=M<=0.152', path=firstpath)
80 ma.reconstructDecay(
'B0 -> K_S0 pi0',
'5.2 < Mbc < 5.3 and -0.3 < deltaE < 0.2', path=firstpath)
82 ma.matchMCTruth(
'B0', path=firstpath)
83 ma.buildRestOfEvent(
'B0', path=firstpath)
85 cleanMask = (
'cleanMask',
'nCDCHits > 0 and useCMSFrame(p)<=3.2',
'p >= 0.05 and useCMSFrame(p)<=3.2')
86 ma.appendROEMasks(
'B0', [cleanMask], path=firstpath)
88 ma.buildContinuumSuppression(
'B0',
'cleanMask', path=firstpath)
91 ma.applyCuts(
'B0',
'isSignal or isContinuumEvent', path=firstpath)
94 TagV(
'B0', path=firstpath)
97 roe_path = basf2.create_path()
99 deadEndPath = basf2.create_path()
101 ma.signalSideParticleFilter(
'B0',
'', roe_path, deadEndPath)
104 ma.fillParticleList(
'gamma:roe',
'isInRestOfEvent == 1 and goodGamma == 1', path=roe_path)
105 ma.fillParticleList(
'gamma:signal',
'isInRestOfEvent == 0 and goodGamma == 1', path=roe_path)
106 ma.fillParticleList(
'pi+:chargedProe',
'isInRestOfEvent == 1', path=roe_path)
107 ma.fillParticleList(
'pi+:chargedPsignal',
'isInRestOfEvent == 0', path=roe_path)
108 ma.fillParticleList(
'pi-:chargedMroe',
'isInRestOfEvent == 1', path=roe_path)
109 ma.fillParticleList(
'pi-:chargedMsignal',
'isInRestOfEvent == 0', path=roe_path)
111 v.variables.addAlias(
'cmsp',
'useCMSFrame(p)')
113 ma.rankByHighest(
'gamma:roe',
'cmsp', path=roe_path)
114 ma.rankByHighest(
'gamma:signal',
'cmsp', path=roe_path)
115 ma.rankByHighest(
'pi+:chargedProe',
'cmsp', path=roe_path)
116 ma.rankByHighest(
'pi+:chargedPsignal',
'cmsp', path=roe_path)
117 ma.rankByHighest(
'pi-:chargedMroe',
'cmsp', path=roe_path)
118 ma.rankByHighest(
'pi-:chargedMsignal',
'cmsp', path=roe_path)
128 'KSFWVariables(mm2)',
129 'KSFWVariables(hso00)',
130 'KSFWVariables(hso02)',
131 'KSFWVariables(hso04)',
132 'KSFWVariables(hso10)',
133 'KSFWVariables(hso12)',
134 'KSFWVariables(hso14)',
135 'KSFWVariables(hso20)',
136 'KSFWVariables(hso22)',
137 'KSFWVariables(hso24)',
138 'KSFWVariables(hoo0)',
139 'KSFWVariables(hoo1)',
140 'KSFWVariables(hoo2)',
141 'KSFWVariables(hoo3)',
142 'KSFWVariables(hoo4)',
155 basic_variables = [
'p',
'phi',
'cosTheta',
'pErr',
'phiErr',
'cosThetaErr']
156 vertex_variables = [
'distance',
'dphi',
'dcosTheta']
157 cluster_specific_variables = [
'clusterNHits',
'clusterTiming',
'clusterE9E25',
'clusterReg',
'isInRestOfEvent']
158 track_specific_variables = [
'kaonID',
'electronID',
'muonID',
'protonID',
'pValue',
'nCDCHits',
'isInRestOfEvent',
'charge']
161 for variablename
in basic_variables + vertex_variables:
162 v.variables.addAlias(
'thrustsig' + variablename,
'useBThrustFrame(' + variablename +
',Signal)')
164 cluster_variables = cluster_specific_variables[:]
165 for variablename
in basic_variables:
166 cluster_variables.append(
'thrustsig' + variablename)
168 track_variables = track_specific_variables
169 for variablename
in basic_variables + vertex_variables:
170 track_variables.append(
'thrustsig' + variablename)
173 variables = [
'isContinuumEvent',
'isNotContinuumEvent',
'isSignal',
'M',
'p',
'Mbc',
'DeltaZ',
174 'deltaE',
'daughter(0, M)',
'daughter(0, p)',
'daughter(1, M)',
'daughter(1, p)']
177 for rank
in range(10):
178 for shortcut, particlelist
in [(
'Croe',
'gamma:roe'), (
'Csig',
'gamma:signal')]:
179 for variable
in cluster_variables:
180 v.variables.addAlias(
182 variable, shortcut, rank),
'getVariableByRank({}, cmsp, {}, {})'.format(
183 particlelist, variable, rank + 1))
184 variables.append(
'{}_{}{}'.format(variable, shortcut, rank))
186 for rank
in range(5):
187 for shortcut, particlelist
in [(
'TProe',
'pi+:chargedProe'), (
'TPsig',
'pi+:chargedPsignal'),
188 (
'TMroe',
'pi+:chargedMroe'), (
'TMsig',
'pi+:chargedMsignal')]:
189 for variable
in track_variables:
190 v.variables.addAlias(
192 variable, shortcut, rank),
'getVariableByRank({}, cmsp, {}, {})'.format(
193 particlelist, variable, rank + 1))
194 variables.append(
'{}_{}{}'.format(variable, shortcut, rank))
197 ma.variablesToNtuple(
'B0', variables + contVars, treename=
'tree', filename=outfile, path=roe_path)
200 firstpath.for_each(
'RestOfEvent',
'RestOfEvents', roe_path)
203 print(basf2.statistics)
206 df = read_root(outfile)
207 df = df.sample(frac=1)
208 df.to_root(outfile, key=
'tree')