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