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