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