Belle II Software  release-08-01-10
simulateLaserData.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # -----------------------------------------------------------------------------------------------
13 # Simulation of local laser run with raw data output in sroot format.
14 # Output file mimics entirely the local data (format, time mis-calibrations etc)
15 # and can be used directly in run_channelT0_laser_calibration.py
16 #
17 # Usage: simulateLaserData.py experiment run [fileNumber] -n <num_of_events>
18 # -----------------------------------------------------------------------------------------------
19 
20 from basf2 import create_path, process, statistics, conditions
21 import sys
22 
23 # Argument parsing
24 argvs = sys.argv
25 if len(argvs) < 3:
26  print("usage: basf2", argvs[0], "experiment run [fileNumber] -n <num_of_events>")
27  sys.exit()
28 experiment = int(argvs[1])
29 run = int(argvs[2])
30 num = 'MC'
31 if len(argvs) > 3:
32  num = 'MC-' + argvs[3]
33 
34 # output file name
35 expRun = '{:0=4d}'.format(experiment) + '.' + '{:0=5d}'.format(run)
36 filename = f"top.{expRun}.{num}.sroot"
37 
38 # global tags for run dependent simulation
39 conditions.append_globaltag('patch_main_release-07_noTOP')
40 if experiment < 20:
41  conditions.append_globaltag('data_reprocessing_proc13') # experiments 8 - 18
42 else:
43  conditions.append_globaltag('data_reprocessing_prompt') # experiments 20 - 26
44 conditions.append_globaltag('online')
45 
46 
47 def addLaserSource(x, angle, slotID, path):
48  '''
49  Adds a laser source to the path
50  :param x local x coordinate of source in the local frame
51  :param angle vertical tilt of the source
52  :param slotID 1-16, slot number. If it's 0, then all the coorinates are in the BelleII frame
53  :param path path
54  '''
55  path.add_module('OpticalGun',
56  minAlpha=0.0, # not used if angulardistribution == 'Gaussian'
57  maxAlpha=33.0, # not used if angulardistribution == 'Gaussian'
58  na=0.50, # used only if angulardistribution == 'Gaussian'
59  startTime=-53.0, # start time relative to the first cal pulse (according to run 8/414)
60  pulseWidth=10.0e-3, # laser time jitter (1 Gaussian sigma), [ns]
61  numPhotons=62.5, # according to run 8/414
62  diameter=10.0e-3, # source diameter in cm
63  slotID=slotID, # if nonzero, local (slot) frame, otherwise Belle II
64  x=x,
65  y=-3.26,
66  z=-131.33,
67  theta=180 + angle,
68  phi=0.0,
69  psi=0.0,
70  angularDistribution='uniform'
71  # angularDistribution='(40-x)*TMath::Sin(x)'
72  )
73 
74 
75 # Create path
76 main = create_path()
77 
78 # Set number of events to generate
79 main.add_module('EventInfoSetter', expList=[experiment], runList=[run])
80 
81 # Gearbox
82 main.add_module('Gearbox')
83 
84 # Geometry
85 main.add_module('Geometry')
86 
87 # Pulse generator
88 main.add_module('TOPCalPulseGenerator', asicChannels=[0])
89 
90 # Optical sources
91 for slot in range(1, 17):
92  for pos in [0.9, 5.7, 11.3, 16.9, 22.5, 28.1, 33.7, 39.3, 44.1]:
93  angle = 17
94  x = -45. / 2. + pos
95  addLaserSource(x, angle, slot, main)
96 
97 # Simulation
98 main.add_module('FullSim')
99 
100 # Digitization
101 main.add_module('TOPDigitizer', lookBackWindows=28)
102 
103 # Raw data packing
104 main.add_module('TOPPacker')
105 
106 # Output in sroot format
107 main.add_module('SeqRootOutput', saveObjs=['EventMetaData', 'RawTOPs'], outputFileName=filename)
108 
109 # Show progress of processing
110 main.add_module('Progress')
111 
112 # Process events
113 process(main)
114 
115 # Print call statistics
116 print(statistics)