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