Belle II Software development
ARICHBtest_sim.py
1#!/usr/bin/env python3
2
3
10
11#
12# Usage:
13# basf2 arich/examples/ARICHBtest2011.py --
14# -r 102 -n 10000
15#
16import basf2 as b2
17from optparse import OptionParser
18import os
19import os.path
20
21b2.set_log_level(b2.LogLevel.INFO)
22
23outroot = 'arichbtest.root'
24
25parser = OptionParser()
26parser.add_option('-r', '--run', dest='runno', default='068',
27 help='analyse runno')
28
29parser.add_option('-y', '--year', dest='year', default='2013',
30 help='beam test year')
31
32parser.add_option('-m', '--avgagel', dest='avgagel', default='0',
33 help='average thc calculation based on the mean agel')
34
35parser.add_option(
36 '-o',
37 '--output',
38 dest='output',
39 default=outroot,
40 help='Output filename',
41 metavar='FILE',
42)
43
44parser.add_option('-n', '--neve', dest='neve', default=20000,
45 help='Number of events to process')
46
47(options, args) = parser.parse_args()
48
49if options.output == outroot:
50 outroot = 'run_' + options.runno + '.root'
51else:
52 outroot = options.output
53
54runno = int(options.runno) # needed for geoarich module
55
56# this variable is called from GeoARICHBtest2011Creator
57averageagel = int(options.avgagel)
58
59eventinfosetter = b2.register_module('EventInfoSetter')
60eventinfosetter.param('evtNumList', [int(options.neve)])
61eventinfosetter.param('runList', [int(options.runno)])
62eventinfosetter.param('expList', [1])
63
64# Load XML parameters
65paramloader = b2.register_module('Gearbox')
66
67xmlgeometry = 'file://%s/arich/modules/arichBtest/data/%s/arichBtest%s.xml' \
68 % (os.getcwd(), options.year, options.year)
69paramloader.param('fileName', xmlgeometry)
70print(xmlgeometry)
71paramloader.param('fileName', xmlgeometry)
72
73# database testing
74# paramloader.param('Backends', ['sql:'])
75# paramloader.param('Filename',
76# 'mysql://basf2:belle2@f9lab02.ijs.si:3306/b2config');
77# paramloader.param('Filename',
78# 'pgsql://basf2:belle2@f9lab02.ijs.si:5432/b2config');
79# paramloader.param('Filename', 'oracle://basf2:belle2@/f9lab02')
80# paramloader.param('Filename',
81# 'file:///afs/f9.ijs.si/home/rok/public_html/basf2/public/Belle2.xml');
82# paramloader.param('Filename',
83# 'file:///net/f9pc137/data0/belle2/rok/local/basf2/test/Belle2-merged.xml');
84
85# Create Geometry
86
87geobuilder = b2.register_module('Geometry')
88geobuilder.param('components', ['ARICHBtest'])
89
90# Particle gun module
91particlegun = b2.register_module('ParticleGun')
92# Setting the random seed for particle generation:
93b2.set_random_seed(1097)
94# Setting the list of particle codes (PDG codes) for the generated particles
95particlegun.param('pdgCodes', [-211, 211])
96# Setting the number of tracks to be generated per event:
97particlegun.param('nTracks', 1)
98# if you set nTracks to 0, then for each PDG code in pdgCodes list a track
99# will be generated on each event.
100# Setting the parameters for the random generation
101# of particles momenta:
102particlegun.param('momentumGeneration', 'uniform')
103particlegun.param('momentumParams', [3.5, 3.51])
104# Setting the parameters for the random generation
105# of the particle polar angle:
106particlegun.param('thetaGeneration', 'uniformCos')
107particlegun.param('thetaParams', [0, 0.2])
108particlegun.param('phiGeneration', 'uniform')
109particlegun.param('phiParams', [0, 360])
110# Setting the vertex position of shooted particles
111particlegun.param('vertexGeneration', 'uniform')
112particlegun.param('xVertexParams', [-2.5, 2.5])
113particlegun.param('yVertexParams', [18, 22])
114particlegun.param('zVertexParams', [-100, -101])
115# Print the parameters of the particle gun
116b2.print_params(particlegun)
117
118# Simulation module
119g4sim = b2.register_module('FullSim')
120# g4sim.param('StoreOpticalPhotons',True)
121# g4sim.param('SecondariesEnergyCut',0)
122# This line is necessary if you want to simulate Cerenkov photons!
123# By default optical processes are not registered.
124g4sim.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.
128g4sim.param('PhotonFraction', 0.3)
129
130arichDIGI = b2.register_module('ARICHDigitizer')
131
132arichrec = b2.register_module('ARICHReconstructor')
133arichrec.param('inputTrackType', 1)
134# choose 1 for measured data, 2 for MC, 3 for data /w likelihood
135# calculation, and 4 for MC /w likelihood
136arichrec.param('beamtest', 2)
137# include tracking resolution
138# arichrec.param('trackPositionResolution', 0.0)
139# arichrec.param('trackAngleResolution', 0.0)
140# file containing cerenkov angle distribution, etc.
141arichrec.param('outfileName', outroot)
142
143# Saves the geometry as a Root file
144geosaver = b2.register_module('ExportGeometry')
145geosaver.param('Filename', 'BeamtestGeo.root')
146
147main = b2.create_path()
148main.add_module(eventinfosetter)
149main.add_module(paramloader)
150main.add_module(geobuilder)
151main.add_module(particlegun)
152main.add_module(g4sim)
153main.add_module(arichDIGI)
154main.add_module(arichrec)
155# main.add_module(geosaver)
156b2.process(main)
157
158# Print basic event statistics to stdout
159print('Event Statistics:')
160print(b2.statistics)