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