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