Belle II Software development
B2A105-SimulateAndReconstruct-withBeamBkg.py
1#!/usr/bin/env python3
2
3
10
11
29
30import basf2 as b2
31from modularAnalysis import inputMdst
32from simulation import add_simulation
33from reconstruction import add_reconstruction
34from mdst import add_mdst_output
35import glob
36import os
37
38# create a path
39my_path = b2.create_path()
40
41# load input ROOT file
42inputMdst(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
46if '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://xwiki.desy.de/xwiki/rest/p/90869 to find them')
51# get list of files and check the list length
52bg = glob.glob(os.environ['BELLE2_BACKGROUND_DIR'] + '/*.root')
53if len(bg) == 0:
54 b2.B2FATAL('No files found in ', os.environ['BELLE2_BACKGROUND_DIR'])
55
56# simulation
57add_simulation(path=my_path, bkgfiles=bg)
58
59# reconstruction
60add_reconstruction(path=my_path)
61
62# dump in MDST format
63add_mdst_output(path=my_path,
64 mc=True,
65 filename='B2A101-Y4SEventGeneration-gsim-BKGx1.root')
66
67# Show progress of processing
68my_path.add_module('ProgressBar')
69
70# Process the events
71b2.process(my_path)
72
73# print out the summary
74print(b2.statistics)