Belle II Software  release-08-01-10
B2A105-SimulateAndReconstruct-withBeamBkg.py
1 #!/usr/bin/env python3
2 
3 
10 
11 
29 
30 import basf2 as b2
31 from modularAnalysis import inputMdst
32 from simulation import add_simulation
33 from reconstruction import add_reconstruction
34 from mdst import add_mdst_output
35 import glob
36 import os
37 
38 # create a path
39 my_path = b2.create_path()
40 
41 # load input ROOT file
42 inputMdst(filename=b2.find_file('B2A101-Y4SEventGeneration-evtgen.root'), path=my_path)
43 
44 # background files
45 # location of the files is obtained from a shell variable - check first if it is set
46 if 'BELLE2_BACKGROUND_DIR' not in os.environ:
47  b2.B2FATAL(
48  'BELLE2_BACKGROUND_DIR variable is not set. \n'
49  'Please export (setenv) the variable to the location of BG overlay sample. \n'
50  'Check https://confluence.desy.de/display/BI/Beam+background+samples to find them')
51 # get list of files and check the list length
52 bg = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '/*.root')
53 if len(bg) == 0:
54  b2.B2FATAL('No files found in ', os.environ['BELLE2_BACKGROUND_DIR'])
55 
56 # simulation
57 add_simulation(path=my_path, bkgfiles=bg)
58 
59 # reconstruction
60 add_reconstruction(path=my_path)
61 
62 # dump in MDST format
63 add_mdst_output(path=my_path,
64  mc=True,
65  filename='B2A101-Y4SEventGeneration-gsim-BKGx1.root')
66 
67 # Show progress of processing
68 my_path.add_module('ProgressBar')
69 
70 # Process the events
71 b2.process(my_path)
72 
73 # print out the summary
74 print(b2.statistics)