Belle II Software  release-08-01-10
cdst_recDstar.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ------------------------------------------------------------------------------------------
13 # Example of Dstar reconstruction where output ntuple includes some additional variables
14 # from group "TOP Calibration". Input must be a cdst file.
15 #
16 # One can print the "TOP Calibration" variables with basf2 top/examples/printTOPVariables.py
17 #
18 # usage: basf2 cdst_recDstar.py -i <cdst_file.root> [-- (see argument parser)]
19 # ------------------------------------------------------------------------------------------
20 
21 import basf2
22 from reconstruction import prepare_user_cdst_analysis
23 import modularAnalysis as ma
24 from variables import variables
25 from vertex import treeFit
26 from ROOT import gSystem
27 import argparse
28 import sys
29 
30 # Argument parser
31 ap = argparse.ArgumentParser()
32 ap.add_argument("--mc", help="Input file is MC", action='store_true', default=False)
33 ap.add_argument("--exp", help="Experiment number, if input file is real data", default=0)
34 ap.add_argument("--vfit", help="Do vertex fit", action='store_true', default=False)
35 ap.add_argument("--out", help="Output file", default="Dstar.root")
36 args = ap.parse_args()
37 
38 MC = args.mc
39 VFit = args.vfit
40 
41 # Global tags if running on real data
42 # *****************************************************************************************************
43 # note: The patching global tags and their order can be bucket number and basf2 version dependent.
44 # Given below is what's been tested to work with cdst files of bucket 16 calibration on release-7
45 # *****************************************************************************************************
46 if not MC:
47  if args.exp == 0:
48  basf2.B2ERROR("Experiment number is not given. Please, provide it with --exp")
49  sys.exit()
50  basf2.conditions.override_globaltags()
51  basf2.conditions.append_globaltag('patch_main_release-07_noTOP')
52  if int(args.exp) < 20:
53  basf2.conditions.append_globaltag('data_reprocessing_proc13') # experiments 7 - 18
54  else:
55  basf2.conditions.append_globaltag('data_reprocessing_prompt') # experiments 20 - 26
56  basf2.conditions.append_globaltag('online')
57 
58 # Load top library
59 gSystem.Load('libtop.so')
60 
61 # Create path
62 main = basf2.create_path()
63 
64 # Just a dummy input file, use basf2 -i option
65 ma.inputMdstList('Input.root', path=main)
66 
67 # Run unpackers and post-tracking reconstruction
68 prepare_user_cdst_analysis(main)
69 
70 # Particle lists
71 ma.fillParticleList('K-:All', '-2.0 < d0 < 2.0 and -4.0 < z0 < 4.0', path=main)
72 ma.fillParticleList('pi+:All', '-2.0 < d0 < 2.0 and -4.0 < z0 < 4.0', path=main)
73 
74 # Reconstruct D0 -> K- pi+ decay
75 ma.reconstructDecay('D0:kpi -> K-:All pi+:All', '1.8 < M < 1.95', path=main)
76 
77 # Reconstruct D*+ -> D0 pi+ decay
78 ma.reconstructDecay('D*+ -> D0:kpi pi+:All', '0.0 < Q < 0.020', path=main)
79 
80 # Vertex fit
81 if VFit:
82  treeFit('D*+', ipConstraint=True, path=main)
83 
84 # MC matching
85 if MC:
86  ma.matchMCTruth('D*+', path=main)
87 
88 # Output ntuple (extend the list if you need more)
89 variables.addAlias('isBunch', 'topBunchIsReconstructed')
90 variables.addAlias('bunchOffset', 'topBunchOffset')
91 variables.addAlias('M_D0', 'daughter(0, M)')
92 variables.addAlias('p_cms', 'useCMSFrame(p)')
93 
94 variables.addAlias('p_K', 'daughter(0, daughter(0, p))')
95 variables.addAlias('flag_K', 'daughter(0, daughter(0, topLogLFlag))')
96 variables.addAlias('kaonLL_K', 'daughter(0, daughter(0, topLogLKaon))')
97 variables.addAlias('pionLL_K', 'daughter(0, daughter(0, topLogLPion))')
98 variables.addAlias('slotID_K', 'daughter(0, daughter(0, topSlotID))')
99 
100 variables.addAlias('p_pi', 'daughter(0, daughter(1, p))')
101 variables.addAlias('flag_pi', 'daughter(0, daughter(1, topLogLFlag))')
102 variables.addAlias('kaonLL_pi', 'daughter(0, daughter(1, topLogLKaon))')
103 variables.addAlias('pionLL_pi', 'daughter(0, daughter(1, topLogLPion))')
104 variables.addAlias('slotID_pi', 'daughter(0, daughter(1, topSlotID))')
105 
106 varlist = ['M_D0', 'Q', 'dQ', 'p_cms', 'isBunch', 'bunchOffset', 'p_K', 'p_pi',
107  'kaonLL_K', 'pionLL_K', 'flag_K', 'slotID_K',
108  'kaonLL_pi', 'pionLL_pi', 'flag_pi', 'slotID_pi']
109 
110 ma.variablesToNtuple('D*+', varlist, 'dstar', args.out, path=main)
111 
112 # Process events
113 basf2.process(main)
114 
115 # Print statistics
116 print(basf2.statistics)