Belle II Software  release-05-02-19
usage_in_python.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 # Thomas Keck 2016
5 
6 import basf2_mva
7 
8 if __name__ == "__main__":
9  from basf2 import conditions
10  # NOTE: do not use testing payloads in production! Any results obtained like this WILL NOT BE PUBLISHED
11  conditions.testing_payloads = [
12  'localdb/database.txt'
13  ]
14 
15  # Train a MVA method and directly upload it to the database
16  general_options = basf2_mva.GeneralOptions()
17  general_options.m_datafiles = basf2_mva.vector("train.root")
18  general_options.m_treename = "tree"
19  general_options.m_identifier = "MVADatabaseIdentifier"
20  general_options.m_variables = basf2_mva.vector('M', 'p', 'pz', 'pt', 'phi', 'daughter(0, kaonID)', 'daughter(0, pionID)',
21  'daughter(1, kaonID)', 'daughter(1, pionID)', 'chiProb', 'dr', 'dz', 'dphi')
22  general_options.m_target_variable = "isSignal"
23 
24  fastbdt_options = basf2_mva.FastBDTOptions()
25 
26  basf2_mva.teacher(general_options, fastbdt_options)
27 
28  # Download the weightfile from the database and store it on disk in a root file
29  basf2_mva.download('MVADatabaseIdentifier', 'weightfile.root')
30 
31  # Train a MVA method and store the weightfile on disk in a root file
32  general_options.m_identifier = "weightfile2.root"
33  basf2_mva.teacher(general_options, fastbdt_options)
34 
35  # Upload the weightfile on disk to the database
36  basf2_mva.upload('weightfile2.root', 'MVADatabaseIdentifier2')
37 
38  # Apply the trained methods on data
39  basf2_mva.expert(basf2_mva.vector('weightfile.root', 'weightfile2.root', 'MVADatabaseIdentifier', 'MVADatabaseIdentifier2'),
40  basf2_mva.vector('train.root'), 'tree', 'expert.root')