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