Belle II Software  release-05-01-25
reconstruct_Dstar.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 """
5 Simple example script to reconstruct Dstart for the purpose of ARICH PID performance studies
6 Usage : basf2 reconstruct_Dstar.py exp start_run end_run
7 set up to use D* skim from proc9 (adjust line 42 to change input!
8 """
9 
10 import os
11 import sys
12 import basf2 as b2
13 import modularAnalysis as ma
14 import variables.collections as vc
15 import variables.utils as vu
16 import stdCharged as stdc
17 from stdV0s import stdKshorts
18 from stdPi0s import stdPi0s
19 import vertex as vtx
20 
21 # create path
22 my_path = b2.create_path()
23 
24 # load input ROOT file
25 
26 argvs = sys.argv
27 exp = argvs[1].zfill(4)
28 start_run = argvs[2]
29 end_run = argvs[3]
30 
31 # Set the global log level
32 # set_log_level(LogLevel.INFO)
33 
34 b2.use_central_database('data_reprocessing_proc9')
35 
36 main_path = b2.create_path()
37 
38 inputFilename = []
39 
40 for i in range(int(start_run), int(end_run) + 1):
41  ru = str(i)
42  fname = '/group/belle2/dataprod/Data/release-03-02-02/DB00000654/proc9/e' + exp + '/4S/r' + \
43  ru.zfill(5) + '/offskim/offskim_dstar/cdst/sub00/cdst.physics.' + exp + '.' + ru.zfill(5) + '.HLT0.offskim_dstar.root'
44  if os.path.exists(fname):
45  inputFilename.append(fname)
46  print(fname)
47 
48 input_module = b2.register_module('RootInput')
49 input_module.param('inputFileNames', inputFilename)
50 # in case you want to reprocess arich data uncomment the line below
51 # input_module.param('excludeBranchNames', ['ARICHTracks','ARICHLikelihoods','ARICHTracksToExtHits','TracksToARICHLikelihoods'])
52 my_path.add_module(input_module)
53 
54 # uncomment the lines below to re-run arich reconstruction
55 # arichHits = b2.register_module('ARICHFillHits')
56 # arichHits.param('MagFieldCorrection',1)
57 # my_path.add_module(arichHits)
58 
59 # reconstruction from ARICHHits
60 # arichRecon = b2.register_module('ARICHReconstructor')
61 # store cherenkov angle information
62 # arichRecon.param('storePhotons', 1)
63 # my_path.add_module(arichRecon)
64 
65 
66 # use standard final state particle lists
67 # creates "pi+:all" ParticleList (and c.c.)
68 stdc.stdPi(listtype='all', path=my_path)
69 stdc.stdK(listtype='all', path=my_path)
70 
71 # reconstruct D0 -> K- pi+ decay
72 # keep only candidates with 1.8 < M(Kpi) < 1.9 GeV
73 ma.reconstructDecay(decayString='D0:kpi -> K-:all pi+:all', cut='1.8 < M < 1.9', path=my_path)
74 
75 # vertex fitting for D0
76 # vtx.vertexRave('D0:kpi', 0.0, path=my_path)
77 
78 # reconstruct D*+ -> D0 pi+ decay
79 # keep only candidates with Q = M(D0pi) - M(D0) - M(pi) < 20 MeV
80 ma.reconstructDecay(decayString='D*+ -> D0:kpi pi+:all', cut='0.0 < Q < 0.2', path=my_path)
81 
82 # vertex fitting for D*
83 # vtx.vertexRave('D*+:my', 0.0, path=my_path)
84 
85 pidVars = [
86  'd0',
87  'z0',
88  'cosTheta',
89  'nCDCHits',
90  'pidPairProbabilityExpert(321, 211, ARICH)',
91  'pidDeltaLogLikelihoodValueExpert(211,321,ARICH)',
92  'pidProbabilityExpert(211, ARICH)',
93  'pidProbabilityExpert(321, ARICH)']
94 
95 # Select variables that we want to store to ntuple
96 dstar_vars = vc.inv_mass + vc.mc_truth + vc.kinematics
97 
98 fs_hadron_vars = vu.create_aliases_for_selected(
99  list_of_variables=vc.pid + vc.track + vc.mc_truth + vc.kinematics + pidVars,
100  decay_string='D*+ -> [D0 -> ^K- ^pi+] ^pi+')
101 
102 d0_vars = vu.create_aliases_for_selected(
103  list_of_variables=vc.inv_mass + vc.mc_truth,
104  decay_string='D*+ -> ^D0 pi+',
105  prefix='D0')
106 
107 # Saving variables to ntuple
108 output_file = 'Dstar2D0Pi-PID_exp' + exp + '_r' + start_run + '-' + end_run + '.root'
109 ma.variablesToNtuple('D*+', dstar_vars + d0_vars + fs_hadron_vars,
110  filename=output_file, treename='dsttree', path=my_path)
111 
112 
113 progress = b2.register_module('Progress')
114 my_path.add_module(progress)
115 
116 b2.process(my_path)
variables.utils
Definition: utils.py:1
variables.collections
Definition: collections.py:1