Belle II Software development
generate_nn_train_data.py
1import basf2
2from ROOT import Belle2
3from reconstruction import add_reconstruction
4import rawdata
5
6basf2.conditions.append_globaltag('patch_main_release-09')
7
8nthreads = 30
9RecoTrackName = "RecoTracks"
10TrackFinderCollectionName = "Track2D_2"
11TrackSegmentCollectionName = "TrackSegment"
12TrackNeuroCollectionName = "TrackNN"
13EventTimeCollectionName = "CDCTRGEventTimeETF"
14TRGSummaryCollectionName = "TRGSummary"
15
16
17def add_cdc_unpacker(path, debug_level=4, debugout=False, **kwargs):
18 #
19 cdc_unpacker = basf2.register_module('CDCUnpacker')
20 cdc_unpacker.param('enableStoreCDCRawHit', True)
21 path.add_module(cdc_unpacker)
22
23 unpacker = basf2.register_module('CDCTriggerUnpacker')
24 unpacker.logging.log_level = basf2.LogLevel.DEBUG
25 # increase this value to get debug mesages in more detail
26 unpacker.logging.debug_level = debug_level
27 unpacker.logging.set_info(basf2.LogLevel.DEBUG, basf2.LogInfo.LEVEL | basf2.LogInfo.MESSAGE)
28 # size (number of words) of the Belle2Link header
29 unpacker.param('headerSize', 3)
30 # unpack the data from the 2D tracker and save its Bitstream
31 unpacker.param('unpackTracker2D', True)
32 # make CDCTriggerTrack and CDCTriggerSegmentHit objects from the 2D output
33 unpacker.param('decode2DFinderTrack', True)
34 # make CDCTriggerSegmentHit objects from the 2D input
35 unpacker.param('decode2DFinderInput', True)
36 # it seems the B2L for 2D0 and 2D1 are swapped
37 unpacker.param('2DNodeId', [
38 [0x11000001, 1],
39 [0x11000001, 0],
40 [0x11000002, 0],
41 [0x11000002, 1]])
42 unpacker.param('2DNodeId_pcie40', [
43 [0x10000001, 0],
44 [0x10000001, 1],
45 [0x10000001, 2],
46 [0x10000001, 3]])
47
48 path.add_module(unpacker)
49
50
51main = basf2.create_path()
52
53input_files = Belle2.Environment.Instance().getInputFilesOverride()
54if not input_files.empty() and input_files.front().endswith(".sroot"):
55 root_input = basf2.register_module('SeqRootInput')
56else:
57 root_input = basf2.register_module('RootInput')
58
59main.add_module(root_input)
60# loading gearbox and geometry, which is needed for simulation: ###
61main.add_module('Gearbox')
62main.add_module('Geometry')
63
64# add filter to skip events without neurotrigger b2link information
65# neurotrigger.filterTRG(main)
66#
67main.add_module('SetupGenfitExtrapolation')
68# show progress at least every 10^maxN events: ###
69main.add_module('Progress', maxN=3)
70# main.add_module('EventLimiter',maxEventsPerRun=100000)
71
72# add unpacker function from the rawdata script or the neurotrigger script: ###
74add_cdc_unpacker(main)
75
76# add reconstruction in case .sroot files were used: ###
77add_reconstruction(main, add_trigger_calculation=False)
78
79main.add_module('CDCTriggerTSF',
80 CDCHitCollectionName="CDCHits",
81 InnerTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/innerLUT_v2.2.coe"),
82 OuterTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/outerLUT_v2.2.coe"),
83 TSHitCollectionName=TrackSegmentCollectionName,
84 SaveADC=True, # save adc for NN train data generation
85 ADC_cut_threshold=20)
86
87main.add_module('CDCTrigger2DFinder',
88 minPt=0.3,
89 hitCollectionName=TrackSegmentCollectionName,
90 outputCollectionName=TrackFinderCollectionName)
91
92main.add_module('CDCTriggerRecoMatcher', TrgTrackCollectionName=TrackFinderCollectionName,
93 hitCollectionName=TrackSegmentCollectionName, axialOnly=True)
94
95main.add_module('CDCTriggerHoughETF',
96 t0CalcMethod=2,
97 useHighPassTimingList=False,
98 usePriorityTiming=False,
99 storeTracks=True,
100 hitCollectionName=TrackSegmentCollectionName,
101 outputCollectionName='CDCTriggerETFTracks',
102 outputEventTimeName=EventTimeCollectionName,
103 offset=-10)
104
105main.add_module('CDCTriggerNeuroData',
106 hitCollectionName=TrackSegmentCollectionName,
107 inputCollectionName=TrackFinderCollectionName,
108 trainOnRecoTracks=True,
109 targetCollectionName='RecoTracks',
110 EventTimeName=EventTimeCollectionName,
111 NeuroTrackInputMode=False,
112 singleUse=True,
113 writeconfigFileName='',
114 configFileName=Belle2.FileSystem.findFile('trg/cdc/examples/test_config_for_generate_nn_train_data.conf'),
115 SaveFakeTrack=True,
116 logLevel=basf2.LogLevel.DEBUG, # show some debug output
117 debugLevel=500,
118 gzipFilename='out2.gz')
119
120basf2.process(main)
static Environment & Instance()
Static method to get a reference to the Environment instance.
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
add_unpackers(path, components=None, writeKLMDigitRaws=False, addTOPRelations=False)
Definition rawdata.py:67