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