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