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