Belle II Software development
train_K_L0_classifier.py
1#!/usr/bin/env python3
2
3
10
11import sys
12import os
13
14# USE THIS TO TRAIN AND UPLOAD A NEW CLASSIFIER FOR THE KLONG ID
15# USE THE OTHER SCRIPT TO GENERATE DATA. THEN TRAIN AND UPLOAD WITH &THIS.
16# only thing to set is the path were you have the data to train the classifier on.
17
18try:
19 data_path = sys.argv[1]
20except BaseException:
21 data_path = "root_files/training/*.root"
22try:
23 identifier = sys.argv[2]
24except BaseException:
25 # the default name used in KLMExpert
26 identifier = "KLM_fBDT_10xbkg100k.xml"
27
28ex_b = 0 # experiment begin, 0 for all of them
29ex_e = -1 # experiment end, -1 for all of them
30run_b = 0 # run begin, 0 for all
31run_e = -1 # run end, -1 for all of them
32
33training_string = f'basf2_mva_teacher --datafiles {data_path} --treename KLMdata --identifier {identifier} ' + \
34 '--variable "KLMnLayer" "KLMnInnermostlayer" "KLMglobalZ" "KLMtime" "KLMdistToNextCl" ' + \
35 '"KLMenergy" "KLMTrackSepDist" "KLMInitialtrackSepAngle" "KLMTrackRotationAngle" ' + \
36 '"KLMTrackSepAngle" "KLMhitDepth" "KLMECLenergy" "KLMECLE9oE25" "KLMECLtiming" ' + \
37 '"KLMECLmintrackDist" "KLMECLZMVA" "KLMECLZ40" "KLMECLZ51" --target_variable isSignal ' + \
38 '--method FastBDT --nTrees 400 --nCutLevels 8 --nLevels 4'
39
40os.system(training_string)
41
42# "upload" to localdb
43os.system(
44 f"basf2_mva_add_to_local_database --weight_file_name {identifier} --db_identifier {identifier.split('.xml')[0]} " +
45 f"--begin_experiment {ex_b} --end_experiment {ex_e} --begin_run {run_b} --end_run {run_e}")