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