Belle II Software  release-08-01-10
arich_process_raw.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # Example script for processing of raw data
12 # It converts arich raw data to arichDigits and arichHits
13 # Using "-t 1" option the cdc tracks are also reconstructed and stored into
14 # the output root file (along with the arichHits).
15 # Using option "-a 1" only the data from events that contain reconstructed track hit
16 # in the is included into the output file.
17 # ARICHDQM module is also included, it produces "DQMhistograms.root" with some basic
18 # dqm histograms (using all events). You can conveniently display some of them using
19 # "root -l histograms.root arich/utility/scripts/plotDQM.C"
20 #
21 # NOTE: by default there is no output file made, only file with histograms from DQM
22 # use option "-o filename" to make output root file with hits...
23 #
24 # run as: "basf2 arich/examples/arich_process_raw.py -- -f path2datafile.root"
25 # additional options:
26 # "-d 1" for unpacker debug info (data headers are printed, >1 raw data bits are printed)
27 # "-t 1" include CDC track reconstruction (reconstructed tracks are stored into output )
28 # "-a 1" store only data from events with track hit in arich
29 # "-g 1" include GDL unpacker to have TRGSummary
30 
31 import basf2 as b2
32 import os
33 from optparse import OptionParser
34 from reconstruction import add_cosmics_reconstruction
35 home = os.environ['BELLE2_LOCAL_DIR']
36 
37 
38 # parameters
39 parser = OptionParser()
40 parser.add_option(
41  '-f',
42  '--file',
43  dest='filename',
44  default='/ghi/fs01/belle2/bdata/users/tkonno/cosmic/cosmic.0002.00951.HLT3.f00000.root')
45 parser.add_option('-o', '--output', dest='output', default='')
46 parser.add_option('-d', '--debug', dest='debug', default=0)
47 parser.add_option('-t', '--tracking', dest='tracking', default=0)
48 parser.add_option('-a', '--arichtrk', dest='arichtrk', default=0)
49 parser.add_option('-g', '--gdl', dest='gdl', default=0)
50 (options, args) = parser.parse_args()
51 
52 
53 # set specific database tag
54 # b2.conditions.override_globaltags(["tagname"])
55 # use local database
56 # b2.conditions.testing_payloads = ["localdb/database.txt"]
57 
58 # create paths
59 main = b2.create_path()
60 store = b2.create_path()
61 
62 # root input module
63 input_module = b2.register_module('SeqRootInput')
64 input_module.param('inputFileName', options.filename)
65 # input_module.param('entrySequences',['5100:5300']) # process only range of events
66 main.add_module(input_module)
67 
68 # Histogram manager module
69 histo = b2.register_module('HistoManager')
70 histo.param('histoFileName', "DQMhistograms.root") # File to save histograms
71 main.add_module(histo)
72 
73 # build geometry if display option
74 if int(options.tracking):
75  main.add_module('Gearbox')
76  geometry = b2.register_module('Geometry')
77  geometry.param('useDB', 1)
78  main.add_module(geometry)
79 
80 # unpack raw data
81 unPacker = b2.register_module('ARICHUnpacker')
82 unPacker.param('debug', int(options.debug))
83 main.add_module(unPacker)
84 
85 # create ARICHHits from ARICHDigits
86 arichHits = b2.register_module('ARICHFillHits')
87 # set bitmask for making hits from digits
88 arichHits.param("bitMask", 0xFF)
89 main.add_module(arichHits)
90 
91 if int(options.tracking):
92  cdcunpacker = b2.register_module('CDCUnpacker')
93  cdcunpacker.param('xmlMapFileName', "data/cdc/ch_map.dat")
94  cdcunpacker.param('enablePrintOut', False)
95  main.add_module(cdcunpacker)
96  add_cosmics_reconstruction(main, 'CDC', False)
97 
98 if int(options.gdl):
99  main.add_module('TRGGDLUnpacker')
100  main.add_module('TRGGDLSummary')
101 
102 # create simple DQM histograms
103 arichHists = b2.register_module('ARICHDQM')
104 main.add_module(arichHists)
105 
106 # store the dataobjects
107 if(options.output != ''):
108  output = b2.register_module('RootOutput')
109  output.param('outputFileName', options.output)
110  branches = ['ARICHDigits', 'ARICHHits', 'ARICHInfo']
111  if int(options.tracking):
112  branches.extend(['Tracks', 'TrackFitResults', 'RecoTracks', 'RecoHitInformations', 'ExtHits'])
113  if int(options.gdl):
114  branches.append('TRGSummary')
115  output.param('branchNames', branches)
116  if int(options.arichtrk):
117  store.add_module(output)
118  else:
119  main.add_module(output)
120 
121 # show progress
122 main.add_module('Progress')
123 
124 if int(options.arichtrk):
125  arichHists.if_value('==1', store)
126 
127 # process
128 b2.process(main)
129 
130 # print stats
131 print(b2.statistics)