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