17 from b2test_utils
import skip_test
19 variables = [
'M',
'p',
'pt',
'pz',
20 'daughter(0, p)',
'daughter(0, pz)',
'daughter(0, pt)',
21 'daughter(1, p)',
'daughter(1, pz)',
'daughter(1, pt)',
22 'daughter(2, p)',
'daughter(2, pz)',
'daughter(2, pt)',
23 'chiProb',
'dr',
'dz',
24 'daughter(0, dr)',
'daughter(1, dr)',
25 'daughter(0, dz)',
'daughter(1, dz)',
26 'daughter(0, chiProb)',
'daughter(1, chiProb)',
'daughter(2, chiProb)',
27 'daughter(0, kaonID)',
'daughter(0, pionID)',
28 'daughterInvariantMass(0, 1)',
'daughterInvariantMass(0, 2)',
'daughterInvariantMass(1, 2)']
31 def feature_importance(state):
33 Return a list containing the feature importances
35 print(
"Called overwritten feature importance")
43 print(
"Called overwritten load")
48 print(
"Executed python script")
50 if __name__ ==
"__main__":
53 if not (os.path.isfile(
'train.root')
and os.path.isfile(
'test.root')):
54 skip_test(
'Necessary files "train.root" and "test.root" not available.')
56 general_options = basf2_mva.GeneralOptions()
57 general_options.m_datafiles = basf2_mva.vector(
"train.root")
58 general_options.m_treename =
"tree"
59 general_options.m_variables = basf2_mva.vector(*variables)
60 general_options.m_target_variable =
"isSignal"
61 general_options.m_identifier =
"Python.xml"
63 specific_options = basf2_mva.PythonOptions()
64 specific_options.m_training_fraction = 0.9
65 specific_options.m_nIterations = 2
66 specific_options.m_mini_batch_size = 10000
67 specific_options.m_framework =
'test'
70 with tempfile.TemporaryDirectory()
as tempdir:
71 os.symlink(os.path.abspath(
'train.root'), tempdir +
'/' + os.path.basename(
'train.root'))
72 os.symlink(os.path.abspath(
'test.root'), tempdir +
'/' + os.path.basename(
'test.root'))
75 basf2_mva.teacher(general_options, specific_options)
77 basf2_mva.expert(basf2_mva.vector(
"Python.xml"),
78 basf2_mva.vector(
'train.root'),
'tree',
'expert.root')
80 specific_options.m_steering_file =
'mva/tests/python.py'
81 basf2_mva.teacher(general_options, specific_options)
83 basf2_mva.expert(basf2_mva.vector(
"Python.xml"),
84 basf2_mva.vector(
'train.root'),
'tree',
'expert.root')