Belle II Software  release-08-01-10
b2bii_example.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import os
12 
13 import basf2 as b2
14 import modularAnalysis as ma
15 import variables as va
16 import variables.collections as vc
17 import variables.utils as vu
18 from b2biiConversion import convertBelleMdstToBelleIIMdst
19 
20 os.environ["USE_GRAND_REPROCESS_DATA"] = "1"
21 os.environ["PGUSER"] = "g0db"
22 
23 # Convert
24 main = b2.create_path()
25 inputfile = b2.find_file(
26  "b2bii_input_evtgen_exp_07_BptoD0pip-D0toKpipi0-0.mdst", "examples", False
27 )
28 convertBelleMdstToBelleIIMdst(inputfile, path=main)
29 
30 # Only charged final state particles need to be loaded. The neutral particles
31 # gamma, pi0, K_S0, K_L0, and Lambda0 are already loaded to the 'gamma:mdst',
32 # 'pi0:mdst', 'K_S0:mdst', 'K_L0:mdst', and 'Lambda0:mdst' particle lists,
33 # respectively.
34 ma.fillParticleList("pi+:sig", "atcPIDBelle(3,2)<0.4", path=main)
35 ma.fillParticleList("K+:sig", "atcPIDBelle(3,2)>0.6", path=main)
36 
37 # The Belle PID variables are: atcPIDBelle(sigHyp, bkgHyp), muIDBelle, and eIDBelle
38 va.variables.addAlias("Lkpi", "atcPIDBelle(3,2)")
39 
40 # Now, let's really reconstruct a B decay with an intermediate D meson:
41 ma.reconstructDecay(
42  "D0:Kpipi0 -> K-:sig pi+:sig pi0:mdst", cut="1.7 < M < 2.0", path=main
43 )
44 ma.reconstructDecay(
45  "B+:D0pi -> anti-D0:Kpipi0 pi+:sig",
46  cut="4.8 < Mbc >5.2 and abs(deltaE) < 0.15",
47  path=main,
48 )
49 
50 ma.matchMCTruth("B+:D0pi", path=main)
51 
52 # create and fill flat Ntuple with MCTruth and kinematic information
53 # Create list of variables to save into the output file
54 b_vars = []
55 
56 standard_vars = vc.kinematics + vc.mc_kinematics + vc.mc_truth + vc.inv_mass
57 b_vars += vc.deltae_mbc
58 b_vars += standard_vars
59 
60 # Variables for D0 and all final state particles (kaons, pions, neutral pions)
61 b_vars += vu.create_aliases_for_selected(
62  standard_vars,
63  "B+ -> [ ^D0 -> ^K- ^pi+ ^pi0] ^pi+",
64  prefix=["D0", "K", "pip1", "pi0", "pip2"],
65 )
66 
67 # Variables for charged final states (kaons, pions)
68 belle1pid = (
69  ["eIDBelle", "muIDBelleQuality", "muIDBelle", "Lkpi"]
70  + vc.track
71  + vc.track_hits
72 )
73 
74 b_vars += vu.create_aliases_for_selected(
75  belle1pid, "B+ -> [ D0 -> ^K- ^pi+ pi0] ^pi+", prefix=["K", "pip1", "pip2"]
76 )
77 
78 ma.variablesToNtuple(
79  "B+:D0pi", b_vars, filename="B2BII_B2D0pi_D2Kpipi0.root", path=main
80 )
81 
82 # progress
83 main.add_module("Progress")
84 
85 b2.process(main)
86 
87 # Print call statistics
88 print(b2.statistics)