Belle II Software  release-08-01-10
create_mcrun.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # Simple basf2 steering file that creates mc file with PXDSimHits and
12 # EventMetaData needed for PXD gain calibration.
13 #
14 # Note that this script should only be used for runs in phase2 geometry
15 # with beams and magnetic field.
16 #
17 # Note that only SimHits from bg will be produced. A path to the mixer
18 # files for phase 2 must be specified. Only use for runs with beam
19 # where most clusters are from bg.
20 #
21 # The command below will create reference mc file for gain calibration
22 # for run=3360 in exp=3 being part of the phase2 campaign.
23 #
24 # basf2 create_mcrun.py -- --tag='Calibration_Offline_Development' --expNo=3 --runNo=3360 --setNo=0
25 
26 
27 import glob
28 import basf2 as b2
29 
30 import argparse
31 parser = argparse.ArgumentParser(
32  description="Create SimHits for a run with user specified ExpRun")
33 parser.add_argument(
34  '--tag',
35  default='Calibration_Offline_Development',
36  type=str,
37  help='Set name of GT')
38 parser.add_argument(
39  '--expNo',
40  default=3,
41  type=int,
42  help='Set experiment number')
43 parser.add_argument('--runNo', default=3360, type=int, help='Set run number')
44 parser.add_argument(
45  '--setNo',
46  default=0,
47  type=int,
48  help='setnumber for bg simulation')
49 parser.add_argument(
50  '--bg',
51  default='/group/belle2/BGFile/OfficialBKG/15thCampaign/phase2',
52  type=str,
53  help='Path to mixer sets')
54 parser.add_argument(
55  '--scaleFactor',
56  default=1.0,
57  type=float,
58  help='Scale factor for mixer')
59 args = parser.parse_args()
60 
61 bg = glob.glob(args.bg + '/set' + str(args.setNo) + '/*.root')
62 
63 
64 b2.reset_database()
65 b2.use_central_database(args.tag)
66 
67 main = b2.create_path()
68 main.add_module(
69  "EventInfoSetter", expList=[
70  args.expNo], runList=[
71  args.runNo], evtNumList=[1000])
72 main.add_module("Gearbox", fileName='geometry/Beast2_phase2.xml')
73 main.add_module("Geometry", useDB=False)
74 bkgmixer = b2.register_module('BeamBkgMixer')
75 bkgmixer.param('backgroundFiles', bg)
76 bkgmixer.param('overallScaleFactor', args.scaleFactor)
77 main.add_module(bkgmixer)
78 output = main.add_module('RootOutput')
79 output.param(
80  'outputFileName',
81  f'beam.{args.expNo:0>4}.{args.runNo:0>5}.HLT2.f{args.setNo:0>5}.root')
82 output.param('branchNames', ['PXDSimHits', 'EventMetaData'])
83 main.add_module("Progress")
84 
85 b2.process(main)
86 print(b2.statistics)