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