Belle II Software  release-05-02-19
trainSecMap.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
24 
25 from basf2 import *
26 import sys
27 import argparse
28 
29 
30 # ---------------------------------------------------------------------------------------
31 # Argument parser for input of training sample file via comandline option.
32 arg_parser = argparse.ArgumentParser(description='Sector Map Training:\
33  Trains and stores SecMap from provided data sample.\n\
34  Usage: basf2 trainSecMap.py -- --train_sample traindata.root --secmap trainedSecMap.root')
35 
36 arg_parser.add_argument('--train_sample', '-i', type=str, action='append',
37  help='List of prepared training data file names which will be used for the training of the SecMap')
38 arg_parser.add_argument('--secmap', '-s', type=str,
39  help='Inclusion of the root file containing the trained SecMap for the application of the VXDTF2.')
40 
41 arguments = arg_parser.parse_args(sys.argv[1:])
42 train_data = arguments.train_sample
43 secmap_name = arguments.secmap
44 assert len(train_data) > 0, 'No data sample for training provided!'
45 
46 # ---------------------------------------------------------------------------------------
47 # Logging and Debug Level
48 set_log_level(LogLevel.ERROR)
49 log_to_file('logVXDTF2Training.log', append=False)
50 
51 
52 # ---------------------------------------------------------------------------------------
53 path = create_path()
54 
55 # Event Info Setter which is requiered as the SecMap Training is performed in the Initilize
56 # Phase. Thus, this script does not run over any events at all, but over the data available
57 # in the prepared training sample root file.
58 eventinfosetter = register_module('EventInfoSetter')
59 # default phase3 geometry:
60 exp_number = 0
61 # if environment variable is set then phase2 (aka Beast2) geometry will be taken
62 if os.environ.get('USE_BEAST2_GEOMETRY'):
63  exp_number = 1002
64 eventinfosetter.param("expList", [exp_number])
65 path.add_module(eventinfosetter)
66 
67 # puts the geometry and gearbox in the path
68 gearbox = register_module('Gearbox')
69 path.add_module(gearbox)
70 # the geometry is loaded from the DB by default now! The correct geometry
71 # should be pickked according to exp number
72 geometry = register_module('Geometry')
73 path.add_module(geometry)
74 
75 
76 # SecMapBootStrap Module is requiered, as it holds all the sector maps and
77 # for storing the trained SecMap.
78 secMapBootStrap = register_module('SectorMapBootstrap')
79 secMapBootStrap.param('ReadSectorMap', False)
80 secMapBootStrap.param('WriteSectorMap', True)
81 if secmap_name:
82  secMapBootStrap.param('SectorMapsOutputFile', secmap_name)
83 elif os.environ.get('USE_BEAST2_GEOMETRY'):
84  secMapBootStrap.param('SectorMapsOutputFile', 'SectorMaps_Beast2.root')
85 path.add_module(secMapBootStrap)
86 
87 # Perform SecMap Training on provided data sample
88 merger = register_module('RawSecMapMerger')
89 merger.param('rootFileNames', train_data)
90 path.add_module(merger)
91 
92 print_path(path)
93 process(path)
94 print(statistics)
tracking.validation.run.TrackingValidationRun.create_path
def create_path(self)
Definition: run.py:114