Belle II Software development
analysisScript.py
1#!/usr/bin/env python3
2
3
10
11# This is the main file for the analysis script
12
13import os
14import sys
15from tools import getBelleUrl_data, getBelleUrl_mc
16import basf2 as b2
17from modularAnalysis import variablesToNtuple
18from modularAnalysis import fillParticleList
19
20from b2biiConversion import convertBelleMdstToBelleIIMdst
21
22
23# ------- Arguments sorting
24
25mc_or_data = sys.argv[1].lower()
26isMC = {"mc": True, "data": False}.get(mc_or_data, None)
27if isMC is None:
28 sys.exit('First parameter must be "mc" or "data" to indicate whether we run on MC or real data')
29
30if isMC:
31 if len(sys.argv) != 9:
32 sys.exit('Must provide all 8 parameters !')
33 expNo = sys.argv[2]
34 eventType = sys.argv[3]
35 dataType = sys.argv[4]
36 belleLevel = sys.argv[5]
37 minRunNo = sys.argv[6]
38 maxRunNo = sys.argv[7]
39 streamNo = sys.argv[8]
40else:
41 if len(sys.argv) != 8:
42 sys.exit('Must provide all 7 parameters !')
43 expNo = sys.argv[2]
44 skimType = sys.argv[3]
45 dataType = sys.argv[4]
46 belleLevel = sys.argv[5]
47 minRunNo = sys.argv[6]
48 maxRunNo = sys.argv[7]
49
50
51# ------- B2BII
52
53os.environ['PGUSER'] = 'g0db'
54os.environ['USE_GRAND_REPROCESS_DATA'] = '1'
55
56if isMC:
57 url = getBelleUrl_mc(expNo, minRunNo, maxRunNo,
58 eventType, dataType, belleLevel, streamNo)
59else:
60 url = getBelleUrl_data(expNo, minRunNo, maxRunNo,
61 skimType, dataType, belleLevel)
62
63mypath = b2.create_path()
64convertBelleMdstToBelleIIMdst(url, applySkim=True, path=mypath)
65
66
67# ------- Output file
68
69outDir = './analysisOutput'
70
71filenameEnd = '_'.join(sys.argv[2:]) + '.root'
72
73outputFileName = outDir + '/output_' + filenameEnd
74
75# ------- Rest of analysis script goes here...
76
77# this sample code is taken from b2bii/examples
78
79fillParticleList('pi+:all', '', path=mypath)
80
81kinematic_variables = ['px', 'py', 'pz', 'E']
82
84 'pi+:all', kinematic_variables, filename=outputFileName, path=mypath)
85
86# progress
87progress = b2.register_module('Progress')
88mypath.add_module(progress)
89
90b2.process(mypath)
91
92# Print call statistics
93print(b2.statistics)