Belle II Software  release-06-00-14
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 # usage: basf2 cdst_recDstar.py -i <cdst_file.root> [-- (see argument parser)]
17 # ---------------------------------------------------------------------------------------
18 
19 import basf2
20 import modularAnalysis as ma
21 from variables import variables
22 from vertex import raveFit
23 from ROOT import gSystem
24 import argparse
25 
26 # Argument parser
27 ap = argparse.ArgumentParser()
28 ap.add_argument("--mc", help="Input file is MC", action='store_true', default=False)
29 ap.add_argument("--vfit", help="Do vertex fit", action='store_true', default=False)
30 ap.add_argument("--tag", help="Global tag (data only)", default="data_reprocessing_proc7")
31 ap.add_argument("--out", help="Output file", default="Dstar.root")
32 args = ap.parse_args()
33 
34 MC = args.mc
35 VFit = args.vfit
36 
37 if not MC:
38  basf2.use_central_database(args.tag, basf2.LogLevel.WARNING)
39 
40 # Load top library
41 gSystem.Load('libtop.so')
42 
43 # Create path
44 main = basf2.create_path()
45 
46 # Just a dummy input file, use basf2 -i option
47 ma.inputMdstList('default', 'Input.root', path=main)
48 
49 # Particle lists
50 ma.fillParticleList('K-:all', '-2.0 < d0 < 2.0 and -4.0 < z0 < 4.0', path=main)
51 ma.fillParticleList('pi+:all', '-2.0 < d0 < 2.0 and -4.0 < z0 < 4.0', path=main)
52 
53 # Reconstruct D0 -> K- pi+ decay
54 ma.reconstructDecay('D0:kpi -> K-:all pi+:all', '1.8 < M < 1.95', path=main)
55 if VFit:
56  raveFit('D0:kpi', 0.001, fit_type='vertex', decay_string='', constraint='', daughtersUpdate=True, path=main)
57 
58 # Reconstruct D*+ -> D0 pi+ decay
59 ma.reconstructDecay('D*+ -> D0:kpi pi+:all', '0.0 < Q < 0.020', path=main)
60 if VFit:
61  raveFit('D*+', 0.001, '', 'rave', 'vertex', 'ipprofile', True, path=main)
62 
63 # MC matching
64 if MC:
65  ma.matchMCTruth('D*+', path=main)
66 
67 # Output ntuple (extend the list if you need more)
68 variables.addAlias('isBunch', 'isTopRecBunchReconstructed')
69 variables.addAlias('bunchOffset', 'topRecBunchCurrentOffset')
70 variables.addAlias('M_D0', 'daughter(0, M)')
71 variables.addAlias('p_cms', 'useCMSFrame(p)')
72 
73 variables.addAlias('p_K', 'daughter(0, daughter(0, p))')
74 variables.addAlias('flag_K', 'daughter(0, daughter(0, topFlag))')
75 variables.addAlias('kaonLL_K', 'daughter(0, daughter(0, topKaonLogL))')
76 variables.addAlias('pionLL_K', 'daughter(0, daughter(0, topPionLogL))')
77 variables.addAlias('slotID_K', 'daughter(0, daughter(0, topSlotID))')
78 
79 variables.addAlias('p_pi', 'daughter(0, daughter(1, p))')
80 variables.addAlias('flag_pi', 'daughter(0, daughter(1, topFlag))')
81 variables.addAlias('kaonLL_pi', 'daughter(0, daughter(1, topKaonLogL))')
82 variables.addAlias('pionLL_pi', 'daughter(0, daughter(1, topPionLogL))')
83 variables.addAlias('slotID_pi', 'daughter(0, daughter(1, topSlotID))')
84 
85 varlist = ['M_D0', 'Q', 'dQ', 'p_cms', 'isBunch', 'bunchOffset', 'p_K', 'p_pi',
86  'kaonLL_K', 'pionLL_K', 'flag_K', 'slotID_K',
87  'kaonLL_pi', 'pionLL_pi', 'flag_pi', 'slotID_pi']
88 
89 ma.variablesToNtuple('D*+', varlist, 'dstar', args.out, path=main)
90 
91 # Process events
92 basf2.process(main)
93 
94 # Print statistics
95 print(basf2.statistics)