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