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