Belle II Software development
firmware_tsf.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12from ROOT import Belle2
13import os
14import socket
15from subprocess import call
16
17read_data = True
18# merger_only = True
19merger_only = False
20save_outout = True
21fast_tsf = True
22
23# set the host-based locations
24hostname = socket.gethostname()
25if 'cc.kek.jp' in hostname:
26 lib_source = '/home/belle2/tasheng/tsim/'
27 rdi_path = '/home/belle2/tasheng/Vivado_2017.2/lib/lnx64.o'
28elif 'btrgpc09' == hostname:
29 lib_source = '/home/trgadmin/tsim/'
30 rdi_path = '/home/trgadmin/Xilinx/Vivado/2017.2/lib/lnx64.o'
31elif 'belle2' '= hostname':
32 lib_source = '/home/ta/tsim/'
33 rdi_path = '/home/ta/Vivado_2017.2/lib/lnx64.o'
34else:
35 lib_source = ''
36 rdi_path = ''
37
38if not merger_only:
39 # set run time library path
40 if rdi_path not in os.environ['LD_LIBRARY_PATH']:
41 print('please set environment variable first! do either')
42 print('export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:' + rdi_path)
43 print('or')
44 print('setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:' + rdi_path)
45 exit(1)
46
47 # link to 2D design snapshot
48 for link in ['xsim.dir', 'innerLRLUT.mif', 'outerLRLUT.mif']:
49 if link not in os.listdir(os.getcwd()):
50 call(['ln', '-s', lib_source + link])
51
52"""
53generate tracks with particle gun, simulate CDC and CDC trigger, save the output.
54"""
55
56# ------------ #
57# user options #
58# ------------ #
59
60# general options
61seed = 10000
62evtnum = 10
63particlegun_params = {
64 'pdgCodes': [-13, 13],
65 'nTracks': 1,
66 'momentumGeneration': 'inversePt',
67 'momentumParams': [2., 10.],
68 'thetaGeneration': 'uniform',
69 'thetaParams': [35, 145],
70 'phiGeneration': 'uniform',
71 'phiParams': [46, 135],
72 'vertexGeneration': 'uniform',
73 'xVertexParams': [0, 0.0],
74 'yVertexParams': [0, 0.0],
75 'zVertexParams': [-10., 10.]}
76
77# ------------------------- #
78# create path up to trigger #
79# ------------------------- #
80environment = Belle2.Environment.Instance()
81if not environment.getNumberEventsOverride():
82 environment.setNumberEventsOverride(evtnum)
83
84# set random seed
85b2.set_random_seed(seed)
86# suppress messages and warnings during processing:
87# b2.set_log_level(b2.LogLevel.ERROR)
88
89main = b2.create_path()
90
91empty_path = b2.create_path()
92
93# The root file is on KEKCC
94if read_data:
95 main.add_module('RootInput', inputFileName='/home/belle2/tasheng/gcr/cdc/cosmic.0001.03898.HLT1.f00007.root')
96
97main.add_module('Progress')
98
99if not read_data:
100 main.add_module('EventInfoSetter', evtNumList=evtnum)
101 main.add_module('Gearbox')
102 main.add_module('Geometry', components=['BeamPipe',
103 'PXD', 'SVD', 'CDC',
104 'MagneticFieldConstant4LimitedRCDC'])
105 particlegun = b2.register_module('ParticleGun')
106 particlegun.param(particlegun_params)
107 main.add_module(particlegun)
108
109 main.add_module('FullSim')
110 main.add_module('CDCDigitizer')
111
112# ---------------------- #
113# CDC trigger and output #
114# ---------------------- #
115
116if fast_tsf:
117 main.add_module('Gearbox')
118 main.add_module('Geometry', components=['BeamPipe',
119 'PXD', 'SVD', 'CDC',
120 'MagneticFieldConstant4LimitedRCDC'])
121 main.add_module('CDCTriggerTSF',
122 InnerTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/innerLUT_Bkg_p0.70_b0.80.coe"),
123 OuterTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/outerLUT_Bkg_p0.70_b0.80.coe"))
124
125firmtsf = b2.register_module('CDCTriggerTSFFirmware')
126firmtsf.param('mergerOnly', merger_only)
127firmtsf.logging.log_level = b2.LogLevel.DEBUG
128firmtsf.logging.debug_level = 10
129firmtsf.logging.set_info(b2.LogLevel.DEBUG, b2.LogInfo.LEVEL | b2.LogInfo.MESSAGE)
130main.add_module(firmtsf)
131
132# 2D finder
133
134# firm2d = register_module('CDCTrigger2DFinderFirmware')
135# firm2d.logging.log_level = b2.LogLevel.DEBUG
136# firm2d.logging.debug_level = 20
137# firm2d.logging.set_info(b2.LogLevel.DEBUG, b2.LogInfo.LEVEL | b2.LogInfo.MESSAGE)
138# main.add_module(firm2d)
139
140if save_outout:
141 main.add_module('RootOutput', outputFileName='tsfout.root')
142
143# Process events
144b2.process(main)
145
146# Print call statistics
147print(b2.statistics)
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
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...
Definition: FileSystem.cc:151