Belle II Software development
builtin_reweighting.py
1#!/usr/bin/env python3
2
3
10
11# The mva package has a builtin reweighting mechanism.
12# If your data and mc do not match, you can use the MetaOptions to do a meta-training.
13# Using 'm_use_reweighting = True' the mva package will train
14# - the provided data files against the provided mc files, and calculate the probability p for each event in the mc files
15# - the provided signal against background in the mc files weighted with the p / (1 - p)
16# You can access the first boost training, it is saved with the postfix _boost.xml
17
18# In general you want to write out
19# - train_mc.root containing the reconstructed candidates from MC (Y4S + Continuum)
20# - train_data.root containing the reconstructed candidates from data
21
22# In this example we investigate the decay D -> K pi pi0 in MC and data (e.g. using b2bii)
23# It turns out that mostly the continuum description is wrong, so we only correct for this
24# - train_mc_continuum contains only candidates from charm and uds
25# - train_data_continuum contains off resonance data with only continuum
26# In the end we also only want to apply the reweighting to continuum events, so we set the
27# m_reweighting_variable to 'isContinuumEvent'
28
29import basf2_mva
30
31if __name__ == "__main__":
32 variables = ['p', 'pt', 'pz', 'phi',
33 'chiProb', 'dr', 'dz', 'dphi',
34 'daughter(0, dr)', 'daughter(1, dr)', 'daughter(0, dz)', 'daughter(1, dz)',
35 'daughter(0, dphi)', 'daughter(1, dphi)',
36 'daughter(0, chiProb)', 'daughter(1, chiProb)', 'daughter(2, chiProb)', 'daughter(2, M)',
37 'daughter(0, atcPIDBelle(3,2))', 'daughter(1, atcPIDBelle(3,2))',
38 'daughter(2, daughter(0, E))', 'daughter(2, daughter(1, E))',
39 'daughter(2, daughter(0, clusterLAT))', 'daughter(2, daughter(1, clusterLAT))',
40 'daughter(2, daughter(0, clusterHighestE))', 'daughter(2, daughter(1, clusterHighestE))',
41 'daughter(2, daughter(0, clusterNHits))', 'daughter(2, daughter(1, clusterNHits))',
42 'daughter(2, daughter(0, clusterE9E25))', 'daughter(2, daughter(1, clusterE9E25))',
43 'daughter(2, daughter(0, minC2TDist))', 'daughter(2, daughter(1, minC2TDist))',
44 'daughterInvM(1, 2)', 'daughterInvM(0, 1)', 'daughterInvM(0, 2)'
45 'daughterAngle(0, 1)', 'daughterAngle(0, 2)', 'daughterAngle(1, 2)',
46 'daughter(0, p)', 'daughter(0, pz)', 'daughter(0, pt)', 'daughter(0, phi)',
47 'daughter(1, p)', 'daughter(1, pz)', 'daughter(1, pt)', 'daughter(1, phi)',
48 'daughter(2, p)', 'daughter(2, pz)', 'daughter(2, pt)', 'daughter(2, phi)',
49 ]
50
51 general_options = basf2_mva.GeneralOptions()
52 general_options.m_datafiles = basf2_mva.vector("train_mc.root")
53 general_options.m_identifier = "MVAReweighted"
54 general_options.m_treename = "tree"
55 general_options.m_variables = basf2_mva.vector(*variables)
56 general_options.m_target_variable = "isSignal"
57
58 fastbdt_options = basf2_mva.FastBDTOptions()
59
60 meta_options = basf2_mva.MetaOptions()
61 meta_options.m_use_reweighting = True
62 meta_options.m_reweighting_variable = 'isContinuumEvent'
63 meta_options.m_reweighting_identifier = "Reweighter"
64 meta_options.m_reweighting_mc_files = basf2_mva.vector("train_mc_continuum.root")
65 meta_options.m_reweighting_data_files = basf2_mva.vector("train_data_continuum.root")
66
67 basf2_mva.teacher(general_options, fastbdt_options, meta_options)