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