Belle II Software  release-08-01-10
BhabhaMC.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2 as b2
12 import os
13 from simulation import add_simulation
14 from optparse import OptionParser
15 from L1trigger import add_trigger_simulation
16 from reconstruction import add_cdst_output, add_reconstruction
17 import glob
18 
19 background_files = glob.glob('/group/belle2/BGFile/OfficialBKG/phase2/pseudorandom/BGOverlay.physics.0003.*.root')
20 # --------------------------------------------------------------------
21 # Example of using ARICH reconstruction
22 # needs reconstructed tracks (Tracks), extrapolated to ARICH (ExtHits)
23 # --------------------------------------------------------------------
24 parser = OptionParser()
25 parser.add_option('-n', '--nevents', dest='nevents', default=200000,
26  help='Number of events to process')
27 parser.add_option('-f', '--file', dest='filename',
28  default='Bhabha_Prod5_MC.root')
29 parser.add_option('-o', '--output', dest='cdstname',
30  default='Bhabha_Prod5_MC_cdst.root')
31 (options, args) = parser.parse_args()
32 
33 home = os.environ['BELLE2_LOCAL_DIR']
34 
35 # Suppress messages and warnings during processing:
36 b2.set_log_level(b2.LogLevel.ERROR)
37 
38 # reset_database()
39 b2.use_database_chain()
40 b2.use_central_database("data_reprocessing_prod5", b2.LogLevel.WARNING)
41 
42 # Create path
43 main = b2.create_path()
44 empty = b2.create_path()
45 
46 # Set number of events to generate
47 eventinfosetter = b2.register_module('EventInfoSetter')
48 eventinfosetter.param({'evtNumList': [int(options.nevents)], 'runList': [1]})
49 main.add_module(eventinfosetter)
50 
51 # Histogram manager immediately after master module
52 histo = b2.register_module('HistoManager')
53 histo.param('histoFileName', 'DQMhistograms.root') # File to save histograms
54 main.add_module(histo)
55 
56 # Gearbox: access to database (xml files)
57 gearbox = b2.register_module('Gearbox', fileName="geometry/Beast2_phase2.xml")
58 main.add_module(gearbox)
59 
60 # Geometry
61 geometry = b2.register_module('Geometry')
62 # geometry.param('components', [
63 # 'MagneticField',
64 # 'BeamPipe',
65 # 'PXD',
66 # 'SVD',
67 # 'CDC',
68 # 'ARICH'])
69 main.add_module(geometry)
70 
71 # to run the framework the used modules need to be registered
72 generator = b2.register_module('BabayagaNLOInput')
73 generator.param('FinalState', 'ee')
74 generator.param('MaxAcollinearity', 180.0)
75 generator.param('ScatteringAngleRange', [15., 165.])
76 generator.param('FMax', 75000)
77 generator.param('MinEnergy', 0.01)
78 generator.param('Order', 'exp')
79 generator.param('DebugEnergySpread', 0.01)
80 generator.param('Epsilon', 0.00005)
81 generatorpreselection = b2.register_module('GeneratorPreselection')
82 generatorpreselection.param('nChargedMin', 1)
83 generatorpreselection.param('nChargedMax', 999)
84 generatorpreselection.param('MinChargedP', 4.)
85 # generatorpreselection.param('MinChargedTheta', 20.)
86 generatorpreselection.param('MinChargedTheta', 17.)
87 generatorpreselection.param('MaxChargedTheta', 36.)
88 generatorpreselection.param('applyInCMS', False)
89 main.add_module(generator)
90 main.add_module(generatorpreselection)
91 generatorpreselection.if_value('!=11', empty)
92 
93 # components = ['PXD', 'SVD', 'CDC']
94 
95 
96 # detector simulation (still use background mixing)
97 # add_simulation(main, components=components, bkgfiles=background_files, bkgOverlay=True)
98 # add_simulation(main, components=components)
99 
100 # add simulation but remove L1 trigger simulation
101 allowed_components = ['PXD', 'SVD', 'CDC', 'ECL', 'TOP', 'ARICH', 'KLM']
102 add_simulation(main, components=allowed_components, bkgfiles=background_files, bkgOverlay=True)
103 
104 # ARICH digitization
105 arich_digitizer = b2.register_module('ARICHDigitizer')
106 arich_digitizer.param('MagneticFieldDistorsion', 1)
107 main.add_module(arich_digitizer)
108 
109 # L1 trigger simulation
110 add_trigger_simulation(main, shortTracks=True, Belle2Phase="Phase2")
111 
112 # tracking
113 # add_tracking_reconstruction(main)
114 add_reconstruction(main)
115 
116 # convert ARICHDigits to ARICHHits
117 arichHits = b2.register_module('ARICHFillHits')
118 arichHits.param('MagFieldCorrection', 1)
119 main.add_module(arichHits)
120 
121 # ARICH reconstruction
122 # calculate PID likelihoods for all tracks
123 arichreco = b2.register_module('ARICHReconstructor')
124 # store cherenkov angle information
125 arichreco.param('storePhotons', 1)
126 arichreco.param('useAlignment', 0)
127 main.add_module(arichreco)
128 
129 # ARICH Ntuple
130 # create flat ntuple for performance analysis
131 arichNtuple = b2.register_module('ARICHNtuple')
132 arichNtuple.param('outputFile', options.filename)
133 main.add_module(arichNtuple)
134 
135 # ARICH DQM
136 # create DQM occupancy plots
137 arichdqm = b2.register_module('ARICHDQM')
138 main.add_module(arichdqm)
139 
140 add_cdst_output(main, True, '/ghi/fs01/belle2/bdata/users/sachit/' + options.cdstname)
141 
142 # Uncomment to store DataStore content to root file
143 # output = register_module('RootOutput')
144 # output.param('outputFileName', 'DataStore.root')
145 # main.add_module(output)
146 
147 # Uncomment to show event display
148 # display = register_module('Display')
149 # display.param('showARICHHits', True)
150 # display.param('fullGeometry', True)
151 # main.add_module(display)
152 
153 # Show progress of processing
154 progress = b2.register_module('Progress')
155 main.add_module(progress)
156 # main.add_module("PrintMCParticles", logLevel=LogLevel.INFO, onlyPrimaries=False)
157 # Process events
158 b2.process(main)
159 
160 # Print call statistics
161 print(b2.statistics)
162 
163 # Make basic performance plots
164 # com = 'root -l ' + options.filename + ' ' + home + '/arich/utility/scripts/plotEfficiency.C'
165 # os.system(com)