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