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