Belle II Software development
B2A703-ContinuumSuppression_MVAExpert.py
1#!/usr/bin/env python3
2
3
10
11
28
29import basf2 as b2
30import modularAnalysis as ma
31import sys
32
33
34# --I/O----------------------------------------------------------------------------------------
35step = 'signal'
36
37if len(sys.argv) >= 2:
38 step = str(sys.argv[1])
39
40if step == 'signal':
41 input_file = b2.find_file('Bd2K0spi0_to_test.root', 'examples', False)
42elif step == 'qqbar':
43 input_file = b2.find_file('ccbar_sample_to_test.root', 'examples', False)
44else:
45 sys.exit('Step does not match any of the available samples: `signal` or `qqbar`')
46
47outfile = 'MVAExpert_fullNTuple_' + step + '.root'
48# ---------------------------------------------------------------------------------------------
49
50# Perform analysis.
51main = b2.create_path()
52
53ma.inputMdst(filename=input_file,
54 path=main)
55
56ma.fillParticleList(decayString='gamma:all',
57 cut='', path=main)
58ma.fillParticleList(decayString='pi+:good',
59 cut='chiProb > 0.001 and pionID > 0.5',
60 path=main)
61ma.fillParticleList(decayString='pi-:good',
62 cut='chiProb > 0.001 and pionID > 0.5',
63 path=main)
64
65ma.reconstructDecay(decayString='K_S0 -> pi+:good pi-:good',
66 cut='0.480<=M<=0.516',
67 dmID=1,
68 path=main)
69ma.reconstructDecay(decayString='pi0 -> gamma:all gamma:all',
70 cut='0.115<=M<=0.152',
71 dmID=1,
72 path=main)
73ma.reconstructDecay(decayString='B0 -> K_S0 pi0',
74 cut='5.2 < Mbc < 5.3 and -0.3 < deltaE < 0.2',
75 path=main)
76
77ma.matchMCTruth(list_name='B0', path=main)
78ma.buildRestOfEvent(target_list_name='B0', path=main)
79
80# The momentum cuts used to be hard-coded in the continuum suppression module. They can now be applied
81# via this mask. The nCDCHits requirement is new, and is recommended to remove VXD-only fake tracks.
82cleanMask = ('cleanMask', 'nCDCHits > 0 and useCMSFrame(p)<=3.2', 'p >= 0.05 and useCMSFrame(p)<=3.2')
83ma.appendROEMasks(list_name='B0',
84 mask_tuples=[cleanMask],
85 path=main)
86
87ma.buildContinuumSuppression(list_name='B0',
88 roe_mask='cleanMask',
89 path=main)
90
91# Define the variables for training.
92# For details, please see the Continuum suppression section at https://software.belle2.org
93# Note that KSFWVariables takes the optional additional argument FS1, to return the variables calculated from the
94# signal-B final state particles.
95# CleoCone also takes the optional additional argument ROE, to return the cones calculated from ROE particles only.
96trainVars = [
97 'R2',
98 'thrustBm',
99 'thrustOm',
100 'cosTBTO',
101 'cosTBz',
102 'KSFWVariables(et)',
103 'KSFWVariables(mm2)',
104 'KSFWVariables(hso00)',
105 'KSFWVariables(hso01)',
106 'KSFWVariables(hso02)',
107 'KSFWVariables(hso03)',
108 'KSFWVariables(hso04)',
109 'KSFWVariables(hso10)',
110 'KSFWVariables(hso12)',
111 'KSFWVariables(hso14)',
112 'KSFWVariables(hso20)',
113 'KSFWVariables(hso22)',
114 'KSFWVariables(hso24)',
115 'KSFWVariables(hoo0)',
116 'KSFWVariables(hoo1)',
117 'KSFWVariables(hoo2)',
118 'KSFWVariables(hoo3)',
119 'KSFWVariables(hoo4)',
120 'CleoConeCS(1)',
121 'CleoConeCS(2)',
122 'CleoConeCS(3)',
123 'CleoConeCS(4)',
124 'CleoConeCS(5)',
125 'CleoConeCS(6)',
126 'CleoConeCS(7)',
127 'CleoConeCS(8)',
128 'CleoConeCS(9)'
129]
130
131# Target variable used in training.
132targetVar = ['isNotContinuumEvent']
133
134# MVAExpert
135main.add_module('MVAExpert', listNames=['B0'], extraInfoName='FastBDT', identifier='MVAFastBDT.root')
136
137# Variables from MVAExpert.
138expertVars = ['extraInfo(FastBDT)', 'transformedNetworkOutput(FastBDT,0.1,1.0)']
139
140# Create output file with all sets of variables.
141ma.variablesToNtuple(decayString='B0',
142 variables=trainVars + targetVar + expertVars,
143 treename='tree',
144 filename=outfile,
145 path=main)
146
147b2.process(main)
148print(b2.statistics)