Belle II Software  release-08-01-10
ARICHCosmicTestData.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # Script for ARICH cosmics data simple analysis
12 # reads arich raw data, stores arichHits and arichDigits into the output root file,
13 # makes and displays DQM histograms, runs the event display
14 #
15 # run as: "basf2 ARICHCosmicTestData.py -- -f path2datafile.sroot"
16 # add "-s 1" for event display
17 #
18 # two parameters (MinHits and MaxHits) are available for DQM module (check below)
19 # only events with number of hits within the range are included in DQM histograms
20 # and shown in the event display (set to 5 and 40, but change accoring your need)
21 
22 import basf2 as b2
23 import os
24 from optparse import OptionParser
25 home = os.environ['BELLE2_LOCAL_DIR']
26 
27 
28 b2.conditions.override_globaltags()
29 b2.conditions.append_globaltag("332_COPY-OF_GT_gen_prod_004.11_Master-20171213-230000")
30 
31 # parameters
32 parser = OptionParser()
33 parser.add_option(
34  '-f',
35  '--file',
36  dest='filename',
37  default='/ghi/fs01/belle2/bdata/users/tkonno/cosmic/cosmic.0002.00951.HLT3.f00000.root')
38 parser.add_option('-o', '--output', dest='output', default='ARICHHits.root')
39 parser.add_option('-d', '--debug', dest='debug', default=0)
40 parser.add_option('-s', '--display', dest='display', default=0)
41 (options, args) = parser.parse_args()
42 
43 # create paths
44 main = b2.create_path()
45 displ = b2.create_path()
46 
47 
48 # root input module
49 input_module = b2.register_module('RootInput')
50 input_module.param('inputFileName', options.filename)
51 # input_module.param('entrySequences',['5100:5300']) # select subrange of events
52 main.add_module(input_module)
53 
54 # Histogram manager module
55 histo = b2.register_module('HistoManager')
56 histo.param('histoFileName', "histograms.root") # File to save histograms
57 main.add_module(histo)
58 
59 
60 # build geometry if display option
61 if int(options.display):
62  main.add_module('Gearbox')
63  geometry = b2.register_module('Geometry')
64  geometry.param('components', ['ARICH'])
65  main.add_module(geometry)
66 
67 # unpack raw data
68 unPacker = b2.register_module('ARICHUnpacker')
69 unPacker.param('debug', int(options.debug))
70 main.add_module(unPacker)
71 
72 # create ARICHHits from ARICHDigits
73 main.add_module('ARICHFillHits')
74 
75 # create simple DQM histograms
76 arichHists = b2.register_module('ARICHDQM')
77 arichHists.param('MaxHits', 40)
78 arichHists.param('MinHits', 5)
79 main.add_module(arichHists)
80 
81 # add display module if display option
82 if int(options.display):
83  display = b2.register_module('Display')
84  # show arich hits
85  display.param('showARICHHits', True)
86  # show full geometry
87  display.param('fullGeometry', True)
88  displ.add_module(display)
89 
90 # store dataobjects
91 output = b2.register_module('RootOutput')
92 output.param('outputFileName', options.output)
93 branches = ['ARICHDigits', 'ARICHHits']
94 output.param('branchNames', branches)
95 main.add_module(output)
96 
97 # show progress
98 main.add_module('Progress')
99 
100 arichHists.if_value('==1', displ)
101 
102 # process
103 b2.process(main)
104 
105 # print stats
106 print(b2.statistics)
107 
108 # plot DQM histograms
109 if not int(options.display):
110  com = 'root -l histograms.root ' + home + '/arich/utility/scripts/plotDQM.C'
111  os.system(com)