Belle II Software development
trainingPreparation.py
1#!/usr/bin/env python3
2
3
10
11
22
23
24import basf2 as b2
25from setup_modules import setup_RTCtoSPTCConverters
26import argparse
27import os
28
29# ---------------------------------------------------------------------------------------
30# Argument parser to enable training sample selection via comandline option.
31parser = argparse.ArgumentParser(description='Training sample preparation:\
32 Prepare a data sample to train the sector map.\n\
33 Usage: basf2 traininPreparation.py -i dataSample.root -- --enable_selection boolean')
34parser.add_argument(
35 '--enable_selection',
36 dest='use_NoKick',
37 action='store_const',
38 const=True,
39 default=False,
40 help='enable the selection of training sample based on track parameters')
41
42parser.add_argument(
43 '--disable_checkFit',
44 dest='checkFit',
45 action='store_const',
46 const=False,
47 default=True,
48 help="By default only RecoTracks with valid fit are taken for training. Using this option will disable that. ")
49
50arguments = parser.parse_args()
51use_noKick = arguments.use_NoKick
52
53
54# ---------------------------------------------------------------------------------------
55# Settings
56
57# Logging and Debug Level
58# TODO: Remove logLevel, as it can be set via basf2 option -l
59b2.set_log_level(b2.LogLevel.ERROR)
60b2.log_to_file('logVXDTF2Preparation.log', append=False)
61# if false PXD hits will be ignored in the trainings data collection
62# Currently we dont do PXD tracking with vxdtf2 (as of 15.02.2018)
63usePXD = False
64
65# ---------------------------------------------------------------------------------------
66# Create paths
67path = b2.create_path()
68
69
70# Input Module
71rootInputM = b2.register_module('RootInput')
72path.add_module(rootInputM)
73
74# Event Info Module
75eventinfoprinter = b2.register_module('EventInfoPrinter')
76path.add_module(eventinfoprinter)
77
78path.add_module("PrintCollections", printForEvent=1)
79
80
81# puts the geometry and gearbox in the path
82gearbox = b2.register_module('Gearbox')
83path.add_module(gearbox)
84# the geometry is loaded from the DB by default now! The correct geometry
85# should be pickked according to exp number for the generated events.
86geometry = b2.register_module('Geometry')
87path.add_module(geometry)
88
89# Event counter
90# eventCounter = register_module('EventCounter')
91# path.add_module(eventCounter)
92
93
94# put PXD and SVD SpacePoints into the same StoreArray
95if usePXD:
96 spCreatorPXD = b2.register_module('PXDSpacePointCreator')
97 spCreatorPXD.param('NameOfInstance', 'PXDSpacePointCreator')
98 spCreatorPXD.param('SpacePoints', 'PXDSpacePoints')
99 path.add_module(spCreatorPXD)
100
101spCreatorSVD = b2.register_module('SVDSpacePointCreator')
102spCreatorSVD.param('OnlySingleClusterSpacePoints', False)
103spCreatorSVD.param('NameOfInstance', 'SVDSpacePointCreator')
104spCreatorSVD.param('SpacePoints', 'SVDSpacePoints')
105path.add_module(spCreatorSVD)
106
107
108# Converts GenFit track candidates and checks them, with respect to the SecMap settings
109# Produces SpacePoint TrackCand which is used in VXDTFTrainingDataCollector.
110setup_RTCtoSPTCConverters(path=path,
111 SVDSPscollection='SVDSpacePoints',
112 PXDSPscollection='PXDSpacePoints',
113 RTCinput='MCRecoTracks',
114 sptcOutput='checkedSPTCs',
115 usePXD=usePXD,
116 logLevel=b2.LogLevel.ERROR,
117 useNoKick=use_noKick,
118 useOnlyFittedTracks=True) # train on fitted tracks only
119
120
121# SecMap BootStrap
122# Module to fetch SecMap Config and store or load SecMap Training.
123# Config is defined in /tracking/modules/vxdtfRedesing/src/SectorMapBootstrapModule.cc
124# and must be available for the training of the SecMap
125# Double False only fetches config.
126secMapBootStrap = b2.register_module('SectorMapBootstrap')
127secMapBootStrap.param('ReadSectorMap', False)
128secMapBootStrap.param('WriteSectorMap', False)
129path.add_module(secMapBootStrap)
130
131
132# Module for generation of train sample for SecMap Training
133nameTag = 'Belle2'
134if os.environ.get('USE_BEAST2_GEOMETRY'):
135 nameTag = 'Beast2'
136
137if usePXD:
138 nameTag += '_VXD'
139else:
140 nameTag += '_SVDOnly'
141
142#
143SecMapTrainerBase = b2.register_module('VXDTFTrainingDataCollector')
144SecMapTrainerBase.param('NameTag', nameTag)
145SecMapTrainerBase.param('SpacePointTrackCandsName', 'checkedSPTCs')
146# SecMapTrainerBase.logging.log_level = LogLevel.DEBUG
147path.add_module(SecMapTrainerBase)
148
149# this can take quite long so it is good to know if it is still running
150path.add_module('Progress')
151
152path.add_module("PrintCollections", printForEvent=1)
153
154b2.process(path)
155
156# to show the settings of all modules (only those differing from default)
157b2.print_path(path)
158
159print(b2.statistics)