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