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