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