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