Belle II Software  release-08-01-10
ARICHBtest.py
1 #!/usr/bin/env python3
2 
3 
10 
11 #
12 # Usage:
13 # basf2 arich/examples/ARICHBtest2011.py --
14 # -r 102 -n 10000
15 #
16 import basf2 as b2
17 from optparse import OptionParser
18 import os
19 import os.path
20 import sys
21 
22 b2.set_log_level(b2.LogLevel.INFO)
23 
24 outroot = 'arichbtest.root'
25 
26 parser = OptionParser()
27 parser.add_option('-r', '--run', dest='runno', default='068',
28  help='analyse runno')
29 parser.add_option('-p', '--path', dest='path',
30  default='/afs/f9.ijs.si/data/belle/data/beamtests/2011/run',
31  help='datapath')
32 
33 parser.add_option('-y', '--year', dest='year', default='2011',
34  help='beam test year')
35 
36 parser.add_option('-t', '--track-mask', dest='mask', default='0x5',
37  help='track mask 4 bits')
38 
39 parser.add_option('-m', '--avgagel', dest='avgagel', default='0',
40  help='average thc calculation based on the mean agel')
41 
42 parser.add_option(
43  '-o',
44  '--output',
45  dest='output',
46  default=outroot,
47  help='Output filename',
48  metavar='FILE',
49 )
50 
51 parser.add_option('-n', '--neve', dest='neve', default=20000,
52  help='Number of events to process')
53 
54 (options, args) = parser.parse_args()
55 
56 fname = options.path + '/run' + options.runno + '.dat'
57 
58 if not os.path.isfile(fname):
59  print('File does not exist:')
60  print(fname)
61  fname += '.gz'
62  print('Appending .gz...')
63 if not os.path.isfile(fname):
64  print('File does not exist:')
65  print(fname)
66  sys.exit(-1)
67 
68 if options.output == outroot:
69  outroot = 'run_' + options.runno + '.root'
70 else:
71  outroot = options.output
72 
73 mask = int(options.mask, 16)
74 runno = int(options.runno) # needed for geoarich module
75 
76 print('TrackMask:' + options.mask)
77 
78 # this variable is called from GeoARICHBtest2011Creator
79 averageagel = int(options.avgagel)
80 
81 eventinfosetter = b2.register_module('EventInfoSetter')
82 eventinfosetter.param('evtNumList', [int(options.neve)])
83 eventinfosetter.param('runList', [int(options.runno)])
84 eventinfosetter.param('expList', [1])
85 
86 # Load XML parameters
87 paramloader = b2.register_module('Gearbox')
88 
89 xmlgeometry = 'file://%s/arich/modules/arichBtest/data/%s/arichBtest%s.xml' \
90  % (os.getcwd(), options.year, options.year)
91 paramloader.param('fileName', xmlgeometry)
92 print(xmlgeometry)
93 paramloader.param('fileName', xmlgeometry)
94 
95 # paramloader.param('Backends', ['sql:'])
96 # paramloader.param('Filename',
97 # 'mysql://basf2:belle2@f9lab02.ijs.si:3306/b2config');
98 # paramloader.param('Filename',
99 # 'pgsql://basf2:belle2@f9lab02.ijs.si:5432/b2config');
100 # paramloader.param('Filename', 'oracle://basf2:belle2@/f9lab02')
101 # paramloader.param('Filename',
102 # 'file:///afs/f9.ijs.si/home/rok/public_html/basf2/public/Belle2.xml');
103 # paramloader.param('Filename',
104 # 'file:///net/f9pc137/data0/belle2/rok/local/basf2/test/Belle2-merged.xml');
105 # Create Geometry
106 geobuilder = b2.register_module('Geometry')
107 geobuilder.param('components', ['ARICHBtest'])
108 
109 btest = b2.register_module('arichBtest')
110 btest.param('mwpcTrackMask', [mask])
111 # btest.param('Filename', 'arich/modules/arichBtest/data/2011/track.dat')
112 btest.param('runList', [fname])
113 btest.param('outputFileName', outroot)
114 momentum = 120.0
115 if options.year == '2013':
116  momentum = 3.0
117 print('Beam momentum ' + str(momentum))
118 btest.param('beamMomentum', momentum)
119 
120 # Simulation module
121 g4sim = b2.register_module('FullSim')
122 # This line is necessary if you want to simulate Cerenkov photons!
123 # By default optical processes are not registered.
124 g4sim.param('RegisterOptics', 1)
125 # To speed up the simulation you can propagate
126 # only a selected fraction of photons.
127 # By default all photons are propagated.
128 g4sim.param('PhotonFraction', 0.3)
129 # Set up the visualization
130 g4sim.param('EnableVisualization', True)
131 # Here you can select visualization driver and visualization commands.
132 # This creates VRML file,
133 # change VRML2FILE to HepRepFile to create HepRep file.
134 g4sim.param('UICommandsAtIdle', ['/vis/open VRML2FILE', '/vis/drawVolume',
135  '/vis/scene/add/axes 0 0 0 100 mm'])
136 
137 # Saves the geometry as a Root file
138 geosaver = b2.register_module('ExportGeometry')
139 geosaver.param('Filename', 'Belle2Geo.root')
140 
141 arichrec = b2.register_module('ARICHReconstructor')
142 arichrec.param('inputTrackType', 1)
143 arichrec.param('beamtest', 3)
144 arichrec.param('trackPositionResolution', 0.0)
145 arichrec.param('trackAngleResolution', 0.0)
146 
147 profile = b2.register_module('Profile')
148 profile.param('outputFileName', 'profileusage.ps')
149 
150 main = b2.create_path()
151 main.add_module(eventinfosetter)
152 main.add_module(paramloader)
153 # main.add_module(profile)
154 main.add_module(geobuilder)
155 main.add_module(btest)
156 main.add_module(arichrec)
157 # main.add_module(g4sim)
158 main.add_module(geosaver)
159 
160 b2.process(main)
161 
162 # Print basic event statistics to stdout
163 print('Event Statistics:')
164 print(b2.statistics)