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