Belle II Software  release-08-01-10
RunSADBgMC_phase1.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2 as b2
12 from ROOT import Belle2
13 import sys
14 import datetime
15 
16 
17 class 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 
42 d = datetime.datetime.today()
43 print(d.strftime('job start: %Y-%m-%d %H:%M:%S\n'))
44 
45 # read parameters
46 
47 argvs = sys.argv
48 argc = len(argvs)
49 
50 if argc == 3:
51  name = argvs[1]
52  num = argvs[2]
53 else:
54  print('./RunBGMC.py [(RBB,Touschek,Coulomb)_(HER,LER)(,_far)] [num]')
55  sys.exit()
56 
57 # set accring (0:LER, 1:HER)
58 if name.find('LER') != -1:
59  accring = 0
60 elif name.find('HER') != -1:
61  accring = 1
62 else:
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)
73 if name.find('far') != -1:
74  range = 2800
75 else:
76  range = 400
77 
78 # inputfilename = 'phase1_fullsim2/' + name + '.root'
79 inputfilename = 'forIgal/' + name + '.root'
80 logfilename = 'log/' + name + '_' + num + '.log'
81 outputfilename = 'output/out_phase1_pos_TiN_' + name + '_' + num + '.root'
82 seed = '1' + num + num + '1'
83 
84 # readouttime [ns]
85 # good readouttime = 100000 #[ns]
86 readouttime = 100000 # [ns]
87 # readouttime = 1000 #[ns]
88 nevent = 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 
96 if name == 'Brems_LER':
97  readmode = 1
98 elif name == 'Touschek_LER':
99  # nevent=583 #1us
100  readmode = 1
101 elif name == 'Coulomb_LER':
102  # nevent=3985
103  readmode = 1
104 elif name == 'Brems_HER':
105  # nevent=1473
106  readmode = 1
107 elif name == 'Touschek_HER':
108  # nevent=2104 #1us
109  readmode = 1
110 elif name == 'Coulomb_HER':
111  # nevent=4257
112  readmode = 1
113 else:
114  # nevent=4489
115 
116  print('Unknown name!')
117  sys.exit()
118 
119 print('accring: ', accring, '(0:LER, 1:HER)')
120 print('input: ', inputfilename)
121 print('log: ', logfilename)
122 print('output: ', outputfilename)
123 print('range: ', range)
124 print('seed: ', seed)
125 print('nevent: ', nevent)
126 print('readouttime:', readouttime)
127 
128 # -----------------------------------------------------------------
129 
130 
164 
165 # Set the global log level
166 # set_log_level(LogLevel.ERROR)
167 b2.set_log_level(b2.LogLevel.WARNING)
168 # set_log_level(LogLevel.DEBUG)
169 
170 b2.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.
176 eventinfosetter = b2.register_module('EventInfoSetter')
177 eventinfosetter.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.
181 touschekinput = b2.register_module('SADInput')
182 touschekinput.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
188 touschekinput.param('ReadMode', readmode)
189 
190 # Set the RingFlag of the TouschekSAD input module
191 # 0 = LER
192 # 1 = HER
193 touschekinput.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.
198 touschekinput.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.
202 touschekinput.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.
210 gearbox = b2.register_module('Gearbox')
211 geometry = b2.register_module('Geometry')
212 gearbox.param('fileName', '/geometry/Beast2_phase1.xml')
213 fullsim = b2.register_module('FullSim')
214 
215 param_fullsim = {'RegisterOptics': 1, 'PhotonFraction': 0.3}
216 fullsim.param(param_fullsim)
217 fullsim.param('PhysicsList', 'QGSP_BERT_HP')
218 fullsim.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.
222 fullsim.param('StoreAllSecondaries', True)
223 fullsim.param('SecondariesEnergyCut', 0.0) # in MeV
224 
225 # fullsim.set_log_level(LogLevel.DEBUG)
226 
227 # Add additional modules according to your own needs
228 progress = b2.register_module('Progress')
229 
230 # Write the output to a file
231 rootoutput = b2.register_module('RootOutput')
232 rootoutput.param('outputFileName', outputfilename)
233 rootoutput.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"])
240 rootoutput.param('branchNames', ['BgoSimHits', 'MicrotpcSimHits',
241  'PindiodeSimHits', 'He3tubeSimHits', 'CsiSimHits'])
242 
243 # Create the main path and add the required modules
244 main = b2.create_path()
245 main.add_module(eventinfosetter)
246 main.add_module(gearbox)
247 main.add_module(touschekinput)
248 main.add_module(geometry)
249 main.add_module(fullsim)
250 main.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 
261 main.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 
270 b2.process(main)
271 
272 # Print some basic event statistics
273 print('Event Statistics:')
274 print(b2.statistics)
275 
276 d = datetime.datetime.today()
277 print(d.strftime('job finish: %Y-%m-%d %H:%M:%S\n'))
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72