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