Belle II Software development
B2A701-ContinuumSuppression_Input.py
1#!/usr/bin/env python3
2
3
10
11
24
25import basf2 as b2
26import modularAnalysis as ma
27import sys
28
29
30# --I/O----------------------------------------------------------------------------------------
31# Please note that the files here are quite small and needed just to test the script.
32# To obtain meaningful output to be used in B2A702 and B2A703 please use grid.
33# > gbasf2 B2A701-ContinuumSuppression_Input.py -i <.mdst file addresses> -p <project name> -s <release_number>
34#
35# For B2A70{2|3} you need four sets of ntuples:
36# -Train dataset composed of signal (B->KsPi0 ) and background MC (continuum MC) samples
37# -Test dataset composed of signal (B->KsPi0 ) and background MC (continuum MC) samples
38# -Signal dataset only
39# -Background dataset only
40# For each of this four sets you need to submit separate grid job.
41# (Or use files that are already prepared for B2A702 and B2A703).
42
43
44input_file_list = []
45
46# Please pick a meaningful output name when running on the grid
47outfile = "B2A702_output.root"
48
49step = 'train'
50
51if len(sys.argv) >= 2:
52 if sys.argv[1] not in ['train', 'test', 'apply_signal', 'apply_qqbar']:
53 sys.exit("usage:\n\tbasf2 B2A701-ContinuumSuppression_Input.py <train,test,apply_signal,apply_qqbar>")
54 else:
55 step = str(sys.argv[1])
56
57if step == 'train':
58 input_file_list = [b2.find_file('ccbar_sample_to_train.root', 'examples', False),
59 b2.find_file('Bd2K0spi0_to_train.root', 'examples', False)]
60elif step == 'test':
61 input_file_list = [b2.find_file('ccbar_sample_to_test.root', 'examples', False),
62 b2.find_file('Bd2K0spi0_to_test.root', 'examples', False)]
63elif step == 'apply_signal':
64 input_file_list = [b2.find_file('Bd2K0spi0_to_test.root', 'examples', False)]
65elif step == 'apply_qqbar':
66 input_file_list = [b2.find_file('ccbar_sample_to_test.root', 'examples', False)]
67else:
68 sys.exit('Step does not match any of the available samples: `train`, `test`, `apply_signal`or `apply_qqbar`')
69outfile = step + '.root'
70
71# ---------------------------------------------------------------------------------------------
72
73# Perform analysis.
74my_path = b2.create_path()
75
76ma.inputMdstList(filelist=input_file_list,
77 path=my_path)
78
79ma.fillParticleList(decayString='gamma:all',
80 cut='',
81 path=my_path)
82ma.fillParticleList(decayString='pi+:good',
83 cut='chiProb > 0.001 and pionID > 0.5',
84 path=my_path)
85ma.fillParticleList(decayString='pi-:good',
86 cut='chiProb > 0.001 and pionID > 0.5',
87 path=my_path)
88
89ma.reconstructDecay(decayString='K_S0 -> pi+:good pi-:good',
90 cut='0.480<=M<=0.516',
91 dmID=1,
92 path=my_path)
93ma.reconstructDecay(decayString='pi0 -> gamma:all gamma:all',
94 cut='0.115<=M<=0.152',
95 dmID=1,
96 path=my_path)
97ma.reconstructDecay(decayString='B0 -> K_S0 pi0',
98 cut='5.2 < Mbc < 5.3 and -0.3 < deltaE < 0.2',
99 path=my_path)
100
101ma.matchMCTruth(list_name='B0', path=my_path)
102ma.buildRestOfEvent(target_list_name='B0', path=my_path)
103
104# The momentum cuts used to be hard-coded in the continuum suppression module. They can now be applied
105# via this mask. The nCDCHits requirement is new, and is recommended to remove VXD-only fake tracks.
106cleanMask = ('cleanMask', 'nCDCHits > 0 and useCMSFrame(p)<=3.2', 'p >= 0.05 and useCMSFrame(p)<=3.2')
107ma.appendROEMasks(list_name='B0',
108 mask_tuples=[cleanMask],
109 path=my_path)
110
111ma.buildContinuumSuppression(list_name='B0',
112 roe_mask='cleanMask',
113 path=my_path)
114
115# Define the variables for training.
116# For details, please see the Continuum suppression section at https://software.belle2.org
117# Note that KSFWVariables takes the optional additional argument FS1, to return the variables calculated from the
118# signal-B final state particles.
119trainVars = [
120 'R2',
121 'thrustBm',
122 'thrustOm',
123 'cosTBTO',
124 'cosTBz',
125 'KSFWVariables(et)',
126 'KSFWVariables(mm2)',
127 'KSFWVariables(hso00)',
128 'KSFWVariables(hso01)',
129 'KSFWVariables(hso02)',
130 'KSFWVariables(hso03)',
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)',
143 'CleoConeCS(1)',
144 'CleoConeCS(2)',
145 'CleoConeCS(3)',
146 'CleoConeCS(4)',
147 'CleoConeCS(5)',
148 'CleoConeCS(6)',
149 'CleoConeCS(7)',
150 'CleoConeCS(8)',
151 'CleoConeCS(9)'
152]
153
154# Save target variable necessary for training.
155targetVar = ['isNotContinuumEvent']
156
157# Create output file.
158ma.variablesToNtuple(decayString='B0',
159 variables=trainVars + targetVar,
160 treename='tree',
161 filename=outfile,
162 path=my_path)
163
164b2.process(my_path)
165print(b2.statistics)