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