Belle II Software  release-06-01-15
ARICHCosmicTestSim.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2 as b2
13 from optparse import OptionParser
14 import os
15 # Options from command line
16 parser = OptionParser()
17 parser.add_option('-n', '--nevents', dest='nevents', default=100,
18  help='Number of events to process')
19 parser.add_option('-f', '--file', dest='filename', default='ARICHDQM.root')
20 parser.add_option('-d', '--debug', dest='debugLevel', default=10)
21 parser.add_option('-s', '--seed', dest='seed', default=111111)
22 (options, args) = parser.parse_args()
23 
24 nevents = int(options.nevents)
25 debugLevel = int(options.debugLevel)
26 seed = int(options.seed)
27 # suppress messages and warnings during processing DEBUG, INFO, WARNING, ERROR
28 b2.set_log_level(b2.LogLevel.INFO)
29 
30 home = os.environ['BELLE2_LOCAL_DIR']
31 # cosmic test local DB folder
32 b2.use_local_database(home + "/arich/database/cosmicTest_payloads/cosmicTest_database.txt",
33  home + "/arich/database/cosmicTest_payloads")
34 
35 # Create path
36 main = b2.create_path()
37 
38 # Create Event information
39 main.add_module('EventInfoSetter', evtNumList=nevents, logLevel=b2.LogLevel.DEBUG)
40 
41 # Histogram manager module
42 histo = b2.register_module('HistoManager')
43 histo.param('histoFileName', options.filename) # File to save histograms
44 main.add_module(histo)
45 
46 
47 # Load parameters
48 gearbox = b2.register_module('Gearbox')
49 main.add_module(gearbox)
50 
51 # Create geometry
52 geometry = b2.register_module('Geometry')
53 geometry.param('components', ['ARICH'])
54 # build from DB
55 geometry.param('useDB', 1)
56 main.add_module(geometry)
57 
58 # Particle gun module
59 particlegun = b2.register_module('ParticleGun')
60 # Setting the random seed for particle generation:
61 b2.set_random_seed(seed)
62 # Setting the list of particle codes (PDG codes) for the generated particles
63 particlegun.param('pdgCodes', [11])
64 # Setting the number of tracks to be generated per event:
65 particlegun.param('nTracks', 1)
66 # if you set nTracks to 0, then for each PDG code in pdgCodes list a track
67 # will be generated on each event.
68 # Setting the parameters for the random generation
69 # of particles momenta:
70 particlegun.param('momentumGeneration', 'fixed')
71 particlegun.param('momentumParams', [5.0])
72 # Setting the parameters of particle direction
73 particlegun.param('thetaGeneration', 'fixed')
74 particlegun.param('thetaParams', [95.])
75 particlegun.param('phiGeneration', 'fixed')
76 particlegun.param('phiParams', [270])
77 
78 # vertex position
79 particlegun.param('vertexGeneration', 'fixed')
80 # particlegun.param('vertexGeneration', 'uniform')
81 particlegun.param('xVertexParams', [-43.88])
82 particlegun.param('yVertexParams', [10.0])
83 particlegun.param('zVertexParams', [-40.0])
84 # Print the parameters of the particle gun
85 b2.print_params(particlegun)
86 main.add_module(particlegun)
87 
88 # ============================================================================
89 
90 # Run simulation
91 simulation = b2.register_module('FullSim')
92 simulation.param('StoreOpticalPhotons', True)
93 # by default only 35% of photons are propagated, which is below QE of some HAPDs! change fraction to 45% here.
94 # -> change the default fraction for the release!
95 simulation.param('PhotonFraction', 0.45)
96 main.add_module(simulation)
97 
98 # ARICH digitization module
99 arichDIGI = b2.register_module('ARICHDigitizer')
100 arichDIGI.param('BackgroundHits', 0)
101 main.add_module(arichDIGI)
102 
103 # fill ARICHHits from ARICHDigits
104 arichHits = b2.register_module('ARICHFillHits')
105 main.add_module(arichHits)
106 
107 # add ARICH DQM module
108 arichDQM = b2.register_module('ARICHDQM')
109 main.add_module(arichDQM)
110 
111 # add display module
112 # display = register_module('Display')
113 # change to True to show the full TGeo geometry instead of simplified extract
114 # display.param('fullGeometry', True)
115 # show ARICH hits
116 # display.param('showARICHHits', True)
117 # main.add_module(display)
118 
119 # store datastore objets into root file
120 # output = register_module('RootOutput')
121 # output.param('outputFileName', "rootOutput.root")
122 # output.param('branchNames', ['ARICHAeroHits', 'ARICHSimHits', 'ARICHDigits', 'ARICHHits'])
123 # main.add_module(output)
124 
125 # Show progress of processing
126 progress = b2.register_module('Progress')
127 main.add_module(progress)
128 
129 # Process events
130 b2.process(main)
131 
132 # Print call statistics
133 print(b2.statistics)
134 
135 # plot DQM histograms
136 com = 'root -l ' + options.filename + ' ' + home + '/arich/utility/scripts/plotDQM.C'
137 os.system(com)