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