Belle II Software  release-05-01-25
runSimulation.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 """
5 Simple example script to simulate cosmics events only with CDC.
6 Usage :
7 basf2 runSimulation.py <exp> <run> <nevt> <st>
8 exp: Experimental number
9 run: Run number
10 nevt: Number of events to be generated
11 st: Stream ID
12 """
13 
14 from basf2 import *
15 from ROOT import Belle2
16 import datetime
17 from generators import add_cosmics_generator
18 from simulation import add_simulation
19 
20 import os.path
21 import sys
22 from cdc.cr import getDataPeriod, getTriggerType, getMapperAngle
23 from cdc.cr import add_cdc_cr_simulation
24 from cdc.cr import add_GCR_Trigger_simulation
25 
26 
27 # Set the global log level
28 set_log_level(LogLevel.INFO)
29 
30 # Set database
31 reset_database()
32 use_database_chain()
33 # For GCR, July and August 2017.
34 use_central_database("GT_gen_data_003.04_gcr2017-08", LogLevel.WARNING)
35 
36 
37 def sim(exp, run, evt, st, topInCounter=False, magneticField=True, fieldMapper=False):
38  """
39  exp : Experimental number
40  run : Run number
41  evt : Number of events to be generated
42  st : stream ID
43  """
44 
45  main_path = create_path()
46 
47  main_path.add_module('EventInfoSetter',
48  expList=[int(exp)],
49  evtNumList=[int(evt)],
50  runList=[int(run)])
51 
52  main_path.add_module('Progress')
53 
54  period = getDataPeriod(exp=int(exp),
55  run=int(run))
56 
57  mapperAngle = getMapperAngle(exp=int(exp),
58  run=int(run))
59 
60  triggerType = getTriggerType(exp=int(exp),
61  run=int(run))
62 
63  if fieldMapper is True:
64  main_path.add_module('CDCJobCntlParModifier',
65  MapperGeometry=True,
66  MapperPhiAngle=mapperAngle)
67 
68  components = ['CDC', 'ECL', 'MagneticField'] if magneticField is True else ['CDC', 'ECL']
69 
70  add_cosmics_generator(path=main_path,
71  components=components,
72  global_box_size=[8, 8, 8],
73  accept_box=[0.7, 0.3, 0.3], # LWH
74  keep_box=[0.7, 0.3, 0.3],
75  cosmics_data_dir='data/generators/modules/cryinput/',
76  setup_file='./cry.setup',
77  data_taking_period=period,
78  top_in_counter=topInCounter)
79 
80  # add_simulation(main_path)
81  add_cdc_cr_simulation(main_path, components=components)
82 
83  if triggerType is not None:
84  add_GCR_Trigger_simulation(main_path,
85  backToBack=True if triggerType == 'b2b' else False,
86  skipEcl=True)
87  else:
88  B2INFO('skip tsim')
89 
90  output = register_module('RootOutput',
91  outputFileName='gcr.cdc.{0:04d}.{1:06d}.{2:04d}.root'.format(int(exp), int(run), int(st)))
92  main_path.add_module(output)
93  print_path(main_path)
94  process(main_path)
95  print(statistics)
96 
97 
98 if __name__ == "__main__":
99 
100  import argparse
101  parser = argparse.ArgumentParser()
102  parser.add_argument('exp', help='Experimental number')
103  parser.add_argument('run', help='Run number')
104  parser.add_argument('evt', help='Number of events to be generated')
105  parser.add_argument('st', help='Stream ID')
106 
107  args = parser.parse_args()
108  sim(args.exp, args.run, args.evt, args.st, topInCounter=False, magneticField=True, fieldMapper=True)
cr