Belle II Software light-2609-luna
combiner_level.py
1# this script applies the combiner level classifier
2
3from flavorTagger.utils import get_Belle_or_Belle2
4import os
5
6
7def combiner_level(weightFiles='B2JpsiKs_mu', categories=None,
8 variablesCombinerLevel=None, categoriesCombinationCode=None,
9 TMVAfbdt=False, downloadFlag=False,
10 useOnlyLocalFlag=False, signal_fraction=-2,
11 filesDirectory="./FlavorTagging/TrainedMethods", path=None):
12 """
13 Samples the input data or tests the combiner according to the selected categories.
14 """
15
16 # imports
17 from basf2 import B2INFO, B2FATAL
18 import basf2_mva
19
20 # verbose
21 B2INFO('COMBINER LEVEL')
22
23 B2INFO("Flavor Tagger: Required Combiner for Categories:")
24 for category in categories:
25 B2INFO(category)
26
27 B2INFO(f"Flavor Tagger: which corresponds to a weight file with categories\
28 combination code {categoriesCombinationCode}")
29
30 # initialise configuration variables
31 if variablesCombinerLevel is None:
32 variablesCombinerLevel = []
33 exp_type = get_Belle_or_Belle2()
34
35 combiner_method_prefix = f"FlavorTagger_{exp_type}_{weightFiles}Combiner{categoriesCombinationCode}"
36
37 # Check if weight files are ready
38 if TMVAfbdt:
39 identifierFBDT = f"{combiner_method_prefix}FBDT"
40 if downloadFlag or useOnlyLocalFlag:
41 identifierFBDT = f"{filesDirectory}/{combiner_method_prefix}FBDT_1.root"
42
43 if downloadFlag:
44 if not os.path.isfile(identifierFBDT):
45 basf2_mva.download(f"{combiner_method_prefix}FBDT", identifierFBDT)
46 if not os.path.isfile(identifierFBDT):
47 B2FATAL(f"Flavor Tagger: Weight file {identifierFBDT} was\
48 not downloaded from Database. Please check the\
49 buildOrRevision name. Stopped")
50
51 if useOnlyLocalFlag:
52 if not os.path.isfile(identifierFBDT):
53 B2FATAL(f"flavorTagger: Combinerlevel FastBDT was not trained\
54 with this combination of categories. Weight file\
55 {identifierFBDT} not found. Stopped")
56
57 B2INFO(f"flavorTagger: Ready to be used with weightFile\
58 {combiner_method_prefix}FBDT_1.root")
59
60 # At this stage, all necessary weight files should be ready.
61 # Call MVAExpert or MVAMultipleExperts module.
62 if TMVAfbdt:
63 B2INFO(f"flavorTagger: Apply FBDTMethod {combiner_method_prefix}FBDT")
64 path.add_module(
65 'MVAExpert',
66 listNames=[],
67 extraInfoName='qrCombinedFBDT',
68 signalFraction=signal_fraction,
69 identifier=identifierFBDT
70 )