Belle II Software  release-08-01-10
cdstAnalysis.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # -------------------------------------------------------------------------
13 # Example of using top variables on real data (cdst files required)
14 # See topVariables.py on how to use top variables on MC
15 #
16 # To print available top variables: basf2 top/examples/printTOPVariables.py
17 # -------------------------------------------------------------------------
18 
19 from basf2 import conditions, create_path, process, statistics
20 from reconstruction import prepare_user_cdst_analysis
21 import modularAnalysis as ma
22 from variables import variables
23 
24 # global tags
25 # ******************************************************************************************************************
26 # note: The patching global tags and their order are bucket number and basf2 version dependent.
27 # Given below is what is needed for cdst files of bucket 16 calibration and January-2023 development version.
28 # ******************************************************************************************************************
29 conditions.override_globaltags()
30 conditions.append_globaltag('patch_main_release-07_noTOP')
31 conditions.append_globaltag('data_reprocessing_proc13') # experiments 7 - 18
32 # conditions.append_globaltag('data_reprocessing_prompt') # experiments 20 - 26
33 conditions.append_globaltag('online')
34 
35 # create path
36 main = create_path()
37 
38 # read events from a cdst file: use -i option to pass the name of the file
39 # files of bucket 16 can be found on KEKCC in /gpfs/group/belle2/dataprod/Data/PromptReco/bucket16_calib/
40 main.add_module('RootInput')
41 
42 # run unpackers and post-tracking reconstruction
43 prepare_user_cdst_analysis(main)
44 
45 # make a particle list of pions from all charged tracks
46 ma.fillParticleList(decayString='pi+:all', cut='', path=main)
47 
48 # make aliases of some expert variables
49 variables.addAlias('topTOF_kaon', 'topTOFExpert(321)')
50 
51 # define a list of variables to be written to ntuple
52 var_list = ['p',
53  'theta',
54  'phi',
55  'charge',
56  'PDG',
57  'topSlotID',
58  'topLocalX',
59  'topLocalY',
60  'topLocalZ',
61  'topLocalPhi',
62  'topLocalTheta',
63  'topTOF',
64  'topTOF_kaon',
65  'extrapTrackToTOPimpactZ',
66  'extrapTrackToTOPimpactTheta',
67  'extrapTrackToTOPimpactPhi',
68  'topDigitCount',
69  'topDigitCountSignal',
70  'topDigitCountBkg',
71  'topDigitCountRaw',
72  'topLogLFlag',
73  'topLogLPhotonCount',
74  'topLogLExpectedPhotonCount',
75  'topLogLEstimatedBkgCount',
76  'topLogLElectron',
77  'topLogLMuon',
78  'topLogLPion',
79  'topLogLKaon',
80  'topLogLProton',
81  'topLogLDeuteron',
82  'topBunchIsReconstructed',
83  'topBunchNumber',
84  'topBunchOffset',
85  'topBunchTrackCount',
86  'topBunchUsedTrackCount',
87  'topTracksInSlot']
88 
89 # write variables to ntuple
90 ma.variablesToNtuple(decayString='pi+:all', variables=var_list, treename='tree', filename='topVars_data.root', path=main)
91 
92 # print progress
93 main.add_module('Progress')
94 
95 # process events
96 process(main)
97 
98 # Print statistics
99 print(statistics)