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