Belle II Software development
truth_charged.py
1#!/usr/bin/env python3
2
3
10
11
14import basf2
15import sys
16import statistics
17from modularAnalysis import inputMdst, fillParticleList, matchMCTruth, variablesToNtuple
18from variables import variables
19
20charged_path = basf2.Path()
21
22variables.addAlias('kBinaryID', 'pidPairProbabilityExpert(321,211,ALL)')
23variables.addAlias('eBinaryID', 'pidPairProbabilityExpert(11,211,ALL)')
24variables.addAlias('muBinaryID', 'pidPairProbabilityExpert(13,211,ALL)')
25variables.addAlias('pBinaryID', 'pidPairProbabilityExpert(2212,211,ALL)')
26
27if len(sys.argv) not in [2, 3]:
28 sys.exit('Must provide an input file and (optionally) an output file')
29
30inFile = sys.argv[1]
31if len(sys.argv) == 3:
32 outFile = sys.argv[2]
33else:
34 outFile = './truth_charged.root'
35
36inputMdst(inFile, path=charged_path)
37
38# --------------------------------------------------
39# Create and fill final state ParticleLists
40# --------------------------------------------------
41trackQuality = 'thetaInCDCAcceptance and nCDCHits > 20'
42ipCut = 'd0 < 0.5 and abs(z0) < 2'
43mcCharged = '(abs(mcPDG)==11 or abs(mcPDG)==13 or abs(mcPDG)==211 or abs(mcPDG)==321 or abs(mcPDG)==2212)'
44goodTrack = trackQuality + ' and ' + ipCut
45
46fillParticleList('pi+:any', goodTrack, path=charged_path)
47matchMCTruth('pi+:any', path=charged_path)
48
49fillParticleList('K+:any', goodTrack, path=charged_path)
50matchMCTruth('K+:any', path=charged_path)
51
52fillParticleList('e+:any', goodTrack, path=charged_path)
53matchMCTruth('e+:any', path=charged_path)
54
55fillParticleList('mu+:any', goodTrack, path=charged_path)
56matchMCTruth('mu+:any', path=charged_path)
57
58fillParticleList('p+:any', goodTrack, path=charged_path)
59matchMCTruth('p+:any', path=charged_path)
60
61# --------------------------------------------------
62# write out useful information to a ROOT file
63# --------------------------------------------------
64ntupleOfInterest = ['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
73variablesToNtuple('pi+:any', ntupleOfInterest, 'pion', outFile, path=charged_path)
74variablesToNtuple('K+:any', ntupleOfInterest, 'kaon', outFile, path=charged_path)
75variablesToNtuple('e+:any', ntupleOfInterest, 'electron', outFile, path=charged_path)
76variablesToNtuple('mu+:any', ntupleOfInterest, 'muon', outFile, path=charged_path)
77variablesToNtuple('p+:any', ntupleOfInterest, 'proton', outFile, path=charged_path)
78
79# --------------------------------------------------
80# Process the events and print call statistics
81# --------------------------------------------------
82basf2.process(charged_path)
83print(statistics)