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
43input_file_list = []
44
45# Please pick a meaningful output name when running on the grid
46outfile = "B2A701_output_"
47
48step = 'train'
49
50if len(sys.argv) >= 2:
51 if sys.argv[1] not in ['train', 'test', 'apply_signal', 'apply_qqbar']:
52 sys.exit("usage:\n\tbasf2 B2A701-ContinuumSuppression_Input.py <train,test,apply_signal,apply_qqbar>")
53 else:
54 step = str(sys.argv[1])
55
56if step == 'train':
57 input_file_list = [b2.find_file('ccbar_sample_to_train.root', 'examples', False),
58 b2.find_file('Bd2K0spi0_to_train.root', 'examples', False)]
59elif step == 'test':
60 input_file_list = [b2.find_file('ccbar_sample_to_test.root', 'examples', False),
61 b2.find_file('Bd2K0spi0_to_test.root', 'examples', False)]
62elif step == 'apply_signal':
63 input_file_list = [b2.find_file('Bd2K0spi0_to_test.root', 'examples', False)]
64elif step == 'apply_qqbar':
65 input_file_list = [b2.find_file('ccbar_sample_to_test.root', 'examples', False)]
66else:
67 sys.exit('Step does not match any of the available samples: `train`, `test`, `apply_signal`or `apply_qqbar`')
68outfile += step + '.root'
69
70# ---------------------------------------------------------------------------------------------
71
72# Perform analysis.
73my_path = b2.create_path()
74
75ma.inputMdstList(filelist=input_file_list,
76 path=my_path)
77
78ma.fillParticleList(decayString='gamma:all',
79 cut='',
80 path=my_path)
81ma.fillParticleList(decayString='pi+:good',
82 cut='chiProb > 0.001 and pionID > 0.5',
83 path=my_path)
84ma.fillParticleList(decayString='pi-:good',
85 cut='chiProb > 0.001 and pionID > 0.5',
86 path=my_path)
87
88ma.reconstructDecay(decayString='K_S0 -> pi+:good pi-:good',
89 cut='0.480<=M<=0.516',
90 dmID=1,
91 path=my_path)
92ma.reconstructDecay(decayString='pi0 -> gamma:all gamma:all',
93 cut='0.115<=M<=0.152',
94 dmID=1,
95 path=my_path)
96ma.reconstructDecay(decayString='B0 -> K_S0 pi0',
97 cut='5.2 < Mbc < 5.3 and -0.3 < deltaE < 0.2',
98 path=my_path)
99
100ma.matchMCTruth(list_name='B0', path=my_path)
101ma.buildRestOfEvent(target_list_name='B0', path=my_path)
102
103# define mask with momentum cuts and requirement of at least one CDC hit to remove VXD-only fake tracks
104cleanMask = ('cleanMask', 'nCDCHits > 0 and useCMSFrame(p)<=3.2', 'p >= 0.05 and useCMSFrame(p)<=3.2')
105ma.appendROEMasks(list_name='B0',
106 mask_tuples=[cleanMask],
107 path=my_path)
108
109ma.buildContinuumSuppression(list_name='B0',
110 roe_mask='cleanMask',
111 ipprofile_fit=False,
112 path=my_path)
113
114# Define the variables for training.
115# For details, please see the Continuum suppression section at https://software.belle2.org
116# Note that KSFWVariables takes the optional additional argument FS1, to return the variables calculated from the
117# signal-B final state particles.
118trainVars = [
119 'R2',
120 'thrustBm',
121 'thrustOm',
122 'cosTBTO',
123 'cosTBz',
124 'KSFWVariables(pt_sum)',
125 'KSFWVariables(mm2)',
126 'KSFWVariables(hso00)',
127 'KSFWVariables(hso01)',
128 'KSFWVariables(hso02)',
129 'KSFWVariables(hso03)',
130 'KSFWVariables(hso04)',
131 'KSFWVariables(hso10)',
132 'KSFWVariables(hso12)',
133 'KSFWVariables(hso14)',
134 'KSFWVariables(hso20)',
135 'KSFWVariables(hso22)',
136 'KSFWVariables(hso24)',
137 'KSFWVariables(hoo0)',
138 'KSFWVariables(hoo1)',
139 'KSFWVariables(hoo2)',
140 'KSFWVariables(hoo3)',
141 'KSFWVariables(hoo4)',
142 'CleoConeCS(1)',
143 'CleoConeCS(2)',
144 'CleoConeCS(3)',
145 'CleoConeCS(4)',
146 'CleoConeCS(5)',
147 'CleoConeCS(6)',
148 'CleoConeCS(7)',
149 'CleoConeCS(8)',
150 'CleoConeCS(9)'
151]
152
153# Save target variable necessary for training.
154targetVar = ['isNotContinuumEvent']
155
156# Create output file.
157ma.variablesToNtuple(decayString='B0',
158 variables=trainVars + targetVar,
159 treename='tree',
160 filename=outfile,
161 path=my_path)
162
163b2.process(my_path)