Belle II Software  release-06-00-14
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 tag for run dependent simulation (the latest one recommended!)
39 conditions.append_globaltag('data_reprocessing_proc11')
40 
41 
42 def addLaserSource(x, angle, slotID, path):
43  '''
44  Adds a laser source to the path
45  :param x local x coordinate of source in the local frame
46  :param angle vertical tilt of the source
47  :param slotID 1-16, slot number. If it's 0, then all the coorinates are in the BelleII frame
48  :param path path
49  '''
50  path.add_module('OpticalGun',
51  minAlpha=0.0, # not used if angulardistribution == 'Gaussian'
52  maxAlpha=33.0, # not used if angulardistribution == 'Gaussian'
53  na=0.50, # used only if angulardistribution == 'Gaussian'
54  startTime=-53.0, # start time relative to the first cal pulse (according to run 8/414)
55  pulseWidth=10.0e-3, # laser time jitter (1 Gaussian sigma), [ns]
56  numPhotons=62.5, # according to run 8/414
57  diameter=10.0e-3, # source diameter in cm
58  slotID=slotID, # if nonzero, local (slot) frame, otherwise Belle II
59  x=x,
60  y=-3.26,
61  z=-131.33,
62  theta=180 + angle,
63  phi=0.0,
64  psi=0.0,
65  angularDistribution='uniform'
66  # angularDistribution='(40-x)*TMath::Sin(x)'
67  )
68 
69 
70 # Create path
71 main = create_path()
72 
73 # Set number of events to generate
74 main.add_module('EventInfoSetter', expList=[experiment], runList=[run])
75 
76 # Gearbox
77 main.add_module('Gearbox')
78 
79 # Geometry
80 main.add_module('Geometry')
81 
82 # Pulse generator
83 main.add_module('TOPCalPulseGenerator', asicChannels=[0])
84 
85 # Optical sources
86 for slot in range(1, 17):
87  for pos in [0.9, 5.7, 11.3, 16.9, 22.5, 28.1, 33.7, 39.3, 44.1]:
88  angle = 17
89  x = -45. / 2. + pos
90  addLaserSource(x, angle, slot, main)
91 
92 # Simulation
93 main.add_module('FullSim')
94 
95 # Digitization
96 main.add_module('TOPDigitizer', lookBackWindows=28)
97 
98 # Raw data packing
99 main.add_module('TOPPacker')
100 
101 # Output in sroot format
102 main.add_module('SeqRootOutput', saveObjs=['EventMetaData', 'RawTOPs'], outputFileName=filename)
103 
104 # Show progress of processing
105 main.add_module('Progress')
106 
107 # Process events
108 process(main)
109 
110 # Print call statistics
111 print(statistics)