Belle II Software  release-08-01-10
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 #
16 import basf2 as b2
17 from optparse import OptionParser
18 import os
19 import os.path
20 
21 b2.set_log_level(b2.LogLevel.INFO)
22 
23 outroot = 'arichbtest.root'
24 
25 parser = OptionParser()
26 parser.add_option('-r', '--run', dest='runno', default='068',
27  help='analyse runno')
28 
29 parser.add_option('-y', '--year', dest='year', default='2013',
30  help='beam test year')
31 
32 parser.add_option('-m', '--avgagel', dest='avgagel', default='0',
33  help='average thc calculation based on the mean agel')
34 
35 parser.add_option(
36  '-o',
37  '--output',
38  dest='output',
39  default=outroot,
40  help='Output filename',
41  metavar='FILE',
42 )
43 
44 parser.add_option('-n', '--neve', dest='neve', default=20000,
45  help='Number of events to process')
46 
47 (options, args) = parser.parse_args()
48 
49 if options.output == outroot:
50  outroot = 'run_' + options.runno + '.root'
51 else:
52  outroot = options.output
53 
54 runno = int(options.runno) # needed for geoarich module
55 
56 # this variable is called from GeoARICHBtest2011Creator
57 averageagel = int(options.avgagel)
58 
59 eventinfosetter = b2.register_module('EventInfoSetter')
60 eventinfosetter.param('evtNumList', [int(options.neve)])
61 eventinfosetter.param('runList', [int(options.runno)])
62 eventinfosetter.param('expList', [1])
63 
64 # Load XML parameters
65 paramloader = b2.register_module('Gearbox')
66 
67 xmlgeometry = 'file://%s/arich/modules/arichBtest/data/%s/arichBtest%s.xml' \
68  % (os.getcwd(), options.year, options.year)
69 paramloader.param('fileName', xmlgeometry)
70 print(xmlgeometry)
71 paramloader.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 
87 geobuilder = b2.register_module('Geometry')
88 geobuilder.param('components', ['ARICHBtest'])
89 
90 # Particle gun module
91 particlegun = b2.register_module('ParticleGun')
92 # Setting the random seed for particle generation:
93 b2.set_random_seed(1097)
94 # Setting the list of particle codes (PDG codes) for the generated particles
95 particlegun.param('pdgCodes', [-211, 211])
96 # Setting the number of tracks to be generated per event:
97 particlegun.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:
102 particlegun.param('momentumGeneration', 'uniform')
103 particlegun.param('momentumParams', [3.5, 3.51])
104 # Setting the parameters for the random generation
105 # of the particle polar angle:
106 particlegun.param('thetaGeneration', 'uniformCos')
107 particlegun.param('thetaParams', [0, 0.2])
108 particlegun.param('phiGeneration', 'uniform')
109 particlegun.param('phiParams', [0, 360])
110 # Setting the vertex position of shooted particles
111 particlegun.param('vertexGeneration', 'uniform')
112 particlegun.param('xVertexParams', [-2.5, 2.5])
113 particlegun.param('yVertexParams', [18, 22])
114 particlegun.param('zVertexParams', [-100, -101])
115 # Print the parameters of the particle gun
116 b2.print_params(particlegun)
117 
118 # Simulation module
119 g4sim = 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.
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 
130 arichDIGI = b2.register_module('ARICHDigitizer')
131 
132 arichrec = b2.register_module('ARICHReconstructor')
133 arichrec.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
136 arichrec.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.
141 arichrec.param('outfileName', outroot)
142 
143 # Saves the geometry as a Root file
144 geosaver = b2.register_module('ExportGeometry')
145 geosaver.param('Filename', 'BeamtestGeo.root')
146 
147 main = b2.create_path()
148 main.add_module(eventinfosetter)
149 main.add_module(paramloader)
150 main.add_module(geobuilder)
151 main.add_module(particlegun)
152 main.add_module(g4sim)
153 main.add_module(arichDIGI)
154 main.add_module(arichrec)
155 # main.add_module(geosaver)
156 b2.process(main)
157 
158 # Print basic event statistics to stdout
159 print('Event Statistics:')
160 print(b2.statistics)