Belle II Software  release-08-01-10
ARICHCosmicTestSim.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2 as b2
12 from optparse import OptionParser
13 import os
14 # Options from command line
15 parser = OptionParser()
16 parser.add_option('-n', '--nevents', dest='nevents', default=100,
17  help='Number of events to process')
18 parser.add_option('-f', '--file', dest='filename', default='ARICHDQM.root')
19 parser.add_option('-d', '--debug', dest='debugLevel', default=10)
20 parser.add_option('-s', '--seed', dest='seed', default=111111)
21 (options, args) = parser.parse_args()
22 
23 nevents = int(options.nevents)
24 debugLevel = int(options.debugLevel)
25 seed = int(options.seed)
26 # suppress messages and warnings during processing DEBUG, INFO, WARNING, ERROR
27 b2.set_log_level(b2.LogLevel.INFO)
28 
29 home = os.environ['BELLE2_LOCAL_DIR']
30 # cosmic test local DB folder
31 b2.conditions.append_testing_payloads(home + "/arich/database/cosmicTest_payloads/cosmicTest_database.txt")
32 
33 # Create path
34 main = b2.create_path()
35 
36 # Create Event information
37 main.add_module('EventInfoSetter', evtNumList=nevents, logLevel=b2.LogLevel.DEBUG)
38 
39 # Histogram manager module
40 histo = b2.register_module('HistoManager')
41 histo.param('histoFileName', options.filename) # File to save histograms
42 main.add_module(histo)
43 
44 
45 # Load parameters
46 main.add_module('Gearbox')
47 
48 # Create geometry
49 geometry = b2.register_module('Geometry')
50 geometry.param('components', ['ARICH'])
51 # build from DB
52 geometry.param('useDB', 1)
53 main.add_module(geometry)
54 
55 # Particle gun module
56 particlegun = b2.register_module('ParticleGun')
57 # Setting the random seed for particle generation:
58 b2.set_random_seed(seed)
59 # Setting the list of particle codes (PDG codes) for the generated particles
60 particlegun.param('pdgCodes', [11])
61 # Setting the number of tracks to be generated per event:
62 particlegun.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:
67 particlegun.param('momentumGeneration', 'fixed')
68 particlegun.param('momentumParams', [5.0])
69 # Setting the parameters of particle direction
70 particlegun.param('thetaGeneration', 'fixed')
71 particlegun.param('thetaParams', [95.])
72 particlegun.param('phiGeneration', 'fixed')
73 particlegun.param('phiParams', [270])
74 
75 # vertex position
76 particlegun.param('vertexGeneration', 'fixed')
77 # particlegun.param('vertexGeneration', 'uniform')
78 particlegun.param('xVertexParams', [-43.88])
79 particlegun.param('yVertexParams', [10.0])
80 particlegun.param('zVertexParams', [-40.0])
81 # Print the parameters of the particle gun
82 b2.print_params(particlegun)
83 main.add_module(particlegun)
84 
85 # ============================================================================
86 
87 # Run simulation
88 simulation = b2.register_module('FullSim')
89 simulation.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!
92 simulation.param('PhotonFraction', 0.45)
93 main.add_module(simulation)
94 
95 # ARICH digitization module
96 arichDIGI = b2.register_module('ARICHDigitizer')
97 arichDIGI.param('BackgroundHits', 0)
98 main.add_module(arichDIGI)
99 
100 # fill ARICHHits from ARICHDigits
101 main.add_module('ARICHFillHits')
102 
103 # add ARICH DQM module
104 main.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
121 main.add_module('Progress')
122 
123 # Process events
124 b2.process(main)
125 
126 # Print call statistics
127 print(b2.statistics)
128 
129 # plot DQM histograms
130 com = 'root -l ' + options.filename + ' ' + home + '/arich/utility/scripts/plotDQM.C'
131 os.system(com)