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