Belle II Software  release-05-01-25
cdst_recDstar.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 # ---------------------------------------------------------------------------------------
5 # Example of Dstar reconstruction where output ntuple includes some additional variables
6 # from group "TOP Calibration". Input must be a cdst file.
7 #
8 # usage: basf2 cdst_recDstar.py -i <cdst_file.root> [-- (see argument parser)]
9 # ---------------------------------------------------------------------------------------
10 
11 import basf2
12 from modularAnalysis import *
13 from variables import variables
14 from ROOT import gSystem
15 import argparse
16 
17 # Argument parser
18 ap = argparse.ArgumentParser()
19 ap.add_argument("--mc", help="Input file is MC", action='store_true', default=False)
20 ap.add_argument("--vfit", help="Do vertex fit", action='store_true', default=False)
21 ap.add_argument("--tag", help="Global tag (data only)", default="data_reprocessing_proc7")
22 ap.add_argument("--out", help="Output file", default="Dstar.root")
23 args = ap.parse_args()
24 
25 MC = args.mc
26 VFit = args.vfit
27 
28 if not MC:
29  use_central_database(args.tag, LogLevel.WARNING)
30 
31 # Load top library
32 gSystem.Load('libtop.so')
33 
34 # Create path
35 main = basf2.create_path()
36 
37 # Just a dummy input file, use basf2 -i option
38 inputMdstList('default', 'Input.root', path=main)
39 
40 # Particle lists
41 fillParticleList('K-:all', '-2.0 < d0 < 2.0 and -4.0 < z0 < 4.0', path=main)
42 fillParticleList('pi+:all', '-2.0 < d0 < 2.0 and -4.0 < z0 < 4.0', path=main)
43 
44 # Reconstruct D0 -> K- pi+ decay
45 reconstructDecay('D0:kpi -> K-:all pi+:all', '1.8 < M < 1.95', path=main)
46 if VFit:
47  fitVertex('D0:kpi', 0.001, '', 'rave', 'vertex', '', True, path=main)
48 
49 # Reconstruct D*+ -> D0 pi+ decay
50 reconstructDecay('D*+ -> D0:kpi pi+:all', '0.0 < Q < 0.020', path=main)
51 if VFit:
52  fitVertex('D*+', 0.001, '', 'rave', 'vertex', 'ipprofile', True, path=main)
53 
54 # MC matching
55 if MC:
56  matchMCTruth('D*+', path=main)
57 
58 # Output ntuple (extend the list if you need more)
59 variables.addAlias('isBunch', 'isTopRecBunchReconstructed')
60 variables.addAlias('bunchOffset', 'topRecBunchCurrentOffset')
61 variables.addAlias('M_D0', 'daughter(0, M)')
62 variables.addAlias('p_cms', 'useCMSFrame(p)')
63 
64 variables.addAlias('p_K', 'daughter(0, daughter(0, p))')
65 variables.addAlias('flag_K', 'daughter(0, daughter(0, topFlag))')
66 variables.addAlias('kaonLL_K', 'daughter(0, daughter(0, topKaonLogL))')
67 variables.addAlias('pionLL_K', 'daughter(0, daughter(0, topPionLogL))')
68 variables.addAlias('slotID_K', 'daughter(0, daughter(0, topSlotID))')
69 
70 variables.addAlias('p_pi', 'daughter(0, daughter(1, p))')
71 variables.addAlias('flag_pi', 'daughter(0, daughter(1, topFlag))')
72 variables.addAlias('kaonLL_pi', 'daughter(0, daughter(1, topKaonLogL))')
73 variables.addAlias('pionLL_pi', 'daughter(0, daughter(1, topPionLogL))')
74 variables.addAlias('slotID_pi', 'daughter(0, daughter(1, topSlotID))')
75 
76 varlist = ['M_D0', 'Q', 'dQ', 'p_cms', 'isBunch', 'bunchOffset', 'p_K', 'p_pi',
77  'kaonLL_K', 'pionLL_K', 'flag_K', 'slotID_K',
78  'kaonLL_pi', 'pionLL_pi', 'flag_pi', 'slotID_pi']
79 
80 variablesToNtuple('D*+', varlist, 'dstar', args.out, path=main)
81 
82 # Process events
83 basf2.process(main)
84 
85 # Print statistics
86 print(basf2.statistics)
variablesToNtuple
Definition: variablesToNtuple.py:1
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25