Belle II Software light-2406-ragdoll
all_classifiers.py
1#!/usr/bin/env python3
2
3
10
11import basf2_mva
12import basf2
13from subprocess import PIPE, run
14import b2test_utils
15
16variables = ['p', 'pz', 'daughter(0, p)', 'daughter(0, pz)', 'daughter(1, p)', 'daughter(1, pz)',
17 'chiProb', 'dr', 'dz', 'daughter(0, dr)', 'daughter(1, dr)', 'daughter(0, chiProb)', 'daughter(1, chiProb)',
18 'daughter(0, kaonID)', 'daughter(0, pionID)', 'daughterAngle(0, 1)']
19
20if __name__ == "__main__":
21
22 # Skip test if files are not available
23 try:
24 train_file = basf2.find_file('mva/train_D0toKpipi.root', 'examples', False)
25 test_file = basf2.find_file('mva/test_D0toKpipi.root', 'examples', False)
26 except BaseException:
27 b2test_utils.skip_test('Necessary files "train.root" and "test.root" not available.')
28
29 general_options = basf2_mva.GeneralOptions()
30 general_options.m_datafiles = basf2_mva.vector(train_file)
31 general_options.m_treename = "tree"
32 general_options.m_variables = basf2_mva.vector(*variables)
33 general_options.m_target_variable = "isSignal"
34 general_options.m_max_events = 200
35
36 methods = [
37 ('Trivial.xml', basf2_mva.TrivialOptions(), None),
38 ('FastBDT.xml', basf2_mva.FastBDTOptions(), None),
39 ('TMVAClassification.xml', basf2_mva.TMVAOptionsClassification(), None),
40 ('FANN.xml', basf2_mva.FANNOptions(), None),
41 ('Python_sklearn.xml', basf2_mva.PythonOptions(), 'sklearn'),
42 ('Python_xgb.xml', basf2_mva.PythonOptions(), 'xgboost'),
43 ('Python_tensorflow.xml', basf2_mva.PythonOptions(), 'tensorflow'),
44 ('Python_torch.xml', basf2_mva.PythonOptions(), 'torch'),
45 ]
46
47 # we create payloads so let's switch to an empty, temporary directory
49 for identifier, specific_options, framework in methods:
50 general_options.m_identifier = identifier
51 if framework is not None:
52 specific_options.m_framework = framework
53 basf2_mva.teacher(general_options, specific_options)
54
55 basf2_mva.expert(basf2_mva.vector(*[i for i, _, _ in methods]),
56 basf2_mva.vector(train_file), 'tree', 'expert.root')
57
58 # don't compile the evaluation as this fails on the build bot due to missing latex files
59 command = f'basf2_mva_evaluate.py -o latex.pdf -train {train_file}'\
60 f' -data {test_file} -i {" ".join([i for i, _, _ in methods])}'
61
62 result = run(command,
63 stdout=PIPE, stderr=PIPE,
64 text=True, shell=True)
65 assert result.returncode == 0, 'basf2_mva_evaluate.py failed!'
def clean_working_directory()
Definition: __init__.py:189
def skip_test(reason, py_case=None)
Definition: __init__.py:31