Belle II Software development
RunSADBgMC_phase1.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12from ROOT import Belle2
13import sys
14import datetime
15
16
17class PyTrigger(b2.Module):
18
19 """Returns 1 if current event contains at least one BEAST hit, 0 otherwise"""
20
21 def initialize(self):
22 """reimplementation of Module::initialize()."""
23
24 def event(self):
25 """reimplementation of Module::event()."""
26
27 self.return_value(0)
28 mcparticles = Belle2.PyStoreArray('MCParticles')
29 for p in mcparticles:
30 print()
31 if len(p.getRelationsTo('MicrotpcSimHits')) > 0 \
32 or len(p.getRelationsTo('He3tubeSimHits')) > 0 \
33 or len(p.getRelationsTo('PindiodeSimHits')) > 0 \
34 or len(p.getRelationsTo('BgoSimHits')) > 0 \
35 or len(p.getRelationsTo('CsiSimHits')) > 0:
36 # B2INFO('found a Beast!')
37 self.return_value(1)
38
39 break
40
41
42d = datetime.datetime.today()
43print(d.strftime('job start: %Y-%m-%d %H:%M:%S\n'))
44
45# read parameters
46
47argvs = sys.argv
48argc = len(argvs)
49
50if argc == 3:
51 name = argvs[1]
52 num = argvs[2]
53else:
54 print('./RunBGMC.py [(RBB,Touschek,Coulomb)_(HER,LER)(,_far)] [num]')
55 sys.exit()
56
57# set accring (0:LER, 1:HER)
58if name.find('LER') != -1:
59 accring = 0
60elif name.find('HER') != -1:
61 accring = 1
62else:
63 print('name should include either of HER or LER')
64 sys.exit()
65
66# set readmode (0:RBB, 1:Toucshek/Coulomb/Brems)
67# if name.find("RBB") != -1 :
68# readmode = 0
69# else
70# readmode = 1
71
72# set range (0:RBB, 1:Toucshek/Coulomb/Brems)
73if name.find('far') != -1:
74 range = 2800
75else:
76 range = 400
77
78# inputfilename = 'phase1_fullsim2/' + name + '.root'
79inputfilename = 'forIgal/' + name + '.root'
80logfilename = 'log/' + name + '_' + num + '.log'
81outputfilename = 'output/out_phase1_pos_TiN_' + name + '_' + num + '.root'
82seed = '1' + num + num + '1'
83
84# readouttime [ns]
85# good readouttime = 100000 #[ns]
86readouttime = 100000 # [ns]
87# readouttime = 1000 #[ns]
88nevent = 10000000
89# overwrite below
90# note that nevent for RBB sample should not exceed the
91# number of nevent included in the input root file.
92
93# readmode 0 is un-weighted
94# readmode 1 is weighted
95
96if name == 'Brems_LER':
97 readmode = 1
98elif name == 'Touschek_LER':
99 # nevent=583 #1us
100 readmode = 1
101elif name == 'Coulomb_LER':
102 # nevent=3985
103 readmode = 1
104elif name == 'Brems_HER':
105 # nevent=1473
106 readmode = 1
107elif name == 'Touschek_HER':
108 # nevent=2104 #1us
109 readmode = 1
110elif name == 'Coulomb_HER':
111 # nevent=4257
112 readmode = 1
113else:
114 # nevent=4489
115
116 print('Unknown name!')
117 sys.exit()
118
119print('accring: ', accring, '(0:LER, 1:HER)')
120print('input: ', inputfilename)
121print('log: ', logfilename)
122print('output: ', outputfilename)
123print('range: ', range)
124print('seed: ', seed)
125print('nevent: ', nevent)
126print('readouttime:', readouttime)
127
128# -----------------------------------------------------------------
129
130
164
165# Set the global log level
166# set_log_level(LogLevel.ERROR)
167b2.set_log_level(b2.LogLevel.WARNING)
168# set_log_level(LogLevel.DEBUG)
169
170b2.set_random_seed(int(seed))
171
172# Register the event meta generator and set the number of events to a very
173# high number which exceeds the number of events in the input file.
174# Register the event meta generator and set the number of events to a very
175# high number which exceeds the number of events in the input file.
176eventinfosetter = b2.register_module('EventInfoSetter')
177eventinfosetter.param({'evtNumList': [nevent], 'runList': [1], 'expList': [1]})
178
179# Register the TouschekSADInput module and specify the location of the Touschek
180# input file. The file can be downloaded from the TWiki.
181touschekinput = b2.register_module('SADInput')
182touschekinput.param('Filename', inputfilename)
183
184# Set the ReadMode of the TouschekSAD input module
185# 0 = one SAD particle per event. This produces weighted events.
186# 1 = one real particle per event. This produces unweighted events.
187# 2 = all SAD particles in one event. Can be used for visualization
188touschekinput.param('ReadMode', readmode)
189
190# Set the RingFlag of the TouschekSAD input module
191# 0 = LER
192# 1 = HER
193touschekinput.param('AccRing', accring)
194
195# Set the readout time for your subdetector in [ns]. The value given
196# here corresponds to the readout time of the PXD.
197# This setting is only used if the 'ReadMode' is set to 1.
198touschekinput.param('ReadoutTime', readouttime)
199
200# Set the range around the IP in which SAD particles are accepted
201# into the simulation. The value given below is highly recommended.
202touschekinput.param('Range', range)
203
204# If you would like to see some information about the created particles
205# set the logging output of the Touschek Input module to DEBUG.
206# touschekinput.set_log_level(LogLevel.DEBUG)
207
208# Register the standard chain of modules to the framework,
209# which are required for the simulation.
210gearbox = b2.register_module('Gearbox')
211geometry = b2.register_module('Geometry')
212gearbox.param('fileName', '/geometry/Beast2_phase1.xml')
213fullsim = b2.register_module('FullSim')
214
215param_fullsim = {'RegisterOptics': 1, 'PhotonFraction': 0.3}
216fullsim.param(param_fullsim)
217fullsim.param('PhysicsList', 'QGSP_BERT_HP')
218fullsim.param('UICommandsAtIdle', ['/process/inactivate nKiller'])
219
220# If you want to store all secondaries in MCParticles, use following lines.
221# Default is False and 1MeV cut.
222fullsim.param('StoreAllSecondaries', True)
223fullsim.param('SecondariesEnergyCut', 0.0) # in MeV
224
225# fullsim.set_log_level(LogLevel.DEBUG)
226
227# Add additional modules according to your own needs
228progress = b2.register_module('Progress')
229
230# Write the output to a file
231rootoutput = b2.register_module('RootOutput')
232rootoutput.param('outputFileName', outputfilename)
233rootoutput.param('updateFileCatalog', False)
234# rootoutput.param('branchNames', ["BeamBackHits"])
235# routoutput.param('branchNames', ["BeamBackHits","EKLMStepHits"])
236# rootoutput.param('branchNames', ["BgoSimHits","MicrotpcSimHits","PindiodeSimHits","He3tubeSimHits","BeamBackHits","MCParticles"])
237# rootoutput.param('branchNames', ["BgoSimHits","MicrotpcSimHits","PindiodeSimHits","He3tubeSimHits","CsiSimHits","MCParticles"])
238# rootoutput.param('branchNames', ["BgoSimHits","MicrotpcSimHits","PindiodeSimHits","He3tubeSimHits","CsiSimHits"])
239# rootoutput.param('branchNames', ["BgoSimHits","MicrotpcSimHits","PindiodeSimHits","He3tubeSimHits","CsiSimHits","MCParticles"])
240rootoutput.param('branchNames', ['BgoSimHits', 'MicrotpcSimHits',
241 'PindiodeSimHits', 'He3tubeSimHits', 'CsiSimHits'])
242
243# Create the main path and add the required modules
244main = b2.create_path()
245main.add_module(eventinfosetter)
246main.add_module(gearbox)
247main.add_module(touschekinput)
248main.add_module(geometry)
249main.add_module(fullsim)
250main.add_module(progress)
251
255
256# if PyTrigger returns 0, we'll jump into an empty path
257# (skipping further modules in 'main': Beast2 SimHits)
258# emptypath = create_path()
259# trigger.if_false(emptypath)
260
261main.add_module(rootoutput)
262
263# he3digi = register_module('He3Digitizer')
264# main.add_module(he3digi)
265# sampletime=10000
266# he3tube = register_module('He3tube')
267# he3tube.param('sampleTime', sampletime);
268# main.add_module(he3tube)
269
270b2.process(main)
271
272# Print some basic event statistics
273print('Event Statistics:')
274print(b2.statistics)
275
276d = datetime.datetime.today()
277print(d.strftime('job finish: %Y-%m-%d %H:%M:%S\n'))
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72