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