Belle II Software  release-08-01-10
python.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2_mva
12 import b2test_utils
13 import basf2
14 
15 variables = ['M', 'p', 'pt', 'pz',
16  'daughter(0, p)', 'daughter(0, pz)', 'daughter(0, pt)',
17  'daughter(1, p)', 'daughter(1, pz)', 'daughter(1, pt)',
18  'daughter(2, p)', 'daughter(2, pz)', 'daughter(2, pt)',
19  'chiProb', 'dr', 'dz',
20  'daughter(0, dr)', 'daughter(1, dr)',
21  'daughter(0, dz)', 'daughter(1, dz)',
22  'daughter(0, chiProb)', 'daughter(1, chiProb)', 'daughter(2, chiProb)',
23  'daughter(0, kaonID)', 'daughter(0, pionID)',
24  'daughterInvM(0, 1)', 'daughterInvM(0, 2)', 'daughterInvM(1, 2)']
25 
26 
27 def feature_importance(state):
28  """
29  Return a list containing the feature importances
30  """
31  print("Called overwritten feature importance")
32  return []
33 
34 
35 def load(obj):
36  """
37  Test load function
38  """
39  print("Called overwritten load")
40  print(obj)
41  return None
42 
43 
44 print("Executed python script")
45 
46 if __name__ == "__main__":
47 
48  # Skip test if files are not available
49  try:
50  train_file = basf2.find_file('mva/train_D0toKpipi.root', 'examples', False)
51  test_file = basf2.find_file('mva/test_D0toKpipi.root', 'examples', False)
52  except BaseException:
53  b2test_utils.skip_test('Necessary files "train.root" and "test.root" not available.')
54 
55  general_options = basf2_mva.GeneralOptions()
56  general_options.m_datafiles = basf2_mva.vector(train_file)
57  general_options.m_treename = "tree"
58  general_options.m_variables = basf2_mva.vector(*variables)
59  general_options.m_target_variable = "isSignal"
60  general_options.m_identifier = "Python.xml"
61  general_options.m_max_events = 200
62 
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'
68 
69  # we create payloads so let's switch to an empty, temporary directory
71 
72  basf2_mva.teacher(general_options, specific_options)
73 
74  basf2_mva.expert(basf2_mva.vector("Python.xml"),
75  basf2_mva.vector(test_file), 'tree', 'expert.root')
76 
77  specific_options.m_steering_file = 'mva/tests/python.py'
78  basf2_mva.teacher(general_options, specific_options)
79 
80  basf2_mva.expert(basf2_mva.vector("Python.xml"),
81  basf2_mva.vector(test_file), 'tree', 'expert.root')
def clean_working_directory()
Definition: __init__.py:189
def skip_test(reason, py_case=None)
Definition: __init__.py:31