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