Belle II Software development
particleGun.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12from optparse import OptionParser
13from tracking import add_tracking_reconstruction
14from simulation import add_simulation
15import os
16# --------------------------------------------------------------------
17# Example of using ARICH reconstruction
18# needs reconstructed tracks (Tracks), extrapolated to ARICH (ExtHits)
19# --------------------------------------------------------------------
20
21parser = OptionParser()
22parser.add_option('-n', '--nevents', dest='nevents', default=1000,
23 help='Number of events to process')
24parser.add_option('-f', '--file', dest='filename',
25 default='ARICHEvents.root')
26(options, args) = parser.parse_args()
27
28home = os.environ['BELLE2_LOCAL_DIR']
29
30# set specific database tag
31# b2.conditions.override_globaltags(["tagname"])
32# use local database
33# b2.conditions.testing_payloads = ["localdb/database.txt"]
34
35# Suppress messages and warnings during processing:
36b2.set_log_level(b2.LogLevel.ERROR)
37
38# Create path
39main = b2.create_path()
40
41# Set number of events to generate
42eventinfosetter = b2.register_module('EventInfoSetter')
43eventinfosetter.param({'evtNumList': [int(options.nevents)], 'runList': [1]})
44main.add_module(eventinfosetter)
45
46# Histogram manager immediately after master module
47histo = b2.register_module('HistoManager')
48histo.param('histoFileName', 'DQMhistograms.root') # File to save histograms
49main.add_module(histo)
50
51# Particle gun: generate multiple tracks
52particlegun = b2.register_module('ParticleGun')
53particlegun.param('pdgCodes', [211, -211, 321, -321])
54particlegun.param('nTracks', 1)
55# particlegun.param('varyNTracks', True)
56particlegun.param('momentumGeneration', 'uniform')
57particlegun.param('momentumParams', [0.5, 4])
58particlegun.param('thetaGeneration', 'uniformCos')
59particlegun.param('thetaParams', [17, 35])
60particlegun.param('phiGeneration', 'uniform')
61particlegun.param('phiParams', [0, 360])
62particlegun.param('vertexGeneration', 'fixed')
63particlegun.param('xVertexParams', [0])
64particlegun.param('yVertexParams', [0])
65particlegun.param('zVertexParams', [0])
66particlegun.param('independentVertices', False)
67main.add_module(particlegun)
68
69# Simulation & Digitizer of inner detectors
70add_simulation(main, usePXDDataReduction=False)
71# tracking
72add_tracking_reconstruction(main)
73
74# Track extrapolation
75main.add_module('Ext')
76
77# convert ARICHDigits to ARICHHits
78main.add_module('ARICHFillHits')
79
80# ARICH reconstruction
81# calculate PID likelihoods for all tracks
82arichreco = b2.register_module('ARICHReconstructor')
83# store cherenkov angle information
84arichreco.param('storePhotons', 1)
85main.add_module(arichreco)
86
87# ARICH Ntuple
88# create flat ntuple for performance analysis
89arichNtuple = b2.register_module('ARICHNtuple')
90arichNtuple.param('outputFile', options.filename)
91main.add_module(arichNtuple)
92
93# ARICH DQM
94# create DQM occupancy plots
95main.add_module('ARICHDQM')
96
97# Uncomment to store DataStore content to root file
98# output = register_module('RootOutput')
99# output.param('outputFileName', 'DataStore.root')
100# main.add_module(output)
101
102# Uncomment to show event display
103# display = register_module('Display')
104# display.param('showARICHHits', True)
105# display.param('fullGeometry', True)
106# main.add_module(display)
107
108# Show progress of processing
109main.add_module('Progress')
110
111# Process events
112b2.process(main)
113
114# Print call statistics
115print(b2.statistics)
116
117# Make basic performance plots
118com = 'root -l ' + options.filename + ' ' + home + '/arich/utility/scripts/plotEfficiency.C'
119os.system(com)