Belle II Software development
RunSRBgMC.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12import sys
13argvs = sys.argv
14argc = len(argvs)
15
16print("The input HEPEvt files needed to run SR MC sim are located in @kekcc:~igal/src/beast/SR")
17
18if len(sys.argv) != 4:
19 print("Usage: requires 2 arguments")
20 print("Argument 1: (SynchRad_HER | SynchRad_LER | test)")
21 print("Argument 2: file number")
22 print("Argument 3: ROOT output directory path")
23 sys.exit(1)
24
25name = argvs[1]
26num = argvs[2]
27output_dir = argvs[3]
28# Set realTime you want to use
29# realTime = 1.0e4 # 10us for each file <-- time in ns
30# realTime = 20 # 20ns for each file <-- time in ns - TEST
31
32outputfilename = output_dir + "/output_" + name + "_" + num + ".root"
33
34# tagname = SynchRad_HER for HER and SynchRad_LER for LER
35tagname = name
36
37
43
44
45# suppress messages and warnings during processing:
46b2.set_log_level(b2.LogLevel.ERROR)
47# set_log_level(LogLevel.DEBUG)
48
49# PHASE 2
50# FileIn = "Ph2_dt_4_8HER21445M.HEPEvt" # data for HER Phase2 dt_4-8 6.6um -> 1.07 of bunch current 0.8A
51#
52# FileIn = "Ph2_dt_4_8LER35124M.HEPEvt" #data for LERPhase2 dt_4-8
53# 6.6um -> 1.4 of bunch current 1.0A
54
55eventinfosetter = b2.register_module('EventInfoSetter')
56hepevtreader = b2.register_module('HepevtInput')
57# Ph2_dt_4_8HER21445M.HEPEvt
58# Ph2_dt_4_8HER21445MK2M.HEPEvt
59# Ph2_dt_4_8LER35124M.HEPEvt
60# PHASE 2 -> HER 6148 repetitions = 1ROF = 20us | LER 3560 repet = 1ROF = 20us
61if name == "SynchRad_HER":
62 realTime = 1.0e4 # 10us per file
63 # data for HER Phase2 dt_4-8 6.6um -> 1.07 of bunch current 0.8A
64 FileIn = "Ph2_dt_4_8HER21445M.HEPEvt"
65 # 2340 - 10us realTime Ph2_dt_4_8HER21445M.HEPEvt
66 hepevtreader.param('inputFileList', [FileIn] * 2340)
67elif name == "SynchRad_LER":
68 realTime = 1.0e4 # 10us per file
69 # data for LERPhase2 dt_4-8 6.6um -> 1.4 of bunch current 1.0A
70 FileIn = "Ph2_dt_4_8LER35124M.HEPEvt"
71 # 2340 - 10us realTime Ph2_dt_4_8HER21445M.HEPEvt
72 hepevtreader.param('inputFileList', [FileIn] * 2340)
73elif name == "test":
74 realTime = 20 # 20ns per file
75 # data HER KeV -> MeV,is used for test to be sure that code works or for
76 # cross-check.
77 FileIn = "Ph2_dt_4_8HER21445MK2M.HEPEvt"
78 # - for quick TEST 5 ->~ 20nsec
79 hepevtreader.param('inputFileList', [FileIn] * 5)
80 name = "ynchRad_HER"
81# hepevtreader.param('inputFileList', [FileIn]*1780) # 1780 - 10us realTime for Ph2_dt_4_8LER35124M.HEPEvt
82# hepevtreader.param('inputFileList', [FileIn] * 2340) # 2340 - 10us
83# realTime Ph2_dt_4_8HER21445M.HEPEvt
84
85# Register
86gearbox = b2.register_module('Gearbox')
87geometry = b2.register_module('Geometry')
88simulation = b2.register_module('FullSim')
89tagSetter = b2.register_module('BeamBkgTagSetter')
90progress = b2.register_module('Progress')
91
92# Setting the option for all non-hepevt reader modules:
93# number of events in the list must be >= number of entries in input file
94# times number of repetitions
95eventinfosetter.param('evtNumList', [1000000000])
96eventinfosetter.param('runList', [1]) # from run number 1
97eventinfosetter.param('expList', [1]) # and experiment number 1
98
99# PHASE 2
100gearbox.param('fileName', '/geometry/Beast2_phase2.xml')
101# select component you need, but always keep 'MagneticField', 'BeamPipe', 'Cryostat','HeavyMetalShield' !
102# geometry.param('components', ['MagneticField', 'BeamPipe', 'Cryostat', 'PXD', 'HeavyMetalShield',
103# 'SVD', 'BEAMABORT', 'PLUME', 'FANGS', 'CLAWS', 'CDC',
104# 'ARICH', 'TOP', 'COIL', 'ECL', 'BKLM', 'EKLM', 'HE3', ''])
105#
106geometry.set_log_level(b2.LogLevel.INFO)
107
108# simulation.param('PhysicsList', "QGSP_BERT_HP")
109simulation.param('PhysicsList', "QGSP_BERT_EMV") # faster than QGSP_BERT_HP
110# simulation.param('PhysicsList', "FTFP_BERT_EMV")
111simulation.param('UICommandsAtIdle', ["/process/inactivate nKiller"])
112simulation.param("StoreAllSecondaries", True)
113# in MeV we need this for CDC EB neutron flux simulation
114simulation.param("SecondariesEnergyCut", 0.000001)
115
116main = b2.create_path()
117
118main.add_module(eventinfosetter)
119main.add_module(progress)
120main.add_module(hepevtreader)
121# print_params(hepevtreader)
122main.add_module(gearbox)
123main.add_module(geometry)
124main.add_module(simulation)
125
126# set background tag in SimHits, leave main path if all SimHits are empty
127tagSetter.param('backgroundType', tagname)
128tagSetter.param('realTime', realTime)
129main.add_module(tagSetter)
130emptyPath = b2.create_path()
131tagSetter.if_false(emptyPath)
132b2.print_params(tagSetter)
133
134# output: SimHits only
135rootoutput = b2.register_module('RootOutput')
136rootoutput.param('outputFileName', outputfilename)
137rootoutput.param('updateFileCatalog', False)
138
139# PHASE 2
140# Select branches you need in output.
141rootoutput.param('branchNames',
142 ["SVDSimHits",
143 "SVDTrueHits",
144 "SVDTrueHitsToSVDSimHits",
145 "PXDSimHits",
146 "MCParticleToPXDSimHits",
147 "CLAWSSimHits",
148 "ClawsHits",
149 "FANGSSimHits",
150 "FANGSHits",
151 "PlumeSimHits",
152 "BeamabortSimHits",
153 "BeamabortHits",
154 "PindiodeSimHits",
155 "PindiodeHits",
156 "QcsmonitorSimHits",
157 "QcsmonitorHits",
158 "He3tubeSimHits",
159 "He3tubeHits",
160 "MicrotpcSimHits",
161 "MicrotpcHits",
162 "SADMetaHits"])
163MIP_to_PE = [12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12]
164he3digi = b2.register_module('He3Digitizer')
165he3digi.param('conversionFactor', 0.303132019)
166he3digi.param('useMCParticles', False)
167main.add_module(he3digi)
168diadigi = b2.register_module('BeamDigitizer')
169diadigi.param('WorkFunction', 13.25)
170diadigi.param('FanoFactor', 0.382)
171main.add_module(diadigi)
172pindigi = b2.register_module('PinDigitizer')
173pindigi.param('WorkFunction', 3.64)
174pindigi.param('FanoFactor', 0.13)
175main.add_module(pindigi)
176clawsdigi = b2.register_module('ClawsDigitizer')
177clawsdigi.param('ScintCell', 16)
178clawsdigi.param('C_keV_to_MIP', 457.114)
179clawsdigi.param('C_MIP_to_PE', MIP_to_PE)
180clawsdigi.param('PEthres', 1.0)
181main.add_module(clawsdigi)
182qcssdigi = b2.register_module('QcsmonitorDigitizer')
183qcssdigi.param('ScintCell', 40)
184qcssdigi.param('C_keV_to_MIP', 1629.827)
185qcssdigi.param('C_MIP_to_PE', 15.0)
186qcssdigi.param('MIPthres', 0.5)
187main.add_module(qcssdigi)
188fangsdigi = b2.register_module('FANGSDigitizer')
189main.add_module(fangsdigi)
190tpcdigi = b2.register_module('TpcDigitizer')
191main.add_module(tpcdigi)
192
193main.add_module(rootoutput)
194
195# Process events
196b2.process(main)
197
198# Print call statistics
199print(b2.statistics)