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