Belle II Software  release-08-01-10
truth_charged.py
1 #!/usr/bin/env python3
2 
3 
10 
11 
14 import basf2
15 import sys
16 import statistics
17 from modularAnalysis import inputMdst, fillParticleList, matchMCTruth, variablesToNtuple
18 from variables import variables
19 
20 charged_path = basf2.Path()
21 
22 variables.addAlias('kBinaryID', 'pidPairProbabilityExpert(321,211,ALL)')
23 variables.addAlias('eBinaryID', 'pidPairProbabilityExpert(11,211,ALL)')
24 variables.addAlias('muBinaryID', 'pidPairProbabilityExpert(13,211,ALL)')
25 variables.addAlias('pBinaryID', 'pidPairProbabilityExpert(2212,211,ALL)')
26 
27 if len(sys.argv) not in [2, 3]:
28  sys.exit('Must provide an input file and (optionally) an output file')
29 
30 inFile = sys.argv[1]
31 if len(sys.argv) == 3:
32  outFile = sys.argv[2]
33 else:
34  outFile = './truth_charged.root'
35 
36 inputMdst(inFile, path=charged_path)
37 
38 # --------------------------------------------------
39 # Create and fill final state ParticleLists
40 # --------------------------------------------------
41 trackQuality = 'thetaInCDCAcceptance and nCDCHits > 20'
42 ipCut = 'd0 < 0.5 and abs(z0) < 2'
43 mcCharged = '(abs(mcPDG)==11 or abs(mcPDG)==13 or abs(mcPDG)==211 or abs(mcPDG)==321 or abs(mcPDG)==2212)'
44 goodTrack = trackQuality + ' and ' + ipCut
45 
46 fillParticleList('pi+:any', goodTrack, path=charged_path)
47 matchMCTruth('pi+:any', path=charged_path)
48 
49 fillParticleList('K+:any', goodTrack, path=charged_path)
50 matchMCTruth('K+:any', path=charged_path)
51 
52 fillParticleList('e+:any', goodTrack, path=charged_path)
53 matchMCTruth('e+:any', path=charged_path)
54 
55 fillParticleList('mu+:any', goodTrack, path=charged_path)
56 matchMCTruth('mu+:any', path=charged_path)
57 
58 fillParticleList('p+:any', goodTrack, path=charged_path)
59 matchMCTruth('p+:any', path=charged_path)
60 
61 # --------------------------------------------------
62 # write out useful information to a ROOT file
63 # --------------------------------------------------
64 ntupleOfInterest = ['px', 'py', 'pz', 'E', 'p', 'pt', 'theta', 'phi', # event kinematics
65  'mcPX', 'mcPY', 'mcPZ', 'mcE', 'mcP', 'mcPT', 'mcTheta', 'mcPhi', # mc kinematics
66  'pionID', 'kaonID', 'electronID', 'muonID', 'protonID', # global PID
67  'kBinaryID', 'eBinaryID', 'muBinaryID', 'pBinaryID', # binary PID
68  'thetaInTOPAcceptance', 'thetaInECLAcceptance', 'thetaInKLMAcceptance', # angular acceptance
69  'ptInTOPAcceptance', 'ptInBECLAcceptance', 'ptInBKLMAcceptance', # momentum acceptance
70  'mcPDG', # true PDG number
71  ]
72 
73 variablesToNtuple('pi+:any', ntupleOfInterest, 'pion', outFile, path=charged_path)
74 variablesToNtuple('K+:any', ntupleOfInterest, 'kaon', outFile, path=charged_path)
75 variablesToNtuple('e+:any', ntupleOfInterest, 'electron', outFile, path=charged_path)
76 variablesToNtuple('mu+:any', ntupleOfInterest, 'muon', outFile, path=charged_path)
77 variablesToNtuple('p+:any', ntupleOfInterest, 'proton', outFile, path=charged_path)
78 
79 # --------------------------------------------------
80 # Process the events and print call statistics
81 # --------------------------------------------------
82 basf2.process(charged_path)
83 print(statistics)