Belle II Software light-2406-ragdoll
custom_reweighting.py
1#!/usr/bin/env python3
2
3
10
11# Besides the builtin reweighting, you can also implement the reweighting yourself.
12# This can be useful if you want to do something special which is not supported by the mva package
13
14import basf2_mva
15
16if __name__ == "__main__":
17 variables = ['p', 'pt', 'pz', 'phi',
18 'daughter(0, p)', 'daughter(0, pz)', 'daughter(0, pt)', 'daughter(0, phi)',
19 'daughter(1, p)', 'daughter(1, pz)', 'daughter(1, pt)', 'daughter(1, phi)',
20 'daughter(2, p)', 'daughter(2, pz)', 'daughter(2, pt)', 'daughter(2, phi)',
21 'chiProb', 'dr', 'dz', 'dphi',
22 'daughter(0, dr)', 'daughter(1, dr)', 'daughter(0, dz)', 'daughter(1, dz)',
23 'daughter(0, dphi)', 'daughter(1, dphi)',
24 'daughter(0, chiProb)', 'daughter(1, chiProb)', 'daughter(2, chiProb)', 'daughter(2, M)',
25 'daughter(0, atcPIDBelle(3,2))', 'daughter(1, atcPIDBelle(3,2))',
26 'daughterAngle(0, 1)', 'daughterAngle(0, 2)', 'daughterAngle(1, 2)',
27 'daughter(2, daughter(0, E))', 'daughter(2, daughter(1, E))',
28 'daughter(2, daughter(0, clusterLAT))', 'daughter(2, daughter(1, clusterLAT))',
29 'daughter(2, daughter(0, clusterHighestE))', 'daughter(2, daughter(1, clusterHighestE))',
30 'daughter(2, daughter(0, clusterNHits))', 'daughter(2, daughter(1, clusterNHits))',
31 'daughter(2, daughter(0, clusterE9E25))', 'daughter(2, daughter(1, clusterE9E25))',
32 'daughter(2, daughter(0, minC2TDist))', 'daughter(2, daughter(1, minC2TDist))',
33 'daughterInvM(1, 2)']
34
35 general_options = basf2_mva.GeneralOptions()
36 general_options.m_datafiles = basf2_mva.vector("train_mc.root")
37 general_options.m_identifier = "boost.xml"
38 general_options.m_treename = "tree"
39 general_options.m_variables = basf2_mva.vector(*variables)
40 # isMC is 1 for MC and 0 for Data
41 general_options.m_target_variable = "isMC"
42 fastbdt_options = basf2_mva.FastBDTOptions()
43 basf2_mva.teacher(general_options, fastbdt_options)
44
45 reweighter_options = basf2_mva.ReweighterOptions()
46 reweighter_options.m_variable = 'isContinuumEvent'
47 reweighter_options.m_weightfile = "boost.xml"
48 general_options.m_identifier = "reweighter.xml"
49 basf2_mva.teacher(general_options, reweighter_options)
50
51 # Now you can use the reweighter.xml expert to output the correct weights
52 # and use them in another training