Belle II Software development
firm2d.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12from ROOT import Belle2
13from math import pi, tan
14import os
15from subprocess import call
16
17read_tsf = True
18save_outout = False
19kekcc = True
20btrgpc09 = False
21
22if kekcc:
23 lib_source = '/home/belle2/tasheng/tsim/'
24 rdi_path = '/home/belle2/tasheng/Vivado_2017.2/lib/lnx64.o'
25elif btrgpc09:
26 lib_source = '/home/trgadmin/tsim/'
27 rdi_path = '/home/trgadmin/Xilinx/Vivado/2017.2/lib/lnx64.o'
28else:
29 lib_source = ''
30 rdi_path = ''
31
32# set run time library path
33if rdi_path not in os.environ['LD_LIBRARY_PATH']:
34 print('please set environment variable first! do either')
35 print('export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:' + rdi_path)
36 print('or')
37 print('setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:' + rdi_path)
38 exit(1)
39
40# link to 2D design snapshot
41for link in ['xsim.dir', 'innerLRLUT.mif', 'outerLRLUT.mif']:
42 if link not in os.listdir(os.getcwd()):
43 call(['ln', '-s', lib_source + link])
44
45"""
46generate tracks with particle gun, simulate CDC and CDC trigger, save the output.
47"""
48
49# ------------ #
50# user options #
51# ------------ #
52
53if not read_tsf:
54 # general options
55 seed = 10000
56 evtnum = 10
57 particlegun_params = {
58 'pdgCodes': [-13, 13],
59 'nTracks': 1,
60 'momentumGeneration': 'inversePt',
61 # 'momentumParams': [0.3, 10.],
62 'momentumParams': [3., 10.],
63 'thetaGeneration': 'uniform',
64 # 'thetaParams': [35, 145],
65 'thetaParams': [80, 100],
66 'phiGeneration': 'uniform',
67 'phiParams': [46, 135],
68 'vertexGeneration': 'uniform',
69 'xVertexParams': [0, 0.0],
70 'yVertexParams': [0, 0.0],
71 # 'zVertexParams': [-50.0, 50.0]}
72 'zVertexParams': [-10., 10.]}
73
74 # ------------------------- #
75 # create path up to trigger #
76 # ------------------------- #
77
78 # set random seed
79 b2.set_random_seed(seed)
80 # suppress messages and warnings during processing:
81 # b2.set_log_level(b2.LogLevel.ERROR)
82
83main = b2.create_path()
84
85empty_path = b2.create_path()
86
87# z position of the two ends of the first layer used by trigger
88z_SL0 = [-31 - 1.5 / tan(30 / 180. * pi), 57 + 1.5 / tan(17 / 180. * pi)]
89# radius of the first layer used by trigger
90r_SL0 = 18.3
91
92
93class Skim(b2.Module):
94 """
95 Reject tracks with bad combination of z0 and theta
96 """
97
98 def initialize(self):
99 """
100 Initialize self.mc with MCParticles StoreArray
101 """
102
103 self.mc = Belle2.PyStoreArray('MCParticles')
104
105 def event(self):
106 """
107 Reject tracks with bad combination of z0 and theta
108 """
109 self.return_value(0)
110 z0 = self.mc[0].getVertex().Z()
111 vec = self.mc[0].getMomentum()
112 # skip the event if the track didn't reach SL0
113 if z_SL0[0] < z0 + r_SL0 / vec.Pt() * vec.Z() < z_SL0[1]:
114 self.return_value(1)
115
116
117main.add_module('Progress')
118
119if read_tsf:
120 inputName = 'tsfout.root'
121 # inputName = '~/gcr/cdc/cosmic.0001.03898.HLT1.f00007.root'
122 main.add_module('RootInput', inputFileName=inputName)
123
124else:
125 main.add_module('EventInfoSetter', evtNumList=evtnum)
126 main.add_module('Gearbox')
127 main.add_module('Geometry', components=['BeamPipe',
128 'PXD', 'SVD', 'CDC',
129 'MagneticFieldConstant4LimitedRCDC'])
130 particlegun = b2.register_module('ParticleGun')
131 particlegun.param(particlegun_params)
132 main.add_module(particlegun)
133
134 skim = Skim()
135
136 main.add_module(skim)
137 skim.if_false(empty_path)
138
139 main.add_module('FullSim')
140 main.add_module('CDCDigitizer')
141
142# ---------------------- #
143# CDC trigger and output #
144# ---------------------- #
145
146# TSF
147# main.add_module('CDCTriggerTSF',
148# InnerTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/innerLUT_Bkg_p0.70_b0.80.coe"),
149# OuterTSLUTFile=Belle2.FileSystem.findFile("data/trg/cdc/outerLUT_Bkg_p0.70_b0.80.coe"))
150
151 firmtsf = b2.register_module('CDCTriggerTSFFirmware')
152 # firmtsf.logging.log_level = b2.LogLevel.DEBUG
153 # firmtsf.logging.debug_level = 30
154 # firmtsf.logging.set_info(b2.LogLevel.DEBUG, b2.LogInfo.LEVEL | b2.LogInfo.MESSAGE)
155 main.add_module(firmtsf)
156
157# 2D finder
158# original2d = register_module('CDCTrigger2DFinder')
159# original2d.param('testFilename', 'tracks.txt')
160
161firm2d = b2.register_module('CDCTrigger2DFinderFirmware')
162firm2d.logging.log_level = b2.LogLevel.DEBUG
163firm2d.logging.debug_level = 20
164firm2d.logging.set_info(b2.LogLevel.DEBUG, b2.LogInfo.LEVEL | b2.LogInfo.MESSAGE)
165firm2d.param('nClocks', 32)
166main.add_module(firm2d)
167
168if save_outout:
169 main.add_module('RootOutput', outputFileName='tsfout.root')
170
171# Process events
172b2.process(main)
173
174# Print call statistics
175print(b2.statistics)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
mc
MCParticles StoreArray.
Definition: firm2d.py:103
def initialize(self)
Definition: firm2d.py:98
def event(self)
Definition: firm2d.py:105