Belle II Software  release-08-01-10
arich_display.py
1 # !/usr/bin/env python3
2 
3 
10 
11 # Script for running arich event display, DQM module, and arich reconstruction on
12 # processed data (containing arichHits)
13 # To process raw data first use arich/examples/arich_process_raw.py
14 #
15 # run as: "basf2 arich/examples/arich_display.py -- -f path2processedDatafile.sroot"
16 # add "-s 1" for event display, otherwise only DQM histograms are produced
17 # add "-a 1" to select only events that have extrapolated track in the arich
18 # add "-r 1" to add the arich reconstruction (for cherenkov angle distribution)
19 #
20 # two parameters (MinHits and MaxHits) are available for DQM module (check below)
21 # only events with number of hits within the range are included in DQM histograms
22 # and shown in the event display (set to 5 and 40, but change according to your need)
23 
24 import basf2 as b2
25 import os
26 from optparse import OptionParser
27 home = os.environ['BELLE2_LOCAL_DIR']
28 
29 # parameters
30 parser = OptionParser()
31 parser.add_option('-f', '--file', dest='filename', default='ARICHHits.root')
32 parser.add_option('-s', '--display', dest='display', default=0)
33 parser.add_option('-a', '--arichtrk', dest='arichtrk', default=0)
34 parser.add_option('-r', '--recon', dest='recon', default=1)
35 parser.add_option('-o', '--output', dest='output', default='arich_recon_ntuple.root')
36 (options, args) = parser.parse_args()
37 
38 # create paths
39 main = b2.create_path()
40 displ = b2.create_path()
41 
42 # root input module
43 input_module = b2.register_module('RootInput')
44 input_module.param('inputFileName', options.filename)
45 main.add_module(input_module)
46 
47 # Histogram manager module
48 histo = b2.register_module('HistoManager')
49 histo.param('histoFileName', "histograms.root") # File to save histograms
50 main.add_module(histo)
51 
52 # build geometry if display option
53 if int(options.display):
54  main.add_module('Gearbox')
55  geometry = b2.register_module('Geometry')
56  geometry.param('components', ['ARICH', 'MagneticField'])
57  main.add_module(geometry)
58 
59 if int(options.recon):
60  arichHits = b2.register_module('ARICHFillHits')
61  arichHits.param('MagFieldCorrection', 1)
62  main.add_module(arichHits)
63  arichreco = b2.register_module('ARICHReconstructor')
64  arichreco.param('storePhotons', 1)
65  arichreco.param('useAlignment', 1)
66  main.add_module(arichreco)
67  arichNtuple = b2.register_module('ARICHNtuple')
68  arichNtuple.param('outputFile', options.output)
69  main.add_module(arichNtuple)
70 
71 
72 # create simple DQM histograms
73 arichHists = b2.register_module('ARICHDQM')
74 arichHists.param('ArichEvents', bool(options.arichtrk))
75 # set hit range - include only events with hits in this range (also for event display!)
76 arichHists.param('MaxHits', 100)
77 arichHists.param('MinHits', 0)
78 main.add_module(arichHists)
79 
80 # add display module if display option
81 if int(options.display):
82  display = b2.register_module('Display')
83  # show arich hits
84  display.param('showARICHHits', True)
85  # show reconstructed tracks
86  display.param('showRecoTracks', True)
87  # show full geometry
88  display.param('fullGeometry', True)
89  displ.add_module(display)
90 
91 
92 # show progress
93 main.add_module('Progress')
94 
95 arichHists.if_value('==1', displ)
96 
97 # process
98 b2.process(main)
99 
100 # print stats
101 print(b2.statistics)
102 
103 # plot DQM histograms
104 if not int(options.display):
105  com = 'root -l histograms.root ' + home + '/arich/utility/scripts/plotDQM.C'
106  os.system(com)