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